/*
* Variables for dialog boxes / options.
- */
+*/
- static char dialogBoxText[512];
- static char *dialogOptText[4];
- static float dialogOptLoc[4][3];
+ static char dialogBoxText[512];
+ static char *dialogOptText[4];
+ static float merchAOptLoc[2][3];
+ static float dialogOptLoc[4][3];
static unsigned char dialogOptCount = 0;
- static bool typeOutDone = true;
+ static bool typeOutDone = true;
+
+ /*
+ * Menu-related objects
+ */
-extern Menu *currentMenu;
+extern Menu* currentMenu;
extern Menu pauseMenu;
-/**
- * The sound made when displaying characters with dialogBox or importantText.
- */
static Mix_Chunk *dialogClick;
}
void Menu::gotoChild(){
- if(!child)
+ if(child == NULL){
currentMenu = NULL;
- else
+ }else{
currentMenu = child;
+ }
}
-static vec2 premouse={0,0};
-
namespace ui {
- /**
- * The current position of the mouse.
- */
+ /*
+ * Mouse coordinates.
+ */
vec2 mouse;
+ static vec2 premouse={0,0};
- /**
- * If true, debug information will be drawn to the screen.
- */
-
- bool debug = false;
-
- /**
- * If true, lines should be drawn to the player when the debug menu is open.
- */
+ /*
+ * Variety of keydown bools
+ */
+ bool edown;
+
+ /*
+ * Debugging flags.
+ */
+ bool debug=false;
bool posFlag=false;
-
- /**
- * If true, the player will be able to move when the current dialog box is
- * displayed.
- */
-
bool dialogPassive = false;
+ bool dialogMerchant = false;
+ std::vector<BuySell> *minv;
int dialogPassiveTime = 0;
- /**
- * When set to true the dialog box will attempt to display.
- */
-
- bool dialogBoxExists = false;
- /**
- * When set to true the text will display as 'important' text.
- */
+ /*
+ * Dialog stuff that needs to be 'public'.
+ */
+ bool dialogBoxExists = false;
bool dialogImportant = false;
-
- /**
- * Contains the last chosen dialog option.
- */
-
unsigned char dialogOptChosen = 0;
- /**
- * Determines how many characters can be displayed in a dialog box before
- * a new line is required.
- */
-
unsigned int textWrapLimit = 110;
- /**
- * The current font size.
- *
- * DO NOT change this directly, use setFontSize() instead.
- */
+ /*
+ * Current font size. Changing this WILL NOT change the font size, see setFontSize() for
+ * actual font size changing.
+ */
unsigned int fontSize;
float putText(const float x,const float y,const char *str,...){
va_list args;
- std::unique_ptr<char[]> buf (new char[512]);
+ char *buf;
+ float width;
- // create the formatted string
- va_start(args, str);
- vsnprintf(buf.get(), 512, str, args);
+ /*
+ * Create a wimpy buffer.
+ */
+
+ buf = new char[512]; //(char *)calloc(128,sizeof(char));
+ memset(buf,0,512*sizeof(char));
+
+ /*
+ * Handle the formatted string, printing it to the buffer.
+ */
+
+ va_start(args,str);
+ vsnprintf(buf,512,str,args);
va_end(args);
- return putString(x, y, buf.get());
+ /*
+ * Draw the string, free resources, return the width of the string.
+ */
+
+ width=putString(x,y,buf);
+ delete[] buf; //free(buf);
+
+ return width;
}
-
- /**
- * Prints a character dialog box.
- *
- * This function sets up the variables necessary to draw a dialog box. If
- * `opt` contains a valid string, options will be printed with the dialog
- * box. If the box is passive, the player will be allowed to move while it
- * is being displayed.
- */
-
void dialogBox(const char *name,const char *opt,bool passive,const char *text,...){
+ textWrapLimit = 110;
va_list dialogArgs;
- size_t len;
+ unsigned int len;
+ char *sopt,*soptbuf;
dialogPassive = passive;
dialogBoxExists = true;
dialogImportant = false;
- // kill the string created by typeOut if it contains something
- if(typeOutStr)
- *typeOutStr = '\0';
+ if(ret)
+ ret[0] = '\0';
}
- if(typeOutStr)
- *typeOutStr = '\0';
+
+ void merchantBox(const char *name,std::vector<BuySell> *bsinv,const char *opt,bool passive,const char *text,...){
+ std::cout << "Buying and selling on the bi-weekly!" << std::endl;
+ va_list dialogArgs;
+ size_t len;
+
+ minv = bsinv;
+ dialogPassive = passive;
+
+ // clear the buffer
+ memset(dialogBoxText, '\0', 512);
+
+ // create the string
+ strcpy(dialogBoxText, name);
+ strcat(dialogBoxText, ": ");
+
+ len=strlen(dialogBoxText);
+ va_start(dialogArgs,text);
+ vsnprintf(dialogBoxText + len, 512 - len, text, dialogArgs);
+ va_end(dialogArgs);
+
+ // free old option text
+ while(dialogOptCount){
+ if(dialogOptText[dialogOptCount]){
+ delete[] dialogOptText[dialogOptCount];
+ dialogOptText[dialogOptCount] = NULL;
+ }
+
+ dialogOptCount--;
+ };
+
+ dialogOptChosen = 0;
+ memset(&dialogOptLoc, 0, sizeof(float) * 12);
+
+ // handle options if desired
+ if(opt){
+ //std::unique_ptr<char[]> soptbuf (new char[strlen(opt) + 1]);
+ char soptbuf[255];
+ strcpy(soptbuf, opt);
+ char *sopt = strtok(soptbuf, ":");
+
+ // cycle through options
+ while(sopt){
+ strcpy( (dialogOptText[dialogOptCount++] = new char[strlen(sopt) + 1]), sopt);
+ sopt = strtok(NULL,":");
+ }
+ }
+
+ // allow box to be displayed
+ dialogBoxExists = true;
+ dialogImportant = false;
+ dialogMerchant = true;
+ textWrapLimit = 50;
+
+ // kill the string created by typeOut if it contains something
++ if(ret)
++ *ret = '\0';
+ }
+
+ void merchantBox(){
+ textWrapLimit = 50;
+ dialogMerchant = true;
+ }
+
+ /**
+ * Wait for a dialog box to be dismissed.
+ */
+
void waitForDialog(void){
do{
mainLoop();
float x,y,tmp;
char *rtext;
- // handle dialog box / important text
if(dialogBoxExists){
- rtext = typeOut(dialogBoxText);
+ rtext=typeOut(dialogBoxText);
if(dialogImportant){
- setFontColor(255, 255, 255);
-
- // handle timeout
- if(dialogPassive && (dialogPassiveTime -= deltaTime) <= 0){
- dialogPassive = false;
- dialogImportant = false;
- dialogBoxExists = false;
+ setFontColor(255,255,255);
+ if(dialogPassive){
+ dialogPassiveTime -= deltaTime;
+ if(dialogPassiveTime < 0){
+ dialogPassive = false;
+ dialogImportant = false;
+ dialogBoxExists = false;
+ }
}
-
- // draw text
if(fadeIntensity == 255 || dialogPassive){
setFontSize(24);
- putStringCentered(offset.x, offset.y, rtext);
+ putStringCentered(offset.x,offset.y,rtext);
setFontSize(16);
}
- }else{
-
- x=offset.x-SCREEN_WIDTH/2+HLINE*8;
+ }else if(dialogMerchant){
+ x=offset.x-SCREEN_WIDTH/6;
y=(offset.y+SCREEN_HEIGHT/2)-HLINE*8;
glColor3ub(255,255,255);
+ glBegin(GL_LINE_STRIP);
+ glVertex2f(x-1 ,y+1);
+ glVertex2f(x+1+(SCREEN_WIDTH/3),y+1);
+ glVertex2f(x+1+(SCREEN_WIDTH/3),y-1-SCREEN_HEIGHT*.6);
+ glVertex2f(x-1,y-1-SCREEN_HEIGHT*.6);
+ glVertex2f(x,y+1);
+ glEnd();
+
+ glColor3ub(0,0,0);
+ glRectf(x,y,x+SCREEN_WIDTH/3,y-SCREEN_HEIGHT*.6);
+
+ // draw typeOut'd text
+ putString(x + HLINE, y - fontSize - HLINE, (rtext = typeOut(dialogBoxText)));
+ merchAOptLoc[0][0] = offset.x - (SCREEN_WIDTH / 6.5) - 16;
+ merchAOptLoc[0][1] = offset.x + (SCREEN_WIDTH / 6.5);
+ merchAOptLoc[1][0] = offset.y + (SCREEN_HEIGHT *.25);
+ merchAOptLoc[1][1] = offset.y + (SCREEN_HEIGHT *.25);
+ merchAOptLoc[2][0] = offset.x - (SCREEN_WIDTH / 6.5);
+ merchAOptLoc[2][1] = offset.x + (SCREEN_WIDTH / 6.5) + 16;
+
+ for(i = 0; i < 2; i++){
+ if(mouse.x > merchAOptLoc[0][i] && mouse.x < merchAOptLoc[2][i] &&
+ mouse.y > merchAOptLoc[1][i] - 8 && mouse.y < merchAOptLoc[1][i] + 8){
+ glColor3ub(255, 255, 0);
+ }else{
+ glColor3ub(255,255,255);
+ }
+ }
+
+ glBegin(GL_TRIANGLES);
+ glVertex2f(merchAOptLoc[0][0],merchAOptLoc[1][0]);
+ glVertex2f(merchAOptLoc[2][0],merchAOptLoc[1][0]-8);
+ glVertex2f(merchAOptLoc[2][0],merchAOptLoc[1][0]+8);
+
+ glVertex2f(merchAOptLoc[2][1],merchAOptLoc[1][1]);
+ glVertex2f(merchAOptLoc[0][1],merchAOptLoc[1][1]-8);
+ glVertex2f(merchAOptLoc[0][1],merchAOptLoc[1][1]+8);
+ glEnd();
+
+ // draw / handle dialog options if they exist
+ for(i = 0; i < dialogOptCount; i++){
+ setFontColor(255, 255, 255);
+
+ // draw option
+ tmp = putStringCentered(offset.x, dialogOptLoc[i][1], dialogOptText[i]);
+
+ // get coordinate information on option
+ dialogOptLoc[i][2] = offset.x + tmp;
+ dialogOptLoc[i][0] = offset.x - tmp;
+ dialogOptLoc[i][1] = y - SCREEN_HEIGHT / 2 - (fontSize + HLINE) * (i + 1);
+
+ // make text yellow if the mouse hovers over the text
+ if(mouse.x > dialogOptLoc[i][0] && mouse.x < dialogOptLoc[i][2] &&
+ mouse.y > dialogOptLoc[i][1] && mouse.y < dialogOptLoc[i][1] + 16 ){
+ setFontColor(255, 255, 0);
+ putStringCentered(offset.x, dialogOptLoc[i][1], dialogOptText[i]);
+ }
+ }
+
+ setFontColor(255, 255, 255);
+ }else{ //normal dialog box
+
+ x=offset.x-SCREEN_WIDTH/2+HLINE*8;
+ y=(offset.y+SCREEN_HEIGHT/2)-HLINE*8;
+
+ // draw white border
+ glColor3ub(255, 255, 255);
++
glBegin(GL_LINE_STRIP);
- glVertex2f(x - 1 , y + 1 );
- glVertex2f(x + 1 + SCREEN_WIDTH - HLINE * 16, y + 1 );
- glVertex2f(x + 1 + SCREEN_WIDTH - HLINE * 16, y - 1 - SCREEN_HEIGHT / 4 );
- glVertex2f(x - 1 , y - 1 - SCREEN_HEIGHT / 4 );
- glVertex2f(x , y + 1 );
+ glVertex2f(x-1 ,y+1);
+ glVertex2f(x+1+SCREEN_WIDTH-HLINE*16,y+1);
+ glVertex2f(x+1+SCREEN_WIDTH-HLINE*16,y-1-SCREEN_HEIGHT/4);
+ glVertex2f(x-1 ,y-1-SCREEN_HEIGHT/4);
+ glVertex2f(x ,y+1);
glEnd();
- // draw black box
- glColor3ub(0, 0, 0);
- glRectf(x, y, x + SCREEN_WIDTH - HLINE * 16, y - SCREEN_HEIGHT / 4);
+ glColor3ub(0,0,0);
+ glRectf(x,y,x+SCREEN_WIDTH-HLINE*16,y-SCREEN_HEIGHT/4);
- // draw typeOut'd text
- putString(x + HLINE, y - fontSize - HLINE, (rtext = typeOut(dialogBoxText)));
+ rtext=typeOut(dialogBoxText);
- // draw / handle dialog options if they exist
- for(i = 0; i < dialogOptCount; i++){
- setFontColor(255, 255, 255);
-
- // draw option
- tmp = putStringCentered(offset.x, dialogOptLoc[i][1], dialogOptText[i]);
-
- // get coordinate information on option
+ putString(x+HLINE,y-fontSize-HLINE,rtext);
+
+ for(i=0;i<dialogOptCount;i++){
+ setFontColor(255,255,255);
+ tmp = putStringCentered(offset.x,dialogOptLoc[i][1],dialogOptText[i]);
dialogOptLoc[i][2] = offset.x + tmp;
dialogOptLoc[i][0] = offset.x - tmp;
dialogOptLoc[i][1] = y - SCREEN_HEIGHT / 4 + (fontSize + HLINE) * (i + 1);
return;
}
- // check for selected option
- for(i = 0; i < dialogOptCount; i++){
- if(mouse.x > dialogOptLoc[i][0] && mouse.x < dialogOptLoc[i][2] &&
- mouse.y > dialogOptLoc[i][1] && mouse.y < dialogOptLoc[i][1] + 16 ){
+ for(i=0;i<dialogOptCount;i++){
+ if(mouse.x > dialogOptLoc[i][0] &&
+ mouse.x < dialogOptLoc[i][2] &&
+ mouse.y > dialogOptLoc[i][1] &&
+ mouse.y < dialogOptLoc[i][1] + 16 ){ // fontSize
dialogOptChosen = i + 1;
- break;
+ goto DONE;
}
}
- if(dialogMerchant){
- for(i = 0; i < 2; i++){
- }
- }
+DONE:
+
+
+ // handle important text
if(dialogImportant){
dialogImportant = false;
setFontSize(16);