]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
UI is now fancy
authordrumsetmonkey <abelleisle@roadrunner.com>
Fri, 25 Nov 2016 23:46:36 +0000 (18:46 -0500)
committerdrumsetmonkey <abelleisle@roadrunner.com>
Fri, 25 Nov 2016 23:46:36 +0000 (18:46 -0500)
include/ui.hpp
src/ui.cpp
src/ui_menu.cpp
src/world.cpp

index 64aa274a18a58ced2c180f52f497f19be2e6c014..5863cf06ac04bb16c2143981efe56b88653f2454 100644 (file)
@@ -120,6 +120,7 @@ namespace ui {
 
        void drawBox(vec2 c1, vec2 c2);
        void drawNiceBox(vec2 c1, vec2 c2, float z);
+       void drawNiceBoxColor(vec2 c1, vec2 c2, float z, Color c);
        void dialogBox(std::string name, std::string opt, bool passive, std::string text, ...);
        void closeBox();
        void waitForDialog(void);
index 5939368860eaea2882d4594fea265867c8a6a77e..d52cbf8b351a93f76335de611bbfb83240e8dc69 100644 (file)
@@ -683,6 +683,10 @@ namespace ui {
        }
 
        void drawNiceBox(vec2 c1, vec2 c2, float z) {
+               drawNiceBoxColor(c1, c2, z, Color(1.0f, 1.0f, 1.0f));
+       }
+
+       void drawNiceBoxColor(vec2 c1, vec2 c2, float z, Color c) {
                // the textures for the box corners
                static GLuint box_corner =              Texture::loadTexture("assets/ui/button_corners.png");
                static GLuint box_side_top =    Texture::loadTexture("assets/ui/button_top_bot_borders.png");
@@ -777,12 +781,14 @@ namespace ui {
                                                        c1.x + box_corner_dim.x,        c1.y + box_corner_dim.y, z, 0.5f, 0.5f};
 
                glActiveTexture(GL_TEXTURE0);
-               glBindTexture(GL_TEXTURE_2D, box_corner);
                glUniform1f(Render::textShader.uniform[WU_texture], 0);
 
                Render::textShader.use();
                Render::textShader.enable();
 
+               glUniform4f(Render::textShader.uniform[WU_tex_color], c.red, c.green, c.blue, c.alpha);
+               glBindTexture(GL_TEXTURE_2D, box_corner);
+               
                // draw upper left corner
         glVertexAttribPointer(Render::textShader.coord, 3, GL_FLOAT, GL_FALSE, stride, &box_ul[0]);
         glVertexAttribPointer(Render::textShader.tex,   2, GL_FLOAT, GL_FALSE, stride, &box_ul[3]);
@@ -1307,6 +1313,11 @@ void InputSystem::update(entityx::EntityManager &en, entityx::EventManager &ev,
                // key presses
                case SDL_KEYDOWN:
                        ev.emit<KeyDownEvent>(SDL_KEY);
+                       switch(SDL_KEY){
+                               case SDLK_t:
+                                       game::time::tick(100);
+                                       break;
+                       }
                        break;
                /*
                 *      KEYUP
index cbe771825cf3e957e31265de94657afb6f7c9fbe..f0660f3748ebf26e8cc113db35607d11457f802b 100644 (file)
@@ -230,15 +230,9 @@ namespace ui {
                 }
             }
 
+                       static float cMult = 1.0f;
                        static GLuint backTex = Texture::genColor(Color(0, 0, 0, 204));
                        //static GLuint bsTex = Texture::genColor(Color(30, 30, 30));
-                       static GLuint border =  Texture::genColor(Color(245, 245, 245));
-
-                       GLfloat line_tex[] = {0.0, 0.0,
-                                                                 1.0, 0.0,
-                                                                 1.0, 1.0,
-                                                                 0.0, 1.0,
-                                                                 0.0, 0.0};
 
                        //draw the dark transparent background
             glColor4f(0.0f, 0.0f, 0.0f, .8f);
@@ -252,44 +246,17 @@ namespace ui {
 
             //loop through all elements of the menu
             for (auto &m : currentMenu->items) {
-                //if the menu is any type of button
+                               // reset the background modifier
+                               cMult = 1.0f;
+                               
+                               //if the menu is any type of button
                 if (m.member == 0 || m.member == -1 || m.member == -2) {
-
-                    //draw the button background
-                    GLuint bsTex = Texture::genColor(Color(m.button.color.red,m.button.color.green,m.button.color.blue));
-
-                                       Render::textShader.use();
-                                       glBindTexture(GL_TEXTURE_2D, bsTex);
-
-                                       Render::drawRect(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);
-                    //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);
-
                     //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) {
-
-                            //if the mouse if over the button, it draws this white outline
-                                                       glBindTexture(GL_TEXTURE_2D, border);
-
-                                                       GLfloat verts[] = {offset.x+m.button.loc.x,                                     offset.y+m.button.loc.y,                                -8.7,
-                                                          offset.x+m.button.loc.x+m.button.dim.x,              offset.y+m.button.loc.y,                                -8.7,
-                                                          offset.x+m.button.loc.x+m.button.dim.x,              offset.y+m.button.loc.y+m.button.dim.y, -8.7,
-                                                          offset.x+m.button.loc.x,                                     offset.y+m.button.loc.y+m.button.dim.y, -8.7,
-                                                          offset.x+m.button.loc.x,                                     offset.y+m.button.loc.y,                                -8.7};
-
-                                                       Render::textShader.use();
-                                                       Render::textShader.enable();
-
-                                                       glVertexAttribPointer(Render::textShader.coord, 3, GL_FLOAT, GL_FALSE, 0, verts);
-                                                       glVertexAttribPointer(Render::textShader.tex, 2, GL_FLOAT, GL_FALSE, 0, line_tex);
-                                                       glDrawArrays(GL_LINE_STRIP, 0, 5);
-
-                                                       Render::textShader.disable();
-                                                       Render::textShader.unuse();
+                                                       
+                                                       // set the darkness multiplier
+                                                       cMult = 0.6f;
 
                             //if the mouse is over the button and clicks
                             if (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT)) {
@@ -308,7 +275,14 @@ namespace ui {
                         }
                     }
 
-                    //if element is a slider
+                                       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));
+                    //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);
+
+                                       //if element is a slider
                 }else if (m.member == 1) {
                     //combining slider text with variable amount
                     char outSV[32];
@@ -330,89 +304,27 @@ namespace ui {
                         m.slider.sliderLoc = m.slider.minValue + (*m.slider.var/m.slider.maxValue)*(m.slider.dim.x-sliderW);
                     }
                     //draw the background of the slider
-                                       Render::textShader.use();
-                    GLuint bsTex = Texture::genColor(Color(m.slider.color.red, m.slider.color.green, m.slider.color.blue, 175));
-                                       GLuint hTex =  Texture::genColor(Color(m.slider.color.red, m.slider.color.green, m.slider.color.blue, 255));
-
-                                       glBindTexture(GL_TEXTURE_2D, bsTex);
-                                       Render::drawRect(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);
-
-                                       //draw the slider handle
-                    glBindTexture(GL_TEXTURE_2D, hTex);
-                                       if (m.slider.dim.y > m.slider.dim.x) {
-                        Render::drawRect(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);
+                                       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));
 
-                        //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{
-                        Render::drawRect(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);
-
-                        //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);
-                    }
                     //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) {
-
-                            //if it is we draw a white border around it
-                            glBindTexture(GL_TEXTURE_2D, border);
-
-                                                       Render::textShader.use();
-                                                       Render::textShader.enable();
-
-                                                       GLfloat box_border[] = {offset.x+m.slider.loc.x,                                        offset.y+m.slider.loc.y,                                -8.8,
-                                                                       offset.x+m.slider.loc.x+m.slider.dim.x,         offset.y+m.slider.loc.y,                                -8.8,
-                                                                       offset.x+m.slider.loc.x+m.slider.dim.x,         offset.y+m.slider.loc.y+m.slider.dim.y, -8.8,
-                                                                       offset.x+m.slider.loc.x,                                        offset.y+m.slider.loc.y+m.slider.dim.y, -8.8,
-                                                                       offset.x+m.slider.loc.x,                                        offset.y+m.slider.loc.y,                                -8.8};
-
-                                                       glVertexAttribPointer(Render::textShader.coord, 3, GL_FLOAT, GL_FALSE, 0, box_border);
-                                                       glVertexAttribPointer(Render::textShader.tex, 2, GL_FLOAT, GL_FALSE, 0, line_tex);
-                                                       glDrawArrays(GL_LINE_STRIP, 0, 5);
-                            if (m.slider.dim.y > m.slider.dim.x) {
-                                //and a border around the slider handle
-                                GLfloat handle_border[] = {offset.x+m.slider.loc.x,              static_cast<GLfloat>(offset.y+m.slider.loc.y + (m.slider.sliderLoc * 1.05)),                          -8.8,
-                                                                                  offset.x+m.slider.loc.x + sliderW, static_cast<GLfloat>(offset.y+m.slider.loc.y + (m.slider.sliderLoc * 1.05)),                              -8.8,
-                                                                                  offset.x+m.slider.loc.x + sliderW, static_cast<GLfloat>(offset.y+m.slider.loc.y + (m.slider.sliderLoc * 1.05) + sliderH),    -8.8,
-                                                                                  offset.x+m.slider.loc.x,           static_cast<GLfloat>(offset.y+m.slider.loc.y + (m.slider.sliderLoc * 1.05) + sliderH),    -8.8,
-                                                                                  offset.x+m.slider.loc.x,           static_cast<GLfloat>(offset.y+m.slider.loc.y + (m.slider.sliderLoc * 1.05)),                              -8.8};
-                                                               glVertexAttribPointer(Render::textShader.coord, 3, GL_FLOAT, GL_FALSE, 0, handle_border);
-                                                               glVertexAttribPointer(Render::textShader.tex, 2, GL_FLOAT, GL_FALSE, 0, line_tex);
-                                                               glDrawArrays(GL_LINE_STRIP, 0, 5);
-                            }else{
-                                //and a border around the slider handle
-                                GLfloat handle_border[] = {offset.x+m.slider.loc.x + m.slider.sliderLoc, offset.y+m.slider.loc.y,                                                      -8.8,
-                                                                                  offset.x+m.slider.loc.x + (m.slider.sliderLoc + sliderW), offset.y+m.slider.loc.y,                           -8.8,
-                                                                                  offset.x+m.slider.loc.x + (m.slider.sliderLoc + sliderW), offset.y+m.slider.loc.y+m.slider.dim.y,-8.8,
-                                                                                  offset.x+m.slider.loc.x + m.slider.sliderLoc, offset.y+m.slider.loc.y+m.slider.dim.y,                        -8.8,
-                                                                                  offset.x+m.slider.loc.x + m.slider.sliderLoc, offset.y+m.slider.loc.y,                                                       -8.8};
-                                                               glVertexAttribPointer(Render::textShader.coord, 3, GL_FLOAT, GL_FALSE, 0, handle_border);
-                                                               glVertexAttribPointer(Render::textShader.tex, 2, GL_FLOAT, GL_FALSE, 0, line_tex);
-                                                               glDrawArrays(GL_LINE_STRIP, 0, 5);
-                            }
-
-
-                                                       Render::textShader.disable();
-
-                            //if we are inside the slider and click it will set the slider to that point
+                    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(NULL, NULL) & 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;
-                                    //draw a white box over the handle
-                                    glBindTexture(GL_TEXTURE_2D, border);
-                                                                       Render::drawRect(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.9);
-
+                                    
+                                                                       cMult = 0.5f;
                                 }else{
                                     *m.slider.var = (((mouse.x-offset.x) - m.slider.loc.x)/m.slider.dim.x)*100;
-                                    //draw a white box over the handle
-                                    glBindTexture(GL_TEXTURE_2D, border);
-                                                                       Render::drawRect(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 + m.slider.dim.y), -8.9);
+                                    
+                                                                       cMult = 0.5f;
                                 }
                             }
 
@@ -420,6 +332,21 @@ namespace ui {
                             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;
                         }
+                    }
+
+                                       //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));
+
+                        //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));
+
+                        //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);
                     }
                 }
             }
index 4a946d75d5ee728c7883fb57be4e01864ad0e2ea..6fc097b050616bb8c8c1e932cbc5bcd3024e6fa0 100644 (file)
@@ -63,7 +63,7 @@ constexpr const float GROUND_HEIGHT_MAXIMUM = 110.0f;
 constexpr const float GROUND_HILLINESS      =  10.0f;
 
 // defines grass height in HLINEs
-constexpr const unsigned int GRASS_HEIGHT = 4;
+const unsigned int GRASS_HEIGHT = HLINES(4);
 
 // the path of the currently loaded XML file, externally referenced in places
 std::string currentXML;
@@ -111,7 +111,7 @@ static const float bgDraw[4][3]={
 
 void WorldSystem::generate(unsigned int width)
 {
-    float geninc = 0;
+       float geninc = 0;
 
     // allocate space for world
     world.data = std::vector<WorldData> (width + GROUND_HILLINESS, WorldData { false, {0, 0}, 0, 0 });
@@ -140,8 +140,8 @@ void WorldSystem::generate(unsigned int width)
            w->groundHeight   = std::clamp(w[-1].groundHeight + geninc, GROUND_HEIGHT_MINIMUM, GROUND_HEIGHT_MAXIMUM);
                w->groundColor    = randGet() % 32 / 8;
                w->grassUnpressed = true;
-               w->grassHeight[0] = (randGet() % 16) / 3 + 2;
-               w->grassHeight[1] = (randGet() % 16) / 3 + 2;
+               w->grassHeight[0] = (randGet() % 16) / 3 + HLINES(2);
+               w->grassHeight[1] = (randGet() % 16) / 3 + HLINES(2);
            }
        }