Add header text display.

CorrectiveAction
sigonasr2 1 year ago
parent 027ec20449
commit 3a995a7a05
  1. 13
      olcCodeJam2023Entry/Info.txt
  2. 42
      olcCodeJam2023Entry/Textbox.cpp
  3. 3
      olcCodeJam2023Entry/Textbox.h

@ -56,3 +56,16 @@ Stage 2
Stage 3 Stage 3
Stage 4 Stage 4
Stage 5 - Hacking a Network Stage 5 - Hacking a Network
Potential Songs:
1 Pixel
Space - Cosmos (Tutorials?)
Space - Gravity (Ambient 1)
1 Epic Boss Battles (Cut for loop) (Ambient 2)
3 Epic Boss Battles (Cut end for loop) (Ambient 3)
1 Glorious Venture (Ending theme?)

@ -21,8 +21,12 @@ void Textbox::SetDefaults(){
textboxMarker=-1; textboxMarker=-1;
lastWordMarker=-1; lastWordMarker=-1;
lastWord=""; lastWord="";
lastHeaderWordMarker=-1;
lastHeaderWord="";
displayText=""; displayText="";
displayHeaderText="";
text=""; text="";
headerText="";
} }
void Textbox::Update(PixelGameEngine*pge){ void Textbox::Update(PixelGameEngine*pge){
@ -31,21 +35,32 @@ void Textbox::Update(PixelGameEngine*pge){
if(textboxMarker<int(text.length()-1)){ if(textboxMarker<int(text.length()-1)){
std::string tempText=displayText; std::string tempText=displayText;
tempText+=text[textboxMarker+1]; tempText+=text[textboxMarker+1];
if(pge->GetTextSizeProp(tempText).x>=maxSize.x){
displayText=displayText.substr(0,lastWordMarker); auto WrapText=[&](std::string&tempText,std::string&text,std::string&displayText,int&lastWordMarker,std::string&lastWord){
displayText+='\n'; if(pge->GetTextSizeProp(tempText).x>=maxSize.x){
displayText+=lastWord; displayText=displayText.substr(0,lastWordMarker);
} displayText+='\n';
if(text[textboxMarker+1]==' '||text[textboxMarker+1]=='\n'){ displayText+=lastWord;
lastWord=""; }
lastWordMarker=textboxMarker+2; if(text[textboxMarker+1]==' '||text[textboxMarker+1]=='\n'){
} else { lastWord="";
lastWord+=text[textboxMarker+1]; lastWordMarker=textboxMarker+2;
} else {
lastWord+=text[textboxMarker+1];
}
displayText+=text[textboxMarker+1];
};
WrapText(tempText,text,displayText,lastWordMarker,lastWord);
if(textboxMarker<int(headerText.length()-1)){
std::string tempHeaderText=displayHeaderText;
tempHeaderText+=headerText[textboxMarker+1];
WrapText(tempHeaderText,headerText,displayHeaderText,lastHeaderWordMarker,lastHeaderWord);
} }
displayText+=text[textboxMarker+1];
textboxMarker++; textboxMarker++;
maxSize.y=std::max(maxSize.y,float(pge->GetTextSizeProp(tempText).y));
} }
maxSize.y=std::max(maxSize.y,float(pge->GetTextSizeProp(displayHeaderText).y+pge->GetTextSizeProp(displayText).y));
lastLetterTime=letterDisplayDelay; lastLetterTime=letterDisplayDelay;
} }
} }
@ -68,7 +83,8 @@ void Textbox::Draw(PixelGameEngine*pge,Resources&resources){
} }
pge->FillRectDecal(boxRect.pos,maxSize+vf2d{6,6},VERY_DARK_GREEN); pge->FillRectDecal(boxRect.pos,maxSize+vf2d{6,6},VERY_DARK_GREEN);
pge->DrawRectDecal(boxRect.pos+vf2d{1,1},maxSize+vf2d{4,4},WHITE); pge->DrawRectDecal(boxRect.pos+vf2d{1,1},maxSize+vf2d{4,4},WHITE);
pge->DrawShadowStringPropDecal(boxRect.pos+vf2d{3,3},displayText,{220,220,220}); pge->DrawShadowStringPropDecal(boxRect.pos+vf2d{3,3},displayHeaderText,{245, 218, 66});
pge->DrawShadowStringPropDecal(boxRect.pos+vf2d{3.f,float(3+pge->GetTextSizeProp(displayHeaderText).y)},displayText,{220,220,220});
} }
} }

@ -6,6 +6,7 @@
class Textbox{ class Textbox{
std::string headerText=""; //If a textbox has a header, it displays at the top in a special color. std::string headerText=""; //If a textbox has a header, it displays at the top in a special color.
std::string displayHeaderText="";
std::string text=""; std::string text="";
std::string displayText=""; std::string displayText="";
vf2d pos={}; vf2d pos={};
@ -15,6 +16,8 @@ class Textbox{
int textboxMarker=-1; int textboxMarker=-1;
int lastWordMarker=-1; int lastWordMarker=-1;
std::string lastWord=""; std::string lastWord="";
int lastHeaderWordMarker=-1;
std::string lastHeaderWord="";
std::vector<Memory> resourceCost; //If resource cost is greater than 0, shows them. std::vector<Memory> resourceCost; //If resource cost is greater than 0, shows them.
bool visible=true; bool visible=true;
public: public:

Loading…
Cancel
Save