diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/config.hpp | 2 | ||||
-rw-r--r-- | include/font.hpp | 56 | ||||
-rw-r--r-- | include/ui.hpp | 130 | ||||
-rw-r--r-- | include/ui_quest.hpp | 8 | ||||
-rw-r--r-- | include/vector2.hpp | 10 | ||||
-rw-r--r-- | include/world.hpp | 47 |
6 files changed, 149 insertions, 104 deletions
diff --git a/include/config.hpp b/include/config.hpp index 13596ff..305f61e 100644 --- a/include/config.hpp +++ b/include/config.hpp @@ -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 index 0000000..a520c15 --- /dev/null +++ b/include/font.hpp @@ -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_ diff --git a/include/ui.hpp b/include/ui.hpp index ac415f5..456c88a 100644 --- a/include/ui.hpp +++ b/include/ui.hpp @@ -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 diff --git a/include/ui_quest.hpp b/include/ui_quest.hpp index a46483a..d9d1708 100644 --- a/include/ui_quest.hpp +++ b/include/ui_quest.hpp @@ -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); } } } diff --git a/include/vector2.hpp b/include/vector2.hpp index beb2787..77ee7e7 100644 --- a/include/vector2.hpp +++ b/include/vector2.hpp @@ -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); diff --git a/include/world.hpp b/include/world.hpp index e47f78f..7d7d016 100644 --- a/include/world.hpp +++ b/include/world.hpp @@ -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); }; |