|
|
|
@ -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,21 +35,32 @@ void Textbox::Update(PixelGameEngine*pge){ |
|
|
|
|
if(textboxMarker<int(text.length()-1)){ |
|
|
|
|
std::string tempText=displayText; |
|
|
|
|
tempText+=text[textboxMarker+1]; |
|
|
|
|
if(pge->GetTextSizeProp(tempText).x>=maxSize.x){ |
|
|
|
|
displayText=displayText.substr(0,lastWordMarker); |
|
|
|
|
displayText+='\n'; |
|
|
|
|
displayText+=lastWord; |
|
|
|
|
} |
|
|
|
|
if(text[textboxMarker+1]==' '||text[textboxMarker+1]=='\n'){ |
|
|
|
|
lastWord=""; |
|
|
|
|
lastWordMarker=textboxMarker+2; |
|
|
|
|
} else { |
|
|
|
|
lastWord+=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'; |
|
|
|
|
displayText+=lastWord; |
|
|
|
|
} |
|
|
|
|
if(text[textboxMarker+1]==' '||text[textboxMarker+1]=='\n'){ |
|
|
|
|
lastWord=""; |
|
|
|
|
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++; |
|
|
|
|
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}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|