]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
modernized ui
authorClyne Sullivan <tullivan99@gmail.com>
Thu, 27 Apr 2017 21:40:12 +0000 (17:40 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Thu, 27 Apr 2017 21:40:12 +0000 (17:40 -0400)
22 files changed:
Makefile
include/config.hpp
include/font.hpp [new file with mode: 0644]
include/ui.hpp
include/ui_quest.hpp
include/vector2.hpp
include/world.hpp
main.cpp
src/attack.cpp
src/components.cpp
src/config.cpp
src/engine.cpp
src/font.cpp [new file with mode: 0644]
src/inventory.cpp
src/particle.cpp
src/player.cpp
src/render.cpp
src/ui.cpp
src/ui_menu.cpp
src/world.cpp
xml/!town.xml
xml/entities.xml

index dd821964907396d71375ed01cf8680bb8e236efe..6aa05e2ebebf196561d5ec0b9119eea302955353 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -12,7 +12,7 @@ ifeq ($(TARGET_OS),win32)
               -lSDL2main -lSDL2 -lSDL2_image -lSDL2_mixer -lfreetype
 endif
 
-CXXFLAGS = -ggdb -m$(TARGET_BITS) -std=c++14 -fext-numeric-literals
+CXXFLAGS = -ggdb -m$(TARGET_BITS) -std=c++17 -fext-numeric-literals
 CXXINC   = -Iinclude -Iinclude/freetype -I.
 CXXWARN  = -Wall -Wextra -Werror -pedantic
 
index 13596ffd45be57e7f733f3922f28894ab66174d8..305f61eede1c41c9ffacfe799557285fee3e0d19 100644 (file)
@@ -52,6 +52,8 @@ namespace game {
                 * The path of the folder to load world XML files from.
                 */
                extern std::string xmlFolder;
+
+               extern std::string fontFamily;
                
                /**
                 * Reads the settings file (config/settings.xml) into the game.
diff --git a/include/font.hpp b/include/font.hpp
new file mode 100644 (file)
index 0000000..a520c15
--- /dev/null
@@ -0,0 +1,56 @@
+#ifndef FONT_HPP_
+#define FONT_HPP_
+
+#include <vector>
+#include <map>
+
+#include <color.hpp>
+#include <render.hpp>
+#include <vector2.hpp>
+
+#include <ft2build.h>
+#include FT_FREETYPE_H
+
+struct FT_Info {
+       vec2 wh;
+       vec2 bl;
+       vec2 ad;
+       GLuint tex;
+
+       FT_Info(void)
+               : tex(0) {}
+};
+
+class FontSystem {
+private:
+       static FT_Library ftLibrary;
+       static FT_Face ftFace;
+
+       static std::string fontFamily;
+       static std::map<int, std::vector<FT_Info>> fontData;
+
+       static int currentSize;
+       static Color currentColor;
+       static float currentZ;
+
+public:
+       ~FontSystem(void) {
+               FT_Done_Face(ftFace);
+               FT_Done_FreeType(ftLibrary);
+       }
+
+       static void init(const std::string& ttf);
+       static void setFontSize(int size);
+       static void setFontColor(float r, float g, float b);
+       static void setFontZ(float z = -8.0f);
+
+       static vec2 putChar(float xx, float yy, char c);
+
+       static inline int getSize(void)
+       { return currentSize; }
+
+       static inline auto& getFont(void)
+       { return fontData.at(currentSize); }
+};
+
+#endif // FONT_HPP_
index ac415f57fa1b8476185062a0f129da40b0b0ff82..456c88aed8e827f40ebf0571af0d774774293741 100644 (file)
@@ -32,112 +32,94 @@ public:
        void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) override;
 };
 
-namespace ui {
+struct OptionDim {
+       float x;
+       float y;
+       float width;
+};
 
-       extern bool fadeEnable;
-       extern int fadeIntensity;
+using DialogOption = std::pair<OptionDim, std::string>;
 
-       // the pixel-coordinates of the mouse
-       extern vec2 mouse;
+class UISystem : public entityx::System<UISystem> {
+private:
+       static bool fadeEnable;
+       static bool fadeFast;
+       static int  fadeIntensity;
 
-       // raw mouse values from SDL
-    extern vec2 premouse;
+       static std::string dialogText;
+       static std::string importantText;
+       static std::vector<DialogOption> dialogOptions;
+       static int dialogOptionResult;
 
-       // the currently used font size for text rendering
-       extern unsigned int fontSize;
+public:
+       UISystem(void) {}
 
-       // shows the debug overlay when set to true
-       extern bool debug;
+       void update(entityx::EntityManager& en, entityx::EventManager& ev, entityx::TimeDelta dt) override;
 
-       // shows tracers when set to true (alongside `debug`)
-       extern bool posFlag;
+       static void render(void);
 
-       extern unsigned char dialogOptChosen;
-       extern bool              dialogBoxExists;
-       extern bool              dialogImportant;
-       extern bool              dialogPassive;
+       /***
+        * Fade library
+        */
 
-       extern unsigned int textWrapLimit;
-       extern int fontTransInv;
+       static void fadeToggle(void);
+       static void fadeToggleFast(void);
+       static void waitForCover(void);
+       static void waitForUncover(void);
 
-       /*
-        *      Initializes the FreeType system.
-       */
 
-       void initFonts(void);
-       void initSounds(void);
+       static inline bool isFading(void)
+       { return fadeIntensity != 0; }
 
-       void destroyFonts(void);
+       static inline bool isDialog(void)
+       { return !dialogText.empty() || !importantText.empty(); }
 
-       /*
-        *      Sets the current font/font size.
-       */
+       /**
+        * Text library
+        */
 
-       void setFontFace(const char *ttf);
-       void setFontSize(unsigned int size);
-       void setFontColor(int r, int g, int b, int a);
-       void setFontZ(float z);
+       static void putText(const vec2& p, const std::string& s, ...);
+       static void putString(const vec2& p, const std::string& s, float wrap = 0.12345f);
+       static float putStringCentered(const vec2& p, const std::string& s, bool print = true);
 
-       /*
-        *      Draw a centered string.
-       */
+       static void dialogBox(const std::string& n, const std::string& s, ...);
+       static void dialogAddOption(const std::string& o);
+       static void dialogImportant(const std::string& s);
 
-       float putStringCentered(const float x,const float y,std::string s);
+       static void waitForDialog(void);
+       static void advanceDialog(void);
+       static int getDialogResult(void);
+};
 
-       /*
-        *      Draws a formatted string at the given coordinates.
-       */
+namespace ui {
+       // the pixel-coordinates of the mouse
+       extern vec2 mouse;
 
-       float putText(const float x,const float y,const char *str,...);
+       // raw mouse values from SDL
+    extern vec2 premouse;
 
-       /**
-        * This function is a facility for logic events to draw text; the text
-        * will be prepared then drawn in the render loop.
-        */
-       void putTextL(vec2 c,const char *str, ...);
+       // shows the debug overlay when set to true
+       extern bool debug;
 
-       /*
-        *      Creates a dialogBox text string (format: `name`: `text`). This function simply sets up
-        *      variables that are drawn in ui::draw(). When the dialog box exists player control is
-        *      limited until a right click is given, closing the box.
-       */
+       // shows tracers when set to true (alongside `debug`)
+       extern bool posFlag;
+
+       void initSounds(void);
 
-       void drawBox(vec2 c1, vec2 c2);
        void drawNiceBox(vec2 c1, vec2 c2, float z);
        void drawNiceBoxColor(vec2 c1, vec2 c2, float z, Color c);
-       void dialogBox(std::string name, std::string opt, bool passive, std::string text, ...);
-       void closeBox();
-       void waitForDialog(void);
 
        bool pageExists(void);
        void drawPage(const GLuint& tex);
 
-       void dontTypeOut(void);
-       /*
-        *      Draws a larger string in the center of the screen. Drawing is done inside this function.
-       */
-
-       void importantText(const char *text,...);
-       void passiveImportantText(int duration,const char *text,...);
+       //void importantText(const char *text,...);
+       //void passiveImportantText(int duration,const char *text,...);
 
        /*
         *      Draw various UI elements (dialogBox, player health)
        */
 
        void draw(void);
-       void drawFade(void);
-       void fadeUpdate(void);
-
-       /*
-        *      Toggle the black overlay thing.
-       */
-
-       void toggleBlack(void);
-       void toggleBlackFast(void);
-       void toggleWhite(void);
-       void toggleWhiteFast(void);
-       void waitForCover(void);
-       void waitForUncover(void);
 
        /*
         *  Takes a screenshot of the game
index a46483a3314cc43c8deaa624da6787af00fae87d..d9d17082f924d6c1ee9333a51172d11198aaaa75 100644 (file)
@@ -27,19 +27,19 @@ namespace ui {
                 * Draws the quest UI to the screen, if enabled.
                 */
                void draw(void) {
-                       static unsigned int textWrap = 40;
+//                     static unsigned int textWrap = 40;
 
                        if (!_toggle)
                                return;
 
-                       std::swap(textWrap, ui::textWrapLimit);
+//                     std::swap(textWrap, ui::textWrapLimit);
 
                        float top_y = offset.y + 200;
                        ui::drawNiceBox(vec2 {offset.x - 200, top_y },
                                        vec2 {offset.x + 200, offset.y - 200 },
                                        -0.7f);
 
-                       ui::putStringCentered(offset.x, top_y - 40, "Current Quests:");
+                       UISystem::putStringCentered(vec2(offset.x, top_y - 40), "Current Quests:");
                        
                        /*auto y = top_y - 100;
                        const auto x = offset.x - 180;
@@ -50,7 +50,7 @@ namespace ui {
                                y -= 40; 
                        }*/
 
-                       std::swap(textWrap, ui::textWrapLimit);
+//                     std::swap(textWrap, ui::textWrapLimit);
                }
        }
 }
