Add header text display.

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

@ -56,3 +56,16 @@ Stage 2
Stage 3
Stage 4
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;
lastWordMarker=-1;
lastWord="";
lastHeaderWordMarker=-1;
lastHeaderWord="";
displayText="";
displayHeaderText="";
text="";
headerText="";
}
void Textbox::Update(PixelGameEngine*pge){
@ -31,6 +35,8 @@ void Textbox::Update(PixelGameEngine*pge){
if(textboxMarker<int(text.length()-1)){
std::string tempText=displayText;
tempText+=text[textboxMarker+1];
auto WrapText=[&](std::string&tempText,std::string&text,std::string&displayText,int&lastWordMarker,std::string&lastWord){
if(pge->GetTextSizeProp(tempText).x>=maxSize.x){
displayText=displayText.substr(0,lastWordMarker);
displayText+='\n';
@ -43,9 +49,18 @@ void Textbox::Update(PixelGameEngine*pge){
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);
}
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;
}
}
@ -68,7 +83,8 @@ void Textbox::Draw(PixelGameEngine*pge,Resources&resources){
}
pge->FillRectDecal(boxRect.pos,maxSize+vf2d{6,6},VERY_DARK_GREEN);
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{
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 displayText="";
vf2d pos={};
@ -15,6 +16,8 @@ class Textbox{
int textboxMarker=-1;
int lastWordMarker=-1;
std::string lastWord="";
int lastHeaderWordMarker=-1;
std::string lastHeaderWord="";
std::vector<Memory> resourceCost; //If resource cost is greater than 0, shows them.
bool visible=true;
public:

Loading…
Cancel
Save