]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
Sliders!
authordrumsetmonkey <abelleisle@roadrunner.com>
Mon, 25 Jan 2016 19:22:34 +0000 (14:22 -0500)
committerdrumsetmonkey <abelleisle@roadrunner.com>
Mon, 25 Jan 2016 19:22:34 +0000 (14:22 -0500)
include/ui.h
main.cpp
src/gameplay.cpp
src/ui.cpp

index 030c73dd728157d3b80b29ba9065f28323c770ec..bf9c0ae3bfb31e3a6563603df330680198b2ccf0 100644 (file)
@@ -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);
 
 
index 9a71729ce68d0036f01859a4c22aa6e076e7303c..14c67c5ff0eeda83e8d0b987790b5e8ec16eddf7 100644 (file)
--- 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);
        }
 
        /*
index 562791d6a676d0d49ab7fdcf1e6d4c1363985d42..0d7f1226d707aedcfabd7d345f7940f9229430ee 100644 (file)
@@ -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;
index 37c646bf03d107db406e550ceb74b60644d74304..f86536079c18873a51c7eb5a6afb2604173f9316 100644 (file)
@@ -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;