index beb278707fee81d4fa3ed9c8c6123e3cf6b45a48..77ee7e718cc67ffcdcc9ff128ae0824b9c03561d 100644 (file)
@@ -35,10 +35,20 @@ struct vector2 {
                return vector2<T>(x + v.x, y + v.y);
        }
 
+       template<typename T2>
+       vector2<T> operator+(const vector2<T2>& v) const {
+               return vector2<T>(x + v.x, y + v.y);
+       }
+
        vector2<T> operator+(const T& n) const {
                return vector2<T>(x + n, y + n);
        }
 
+       vector2<T> operator+=(const vector2<T>& v) {
+               x += v.x, y += v.y;
+               return *this;
+       }
+
        // subtraction
        vector2<T> operator-(const vector2<T>& v) const {
                return vector2<T>(x - v.x, y - v.y);
index e47f78f92237024af79fab53cbaca43785f6c703..7d7d016adfa91a18b0d06874cbe1019309a15c36 100644 (file)
@@ -108,36 +108,36 @@ private:
        /**
         * The world's data.
         */
-       WorldData2 world;
+       static WorldData2 world;
 
        /**
         * SDL's object for handling the background music.
         */
-       Mix_Music *bgmObj;
-       std::string bgmCurrent;
+       static Mix_Music *bgmObj;
+       static std::string bgmCurrent;
 
        /**
         * Paths of files to get stylized textures from.
         */
-       std::vector<std::string> bgFiles;
+       static std::vector<std::string> bgFiles;
 
        /**
         * Allows for iteration between background textures, for rendering.
         */
-       TextureIterator bgTex;
+       static TextureIterator bgTex;
 
        /**
         * An object to handle and parse world XML files.
         */
-       XMLDocument xmlDoc;
+       static XMLDocument xmlDoc;
 
        /**
         * The file path to the currently loaded world.
         */
-       std::string currentXMLFile;
+       static std::string currentXMLFile;
 
 public:
-       std::thread thAmbient;
+       static std::thread thAmbient;
 
        explicit WorldSystem(void);
        ~WorldSystem(void);
@@ -146,37 +146,32 @@ public:
                ev.subscribe<BGMToggleEvent>(*this);
        }
 
-       inline XMLDocument* getXML(void)
+       static inline XMLDocument* getXML(void)
        { return &xmlDoc; }
 
-       inline float getWidth(void) const
+       static inline float getWidth(void) //const
        { return world.startX * -2.0f; }
 
-       float isAboveGround(const vec2& p) const;
+       static inline const std::string& getXMLFile(void) //const
+       { return currentXMLFile; }
 
-       void receive(const BGMToggleEvent &bte);
+       static float isAboveGround(const vec2& p); //const;
 
+       void receive(const BGMToggleEvent &bte);
        void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) override;
-       void render(void);
+       static void render(void);
 
-       inline const std::string& getXMLFile(void) const
-       { return currentXMLFile; }
 
        void detect(entityx::TimeDelta dt);
 
-       void goWorldLeft(Position& p);
-       void goWorldRight(Position& p, Solid &d);
-       void goWorldPortal(Position& p);
-
-       // worlddata2 stuff
-       WorldData2 worldData;
+       static void goWorldLeft(Position& p);
+       static void goWorldRight(Position& p, Solid &d);
+       static void goWorldPortal(Position& p);
 
-       void generate(int width = 0);
-       //void addHole(const unsigned int& start, const unsigned int& end);
-       //void addHill(const ivec2& peak, const unsigned int& width);
+       static void generate(int width = 0);
 
-       bool save(void);
-       void load(const std::string& file);
+       static bool save(void);
+       static void load(const std::string& file);
 
        void fight(entityx::Entity entity);
 };
index 2cc578646e48cfd6a76e18c76675fec1039db39a..967050ced5ade29ccf5d304ae0bc55cb2bc057eb 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -17,6 +17,7 @@ using namespace std::literals::chrono_literals;
 #include <engine.hpp>
 #include <error.hpp>
 #include <fileio.hpp>
+#include <font.hpp>
 #include <gametime.hpp>
 #include <window.hpp>
 #include <world.hpp>
@@ -95,16 +96,15 @@ int main(int argc, char *argv[])
        }
 
        // either load the given XML, or find one
-       auto worldSys = game::engine.getSystem<WorldSystem>();
        if (!worldActuallyUseThisXMLFile.empty()) {
-               worldSys->load(worldActuallyUseThisXMLFile);
+               WorldSystem::load(worldActuallyUseThisXMLFile);
        } else {
                // load the first valid XML file for the world
                for (const auto &xf : xmlFiles) {
                        if (xf[0] != '.') {
                                // read it in
                                std::cout << "File to load: " << xf << '\n';
-                               worldSys->load(xf);
+                               WorldSystem::load(xf);
                                break;
                        }
                }
@@ -133,9 +133,6 @@ int main(int argc, char *argv[])
                                extern int worldShade; // TODO kill
                                worldShade = 50 * sin((game::time::getTickCount() + (DAY_CYCLE / 2)) / (DAY_CYCLE / PI));
 
-                               // update fades
-                               //ui::fadeUpdate();
-
                                // increment game ticker
                                game::time::tick();
                        }
@@ -157,10 +154,10 @@ int main(int argc, char *argv[])
                        std::this_thread::sleep_for(1s);
                });
 
-               GameThread gtFade ([&] {
+               /*GameThread gtFade ([&] {
                        ui::fadeUpdate();
                        std::this_thread::sleep_for(20ms);
-               });
+               });*/
 
                // the render loop, renders
                const bool &run = game::engine.shouldRun;
@@ -176,19 +173,18 @@ int main(int argc, char *argv[])
                // on game end, get back together
                gtMain.stop();
                gtDebug.stop();
-               gtFade.stop();
+               //gtFade.stop();
                //game::engine.getSystem<WorldSystem>()->thAmbient.join(); // segfault or something
        }
 
        // save
        game::briceSave();
-       worldSys->save();
+       WorldSystem::save();
 
        // exit
     Mix_HaltMusic();
     Mix_CloseAudio();
 
-       ui::destroyFonts();
     unloadTextures();
 
        game::engine.getSystem<WindowSystem>()->die();
index e1ce45c12edbe1fa768edd34d6e175adf962f119..e91b4cd19b231158ccc650f4383b2a9817e1e3d1 100644 (file)
@@ -48,7 +48,7 @@ void AttackSystem::update(entityx::EntityManager& en, entityx::EventManager& ev,
                                game::engine.getSystem<ParticleSystem>()->addMultiple(15, ParticleType::SmallBlast,
                                        [&](){ return vec2(pos.x + dim.width / 2, pos.y + dim.height / 2); }, 300, 7);
                                die = !hit.pierce;
-                       } else if (game::engine.getSystem<WorldSystem>()->isAboveGround(vec2(ppos.x, ppos.y - 5)))
+                       } else if (WorldSystem::isAboveGround(vec2(ppos.x, ppos.y - 5)))
                                die = true;
                });
 
index 14599c2303c0b772f9f95fb2a1fba586b71f8c61..d89e195eb90a5eeb705f04429f8afff2758dfe24 100644 (file)
@@ -8,6 +8,7 @@
 #include <ui.hpp>
 #include <engine.hpp>
 #include <error.hpp>
+#include <font.hpp>
 #include <world.hpp>
 #include <brice.hpp>
 #include <quest.hpp>
@@ -23,7 +24,7 @@ static std::vector<std::string> randomDialog (readFileA("assets/dialog_en-us"));
 
 void MovementSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt)
 {
-       bool fight = false;
+       //bool fight = false;
        entityx::Entity toFight;
 
        (void)ev;
@@ -78,12 +79,12 @@ void MovementSystem::update(entityx::EntityManager &en, entityx::EventManager &e
                }
        });
 
-       if (fight) {
-               ui::toggleWhiteFast();
-               ui::waitForCover();
-               game::engine.getSystem<WorldSystem>()->fight(toFight);
-               ui::toggleWhiteFast();
-       }
+//     if (fight) {
+//             UISystem::fadeToggleFast();
+//             UISystem::waitForCover();
+               //game::engine.getSystem<WorldSystem>()->fight(toFight);
+//             UISystem::fadeToggleFast();
+//     }
 }
 
 void PhysicsSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt)
@@ -209,8 +210,8 @@ void RenderSystem::render(void)
        game::entities.each<Visible, Position, Solid, Name>([](entityx::Entity e, Visible &v, Position &pos, Solid& dim, Name &name) {
                (void)e;
                (void)v;
-               ui::setFontZ(-5.0);
-               ui::putStringCentered(pos.x + dim.width / 2, pos.y - ui::fontSize - HLINES(0.5), name.name);
+               FontSystem::setFontZ(-5.0f);
+               UISystem::putStringCentered(vec2(pos.x + dim.width / 2, pos.y - FontSystem::getSize() - HLINES(0.5)), name.name);
        });
 }
 
