diff options
author | drumsetmonkey <abelleisle@roadrunner.com> | 2015-12-03 09:29:34 -0500 |
---|---|---|
committer | drumsetmonkey <abelleisle@roadrunner.com> | 2015-12-03 09:29:34 -0500 |
commit | 8a2f08dc35632a9a8e5272a629e0b4770d567c3a (patch) | |
tree | a58dd9f26094d7cac7710180f3848d393ac507c5 /src/inventory.cpp | |
parent | bf91141782766f3648b62c6d96528fddb9ae7447 (diff) |
New inventory highlight system
Diffstat (limited to 'src/inventory.cpp')
-rw-r--r-- | src/inventory.cpp | 66 |
1 files changed, 62 insertions, 4 deletions
diff --git a/src/inventory.cpp b/src/inventory.cpp index 73e5e32..e364ce0 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -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)); |