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"));
|
DOME_DECAL=new olc::Decal(new olc::Sprite("assets/dome.png"));
|
||||||
BASE_OBJECTS["DOME"]=DOME_DECAL;
|
BASE_OBJECTS["DOME"]=DOME_DECAL;
|
||||||
LoadMap("assets/maps/map1");
|
LoadMap("assets/maps/map1");
|
||||||
|
DisplayMessageBox(7);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GetAnyKey() override {
|
void GetAnyKeyPress() override {
|
||||||
|
if (messageBoxVisible) {
|
||||||
|
while (messageBoxCursor<messageBoxRefText.length()) {
|
||||||
|
advanceMessageBox();
|
||||||
|
}
|
||||||
|
}
|
||||||
switch (GAME_STATE) {
|
switch (GAME_STATE) {
|
||||||
case CUTSCENE_1:{
|
case CUTSCENE_1:{
|
||||||
if (textInd>=STORY_TEXT1.length()) {
|
if (textInd>=STORY_TEXT1.length()) {
|
||||||
@ -155,7 +161,6 @@ public:
|
|||||||
}
|
}
|
||||||
}break;
|
}break;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OnUserUpdate(float fElapsedTime) override
|
bool OnUserUpdate(float fElapsedTime) override
|
||||||
@ -234,37 +239,10 @@ public:
|
|||||||
if (messageBoxVisible) {
|
if (messageBoxVisible) {
|
||||||
if (frameCount%MESSAGE_SCROLL_WAIT_SPD==0) {
|
if (frameCount%MESSAGE_SCROLL_WAIT_SPD==0) {
|
||||||
if (messageBoxCursor<messageBoxRefText.length()) {
|
if (messageBoxCursor<messageBoxRefText.length()) {
|
||||||
char c = messageBoxRefText[messageBoxCursor++];
|
advanceMessageBox();
|
||||||
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++];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
next:
|
|
||||||
if (GetKey(olc::F1).bPressed) {
|
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(){
|
void drawGame(){
|
||||||
switch (GAME_STATE) {
|
switch (GAME_STATE) {
|
||||||
case CUTSCENE_1:{
|
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});
|
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;
|
}break;
|
||||||
}
|
}
|
||||||
if (messageBoxVisible) {
|
DrawDialogBox({4,HEIGHT-60},{WIDTH/3,16},olc::Pixel(18, 0, 33,180));
|
||||||
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));
|
||||||
DrawDialogBox({0,HEIGHT-48},{WIDTH,48},olc::Pixel(18, 0, 33,180));
|
DrawStringPropDecal({8,HEIGHT-40},messageBoxText);
|
||||||
DrawStringPropDecal({8,HEIGHT-40},messageBoxText);
|
DrawStringPropDecal({8,HEIGHT-57},messageBoxSpeaker);
|
||||||
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));
|
FillRectDecal({0,0},{WIDTH,HEIGHT},olc::Pixel(0,0,0,transparency));
|
||||||
}
|
}
|
||||||
@ -427,9 +436,12 @@ public:
|
|||||||
void DisplayMessageBox(int dialogNumber) {
|
void DisplayMessageBox(int dialogNumber) {
|
||||||
messageBoxVisible=true;
|
messageBoxVisible=true;
|
||||||
messageBoxCursor=0;
|
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="";
|
messageBoxText="";
|
||||||
messageBoxRefText=STORY_DIALOG[dialogNumber];
|
messageBoxRefText=split3;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
@ -928,7 +928,8 @@ namespace olc
|
|||||||
virtual bool OnUserUpdate(float fElapsedTime);
|
virtual bool OnUserUpdate(float fElapsedTime);
|
||||||
// Called once on application termination, so you can be one clean coder
|
// Called once on application termination, so you can be one clean coder
|
||||||
virtual bool OnUserDestroy();
|
virtual bool OnUserDestroy();
|
||||||
virtual bool GetAnyKey();
|
virtual void GetAnyKey();
|
||||||
|
virtual void GetAnyKeyPress();
|
||||||
|
|
||||||
// Called when a text entry is confirmed with "enter" key
|
// Called when a text entry is confirmed with "enter" key
|
||||||
virtual void OnTextEntryComplete(const std::string& sText);
|
virtual void OnTextEntryComplete(const std::string& sText);
|
||||||
@ -3291,8 +3292,8 @@ namespace olc
|
|||||||
bool PixelGameEngine::OnUserDestroy()
|
bool PixelGameEngine::OnUserDestroy()
|
||||||
{ return true; }
|
{ return true; }
|
||||||
|
|
||||||
bool PixelGameEngine::GetAnyKey()
|
void PixelGameEngine::GetAnyKey(){};
|
||||||
{ return false; }
|
void PixelGameEngine::GetAnyKeyPress(){};
|
||||||
|
|
||||||
void PixelGameEngine::OnTextEntryComplete(const std::string& sText) { UNUSED(sText); }
|
void PixelGameEngine::OnTextEntryComplete(const std::string& sText) { UNUSED(sText); }
|
||||||
bool PixelGameEngine::OnConsoleCommand(const std::string& sCommand) { UNUSED(sCommand); return false; }
|
bool PixelGameEngine::OnConsoleCommand(const std::string& sCommand) { UNUSED(sCommand); return false; }
|
||||||
@ -3449,6 +3450,7 @@ namespace olc
|
|||||||
{
|
{
|
||||||
if (pStateNew[i])
|
if (pStateNew[i])
|
||||||
{
|
{
|
||||||
|
GetAnyKeyPress();
|
||||||
pKeys[i].bPressed = !pKeys[i].bHeld;
|
pKeys[i].bPressed = !pKeys[i].bHeld;
|
||||||
pKeys[i].bHeld = true;
|
pKeys[i].bHeld = true;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user