]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
Better text boxes
authordrumsetmonkey <abelleisle@roadrunner.com>
Wed, 15 Jun 2016 11:45:30 +0000 (07:45 -0400)
committerdrumsetmonkey <abelleisle@roadrunner.com>
Wed, 15 Jun 2016 11:45:30 +0000 (07:45 -0400)
13 files changed:
assets/dialog_en-us
assets/ui/button_corners.png [new file with mode: 0644]
assets/ui/button_corners_flat.png [new file with mode: 0644]
assets/ui/button_side_borders.png [new file with mode: 0644]
assets/ui/button_side_borders_flat.png [new file with mode: 0644]
assets/ui/button_top_bot_borders.png [new file with mode: 0644]
assets/ui/button_top_bot_borders_flat.png [new file with mode: 0644]
brice.dat
include/ui.hpp
shaders/world.frag
src/ui.cpp
xml/000.xml
xml/playerSpawnHill1_Building1.xml

index dfe7b03f3c164ceb81fc938c34e12df01c58de11..2224aa6871ff95a98c73cf636a37b3c54e15459b 100644 (file)
@@ -4,7 +4,7 @@ I heard if you complete a quest, you'll get a special reward.
 How much wood could a woodchuck chuck if a woodchuck could chuck wood?
 I don't think anyone has ever been able to climb up that hill.
 If you ever see a hole in the ground, watch out; it could mean the end for you.
-Did you know this game has over 5000 lines of code? I didn't. I didn't even know I was in a game until now...
+Did you know this game has over 10000 lines of code? I didn't. I didn't even know I was in a game until now...
 HELP MY CAPS LOCK IS STUCK
 You know, if anyone ever asked me who I wanted to be when I grow up, I would say Abby Ross.
 I want to have the wallpaper in our house changed. It doesn't really fit the environment.
diff --git a/assets/ui/button_corners.png b/assets/ui/button_corners.png
new file mode 100644 (file)
index 0000000..38f0cf9
Binary files /dev/null and b/assets/ui/button_corners.png differ
diff --git a/assets/ui/button_corners_flat.png b/assets/ui/button_corners_flat.png
new file mode 100644 (file)
index 0000000..527500f
Binary files /dev/null and b/assets/ui/button_corners_flat.png differ
diff --git a/assets/ui/button_side_borders.png b/assets/ui/button_side_borders.png
new file mode 100644 (file)
index 0000000..4f0ec6d
Binary files /dev/null and b/assets/ui/button_side_borders.png differ
diff --git a/assets/ui/button_side_borders_flat.png b/assets/ui/button_side_borders_flat.png
new file mode 100644 (file)
index 0000000..ef9dbfe
Binary files /dev/null and b/assets/ui/button_side_borders_flat.png differ
diff --git a/assets/ui/button_top_bot_borders.png b/assets/ui/button_top_bot_borders.png
new file mode 100644 (file)
index 0000000..f78b1e3
Binary files /dev/null and b/assets/ui/button_top_bot_borders.png differ
diff --git a/assets/ui/button_top_bot_borders_flat.png b/assets/ui/button_top_bot_borders_flat.png
new file mode 100644 (file)
index 0000000..431e6b8
Binary files /dev/null and b/assets/ui/button_top_bot_borders_flat.png differ
index 3b090ad887b4d2aa51cf2d99adc0eeaf055a2798..2653f9ce5cd4f99cef1fe2519168885e87cffb42 100644 (file)
--- a/brice.dat
+++ b/brice.dat
@@ -1,7 +1,7 @@
 3
-canSprint
-0
-canJump
-0
 Slow
 1
+canJump
+0
+canSprint
+0
index 7d9b9f545a85b4d97c7b873e7cb9ee2d6f1a2e5b..507a21128535349ef15677744f3d35a5aab99f18 100644 (file)
@@ -108,6 +108,7 @@ namespace ui {
        */
 
        void drawBox(vec2 c1, vec2 c2);
+       void drawNiceBox(vec2 c1, vec2 c2, float z);
        void dialogBox(std::string name, std::string opt, bool passive, std::string text, ...);
        void merchantBox(const char *name,Trade trade,const char *opt,bool passive,const char *text,...);
        void merchantBox();
index 617cbb1ce777852ea690030a546f3b7379117bdd..87d86cad28d9616eda2cc7d42a0f4a8e18385686 100644 (file)
@@ -26,7 +26,6 @@ void main()
                        if (dist < light[i].w) {
                                float attenuation = clamp(1.0f - dist*dist/(light[i].w*light[i].w), 0.0f, 1.0f);
                                attenuation *= attenuation;
-
                                shadeColor += (vec4(attenuation, attenuation, attenuation, 0.0f) * vec4(lightColor[i])) * lightImpact;
                        }
                }
