diff options
author | Andrei Karas <akaras@inbox.ru> | 2016-07-26 22:47:45 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2016-07-26 22:47:45 +0300 |
commit | 83981f76348655507d225aca220893e668b09bdc (patch) | |
tree | a86b9a28bb584bed5a6f397bc0b47aba908d0f82 /src | |
parent | 8f3d5cce14912a4c955a02f50a13130ca15b585e (diff) | |
download | mv-83981f76348655507d225aca220893e668b09bdc.tar.gz mv-83981f76348655507d225aca220893e668b09bdc.tar.bz2 mv-83981f76348655507d225aca220893e668b09bdc.tar.xz mv-83981f76348655507d225aca220893e668b09bdc.zip |
Add support for loading stats pages from stats.xml
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/widgets/statspage.cpp | 5 | ||||
-rw-r--r-- | src/gui/widgets/statspage.h | 3 | ||||
-rw-r--r-- | src/gui/windows/statuswindow.cpp | 11 | ||||
-rw-r--r-- | src/resources/db/statdb.cpp | 16 | ||||
-rw-r--r-- | src/resources/db/statdb.h | 4 |
5 files changed, 28 insertions, 11 deletions
diff --git a/src/gui/widgets/statspage.cpp b/src/gui/widgets/statspage.cpp index b41cc6224..1f30f2862 100644 --- a/src/gui/widgets/statspage.cpp +++ b/src/gui/widgets/statspage.cpp @@ -37,7 +37,8 @@ #include "debug.h" -StatsPage::StatsPage(const Widget2 *const widget) : +StatsPage::StatsPage(const Widget2 *const widget, + const std::string &page) : Container(widget), WidgetListener(), StatListener(), @@ -51,7 +52,7 @@ StatsPage::StatsPage(const Widget2 *const widget) : mAttrScroll->setVerticalScrollPolicy(ScrollArea::SHOW_AUTO); add(mAttrScroll); - const std::vector<BasicStat> &basicStats = StatDb::getExtendedStats(); + const std::vector<BasicStat> &basicStats = StatDb::getStats(page); FOR_EACH (std::vector<BasicStat>::const_iterator, it, basicStats) { const BasicStat &stat = *it; diff --git a/src/gui/widgets/statspage.h b/src/gui/widgets/statspage.h index 2bfb144d2..b9ab37df5 100644 --- a/src/gui/widgets/statspage.h +++ b/src/gui/widgets/statspage.h @@ -35,7 +35,8 @@ class StatsPage final : public Container, public StatListener { public: - StatsPage(const Widget2 *const widget); + StatsPage(const Widget2 *const widget, + const std::string &page); A_DELETE_COPY(StatsPage) diff --git a/src/gui/windows/statuswindow.cpp b/src/gui/windows/statuswindow.cpp index 461d5e01d..57ca97206 100644 --- a/src/gui/windows/statuswindow.cpp +++ b/src/gui/windows/statuswindow.cpp @@ -48,6 +48,8 @@ #include "net/inventoryhandler.h" #include "net/playerhandler.h" +#include "resources/db/statdb.h" + #include "resources/item/item.h" #include "utils/gettext.h" @@ -213,15 +215,18 @@ void StatusWindow::addTabs() { // TRANSLATORS: status window tab name addTabBasic(_("Basic")); - // TRANSLATORS: status window tab name - addTab(_("Extended")); + const std::vector<std::string> &pages = StatDb::getPages(); + FOR_EACH(std::vector<std::string>::const_iterator, it, pages) + { + addTab(*it); + } mTabs->adjustSize(); } void StatusWindow::addTab(const std::string &name) { mTabs->addTab(name, - new StatsPage(this)); + new StatsPage(this, name)); } void StatusWindow::addTabBasic(const std::string &name) diff --git a/src/resources/db/statdb.cpp b/src/resources/db/statdb.cpp index b68ee9576..0e7175310 100644 --- a/src/resources/db/statdb.cpp +++ b/src/resources/db/statdb.cpp @@ -35,6 +35,7 @@ namespace bool mLoaded = false; static std::vector<BasicStat> mBasicStats; static std::map<std::string, std::vector<BasicStat> > mStats; + static std::vector<std::string> mPages; } // namespace void StatDb::addDefaultStats() @@ -70,9 +71,14 @@ const std::vector<BasicStat> &StatDb::getBasicStats() return mBasicStats; } -const std::vector<BasicStat> &StatDb::getExtendedStats() +const std::vector<BasicStat> &StatDb::getStats(const std::string &page) { - return mStats["extended"]; + return mStats[page]; +} + +const std::vector<std::string> &StatDb::getPages() +{ + return mPages; } void StatDb::load() @@ -116,6 +122,7 @@ static void loadStats(const XmlNodePtr rootNode, { const int maxAttr = static_cast<int>(Attributes::MAX_ATTRIBUTE); std::vector<BasicStat> &stats = mStats[page]; + mPages.push_back(page); for_each_xml_child_node(node, rootNode) { if (xmlNameEqual(node, "stat")) @@ -167,11 +174,12 @@ void StatDb::loadXmlFile(const std::string &fileName, } else if (xmlNameEqual(node, "extended")) { - loadStats(node, "extended"); + // TRANSLATORS: stats page name + loadStats(node, _("Extended")); } else if (xmlNameEqual(node, "page")) { - std::string page = XML::getProperty(node, "name", ""); + std::string page = XML::langProperty(node, "name", ""); if (page.empty()) { reportAlways("Page without name in stats.xml"); diff --git a/src/resources/db/statdb.h b/src/resources/db/statdb.h index 96392d06f..f98eac111 100644 --- a/src/resources/db/statdb.h +++ b/src/resources/db/statdb.h @@ -42,7 +42,9 @@ namespace StatDb const std::vector<BasicStat> &getBasicStats(); - const std::vector<BasicStat> &getExtendedStats(); + const std::vector<BasicStat> &getStats(const std::string &page); + + const std::vector<std::string> &getPages(); } // namespace StatDb #endif // RESOURCES_DB_STATDB_H |