diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-10-18 19:02:04 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-10-18 19:02:04 +0300 |
commit | c7ad8d093591214a32cacc79fa25d8e118493093 (patch) | |
tree | 2be3eacaa43c6941862b15ca099eeba8cd292fa5 /src | |
parent | 2b4110a217110dfe9919fa3cc70e41c6920ac597 (diff) | |
download | manaplus-c7ad8d093591214a32cacc79fa25d8e118493093.tar.gz manaplus-c7ad8d093591214a32cacc79fa25d8e118493093.tar.bz2 manaplus-c7ad8d093591214a32cacc79fa25d8e118493093.tar.xz manaplus-c7ad8d093591214a32cacc79fa25d8e118493093.zip |
Add button in themes to show additional theme info.
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/setup_theme.cpp | 32 | ||||
-rw-r--r-- | src/gui/setup_theme.h | 10 | ||||
-rw-r--r-- | src/gui/theme.cpp | 32 | ||||
-rw-r--r-- | src/gui/theme.h | 8 |
4 files changed, 74 insertions, 8 deletions
diff --git a/src/gui/setup_theme.cpp b/src/gui/setup_theme.cpp index 1886405be..66d806fc4 100644 --- a/src/gui/setup_theme.cpp +++ b/src/gui/setup_theme.cpp @@ -51,6 +51,7 @@ const char* ACTION_PARTICLE_FONT = "particle font"; const char* ACTION_HELP_FONT = "help font"; const char* ACTION_SECURE_FONT = "secure font"; const char* ACTION_JAPAN_FONT = "japan font"; +const char* ACTION_INFO = "info"; class ThemesModel final : public NamesModel { @@ -194,7 +195,9 @@ Setup_Theme::Setup_Theme() : mNpcFontSizeListModel(new FontSizeChoiceListModel), mNpcFontSizeLabel(new Label(_("Npc font size"))), mNpcFontSize(config.getIntValue("npcfontSize")), - mNpcFontSizeDropDown(new DropDown(mNpcFontSizeListModel)) + mNpcFontSizeDropDown(new DropDown(mNpcFontSizeListModel)), + // TRANSLATORS: button name with information about selected theme + mInfoButton(new Button(_("i"), ACTION_INFO, this)) { setName(_("Theme")); @@ -249,6 +252,8 @@ Setup_Theme::Setup_Theme() : mJapanFontDropDown->setSelectedString(getFileName( config.getStringValue("japanFont"))); + updateInfo(); + // Do the layout LayoutHelper h(this); ContainerPlacer place = h.getPlacer(0, 0); @@ -275,8 +280,7 @@ Setup_Theme::Setup_Theme() : place(6, 8, mSecureFontDropDown, 10); place(6, 9, mJapanFontDropDown, 10); - place.getCell().matchColWidth(0, 0); - place = h.getPlacer(0, 1); + place(17, 0, mInfoButton, 1); setDimension(gcn::Rectangle(0, 0, 365, 500)); } @@ -299,6 +303,22 @@ Setup_Theme::~Setup_Theme() mLangListModel = nullptr; } +void Setup_Theme::updateInfo() +{ + ThemeInfo *info = Theme::loadInfo(mTheme); + if (info) + { + mThemeInfo = "Name: " + info->name + + "\nCopyright:\n" + info->copyright; + } + else + { + mThemeInfo = ""; + } + replaceAll(mThemeInfo, "\\n", "\n"); + delete info; +} + void Setup_Theme::action(const gcn::ActionEvent &event) { if (event.getId() == ACTION_THEME) @@ -307,6 +327,7 @@ void Setup_Theme::action(const gcn::ActionEvent &event) mTheme = ""; else mTheme = mThemeDropDown->getSelectedString(); + updateInfo(); } else if (event.getId() == ACTION_FONT) { @@ -340,6 +361,11 @@ void Setup_Theme::action(const gcn::ActionEvent &event) { mJapanFont = mJapanFontDropDown->getSelectedString(); } + else if (event.getId() == ACTION_INFO) + { + new OkDialog(_("Theme info"), mThemeInfo, DIALOG_OK, + false, true, nullptr, 600); + } } void Setup_Theme::cancel() diff --git a/src/gui/setup_theme.h b/src/gui/setup_theme.h index 9754b7915..2a0152035 100644 --- a/src/gui/setup_theme.h +++ b/src/gui/setup_theme.h @@ -27,6 +27,7 @@ #include <guichan/actionlistener.hpp> +class Button; class DropDown; class EditDialog; class FontsModel; @@ -35,11 +36,6 @@ class Label; class LangListModel; class ThemesModel; -namespace gcn -{ - class DropDown; -} - class Setup_Theme final : public SetupTab { public: @@ -55,6 +51,8 @@ class Setup_Theme final : public SetupTab void action(const gcn::ActionEvent &event) override; + void updateInfo(); + private: Label *mThemeLabel; ThemesModel *mThemesModel; @@ -102,6 +100,8 @@ class Setup_Theme final : public SetupTab int mNpcFontSize; DropDown *mNpcFontSizeDropDown; + Button *mInfoButton; + std::string mThemeInfo; // EditDialog *mEditDialog; }; diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp index 4abf76eb6..9ecac247c 100644 --- a/src/gui/theme.cpp +++ b/src/gui/theme.cpp @@ -1031,3 +1031,35 @@ ImageSet *Theme::getImageSetFromThemeXml(const std::string &name, } return nullptr; } + +ThemeInfo *Theme::loadInfo(const std::string &themeName) +{ + std::string path; + if (themeName.empty()) + path = "graphics/gui/info.xml"; + else + path = defaultThemePath + themeName + "/info.xml"; + logger->log("loading: " + path); + XML::Document doc(path); + const XmlNodePtr rootNode = doc.rootNode(); + + if (!rootNode || !xmlNameEqual(rootNode, "info")) + return nullptr; + + ThemeInfo *info = new ThemeInfo(); + + for_each_xml_child_node(infoNode, rootNode) + { + if (xmlNameEqual(infoNode, "name")) + { + info->name = reinterpret_cast<const char*>( + xmlNodeGetContent(infoNode)); + } + else if (xmlNameEqual(infoNode, "copyright")) + { + info->copyright = reinterpret_cast<const char*>( + xmlNodeGetContent(infoNode)); + } + } + return info; +} diff --git a/src/gui/theme.h b/src/gui/theme.h index 92ff6073b..680fe63bd 100644 --- a/src/gui/theme.h +++ b/src/gui/theme.h @@ -39,6 +39,12 @@ class Image; class ImageSet; class ProgressBar; +struct ThemeInfo final +{ + std::string name; + std::string copyright; +}; + class Skin final { public: @@ -333,6 +339,8 @@ class Theme final : public Palette, public ConfigListener static Image *getImageFromThemeXml(const std::string &name, const std::string &name2); + static ThemeInfo *loadInfo(const std::string &themeName); + private: Theme(); |