]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
dialog options now function
authorClyne Sullivan <tullivan99@gmail.com>
Sat, 22 Jul 2017 14:09:13 +0000 (10:09 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Sat, 22 Jul 2017 14:09:13 +0000 (10:09 -0400)
include/ui.hpp
src/systems/dialog.cpp
src/ui.cpp
xml/!town2.xml
xml/bobshouse.xml

index 3f0a67ff8b080f7ea68937917fa72e78ff67262c..fa711d260df774d167b35b7a6c9babc8907d62f8 100644 (file)
@@ -32,13 +32,17 @@ public:
        void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) override;
 };
 
-struct OptionDim {
+struct DialogOption {
        float x;
        float y;
        float width;
-};
 
-using DialogOption = std::pair<OptionDim, std::string>;
+       std::string text;
+       std::string value;
+
+       DialogOption(float _x, float _y, float _width, std::string _text, std::string _value)
+               : x(_x), y(_y), width(_width), text(_text), value(_value) {}
+};
 
 class UISystem : public entityx::System<UISystem> {
 private:
@@ -49,7 +53,7 @@ private:
        static std::string dialogText;
        static std::string importantText;
        static std::vector<DialogOption> dialogOptions;
-       static int dialogOptionResult;
+       static std::string dialogOptionResult;
 
 public:
        UISystem(void) {}
@@ -83,12 +87,12 @@ public:
        static float putStringCentered(const vec2& p, const std::string& s, bool print = true);
 
        static void dialogBox(const std::string& n, const std::string& s, ...);
-       static void dialogAddOption(const std::string& o);
+       static void dialogAddOption(const std::string& o, const std::string& value);
        static void dialogImportant(const std::string& s);
 
        static void waitForDialog(void);
        static void advanceDialog(void);
-       static int getDialogResult(void);
+       static std::string getDialogResult(void);
 };
 
 namespace ui {
index f81876096062ae45fa4db6083f1927df0544559e..76c0f93c70b7365b71b27b7123a24c551f70d57e 100644 (file)
@@ -109,14 +109,9 @@ void DialogSystem::receive(const MouseClickEvent &mce)
                                                }
 
                                                auto xxml = exml->FirstChildElement("option");
-                                               std::string options;
-                                               std::vector<int> optionNexts;
                                                if (xxml != nullptr) {
                                                        do {
-                                                               UISystem::dialogAddOption(xxml->StrAttribute("name"));
-
-                                                               options += '\"' + xxml->StrAttribute("name");
-                                                               optionNexts.emplace_back(xxml->IntAttribute("value"));
+                                                               UISystem::dialogAddOption(xxml->StrAttribute("name"), xxml->StrAttribute("value"));
                                                                xxml = xxml->NextSiblingElement();
                                                        } while (xxml != nullptr);
                                                }
@@ -130,15 +125,16 @@ void DialogSystem::receive(const MouseClickEvent &mce)
                                                        while (*++content && isspace(*content));
                                                }
 
-                                               UISystem::dialogBox(name.name, /*options, false,*/ content);
-                                               UISystem::waitForDialog();
+                                               UISystem::dialogBox(name.name, content);
                                                UISystem::waitForDialog();
 
                                                if (!questAssignedText.empty())
                                                        UISystem::dialogImportant("Quest assigned:\n\"" + questAssignedText + "\"");
                                                        //passiveImportantText(5000, ("Quest assigned:\n\"" + questAssignedText + "\"").c_str());
 
-                                               if (exml->QueryIntAttribute("nextid", &newIndex) == XML_NO_ERROR)
+                                               if (!UISystem::getDialogResult().empty())
+                                                       d.index = std::stoi(UISystem::getDialogResult());
+                                               else if (exml->QueryIntAttribute("nextid", &newIndex) == XML_NO_ERROR)
                                                        d.index = newIndex;
                                        }
 
index e16c15c9ffcc27039c675629926cfa87562a50e9..35de60c6493b06f454d8cda3b5323296638cfcc6 100644 (file)
@@ -750,7 +750,7 @@ int  UISystem::fadeIntensity = 0;
 std::string UISystem::dialogText;
 std::string UISystem::importantText;
 std::vector<DialogOption> UISystem::dialogOptions;
-int UISystem::dialogOptionResult;
+std::string UISystem::dialogOptionResult;
 
 void UISystem::fadeToggle(void)
 {
@@ -867,9 +867,9 @@ void UISystem::dialogBox(const std::string& n, const std::string& s, ...)
        ui::ret.clear();
 }
 
-void UISystem::dialogAddOption(const std::string& o)
+void UISystem::dialogAddOption(const std::string& o, const std::string& v)
 {
-       dialogOptions.emplace_back(OptionDim(), o);
+       dialogOptions.emplace_back(0, 0, 0, o, v);
 }
 
 void UISystem::dialogImportant(const std::string& s)
@@ -884,7 +884,7 @@ void UISystem::waitForDialog(void)
                std::this_thread::sleep_for(1ms);
 }
 
-int UISystem::getDialogResult(void)
+std::string UISystem::getDialogResult(void)
 {
        return dialogOptionResult;
 }
