diff options
Diffstat (limited to 'src/ui.cpp')
-rw-r--r-- | src/ui.cpp | 92 |
1 files changed, 71 insertions, 21 deletions
@@ -43,7 +43,7 @@ static vec2 ftexwh[93]; static vec2 ftexbl[93]; static vec2 ftexad[93]; -static unsigned char fontColor[3] = {255,255,255}; +static unsigned char fontColor[4] = {255,255,255,255}; /* * Variables for dialog boxes / options. @@ -126,6 +126,7 @@ namespace ui { int dialogPassiveTime = 0; Trade merchTrade; + int fontTransInv = 255; /* * Dialog stuff that needs to be 'public'. @@ -193,6 +194,7 @@ namespace ui { */ void setFontSize(unsigned int size){ + mtx.lock(); unsigned int i,j; unsigned char *buf; @@ -255,6 +257,7 @@ namespace ui { delete[] buf; //free(buf); } + mtx.unlock(); } /* @@ -265,6 +268,14 @@ namespace ui { fontColor[0]=r; fontColor[1]=g; fontColor[2]=b; + fontColor[3]=255; + } + + void setFontColor(unsigned char r,unsigned char g,unsigned char b, unsigned char a){ + fontColor[0]=r; + fontColor[1]=g; + fontColor[2]=b; + fontColor[3]=a; } /* @@ -293,7 +304,7 @@ namespace ui { glPushMatrix(); glTranslatef(0,-c2.y,0); glBegin(GL_QUADS); - glColor3ub(fontColor[0],fontColor[1],fontColor[2]); + glColor4ub(fontColor[0],fontColor[1],fontColor[2],fontColor[3]); glTexCoord2f(0,1);glVertex2f(c1.x ,c1.y ); glTexCoord2f(1,1);glVertex2f(c1.x+c2.x,c1.y ); glTexCoord2f(1,0);glVertex2f(c1.x+c2.x,c1.y+c2.y); @@ -321,7 +332,7 @@ namespace ui { * Loop on each character: */ - do { + do{ if(i && ((i / 110.0) == (i / 110))){ o.y -= fontSize * 1.05f; o.x = x; @@ -384,7 +395,6 @@ namespace ui { break; } } while(s[++i]); - putString(floor(x-width/2),y,s); return width; } @@ -569,6 +579,7 @@ namespace ui { }; dialogOptChosen = 0; + merchOptChosen = 0; memset(&dialogOptLoc, 0, sizeof(float) * 12); // handle options if desired @@ -605,8 +616,9 @@ namespace ui { void waitForDialog(void){ do{ - mainLoop(); - }while(ui::dialogBoxExists); + //std::thread(dialogAdvance); + //mainLoop(); + }while(dialogBoxExists); } void waitForCover(void){ do{ @@ -802,10 +814,10 @@ namespace ui { 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); 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 ); + glVertex2i(x-1 ,y+1); glEnd(); glColor3ub(0,0,0); @@ -862,6 +874,7 @@ namespace ui { * Lists all of the quests the player is currently taking. */ + setFontColor(255,255,255,fontTransInv); if(player->inv->invOpen){ hub.y = player->loc.y + fontSize * 8; hub.x = player->loc.x;// + player->width / 2; @@ -872,7 +885,18 @@ namespace ui { hub.y -= fontSize * 1.15; putStringCentered(hub.x,hub.y,c.title.c_str()); } + + hub.y = offset.y + 40*1.2; + hub.x = offset.x + SCREEN_WIDTH/2 - 40*1.5; + + putStringCentered(hub.x,hub.y,"Equipment:"); + + hub.y = offset.y + SCREEN_HEIGHT/2 - 20; + hub.x = offset.x - SCREEN_WIDTH/2 + 45*4*1.5; + + putStringCentered(hub.x,hub.y,"Inventory:"); } + setFontColor(255,255,255,255); } } @@ -1210,6 +1234,11 @@ namespace ui { fclose(bmp); } + void closeBox(){ + dialogBoxExists = false; + dialogMerchant = false; + } + void dialogAdvance(void){ unsigned char i; @@ -1223,31 +1252,46 @@ namespace ui { typeOutDone = true; return; } - 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; - goto DONE; + goto EXIT; + } + } + if(dialogMerchant){ + for(i=0;i<2;i++){ + if(((merchAOptLoc[i][0] < merchAOptLoc[i][2]) ? + (mouse.x > merchAOptLoc[i][0] && mouse.x < merchAOptLoc[i][2]) : + (mouse.x < merchAOptLoc[i][0] && mouse.x > merchAOptLoc[i][2])) && + mouse.y > merchAOptLoc[i][1] - 8 && mouse.y < merchAOptLoc[i][1] + 8){ // fontSize + merchOptChosen = i + 1; + goto EXIT; + } } } -DONE: + + + EXIT: + //if(!dialogMerchant)closeBox(); + dialogBoxExists = false; + dialogMerchant = false; + + //DONE: // handle important text if(dialogImportant){ dialogImportant = false; setFontSize(16); } - - if(dialogMerchant) dialogMerchant = false; - dialogBoxExists = false; } void handleEvents(void){ static bool left=true,right=false; static int heyOhLetsGo = 0; + static int mouseWheelUpCount = 0, mouseWheelDownCount = 0; World *tmp; vec2 oldpos,tmppos; SDL_Event e; @@ -1279,7 +1323,19 @@ DONE: if ( ( e.button.button & SDL_BUTTON_LEFT ) && !dialogBoxExists ) player->inv->usingi = true; break; - + case SDL_MOUSEWHEEL: + if (e.wheel.y < 0){ + if(mouseWheelUpCount++ && mouseWheelUpCount%5==0){ + player->inv->setSelectionUp(); + mouseWheelUpCount = 0; + } + }else{ + if(mouseWheelDownCount-- && mouseWheelDownCount%5==0){ + player->inv->setSelectionDown(); + mouseWheelDownCount = 0; + } + } + break; // key presses case SDL_KEYDOWN: @@ -1432,12 +1488,6 @@ DONE: } heyOhLetsGo = 0; break; - case SDLK_LEFT: - if(player->inv->sel)player->inv->sel--; - break; - case SDLK_RIGHT: - player->inv->sel++; - break; case SDLK_l: player->light^=true; break; |