From ed10ef9ede3d397672239c3b3dbe42cc6fbe56b4 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Fri, 28 Oct 2016 09:18:53 -0400 Subject: npc dialog --- src/components.cpp | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'src/components.cpp') diff --git a/src/components.cpp b/src/components.cpp index e00d474..220ecab 100644 --- a/src/components.cpp +++ b/src/components.cpp @@ -6,6 +6,7 @@ #include #include #include +#include void MovementSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) { @@ -245,3 +246,58 @@ if (health != maxHealth) { Render::worldShader.disable(); Render::worldShader.unuse(); }*/ + +void DialogSystem::configure(entityx::EventManager &ev) +{ + ev.subscribe(*this); +} + +void DialogSystem::receive(const MouseClickEvent &mce) +{ + game::entities.each( + [&](entityx::Entity e, Position &pos, Solid &dim, Dialog &d, Name &name) { + (void)e; + (void)d; + + if (((mce.position.x > pos.x) & (mce.position.x < pos.x + dim.width)) && + ((mce.position.y > pos.y) & (mce.position.y < pos.y + dim.height))) { + + std::thread([&] { + auto exml = game::engine.getSystem()->getXML()->FirstChildElement("Dialog"); + int newIndex; + + if (exml != nullptr) { + while (exml->StrAttribute("name") != name.name) + exml = exml->NextSiblingElement(); + + exml = exml->FirstChildElement("text"); + while (exml->IntAttribute("id") != d.index) + exml = exml->NextSiblingElement(); + + auto cxml = exml->FirstChildElement("content"); + if (cxml == nullptr) + return; + + auto content = cxml->GetText() - 1; + while (*++content && isspace(*content)); + + ui::dialogBox(name.name, "", false, content); + ui::waitForDialog(); + + if (exml->QueryIntAttribute("nextid", &newIndex) == XML_NO_ERROR) + d.index = newIndex; + } + }).detach(); + + } + } + ); +} + +void DialogSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) +{ + (void)en; + (void)ev; + (void)dt; +} + -- cgit v1.2.3