@@ -896,11 +896,11 @@ void UISystem::advanceDialog(void)
 
        if (!dialogOptions.empty()) {
                int r = 1;
-               dialogOptionResult = 0;
+               dialogOptionResult.clear();
                for (auto& o : dialogOptions) {
-                       if (ui::mouse.x > o.first.x - o.first.width / 2 && ui::mouse.x < o.first.x + o.first.width / 2 &&
-                               ui::mouse.y > o.first.y && ui::mouse.y < o.first.y + 20) {
-                               dialogOptionResult = r;
+                       if (ui::mouse.x > o.x - o.width / 2 && ui::mouse.x < o.x + o.width / 2 &&
+                               ui::mouse.y > o.y && ui::mouse.y < o.y + 20) {
+                               dialogOptionResult = o.value;
                                break;
                        }
                        r++;
@@ -933,7 +933,7 @@ void UISystem::render(void)
                vec2 p1 (offset.x - game::SCREEN_WIDTH / 2, offset.y - game::SCREEN_HEIGHT / 2);
                vec2 p2 (p1.x + game::SCREEN_WIDTH, p1.y + game::SCREEN_HEIGHT);
 
-        GLfloat backdrop[] = {
+               GLfloat backdrop[] = {
                        p1.x, p1.y, -7.9, 0, 0,
                        p2.x, p1.y, -7.9, 0, 0, 
                        p2.x, p2.y, -7.9, 0, 0,
@@ -947,9 +947,9 @@ void UISystem::render(void)
 
                Colors::black.use();
                glUniform4f(Render::textShader.uniform[WU_tex_color], 1.0f, 1.0f, 1.0f, fadeIntensity / 255.0f);
-        glVertexAttribPointer(Render::textShader.coord, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), backdrop);
-        glVertexAttribPointer(Render::textShader.tex, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), backdrop + 3);
-        glDrawArrays(GL_TRIANGLES, 0, 6);
+               glVertexAttribPointer(Render::textShader.coord, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), backdrop);
+               glVertexAttribPointer(Render::textShader.tex, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), backdrop + 3);
+               glDrawArrays(GL_TRIANGLES, 0, 6);
 
                Render::textShader.disable();
                Render::textShader.unuse();
@@ -965,16 +965,16 @@ void UISystem::render(void)
                if (!dialogOptions.empty()) {
                        float y = where.y - 180;
                        for (auto& o : dialogOptions) {
-                               o.first.x = offset.x;
-                               o.first.y = y;
-                               o.first.width = putStringCentered(vec2(o.first.x, o.first.y), o.second, false);
+                               o.x = offset.x;
+                               o.y = y;
+                               o.width = putStringCentered(vec2(o.x, o.y), o.text, false);
                                y += 20;
 
-                               if (ui::mouse.x > o.first.x - o.first.width / 2 && ui::mouse.x < o.first.x + o.first.width / 2 &&
-                                       ui::mouse.y > o.first.y && ui::mouse.y < y)
+                               if (ui::mouse.x > o.x - o.width / 2 && ui::mouse.x < o.x + o.width / 2 &&
+                                       ui::mouse.y > o.y && ui::mouse.y < y)
                                        FontSystem::setFontColor(255, 255, 0);
 
-                               putStringCentered(vec2(o.first.x, o.first.y), o.second);
+                               putStringCentered(vec2(o.x, o.y), o.text);
                                FontSystem::setFontColor(255, 255, 255);
                        }
                }
index 77ccf513b145e2e3b0811cb024ad623510805839..bea653837cdf70e90c803b5551156024feaf2662 100644 (file)
@@ -1,7 +1,16 @@
 <?xml version="1.0"?>
 <World>
-    <style background="0" bgm="assets/music/embark.wav" folder="assets/style/classic/"/>
-    <generation width="600"/>
-    <time>6000</time>
-    <link left="!town.xml"/>
+       <style background="0" bgm="assets/music/embark.wav" folder="assets/style/classic/">
+               <layer path="bg/bg.png"/>
+               <layer path="bg/bgFarMountain.png"/>
+               <layer path="bg/forestTileFar.png"/>
+               <layer path="bg/forestTileBack.png"/>
+               <layer path="bg/forestTileMid.png"/>
+               <layer path="bg/forestTileFront.png"/>
+               <layer path="bg/dirt.png"/>
+               <layer path="bg/grass.png"/>
+       </style>
+       <generation width="600"/>
+       <time>6000</time>
+       <link left="!town.xml"/>
 </World>
index d79274da82eee51da70f8284963dc40e00d1eb98..e6b87e58cf56ad273e481824ac2b5d094044edb6 100644 (file)
@@ -2,10 +2,19 @@
 <include file="entities.xml"/>
 
 <IndoorWorld>
-       <style background="0" bgm="assets/music/theme_jazz.wav" folder="assets/style/classic/"/>
+       <style background="0" bgm="assets/music/theme_jazz.wav" folder="assets/style/classic/">
+               <layer path="bg/bg.png"/>
+               <layer path="bg/bgFarMountain.png"/>
+               <layer path="bg/forestTileFar.png"/>
+               <layer path="bg/forestTileBack.png"/>
+               <layer path="bg/forestTileMid.png"/>
+               <layer path="bg/forestTileFront.png"/>
+               <layer path="bg/dirt.png"/>
+               <layer path="bg/grass.png"/>
+       </style>
        <house width="800" texture="assets/style/classic/bg/insideWoodHouse.png"/>
-    <generation width="320"/>
-    <time>6000</time>
-    <!--<link outside="town.xml"/>-->
-    <npc name="Bob" hasDialog="false" spawnx="30"/>
+       <generation width="320"/>
+       <time>6000</time>
+       <!--<link outside="town.xml"/>-->
+       <npc name="Bob" hasDialog="false" spawnx="30"/>
 </IndoorWorld>