aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui.cpp
diff options
context:
space:
mode:
authordrumsetmonkey <abelleisle@roadrunner.com>2016-04-23 21:55:31 -0400
committerdrumsetmonkey <abelleisle@roadrunner.com>2016-04-23 21:55:31 -0400
commitdebb080a17eba2b2957e99ba7f1ce0fa0c4d2e4e (patch)
tree621bcf54c0f97b202e21bb4f21f5107f852cba63 /src/ui.cpp
parent6e51f9723635de3defce30517fa1043f26e27ee9 (diff)
parente04fae7b72b424e5019429a071ad2de9edf4df1f (diff)
Fixed some bugs
Diffstat (limited to 'src/ui.cpp')
-rw-r--r--src/ui.cpp131
1 files changed, 72 insertions, 59 deletions
diff --git a/src/ui.cpp b/src/ui.cpp
index bcac044..59ea102 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -615,11 +615,30 @@ namespace ui {
pageTexReady = true;
}
- void draw(void) {
+ void drawBox(vec2 c1, vec2 c2) {
+ // draw black body
+ glColor3ub(0, 0, 0);
+ glRectf(c1.x, c1.y, c2.x, c2.y);
+
+ // draw white border
+ glColor3ub(255, 255, 255);
+ glBegin(GL_LINE_STRIP);
+ glVertex2i(c1.x , c1.y);
+ glVertex2i(c2.x + 1, c1.y);
+ glVertex2i(c2.x + 1, c2.y);
+ glVertex2i(c1.x - 1, c2.y);
+ glVertex2i(c1.x , c1.y);
+ glEnd();
+ }
+
+ void draw(void){
unsigned char i;
float x,y,tmp;
std::string rtext;
+ // will return if not toggled
+ action::draw(vec2 {player->loc.x + player->width / 2, player->loc.y + player->height + HLINE});
+
if (pageTexReady) {
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, pageTex);
@@ -654,38 +673,24 @@ namespace ui {
x=offset.x-SCREEN_WIDTH/6;
y=(offset.y+SCREEN_HEIGHT/2)-HLINE*8;
- // draw the box border
- 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 - 1,y+1);
- glEnd();
-
- // draw the box
- glColor3ub(0,0,0);
- glRectf(x,y,x+SCREEN_WIDTH/3,y-SCREEN_HEIGHT*.6);
+ drawBox(vec2 {x, y}, vec2 {x + SCREEN_WIDTH / 3, y - SCREEN_HEIGHT * 0.6f});
// draw typeOut'd text
putString(x + HLINE, y - fontSize - HLINE, (rtext = typeOut(dialogBoxText)));
- std::string itemString1 = std::to_string(merchTrade.quantity[0]);
- itemString1 += "x";
-
- std::string itemString2 = std::to_string(merchTrade.quantity[1]);
- itemString2 += "x";
+ std::string itemString1 = std::to_string(merchTrade.quantity[0]) + "x",
+ itemString2 = std::to_string(merchTrade.quantity[1]) + "x";
- putStringCentered(offset.x - (SCREEN_WIDTH / 10) + 20, offset.y + (SCREEN_HEIGHT / 5) + 40 + (fontSize*2), itemString1.c_str());
- putStringCentered(offset.x - (SCREEN_WIDTH / 10) + 20, offset.y + (SCREEN_HEIGHT / 5) + 40 + fontSize, merchTrade.item[0].c_str());
+ vec2 merchBase = {offset.x, offset.y + SCREEN_HEIGHT / 5};
- putStringCentered(offset.x + (SCREEN_WIDTH / 10) - 20, offset.y + (SCREEN_HEIGHT / 5) + 40 + (fontSize*2), itemString2.c_str());
- putStringCentered(offset.x + (SCREEN_WIDTH / 10) - 20, offset.y + (SCREEN_HEIGHT / 5) + 40 + fontSize, merchTrade.item[1].c_str());
-
- putStringCentered(offset.x,offset.y + (SCREEN_HEIGHT / 5) + 60, "for");
+ putStringCentered(merchBase.x + SCREEN_WIDTH / 10 - 20, merchBase.y + 40 + fontSize * 2, itemString1.c_str());
+ putStringCentered(merchBase.x + SCREEN_WIDTH / 10 - 20, merchBase.y + 40 + fontSize , merchTrade.item[0].c_str());
+ putStringCentered(merchBase.x - SCREEN_WIDTH / 10 , merchBase.y + 40 + fontSize * 2, itemString2.c_str());
+ putStringCentered(merchBase.x - SCREEN_WIDTH / 10 , merchBase.y + 40 + fontSize , merchTrade.item[1].c_str());
+ putStringCentered(offset.x, merchBase.y + 60, "for");
glEnable(GL_TEXTURE_2D);
+
glBindTexture(GL_TEXTURE_2D, getItemTexture(merchTrade.item[0]));
glBegin(GL_QUADS);
glTexCoord2d(0,1);glVertex2f(offset.x - (SCREEN_WIDTH / 10) ,offset.y + (SCREEN_HEIGHT/5));
@@ -701,6 +706,7 @@ namespace ui {
glTexCoord2d(1,0);glVertex2f(offset.x + (SCREEN_WIDTH / 10) ,offset.y + (SCREEN_HEIGHT/5) + 40);
glTexCoord2d(0,0);glVertex2f(offset.x + (SCREEN_WIDTH / 10) - 40,offset.y + (SCREEN_HEIGHT/5) + 40);
glEnd();
+
glDisable(GL_TEXTURE_2D);
merchArrowLoc[0].x = offset.x - (SCREEN_WIDTH / 8.5) - 16;
@@ -748,24 +754,12 @@ namespace ui {
}
setFontColor(255, 255, 255);
- }else{ //normal dialog box
+ } 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);
+ x = offset.x - SCREEN_WIDTH / 2 + HLINE * 8;
+ y = offset.y + SCREEN_HEIGHT / 2 - HLINE * 8;
- glBegin(GL_LINE_STRIP);
- glVertex2i(x-1 ,y+1);
- glVertex2i(x+1+SCREEN_WIDTH-HLINE*16,y+1);
- glVertex2i(x+1+SCREEN_WIDTH-HLINE*16,y-1-SCREEN_HEIGHT/4);
- glVertex2i(x-1 ,y-1-SCREEN_HEIGHT/4);
- glVertex2i(x-1 ,y+1);
- glEnd();
-
- glColor3ub(0,0,0);
- glRectf(x,y,x+SCREEN_WIDTH-HLINE*16,y-SCREEN_HEIGHT/4);
+ drawBox(vec2 {x, y}, vec2 {x + SCREEN_WIDTH - HLINE * 16, y - SCREEN_HEIGHT / 4});
rtext = typeOut(dialogBoxText);
@@ -956,16 +950,22 @@ EXIT:
// mouse clicks
case SDL_MOUSEBUTTONDOWN:
- // right click advances dialog
- if ((e.button.button & SDL_BUTTON_RIGHT) && (dialogBoxExists | pageTexReady))
- dialogAdvance();
+ // run actions?
+ if ((action::make = e.button.button & SDL_BUTTON_RIGHT))
+ /*player->inv->invHover =*/ edown = false;
- // left click uses item
- if ((e.button.button & SDL_BUTTON_LEFT) && !dialogBoxExists)
- player->inv->usingi = true;
+ if (dialogBoxExists || pageTexReady) {
+ // right click advances dialog
+ if ((e.button.button & SDL_BUTTON_RIGHT))
+ dialogAdvance();
+ } else {
+ // left click uses item
+ if (e.button.button & SDL_BUTTON_LEFT)
+ player->inv->usingi = true;
+ }
- if (mouse.x > player->loc.x && mouse.x < player->loc.x + player->width &&
- mouse.y > player->loc.y && mouse.y < player->loc.y + player->height) {
+ if(mouse.x > player->loc.x && mouse.x < player->loc.x + player->width &&
+ mouse.y > player->loc.y && mouse.y < player->loc.y + player->height) {
player->vel.y = .05;
fr = mouse;
ig = player;
@@ -1054,8 +1054,6 @@ EXIT:
}
}
break;
- case SDLK_s:
- break;
case SDLK_w:
if (inBattle) {
tmp = currentWorld;
@@ -1067,31 +1065,42 @@ EXIT:
break;
case SDLK_LSHIFT:
if (debug) {
- Mix_PlayChannel(1,sanic,-1);
+ Mix_PlayChannel(1, sanic, -1);
player->speed = 4.0f;
- }else
+ } else
player->speed = 2.0f;
break;
case SDLK_LCTRL:
player->speed = .5;
break;
case SDLK_e:
- edown=true;
+ edown = true;
+
+ // start hover counter?
if (!heyOhLetsGo) {
heyOhLetsGo = loops;
player->inv->mouseSel = false;
}
- if (loops - heyOhLetsGo >= 2 && !(player->inv->invOpen) && !(player->inv->selected))
- player->inv->invHover=true;
+
+ // run hover thing
+ if (loops - heyOhLetsGo >= 2 && !(player->inv->invOpen) && !(player->inv->selected)) {
+ player->inv->invHover = true;
+
+ // enable action ui
+ action::enable();
+ }
+
break;
default:
break;
}
+
+ // handle world switches?
if (tmp != currentWorld) {
- std::swap(tmp,currentWorld);
+ std::swap(tmp, currentWorld);
toggleBlackFast();
waitForCover();
- std::swap(tmp,currentWorld);
+ std::swap(tmp, currentWorld);
toggleBlackFast();
}
}
@@ -1149,6 +1158,10 @@ EXIT:
else player->inv->selected = false;
player->inv->mouseSel = false;
}
+
+ // disable action ui
+ action::disable();
+
heyOhLetsGo = 0;
break;
case SDLK_l:
@@ -1165,7 +1178,7 @@ EXIT:
else {
currentWorld->addStructure(FIRE_PIT, player->loc.x, player->loc.y, "", "");
currentWorld->addLight({player->loc.x + SCREEN_WIDTH/2, player->loc.y},{1.0f,1.0f,1.0f});
- currentWorld->getLastLight()->follow(currentWorld->build.back());
+ //currentWorld->getLastLight()->follow(currentWorld->build.back());
currentWorld->getLastLight()->makeFlame();
}
break;