Prep choice dialog text messages

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2 2 years ago
parent 7361111292
commit 4483444dd9
  1. BIN
      C++ProjectTemplate
  2. 103
      main.cpp
  3. 2
      object.h

Binary file not shown.

@ -166,9 +166,13 @@ int EQUIP_ITEM_MENU_CURSOR=0;
int EQUIP_ITEM_MENU_OFFSET=0; int EQUIP_ITEM_MENU_OFFSET=0;
std::vector<int> EQUIP_ITEM_MENU_CONTENTS={}; std::vector<int> EQUIP_ITEM_MENU_CONTENTS={};
std::vector<std::pair<Item*,int>> SHOP_MENU_CONTENTS={}; std::vector<std::pair<Item*,int>> SHOP_MENU_CONTENTS={};
std::array<int,16> MESSAGE_BOX_DIALOG_ANSWERS={}; std::array<int,16> MESSAGE_BOX_DIALOG_ANSWERS={-1};
std::array<std::string,3> MESSAGE_BOX_CHOICE_LIST={"","",""}; int MESSAGE_BOX_DIALOG_CHOICES_MADE=0;
std::vector<std::string> MESSAGE_BOX_CHOICE_LIST={};
bool waitingForChoice=false; bool waitingForChoice=false;
int MESSAGE_BOX_DIALOG_CHOICE_CURSOR=0;
bool insideChoice=false;
bool selectionMade=false;
/* /*
[Choice1,Choice2,Choice3] [Choice1,Choice2,Choice3]
@ -188,6 +192,10 @@ void DisplayMessageBox(std::string targetT) {
messageBoxMarker=0; messageBoxMarker=0;
messageBoxStartMarker=0; messageBoxStartMarker=0;
messageBoxStopMarker=0; messageBoxStopMarker=0;
for (int i=0;i<MESSAGE_BOX_DIALOG_ANSWERS.size();i++) {
MESSAGE_BOX_DIALOG_ANSWERS[i]=-1;
}
MESSAGE_BOX_DIALOG_CHOICES_MADE=0;
} }
bool MOUSE_PRESSED_DOWN=false,MOUSE_DOWN=false,MOUSE_RELEASED=false; //TODO Implement Mouse things. bool MOUSE_PRESSED_DOWN=false,MOUSE_DOWN=false,MOUSE_RELEASED=false; //TODO Implement Mouse things.
@ -369,7 +377,7 @@ This is a test message that lets us trigger straight from a cutscene! Cool!)"),
lastPress=frameCount; lastPress=frameCount;
lastRepeatedFrame=frameCount; lastRepeatedFrame=frameCount;
} }
if (messageBoxVisible) { if (messageBoxVisible&&!waitingForChoice) {
if (messageBoxMarker==messageBoxFinalText.length()) { if (messageBoxMarker==messageBoxFinalText.length()) {
if (messageBoxStartMarker+messageBoxStopMarker<targetText.length()) { if (messageBoxStartMarker+messageBoxStopMarker<targetText.length()) {
messageBoxStartMarker+=messageBoxStopMarker; messageBoxStartMarker+=messageBoxStopMarker;
@ -378,6 +386,7 @@ This is a test message that lets us trigger straight from a cutscene! Cool!)"),
messageBoxText=""; messageBoxText="";
messageBoxMarker=0; messageBoxMarker=0;
messageBoxLoad=true; messageBoxLoad=true;
printf("Called 2\n");
} else { } else {
messageBoxVisible=false; messageBoxVisible=false;
if (CLOSE_OVERWORLD_WINDOW&&INTERACTION_MESSAGES.size()==0) { if (CLOSE_OVERWORLD_WINDOW&&INTERACTION_MESSAGES.size()==0) {
@ -399,6 +408,7 @@ This is a test message that lets us trigger straight from a cutscene! Cool!)"),
target->AddHP(healAmt); target->AddHP(healAmt);
targetText+=target->obj->name+" recovered "+std::to_string(healAmt)+" hitpoints.\n"; targetText+=target->obj->name+" recovered "+std::to_string(healAmt)+" hitpoints.\n";
messageBoxLoad=true; messageBoxLoad=true;
printf("Called 3\n");
messageBoxVisible=true; messageBoxVisible=true;
HEALING_OVERWORLD_MEMBER++; HEALING_OVERWORLD_MEMBER++;
break; break;
@ -424,13 +434,14 @@ This is a test message that lets us trigger straight from a cutscene! Cool!)"),
targetText+="But it failed."; targetText+="But it failed.";
} }
messageBoxLoad=true; messageBoxLoad=true;
printf("Called 4\n");
messageBoxVisible=true; messageBoxVisible=true;
HEALING_OVERWORLD_SINGLE_MEMBER=false; HEALING_OVERWORLD_SINGLE_MEMBER=false;
castingMember->selectedMove=nullptr; castingMember->selectedMove=nullptr;
} }
} }
} else { } else {
while (messageBoxMarker<messageBoxFinalText.length()&&!waitingForChoice) { while (MessageBoxAllowedToAdvance()) {
AdvanceMessageBox(); AdvanceMessageBox();
} }
} }
@ -665,9 +676,10 @@ This is a test message that lets us trigger straight from a cutscene! Cool!)"),
std::string lastLine=""; std::string lastLine="";
while (messageBoxStartMarker+messageBoxStopMarker<targetText.length()&&GetTextSizeProp(messageBoxFinalText).y<HEIGHT/4-MESSAGE_BORDER_Y) { while (messageBoxStartMarker+messageBoxStopMarker<targetText.length()&&GetTextSizeProp(messageBoxFinalText).y<HEIGHT/4-MESSAGE_BORDER_Y) {
if (targetText[messageBoxStopMarker+messageBoxStartMarker]=='[') { if (targetText[messageBoxStopMarker+messageBoxStartMarker]=='[') {
while (targetText[messageBoxStopMarker+messageBoxStartMarker]!=']') { while (targetText[messageBoxStopMarker+messageBoxStartMarker]!='<') {
messageBoxFinalText+=targetText[messageBoxStopMarker+++messageBoxStartMarker]; messageBoxFinalText+=targetText[messageBoxStopMarker+++messageBoxStartMarker];
} }
messageBoxFinalText+=targetText[messageBoxStopMarker+++messageBoxStartMarker];
break; break;
} }
while (messageBoxStartMarker+messageBoxStopMarker<targetText.length()&&GetTextSizeProp(messageBoxFinalText).x<WIDTH/2-MESSAGE_BORDER_X) { while (messageBoxStartMarker+messageBoxStopMarker<targetText.length()&&GetTextSizeProp(messageBoxFinalText).x<WIDTH/2-MESSAGE_BORDER_X) {
@ -691,27 +703,55 @@ This is a test message that lets us trigger straight from a cutscene! Cool!)"),
} }
} }
messageBoxLoad=false; messageBoxLoad=false;
for (int i=0;i<16;i++) {
MESSAGE_BOX_DIALOG_ANSWERS[i]=-1;
}
MESSAGE_BOX_DIALOG_CHOICES_MADE=0;
} else { } else {
if (messageBoxMarker<messageBoxFinalText.length()) { if (MessageBoxAllowedToAdvance()) {
printf("In here: %c\n",messageBoxFinalText[messageBoxMarker]);
if (messageBoxFinalText[messageBoxMarker]=='[') { if (messageBoxFinalText[messageBoxMarker]=='[') {
messageBoxMarker++; messageBoxMarker++;
waitingForChoice=true; waitingForChoice=true;
MESSAGE_BOX_CHOICE_LIST={"","",""}; MESSAGE_BOX_CHOICE_LIST.clear();
int counter=0; std::string newMessageBoxChoice="";
while (messageBoxFinalText[messageBoxMarker]!=']') { while (messageBoxFinalText[messageBoxMarker]!=']') {
if (messageBoxFinalText[messageBoxMarker]==',') { if (messageBoxFinalText[messageBoxMarker]==',') {
counter++; MESSAGE_BOX_CHOICE_LIST.push_back(newMessageBoxChoice);
newMessageBoxChoice="";
messageBoxMarker++; messageBoxMarker++;
} } else
if (messageBoxFinalText[messageBoxMarker]!=']') { {
MESSAGE_BOX_CHOICE_LIST[counter]+=messageBoxFinalText[messageBoxMarker++]; newMessageBoxChoice+=messageBoxFinalText[messageBoxMarker++];
} }
} }
MESSAGE_BOX_CHOICE_LIST.push_back(newMessageBoxChoice);
newMessageBoxChoice="";
for (int i=0;i<MESSAGE_BOX_CHOICE_LIST.size();i++) { for (int i=0;i<MESSAGE_BOX_CHOICE_LIST.size();i++) {
printf("%s\n",MESSAGE_BOX_CHOICE_LIST[i].c_str()); printf("%s\n",MESSAGE_BOX_CHOICE_LIST[i].c_str());
} }
} else { MESSAGE_BOX_DIALOG_CHOICE_CURSOR=0;
messageBoxText+=messageBoxFinalText[messageBoxMarker++]; messageBoxMarker++;
} else
if (messageBoxFinalText[messageBoxMarker]=='>') {
messageBoxMarker++;
int counter=0;
if (messageBoxFinalText[messageBoxMarker]-'0'==MESSAGE_BOX_DIALOG_CHOICE_CURSOR) {
messageBoxMarker+=2;
insideChoice=true;
} else {
while(messageBoxFinalText[messageBoxMarker]!='>'&&messageBoxFinalText[messageBoxMarker]!='<') {
messageBoxMarker++;
}
}
} else
if (!waitingForChoice){
if (!insideChoice||insideChoice&&messageBoxFinalText[messageBoxMarker]!='<'&&messageBoxFinalText[messageBoxMarker]!='>') {
messageBoxText+=messageBoxFinalText[messageBoxMarker++];
} else
if (messageBoxFinalText[messageBoxMarker]=='<') {
messageBoxMarker++;
}
} }
} }
} }
@ -763,6 +803,29 @@ This is a test message that lets us trigger straight from a cutscene! Cool!)"),
KEY_LASTPRESSED=NONE; KEY_LASTPRESSED=NONE;
} }
if (waitingForChoice) {
if (UpPressed()) {
MESSAGE_BOX_DIALOG_CHOICE_CURSOR--;
if (MESSAGE_BOX_DIALOG_CHOICE_CURSOR<0) {
MESSAGE_BOX_DIALOG_CHOICE_CURSOR=MESSAGE_BOX_CHOICE_LIST.size()-1;
}
if (MESSAGE_BOX_DIALOG_CHOICE_CURSOR==0) {
KEY_LASTPRESSED=NONE;
}
}
if (DownPressed()) {
MESSAGE_BOX_DIALOG_CHOICE_CURSOR=(MESSAGE_BOX_DIALOG_CHOICE_CURSOR+1)%MESSAGE_BOX_CHOICE_LIST.size();
if (MESSAGE_BOX_DIALOG_CHOICE_CURSOR==MESSAGE_BOX_CHOICE_LIST.size()-1) {
KEY_LASTPRESSED=NONE;
}
}
if (ACTIONKEYPRESSED) {
MESSAGE_BOX_DIALOG_ANSWERS[MESSAGE_BOX_DIALOG_CHOICES_MADE++]=MESSAGE_BOX_DIALOG_CHOICE_CURSOR;
waitingForChoice=false;
}
goto reset;
}
if (BATTLE_ENCOUNTER!=nullptr&&!messageBoxVisible) { if (BATTLE_ENCOUNTER!=nullptr&&!messageBoxVisible) {
switch (BATTLE_STATE) { switch (BATTLE_STATE) {
case BattleState::SELECT_ACTION:{ case BattleState::SELECT_ACTION:{
@ -1727,6 +1790,7 @@ This is a test message that lets us trigger straight from a cutscene! Cool!)"),
} }
}break; }break;
} }
reset:
ANYKEYPRESSED=ACTIONKEYPRESSED=false; ANYKEYPRESSED=ACTIONKEYPRESSED=false;
if (KEY_LASTPRESSED!=NONE) { if (KEY_LASTPRESSED!=NONE) {
lastRepeatedFrame=frameCount; lastRepeatedFrame=frameCount;
@ -2249,6 +2313,13 @@ This is a test message that lets us trigger straight from a cutscene! Cool!)"),
if (messageBoxVisible) { if (messageBoxVisible) {
DrawDialogBox({1,1},{WIDTH/2,HEIGHT/4},Pixel(70, 33, 105,220),Pixel(62, 54, 69,220),Pixel(185, 148, 255,220)); DrawDialogBox({1,1},{WIDTH/2,HEIGHT/4},Pixel(70, 33, 105,220),Pixel(62, 54, 69,220),Pixel(185, 148, 255,220));
DrawStringPropDecal({6,6},messageBoxText); DrawStringPropDecal({6,6},messageBoxText);
if (waitingForChoice) {
DrawDialogBox({1,1+HEIGHT/4},{WIDTH/3,(int)MESSAGE_BOX_CHOICE_LIST.size()*12+4},Pixel(70, 33, 105,220),Pixel(62, 54, 69,220),Pixel(185, 148, 255,220));
for (int i=0;i<MESSAGE_BOX_CHOICE_LIST.size();i++) {
DrawStringPropDecal({13,(float)(1+HEIGHT/4+4+i*12)},MESSAGE_BOX_CHOICE_LIST[i]);
}
DrawDecal({5,(float)(1+HEIGHT/4+MESSAGE_BOX_DIALOG_CHOICE_CURSOR*12+4)},SPRITES["cursor.png"]);
}
} }
for (int i=0;i<PARTICLES.size();i++) { for (int i=0;i<PARTICLES.size();i++) {
PARTICLES[i]->render(this); PARTICLES[i]->render(this);
@ -4676,6 +4747,10 @@ This is a test message that lets us trigger straight from a cutscene! Cool!)"),
} }
return 1; return 1;
} }
bool MessageBoxAllowedToAdvance() {
return messageBoxMarker<messageBoxFinalText.length()&&!waitingForChoice;
}
}; };
int main() int main()

@ -183,7 +183,7 @@ class TrashCan_Obj : public Object{
class Shopkeeper_Obj : public Object{ class Shopkeeper_Obj : public Object{
DynamicObject(Shopkeeper_Obj) DynamicObject(Shopkeeper_Obj)
std::vector<std::pair<Item*,int>> itemList; std::vector<std::pair<Item*,int>> itemList;
std::string welcomeMessage="Welcome! Please choose an option: [BUY,SELL]"; std::string welcomeMessage="Welcome! Please choose an option: [BUY,SELL]>0:Please take a look through our wares.>1:What would you like to sell?<";
Interaction Interact()override{ Interaction Interact()override{
return {{welcomeMessage}}; return {{welcomeMessage}};
} }

Loading…
Cancel
Save