From 3dfa4f4a5f80fe82f73a28ae33c257341100226d Mon Sep 17 00:00:00 2001
From: drumsetmonkey <abelleisle@roadrunner.com>
Date: Mon, 25 Jan 2016 14:22:34 -0500
Subject: Sliders!

---
 include/ui.h     |  7 +++-
 main.cpp         | 10 ++++--
 src/gameplay.cpp |  8 ++++-
 src/ui.cpp       | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++----
 4 files changed, 111 insertions(+), 12 deletions(-)

diff --git a/include/ui.h b/include/ui.h
index 030c73d..bf9c0ae 100644
--- a/include/ui.h
+++ b/include/ui.h
@@ -37,7 +37,9 @@ struct menuItem{
 			float minValue;
 			float maxValue;
 			const char* text;
-			void* var;
+			float* var;
+
+			float sliderLoc;
 		}slider;
 
 	};
@@ -46,6 +48,7 @@ struct menuItem{
 namespace ui {
 
 	menuItem createButton(vec2 l, dim2 d, Color c, const char* t, menuFunc f);
+	menuItem createSlider(vec2 l, dim2 d, Color c, float min, float max, const char* t, float* v);
 	/**
 	 *	Contains the coordinates of the mouse inside the window.
 	 */
@@ -56,6 +59,7 @@ namespace ui {
 	 *	These flags are used elsewhere.
 	*/
 
+	extern bool oMenu;
 	extern bool pMenu;
 	extern bool menu;
 	extern bool debug;
@@ -121,6 +125,7 @@ namespace ui {
 	*/
 	void quitGame();
 	void quitMenu();
+	void optionsMenuF();
 	void drawMenu(std::vector<menuItem>mi);
 
 
diff --git a/main.cpp b/main.cpp
index 9a71729..14c67c5 100644
--- a/main.cpp
+++ b/main.cpp
@@ -167,7 +167,10 @@ void mainLoop(void);
 
 vec2 offset;																			/*	OFFSET!!!!!!!!!!!!!!!!!!!! */
 
+float shit = 0;
 std::vector<menuItem>pauseMenu;
+std::vector<menuItem>optionsMenu;
+
 
 extern WEATHER weather;
 
@@ -488,8 +491,6 @@ void mainLoop(void){
 	*/
 	
 	currentWorld->update(player,deltaTime);
-
-	MENU:
 	
 	/*
 	 * 	Update debug variables if necessary
@@ -504,6 +505,8 @@ void mainLoop(void){
 		debugY = player->loc.y;
 	}	
 
+	MENU:
+
 	render();	// Call the render loop;
 }
 
@@ -746,7 +749,8 @@ void render(){
 	}
 
 	if(ui::menu){
-		if(ui::pMenu)ui::drawMenu(pauseMenu);
+		if(ui::oMenu)ui::drawMenu(optionsMenu);
+		else if(ui::pMenu)ui::drawMenu(pauseMenu);
 	}
 
 	/*
diff --git a/src/gameplay.cpp b/src/gameplay.cpp
index 562791d..0d7f122 100644
--- a/src/gameplay.cpp
+++ b/src/gameplay.cpp
@@ -10,7 +10,9 @@ using namespace tinyxml2;
 extern World	*currentWorld;
 extern Player	*player;
 
+extern float shit;
 extern std::vector<menuItem>pauseMenu;
+extern std::vector<menuItem>optionsMenu;
 
 extern void mainLoop(void);
 
@@ -217,7 +219,11 @@ void initEverything(void){
 	atexit(destroyEverything);
 
 	pauseMenu.push_back(ui::createButton({-256/2,0},{256,75},{0.0f,0.0f,0.0f}, (const char*)("Resume"), ui::quitMenu));
-	pauseMenu.push_back(ui::createButton({-256/2,-100},{256,75},{0.0f,0.0f,0.0f}, (const char*)("Save and Quit"), ui::quitGame));
+	pauseMenu.push_back(ui::createButton({-256/2,-100},{256,75},{0.0f,0.0f,0.0f}, (const char*)("Options"), ui::optionsMenuF));
+	pauseMenu.push_back(ui::createButton({-256/2,-200},{256,75},{0.0f,0.0f,0.0f}, (const char*)("Save and Quit"), ui::quitGame));
+
+	optionsMenu.push_back(ui::createSlider({-512/2,100}, {512,50}, {0.0f, 0.0f, 0.0f}, 0, 100, (const char*)("Shit"), &shit));
+	//optionsMenu.push_back(ui::createButton({-256/2,-200},{256,75},{0.0f,0.0f,0.0f}, (const char*)("Save and Quit"), );
 }
 
 extern std::vector<int (*)(NPC *)> AIpreload;
diff --git a/src/ui.cpp b/src/ui.cpp
index 37c646b..f865360 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -6,6 +6,8 @@
 
 #define SDL_KEY e.key.keysym.sym
 
+extern std::vector<menuItem>optionsMenu;
+
 extern SDL_Window *window;
 
 /*
@@ -84,6 +86,7 @@ namespace ui {
 	 *	Variety of keydown bools
 	*/
 	bool edown;
+	bool oMenu = false;
 	bool pMenu = false;
 	bool menu = false;
 	
@@ -612,27 +615,70 @@ namespace ui {
 
 	void quitGame(){
 		if(pMenu)pMenu^=pMenu;
+		if(oMenu)oMenu^=oMenu;
 		if(menu)menu^=menu;
 		gameRunning = false;
 	}
 
 	void quitMenu(){
 		if(pMenu)pMenu^=pMenu;
+		if(oMenu)oMenu^=oMenu;
 		if(menu)menu^=menu;
 	}
 
+	void optionsMenuF(){
+		//pMenu = false;
+		oMenu = true;
+		drawMenu(optionsMenu);
+	}
+
 
 	menuItem createButton(vec2 l, dim2 d, Color c, const char* t, menuFunc f){
 		menuItem temp;
 		temp.member = 0;
+
 		temp.button.loc = l;
 		temp.button.dim = d;
 		temp.button.color = c;
+
 		temp.button.text = t;
+
 		temp.button.func = f;
+
+		return temp;
+	}
+
+	menuItem createSlider(vec2 l, dim2 d, Color c, float min, float max, const char* t, float* v){
+		menuItem temp;
+		temp.member = 1;
+
+		temp.slider.loc = l;
+		temp.slider.dim = d;
+		temp.slider.color = c;
+		temp.slider.minValue = min;
+		temp.slider.maxValue = max;
+
+		temp.slider.text = t;
+
+		temp.slider.var = v;
+
+		temp.slider.sliderLoc = *v;
+
 		return temp;
 	}
 
+	char* stradd(const char* a, const char* b){
+		size_t len = strlen(a) + strlen(b);
+		char *ret = (char*)malloc(len * sizeof(char) + 1);
+		*ret = '\0';
+
+		return strcat(strcat(ret,a),b);
+	}
+
+	/*
+	 *	Don't even try to understand this Clyne...
+	*/
+
 	void drawMenu(std::vector<menuItem>mi){
 		SDL_Event e;
 			
@@ -684,15 +730,53 @@ namespace ui {
 						if(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT)) m.button.func();
 					}
 				}
+			}else if(m.member == 1){
+				char outSV[32];
+				sprintf(outSV, "%s: %.1f",m.slider.text, *m.slider.var);
+				float sliderW = m.slider.dim.x * .05;
+				m.slider.sliderLoc = m.slider.minValue + (*m.slider.var/m.slider.maxValue)*(m.slider.dim.x-sliderW);
+				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, 
+							offset.y+m.slider.loc.y + m.slider.dim.y);
+				glColor4f(m.slider.color.red,m.slider.color.green,m.slider.color.blue, 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 + (m.slider.dim.x*.05),
+							offset.y+m.slider.loc.y + m.slider.dim.y);
+				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);
+				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){
+						glColor3f(1.0f,1.0f,1.0f);
+						glBegin(GL_LINE_STRIP);
+							glVertex2f(offset.x+m.slider.loc.x, 					offset.y+m.slider.loc.y);
+							glVertex2f(offset.x+m.slider.loc.x+m.slider.dim.x, 		offset.y+m.slider.loc.y);
+							glVertex2f(offset.x+m.slider.loc.x+m.slider.dim.x, 		offset.y+m.slider.loc.y+m.slider.dim.y);
+							glVertex2f(offset.x+m.slider.loc.x, 					offset.y+m.slider.loc.y+m.slider.dim.y);
+							glVertex2f(offset.x+m.slider.loc.x, 					offset.y+m.slider.loc.y);
+
+							glVertex2f(offset.x+m.slider.loc.x + m.slider.sliderLoc, offset.y+m.slider.loc.y);
+							glVertex2f(offset.x+m.slider.loc.x + (m.slider.sliderLoc + sliderW), offset.y+m.slider.loc.y);
+							glVertex2f(offset.x+m.slider.loc.x + (m.slider.sliderLoc + sliderW), offset.y+m.slider.loc.y+m.slider.dim.y);
+							glVertex2f(offset.x+m.slider.loc.x + m.slider.sliderLoc, offset.y+m.slider.loc.y+m.slider.dim.y);
+							glVertex2f(offset.x+m.slider.loc.x + m.slider.sliderLoc, offset.y+m.slider.loc.y);
+
+						glEnd();
+						if(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT)){
+							*m.slider.var = (((mouse.x-offset.x) - m.slider.loc.x)/m.slider.dim.x)*100;
+							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), 
+										offset.y+m.slider.loc.y + m.slider.dim.y);
+						}
+						if(*m.slider.var >= m.slider.maxValue)*m.slider.var = m.slider.maxValue;
+						else if(*m.slider.var <= m.slider.minValue)*m.slider.var = m.slider.minValue;
+					}
+				}
 			}
 		}
-
-		/*glColor3ub(255,255,255);
-		glBegin(GL_TRIANGLES);
-			glVertex2i(mx		   ,my		  );
-			glVertex2i(mx+HLINE*3.5,my		  );
-			glVertex2i(mx		   ,my-HLINE*3.5);
-		glEnd();*/
 	}
 	void dialogAdvance(void){
 		unsigned char i;
-- 
cgit v1.2.3