From 00de7a4b0aa48c3cb42c45e0f203902ca034b94c Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Thu, 27 Apr 2017 21:28:33 -0400 Subject: important textls --- assets/music/town.ogg | Bin 0 -> 3159813 bytes include/components.hpp | 16 ++++++++++++++++ include/ui.hpp | 2 ++ main.cpp | 4 +++- src/components.cpp | 32 ++++++++++++++++++++++++-------- src/ui.cpp | 22 +++++++++++++++++++--- src/world.cpp | 2 ++ xml/!town.xml | 2 +- xml/entities.xml | 9 +++++++++ 9 files changed, 76 insertions(+), 13 deletions(-) create mode 100644 assets/music/town.ogg diff --git a/assets/music/town.ogg b/assets/music/town.ogg new file mode 100644 index 0000000..0cbe3a7 Binary files /dev/null and b/assets/music/town.ogg differ diff --git a/include/components.hpp b/include/components.hpp index dafb859..87d4293 100644 --- a/include/components.hpp +++ b/include/components.hpp @@ -623,6 +623,22 @@ struct Hit : public Component { } }; +struct Trigger : public Component { + Trigger(const std::string& t) + : text(t) {} + Trigger(XMLElement* imp, XMLElement* def) { + fromXML(imp, def); + } + + std::string text; + + void fromXML(XMLElement* imp, XMLElement* def) final { + (void)imp; + (void)def; + text = "You got me!"; + } +}; + /** * SYSTEMS */ diff --git a/include/ui.hpp b/include/ui.hpp index 456c88a..3f0a67f 100644 --- a/include/ui.hpp +++ b/include/ui.hpp @@ -126,6 +126,8 @@ namespace ui { */ void takeScreenshot(GLubyte *pixels); + + bool handleGLEvent(SDL_Event& e); } #endif // UI_HPP_ diff --git a/main.cpp b/main.cpp index 967050c..a934b40 100644 --- a/main.cpp +++ b/main.cpp @@ -166,8 +166,10 @@ int main(int argc, char *argv[]) Render::render(fps); SDL_Event e; - while (SDL_PollEvent(&e)) + while (SDL_PollEvent(&e)) { + ui::handleGLEvent(e); eventQueue.push_back(e); + } } // on game end, get back together diff --git a/src/components.cpp b/src/components.cpp index d89e195..dcb1551 100644 --- a/src/components.cpp +++ b/src/components.cpp @@ -50,11 +50,9 @@ void MovementSystem::update(entityx::EntityManager &en, entityx::EventManager &e fl = (direction.x < 0); } - // make the entity wander - // TODO initialX and range? - if (entity.has_component()) { - auto ppos = game::engine.getSystem()->getPosition(); - if (ppos.x > position.x && ppos.x < position.x + entity.component()->width) { + auto ppos = game::engine.getSystem()->getPosition(); + if (ppos.x > position.x && ppos.x < position.x + entity.component()->width) { + if (entity.has_component()) { auto dim = entity.component(); ev.emit(vec2(position.x + dim->width, position.y + dim->height), AttackType::ShortSlash, false); @@ -64,9 +62,27 @@ void MovementSystem::update(entityx::EntityManager &en, entityx::EventManager &e toFight = entity; h = 0; }*/ - } else - direction.x = (ppos.x > position.x) ? .01 : -.01; - } else if (entity.has_component()) { + } else if (entity.has_component()) { + static bool triggering = false; + if (!triggering) { + triggering = true; + std::thread([&](entityx::Entity e) { + UISystem::fadeToggle(); + UISystem::waitForCover(); + UISystem::dialogImportant(e.component()->text); + UISystem::waitForDialog(); + UISystem::fadeToggle(); + e.destroy(); + triggering = false; + }, entity).detach(); + } + return; + } + } + + // make the entity wander + // TODO initialX and range? + if (entity.has_component()) { auto& countdown = entity.component()->countdown; if (countdown > 0) { diff --git a/src/ui.cpp b/src/ui.cpp index fc815f2..d14b0a6 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -618,6 +618,20 @@ namespace ui { fclose(bmp); } + + bool handleGLEvent(SDL_Event& e) { + switch (e.type) { + case SDL_MOUSEBUTTONDOWN: + if ((UISystem::isDialog() | pageTexReady) && (e.button.button & SDL_BUTTON_RIGHT)) + UISystem::advanceDialog(); + return true; + break; + default: + break; + } + + return false; + } } using namespace ui; @@ -658,8 +672,6 @@ void InputSystem::receive(const MainSDLEvent& event) case SDL_MOUSEBUTTONDOWN: ev.emit(mouse, e.button.button); - UISystem::advanceDialog(); - if (UISystem::isDialog() || pageTexReady) { if ((e.button.button & SDL_BUTTON_RIGHT)) UISystem::advanceDialog(); @@ -974,6 +986,10 @@ void UISystem::render(void) } if (!importantText.empty()) { - putStringCentered(offset, importantText); + FontSystem::setFontSize(24); + FontSystem::setFontZ(-9.0f); + putStringCentered(vec2(offset.x, 400), importantText); + FontSystem::setFontZ(-6.0f); + FontSystem::setFontSize(16); } } diff --git a/src/world.cpp b/src/world.cpp index 648507a..e251706 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -389,6 +389,8 @@ void WorldSystem::load(const std::string& file) entity.assign(wxml, abcd); else if (tname == "Animation") entity.assign(wxml, abcd); + else if (tname == "Trigger") + entity.assign(wxml, abcd); abcd = abcd->NextSiblingElement(); } diff --git a/xml/!town.xml b/xml/!town.xml index e3fb946..32f696a 100644 --- a/xml/!town.xml +++ b/xml/!town.xml @@ -2,7 +2,7 @@ -