@@ -236,15 +237,15 @@ void DialogSystem::receive(const MouseClickEvent &mce)
                                        std::string questAssignedText;
                                        int newIndex;
 
-                                       auto exml = game::engine.getSystem<WorldSystem>()->getXML()->FirstChildElement("Dialog");
+                                       auto exml = WorldSystem::getXML()->FirstChildElement("Dialog");
                                        dialogRun.store(true);
 
                                        if (e.has_component<Direction>())
                                                d.talking = true;
 
                                        if (d.index == 9999) {
-                                               ui::dialogBox(name.name, "", false, randomDialog[d.rindex % randomDialog.size()]);
-                                               ui::waitForDialog();
+                                               UISystem::dialogBox(name.name, /*"", false,*/ randomDialog[d.rindex % randomDialog.size()]);
+                                               UISystem::waitForDialog();
                                        } else if (exml != nullptr) {
                                                while (exml->StrAttribute("name") != name.name)
                                                        exml = exml->NextSiblingElement();
@@ -290,8 +291,8 @@ void DialogSystem::receive(const MouseClickEvent &mce)
                                                                                if (qname != nullptr && qsys->finish(qname) == 0) {
                                                                                        d.index = 9999;
                                                                                } else {
-                                                                                       ui::dialogBox(name.name, "", false, "Finish my quest u nug");
-                                                                                       ui::waitForDialog();
+                                                                                       UISystem::dialogBox(name.name, /*"", false,*/ "Finish my quest u nug");
+                                                                                       UISystem::waitForDialog();
                                                                                        return;
                                                                                }
                                                                        //      oldidx = d.index;
@@ -307,6 +308,8 @@ void DialogSystem::receive(const MouseClickEvent &mce)
                                                std::vector<int> optionNexts;
                                                if (xxml != nullptr) {
                                                        do {
+                                                               UISystem::dialogAddOption(xxml->StrAttribute("name"));
+
                                                                options += '\"' + xxml->StrAttribute("name");
                                                                optionNexts.emplace_back(xxml->IntAttribute("value"));
                                                                xxml = xxml->NextSiblingElement();
@@ -322,11 +325,13 @@ void DialogSystem::receive(const MouseClickEvent &mce)
                                                        while (*++content && isspace(*content));
                                                }
 
-                                               ui::dialogBox(name.name, options, false, content);
-                                               ui::waitForDialog();
+                                               UISystem::dialogBox(name.name, /*options, false,*/ content);
+                                               UISystem::waitForDialog();
+                                               UISystem::waitForDialog();
 
                                                if (!questAssignedText.empty())
-                                                       ui::passiveImportantText(5000, ("Quest assigned:\n\"" + questAssignedText + "\"").c_str());
+                                                       UISystem::dialogImportant("Quest assigned:\n\"" + questAssignedText + "\"");
+                                                       //passiveImportantText(5000, ("Quest assigned:\n\"" + questAssignedText + "\"").c_str());
 
                                                if (exml->QueryIntAttribute("nextid", &newIndex) == XML_NO_ERROR)
                                                        d.index = newIndex;
index 844bf3962c85e55de9f72d9c5cb819d2389ad7d8..7f0af00a8dea89e86c8ab8a64a4203d0af31698c 100644 (file)
@@ -22,6 +22,7 @@ namespace game {
                float VOLUME_SFX;
 
                std::string xmlFolder;
+               std::string fontFamily;
 
                void read(void) {
                        xml.LoadFile("config/settings.xml");
@@ -49,8 +50,8 @@ namespace game {
                        if (xmlFolder.empty())
                                xmlFolder = "xml/";
 
-                       ui::initFonts();
-                       ui::setFontFace(xml.FirstChildElement("font")->Attribute("path"));
+                       // FONT SETUP
+                       fontFamily = xml.FirstChildElement("font")->Attribute("path");
 
                        if (xml.FirstChildElement("debug"))
                                ui::debug = ui::posFlag = true;
index 640356e3f3fde0f1dd860818799f47eac93651d2..dc7aa775f990f955ceb10a5fcd75710ee9d4e874 100644 (file)
@@ -1,6 +1,7 @@
 #include <engine.hpp>
 
 #include <config.hpp>
+#include <font.hpp>
 #include <world.hpp>
 #include <window.hpp>
 #include <ui.hpp>
@@ -38,8 +39,17 @@ void Engine::init(void) {
        systems.add<WeatherSystem>();
        systems.add<AttackSystem>();
 
+       systems.add<UISystem>();
+
     systems.configure();
 
+       // init ui
+
+       FontSystem::init(game::config::fontFamily);
+       FontSystem::setFontSize(16);
+       FontSystem::setFontColor(1, 1, 1);
+       FontSystem::setFontZ(-6.0f);
+
     ui::initSounds();
        ui::menu::init();
        game::config::update();
@@ -57,6 +67,7 @@ void Engine::update(entityx::TimeDelta dt)
        systems.update<WeatherSystem>(dt);
        systems.update<ParticleSystem>(dt);
        systems.update<AttackSystem>(dt);
+       //systems.update<UISystem>(dt);
 }
 
 
diff --git a/src/font.cpp b/src/font.cpp
new file mode 100644 (file)
index 0000000..adffa9c
--- /dev/null
@@ -0,0 +1,131 @@
+#include <font.hpp>
+
+FT_Library FontSystem::ftLibrary;
+FT_Face FontSystem::ftFace;
+
+std::string FontSystem::fontFamily;
+std::map<int, std::vector<FT_Info>> FontSystem::fontData;
+
+int FontSystem::currentSize = 0;
+Color FontSystem::currentColor;
+float FontSystem::currentZ = -8.0f;
+
+void FontSystem::init(const std::string& ttf)
+{
+       FT_Init_FreeType(&ftLibrary);
+       FT_New_Face(ftLibrary, ttf.c_str(), 0, &ftFace);
+}
+
+void FontSystem::setFontSize(int size)
+{
+       auto result = fontData.try_emplace(size, 93);
+       if (result.second) {
+               FT_Set_Pixel_Sizes(ftFace, 0, size);
+
+               char c = 33;
+               for (auto& d : fontData.at(size)) {
+                       glDeleteTextures(1, &d.tex);
+                       glGenTextures(1, &d.tex);    // Generate new texture name/locations?
+
+                       // load the character from the font family file
+                       FT_Load_Char(ftFace, c++, FT_LOAD_RENDER);
+
+                       // transfer the character's bitmap (?) to a texture for rendering
+                       glBindTexture(GL_TEXTURE_2D, d.tex);
+                       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S , GL_CLAMP_TO_EDGE);
+                       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T , GL_CLAMP_TO_EDGE);
+                       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER , GL_LINEAR);
+                       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER , GL_LINEAR);
+                       glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+
+                       /**
+                        * The just-created texture will render red-on-black if we don't do anything to it, so
+                        * here we create a buffer 4 times the size and transform the texture into an RGBA array,
+                        * making it white-on-black.
+                        */
+                       auto& g = ftFace->glyph;
+                       std::vector<uint32_t> buf (g->bitmap.width * g->bitmap.rows, 0xFFFFFFFF);
+                       for (auto j = buf.size(); j--;)
+                               buf[j] ^= !g->bitmap.buffer[j] ? buf[j] : 0;
+
+                       d.wh.x = g->bitmap.width;
+                       d.wh.y = g->bitmap.rows;
+                       d.bl.x = g->bitmap_left;
+                       d.bl.y = g->bitmap_top;
+                       d.ad.x = g->advance.x >> 6;
+                       d.ad.y = g->advance.y >> 6;
+                       glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, g->bitmap.width, g->bitmap.rows,
+                               0, GL_RGBA, GL_UNSIGNED_BYTE, buf.data());
+               }
+       }
+
+       currentSize = size;
+}
+
+void FontSystem::setFontColor(float r, float g, float b)
+{
+       currentColor.red = r;
+       currentColor.green = g;
+       currentColor.blue = b;
+}
+
+void FontSystem::setFontZ(float z)
+{
+       currentZ = z;
+}
+
+vec2 FontSystem::putChar(float xx, float yy, char c)
+{
+       const auto& ch = fontData.at(currentSize)[c - 33];
+       int x = xx, y = yy;
+
+       // get dimensions of the rendered character
+       vec2 c1 = {
+               static_cast<float>(floor(x) + ch.bl.x),
+               static_cast<float>(floor(y) + ch.bl.y)
+       };
+       const auto& c2 = ch.wh;
+
+       Render::textShader.use();
+       Render::textShader.enable();
+
+       // draw the character
+       glActiveTexture(GL_TEXTURE0);
+       glBindTexture(GL_TEXTURE_2D, ch.tex);
+
+       glUniform4f(Render::textShader.uniform[WU_tex_color], 1.0f, 1.0f, 1.0f, 1.0f);
+
+       GLfloat tex_coord[] = {
+               0.0, 1.0, // bottom left
+               1.0, 1.0, // bottom right
+               1.0, 0.0, // top right
+               1.0, 0.0, // top right
+               0.0, 0.0, // top left
+               0.0, 1.0, // bottom left
+       };
+
+       GLfloat text_vert[] = {
+               c1.x,        c1.y - c2.y, currentZ,        // bottom left
+               c1.x + c2.x, c1.y - c2.y, currentZ,        // bottom right
+               c1.x + c2.x, c1.y + c2.y - c2.y, currentZ, // top right
+               c1.x + c2.x, c1.y + c2.y - c2.y, currentZ, // top right
+               c1.x,        c1.y + c2.y - c2.y, currentZ, // top left
+               c1.x,        c1.y - c2.y, currentZ         // bottom left
+       };
+
+       glUniform4f(Render::textShader.uniform[WU_tex_color],
+               currentColor.red, currentColor.green, currentColor.blue, currentColor.alpha);
+
+       glVertexAttribPointer(Render::textShader.coord, 3, GL_FLOAT, GL_FALSE, 0, text_vert);
+       glVertexAttribPointer(Render::textShader.tex, 2, GL_FLOAT, GL_FALSE, 0, tex_coord);
+       glDrawArrays(GL_TRIANGLES, 0, 6);
+
+       glUniform4f(Render::textShader.uniform[WU_tex_color], 1.0, 1.0, 1.0, 1.0); 
+
+       Render::textShader.disable();
+       Render::textShader.unuse();
+
+       // return the width.
+       return ch.ad;
+}
+
index 664d8a64cf2ca5f01ee0a7766c75e2eb7a563ca2..f307de27d7d4213cf2f78c1a67bdf6940f041316 100644 (file)
@@ -4,6 +4,7 @@
 #include <components.hpp>
 #include <engine.hpp>
 #include <error.hpp>
