diff options
author | drumsetmonkey <abelleisle@roadrunner.com> | 2016-03-21 08:04:33 -0400 |
---|---|---|
committer | drumsetmonkey <abelleisle@roadrunner.com> | 2016-03-21 08:04:33 -0400 |
commit | bbdc924d409f74594bd8c8b0d4bf55d5e5f32209 (patch) | |
tree | 6bbe247053be8686ed0223225f4d2be76f75fed9 /src/ui.cpp | |
parent | 569d23b5d4577fce1473a82ae7f8977205ff7f0f (diff) |
Created currency and new inventory
Diffstat (limited to 'src/ui.cpp')
-rw-r--r-- | src/ui.cpp | 376 |
1 files changed, 205 insertions, 171 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. @@ -100,13 +100,13 @@ void Menu::gotoChild(){ } namespace ui { - + /* * Mouse coordinates. */ - + vec2 mouse; - static vec2 premouse={0,0}; + static vec2 premouse={0,0}; /* * Variety of keydown bools @@ -116,7 +116,7 @@ namespace ui { /* * Debugging flags. */ - + bool debug=false; bool posFlag=false; bool dialogPassive = false; @@ -124,23 +124,25 @@ namespace ui { int dialogPassiveTime = 0; Trade merchTrade; - + int fontTransInv = 255; + + /* * Dialog stuff that needs to be 'public'. */ - + bool dialogBoxExists = false; bool dialogImportant = false; unsigned char dialogOptChosen = 0; unsigned char merchOptChosen = 0; - + unsigned int textWrapLimit = 110; - + /* * Current font size. Changing this WILL NOT change the font size, see setFontSize() for * actual font size changing. */ - + unsigned int fontSize; /* @@ -162,20 +164,20 @@ namespace ui { sanic = Mix_LoadWAV("assets/sounds/sanic.wav"); //Mix_Volume(1,50); } - + void destroyFonts(void){ FT_Done_Face(ftf); FT_Done_FreeType(ftl); - + Mix_FreeChunk(dialogClick); Mix_FreeChunk(battleStart); Mix_FreeChunk(sanic); } - + /* * Sets a new font family to use (*.ttf). */ - + void setFontFace(const char *ttf){ if(FT_New_Face(ftl,ttf,0,&ftf)){ std::cout<<"Error! Couldn't open "<<ttf<<"."<<std::endl; @@ -185,56 +187,56 @@ namespace ui { DEBUG_printf("Using font %s\n",ttf); #endif // DEBUG } - + /* * Sets a new font size (default: 12). */ - + void setFontSize(unsigned int size){ mtx.lock(); unsigned int i,j; unsigned char *buf; - + fontSize=size; FT_Set_Pixel_Sizes(ftf,0,fontSize); - + /* * Pre-render 'all' the characters. */ - + glDeleteTextures(93,ftex); // delete[] any already-rendered textures glGenTextures(93,ftex); // Generate new texture name/locations? - + for(i=33;i<126;i++){ - + /* * Load the character from the font family file. */ - + if(FT_Load_Char(ftf,i,FT_LOAD_RENDER)){ std::cout<<"Error! Unsupported character "<<(char)i<<" ("<<i<<")."<<std::endl; abort(); } - + /* * Transfer the character's bitmap (?) to a texture for rendering. */ - + glBindTexture(GL_TEXTURE_2D,ftex[i-33]); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S ,GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T ,GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER ,GL_LINEAR ); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER ,GL_LINEAR ); glPixelStorei(GL_UNPACK_ALIGNMENT,1); - + /* * The just-created texture will render red-on-black if we don't do anything to it, so * here we create a buffer 4 times the size and transform the texture into an RGBA array, * making it white-on-black. */ - + buf = new unsigned char[ftf->glyph->bitmap.width * ftf->glyph->bitmap.rows * 4]; - + for(j=0;j<ftf->glyph->bitmap.width*ftf->glyph->bitmap.rows;j++){ buf[j*4 ]=255;//fontColor[0]; buf[j*4+1]=255;//fontColor[1]; @@ -242,58 +244,66 @@ namespace ui { buf[j*4+3]=ftf->glyph->bitmap.buffer[j] ? 255 : 0; //buf[j*4+3]=ftf->glyph->bitmap.buffer[j]; } - + ftexwh[i-33].x=ftf->glyph->bitmap.width; ftexwh[i-33].y=ftf->glyph->bitmap.rows; ftexbl[i-33].x=ftf->glyph->bitmap_left; ftexbl[i-33].y=ftf->glyph->bitmap_top; ftexad[i-33].x=ftf->glyph->advance.x>>6; ftexad[i-33].y=ftf->glyph->advance.y>>6; - - glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,ftf->glyph->bitmap.width,ftf->glyph->bitmap.rows,0,GL_RGBA,GL_UNSIGNED_BYTE,buf); - + + glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,ftf->glyph->bitmap.width,ftf->glyph->bitmap.rows,0,GL_RGBA,GL_UNSIGNED_BYTE,buf); + delete[] buf; //free(buf); } mtx.unlock(); } - + /* * Set a color for font rendering (default: white). */ - + void setFontColor(unsigned char r,unsigned char g,unsigned char b){ 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; + } + /* * Draws a character at the specified coordinates, aborting if the character is unknown. */ - + vec2 putChar(float xx,float yy,char c){ vec2 c1,c2; int x = xx, y = yy; - + /* * Get the width and height of the rendered character. */ - + c1={(float)floor(x)+ftexbl[c-33].x, (float)floor(y)+ftexbl[c-33].y}; c2=ftexwh[c-33]; - + /* * Draw the character: */ - + glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D,ftex[c-33]); 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); @@ -301,28 +311,28 @@ namespace ui { glEnd(); glPopMatrix(); glDisable(GL_TEXTURE_2D); - + /* * return the width. */ - + return ftexad[c-33];//(vec2){c2.x,ftexad[c-33].y}; } - + /* * Draw a string at the specified coordinates. */ - + float putString(const float x,const float y,const char *s){ unsigned int i=0; float xo=x,yo=y; vec2 add; //vec2 off = { (float)floor(x), (float)floor(y) }; - + /* * Loop on each character: */ - + do{ if(i && ((i / 110.0) == (i / 110))){ yo-=fontSize*1.05; @@ -333,7 +343,7 @@ namespace ui { if(i && (i / (float)textWrapLimit == i / textWrapLimit)){ yo -= fontSize * 1.05; xo = x; - + // skip a space if it's there since we just newline'd if(s[i] == ' ') i++; @@ -355,14 +365,14 @@ namespace ui { yo+=add.y; } }while(s[++i]); - + return xo; // i.e. the string width } - + float putStringCentered(const float x,const float y,const char *s){ unsigned int i = 0; float width = 0; - + do{ if(s[i]=='\n'){ // Handle newlines // TODO @@ -375,11 +385,11 @@ namespace ui { width+=ftexwh[i].x+fontSize*.1; } }while(s[++i]); - + putString(floor(x-width/2),y,s); return width; } - + /* * Draw a string in a typewriter-esque fashion. Each letter is rendered as calls are made * to this function. Passing a different string to the function will reset the counters. @@ -391,20 +401,20 @@ namespace ui { linc=0, // Contains the number of letters that should be drawn. size=0; // Contains the full size of the current string. //static char *ret = NULL; - + /* * Create a well-sized buffer if we haven't yet. */ - + if(!ret){ ret = new char[512]; //(char *)calloc(512,sizeof(char)); memset(ret,0,512*sizeof(char)); } - + /* * Reset values if a new string is being passed. */ - + if(strncmp(ret,str,linc-1)){ memset(ret,0,512); // Zero the buffer size=strlen(str); // Set the new target string size @@ -412,58 +422,58 @@ namespace ui { sinc=1; typeOutDone = false; } - + /* * Draw the next letter if necessary. */ - + if(typeOutDone) return str; else if(++sinc==2){ sinc=0; - + strncpy(ret+linc,str+linc,1); // Get next character - + if(linc<size) linc++; else typeOutDone = true; } - + return ret; // The buffered string. } - + /* * Draw a formatted string to the specified coordinates. */ - + float putText(const float x,const float y,const char *str,...){ va_list args; char *buf; float width; - + /* * 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); - + /* * Draw the string, free resources, return the width of the string. */ - + width=putString(x,y,buf); delete[] buf; //free(buf); - + return width; } void dialogBox(const char *name,const char *opt,bool passive,const char *text,...){ @@ -471,32 +481,32 @@ namespace ui { va_list dialogArgs; unsigned int len; char *sopt,*soptbuf; - + dialogPassive = passive; - + /* * Set up the text buffer. */ - + memset(dialogBoxText,0,512); - + /* * Get the text ready for rendering. */ - + len=strlen(name); strcpy(dialogBoxText ,name); strcpy(dialogBoxText+len,": "); len+=2; - + va_start(dialogArgs,text); vsnprintf(dialogBoxText+len,512-len,text,dialogArgs); va_end(dialogArgs); - + /* * Set up option text. */ - + while(dialogOptCount){ if(dialogOptText[dialogOptCount]){ delete[] dialogOptText[dialogOptCount]; //free(dialogOptText[dialogOptCount]); @@ -508,30 +518,30 @@ namespace ui { dialogOptCount = 0; dialogOptChosen = 0; memset(&dialogOptLoc,0,sizeof(float)*12); - + if(opt != NULL){ - + soptbuf = new char[strlen(opt)+1]; strcpy(soptbuf,opt); - + sopt=strtok(soptbuf,":"); while(sopt != NULL){ dialogOptText[dialogOptCount] = new char[strlen(sopt)+1]; //(char *)malloc(strlen(sopt)); strcpy(dialogOptText[dialogOptCount++],sopt); sopt=strtok(NULL,":"); } - + delete[] soptbuf; } - + /* - * Tell draw() that the box is ready. + * Tell draw() that the box is ready. */ - + dialogBoxExists = true; dialogImportant = false; - + if(ret) ret[0] = '\0'; } @@ -541,39 +551,39 @@ namespace ui { std::cout << "Buying and selling on the bi-weekly!" << std::endl; va_list dialogArgs; size_t len; - + dialogPassive = passive; std::cout << "Market Trading: " << trade.quantity[0] << " " << trade.item[0] << " for " << trade.quantity[1] << " " << trade.item[1] << std::endl; merchTrade = trade; - + // 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; merchOptChosen = 0; memset(&dialogOptLoc, 0, sizeof(float) * 12); - + // handle options if desired if(opt){ //std::unique_ptr<char[]> soptbuf (new char[strlen(opt) + 1]); @@ -587,27 +597,27 @@ namespace ui { 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{ //std::thread(dialogAdvance); @@ -663,11 +673,11 @@ namespace ui { unsigned char i; float x,y,tmp; char *rtext; - + if(dialogBoxExists){ - + rtext=typeOut(dialogBoxText); - + if(dialogImportant){ setFontColor(255,255,255); if(dialogPassive){ @@ -688,8 +698,8 @@ namespace ui { 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); @@ -698,10 +708,10 @@ namespace ui { glVertex2f(x-1,y-1-SCREEN_HEIGHT*.6); glVertex2f(x-1,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))); @@ -745,8 +755,8 @@ namespace ui { merchAOptLoc[1][2] = offset.x + (SCREEN_WIDTH / 8.5); for(i = 0; i < 2; i++){ - if(((merchAOptLoc[i][0] < merchAOptLoc[i][2]) ? - (mouse.x > merchAOptLoc[i][0] && mouse.x < merchAOptLoc[i][2]) : + 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){ glColor3ub(255,255, 0); @@ -760,19 +770,19 @@ namespace ui { 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 ){ @@ -780,13 +790,13 @@ namespace ui { 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); @@ -797,14 +807,14 @@ namespace ui { 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); - + rtext=typeOut(dialogBoxText); - + 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]); @@ -821,17 +831,17 @@ namespace ui { } setFontColor(255,255,255); } - + if(strcmp(rtext,dialogBoxText)){ Mix_PlayChannel(1,dialogClick,0); } - + }if(!fadeIntensity){ vec2 hub = { (SCREEN_WIDTH/2+offset.x)-fontSize*10, (offset.y+SCREEN_HEIGHT/2)-fontSize }; - + putText(hub.x,hub.y,"Health: %u/%u",player->health>0?(unsigned)player->health:0, (unsigned)player->maxHealth ); @@ -848,22 +858,34 @@ namespace ui { hub.x+(player->health/player->maxHealth * 150), hub.y+12); } - + /* * 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; - + putStringCentered(hub.x,hub.y,"Current Quests:"); - + for(auto &c : player->qh.current){ 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); } } @@ -875,7 +897,7 @@ namespace ui { updateConfig(); saveConfig(); } - + menuItem createButton(vec2 l, dim2 d, Color c, const char* t, menuFunc f){ menuItem temp; temp.member = 0; @@ -948,7 +970,7 @@ namespace ui { setFontSize(24); updateConfig(); SDL_Event e; - + mouse.x=premouse.x+offset.x-(SCREEN_WIDTH/2); mouse.y=(offset.y+SCREEN_HEIGHT/2)-premouse.y; @@ -984,15 +1006,15 @@ namespace ui { //draw the button background glColor3f(m.button.color.red,m.button.color.green,m.button.color.blue); - glRectf(offset.x+m.button.loc.x, - offset.y+m.button.loc.y, - offset.x+m.button.loc.x + m.button.dim.x, + glRectf(offset.x+m.button.loc.x, + offset.y+m.button.loc.y, + offset.x+m.button.loc.x + m.button.dim.x, offset.y+m.button.loc.y + m.button.dim.y); //draw the button text putStringCentered(offset.x + m.button.loc.x + (m.button.dim.x/2), (offset.y + m.button.loc.y + (m.button.dim.y/2)) - ui::fontSize/2, m.button.text); - + //tests if the mouse is over the button if(mouse.x >= offset.x+m.button.loc.x && mouse.x <= offset.x+m.button.loc.x + m.button.dim.x){ if(mouse.y >= offset.y+m.button.loc.y && mouse.y <= offset.y+m.button.loc.y + m.button.dim.y){ @@ -1047,9 +1069,9 @@ namespace ui { } //draw the background of the slider glColor4f(m.slider.color.red,m.slider.color.green,m.slider.color.blue, .5f); - glRectf(offset.x+m.slider.loc.x, - offset.y+m.slider.loc.y, - offset.x+m.slider.loc.x + m.slider.dim.x, + glRectf(offset.x+m.slider.loc.x, + offset.y+m.slider.loc.y, + offset.x+m.slider.loc.x + m.slider.dim.x, offset.y+m.slider.loc.y + m.slider.dim.y); //draw the slider handle @@ -1070,7 +1092,7 @@ namespace ui { //draw the now combined slider text putStringCentered(offset.x + m.slider.loc.x + (m.slider.dim.x/2), (offset.y + m.slider.loc.y + (m.slider.dim.y/2)) - ui::fontSize/2, outSV); - } + } //test if mouse is inside of the slider's borders if(mouse.x >= offset.x+m.slider.loc.x && mouse.x <= offset.x+m.slider.loc.x + m.slider.dim.x){ if(mouse.y >= offset.y+m.slider.loc.y && mouse.y <= offset.y+m.slider.loc.y + m.slider.dim.y){ @@ -1109,18 +1131,18 @@ namespace ui { *m.slider.var = (((mouse.y-offset.y) - m.slider.loc.y)/m.slider.dim.y)*100; //draw a white box over the handle glColor3f(1.0f,1.0f,1.0f); - glRectf(offset.x+m.slider.loc.x, - offset.y+m.slider.loc.y + (m.slider.sliderLoc * 1.05), - offset.x+m.slider.loc.x + sliderW, + glRectf(offset.x+m.slider.loc.x, + offset.y+m.slider.loc.y + (m.slider.sliderLoc * 1.05), + offset.x+m.slider.loc.x + sliderW, offset.y+m.slider.loc.y + (m.slider.sliderLoc * 1.05) + sliderH); }else{ *m.slider.var = (((mouse.x-offset.x) - m.slider.loc.x)/m.slider.dim.x)*100; //draw a white box over the handle glColor3f(1.0f,1.0f,1.0f); - glRectf(offset.x+m.slider.loc.x + m.slider.sliderLoc, - offset.y+m.slider.loc.y, - offset.x+m.slider.loc.x + (m.slider.sliderLoc + sliderW), + glRectf(offset.x+m.slider.loc.x + m.slider.sliderLoc, + offset.y+m.slider.loc.y, + offset.x+m.slider.loc.x + (m.slider.sliderLoc + sliderW), offset.y+m.slider.loc.y + m.slider.dim.y); } } @@ -1137,7 +1159,7 @@ namespace ui { void takeScreenshot(GLubyte* pixels){ std::vector<GLubyte> bgr (SCREEN_WIDTH * SCREEN_HEIGHT * 3, 0); - + for(uint x = 0; x < SCREEN_WIDTH*SCREEN_HEIGHT*3; x+=3){ bgr[x] = pixels[x+2]; bgr[x+1] = pixels[x+1]; @@ -1197,10 +1219,15 @@ namespace ui { fwrite(&bgr, 1,3*SCREEN_WIDTH*SCREEN_HEIGHT,bmp); delete[] pixels; - + fclose(bmp); } + void closeBox(){ + dialogBoxExists = false; + dialogMerchant = false; + } + void dialogAdvance(void){ unsigned char i; if(!typeOutDone){ @@ -1218,8 +1245,8 @@ namespace ui { } 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]) : + 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; @@ -1227,7 +1254,7 @@ namespace ui { } } } - + EXIT: //if(!dialogMerchant)closeBox(); @@ -1246,28 +1273,29 @@ namespace ui { 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; - + // update mouse coords mouse.x = premouse.x + offset.x - ( SCREEN_WIDTH / 2 ); mouse.y = ( offset.y + SCREEN_HEIGHT / 2 ) - premouse.y; - + while(SDL_PollEvent(&e)){ switch(e.type){ - + // escape - quit game case SDL_QUIT: gameRunning=false; break; - + // mouse movement - update mouse vector case SDL_MOUSEMOTION: premouse.x=e.motion.x; premouse.y=e.motion.y; break; - + // mouse clicks case SDL_MOUSEBUTTONDOWN: // right click advances dialog @@ -1277,10 +1305,22 @@ namespace ui { 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: - + // space - make player jump if ( SDL_KEY == SDLK_SPACE ) { if ( player->ground ) { @@ -1309,11 +1349,11 @@ namespace ui { if((tmp = currentWorld->goWorldLeft(player)) != currentWorld){ tmppos = player->loc; player->loc = oldpos; - + toggleBlackFast(); waitForCover(); player->loc = tmppos; - + currentWorld = tmp; toggleBlackFast(); } @@ -1331,11 +1371,11 @@ namespace ui { if((tmp = currentWorld->goWorldRight(player)) != currentWorld){ tmppos = player->loc; player->loc = oldpos; - + toggleBlackFast(); waitForCover(); player->loc = tmppos; - + currentWorld = tmp; toggleBlackFast(); } @@ -1357,7 +1397,7 @@ namespace ui { } break; case SDLK_i: - /*currentWorld=currentWorld->goWorldBack(player); // Go back a layer if possible + /*currentWorld=currentWorld->goWorldBack(player); // Go back a layer if possible if(tmp!=currentWorld){ currentWorld->detect(player); player->vel.y=.2; @@ -1415,7 +1455,7 @@ namespace ui { /* * KEYUP */ - + case SDL_KEYUP: if(SDL_KEY == SDLK_ESCAPE){ //gameRunning = false; @@ -1450,12 +1490,6 @@ namespace ui { } 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; @@ -1494,16 +1528,16 @@ namespace ui { default: break; } - + if(!left&&!right) player->vel.x=0; - + break; default: break; } } - + // Flush preloaded AI functions if necessary if ( !dialogBoxExists && AIpreaddr.size() ) { while ( !AIpreaddr.empty() ) { @@ -1513,7 +1547,7 @@ namespace ui { } } } - + void toggleBlack(void){ fadeEnable ^= true; fadeWhite = false; @@ -1533,7 +1567,7 @@ namespace ui { fadeEnable ^= true; fadeWhite = true; fadeFast = true; - + Mix_PlayChannel( 1, battleStart, 0 ); } } |