aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui.cpp')
-rw-r--r--src/ui.cpp159
1 files changed, 147 insertions, 12 deletions
diff --git a/src/ui.cpp b/src/ui.cpp
index 0d1fb49..00c0864 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -47,10 +47,10 @@ static unsigned char fontColor[3] = {255,255,255};
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 int dialogPassiveTime = 0;
/*
* Menu-related objects
@@ -140,6 +140,9 @@ namespace ui {
*/
bool dialogPassive = false;
+ bool dialogMerchant = false;
+ std::vector<BuySell> *minv;
+ int dialogPassiveTime = 0;
/**
* When set to true the dialog box will attempt to display.
@@ -237,6 +240,7 @@ namespace ui {
*/
void setFontSize(unsigned int size){
+ mtx.lock();
unsigned int i,j;
std::unique_ptr<uint8_t[]> rgbaBuf;
@@ -298,6 +302,7 @@ namespace ui {
rgbaBuf.release();
}
+ mtx.unlock();
}
/**
@@ -515,6 +520,7 @@ namespace ui {
*/
void dialogBox(const char *name,const char *opt,bool passive,const char *text,...){
+ textWrapLimit = 110;
va_list dialogArgs;
size_t len;
@@ -544,14 +550,20 @@ namespace ui {
dialogOptChosen = 0;
memset(&dialogOptLoc, 0, sizeof(float) * 12);
+ //char *sopt = (char*)malloc(255);
+ //dialogOptCount = 4;
// handle options if desired
if(opt){
- std::unique_ptr<char[]> soptbuf (new char[strlen(opt) + 1]);
- char *sopt = strtok(soptbuf.get(), ":");
+ //std::vector<char*> soptbuf (new char[strlen(opt) + 1]);
+ //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){
+ printf("%s",sopt);
strcpy( (dialogOptText[dialogOptCount++] = new char[strlen(sopt) + 1]), sopt);
sopt = strtok(NULL,":");
}
@@ -565,6 +577,69 @@ namespace ui {
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(typeOutStr)
+ *typeOutStr = '\0';
+ }
+
+ void merchantBox(){
+ textWrapLimit = 50;
+ dialogMerchant = true;
+ }
/**
* Wait for a dialog box to be dismissed.
@@ -663,10 +738,65 @@ namespace ui {
putStringCentered(offset.x, offset.y, rtext);
setFontSize(16);
}
- }else{ // normal dialog box
- x = offset.x - SCREEN_WIDTH / 2 + HLINE * 8;
- y = (offset.y + SCREEN_HEIGHT / 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 / 5.5);
+ merchAOptLoc[0][1] = offset.x + (SCREEN_WIDTH / 5.5);
+ merchAOptLoc[1][0] = offset.y + (SCREEN_HEIGHT *.25);
+ merchAOptLoc[1][1] = offset.y + (SCREEN_HEIGHT *.25);
+ merchAOptLoc[2][0] = offset.x - (SCREEN_WIDTH / 5.5) - 16;
+ merchAOptLoc[2][1] = offset.x + (SCREEN_WIDTH / 5.5) + 16;
+
+ glColor3ub(255,255,255);
+ glBegin(GL_TRIANGLES);
+ glVertex2f(merchAOptLoc[2][0],merchAOptLoc[1][0]);
+ glVertex2f(merchAOptLoc[0][0],merchAOptLoc[1][0]-8);
+ glVertex2f(merchAOptLoc[0][0],merchAOptLoc[1][0]+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);
@@ -1123,6 +1253,11 @@ namespace ui {
break;
}
}
+
+ if(dialogMerchant){
+ for(i = 0; i < 2; i++){
+ }
+ }
// handle important text
if(dialogImportant){
@@ -1130,10 +1265,10 @@ namespace ui {
setFontSize(16);
}
- // kill the dialog box
+ if(dialogMerchant) dialogMerchant = false;
dialogBoxExists = false;
}
-
+
void handleEvents(void){
static bool left=true,right=false;
static int heyOhLetsGo = 0;
@@ -1364,10 +1499,10 @@ namespace ui {
pixels = new GLubyte[ 3 * SCREEN_WIDTH * SCREEN_HEIGHT];
glReadPixels(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, GL_RGB, GL_UNSIGNED_BYTE, pixels);
- static std::thread scr;
- scr = std::thread(takeScreenshot,pixels);
- scr.detach();
- //takeScreenshot(pixels);
+ //static std::thread scr;
+ //scr = std::thread(takeScreenshot,pixels);
+ //scr.detach();
+ takeScreenshot(pixels);
std::cout << "Took screenshot" << std::endl;
break;