+#include <font.hpp>
 #include <player.hpp>
 #include <render.hpp>
 #include <ui.hpp>
@@ -126,9 +127,9 @@ void InventorySystem::render(void)
                        if (n == movingItem)
                                glUniform4f(Render::textShader.uniform[WU_tex_color], .8, .8, 1, .8);
                        glDrawArrays(GL_TRIANGLES, 0, 6);
-                       ui::setFontZ(inventoryZ - 0.3); // TODO fix z's
-                       ui::putText(i.loc.x, i.loc.y, std::to_string(i.count).c_str());
-                       ui::setFontZ(-6);
+                       FontSystem::setFontZ(inventoryZ - 0.3); // TODO fix z's
+                       UISystem::putString(i.loc, std::to_string(i.count));
+                       FontSystem::setFontZ(-6);
                        glUniform4f(Render::textShader.uniform[WU_tex_color], 1, 1, 1, 1);
                }
        }
index 02f36401375b22e6b768ada1ef2efc67cb023049..a546c0c4feb3f71c82e77e2ece6d005a365b0b72 100644 (file)
@@ -98,8 +98,6 @@ void ParticleSystem::update(entityx::EntityManager &en, entityx::EventManager &e
        (void)en;
        (void)ev;
 
-       auto& worldSystem = *game::engine.getSystem<WorldSystem>();
-
        for (unsigned int i = 0; i < parts.size(); i++) {
                auto& p = parts[i];
                auto& vel = p.velocity;
@@ -160,7 +158,7 @@ void ParticleSystem::update(entityx::EntityManager &en, entityx::EventManager &e
                p.location.y += vel.y * dt;
 
                // world collision
-               auto height = worldSystem.isAboveGround(p.location);
+               auto height = WorldSystem::isAboveGround(p.location);
                if (height != 0) {
                        if (p.type == ParticleType::Drop || p.type == ParticleType::SmallPoof)
                                p.location.y = height + 5, p.velocity.y = randGet() % 10 / 40.0f;
index 204b7f0bbfd2deabb23e3468118566c3e9cae259..f08bf6561acea793d87dafba833a184f0c63f3b4 100644 (file)
@@ -149,8 +149,6 @@ void PlayerSystem::receive(const KeyUpEvent &kue)
 
 void PlayerSystem::receive(const KeyDownEvent &kde)
 {
-       static auto& worldSystem = *game::engine.getSystem<WorldSystem>();
-
        auto kc = kde.keycode;
        auto& loc = *player.component<Position>().get();
        auto& vel = *player.component<Direction>().get();
@@ -159,24 +157,24 @@ void PlayerSystem::receive(const KeyDownEvent &kde)
                loc.y += HLINES(2);
                vel.y = 0.05f;
                vel.grounded = false;
-       } else if (!ui::dialogBoxExists || ui::dialogPassive) {
+       } else if (!UISystem::isDialog()) {
                if (kc == getControl(0)) {
-                       if (!ui::fadeIntensity)
-                               worldSystem.goWorldPortal(loc);
+                       if (!UISystem::isFading())
+                               WorldSystem::goWorldPortal(loc);
 
                } else if (kc == getControl(1)) {
-                       if (!ui::fadeEnable) {
+                       if (!UISystem::isFading()) {
                 moveLeft = true;
                                moveRight = false;
 
-                               worldSystem.goWorldLeft(loc);
+                               WorldSystem::goWorldLeft(loc);
                        }
                } else if (kc == getControl(2)) {
-                       if (!ui::fadeEnable) {
+                       if (!UISystem::isFading()) {
                                moveLeft = false;
                 moveRight = true;
 
-                               worldSystem.goWorldRight(loc, *player.component<Solid>().get());
+                               WorldSystem::goWorldRight(loc, *player.component<Solid>().get());
                        }
                } else if (kc == getControl(3)) {
                        if (game::canSprint)
index 84f3e7e0ca4b269aa99183779866518778b4bc01..8c2f50d7249de5df7164492e0558a5d132d5a192 100644 (file)
@@ -5,6 +5,7 @@
 #include <config.hpp>
 #include <error.hpp>
 #include <glm.hpp>
+#include <font.hpp>
 #include <texture.hpp>
 
 extern vec2 offset;
@@ -135,7 +136,7 @@ void preRender(void)
        auto ploc = ps->getPosition();
        offset.x = ploc.x + ps->getWidth() / 2;
 
-       const auto& worldWidth = game::engine.getSystem<WorldSystem>()->getWidth();
+       const auto& worldWidth = WorldSystem::getWidth();
        if (worldWidth < (int)SCREEN_WIDTH2 * 2)
                offset.x = 0;
        else if (offset.x - SCREEN_WIDTH2 < worldWidth * -0.5f)
@@ -174,7 +175,7 @@ void render(const int& fps)
 {
        preRender();
 
-       game::engine.getSystem<WorldSystem>()->render();
+       WorldSystem::render();
 
        game::engine.getSystem<ParticleSystem>()->render();
 
@@ -185,14 +186,17 @@ void render(const int& fps)
        // draw the debug overlay if desired
        if (ui::debug) {
                auto pos = game::engine.getSystem<PlayerSystem>()->getPosition();
-               ui::putText(offset.x - game::SCREEN_WIDTH / 2, (offset.y + game::SCREEN_HEIGHT / 2) - ui::fontSize,
+               UISystem::putText(vec2(offset.x - game::SCREEN_WIDTH / 2, (offset.y + game::SCREEN_HEIGHT / 2) - FontSystem::getSize()),
                    "loc: %s\noffset: %s\nfps: %d\nticks: %d\npcount: %d\nxml: %s",
                        pos.toString().c_str(), offset.toString().c_str(), fps,
                        game::time::getTickCount(), game::engine.getSystem<ParticleSystem>()->getCount(),
-                       game::engine.getSystem<WorldSystem>()->getXMLFile().c_str());
+                       WorldSystem::getXMLFile().c_str()
+                       );
        }
 
-       ui::drawFade();
+       UISystem::render();
+
+       //ui::drawFade();
        ui::draw();
        
        game::engine.getSystem<WindowSystem>()->render();
index 00e43a2ab31d4afa44e4ce85131b18343606960b..fc815f235bee76c438d7e4b727dd5d9cbef38619 100644 (file)
@@ -6,6 +6,7 @@
 #include <bmpimage.hpp>
 #include <debug.hpp>
 #include <error.hpp>
+#include <font.hpp>
 #include <ui_menu.hpp>
 #include <vector3.hpp>
 
@@ -43,47 +44,15 @@ SDL_Keycode getControl(int index)
        return controlMap[index];
 }
 
-/**
- *     Freetype variables
- */
-
-static FT_Library   ftl;
-static FT_Face      ftf;
-
-struct FT_Info {
-       vec2 wh;
-       vec2 bl;
-       vec2 ad;
-       GLuint tex;
-
-       FT_Info(void)
-               : tex(0) {}
-};
-
-static std::vector<FT_Info> ftData (93);
-
-static Color fontColor (255, 255, 255);
-
 /*
  *     Variables for dialog boxes / options.
  */
 
-static std::vector<std::pair<vec2, std::string>> textToDraw;
-
-static std::vector<std::pair<std::string,vec3>> dialogOptText;
-static std::string dialogBoxText;
 static bool typeOutDone = true;
 static bool typeOutSustain = false;
 
 static Mix_Chunk *dialogClick;
 
-/*
- * Fade effect flags
- */
-
-static bool fadeWhite  = false;
-static bool fadeFast   = false;
-
 bool inBattle = false;
 Mix_Chunk *battleStart;
 
@@ -92,55 +61,7 @@ Mix_Chunk *sanic;
 static GLuint pageTex = 0;
 static bool   pageTexReady = false;
 
-void loadFontSize(int size, std::vector<FT_Info> &data)
-{
-       FT_Set_Pixel_Sizes(ftf, 0, size);
-
-       // pre-render 'all' the characters
-       for (auto& d : data) {
-               glDeleteTextures(1, &d.tex);
-               glGenTextures(1, &d.tex);    // Generate new texture name/locations?
-       }
-
-       for (char i = 33; i < 126; i++) {
-               // load the character from the font family file
-               UserAssert(!FT_Load_Char(ftf, i, FT_LOAD_RENDER), "Error! Unsupported character " + i);
-
-               // transfer the character's bitmap (?) to a texture for rendering
-               glBindTexture(GL_TEXTURE_2D, data[i - 33].tex);
-               glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S , GL_CLAMP_TO_EDGE);
-               glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T , GL_CLAMP_TO_EDGE);
-               glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER , GL_LINEAR);
-               glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER , GL_LINEAR);
-               glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
-
-               /**
-                * The just-created texture will render red-on-black if we don't do anything to it, so
-                * here we create a buffer 4 times the size and transform the texture into an RGBA array,
-                * making it white-on-black.
-                */
-               auto& g = ftf->glyph;
-               std::vector<uint32_t> buf (g->bitmap.width * g->bitmap.rows, 0xFFFFFFFF);
-               for (auto j = buf.size(); j--;)
-                       buf[j] ^= !g->bitmap.buffer[j] ? buf[j] : 0;
-
-               auto& d = data[i - 33];
-               d.wh.x = g->bitmap.width;
-               d.wh.y = g->bitmap.rows;
-               d.bl.x = g->bitmap_left;
-               d.bl.y = g->bitmap_top;
-               d.ad.x = g->advance.x >> 6;
-               d.ad.y = g->advance.y >> 6;
-               glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, g->bitmap.width, g->bitmap.rows,
-                                 0, GL_RGBA, GL_UNSIGNED_BYTE, buf.data());
-       }
-}
-
 namespace ui {
-
-       bool fadeEnable = false;
-       int fadeIntensity = 0;
-
        /*
         *      Mouse coordinates.
        */
@@ -148,57 +69,15 @@ namespace ui {
        vec2 mouse;
        vec2 premouse={0,0};
 
-       /*
-        *      Variety of keydown bools
-       */
-       bool edown;
-
        /*
         *      Debugging flags.
        */
 
        bool debug=false;
        bool posFlag=false;
-       bool dialogPassive = false;
-       bool dialogMerchant = false;
-       int dialogPassiveTime = 0;
-
-       int fontTransInv = 255;
-
-       /*
-        *      Dialog stuff that needs to be 'public'.
-       */
-
-       bool dialogBoxExists = false;
-       bool dialogImportant = false;
-       unsigned char dialogOptChosen = 0;
-
-       unsigned int textWrapLimit = 72;
-
-       /*
-        *      Current font size. Changing this WILL NOT change the font size, see setFontSize() for
-        *      actual font size changing.
-       */
-
-       unsigned int fontSize;
-       float fontZ = -8.0;
-
+       
     void takeScreenshot(GLubyte* pixels);
 
-       /*
-        *      Initialises the Freetype library, and sets a font size.
-       */
-
-       void initFonts(void) {
-               UserAssert(!FT_Init_FreeType(&ftl), "Couldn't initialize freetype.");
-
-#ifdef DEBUG
-               DEBUG_printf("Initialized FreeType2.\n", nullptr);
-#endif // DEBUG
-
-               fontSize = 0;
-       }
-
        void initSounds(void) {
                dialogClick = Mix_LoadWAV("assets/sounds/click.wav");
                battleStart = Mix_LoadWAV("assets/sounds/frig.wav");
@@ -206,183 +85,11 @@ namespace ui {
        }
 
        void destroyFonts(void) {
-               FT_Done_Face(ftf);
-               FT_Done_FreeType(ftl);
-
                Mix_FreeChunk(dialogClick);
                Mix_FreeChunk(battleStart);
                Mix_FreeChunk(sanic);
        }
 
-       /*
-        *      Sets a new font family to use (*.ttf).
-       */
-
-       void setFontFace(const char *ttf) {
-               UserAssert(!FT_New_Face(ftl, ttf, 0, &ftf), "Error! Couldn't open " +
-                       std::string(ttf) + ".");
-
-#ifdef DEBUG
-               DEBUG_printf("Using font %s\n",ttf);
-#endif // DEBUG
-       }
-
-       /*
-        *      Sets a new font size (default: 12).
-       */
-
-       void setFontSize(unsigned int size) {
-               fontSize = size;
-               loadFontSize(size, ftData);
-       }
-
-       /*
-        *      Set a color for font rendering (default: white).
-        */
-       void setFontColor(int r, int g, int b, int a = 255) {
-               fontColor = Color(r, g, b, a);
-       }
-
-       /*
-        *      Set the font's z layer
-        */
-       void setFontZ(float z) {
-               fontZ = z;
-       }
-
-       /*
-        *      Draws a character at the specified coordinates, aborting if the character is unknown.
-        */
-       vec2 putChar(float xx,float yy,char c){
-               const auto& ch = ftData[c - 33];
-               int x = xx, y = yy;
-
-               // get dimensions of the rendered character
-               vec2 c1 = {
-                       static_cast<float>(floor(x) + ch.bl.x),
-                       static_cast<float>(floor(y) + ch.bl.y)
-               };
-
-               const auto& c2 = ch.wh;
-
-               // draw the character
-               glActiveTexture(GL_TEXTURE0);
-               glBindTexture(GL_TEXTURE_2D, ch.tex);
-
-               Render::textShader.use();
-               Render::textShader.enable();
-
-               glUniform4f(Render::textShader.uniform[WU_tex_color], 1.0f, 1.0f, 1.0f, 1.0f);
-
-               GLfloat tex_coord[] = {
-                       0.0, 1.0,                               //bottom left
-                       1.0, 1.0,                               //bottom right
-                       1.0, 0.0,                               //top right
-                       1.0, 0.0,                               //top right
-                       0.0, 0.0,                               //top left
-                       0.0, 1.0,                               //bottom left
-               };
-
-               GLfloat text_vert[] = {
-                       c1.x,           c1.y     -c2.y, fontZ,  //bottom left
-                       c1.x+c2.x,      c1.y     -c2.y, fontZ,  //bottom right
-                       c1.x+c2.x,      c1.y+c2.y-c2.y, fontZ,  //top right
-                       c1.x+c2.x,      c1.y+c2.y-c2.y, fontZ,  //top right
-                       c1.x,           c1.y+c2.y-c2.y, fontZ,  //top left
-                       c1.x,           c1.y     -c2.y, fontZ   //bottom left
-               };
-
-        glUniform4f(Render::textShader.uniform[WU_tex_color],
-                    static_cast<float>(fontColor.red / 255),
-                    static_cast<float>(fontColor.green / 255),
-                    static_cast<float>(fontColor.blue / 255),
-                    static_cast<float>(fontColor.alpha / 255));
-
-               glVertexAttribPointer(Render::textShader.coord, 3, GL_FLOAT, GL_FALSE, 0, text_vert);
-               glVertexAttribPointer(Render::textShader.tex, 2, GL_FLOAT, GL_FALSE, 0, tex_coord);
-               glDrawArrays(GL_TRIANGLES, 0, 6);
-
-        glUniform4f(Render::textShader.uniform[WU_tex_color], 1.0, 1.0, 1.0, 1.0); // TODO seg faults
-
-               Render::textShader.disable();
-               Render::textShader.unuse();
-
-               // return the width.
-               return ch.ad;
-       }
-
-       /*
-        *      Draw a string at the specified coordinates.
-       */
-
-       float putString(const float x, const float y, std::string s) {
-               unsigned int i = 0, nl = 1;
-               vec2 add, o = {x, y};
-
-               // loop on each character
-               do {
-                       if (dialogBoxExists && i > textWrapLimit * nl) {
-                               o.y -= fontSize * 1.05f;
-                               o.x = x;
-                               ++nl;
-
-                               // skip a space if it's there since we just newline'd
-                               if (s[i] == ' ')
-                                       i++;
-                       }
-
-                       switch (s[i]) {
-                       case '\r':
-                       case '\t':
-                               break;
-                       case '\n':
-                               o.y -= fontSize * 1.05f;
-                               o.x = x;
-                               break;
-                       case '\b':
-                               o.x -= add.x;
-                               break;
-                       case ' ':
-                               o.x += fontSize / 2;
-                               break;
-                       default:
-                               add = putChar(floor(o.x), floor(o.y), s[i]);
-                               o.x += add.x;
-                               o.y += add.y;
-                               break;
-                       }
-               } while (s[++i]);
-
-               return o.x;     // the string width
-       }
-
-       float putStringCentered(const float x, const float y, std::string s) {
-               unsigned int i = 0, lastnl = 0;
-               float width = 0, yy = y;
-
-               do {
-                       switch (s[i]) {
-                       case '\n':
-                               putString(floor(x - width / 2), yy, s.substr(0, i));
-                               lastnl = 1 + i;
-                               width = 0;
-                               yy -= fontSize * 1.15f;
-                               break;
-                       case '\b':
-                               break;
-                       case ' ':
-                               width += fontSize / 2;
-                               break;
-                       default:
-                               width += ftData[i].wh.x + fontSize * 0.1f;
-                               break;
-                       }
-               } while(s[++i]);
-
-               putString(floor(x - width / 2), yy, s.substr(lastnl));
-               return width;
-       }
-
        /**
         * Prevents typeOut from typing the next string it's given.
         */
@@ -458,89 +165,7 @@ namespace ui {
                return ret;
        }
 
-       float putText(const float x, const float y, const char *str, ...) {
-               va_list args;
-       
-               va_start(args,str);
-               auto s = uisprintf(str, args);
-               va_end(args);
-
-               // draw the string and return the width
-               return putString(x, y, s);
-       }
-
-       void putTextL(vec2 c, const char *str, ...) {
-               va_list args;
-
-               va_start(args, str);
-               auto s = uisprintf(str, args);
-               va_end(args);
-
-               textToDraw.push_back(std::make_pair(c, s));
-       }
-
-       void dialogBox(std::string name, std::string opt, bool passive, std::string text, ...) {
-               va_list args;
-
-               dialogPassive = passive;
-
-               // add speaker prefix
-               dialogBoxText = name + ": ";
-
-               // handle the formatted string
-               va_start(args, text);
-               auto s = uisprintf(text.c_str(), args);
-               va_end(args);
-
-               dialogBoxText += s;
-
-               // setup option text
-               dialogOptText.clear();
-               dialogOptChosen = 0;
-
-               if (!opt.empty()) {
-                       char *sopt = strtok(&opt[0], ":");
-
-                       // cycle through options
-                       while (sopt) {
-                               dialogOptText.push_back(std::make_pair((std::string)sopt, vec3 {0,0,0}));
-                               sopt = strtok(nullptr, ":");
-                       }
-               }
-
-               // tell draw() that the box is ready
-               dialogBoxExists = true;
-               dialogImportant = false;
-
-               ret.clear();
-       }
-
-       /**
-        * Wait for a dialog box to be dismissed.
-        */
-
-       void waitForDialog(void) {
-               while (dialogBoxExists)
-                       std::this_thread::sleep_for(1ms);
-       }
-
-       void waitForCover(void) {
-               auto& fi = fadeIntensity;
-               fi = 0;
-
-               while (fi < 255)
-                       std::this_thread::sleep_for(1ms);
-                       
-               fi = 255;
-       }
-
-       void waitForUncover(void) {
-               fadeIntensity = 255;
-               while (fadeIntensity > 0);
-               fadeIntensity = 0;
-       }
-
-       void importantText(const char *text, ...) {
+       /*void importantText(const char *text, ...) {
                va_list args;
 
                dialogBoxText.clear();
@@ -572,7 +197,7 @@ namespace ui {
                dialogImportant = true;
                dialogPassive = true;
                dialogPassiveTime = duration;
-       }
+       }*/
 
 
        void drawPage(const GLuint& tex) {
@@ -580,51 +205,6 @@ namespace ui {
                pageTexReady = true;
        }
 
-       void drawBox(vec2 c1, vec2 c2) {
-        GLfloat box[] = {c1.x, c1.y, -7.0,
-                         c2.x, c1.y, -7.0,
-                         c2.x, c2.y, -7.0,
-
-                         c2.x, c2.y, -7.0,
-                         c1.x, c2.y, -7.0,
-                         c1.x, c1.y, -7.0};
-
-        GLfloat line_strip[] = {c1.x,     c1.y, -7.1,
-                                c2.x + 1, c1.y, -7.1,
-                                c2.x + 1, c2.y, -7.1,
-                                c1.x,     c2.y, -7.1,
-                                c1.x,     c1.y, -7.1};
-
-        GLfloat box_tex[] = {0,0,
-                             1,0,
-                             1,1,
-
-                             1,1,
-                             0,1,
-                             0,0};
-
-        glActiveTexture(GL_TEXTURE0);
-               Colors::black.use();
-        glUniform1i(Render::textShader.uniform[WU_texture], 0);
-
-        Render::textShader.use();
-               Render::textShader.enable();
-
-        glVertexAttribPointer(Render::textShader.coord, 3, GL_FLOAT, GL_FALSE, 0, box);
-        glVertexAttribPointer(Render::textShader.tex, 2, GL_FLOAT, GL_FALSE, 0, box_tex);
-        glDrawArrays(GL_TRIANGLES, 0 ,6);
-
-        Colors::white.use();
-        glUniform1i(Render::textShader.uniform[WU_texture], 0);
-
-        glVertexAttribPointer(Render::textShader.coord, 3, GL_FLOAT, GL_FALSE, 0, line_strip);
-        glVertexAttribPointer(Render::textShader.tex, 2, GL_FLOAT, GL_FALSE, 0, box_tex);
-        glDrawArrays(GL_LINE_STRIP, 0 ,8);
-
-        Render::textShader.disable();
-               Render::textShader.unuse();
-       }
-
        void drawNiceBox(vec2 c1, vec2 c2, float z) {
                drawNiceBoxColor(c1, c2, z, Color(1.0f, 1.0f, 1.0f));
        }
@@ -785,7 +365,6 @@ namespace ui {
        }
 
        void draw(void){
-               unsigned char i;
                std::string rtext;
 
                auto SCREEN_HEIGHT = static_cast<float>(game::SCREEN_HEIGHT);
@@ -826,7 +405,7 @@ namespace ui {
             Render::textShader.disable();
                        Render::textShader.unuse();
 
-               } else if (dialogBoxExists) {
+               } /* else if (dialogBoxExists) {
                        rtext = typeOut(dialogBoxText);
 
                        if (dialogImportant) {
@@ -840,11 +419,11 @@ namespace ui {
                                        }
                                }
 
-                               if (fadeIntensity == 255 || dialogPassive) {
+                               *if (fadeIntensity == 255 || dialogPassive) {
                                        setFontSize(24);
                                        putStringCentered(offset.x,offset.y,rtext);
                                        setFontSize(16);
-                               }
+                               }*
                        } else { //normal dialog box
 
                                float y = offset.y + SCREEN_HEIGHT / 2 - HLINES(8);
@@ -854,7 +433,7 @@ namespace ui {
 
                                setFontZ(-7.2f);
                                rtext = typeOut(dialogBoxText);
-                               putString(x + HLINES(2), y - fontSize - game::HLINE, rtext);
+                               UISystem::putString(vec2(x + HLINES(2), y - fontSize - game::HLINE), rtext);
 
                                for (i = 0; i < dialogOptText.size(); i++) {
                                        auto& sec = dialogOptText[i].second;
@@ -884,9 +463,9 @@ namespace ui {
                } else {
                        for (const auto &s : textToDraw)
                                putString(s.first.x, s.first.y, s.second);
-               }
+               }*/
 
-               if (!fadeIntensity) {
+               //if (!fadeIntensity) {
                        /*vec2 hub = {
                                (SCREEN_WIDTH/2+offset.x)-fontSize*10,
                                (offset.y+SCREEN_HEIGHT/2)-fontSize
@@ -964,8 +543,8 @@ namespace ui {
 
                                putStringCentered(hub.x,hub.y,"Inventory:");
                        }*/
-                       setFontColor(255,255,255,255);
-               }
+               //      setFontColor(255,255,255,255);
+               //}
 
                menu::draw();
 
@@ -979,126 +558,6 @@ namespace ui {
                Render::textShader.unuse();
        }
 
-       void closeBox() {
-               dialogBoxExists = false;
-               dialogMerchant = false;
-       }
-
-       void dialogAdvance(void) {
-               dialogPassive = false;
-               dialogPassiveTime = 0;
-
-               if (pageTex) {
-                       glDeleteTextures(1, &pageTex);
-                       pageTex = 0;
-                       pageTexReady = false;
-                       return;
-               }
-
-               if (!typeOutDone) {
-                       if (!dialogImportant)
-                               typeOutDone = true;
-                       return;
-               }
-
-               for (int i = 0; i < static_cast<int>(dialogOptText.size()); i++) {
-                       const auto& dot = dialogOptText[i].second;
-
-                       if (mouse.x > dot.x && mouse.x < dot.z &&
-                           mouse.y > dot.y && mouse.y < dot.y + 16) { // fontSize
-                               dialogOptChosen = i + 1;
-                               break;
-                       }
-               }
-
-               dialogBoxExists = false;
-
-               // handle important text
-               if (dialogImportant) {
-                       dialogImportant = false;
-                       setFontSize(16);
-               }
-       }
-
-       void drawFade(void) {
-               if (!fadeIntensity) {
-                       if (fontSize != 16)
-                               setFontSize(16);
-                       return;
-               }
-
-               static const GLfloat tex[12] = {
-                       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
-               };
-
-               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[18] = {
-                       p1.x, p1.y, -7.9,
-                       p2.x, p1.y, -7.9,
-                       p2.x, p2.y, -7.9,
-
-                       p2.x, p2.y, -7.9,
-                       p1.x, p2.y, -7.9,
-                       p1.x, p1.y, -7.9
-               };
-
-               setFontZ(-8.2);
-               Render::textShader.use();
-               Render::textShader.enable();
-
-               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, 0, backdrop);
-        glVertexAttribPointer(Render::textShader.tex, 2, GL_FLOAT, GL_FALSE, 0, tex);
-        glDrawArrays(GL_TRIANGLES, 0, 6);
-
-               Render::textShader.disable();
-               Render::textShader.unuse();
-               setFontZ(-8.0);
-    }
-
-       void fadeUpdate(void) {
-               if (fadeEnable) {
-                       if (fadeIntensity < 150)
-                               fadeIntensity += fadeFast ? 20 : 5;
-                       else if (fadeIntensity < 255)
-                               fadeIntensity += fadeFast ? 10 : 5;
-                       else
-                               fadeIntensity = 255;
-               } else {
-                       if (fadeIntensity > 150)
-                               fadeIntensity -= fadeFast ? 10 : 5;
-                       else if (fadeIntensity > 0)
-                               fadeIntensity -= fadeFast ? 20 : 5;
-                       else
-                               fadeIntensity = 0;
-               }
-       }
-
-       void toggleBlack(void) {
-               fadeEnable ^= true;
-               fadeWhite   = false;
-               fadeFast    = false;
-       }
-       void toggleBlackFast(void) {
-               fadeEnable ^= true;
-               fadeWhite   = false;
-               fadeFast    = true;
-       }
-       void toggleWhite(void) {
-               fadeEnable ^= true;
-               fadeWhite   = true;
-               fadeFast    = false;
-       }
-       void toggleWhiteFast(void) {
-               fadeEnable ^= true;
-               fadeWhite   = true;
-               fadeFast    = true;
-
-               //Mix_PlayChannel(1, battleStart, 0);
-       }
-
     void takeScreenshot(GLubyte* pixels) {
                auto SCREEN_WIDTH = game::SCREEN_WIDTH;
                auto SCREEN_HEIGHT = game::SCREEN_HEIGHT;
@@ -1199,25 +658,11 @@ void InputSystem::receive(const MainSDLEvent& event)
        case SDL_MOUSEBUTTONDOWN:
                ev.emit<MouseClickEvent>(mouse, e.button.button);
 
-               // run actions?
-               //if ((action::make = e.button.button & SDL_BUTTON_RIGHT))
-               //      /*player->inv->invHover =*/ edown = false;
-
-               textToDraw.clear();
+               UISystem::advanceDialog();
 
-               if (dialogBoxExists || pageTexReady) {
-                       // right click advances dialog
+               if (UISystem::isDialog() || pageTexReady) {
                        if ((e.button.button & SDL_BUTTON_RIGHT))
-                               dialogAdvance();
-               } else {
-                       // left click uses item
-                       if (e.button.button & SDL_BUTTON_LEFT) {
-                               /*if ((ent = currentWorld->getNearMob(*player)) != nullptr) {
-                                       player->inv->currentAddInteract(ent);
-                               }
-                                       player->inv->useCurrent();*/
-                       }
-
+                               UISystem::advanceDialog();
                }
                break;
 
@@ -1242,22 +687,12 @@ void InputSystem::receive(const MainSDLEvent& event)
                if (SDL_KEY == SDLK_ESCAPE)
                        ui::menu::toggle();
 
-               if (SDL_KEY == SDLK_q) {
-                       /*auto item = player->inv->getCurrentItem();
-                       if (item != nullptr) {
-                               if (player->inv->takeItem(item->name, 1) == 0)
-                                       currentWorld->addObject(item->name, "o shit waddup",
-                                                                                       player->loc.x + player->width / 2, player->loc.y + player->height / 2);
-                       }*/
-               } else if (SDL_KEY == SDLK_h) {
+               if (SDL_KEY == SDLK_h) {
                        quest::toggle();
                } else switch (SDL_KEY) {
                case SDLK_F3:
                        debug ^= true;
                        break;
-               case SDLK_BACKSLASH:
-                       dialogBoxExists = false;
-                       break;
                case SDLK_b:
                        if (debug)
                                posFlag ^= true;
@@ -1300,3 +735,245 @@ void InputSystem::update(entityx::EntityManager &en, entityx::EventManager &ev,
        mouse.x = premouse.x + offset.x - (game::SCREEN_WIDTH / 2);
        mouse.y = (offset.y + game::SCREEN_HEIGHT / 2) - premouse.y;
 }
+
+bool UISystem::fadeEnable = false;
+bool UISystem::fadeFast = false;
+int  UISystem::fadeIntensity = 0;
+
+std::string UISystem::dialogText;
+std::string UISystem::importantText;
+std::vector<DialogOption> UISystem::dialogOptions;
+int UISystem::dialogOptionResult;
+
+void UISystem::fadeToggle(void)
+{
+       fadeEnable ^= true;
+       fadeFast = false;
+
+       fadeIntensity = fadeEnable ? 0 : 255;
+}
+
+void UISystem::fadeToggleFast(void)
+{
+       fadeEnable ^= true;
+       fadeFast = true;
+}
+
+void UISystem::waitForCover(void)
+{
+       fadeIntensity = 0;
+       while (fadeIntensity < 255)
+               std::this_thread::sleep_for(1ms);
+}
+
+void UISystem::waitForUncover(void)
+{
+       fadeIntensity = 255;
+       while (fadeIntensity > 0)
+               std::this_thread::sleep_for(1ms);
+}
+
+void UISystem::putText(const vec2& p, const std::string& s, ...)
+{
+       va_list args;
+       
+       va_start(args, s);
+       putString(p, uisprintf(s.c_str(), args));
+       va_end(args);
+}
+
+void UISystem::putString(const vec2& p, const std::string& s, float wrap)
+{
+       vec2 offset = p, add;
+
+       for (auto c : s) {
+               switch (c) {
+               case '\n':
+                       offset.y -= FontSystem::getSize() * 1.05f;
+                       offset.x = p.x;
+                       break;
+               case '\b':
+                       offset.x -= add.x;
+                       break;
+               case '\r':
+               case '\t':
+                       break;
+               case ' ':
+                       offset.x += FontSystem::getSize() / 2.0f;
+                       break;
+               default:
+                       add = FontSystem::putChar(floor(offset.x), floor(offset.y), c);
+                       offset += add;
+                       break;
+               }
+
+               if (wrap != 0.12345f && offset.x >= (wrap - 10)) {
+                       offset.y -= FontSystem::getSize() * 1.05f;
+                       offset.x = p.x;
+               }
+       }
+
+       //return offset.x;
+}
+
+float UISystem::putStringCentered(const vec2& p, const std::string& s, bool print)
+{
+       int i = 0, lastnl = 0;
+       float width = 0, yy = p.y;
+       auto& font = FontSystem::getFont();
+
+       do {
+               switch (s[i]) {
+               case '\n':
+                       putString(vec2(floor(p.x - width / 2), yy), s.substr(0, i));
+                       lastnl = 1 + i;
+                       width = 0;
+                       yy -= FontSystem::getSize() * 1.15f;
+                       break;
+               case '\b':
+                       break;
+               case ' ':
+                       width += FontSystem::getSize() / 2;
+                       break;
+               default:
+                       width += font[i].wh.x + FontSystem::getSize() * 0.1f;
+                       break;
+               }
+
+       } while(s[++i]);
+
+       if (print)
+               putString(vec2(floor(p.x - width / 2), yy), s.substr(lastnl));
+       return width;
+}
+
+void UISystem::dialogBox(const std::string& n, const std::string& s, ...)
+{
+       va_list args;
+
+       dialogText = n + ": ";
+
+       va_start(args, s);
+       dialogText += ui::uisprintf(s.c_str(), args);
+       va_end(args);
+}
+
+void UISystem::dialogAddOption(const std::string& o)
+{
+       dialogOptions.emplace_back(OptionDim(), o);
+}
+
+void UISystem::dialogImportant(const std::string& s)
+{
+       importantText = s;
+}
+
+void UISystem::waitForDialog(void)
+{
+       while (isDialog())
+               std::this_thread::sleep_for(1ms);
+}
+
+int UISystem::getDialogResult(void)
+{
+       return dialogOptionResult;
+}
+
+void UISystem::advanceDialog(void)
+{
+       dialogText.clear();
+       importantText.clear();
+
+       if (!dialogOptions.empty()) {
+               int r = 1;
+               dialogOptionResult = 0;
+               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;
+                               break;
+                       }
+                       r++;
+               }
+
+               dialogOptions.clear();
+       }
+}
+
+void UISystem::update(entityx::EntityManager& en, entityx::EventManager& ev, entityx::TimeDelta dt)
+{
+       (void)en;
+       (void)ev;
+       (void)dt;
+}
+
+void UISystem::render(void)
+{
+       if ((fadeEnable & (fadeIntensity < 255)))
+               fadeIntensity += fadeFast ? 15 : 5;
+       else if ((!fadeEnable & (fadeIntensity > 0)))
+               fadeIntensity -= fadeFast ? 15 : 5;
+
+       if (fadeIntensity < 0)
+               fadeIntensity = 0;
+       if (fadeIntensity > 255)
+               fadeIntensity = 255;
+
+       if (fadeIntensity != 0) {
+               static const GLfloat tex[12] = {
+                       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+               };
+
+               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[18] = {
+                       p1.x, p1.y, -7.9,
+                       p2.x, p1.y, -7.9,
+                       p2.x, p2.y, -7.9,
+
+                       p2.x, p2.y, -7.9,
+                       p1.x, p2.y, -7.9,
+                       p1.x, p1.y, -7.9
+               };
+
+               Render::textShader.use();
+               Render::textShader.enable();
+
+               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, 0, backdrop);
+        glVertexAttribPointer(Render::textShader.tex, 2, GL_FLOAT, GL_FALSE, 0, tex);
+        glDrawArrays(GL_TRIANGLES, 0, 6);
+
+               Render::textShader.disable();
+               Render::textShader.unuse();
+               //setFontZ(-8.0);
+       }
+
+       if (!dialogText.empty()) {
+               vec2 where (offset.x - 300, game::SCREEN_HEIGHT - 60);
+               ui::drawNiceBox(vec2(where.x - 10, where.y - 200), vec2(where.x + 620, where.y + 20), -5.5f);
+               putString(where, dialogText, where.x + 600);
+
+               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);
+                               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)
+                                       FontSystem::setFontColor(255, 255, 0);
+
+                               putStringCentered(vec2(o.first.x, o.first.y), o.second);
+                               FontSystem::setFontColor(255, 255, 255);
+                       }
+               }
+       }
+
+       if (!importantText.empty()) {
+               putStringCentered(offset, importantText);
+       }
+}
index e5f5f9db6ff6e9856380b548269cf5570bb7fccc..b49f0e9e4a3a9f1791e3e6d633e4a45a68bdab21 100644 (file)
@@ -5,6 +5,7 @@
 #include <fileio.hpp>
 #include <render.hpp>
 #include <texture.hpp>
+#include <font.hpp>
 
 #include <fstream>
 
@@ -18,8 +19,10 @@ static Menu controlsMenu;
 
 void Menu::gotoParent(void)
 {
-       if (parent == nullptr)
+       if (parent == nullptr) {
                game::config::update();
+               FontSystem::setFontSize(16);
+       }
        
        currentMenu = parent;
 }
@@ -219,9 +222,9 @@ namespace ui {
 
                        Render::useShader(&Render::textShader);
 
-            setFontSize(24);
             game::config::update();
-                       setFontZ(-9.0);
+            FontSystem::setFontSize(24);
+                       FontSystem::setFontZ(-9.0);
        
             mouse.x = ui::premouse.x+offset.x-(SCREEN_WIDTH/2);
             mouse.y = (offset.y+SCREEN_HEIGHT/2)-ui::premouse.y;
@@ -297,8 +300,8 @@ namespace ui {
 
                                        ui::drawNiceBoxColor(loc, end, -8.6, Color(cMult, cMult, cMult, 1.0f));
                     //draw the button text
-                    putStringCentered(loc.x + (m.dim.x / 2),
-                       loc.y + (m.dim.y / 2) - (ui::fontSize / 2),
+                    UISystem::putStringCentered(vec2(loc.x + (m.dim.x / 2),
+                       loc.y + (m.dim.y / 2) - (FontSystem::getSize() / 2)),
                         m.text);
 
                                        //if element is a slider
@@ -348,18 +351,19 @@ namespace ui {
                                vec2(loc.x + sliderW, loc.y + (m.slider.sliderLoc * 1.05) + sliderH), -8.7, Color(cMult, cMult, cMult, 1.0f));
 
                         //draw the now combined slider text
-                        putStringCentered(loc.x + (m.dim.x/2), (loc.y + (m.dim.y*1.05)) - ui::fontSize/2, outSV);
+                        UISystem::putStringCentered(vec2(loc.x + (m.dim.x/2), (loc.y + (m.dim.y*1.05)) - FontSystem::getSize() / 2), outSV);
                     } else {
                         ui::drawNiceBoxColor(vec2(loc.x+m.slider.sliderLoc, loc.y),
                             vec2(loc.x + m.slider.sliderLoc + sliderW, loc.y + sliderH), -8.7, Color(cMult, cMult, cMult, 1.0f));
 
                         //draw the now combined slider text
-                        putStringCentered(loc.x + (m.dim.x/2), (loc.y + (m.dim.y/2)) - ui::fontSize/2, outSV);
+                        UISystem::putStringCentered(loc + (m.dim / 2) /*- FontSystem::getSize() / 2*/, outSV);
                     }
                 }
             }
-            setFontSize(16);
-                       setFontZ(-8.0);
+
+            FontSystem::setFontSize(16);
+                       FontSystem::setFontZ(-8.0);
         }
 
 
index 3688e98467fba3d3543cb4767f06c43ed47221c8..6351577e4ec7c5d9bed7dc6b1c75b09d1892f5f0 100644 (file)
@@ -28,6 +28,15 @@ using namespace tinyxml2;
 #include <vector3.hpp>
 #include <weather.hpp>
 
+WorldData2               WorldSystem::world;
+Mix_Music*               WorldSystem::bgmObj;
+std::string              WorldSystem::bgmCurrent;
+std::vector<std::string> WorldSystem::bgFiles;
+TextureIterator          WorldSystem::bgTex;
+XMLDocument              WorldSystem::xmlDoc;
+std::string              WorldSystem::currentXMLFile;
+std::thread              WorldSystem::thAmbient;
+
 extern std::string xmlFolder;
 
 // wait
@@ -116,7 +125,7 @@ void WorldSystem::generate(int width)
     world.startX = HLINES(width * -0.5);
 }
 
-float WorldSystem::isAboveGround(const vec2& p) const
+float WorldSystem::isAboveGround(const vec2& p) 
 {
        int line = std::clamp(static_cast<int>((p.x - world.startX) / game::HLINE),
                0, static_cast<int>(world.data.size()));
@@ -379,11 +388,6 @@ void WorldSystem::load(const std::string& file)
                        }
                }
 
-               // hill creation
-               /*else if (tagName == "hill") {
-                       addHill(ivec2 { wxml->IntAttribute("peakx"), wxml->IntAttribute("peaky") }, wxml->UnsignedAttribute("width"));
-               }*/
-
                wxml = wxml->NextSiblingElement();
        }
 
@@ -617,7 +621,9 @@ loadWorldFromXMLNoSave(std::string path) {
 }*/
 
 WorldSystem::WorldSystem(void)
-       : bgmObj(nullptr) {}
+{
+       bgmObj = nullptr;
+}
 
 WorldSystem::~WorldSystem(void)
 {
@@ -1152,9 +1158,11 @@ void WorldSystem::detect(entityx::TimeDelta dt)
 
                // insure that the entity doesn't fall off either edge of the world.
         if (loc.x < world.startX) {
+                       std::cout << "Left!\n";
                        vel.x = 0;
                        loc.x = world.startX + HLINES(0.5f);
                } else if (loc.x + dim.width + game::HLINE > -(static_cast<int>(world.startX))) {
+                       std::cout << "Right\n";
                        vel.x = 0;
                        loc.x = -(static_cast<int>(world.startX)) - dim.width - game::HLINE;
                }
@@ -1164,26 +1172,26 @@ void WorldSystem::detect(entityx::TimeDelta dt)
 void WorldSystem::goWorldRight(Position& p, Solid &d)
 {
        if (!(world.toRight.empty()) && (p.x + d.width > world.startX * -1 - HLINES(5))) {
-               ui::toggleBlack();
-               ui::waitForCover();
+               UISystem::fadeToggle();
+               UISystem::waitForCover();
                while (waitToSwap)
                        std::this_thread::sleep_for(1ms);
                load(world.toRight);
                game::engine.getSystem<PlayerSystem>()->setX(world.startX + HLINES(10));
-               ui::toggleBlack();
+               UISystem::fadeToggle();
        }
 }
 
 void WorldSystem::goWorldLeft(Position& p)
 {
        if (!(world.toLeft.empty()) && (p.x < world.startX + HLINES(10))) {
-               ui::toggleBlack();
-               ui::waitForCover();
+               UISystem::fadeToggle();
+               UISystem::waitForCover();
                while (waitToSwap)
                        std::this_thread::sleep_for(1ms);
                load(world.toLeft);
                game::engine.getSystem<PlayerSystem>()->setX(world.startX * -1 - HLINES(15));
-               ui::toggleBlack();
+               UISystem::fadeToggle();
        }
 }
 
@@ -1209,11 +1217,11 @@ void WorldSystem::goWorldPortal(Position& p)
        }
 
        if (!file.empty()) {
-               ui::toggleBlack();
-               ui::waitForCover();
+               UISystem::fadeToggle();
+               UISystem::waitForCover();
                while (waitToSwap)
                        std::this_thread::sleep_for(1ms);
                load(file);
-               ui::toggleBlack();
+               UISystem::fadeToggle();
        }
 }
index 9351652dc511256df105223aa993a018dda5f082..72c11de0dd10ccb1796f95daccb9897f75fc28ad 100644 (file)
@@ -18,6 +18,9 @@
 <Dialog name="Bob">
     <text id="0" nextid="1">
         <give name="Dank MayMay" count="10"/>
+               <option name="Yes" />
+               <option name="Yes daddy" />
+               <option name="Ooooh boy yesss please" />
         <content>
                        Hey there! The name's Bob. Good to see you've finally woken up from your nap by the cliff there... lol
                </content>
index df2751a48296769f146bece2bc1c6baf3cb7cce9..a1b5f5cb7143bf10b91b659aea3b20eb17a268cf 100644 (file)
                </frame>
        </Sprite>
        <Direction />
-       <Health value="5" />
+       <Health value="50" />
        <Solid />
        <Physics />
        <Name value="SKIRL" />
        <Wander />
-       <Aggro arena="arena.xml" />
 </skirl>
 
 <structure>