Syntax for dialog options in message boxes

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2 2 years ago
parent 948e8600a6
commit 7361111292
  1. BIN
      C++ProjectTemplate
  2. 3
      assets/maps/map0
  3. 67
      main.cpp
  4. 261
      object.h
  5. 2
      references.h
  6. 2
      states.h

Binary file not shown.

@ -80,7 +80,8 @@ OBJECT256.000000;256.000000;8
OBJECT224.000000;256.000000;8
OBJECT192.000000;256.000000;8
OBJECT160.000000;256.000000;8
OBJECT322.000000;255.000000;0
OBJECT512.000000;288.000000;158
OBJECT333.000000;286.000000;0
OBJECT256.000000;288.000000;90
OBJECT128.000000;288.000000;90
OBJECT192.000000;320.000000;90

@ -165,6 +165,30 @@ EquipSlot::Equip EQUIP_MENU_SLOT=EquipSlot::WEAPON;
int EQUIP_ITEM_MENU_CURSOR=0;
int EQUIP_ITEM_MENU_OFFSET=0;
std::vector<int> EQUIP_ITEM_MENU_CONTENTS={};
std::vector<std::pair<Item*,int>> SHOP_MENU_CONTENTS={};
std::array<int,16> MESSAGE_BOX_DIALOG_ANSWERS={};
std::array<std::string,3> MESSAGE_BOX_CHOICE_LIST={"","",""};
bool waitingForChoice=false;
/*
[Choice1,Choice2,Choice3]
After a choice, dialog parser will jump to appropriate branch labeled as:
0: Stuff
1: Stuff
2: Stuff
In addition, each branch will store its choice selector in an incrementing variable.
*/
void DisplayMessageBox(std::string targetT) {
targetText=targetT;
messageBoxText="";
messageBoxFinalText="";
messageBoxLoad=true;
messageBoxVisible=true;
messageBoxMarker=0;
messageBoxStartMarker=0;
messageBoxStopMarker=0;
}
bool MOUSE_PRESSED_DOWN=false,MOUSE_DOWN=false,MOUSE_RELEASED=false; //TODO Implement Mouse things.
@ -406,7 +430,7 @@ This is a test message that lets us trigger straight from a cutscene! Cool!)"),
}
}
} else {
while (messageBoxMarker<messageBoxFinalText.length()) {
while (messageBoxMarker<messageBoxFinalText.length()&&!waitingForChoice) {
AdvanceMessageBox();
}
}
@ -638,7 +662,14 @@ This is a test message that lets us trigger straight from a cutscene! Cool!)"),
const int MESSAGE_BORDER_X=4;
const int MESSAGE_BORDER_Y=4;
bool charsWritten=false;
std::string lastLine="";
while (messageBoxStartMarker+messageBoxStopMarker<targetText.length()&&GetTextSizeProp(messageBoxFinalText).y<HEIGHT/4-MESSAGE_BORDER_Y) {
if (targetText[messageBoxStopMarker+messageBoxStartMarker]=='[') {
while (targetText[messageBoxStopMarker+messageBoxStartMarker]!=']') {
messageBoxFinalText+=targetText[messageBoxStopMarker+++messageBoxStartMarker];
}
break;
}
while (messageBoxStartMarker+messageBoxStopMarker<targetText.length()&&GetTextSizeProp(messageBoxFinalText).x<WIDTH/2-MESSAGE_BORDER_X) {
if (!charsWritten&&targetText[messageBoxStopMarker+messageBoxStartMarker]!=' ') {
messageBoxFinalText+=targetText[messageBoxStopMarker+++messageBoxStartMarker];
@ -662,7 +693,26 @@ This is a test message that lets us trigger straight from a cutscene! Cool!)"),
messageBoxLoad=false;
} else {
if (messageBoxMarker<messageBoxFinalText.length()) {
messageBoxText+=messageBoxFinalText[messageBoxMarker++];
if (messageBoxFinalText[messageBoxMarker]=='[') {
messageBoxMarker++;
waitingForChoice=true;
MESSAGE_BOX_CHOICE_LIST={"","",""};
int counter=0;
while (messageBoxFinalText[messageBoxMarker]!=']') {
if (messageBoxFinalText[messageBoxMarker]==',') {
counter++;
messageBoxMarker++;
}
if (messageBoxFinalText[messageBoxMarker]!=']') {
MESSAGE_BOX_CHOICE_LIST[counter]+=messageBoxFinalText[messageBoxMarker++];
}
}
for (int i=0;i<MESSAGE_BOX_CHOICE_LIST.size();i++) {
printf("%s\n",MESSAGE_BOX_CHOICE_LIST[i].c_str());
}
} else {
messageBoxText+=messageBoxFinalText[messageBoxMarker++];
}
}
}
}
@ -2817,7 +2867,7 @@ This is a test message that lets us trigger straight from a cutscene! Cool!)"),
CreateObjectInfo(new Standard_Obj(NPC16_8,"npc17_8",{0,0},nullptr,{2,2},BLUE,20),"player.png",32,Flag::NONE,Flag::NONE);
CreateObjectInfo(new Standard_Obj(NPC17_8,"npc18_8",{0,0},nullptr,{2,2},BLUE,20),"player.png",32,Flag::NONE,Flag::NONE);
CreateObjectInfo(new Standard_Obj(NPC18_8,"npc19_8",{0,0},nullptr,{2,2},BLUE,20),"player.png",32,Flag::NONE,Flag::NONE);
CreateObjectInfo(new Standard_Obj(NPC19_8,"npc20_8",{0,0},nullptr,{2,2},BLUE,20),"player.png",32,Flag::NONE,Flag::NONE);
CreateObjectInfo(new Shopkeeper_Obj(SHOPKEEPER,"Shopkeeper",{0,0},nullptr,{1,1},YELLOW,20),"player.png",32,Flag::NONE,Flag::NONE);
CreateObjectInfo(new TrashCan_Obj(TRASH_CAN,"trashCan",{0,0},nullptr,{1,1},WHITE,0),"trashcan.png",32,Flag::NONE,Flag::NONE);
}
@ -3043,17 +3093,6 @@ This is a test message that lets us trigger straight from a cutscene! Cool!)"),
return GAME_STATE==GameState::GAME_WORLD&&BATTLE_ENCOUNTER==nullptr&&!IsTextEntryEnabled()&&!messageBoxVisible&&PARTY_MEMBER_OBJ[0]!=nullptr&&CurrentCutscene==nullptr;
}
void DisplayMessageBox(std::string targetT) {
targetText=targetT;
messageBoxText="";
messageBoxFinalText="";
messageBoxLoad=true;
messageBoxVisible=true;
messageBoxMarker=0;
messageBoxStartMarker=0;
messageBoxStopMarker=0;
}
void DrawDialogBox(const vi2d &pos, const vi2d &size, Pixel p = WHITE, Pixel p2 = DARK_GREY, Pixel p3 = VERY_DARK_GREY) {
DrawDecal({(float)pos.x,(float)pos.y},SPRITES["pixel.png"],size,p2);
DrawDecal({(float)pos.x+1,(float)pos.y+1},SPRITES["pixel.png"],{(float)size.x-2,(float)size.y-2},p);

@ -16,147 +16,147 @@ struct Interaction{
class Object{
private:
vd2d scale={1,1};
vd2d pos;
vd2d scale={1,1};
vd2d pos;
public:
int id;
Animation*spr;
int frameIndex=0;
int frameCount=0;
int animationSpd=12; //How many frames to wait between each frame. Setting to 0 pauses the animation.
std::string name;
Pixel color=WHITE;
vd2d originPoint={0,0};
bool drawn=false;
Flag disableFlag=Flag::NONE;
Flag enableFlag=Flag::NONE;
int objArrElement; //Which element in the object array this object is located in. For sorting purposes.
bool temp=false; //If set to true, it's marked for deletion after cutscene handling.
bool enc=false; //If set to true, it's not included in the main list of entities for map saving because it's from an encounter.
bool dead=false; //If set to true, this object was properly part of an Entity and got declared as dead.
int blinkFrames=0; //Frame count of how much time is left for the image to be blinking. Used when enemies take damage.
//animationSpd is how long to wait before switching frames.
bool highlighted=false; //Whether or not this object has been declared as highlighted by a target range selector.
bool Collision(vd2d pos) {
GAME->SetDrawTarget(layer::COLLISION);
Pixel collisionData = GAME->GetDrawTarget()->GetPixel((int)pos.x-cameraPos.x,(int)pos.y-cameraPos.y);
return collisionData!=MAGENTA;
}
//A grid version of the constructor. used ONLY for battle setups.
Object(int id,std::string name,int gridx,int gridy,Animation*spr,vd2d scale={1,1},Pixel color=WHITE,int animationSpd=1,bool temp=false)
:Object(id,name,{gridx*32-(spr->width*0.5)*(scale.x-1),gridy*32-(spr->spr->sprite->height-4)*(scale.y-1)},spr,scale,color,animationSpd,temp) {}
Object(int id,std::string name,vd2d pos,Animation*spr,vd2d scale={1,1},Pixel color=WHITE,int animationSpd=1,bool temp=false) {
this->spr=spr;
this->pos=pos;
this->id=id;
this->name=name;
this->color=color;
this->animationSpd=animationSpd;
SetScale(scale);
this->temp=temp;
}
virtual Object* CreateType(int id,std::string name,vd2d pos,Animation*spr,vd2d scale={1,1},Pixel color=WHITE,int animationSpd=1,bool temp=false)=0;
//When the player tries to interact with this object.
virtual Interaction Interact()=0;
void SetScale(vd2d scale) {
this->scale=scale;
if (spr!=nullptr) {
this->originPoint={spr->width/2*scale.x,(spr->spr->sprite->height-4)*scale.y};
}
}
vd2d GetScale() {
return scale;
}
vd2d GetPos() {
return pos;
}
void Move(vd2d move);
void SetPos(vd2d pos) {
Move(pos-this->pos);
int id;
Animation*spr;
int frameIndex=0;
int frameCount=0;
int animationSpd=12; //How many frames to wait between each frame. Setting to 0 pauses the animation.
std::string name;
Pixel color=WHITE;
vd2d originPoint={0,0};
bool drawn=false;
Flag disableFlag=Flag::NONE;
Flag enableFlag=Flag::NONE;
int objArrElement; //Which element in the object array this object is located in. For sorting purposes.
bool temp=false; //If set to true, it's marked for deletion after cutscene handling.
bool enc=false; //If set to true, it's not included in the main list of entities for map saving because it's from an encounter.
bool dead=false; //If set to true, this object was properly part of an Entity and got declared as dead.
int blinkFrames=0; //Frame count of how much time is left for the image to be blinking. Used when enemies take damage.
//animationSpd is how long to wait before switching frames.
bool highlighted=false; //Whether or not this object has been declared as highlighted by a target range selector.
bool Collision(vd2d pos) {
GAME->SetDrawTarget(layer::COLLISION);
Pixel collisionData = GAME->GetDrawTarget()->GetPixel((int)pos.x-cameraPos.x,(int)pos.y-cameraPos.y);
return collisionData!=MAGENTA;
}
//A grid version of the constructor. used ONLY for battle setups.
Object(int id,std::string name,int gridx,int gridy,Animation*spr,vd2d scale={1,1},Pixel color=WHITE,int animationSpd=1,bool temp=false)
:Object(id,name,{gridx*32-(spr->width*0.5)*(scale.x-1),gridy*32-(spr->spr->sprite->height-4)*(scale.y-1)},spr,scale,color,animationSpd,temp) {}
Object(int id,std::string name,vd2d pos,Animation*spr,vd2d scale={1,1},Pixel color=WHITE,int animationSpd=1,bool temp=false) {
this->spr=spr;
this->pos=pos;
this->id=id;
this->name=name;
this->color=color;
this->animationSpd=animationSpd;
SetScale(scale);
this->temp=temp;
}
virtual Object* CreateType(int id,std::string name,vd2d pos,Animation*spr,vd2d scale={1,1},Pixel color=WHITE,int animationSpd=1,bool temp=false)=0;
//When the player tries to interact with this object.
virtual Interaction Interact()=0;
void SetScale(vd2d scale) {
this->scale=scale;
if (spr!=nullptr) {
this->originPoint={spr->width/2*scale.x,(spr->spr->sprite->height-4)*scale.y};
}
vd2d GetPosWithOrigin() {
return GetPos()+originPoint;
}
vd2d GetScale() {
return scale;
}
vd2d GetPos() {
return pos;
}
void Move(vd2d move);
void SetPos(vd2d pos) {
Move(pos-this->pos);
}
vd2d GetPosWithOrigin() {
return GetPos()+originPoint;
}
bool SmoothMove(vd2d move) {
const int wiggleRoom=5;
vd2d originPos = {pos.x+originPoint.x,pos.y-1+originPoint.y};
if (!Collision(originPos+move)) {
Move(move);
return true;
} else
if (move.x!=0&&!Collision({originPos.x+move.x,originPos.y})) {
Move({move.x,0});
return true;
} else
if (move.y!=0&&!Collision({originPos.x,originPos.y+move.y})) {
Move({0,move.y});
return true;
}
bool SmoothMove(vd2d move) {
const int wiggleRoom=5;
vd2d originPos = {pos.x+originPoint.x,pos.y-1+originPoint.y};
if (!Collision(originPos+move)) {
Move(move);
return true;
} else
if (move.x!=0&&!Collision({originPos.x+move.x,originPos.y})) {
Move({move.x,0});
return true;
} else
if (move.y!=0&&!Collision({originPos.x,originPos.y+move.y})) {
Move({0,move.y});
return true;
else
if (move.x>0) {
for (int i=0;i<wiggleRoom;i++) { //Search Up.
if (!Collision({originPos.x+move.x,originPos.y-i})) {
//There is potentially to move up-right here, so we will do so.
Move({0,-1});
originPos.y+=-1;
return true;
}
}
else
if (move.x>0) {
for (int i=0;i<wiggleRoom;i++) { //Search Up.
if (!Collision({originPos.x+move.x,originPos.y-i})) {
//There is potentially to move up-right here, so we will do so.
Move({0,-1});
originPos.y+=-1;
return true;
}
for (int i=0;i<wiggleRoom;i++) { //Search Down.
if (!Collision({originPos.x+move.x,originPos.y+i})) {
//There is potentially to move down-right here, so we will do so.
Move({0,1});
return true;
}
for (int i=0;i<wiggleRoom;i++) { //Search Down.
if (!Collision({originPos.x+move.x,originPos.y+i})) {
//There is potentially to move down-right here, so we will do so.
Move({0,1});
return true;
}
if (!Collision({originPos.x+move.x,originPos.y-i})) {
//There is potentially to move up-left here, so we will do so.
Move({0,-1});
return true;
}
if (!Collision({originPos.x+move.x,originPos.y-i})) {
//There is potentially to move up-left here, so we will do so.
Move({0,-1});
return true;
}
for (int i=0;i<wiggleRoom;i++) { //Search Down.
if (!Collision({originPos.x+move.x,originPos.y+i})) {
//There is potentially to move down-left here, so we will do so.
Move({0,1});
return true;
}
}
for (int i=0;i<wiggleRoom;i++) { //Search Down.
if (!Collision({originPos.x+move.x,originPos.y+i})) {
//There is potentially to move down-left here, so we will do so.
Move({0,1});
return true;
}
}
if (move.y>0) {
for (int i=0;i<wiggleRoom;i++) { //Search Left.
if (!Collision({originPos.x-i,originPos.y+move.y})) {
//There is potentially to move down-left here, so we will do so.
Move({-1,0});
return true;
}
}
if (move.y>0) {
for (int i=0;i<wiggleRoom;i++) { //Search Left.
if (!Collision({originPos.x-i,originPos.y+move.y})) {
//There is potentially to move down-left here, so we will do so.
Move({-1,0});
return true;
}
for (int i=0;i<wiggleRoom;i++) { //Search Right.
if (!Collision({originPos.x+i,originPos.y+move.y})) {
//There is potentially to move down-right here, so we will do so.
Move({1,0});
return true;
}
}
for (int i=0;i<wiggleRoom;i++) { //Search Right.
if (!Collision({originPos.x+i,originPos.y+move.y})) {
//There is potentially to move down-right here, so we will do so.
Move({1,0});
return true;
}
} else
if (move.y<0) {
for (int i=0;i<wiggleRoom;i++) { //Search Left.
if (!Collision({originPos.x-i,originPos.y+move.y})) {
//There is potentially to move up-left here, so we will do so.
Move({-1,0});
return true;
}
}
} else
if (move.y<0) {
for (int i=0;i<wiggleRoom;i++) { //Search Left.
if (!Collision({originPos.x-i,originPos.y+move.y})) {
//There is potentially to move up-left here, so we will do so.
Move({-1,0});
return true;
}
for (int i=0;i<wiggleRoom;i++) { //Search Right.
if (!Collision({originPos.x+i,originPos.y+move.y})) {
//There is potentially to move up-right here, so we will do so.
Move({1,0});
return true;
}
}
for (int i=0;i<wiggleRoom;i++) { //Search Right.
if (!Collision({originPos.x+i,originPos.y+move.y})) {
//There is potentially to move up-right here, so we will do so.
Move({1,0});
return true;
}
}
return false;
}
return false;
}
};
#define DynamicObject(objName) public:\
@ -179,4 +179,13 @@ class TrashCan_Obj : public Object{
frameIndex=1;
return {{"You dig around the trash can.","Nope! Just looks like plain ol' trash."}};}
};
class Shopkeeper_Obj : public Object{
DynamicObject(Shopkeeper_Obj)
std::vector<std::pair<Item*,int>> itemList;
std::string welcomeMessage="Welcome! Please choose an option: [BUY,SELL]";
Interaction Interact()override{
return {{welcomeMessage}};
}
};
#endif

@ -159,7 +159,7 @@ enum Reference{
NPC16_8,
NPC17_8,
NPC18_8,
NPC19_8,
SHOPKEEPER,
TRASH_CAN
};

@ -17,6 +17,8 @@ namespace GameState{
OVERWORLD_EQUIP_PLAYER_MENU,
OVERWORLD_STATUS_MENU,
OVERWORLD_TARGET_MENU,
SHOPKEEPER_MENU,
SHOPKEEPER_ASK_MENU,
};
}

Loading…
Cancel
Save