From 8a2f08dc35632a9a8e5272a629e0b4770d567c3a Mon Sep 17 00:00:00 2001
From: drumsetmonkey <abelleisle@roadrunner.com>
Date: Thu, 3 Dec 2015 09:29:34 -0500
Subject: New inventory highlight system

---
 include/inventory.h |  3 +++
 src/gameplay.cpp    |  9 ++++----
 src/inventory.cpp   | 66 +++++++++++++++++++++++++++++++++++++++++++++++++----
 src/ui.cpp          | 16 ++++++++++---
 4 files changed, 83 insertions(+), 11 deletions(-)

diff --git a/include/inventory.h b/include/inventory.h
index 18ef6c4..d28a930 100644
--- a/include/inventory.h
+++ b/include/inventory.h
@@ -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
diff --git a/src/gameplay.cpp b/src/gameplay.cpp
index c9c2b1e..fa030c3 100644
--- a/src/gameplay.cpp
+++ b/src/gameplay.cpp
@@ -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);
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));
diff --git a/src/ui.cpp b/src/ui.cpp
index 181803d..31a9056 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -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;}
-- 
cgit v1.2.3