]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
New inventory highlight system
authordrumsetmonkey <abelleisle@roadrunner.com>
Thu, 3 Dec 2015 14:29:34 +0000 (09:29 -0500)
committerdrumsetmonkey <abelleisle@roadrunner.com>
Thu, 3 Dec 2015 14:29:34 +0000 (09:29 -0500)
include/inventory.h
src/gameplay.cpp
src/inventory.cpp
src/ui.cpp

index 18ef6c4f18e744c27a5178883e0feb3fde1fc70b..d28a9304fdedcbfe0799149117d096f3b38823bc 100644 (file)
@@ -74,6 +74,9 @@ public:
        bool invOpen = false;
        bool invOpening = false;
        bool invHover = false;
+       bool selected = false;
+       bool mouseSel = false;
+
 
        Inventory(unsigned int s);      // Creates an inventory of size 's'
        ~Inventory(void);                       // Free's allocated memory
index c9c2b1eb72923b2ef133d5f565e466cce69d7e86..fa030c303b3496c872bb00c8549f46c76a1a0417 100644 (file)
@@ -51,8 +51,7 @@ void CUTSCENEEE(Mob *callee){
 void CUTSCENEEE2(Mob *callee){
        player->vel.x = 0;
        ui::dialogBox(player->name,":Yeah.",
-       "What the fuck is this dead end supposed \
-       to mean, and why this place smells like soap.");
+       "What the fuck is this dead end supposed to mean, and why does this place smell like soap?");
        ui::waitForDialog();
        callee->alive = false;
 }
