]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
ui menu cleanup
authorClyne Sullivan <tullivan99@gmail.com>
Tue, 10 Jan 2017 00:06:36 +0000 (19:06 -0500)
committerClyne Sullivan <tullivan99@gmail.com>
Tue, 10 Jan 2017 00:06:36 +0000 (19:06 -0500)
include/ui_menu.hpp
main.cpp
src/components.cpp
src/particle.cpp
src/ui.cpp
src/ui_menu.cpp
src/world.cpp

index 8ca9368785f3f6d3fa9cf3aa1dcb9dd887c4ffc2..b45a76d836e4ac95a0599e453a5f9b5691f30491 100644 (file)
@@ -13,28 +13,24 @@ class menuItem {
 public:
        int member;
        Menu *child;
+
+       vec2 loc;
+       dim2 dim;
+       Color color;
+       std::string text;
        //union {
                struct {
-                       vec2 loc;
-                       dim2 dim;
-                       Color color;
-
-                       std::string text;
                        menuFunc func;
                } button;
-               struct {
-                       vec2 loc;
-                       dim2 dim;
-                       Color color;
 
+               struct {
                        float minValue;
                        float maxValue;
             float sliderLoc;
-
-                       std::string text;
                        float *var;
                } slider;
        //};
+
        menuItem(){}
        ~menuItem(){
                //button.text = NULL;
index d2ae4195e053f0ada8c37637362baebb60ae6482..a9ccac85de505e1199adabb2e6f2c6b1e67538ec 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -304,15 +304,17 @@ void render() {
        // TODO add depth
     glEnable(GL_DEPTH_TEST);
 
-       Render::textShader.use();
-               glUniformMatrix4fv(Render::textShader.uniform[WU_transform], 1, GL_FALSE, glm::value_ptr(ortho));
-       glUniform4f(Render::textShader.uniform[WU_tex_color], 1.0, 1.0, 1.0, 1.0);
-       Render::textShader.unuse();
+
     Render::worldShader.use();
                glUniformMatrix4fv(Render::worldShader.uniform[WU_ortho], 1, GL_FALSE, glm::value_ptr(ortho));
                glUniformMatrix4fv(Render::worldShader.uniform[WU_transform], 1, GL_FALSE, glm::value_ptr(glm::mat4(1.0f)));
        Render::worldShader.unuse();
 
+       Render::textShader.use();
+               glUniformMatrix4fv(Render::textShader.uniform[WU_transform], 1, GL_FALSE, glm::value_ptr(ortho));
+       glUniform4f(Render::textShader.uniform[WU_tex_color], 1.0, 1.0, 1.0, 1.0);
+       Render::textShader.unuse();
+
        // draw the world and player
        game::engine.getSystem<WorldSystem>()->render();
        game::engine.getSystem<ParticleSystem>()->render();
index 6f243a791ef208bca6bbdb31a49ceb9e5e9e2642..7e6f204ea79d0b3d8773a43c9845ffae7a55a379 100644 (file)
@@ -96,7 +96,7 @@ void RenderSystem::update(entityx::EntityManager &en, entityx::EventManager &ev,
                        glm::mat4 mov = scale * translate;
                        glUniformMatrix4fv(Render::worldShader.uniform[WU_transform], 1, GL_FALSE, glm::value_ptr(mov));
                }
-               
+
                for (auto &S : sprite.sprite) {
                        auto sp = S.first;
                        auto size = sp.size * game::HLINE;
@@ -137,8 +137,8 @@ void RenderSystem::update(entityx::EntityManager &en, entityx::EventManager &ev,
                        glVertexAttribPointer(Render::worldShader.tex, 2, GL_FLOAT, GL_FALSE, 0 ,tex_coord);
                        glDrawArrays(GL_TRIANGLES, 0, 6);
 
-                       glUniform4f(Render::worldShader.uniform[WU_tex_color], 1.0, 1.0, 1.0, 1.0);
-                       
+                       //glUniform4f(Render::worldShader.uniform[WU_tex_color], 1.0, 1.0, 1.0, 1.0);
+
                        its-=.01;
                }
                glUniformMatrix4fv(Render::worldShader.uniform[WU_transform], 1, GL_FALSE, glm::value_ptr(glm::mat4(1.0f)));
index b97d0e963130903afe32e1f18df5dcc564e3f016..b0b98aeafc9c1d4f2022e5cb45ad9595a71e2407 100644 (file)
@@ -78,6 +78,7 @@ void ParticleSystem::render(void)
                5 * sizeof(GLfloat), reinterpret_cast<void*>(3 * sizeof(GLfloat)));
 
        palette.use();
+       //if(glGetError() != GL_NO_ERROR)abort();
        glDrawArrays(GL_TRIANGLES, 0, parts.size() * 6);
 
        glBindBuffer(GL_ARRAY_BUFFER, 0);
index 09a87bf7faac93b17bed152c5765d03049403fbb..88a314cb01d507a14fb4d41baae4b46fd18997fd 100644 (file)
@@ -275,11 +275,12 @@ namespace ui {
                // draw the character
                glActiveTexture(GL_TEXTURE0);
                glBindTexture(GL_TEXTURE_2D, (*ftex)[c - 33]);
-               glUniform1i(Render::textShader.uniform[WU_texture], 0);
-               glUniform4f(Render::textShader.uniform[WU_tex_color], 1.0f, 1.0f, 1.0f, 1.0f);
 
                Render::textShader.use();
                Render::textShader.enable();
+
+               glUniform4f(Render::textShader.uniform[WU_tex_color], 1.0f, 1.0f, 1.0f, 1.0f);
+
                GLfloat tex_coord[] = {
                        0.0, 1.0,                               //bottom left
                        1.0, 1.0,                               //bottom right
index cbf30befe2b5a2115f95d6523ef9d5e1a7109f28..c0bd3fb8bd31c009d33996d829f63bd0e5776df6 100644 (file)
@@ -73,7 +73,7 @@ void initControls(Menu *m)
        for (const auto &l : cfg) {
                z = static_cast<SDL_Keycode>(std::stoi(l));
                setControl(i, z);
-               m->items[i++].button.text += sym2str(z);
+               m->items[i++].text += sym2str(z);
        }
 }
 
@@ -98,9 +98,9 @@ void setControlF(unsigned int index, menuItem &m)
        while (e.type != SDL_KEYDOWN);
 
        setControl(index, e.key.keysym.sym);
-       deleteWord(m.button.text);
+       deleteWord(m.text);
 
-       m.button.text += sym2str(e.key.keysym.sym);
+       m.text += sym2str(e.key.keysym.sym);
        saveControls();
 }
 
@@ -110,10 +110,10 @@ namespace ui {
             menuItem temp;
 
             temp.member = 0;
-            temp.button.loc = l;
-            temp.button.dim = d;
-            temp.button.color = c;
-            temp.button.text = t;
+            temp.loc = l;
+            temp.dim = d;
+            temp.color = c;
+            temp.text = t;
             temp.button.func = f;
                        temp.child = nullptr;
 
@@ -124,10 +124,10 @@ namespace ui {
             menuItem temp;
 
             temp.member = -1;
-            temp.button.loc = l;
-            temp.button.dim = d;
-            temp.button.color = c;
-            temp.button.text = t;
+            temp.loc = l;
+            temp.dim = d;
+            temp.color = c;
+            temp.text = t;
             temp.button.func = nullptr;
                        temp.child = _child;
 
@@ -138,10 +138,10 @@ namespace ui {
             menuItem temp;
 
             temp.member = -2;
-            temp.button.loc = l;
-            temp.button.dim = d;
-            temp.button.color = c;
-            temp.button.text = t;
+            temp.loc = l;
+            temp.dim = d;
+            temp.color = c;
+            temp.text = t;
             temp.button.func = nullptr;
                        temp.child = nullptr;
 
@@ -152,12 +152,12 @@ namespace ui {
             menuItem temp;
 
             temp.member = 1;
-            temp.slider.loc = l;
-            temp.slider.dim = d;
-            temp.slider.color = c;
+            temp.loc = l;
+            temp.dim = d;
+            temp.color = c;
             temp.slider.minValue = min;
             temp.slider.maxValue = max;
-            temp.slider.text = t;
+            temp.text = t;
             temp.slider.var = v;
             temp.slider.sliderLoc = *v;
                        temp.child = nullptr;
@@ -247,7 +247,6 @@ namespace ui {
                        static const ColorTex back (Color(0, 0, 0, 204));
 
                        //draw the dark transparent background
-            glColor4f(0.0f, 0.0f, 0.0f, .8f);
                        Render::textShader.use();
 
                        back.use();
@@ -261,104 +260,92 @@ namespace ui {
                                // reset the background modifier
                                cMult = 1.0f;
 
+                               vec2 loc (offset.x + m.loc.x, offset.y + m.loc.y);
+                               vec2 end (loc.x + m.dim.x, loc.y + m.dim.y);
+
                                //if the menu is any type of button
                 if (m.member == 0 || m.member == -1 || m.member == -2) {
                     //tests if the mouse is over the button
-                    if (mouse.x >= offset.x+m.button.loc.x && mouse.x <= offset.x+m.button.loc.x + m.button.dim.x) {
-                        if (mouse.y >= offset.y+m.button.loc.y && mouse.y <= offset.y+m.button.loc.y + m.button.dim.y) {
-
-                                                       // set the darkness multiplier
-                                                       cMult = 0.6f;
-
-                            //if the mouse is over the button and clicks
-                            if (clicked) {
-                                switch(m.member) {
-                                    case 0: //normal button
-                                        m.button.func();
-                                        break;
-                                    case -1:
-                                        currentMenu = m.child;
-                                        break;
-                                    case -2:
-                                        currentMenu->gotoParent();
-                                    default:break;
-                                }
+                    if ((mouse.x >= loc.x && mouse.x <= end.x) && (mouse.y >= loc.y && mouse.y <= end.y)) {
+                                               // set the darkness multiplier
+                                               cMult = 0.6f;
+
+                        //if the mouse is over the button and clicks
+                        if (clicked) {
+                            switch(m.member) {
+                                case 0: //normal button
+                                    m.button.func();
+                                    break;
+                                case -1:
+                                    currentMenu = m.child;
+                                    break;
+                                case -2:
+                                    currentMenu->gotoParent();
+                                default:break;
                             }
                         }
                     }
 
-                                       ui::drawNiceBoxColor(vec2(offset.x + m.button.loc.x, offset.y + m.button.loc.y),
-                                                               vec2(offset.x + m.button.loc.x + m.button.dim.x, offset.y + m.button.loc.y + m.button.dim.y), -8.6, Color(cMult, cMult, cMult, 1.0f));
+                                       ui::drawNiceBoxColor(loc, end, -8.6, Color(cMult, cMult, cMult, 1.0f));
                     //draw the button text
-                    putStringCentered(offset.x + m.button.loc.x + (m.button.dim.x/2),
-                                      (offset.y + m.button.loc.y + (m.button.dim.y/2)) - ui::fontSize/2,
-                                      m.button.text);
+                    putStringCentered(loc.x + (m.dim.x / 2),
+                       loc.y + (m.dim.y / 2) - (ui::fontSize / 2),
+                        m.text);
 
                                        //if element is a slider
-                }else if (m.member == 1) {
+                } else if (m.member == 1) {
                     //combining slider text with variable amount
                     char outSV[32];
-                    sprintf(outSV, "%s: %.1f",m.slider.text.c_str(), *m.slider.var);
-
-                    float sliderW, sliderH;
+                    sprintf(outSV, "%s: %.1f",m.text.c_str(), *m.slider.var);
+       
+                    float sliderW = m.dim.x, sliderH = m.dim.y;
+                    m.slider.sliderLoc = m.slider.minValue + (*m.slider.var / m.slider.maxValue);
 
-                    if (m.slider.dim.y > m.slider.dim.x) {
-                        //width of the slider handle
-                        sliderW = m.slider.dim.x;
-                        sliderH = m.slider.dim.y * .05;
+                    if (sliderH > sliderW) {
+                        sliderH *= 0.05f;
                         //location of the slider handle
-                        m.slider.sliderLoc = m.slider.minValue + (*m.slider.var/m.slider.maxValue)*(m.slider.dim.y-sliderW);
-                    }else{
-                        //width of the slider handle
-                        sliderW = m.slider.dim.x * .05;
-                        sliderH = m.slider.dim.y;
+                        m.slider.sliderLoc *= m.dim.y - sliderW;
+                    } else {
+                        sliderW *= 0.05f;
                         //location of the slider handle
-                        m.slider.sliderLoc = m.slider.minValue + (*m.slider.var/m.slider.maxValue)*(m.slider.dim.x-sliderW);
+                        m.slider.sliderLoc *= m.dim.x - sliderW;
                     }
-                    //draw the background of the slider
-                                       ui::drawNiceBoxColor(vec2(offset.x + m.slider.loc.x, offset.y + m.slider.loc.y),
-                                                                vec2(offset.x + m.slider.loc.x + m.slider.dim.x, offset.y + m.slider.loc.y + m.slider.dim.y), -8.6, Color(.5f, .5f, .5f, 1.0f));
-
-                    //test if mouse is inside of the slider's borders
-                    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) {
-
-                                                       // change multiplier background modifier
-                                                       cMult = 0.75f;
 
-                                                       //if we are inside the slider and click it will set the slider to that point
-                            if (SDL_GetMouseState(nullptr, nullptr) & SDL_BUTTON(SDL_BUTTON_LEFT)) {
-                                //change handle location
-                                if (m.slider.dim.y > m.slider.dim.x) {
-                                    *m.slider.var = (((mouse.y-offset.y) - m.slider.loc.y)/m.slider.dim.y)*100;
+                                       ui::drawNiceBoxColor(loc, end, -8.6, Color(.5f, .5f, .5f, 1.0f));
 
-                                                                       cMult = 0.5f;
-                                }else{
-                                    *m.slider.var = (((mouse.x-offset.x) - m.slider.loc.x)/m.slider.dim.x)*100;
-
-                                                                       cMult = 0.5f;
-                                }
-                            }
-
-                            //makes sure handle can't go below or above min and max values
-                            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;
+                    //test if mouse is inside of the slider's borders
+                    if ((mouse.x >= loc.x && mouse.x <= end.x) && (mouse.y >= loc.y && mouse.y <= end.y)) {
+                                               // change multiplier background modifier
+                                               cMult = 0.75f;
+
+                                               //if we are inside the slider and click it will set the slider to that point
+                        if (SDL_GetMouseState(nullptr, nullptr) & SDL_BUTTON(SDL_BUTTON_LEFT)) {
+                            //change handle location
+                            if (m.dim.y > m.dim.x)
+                                *m.slider.var = ((mouse.y-offset.y) - m.loc.y)/m.dim.y * 100;
+                            else
+                                *m.slider.var = ((mouse.x-offset.x) - m.loc.x)/m.dim.x * 100;
+
+                                                       cMult = 0.5f;
                         }
+
+                        //makes sure handle can't go below or above min and max values
+                                               *m.slider.var = std::clamp(*m.slider.var, m.slider.minValue, m.slider.maxValue);
                     }
 
                                        //draw the slider handle
-                                       if (m.slider.dim.y > m.slider.dim.x) {
-                        ui::drawNiceBoxColor(vec2(offset.x+m.slider.loc.x, offset.y+m.slider.loc.y + (m.slider.sliderLoc * 1.05)),
-                                        vec2(offset.x+m.slider.loc.x + sliderW, offset.y+m.slider.loc.y + (m.slider.sliderLoc * 1.05) + sliderH), -8.7, Color(cMult, cMult, cMult, 1.0f));
+                                       if (m.dim.y > m.dim.x) {
+                        ui::drawNiceBoxColor(vec2(loc.x, loc.y + (m.slider.sliderLoc * 1.05)),
+                               vec2(loc.x + sliderW, loc.y + (m.slider.sliderLoc * 1.05) + sliderH), -8.7, Color(cMult, cMult, cMult, 1.0f));
 
                         //draw the now combined slider text
-                        putStringCentered(offset.x + m.slider.loc.x + (m.slider.dim.x/2), (offset.y + m.slider.loc.y + (m.slider.dim.y*1.05)) - ui::fontSize/2, outSV);
-                    }else{
-                        ui::drawNiceBoxColor(vec2(offset.x+m.slider.loc.x+m.slider.sliderLoc, offset.y+m.slider.loc.y),
-                                         vec2(offset.x+m.slider.loc.x + m.slider.sliderLoc + sliderW, offset.y+m.slider.loc.y + sliderH), -8.7, Color(cMult, cMult, cMult, 1.0f));
+                        putStringCentered(loc.x + (m.dim.x/2), (loc.y + (m.dim.y*1.05)) - ui::fontSize/2, outSV);
+                    } else {
+                        ui::drawNiceBoxColor(vec2(loc.x+m.slider.sliderLoc, loc.y),
+                            vec2(loc.x + m.slider.sliderLoc + sliderW, loc.y + sliderH), -8.7, Color(cMult, cMult, cMult, 1.0f));
 
                         //draw the now combined slider text
-                        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);
+                        putStringCentered(loc.x + (m.dim.x/2), (loc.y + (m.dim.y/2)) - ui::fontSize/2, outSV);
                     }
                 }
             }
index 6f31a5b3963803184af456a62b4574820b129150..f54af3ec22d301280f1a024bec60c623a02752c1 100644 (file)
@@ -745,23 +745,18 @@ void WorldSystem::render(void)
        // rendering!!
 
     glActiveTexture(GL_TEXTURE0);
-    glUniform1i(Render::worldShader.uniform[WU_texture], 0);
-
        Render::worldShader.use();
+    glUniform1i(Render::worldShader.uniform[WU_texture], 0);
        glUniform1f(Render::worldShader.uniform[WU_light_impact], 0.0f);
        glUniform4f(Render::worldShader.uniform[WU_ambient], 1.0, 1.0, 1.0, 1.0);
-
     Render::worldShader.enable();
 
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
-
     bgTex(0);
        glUniform4f(Render::worldShader.uniform[WU_tex_color], 1.0, 1.0, 1.0, 1.0);
 
-
        makeWorldDrawingSimplerEvenThoughAndyDoesntThinkWeCanMakeItIntoFunctions(0, back_tex_coord, scrolling_tex_coord, 6);
-
        // no more night bg
        //bgTex++;
        //glUniform4f(Render::worldShader.uniform[WU_tex_color], 1.0, 1.0, 1.0, 1.3 - static_cast<float>(alpha) / 255.0f);
@@ -800,7 +795,6 @@ void WorldSystem::render(void)
 
        glUniform4f(Render::worldShader.uniform[WU_tex_color], 1.0, 1.0, 1.0, 1.0);
        glUniform4f(Render::worldShader.uniform[WU_ambient], ambient.red, ambient.green, ambient.blue, 1.0);
-
        Render::worldShader.unuse();
 
     std::vector<vec3> bg_items;
@@ -832,7 +826,6 @@ void WorldSystem::render(void)
        makeWorldDrawingSimplerEvenThoughAndyDoesntThinkWeCanMakeItIntoFunctions_JustDrawThis(0, bg_items.data(), bg_tex.data(), bg_items.size());
 
     Render::worldShader.unuse();
-
        // draw the remaining layers
        for (int i = 0; i < 4; i++) {
                bgTex++;