index c5d134e87e287890b3dadb3d9fda2fcc62d4d8b1..8f234dfff18e2fd7f3737cc1832c29247f5ae1ff 100644 (file)
@@ -731,6 +731,163 @@ namespace ui {
         glUseProgram(0);
        }
 
+       void drawNiceBox(vec2 c1, vec2 c2, float z) {
+               // 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");
+               static GLuint box_side =                Texture::loadTexture("assets/ui/button_side_borders.png");
+
+               // the dimensions of the corner textures
+               static dim2 box_corner_dim_t =  Texture::imageDim("assets/ui/button_corners.png");
+               static vec2 box_corner_dim = vec2(box_corner_dim_t.x / 2.0, box_corner_dim_t.y / 2.0);
+               
+               // the amount of bytes to skip in the OpenGL arrays (see below)
+               auto stride = 5 * sizeof(GLfloat);
+       
+               // we always want to make sure c1 is lower left and c2 is upper right
+               if (c1.x > c2.x) std::swap(c1.x, c2.y);
+               if (c1.y > c2.y) std::swap(c1.y, c2.y);
+       
+               // if the box is too small, we will not be able to draw it      
+               if (c2.x - c1.x < (box_corner_dim_t.x)) return;
+               if (c2.y - c1.y < (box_corner_dim_t.y)) return;
+
+
+               GLfloat box_ul[] = {c1.x,                                               c2.y - box_corner_dim.y, z,     0.0f, 0.5f,
+                               c1.x + box_corner_dim.x,        c2.y - box_corner_dim.y, z,     0.5f, 0.5f,
+                               c1.x + box_corner_dim.x,        c2.y,                                    z,     0.5f, 1.0f,
+
+                               c1.x + box_corner_dim.x,        c2.y,                                    z, 0.5f, 1.0f,
+                                       c1.x,                                           c2.y,                                    z, 0.0f, 1.0f,
+                               c1.x,                                           c2.y - box_corner_dim.y, z,     0.0f, 0.5f};
+
+               GLfloat box_ll[] = {c1.x,                                               c1.y,                                    z,     0.0f, 0.0f,
+                               c1.x + box_corner_dim.x,        c1.y,                                    z,     0.5f, 0.0f,
+                               c1.x + box_corner_dim.x,        c1.y + box_corner_dim.y, z,     0.5f, 0.5f,
+
+                               c1.x + box_corner_dim.x,        c1.y + box_corner_dim.y, z, 0.5f, 0.5f,
+                                       c1.x,                                           c1.y + box_corner_dim.y, z, 0.0f, 0.5f,
+                               c1.x,                                           c1.y,                                    z,     0.0f, 0.0f};
+
+               GLfloat box_ur[] = {c2.x - box_corner_dim.x,    c2.y - box_corner_dim.y, z,     0.5f, 0.5f,
+                               c2.x,                                           c2.y - box_corner_dim.y, z,     1.0f, 0.5f,
+                               c2.x,                                           c2.y,                                    z,     1.0f, 1.0f,
+
+                               c2.x,                                           c2.y,                                    z, 1.0f, 1.0f,
+                                       c2.x - box_corner_dim.x,        c2.y,                                    z, 0.5f, 1.0f,
+                               c2.x - box_corner_dim.x,        c2.y - box_corner_dim.y, z,     0.5f, 0.5f};
+
+               GLfloat box_lr[] = {c2.x - box_corner_dim.x,    c1.y,                                    z,     0.5f, 0.0f,
+                               c2.x,                                           c1.y,                                    z,     1.0f, 0.0f,
+                               c2.x,                                           c1.y + box_corner_dim.y, z,     1.0f, 0.5f,
+
+                               c2.x,                                           c1.y + box_corner_dim.y, z, 1.0f, 0.5f,
+                                       c2.x - box_corner_dim.x,        c1.y + box_corner_dim.y, z, 0.0f, 0.5f,
+                               c2.x - box_corner_dim.x,        c1.y,                                    z,     0.5f, 0.0f};
+
+               GLfloat box_l[] =  {c1.x,                                               c1.y + box_corner_dim.y, z, 0.0f, 0.0f,
+                                                       c1.x + box_corner_dim.x,        c1.y + box_corner_dim.y, z, 0.5f, 0.0f,
+                                                       c1.x + box_corner_dim.x,        c2.y - box_corner_dim.y, z, 0.5f, 1.0f,
+
+                                                       c1.x + box_corner_dim.x,        c2.y - box_corner_dim.y, z, 0.5f, 1.0f,
+                                                       c1.x,                                           c2.y - box_corner_dim.y, z, 0.0f, 1.0f,
+                                                       c1.x,                                           c1.y + box_corner_dim.y, z, 0.0f, 0.0f};
+
+               GLfloat box_r[] =  {c2.x - box_corner_dim.x,    c1.y + box_corner_dim.y, z, 0.5f, 0.0f,
+                                                       c2.x,                                           c1.y + box_corner_dim.y, z, 1.0f, 0.0f,
+                                                       c2.x,                                           c2.y - box_corner_dim.y, z, 1.0f, 1.0f,
+
+                                                       c2.x,                                           c2.y - box_corner_dim.y, z, 1.0f, 1.0f,
+                                                       c2.x - box_corner_dim.x,        c2.y - box_corner_dim.y, z, 0.5f, 1.0f,
+                                                       c2.x - box_corner_dim.x,        c1.y + box_corner_dim.y, z, 0.5f, 0.0f};
+
+        GLfloat box_b[] =  {c1.x + box_corner_dim.x,   c1.y,                                    z,     0.0f, 0.0f,
+                                                       c2.x - box_corner_dim.x,        c1.y,                                    z, 1.0f, 0.0f,
+                                                       c2.x - box_corner_dim.x,        c1.y + box_corner_dim.y, z,     1.0f, 0.5f,
+
+                                                       c2.x - box_corner_dim.x,        c1.y + box_corner_dim.y, z,     1.0f, 0.5f,
+                                                       c1.x + box_corner_dim.x,        c1.y + box_corner_dim.y, z, 0.0f, 0.5f,
+                                                       c1.x + box_corner_dim.x,        c1.y,                                    z, 0.0f, 0.0f};
+
+        GLfloat box_t[] =  {c1.x + box_corner_dim.x,   c2.y - box_corner_dim.y, z,     0.0f, 0.5f,
+                                                       c2.x - box_corner_dim.x,        c2.y - box_corner_dim.y, z, 1.0f, 0.5f,
+                                                       c2.x - box_corner_dim.x,        c2.y,                                    z,     1.0f, 1.0f,
+
+                                                       c2.x - box_corner_dim.x,        c2.y,                                    z,     1.0f, 1.0f,
+                                                       c1.x + box_corner_dim.x,        c2.y,                                    z, 0.0f, 1.0f,
+                                                       c1.x + box_corner_dim.x,        c2.y - box_corner_dim.y, z, 0.0f, 0.5f};
+
+               GLfloat box_f[] =  {c1.x + box_corner_dim.x,    c1.y + box_corner_dim.y, z, 0.5f, 0.5f,
+                                                       c2.x - box_corner_dim.x,        c1.y + box_corner_dim.y, z, 0.5f, 0.5f,
+                                                       c2.x - box_corner_dim.x,        c2.y - box_corner_dim.y, z, 0.5f, 0.5f,
+
+                                                       c2.x - box_corner_dim.x,        c2.y - box_corner_dim.y, z, 0.5f, 0.5f,
+                                                       c1.x + box_corner_dim.x,        c2.y - box_corner_dim.y, z, 0.5f, 0.5f,
+                                                       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(textShader_uniform_texture, 0);
+               glUseProgram(textShader);
+
+               glEnableVertexAttribArray(textShader_attribute_coord);
+        glEnableVertexAttribArray(textShader_attribute_tex);
+
+               // draw upper left corner
+        glVertexAttribPointer(textShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, stride, &box_ul[0]);
+        glVertexAttribPointer(textShader_attribute_tex,   2, GL_FLOAT, GL_FALSE, stride, &box_ul[3]);
+        glDrawArrays(GL_TRIANGLES, 0, 6);
+
+               // lower left corner
+        glVertexAttribPointer(textShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, stride, &box_ll[0]);
+        glVertexAttribPointer(textShader_attribute_tex,   2, GL_FLOAT, GL_FALSE, stride, &box_ll[3]);
+        glDrawArrays(GL_TRIANGLES, 0, 6);
+        
+               // upper right corner
+               glVertexAttribPointer(textShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, stride, &box_ur[0]);
+        glVertexAttribPointer(textShader_attribute_tex,   2, GL_FLOAT, GL_FALSE, stride, &box_ur[3]);
+        glDrawArrays(GL_TRIANGLES, 0, 6);
+        
+               // lower right corner
+               glVertexAttribPointer(textShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, stride, &box_lr[0]);
+        glVertexAttribPointer(textShader_attribute_tex,   2, GL_FLOAT, GL_FALSE, stride, &box_lr[3]);
+        glDrawArrays(GL_TRIANGLES, 0, 6);
+
+               // draw the middle of the box
+               glVertexAttribPointer(textShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, stride, &box_f[0]);
+        glVertexAttribPointer(textShader_attribute_tex,   2, GL_FLOAT, GL_FALSE, stride, &box_f[3]);
+        glDrawArrays(GL_TRIANGLES, 0, 6);
+               
+               glBindTexture(GL_TEXTURE_2D, box_side);
+
+               // draw the left edge of the box
+               glVertexAttribPointer(textShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, stride, &box_l[0]);
+        glVertexAttribPointer(textShader_attribute_tex,   2, GL_FLOAT, GL_FALSE, stride, &box_l[3]);
+        glDrawArrays(GL_TRIANGLES, 0, 6);
+
+               // draw right edge of the box
+               glVertexAttribPointer(textShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, stride, &box_r[0]);
+        glVertexAttribPointer(textShader_attribute_tex,   2, GL_FLOAT, GL_FALSE, stride, &box_r[3]);
+        glDrawArrays(GL_TRIANGLES, 0, 6);
+               
+               glBindTexture(GL_TEXTURE_2D, box_side_top);
+
+               // draw bottom of the box
+               glVertexAttribPointer(textShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, stride, &box_b[0]);
+        glVertexAttribPointer(textShader_attribute_tex,   2, GL_FLOAT, GL_FALSE, stride, &box_b[3]);
+        glDrawArrays(GL_TRIANGLES, 0, 6);
+
+               // draw top of the box
+               glVertexAttribPointer(textShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, stride, &box_t[0]);
+        glVertexAttribPointer(textShader_attribute_tex,   2, GL_FLOAT, GL_FALSE, stride, &box_t[3]);
+        glDrawArrays(GL_TRIANGLES, 0, 6);
+
+        glDisableVertexAttribArray(textShader_attribute_coord);
+        glDisableVertexAttribArray(textShader_attribute_tex);
+
+               glUseProgram(0);
+       }
+       
        void draw(void){
                unsigned char i;
                float x,y,tmp;
@@ -800,8 +957,7 @@ namespace ui {
                                x = offset.x - SCREEN_WIDTH / 6;
                                y = (offset.y + SCREEN_HEIGHT / 2) - HLINES(8);
 
-                               drawBox(vec2 {x, y}, vec2 {x + SCREEN_WIDTH / 3, y - SCREEN_HEIGHT * 0.6f});
-
+                               drawNiceBox(vec2(x, y), vec2(x + (SCREEN_WIDTH / 3.0f), y - (SCREEN_HEIGHT * 0.6f)), -7.0f);
                                // draw typeOut'd text
                                putString(x + game::HLINE, y - fontSize - game::HLINE, (rtext = typeOut(dialogBoxText)));
 
@@ -934,7 +1090,7 @@ namespace ui {
                                x = offset.x - SCREEN_WIDTH / 2  + HLINES(8);
                                y = offset.y + SCREEN_HEIGHT / 2 - HLINES(8);
 
-                               drawBox(vec2 {x, y}, vec2 {x + SCREEN_WIDTH - HLINES(16), y - SCREEN_HEIGHT / 4});
+                               drawNiceBox(vec2 {x, y}, vec2 {x + SCREEN_WIDTH - HLINES(16), y - SCREEN_HEIGHT / 4}, -7.0);
 
                                rtext = typeOut(dialogBoxText);
                                putString(x + game::HLINE, y - fontSize - game::HLINE, rtext);
index 9996cec1623cab9150df0ac098b4733ed45d3569..1779b0ce224c4a726922d7f90a3c7af4dfefea0d 100644 (file)
@@ -8,7 +8,7 @@
     <time>3400</time>
     <spawnx>-880</spawnx>
     <trigger spawnx="-850" id="first" notext="1"/>
-    <npc name="Guy" hasDialog="true" spawnx="0" canMove="false" health="1" x="-582.05096" y="65.998985" dindex="9999"/>
+    <npc name="Guy" hasDialog="true" spawnx="0" canMove="false" health="1" x="-582.05096" y="66.298981" dindex="9999"/>
 </World>
 
 <Trigger id="first">Guy</Trigger>
index 0b51b552bec4c2f94886fa79eb09d0680189e7d4..b86fd9fbad3757d56718b116ab3089ff4643c28b 100644 (file)
@@ -10,7 +10,7 @@
 <Dialog name="Bob">
     <text id="0" nextid="1" pause="true">
                Hey. Have a Dank MayMay :)
-                                                                                                                                                                                                                                                                                       <give id="Dank MayMay" count="1"/></text>
+                                                                                                                                               <give id="Dank MayMay" count="1"/></text>
     <text id="1" nextid="2">
                What? You want another Dank MayMay?
        </text>