@@ -120,8 +119,10 @@ void initEverything(void){
        playerSpawnHill->addMob(MS_TRIGGER,-1300,0,CUTSCENEEE);
        
        playerSpawnHill->addObject(SWORD_WOOD, false, "", 480,200);
-       playerSpawnHill->addObject(SWORD_WOOD, false, "", 500,200);
-       playerSpawnHill->addObject(FLASHLIGHT, true, "This looks important, do you want to pick it up?",600,200);
+       playerSpawnHill->addObject(FLASHLIGHT, false, "", 500,200);
+       playerSpawnHill->addObject(PLAYER_BAG, false, "", 520,200);
+       playerSpawnHill->addObject(TEST_ITEM, false, "", 540,200);
+       //playerSpawnHill->addObject(FLASHLIGHT, true, "This looks important, do you want to pick it up?",600,200);
        
        test->addMob(MS_RABBIT,200,100);
        test->addMob(MS_BIRD,-500,500);
index 73e5e32d7f3f76f4e1be7a318989d63160a975bc..e364ce07e1ec41bcfd03f756755d6e44800905f8 100644 (file)
@@ -90,7 +90,6 @@ int Inventory::takeItem(ITEM_ID id,unsigned char count){
 }
 
 void Inventory::draw(void){
-       std::cout << invHover << std::endl;
        unsigned int i=0;
        static unsigned int lop = 0;
        float y,xoff;
@@ -104,6 +103,7 @@ void Inventory::draw(void){
        float angle = float(angleB/2.0f);
        unsigned int a = 0;
        unsigned int end = 0;
+       static vec2 mouseStart = {0,0};
        for(auto &r : iray){
                r.start.x = player->loc.x + (player->width/2);
                r.start.y = player->loc.y + (player->height/2);
@@ -132,14 +132,14 @@ void Inventory::draw(void){
                }
                if(end >= numSlot)invOpen=false;
        }
-       if(invOpen || invHover){
+       if(invOpen){
                for(auto &r : iray){
                        angle=180-(angleB*a) - angleB/2.0f;
                        curCoord[a].x += float((dfp[a]) * cos(angle*PI/180));
                        curCoord[a].y += float((dfp[a]) * sin(angle*PI/180));
                        r.end = curCoord[a];
 
-                       glColor4f(0.0f, 0.0f, 0.0f, ((float)dfp[a]/(float)range)*invHover ? 0.2f : 0.5f);
+                       glColor4f(0.0f, 0.0f, 0.0f, ((float)dfp[a]/(float)range)*0.4f);
                        glBegin(GL_QUADS);
                                glVertex2i(r.end.x-(itemWide/2),                        r.end.y-(itemWide/2));
                                glVertex2i(r.end.x-(itemWide/2)+itemWide,       r.end.y-(itemWide/2));
@@ -150,7 +150,65 @@ void Inventory::draw(void){
                        if(inv[a].count > 0){
                                glEnable(GL_TEXTURE_2D);
                                glBindTexture(GL_TEXTURE_2D, itemtex[inv[a].id]);                       
-                               glColor4f(1.0f, 1.0f, 1.0f, ((float)dfp[a]/(float)range)*invHover ? 0.5f : 1.0f);
+                               glColor4f(1.0f, 1.0f, 1.0f, ((float)dfp[a]/(float)range)*0.8f);
+                               glBegin(GL_QUADS);
+                                       glTexCoord2i(0,1);glVertex2i(r.end.x-(itemWide/2),                      r.end.y-(itemWide/2));
+                                       glTexCoord2i(1,1);glVertex2i(r.end.x-(itemWide/2)+itemWide,     r.end.y-(itemWide/2));
+                                       glTexCoord2i(1,0);glVertex2i(r.end.x-(itemWide/2)+itemWide,     r.end.y-(itemWide/2)+itemWide);
+                                       glTexCoord2i(0,0);glVertex2i(r.end.x-(itemWide/2),                      r.end.y-(itemWide/2)+itemWide);
+                               glEnd();
+                               glDisable(GL_TEXTURE_2D);
+                               ui::putText(r.end.x-(itemWide/2)+(itemWide*.85),r.end.y-(itemWide/1.75),"%d",inv[a].count);
+                       }
+                       a++;
+               }
+       }else if(invHover){
+               static int highlight = 0;
+               std::cout << ui::mouse.x << "," << mouseStart.x  << "," << mouseSel << std::endl;
+               if(!mouseSel){
+                       mouseStart.x = ui::mouse.x;
+                       highlight = sel;
+                       mouseSel=true;
+               }else{
+                       if(ui::mouse.x >= mouseStart.x){
+                               highlight = (ui::mouse.x - mouseStart.x)/45;
+                               if(highlight>numSlot)highlight=numSlot;
+                               if(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_RIGHT)){
+                                       sel = highlight;
+                                       mouseSel=false;
+                                       invHover=false;
+                                       selected = true;
+                               }
+                       }
+                       if(ui::mouse.x < mouseStart.x){
+                               highlight = (mouseStart.x - ui::mouse.x)/45;
+                               if(highlight<0)highlight=0;
+                               if(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_RIGHT)){
+                                       sel = highlight;
+                                       mouseSel=false;
+                                       invHover=false;
+                                       selected = true;
+                               }
+                       }
+               }
+               for(auto &r : iray){
+                       angle=180-(angleB*a) - angleB/2.0f;
+                       curCoord[a].x += float(range) * cos(angle*PI/180);
+                       curCoord[a].y += float(range) * sin(angle*PI/180);
+                       r.end = curCoord[a];
+
+                       glColor4f(0.0f, 0.0f, 0.0f, 0.1f);
+                       glBegin(GL_QUADS);
+                               glVertex2i(r.end.x-(itemWide/2),                        r.end.y-(itemWide/2));
+                               glVertex2i(r.end.x-(itemWide/2)+itemWide,       r.end.y-(itemWide/2));
+                               glVertex2i(r.end.x-(itemWide/2)+itemWide,       r.end.y-(itemWide/2)+itemWide);
+                               glVertex2i(r.end.x-(itemWide/2),                        r.end.y-(itemWide/2)+itemWide);
+                       glEnd();
+
+                       if(inv[a].count > 0){
+                               glEnable(GL_TEXTURE_2D);
+                               glBindTexture(GL_TEXTURE_2D, itemtex[inv[a].id]);                       
+                               glColor4f(1.0f, 1.0f, 1.0f, a == highlight ? 0.4f : 0.2f);
                                glBegin(GL_QUADS);
                                        glTexCoord2i(0,1);glVertex2i(r.end.x-(itemWide/2),                      r.end.y-(itemWide/2));
                                        glTexCoord2i(1,1);glVertex2i(r.end.x-(itemWide/2)+itemWide,     r.end.y-(itemWide/2));
index 181803d499e73b5e92b1362245f7bd2aec367bf3..31a9056dc0ef0f54e3c0420abcb8953979c71583 100644 (file)
@@ -627,8 +627,11 @@ DONE:
                                if(SDL_KEY==SDLK_e){
                                        if(heyOhLetsGo == 0){
                                                heyOhLetsGo = loops;
-                                       }else if(loops - heyOhLetsGo >= 5 && !(player->inv->invOpen)){
+                                               player->inv->mouseSel = false;
+                                       }
+                                       if(loops - heyOhLetsGo >= 2 && !(player->inv->invOpen) && !(player->inv->selected)){
                                                player->inv->invHover=true;
+                                               //heyOhLetsGo = 0;
                                        }
                                }
                                break;
@@ -648,8 +651,15 @@ DONE:
                                                player->inv->invHover = false;
                                                heyOhLetsGo = 0;
                                        }else{
-                                               player->inv->invOpening ^= true;
-                                               heyOhLetsGo = 0;
+                                               if(player->inv->selected == false){
+                                                       player->inv->invOpening ^= true;
+                                                       player->inv->mouseSel = false;
+                                                       heyOhLetsGo = 0;
+                                               }else{
+                                                       player->inv->selected = false;
+                                                       player->inv->mouseSel = false;
+                                                       heyOhLetsGo = 0;
+                                               }
                                        }
                                }
                                if(SDL_KEY==SDLK_RIGHT){player->inv->sel+=1;}