Corrected word wrapping issues with PGEX_TTF. Added another line, fixed word wrapping width. Fixed up which fonts were used for measuring sizes.

pull/28/head
sigonasr2 1 year ago
parent d9b1908985
commit 25b6dc0299
  1. 2
      Crawler/Version.h
  2. 35
      Crawler/VisualNovel.cpp
  3. 2
      Crawler/VisualNovel.h
  4. BIN
      Crawler/assets/LCDBlock.ttf
  5. 5
      Crawler/assets/config/configuration.txt
  6. 3
      Crawler/olcPGEX_TTF.h
  7. 26
      Crawler/olcPixelGameEngine.h
  8. BIN
      Crawler/pge.data
  9. 2
      Crawler/pge.js
  10. BIN
      Crawler/pge.wasm

@ -39,7 +39,7 @@ All rights reserved.
#define VERSION_MAJOR 0
#define VERSION_MINOR 2
#define VERSION_PATCH 1
#define VERSION_BUILD 3298
#define VERSION_BUILD 3321
#define stringify(a) stringify_(a)
#define stringify_(a) #a

@ -50,10 +50,12 @@ INCLUDE_GFX
VisualNovel VisualNovel::novel;
safemap<std::string,std::vector<std::unique_ptr<Command>>>VisualNovel::storyLevelData;
std::set<std::string>VisualNovel::graphicsToLoad;
Font VisualNovel::font;
Font VisualNovel::font,VisualNovel::narratorFont,VisualNovel::locationFont;
void VisualNovel::Initialize(){
font=Font("GFX_Prefix"_S+"dialog_font_size"_s[0]+".ttf","dialog_font_size"_i[1]);
narratorFont=Font("GFX_Prefix"_S+"narrator_font_size"_s[0]+".ttf","narrator_font_size"_i[1]);
locationFont=Font("GFX_Prefix"_S+"location_font_size"_s[0]+".ttf","location_font_size"_i[1]);
for(int chapter=1;chapter<=6;chapter++){
std::string chapterFilename="assets/"+"story_directory"_S+"Chapter "+std::to_string(chapter)+".txt";
std::ifstream file(chapterFilename);
@ -172,8 +174,9 @@ void VisualNovel::LoadVisualNovel(std::string storyLevelName){
novel.activeText=U"";
novel.leftCharacters.clear();
novel.rightCharacters.clear();
novel.backgroundFilename="";
novel.backgroundFilename=novel.prevBackgroundFilename="";
novel.commands.clear();
novel.commandIndex=0;
for(std::unique_ptr<Command>&command:storyLevelData.at(storyLevelName)){
novel.commands.push_back(command.get());
}
@ -230,10 +233,13 @@ void VisualNovel::Draw(){
game->DrawRotatedDecal(game->GetScreenSize()-vi2d{i*64+int(spriteWidth)/2,72+168},GFX[GetCharacterImage(character)].Decal(),0,vf2d{spriteWidth/2,0.f},{-1,1},fadeColor);
}
if(locationDisplayTime>0){
vi2d textSize=game->GetTextSizeProp(locationDisplayText)*2;
game->FillRectDecal(game->GetScreenSize()/2-textSize/2-vi2d{4,4},textSize+vi2d{8,8},BLACK);
game->DrawRectDecal(game->GetScreenSize()/2-textSize/2-vi2d{4,4},textSize+vi2d{8,8},WHITE);
game->DrawShadowStringPropDecal(game->GetScreenSize()/2-textSize/2,locationDisplayText,WHITE,VERY_DARK_BLUE,{2.f,2.f});
std::u32string locationStr=std::u32string(locationDisplayText.begin(),locationDisplayText.end());
FontRect textSize=locationFont.GetStringBounds(locationStr);
textSize.offset*=2;
textSize.size*=2;
game->FillRectDecal(game->GetScreenSize()/2-textSize.size/2-vi2d{4,4}+textSize.offset/2,textSize.size+vi2d{8,8},BLACK);
game->DrawRectDecal(game->GetScreenSize()/2-textSize.size/2-vi2d{4,4}+textSize.offset/2,textSize.size+vi2d{8,8},WHITE);
game->DrawShadowStringDecal(locationFont,game->GetScreenSize()/2-textSize.size/2+textSize.offset/2,locationStr,WHITE,VERY_DARK_BLUE,{2.f,2.f});
}
if(activeText.length()>0){
vf2d nameDisplayPos={24.f,game->GetScreenSize().y-60.f};
@ -244,9 +250,14 @@ void VisualNovel::Draw(){
vf2d dialogDisplayPos={24.f,game->GetScreenSize().y-48.f};
vf2d dialogDisplaySize={game->GetScreenSize().x-48.f,20.f};
Menu::DrawThemedWindow(dialogDisplayPos,dialogDisplaySize);
FontRect dialogTextSize=font.GetStringBounds(activeText);
FontRect speakerTextSize=font.GetStringBounds(speakerDisplayName);
game->DrawStringDecal(font,nameDisplayPos-vf2d{10,8}+(nameDisplayWindowSize+vf2d{24,0})/2-speakerTextSize.size/2,speakerDisplayName);
game->DrawStringDecal(font,dialogDisplayPos-vf2d{10,10},activeText);
if(speakerDisplayName.length()>0){
game->DrawShadowStringDecal(font,nameDisplayPos-vf2d{10,7}+(nameDisplayWindowSize+vf2d{24,0})/2-speakerTextSize.size/2+speakerTextSize.offset/2,speakerDisplayName);
game->DrawShadowStringDecal(font,dialogDisplayPos-vf2d{10,6}+dialogTextSize.offset,activeText);
}else{
game->DrawDropShadowStringDecal(narratorFont,dialogDisplayPos-vf2d{10,6}+dialogTextSize.offset,activeText);
}
float yOffset=util::lerp(dialogDisplaySize.y+12,-8,textScrollTime/maxTextScrollTime);
game->DrawPolygonDecal(
Menu::GetPatchPart(1,1).Decal(),
@ -315,10 +326,14 @@ CommandType::CommandType SpeakerCommand::GetType(){return CommandType::SPEAKER;}
void DialogCommand::Execute(VisualNovel&vn){
vn.textScrollTime=VisualNovel::maxTextScrollTime;
bool mustDisplay=vn.activeText.length()==0;
std::u32string newText=util::WrapText(game,vn.activeText+(vn.activeText.length()>0?U" ":U"")+std::u32string(dialog.begin(),dialog.end()),game->GetScreenSize().x-48,VisualNovel::font,{1,1});
if(VisualNovel::font.GetStringBounds(newText).size.y>40){//Hit the maximum of 3 lines.
Font*displayFont=&VisualNovel::font;
if(vn.actualSpeakerName.length()==0)displayFont=&VisualNovel::narratorFont;
std::u32string newText=util::WrapText(game,vn.activeText+(vn.activeText.length()>0?U" ":U"")+std::u32string(dialog.begin(),dialog.end()),game->GetScreenSize().x-24,*displayFont,{1,1});
if(VisualNovel::font.GetStringBounds(newText).size.y>48){//Hit the maximum of 3 lines.
if(!mustDisplay){
vn.commandIndex--;
}else{
vn.activeText=newText;
}
}else{
vn.activeText=newText;

@ -150,7 +150,7 @@ class VisualNovel{
std::string prevTheme="";
float textScrollTime=0;
static constexpr float maxTextScrollTime=1.0f;
static Font font;
static Font font,narratorFont,locationFont;
static std::set<std::string>graphicsToLoad;
static safemap<std::string,std::vector<std::unique_ptr<Command>>>storyLevelData;

Binary file not shown.

@ -61,7 +61,10 @@ story_background_image_location = backgrounds/
story_player_name = You
# Dialog font and size.
dialog_font_size = Habbo,12
dialog_font_size = c64esque,12
# Narrator font and size.
narrator_font_size = Habbo,12
# Location font and size.
location_font_size = Habbo,24

@ -195,6 +195,8 @@ namespace olc {
char32_t chr = string[i];
if(chr=='\r')continue;
int prevmaxX=maxX;
Font *toUse = this;
FT_UInt chrIndex = GetCharIndex(chr);
@ -246,6 +248,7 @@ namespace olc {
if(chr=='\n'){
int scaled_line_spacing = fontFace->size->metrics.height;
pen.y -=scaled_line_spacing;
maxX=prevmaxX; //Since this character is getting ignored, we need to revert back to the previous max X.
pen.x=minX;
}
FT_Done_Glyph(glyph);

@ -1147,6 +1147,7 @@ namespace olc
void DrawShadowStringDecal(const olc::vf2d& pos, const std::string& sText, const Pixel col = olc::WHITE, const Pixel shadowCol = olc::BLACK, const olc::vf2d& scale = { 1.0f, 1.0f },const float shadowSizeFactor=1);
void DrawShadowStringPropDecal(const olc::vf2d& pos, const std::string& sText, const Pixel col = olc::WHITE, const Pixel shadowCol = olc::BLACK, const olc::vf2d& scale = { 1.0f, 1.0f },const float shadowSizeFactor=1);
void DrawShadowStringDecal(Font&font, const olc::vf2d& pos, const std::u32string& sText, const Pixel col = olc::WHITE, const Pixel shadowCol = olc::BLACK, const olc::vf2d& scale = { 1.0f, 1.0f },const float shadowSizeFactor=1);
void DrawDropShadowStringDecal(Font&font, const olc::vf2d& pos, const std::u32string& sText, const Pixel col = olc::WHITE, const Pixel shadowCol = olc::BLACK, const olc::vf2d& scale = { 1.0f, 1.0f });
// Draws a single shaded filled rectangle as a decal
void DrawRectDecal(const olc::vf2d& pos, const olc::vf2d& size, const olc::Pixel col = olc::WHITE);
void FillRectDecal(const olc::vf2d& pos, const olc::vf2d& size, const olc::Pixel col = olc::WHITE);
@ -3394,6 +3395,31 @@ namespace olc
DrawDecal(pos,garbageCollector[key].decal,scale/4,col);
}
void PixelGameEngine::DrawDropShadowStringDecal(Font&font, const olc::vf2d& pos, const std::u32string& sText, const Pixel col, const Pixel shadowCol, const olc::vf2d& scale){
struct DecalData{
Decal*decal;
float expireTime=0.0f;
};
if(sText.length()==0)return;
static std::map<std::u32string,DecalData>garbageCollector;
std::u32string key=font.GetFontName()+U"_"+sText;
if(!garbageCollector.count(key)){ //If the text key already exists, don't have to recreate the decal, just update the expire time.
garbageCollector[key].decal=font.RenderStringToDecal(sText,WHITE);
}
garbageCollector[key].expireTime=GetRuntime()+120.0f;
std::erase_if(garbageCollector,[&](auto&key){
if(key.second.expireTime<GetRuntime()){
delete key.second.decal;
return true;
}
return false;
});
DrawDecal(pos+vf2d{0,0.5f},garbageCollector[key].decal,scale/4,shadowCol);
DrawDecal(pos+vf2d{0.5f,0},garbageCollector[key].decal,scale/4,shadowCol);
DrawDecal(pos+vf2d{0.5f,0.5f},garbageCollector[key].decal,scale/4,shadowCol);
DrawDecal(pos,garbageCollector[key].decal,scale/4,col);
}
void PixelGameEngine::DrawShadowStringPropDecal(const olc::vf2d& pos, const std::string& sText, const Pixel col, const Pixel shadowCol, const olc::vf2d& scale,const float shadowSizeFactor){
for(float y=-shadowSizeFactor;y<=shadowSizeFactor+0.1;y+=shadowSizeFactor/2){
for(float x=-shadowSizeFactor;x<=shadowSizeFactor+0.1;x+=shadowSizeFactor/2){

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.3 MiB

After

Width:  |  Height:  |  Size: 8.9 MiB

File diff suppressed because one or more lines are too long

Binary file not shown.
Loading…
Cancel
Save