diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2017-07-22 10:09:13 -0400 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2017-07-22 10:09:13 -0400 |
commit | 132172601e249327d30b3756c9dbfc73cb2b6b0c (patch) | |
tree | a8bf275357e5c4125970359f3714f4a61fa8dbc7 | |
parent | 0649af210afa6e7da051d655c3b28a7cd3b9ebc6 (diff) |
dialog options now function
-rw-r--r-- | include/ui.hpp | 16 | ||||
-rw-r--r-- | src/systems/dialog.cpp | 14 | ||||
-rw-r--r-- | src/ui.cpp | 36 | ||||
-rw-r--r-- | xml/!town2.xml | 17 | ||||
-rw-r--r-- | xml/bobshouse.xml | 19 |
5 files changed, 60 insertions, 42 deletions
diff --git a/include/ui.hpp b/include/ui.hpp index 3f0a67f..fa711d2 100644 --- a/include/ui.hpp +++ b/include/ui.hpp @@ -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 { diff --git a/src/systems/dialog.cpp b/src/systems/dialog.cpp index f818760..76c0f93 100644 --- a/src/systems/dialog.cpp +++ b/src/systems/dialog.cpp @@ -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; } @@ -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); } } diff --git a/xml/!town2.xml b/xml/!town2.xml index 77ccf51..bea6538 100644 --- a/xml/!town2.xml +++ b/xml/!town2.xml @@ -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> diff --git a/xml/bobshouse.xml b/xml/bobshouse.xml index d79274d..e6b87e5 100644 --- a/xml/bobshouse.xml +++ b/xml/bobshouse.xml @@ -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> |