diff options
Diffstat (limited to 'src/resources/theme.h')
-rw-r--r-- | src/resources/theme.h | 99 |
1 files changed, 81 insertions, 18 deletions
diff --git a/src/resources/theme.h b/src/resources/theme.h index 6d71b067..80b78fdd 100644 --- a/src/resources/theme.h +++ b/src/resources/theme.h @@ -30,8 +30,10 @@ #include "resources/image.h" #include "utils/xml.h" +#include <array> #include <map> #include <memory> +#include <optional> #include <string> #include <variant> @@ -44,11 +46,32 @@ class Image; class ImageSet; class ProgressBar; +class ThemeInfo +{ +public: + ThemeInfo() = default; + explicit ThemeInfo(const std::string &path); + + bool isValid() const { return !name.empty(); } + + const std::string &getName() const { return name; } + const std::string &getPath() const { return path; } + std::string getFullPath() const; + const XML::Document &getDocument() const { return *doc; } + +private: + std::string name; + std::string path; + std::unique_ptr<XML::Document> doc; +}; + enum class SkinType { Window, + ToolWindow, Popup, SpeechBubble, + Desktop, Button, ButtonUp, ButtonDown, @@ -72,6 +95,9 @@ enum class SkinType SliderHandle, ResizeGrip, ShortcutBox, + EquipmentBox, + ItemSlot, + EmoteSlot, }; enum StateFlags : uint8_t @@ -85,6 +111,7 @@ enum StateFlags : uint8_t struct ColoredRectangle { gcn::Color color; + bool filled = true; }; struct SkinPart @@ -150,25 +177,32 @@ class Skin */ void updateAlpha(float alpha); + int width = 0; + int height = 0; int frameSize = 0; int padding = 0; int spacing = 0; int titleBarHeight = 0; int titleOffsetX = 0; int titleOffsetY = 0; + int palette = 0; + bool showButtons = true; private: std::vector<SkinState> mStates; }; -class Theme : public Palette, public EventListener +class Theme : public EventListener { public: static std::string prepareThemePath(); + static std::vector<ThemeInfo> getAvailableThemes(); - Theme(const std::string &path); + Theme(const ThemeInfo &themeInfo); ~Theme() override; + const std::string &getThemePath() const { return mThemePath; } + /** * Returns the patch to the given GUI resource relative to the theme * or, if it isn't in the theme, relative to 'graphics/gui'. @@ -178,18 +212,33 @@ class Theme : public Palette, public EventListener enum ThemePalette { TEXT, + BLACK, // Color 0 + RED, // Color 1 + GREEN, // Color 2 + BLUE, // Color 3 + ORANGE, // Color 4 + YELLOW, // Color 5 + PINK, // Color 6 + PURPLE, // Color 7 + GRAY, // Color 8 + BROWN, // Color 9 + CARET, SHADOW, OUTLINE, - PARTY_CHAT_TAB, - PARTY_SOCIAL_TAB, + PARTY_TAB, + WHISPER_TAB, BACKGROUND, HIGHLIGHT, + HIGHLIGHT_TEXT, TAB_FLASH, SHOP_WARNING, ITEM_EQUIPPED, CHAT, + OLDCHAT, + AWAYCHAT, BUBBLE_TEXT, GM, + GLOBAL, PLAYER, WHISPER, IS, @@ -229,30 +278,42 @@ class Theme : public Palette, public EventListener }; /** - * Gets the color associated with the type. Sets the alpha channel - * before returning. + * Gets the color associated with the type in the default palette (0). * * @param type the color type requested - * @param alpha alpha channel to use - * * @return the requested color */ - static const gcn::Color &getThemeColor(int type, int alpha = 255); - static const gcn::Color &getThemeColor(char c, bool &valid); + static const gcn::Color &getThemeColor(int type); static gcn::Color getProgressColor(int type, float progress); + const Palette &getPalette(size_t index) const; + + /** + * Returns a color from the default palette (0). + */ + const gcn::Color &getColor(int type) const; + + /** + * Returns the color ID associated with a character, if it exists. + * Returns no value if the character is not found. + * + * @param c character requested + * @return the requested color or none + */ + static std::optional<int> getColorIdForChar(char c); + void drawSkin(Graphics *graphics, SkinType type, const WidgetState &state) const; void drawProgressBar(Graphics *graphics, const gcn::Rectangle &area, const gcn::Color &color, float progress, - const std::string &text = std::string()) const; + const std::string &text = std::string(), + ProgressPalette progressType = ProgressPalette::THEME_PROG_END) const; const Skin &getSkin(SkinType skinType) const; - int getMinWidth(SkinType skinType) const; - int getMinHeight(SkinType skinType) const; + const Image *getIcon(const std::string &name) const; /** * Get the current GUI alpha value. @@ -280,17 +341,17 @@ class Theme : public Palette, public EventListener ResourceRef<Image> getImage(const std::string &path) const; - bool readTheme(const std::string &filename); + bool readTheme(const ThemeInfo &themeInfo); void readSkinNode(XML::Node node); void readSkinStateNode(XML::Node node, Skin &skin) const; - void readSkinStateTextNode(XML::Node node, SkinState &state) const; void readSkinStateImgNode(XML::Node node, SkinState &state) const; - void readSkinStateRectNode(XML::Node node, SkinState &state) const; - void readColorNode(XML::Node node); + void readIconNode(XML::Node node); + void readPaletteNode(XML::Node node); void readProgressBarNode(XML::Node node); std::string mThemePath; std::map<SkinType, Skin> mSkins; + std::map<std::string, Image *> mIcons; /** * Tells if the current skins opacity @@ -299,5 +360,7 @@ class Theme : public Palette, public EventListener float mMinimumOpacity = 0.0f; float mAlpha = 1.0; - std::vector<std::unique_ptr<DyePalette>> mProgressColors; + std::vector<Palette> mPalettes; + std::array<std::unique_ptr<DyePalette>, THEME_PROG_END> mProgressColors; + std::array<std::optional<TextFormat>, THEME_PROG_END> mProgressTextFormats; }; |