generated from sigonasr2/CPlusPlusProjectTemplate
Message box display with wrapping now working correctly.
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
f8f626f04f
commit
e9b1aee4f3
@ -144,10 +144,16 @@ public:
|
||||
DOME_DECAL=new olc::Decal(new olc::Sprite("assets/dome.png"));
|
||||
BASE_OBJECTS["DOME"]=DOME_DECAL;
|
||||
LoadMap("assets/maps/map1");
|
||||
DisplayMessageBox(7);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GetAnyKey() override {
|
||||
void GetAnyKeyPress() override {
|
||||
if (messageBoxVisible) {
|
||||
while (messageBoxCursor<messageBoxRefText.length()) {
|
||||
advanceMessageBox();
|
||||
}
|
||||
}
|
||||
switch (GAME_STATE) {
|
||||
case CUTSCENE_1:{
|
||||
if (textInd>=STORY_TEXT1.length()) {
|
||||
@ -155,7 +161,6 @@ public:
|
||||
}
|
||||
}break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OnUserUpdate(float fElapsedTime) override
|
||||
@ -234,37 +239,10 @@ public:
|
||||
if (messageBoxVisible) {
|
||||
if (frameCount%MESSAGE_SCROLL_WAIT_SPD==0) {
|
||||
if (messageBoxCursor<messageBoxRefText.length()) {
|
||||
char c = messageBoxRefText[messageBoxCursor++];
|
||||
printf("%c",c);
|
||||
if (c=='\n') {
|
||||
if (!firstNewline) {
|
||||
firstNewline=true;
|
||||
goto next;
|
||||
} else if (!secondNewline) {
|
||||
secondNewline=true;
|
||||
goto next;
|
||||
}
|
||||
}
|
||||
if (firstNewline&&!secondNewline) {
|
||||
messageBoxSpeaker+=c;
|
||||
goto next;
|
||||
}
|
||||
messageBoxText+=c;
|
||||
if (GetTextSizeProp(messageBoxText).x>WIDTH-16) {
|
||||
int tempIndex=messageBoxCursor;
|
||||
while (messageBoxText[--tempIndex]!=' ') {
|
||||
messageBoxText.erase(tempIndex);
|
||||
}
|
||||
messageBoxText.erase(tempIndex++);
|
||||
messageBoxText+='\n';
|
||||
while (tempIndex<messageBoxCursor) {
|
||||
messageBoxText+=messageBoxRefText[tempIndex++];
|
||||
advanceMessageBox();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
next:
|
||||
if (GetKey(olc::F1).bPressed) {
|
||||
}
|
||||
|
||||
@ -354,6 +332,36 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void advanceMessageBox() {
|
||||
char c = messageBoxRefText[messageBoxCursor++];
|
||||
printf("%c",c);
|
||||
if (c=='\n') {
|
||||
if (!firstNewline) {
|
||||
firstNewline=true;
|
||||
return;
|
||||
} else if (!secondNewline) {
|
||||
secondNewline=true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (firstNewline&&!secondNewline) {
|
||||
messageBoxSpeaker+=c;
|
||||
return;
|
||||
}
|
||||
messageBoxText+=c;
|
||||
if (GetTextSizeProp(messageBoxText).x>WIDTH-16) {
|
||||
int tempIndex=messageBoxCursor;
|
||||
while (messageBoxText[--tempIndex]!=' ') {
|
||||
messageBoxText.erase(tempIndex);
|
||||
}
|
||||
messageBoxText.erase(tempIndex++);
|
||||
messageBoxText+='\n';
|
||||
while (tempIndex<messageBoxCursor) {
|
||||
messageBoxText+=messageBoxRefText[tempIndex++];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void drawGame(){
|
||||
switch (GAME_STATE) {
|
||||
case CUTSCENE_1:{
|
||||
@ -385,11 +393,12 @@ public:
|
||||
GradientFillRectDecal({WIDTH/2,HEIGHT/2},{WIDTH/2,HEIGHT/2},{100, 10, 255,ALPHA_SCREEN2},{100, 10, 255,ALPHA_SCREEN1},{100, 10, 255,ALPHA_SCREEN1},{100, 10, 255,ALPHA_SCREEN1});
|
||||
}break;
|
||||
}
|
||||
if (messageBoxVisible) {
|
||||
DrawDialogBox({4,HEIGHT-60},{WIDTH/3,16},olc::Pixel(18, 0, 33,180));
|
||||
DrawDialogBox({0,HEIGHT-48},{WIDTH,48},olc::Pixel(18, 0, 33,180));
|
||||
DrawStringPropDecal({8,HEIGHT-40},messageBoxText);
|
||||
DrawStringPropDecal({8,HEIGHT-57},messageBoxSpeaker);
|
||||
if (messageBoxCursor==messageBoxRefText.length()) {
|
||||
DrawStringPropDecal({WIDTH-16-sin(frameCount*8/60.0)*3,HEIGHT-8+cos(frameCount*6/60.0)*0.6},"v",olc::Pixel(173, 74, 255,(0.5*sin(frameCount*8/60.0)+0.5)*128+128),{sin(frameCount*8/60.0),0.5});
|
||||
}
|
||||
FillRectDecal({0,0},{WIDTH,HEIGHT},olc::Pixel(0,0,0,transparency));
|
||||
}
|
||||
@ -427,9 +436,12 @@ public:
|
||||
void DisplayMessageBox(int dialogNumber) {
|
||||
messageBoxVisible=true;
|
||||
messageBoxCursor=0;
|
||||
messageBoxSpeaker="";
|
||||
std::string split1=STORY_DIALOG[dialogNumber].substr(0,STORY_DIALOG[dialogNumber].find('\n')); //Unused for now.
|
||||
std::string split2=STORY_DIALOG[dialogNumber].substr(STORY_DIALOG[dialogNumber].find('\n')+1,STORY_DIALOG[dialogNumber].find('\n',STORY_DIALOG[dialogNumber].find('\n')+1)-(STORY_DIALOG[dialogNumber].find('\n')+1));
|
||||
std::string split3=STORY_DIALOG[dialogNumber].substr(STORY_DIALOG[dialogNumber].find('\n',STORY_DIALOG[dialogNumber].find('\n')+1)+1,STORY_DIALOG[dialogNumber].length()-(STORY_DIALOG[dialogNumber].find('\n',STORY_DIALOG[dialogNumber].find('\n')+1)+1));
|
||||
messageBoxSpeaker=split2;
|
||||
messageBoxText="";
|
||||
messageBoxRefText=STORY_DIALOG[dialogNumber];
|
||||
messageBoxRefText=split3;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Binary file not shown.
@ -928,7 +928,8 @@ namespace olc
|
||||
virtual bool OnUserUpdate(float fElapsedTime);
|
||||
// Called once on application termination, so you can be one clean coder
|
||||
virtual bool OnUserDestroy();
|
||||
virtual bool GetAnyKey();
|
||||
virtual void GetAnyKey();
|
||||
virtual void GetAnyKeyPress();
|
||||
|
||||
// Called when a text entry is confirmed with "enter" key
|
||||
virtual void OnTextEntryComplete(const std::string& sText);
|
||||
@ -3291,8 +3292,8 @@ namespace olc
|
||||
bool PixelGameEngine::OnUserDestroy()
|
||||
{ return true; }
|
||||
|
||||
bool PixelGameEngine::GetAnyKey()
|
||||
{ return false; }
|
||||
void PixelGameEngine::GetAnyKey(){};
|
||||
void PixelGameEngine::GetAnyKeyPress(){};
|
||||
|
||||
void PixelGameEngine::OnTextEntryComplete(const std::string& sText) { UNUSED(sText); }
|
||||
bool PixelGameEngine::OnConsoleCommand(const std::string& sCommand) { UNUSED(sCommand); return false; }
|
||||
@ -3449,6 +3450,7 @@ namespace olc
|
||||
{
|
||||
if (pStateNew[i])
|
||||
{
|
||||
GetAnyKeyPress();
|
||||
pKeys[i].bPressed = !pKeys[i].bHeld;
|
||||
pKeys[i].bHeld = true;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user