diff options
author | Andrei Karas <akaras@inbox.ru> | 2018-02-13 01:54:28 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2018-02-13 04:28:32 +0300 |
commit | acba95ebb0119e7b0f9ef01d9bf3577582857253 (patch) | |
tree | b5346c2a5642456e793b28487020cf1c727d8f07 /src | |
parent | 0a47f5c44ddd5fb5157d116ffe0f5ee5f4207eb0 (diff) | |
download | ManaVerse-acba95ebb0119e7b0f9ef01d9bf3577582857253.tar.gz ManaVerse-acba95ebb0119e7b0f9ef01d9bf3577582857253.tar.bz2 ManaVerse-acba95ebb0119e7b0f9ef01d9bf3577582857253.tar.xz ManaVerse-acba95ebb0119e7b0f9ef01d9bf3577582857253.zip |
Add clan window.
For now can be opened only by chat command /clan.
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/Makefile.am | 4 | ||||
-rw-r--r-- | src/actions/windows.h | 1 | ||||
-rw-r--r-- | src/being/localclan.h | 2 | ||||
-rw-r--r-- | src/enums/input/inputaction.h | 1 | ||||
-rw-r--r-- | src/game.cpp | 3 | ||||
-rw-r--r-- | src/gui/widgets/layoutcell.h | 6 | ||||
-rw-r--r-- | src/gui/widgets/tabs/clanwindowtabs.cpp | 162 | ||||
-rw-r--r-- | src/gui/widgets/tabs/clanwindowtabs.h | 83 | ||||
-rw-r--r-- | src/gui/windows/clanwindow.cpp | 163 | ||||
-rw-r--r-- | src/gui/windows/clanwindow.h | 77 | ||||
-rw-r--r-- | src/input/inputactionmap.h | 12 | ||||
-rw-r--r-- | src/net/eathena/clanrecv.cpp | 5 | ||||
-rw-r--r-- | src/progs/dyecmd/actions/windows.cpp | 1 | ||||
-rw-r--r-- | src/progs/manaplus/actions/windows.cpp | 7 | ||||
-rw-r--r-- | src/resources/claninfo.h | 4 | ||||
-rw-r--r-- | src/resources/db/clandb.cpp | 2 | ||||
-rw-r--r-- | src/utils/itemxmlutils.cpp | 25 | ||||
-rw-r--r-- | src/utils/itemxmlutils.h | 5 |
19 files changed, 564 insertions, 3 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e748661dd..24e7a7817 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -135,6 +135,8 @@ SET(SRCS gui/widgets/attrs/changedisplay.h gui/widgets/attrs/derdisplay.cpp gui/widgets/attrs/derdisplay.h + gui/widgets/tabs/clanwindowtabs.cpp + gui/widgets/tabs/clanwindowtabs.h gui/widgets/tabs/debugwindowtabs.cpp gui/widgets/tabs/debugwindowtabs.h gui/widgets/tabs/chat/chattab.cpp @@ -355,6 +357,8 @@ SET(SRCS gui/windows/chardeleteconfirm.h gui/windows/chatwindow.cpp gui/windows/chatwindow.h + gui/windows/clanwindow.cpp + gui/windows/clanwindow.h gui/windows/confirmdialog.cpp gui/windows/confirmdialog.h gui/windows/connectiondialog.cpp diff --git a/src/Makefile.am b/src/Makefile.am index b7d86b47d..349d1e17d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1128,6 +1128,8 @@ SRC = ${BASE_SRC} \ gui/widgets/attrs/changedisplay.h \ gui/widgets/attrs/derdisplay.cpp \ gui/widgets/attrs/derdisplay.h \ + gui/widgets/tabs/clanwindowtabs.cpp \ + gui/widgets/tabs/clanwindowtabs.h \ gui/widgets/tabs/debugwindowtabs.cpp \ gui/widgets/tabs/debugwindowtabs.h \ gui/widgets/tabs/chat/chattab.cpp \ @@ -1302,6 +1304,8 @@ SRC = ${BASE_SRC} \ gui/windows/chardeleteconfirm.h \ gui/windows/chatwindow.cpp \ gui/windows/chatwindow.h \ + gui/windows/clanwindow.cpp \ + gui/windows/clanwindow.h \ gui/windows/connectiondialog.cpp \ gui/windows/connectiondialog.h \ gui/windows/debugwindow.cpp \ diff --git a/src/actions/windows.h b/src/actions/windows.h index 9349a97a6..97851870b 100644 --- a/src/actions/windows.h +++ b/src/actions/windows.h @@ -55,6 +55,7 @@ namespace Actions decHandler(quickWindowShow); decHandler(mailWindowShow); decHandler(serverInfoWindowShow); + decHandler(clanWindowShow); decHandler(showItems); } // namespace Actions diff --git a/src/being/localclan.h b/src/being/localclan.h index 9145184b5..d1f9a49b6 100644 --- a/src/being/localclan.h +++ b/src/being/localclan.h @@ -62,7 +62,7 @@ struct LocalClan final std::string name; std::string masterName; std::string mapName; - std::string stats; + STD_VECTOR<std::string> stats; int id; int onlineMembers; int totalMembers; diff --git a/src/enums/input/inputaction.h b/src/enums/input/inputaction.h index 675dc55fe..06602f8ba 100644 --- a/src/enums/input/inputaction.h +++ b/src/enums/input/inputaction.h @@ -709,6 +709,7 @@ enumStart(InputAction) PET_RETURN_TO_EGG, PET_UNEQUIP, ADD_SKILL_SHORTCUT, + WINDOW_CLAN, TOTAL } enumEnd(InputAction); diff --git a/src/game.cpp b/src/game.cpp index 7cf1ef7de..bb9559924 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -61,6 +61,7 @@ #include "gui/popups/popupmenu.h" #include "gui/windows/bankwindow.h" +#include "gui/windows/clanwindow.h" #include "gui/windows/cutinwindow.h" #include "gui/windows/mailwindow.h" #include "gui/windows/chatwindow.h" @@ -283,6 +284,7 @@ static void createGuiWindows() CREATEWIDGETV0(killStats, KillStats); CREATEWIDGETV0(socialWindow, SocialWindow); CREATEWIDGETV0(questsWindow, QuestsWindow); + CREATEWIDGETV0(clanWindow, ClanWindow); // TRANSLATORS: chat tab header localChatTab = new ChatTab(chatWindow, _("General"), @@ -391,6 +393,7 @@ static void destroyGuiWindows() delete2(questsWindow); delete2(whoIsOnline); delete2(killStats); + delete2(clanWindow); } Game *Game::mInstance = nullptr; diff --git a/src/gui/widgets/layoutcell.h b/src/gui/widgets/layoutcell.h index 3067d9677..3a28fd30c 100644 --- a/src/gui/widgets/layoutcell.h +++ b/src/gui/widgets/layoutcell.h @@ -59,6 +59,12 @@ class LayoutCell notfinal LayoutCell &setPadding(int p) { mHPadding = p; mVPadding = p; return *this; } + int getVPadding() const + { return mVPadding; } + + int getHPadding() const + { return mHPadding; } + /** * Sets the vertical padding around the cell content. */ diff --git a/src/gui/widgets/tabs/clanwindowtabs.cpp b/src/gui/widgets/tabs/clanwindowtabs.cpp new file mode 100644 index 000000000..a73e8ce39 --- /dev/null +++ b/src/gui/widgets/tabs/clanwindowtabs.cpp @@ -0,0 +1,162 @@ +/* + * The ManaPlus Client + * Copyright (C) 2011-2018 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "gui/widgets/tabs/clanwindowtabs.h" + +#include "being/localclan.h" + +#include "gui/widgets/containerplacer.h" +#include "gui/widgets/label.h" +#include "gui/widgets/layouthelper.h" + +#include "utils/foreach.h" +#include "utils/gettext.h" +#include "utils/stringutils.h" + +#include "debug.h" + +InfoClanTab::InfoClanTab(const Widget2 *const widget) : + Container(widget), + mNameLabel(new Label(this, " ")), + mMasterLabel(new Label(this, " ")), + mMapLabel(new Label(this, " ")) +{ + setSelectable(false); + + LayoutHelper h(this); + ContainerPlacer place = h.getPlacer(0, 0); + + place(0, 0, mNameLabel, 2, 1); + place(0, 1, mMasterLabel, 2, 1); + place(0, 2, mMapLabel, 2, 1); + + place.getCell().matchColWidth(0, 0); + setDimension(Rect(0, 0, 600, 300)); +} + +void InfoClanTab::resetClan() +{ + // TRANSLATORS: not in clan label + mNameLabel->setCaption(strprintf(_("Not in clan"))); + mMasterLabel->setCaption(std::string()); + mMapLabel->setCaption(std::string()); +} + +void InfoClanTab::updateClan() +{ + mNameLabel->setCaption(strprintf("%s: %s", + // TRANSLATORS: clan name label + _("Clan name"), + localClan.name.c_str())); + mMasterLabel->setCaption(strprintf("%s: %s", + // TRANSLATORS: clan master name label + _("Master name"), + localClan.masterName.c_str())); + mMapLabel->setCaption(strprintf("%s: %s", + // TRANSLATORS: clan map name label + _("Map name"), + localClan.mapName.c_str())); +} + +StatsClanTab::StatsClanTab(const Widget2 *const widget) : + Container(widget), + mLabels() +{ + setSelectable(false); +} + +void StatsClanTab::clearLabels() +{ + FOR_EACH (STD_VECTOR<Label*>::iterator, it, mLabels) + { + remove(*it); + delete *it; + } + mLabels.clear(); +} + +void StatsClanTab::resetClan() +{ + clearLabels(); +} + + +void StatsClanTab::updateClan() +{ + clearLabels(); + + LayoutHelper h(this); + + const int hPadding = h.getLayout().getHPadding(); + const int vPadding = h.getLayout().getVPadding(); + int y = vPadding; + FOR_EACH (STD_VECTOR<std::string>::const_iterator, it, localClan.stats) + { + Label *const label = new Label(this, *it); + add(label); + label->setPosition(hPadding, y); + label->adjustSize(); + y += label->getHeight() + vPadding; + mLabels.push_back(label); + } +} + +RelationClanTab::RelationClanTab(const Widget2 *const widget) : + Container(widget), + mLabels() +{ + setSelectable(false); +} + +void RelationClanTab::clearLabels() +{ + FOR_EACH (STD_VECTOR<Label*>::iterator, it, mLabels) + { + remove(*it); + delete *it; + } + mLabels.clear(); +} + +void RelationClanTab::resetClan() +{ + clearLabels(); +} + +void RelationClanTab::updateClan(const STD_VECTOR<std::string> &restrict names) +{ + clearLabels(); + + LayoutHelper h(this); + + const int hPadding = h.getLayout().getHPadding(); + const int vPadding = h.getLayout().getVPadding(); + int y = vPadding; + FOR_EACH (STD_VECTOR<std::string>::const_iterator, it, names) + { + Label *const label = new Label(this, *it); + add(label); + label->setPosition(hPadding, y); + label->adjustSize(); + y += label->getHeight() + vPadding; + mLabels.push_back(label); + } +} + diff --git a/src/gui/widgets/tabs/clanwindowtabs.h b/src/gui/widgets/tabs/clanwindowtabs.h new file mode 100644 index 000000000..752c6d87a --- /dev/null +++ b/src/gui/widgets/tabs/clanwindowtabs.h @@ -0,0 +1,83 @@ +/* + * The ManaPlus Client + * Copyright (C) 2011-2018 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GUI_WIDGETS_TABS_DEBUGWINDOWTABS_H +#define GUI_WIDGETS_TABS_DEBUGWINDOWTABS_H + +#include "gui/widgets/container.h" + +#include "utils/vector.h" + +#include <string> + +class Label; + +class InfoClanTab final : public Container +{ + public: + explicit InfoClanTab(const Widget2 *const widget); + + A_DELETE_COPY(InfoClanTab) + + void resetClan(); + + void updateClan(); + + private: + Label *mNameLabel A_NONNULLPOINTER; + Label *mMasterLabel A_NONNULLPOINTER; + Label *mMapLabel A_NONNULLPOINTER; +}; + +class StatsClanTab final : public Container +{ + public: + explicit StatsClanTab(const Widget2 *const widget); + + A_DELETE_COPY(StatsClanTab) + + void clearLabels(); + + void resetClan(); + + void updateClan(); + + private: + STD_VECTOR<Label*> mLabels; +}; + +class RelationClanTab final : public Container +{ + public: + explicit RelationClanTab(const Widget2 *const widget); + + A_DELETE_COPY(RelationClanTab) + + void clearLabels(); + + void resetClan(); + + void updateClan(const STD_VECTOR<std::string> &restrict names); + + private: + STD_VECTOR<Label*> mLabels; +}; + +#endif // GUI_WIDGETS_TABS_DEBUGWINDOWTABS_H diff --git a/src/gui/windows/clanwindow.cpp b/src/gui/windows/clanwindow.cpp new file mode 100644 index 000000000..9d08e5914 --- /dev/null +++ b/src/gui/windows/clanwindow.cpp @@ -0,0 +1,163 @@ +/* + * The ManaPlus Client + * Copyright (C) 2011-2018 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "gui/windows/clanwindow.h" + +#include "being/localclan.h" +#include "being/localplayer.h" + +#include "gui/windows/setupwindow.h" + +#include "gui/widgets/createwidget.h" +#include "gui/widgets/tabbedarea.h" + +#include "gui/widgets/tabs/clanwindowtabs.h" + +#include "utils/delete2.h" +#include "utils/gettext.h" + +#include "debug.h" + +ClanWindow *clanWindow = nullptr; + +ClanWindow::ClanWindow() : + // TRANSLATORS: clan window name + Window(_("Clan"), Modal_false, nullptr, "clan.xml"), + mTabs(CREATEWIDGETR(TabbedArea, this)), + mInfoWidget(new InfoClanTab(this)), + mStatsWidget(new StatsClanTab(this)), + mAllyWidget(new RelationClanTab(this)), + mAntagonistWidget(new RelationClanTab(this)) +{ + setWindowName("clan"); + if (setupWindow != nullptr) + setupWindow->registerWindowForReset(this); + + setResizable(true); + setCloseButton(true); + setSaveVisible(true); + setStickyButtonLock(true); + + setDefaultSize(400, 300, ImagePosition::CENTER, 0, 0); + + mTabs->setSelectable(false); + mTabs->getWidgetContainer()->setSelectable(false); + mTabs->getTabContainer()->setSelectable(false); + // TRANSLATORS: clan window tab + mTabs->addTab(std::string(_("Info")), mInfoWidget); + // TRANSLATORS: clan window tab + mTabs->addTab(std::string(_("Stats")), mStatsWidget); + // TRANSLATORS: clan window tab + mTabs->addTab(std::string(_("Ally")), mAllyWidget); + // TRANSLATORS: clan window tab + mTabs->addTab(std::string(_("Antagonist")), mAntagonistWidget); + + mTabs->setDimension(Rect(0, 0, 600, 300)); + + const int w = mDimension.width; + const int h = mDimension.height; + mInfoWidget->setDimension(Rect(0, 0, w, h)); + mStatsWidget->setDimension(Rect(0, 0, w, h)); + mAllyWidget->setDimension(Rect(0, 0, w, h)); + mAntagonistWidget->setDimension(Rect(0, 0, w, h)); + loadWindowState(); + enableVisibleSound(true); + resetClan(); +} + +ClanWindow::~ClanWindow() +{ + delete2(mInfoWidget); + delete2(mStatsWidget); + delete2(mAllyWidget); + delete2(mAntagonistWidget); +} + +void ClanWindow::postInit() +{ + Window::postInit(); + add(mTabs); +} + +void ClanWindow::slowLogic() +{ + BLOCK_START("ClanWindow::slowLogic") + if (!isWindowVisible() || (mTabs == nullptr)) + { + BLOCK_END("ClanWindow::slowLogic") + return; + } + + switch (mTabs->getSelectedTabIndex()) + { + default: + case 0: + mInfoWidget->logic(); + break; + case 1: + mStatsWidget->logic(); + break; + case 2: + mAllyWidget->logic(); + break; + case 3: + mAntagonistWidget->logic(); + break; + } + + BLOCK_END("ClanWindow::slowLogic") +} + +void ClanWindow::widgetResized(const Event &event) +{ + Window::widgetResized(event); + + mTabs->setDimension(Rect(0, 0, + mDimension.width, mDimension.height)); +} + +void ClanWindow::updateClan() +{ + mInfoWidget->updateClan(); + mStatsWidget->updateClan(); + mAllyWidget->updateClan(localClan.allyClans); + mAntagonistWidget->updateClan(localClan.antagonistClans); +} + +void ClanWindow::resetClan() +{ + mInfoWidget->resetClan(); + mStatsWidget->resetClan(); + mAllyWidget->resetClan(); + mAntagonistWidget->resetClan(); +} + +void ClanWindow::updateClanMembers() +{ +} + +#ifdef USE_PROFILER +void ClanWindow::logicChildren() +{ + BLOCK_START("ClanWindow::logicChildren") + BasicContainer::logicChildren(); + BLOCK_END("ClanWindow::logicChildren") +} +#endif // USE_PROFILER diff --git a/src/gui/windows/clanwindow.h b/src/gui/windows/clanwindow.h new file mode 100644 index 000000000..5251d9b32 --- /dev/null +++ b/src/gui/windows/clanwindow.h @@ -0,0 +1,77 @@ +/* + * The ManaPlus Client + * Copyright (C) 2011-2018 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GUI_WINDOWS_CLANWINDOW_H +#define GUI_WINDOWS_CLANWINDOW_H + +#include "gui/widgets/window.h" + +class InfoClanTab; +class RelationClanTab; +class StatsClanTab; +class TabbedArea; + +/** + * The clan window. + * + * \ingroup Interface + */ +class ClanWindow final : public Window +{ + public: + /** + * Constructor. + */ + ClanWindow(); + + A_DELETE_COPY(ClanWindow) + + ~ClanWindow() override final; + + void postInit() override final; + + /** + * Logic (updates components' size and infos) + */ + void slowLogic(); + + void widgetResized(const Event &event) override final; + + void resetClan(); + + void updateClan(); + + void updateClanMembers(); + +#ifdef USE_PROFILER + void logicChildren(); +#endif // USE_PROFILER + + private: + TabbedArea *mTabs A_NONNULLPOINTER; + InfoClanTab *mInfoWidget A_NONNULLPOINTER; + StatsClanTab *mStatsWidget A_NONNULLPOINTER; + RelationClanTab *mAllyWidget A_NONNULLPOINTER; + RelationClanTab *mAntagonistWidget A_NONNULLPOINTER; +}; + +extern ClanWindow *clanWindow; + +#endif // GUI_WINDOWS_CLANWINDOW_H diff --git a/src/input/inputactionmap.h b/src/input/inputactionmap.h index 45561eec6..6e00ebe10 100644 --- a/src/input/inputactionmap.h +++ b/src/input/inputactionmap.h @@ -5954,6 +5954,18 @@ static const InputActionData inputActionData "addskillshortcut|skillshortcut", UseArgs_true, Protected_false}, + {"keyWindowClan", + emptyKey, + emptyKey, + Input::GRP_DEFAULT | Input::GRP_GUI, + &Actions::clanWindowShow, + InputAction::NO_VALUE, 50, + InputCondition::KEY_DOWN | + InputCondition::GAME | + InputCondition::NOTARGET, + "clanwindow|clan", + UseArgs_false, + Protected_false}, }; #undef defaultAction diff --git a/src/net/eathena/clanrecv.cpp b/src/net/eathena/clanrecv.cpp index 7324003b3..c2c5680db 100644 --- a/src/net/eathena/clanrecv.cpp +++ b/src/net/eathena/clanrecv.cpp @@ -27,6 +27,7 @@ #include "gui/widgets/tabs/chat/clantab.h" #include "gui/windows/chatwindow.h" +#include "gui/windows/clanwindow.h" #include "net/messagein.h" @@ -72,17 +73,21 @@ void ClanRecv::processClanInfo(Net::MessageIn &msg) localClan.stats = info->stats; } createTab(); + clanWindow->updateClan(); } void ClanRecv::processClanOnlineCount(Net::MessageIn &msg) { localClan.onlineMembers = msg.readInt16("online members count"); localClan.totalMembers = msg.readInt16("total members count"); + clanWindow->updateClanMembers(); } void ClanRecv::processClanLeave(Net::MessageIn &msg A_UNUSED) { delete2(clanTab); + localClan.clear(); + clanWindow->resetClan(); } void ClanRecv::processClanChat(Net::MessageIn &msg) diff --git a/src/progs/dyecmd/actions/windows.cpp b/src/progs/dyecmd/actions/windows.cpp index 0ebbaaa7b..c5ab862fa 100644 --- a/src/progs/dyecmd/actions/windows.cpp +++ b/src/progs/dyecmd/actions/windows.cpp @@ -55,6 +55,7 @@ impHandlerVoid(updaterWindowShow) impHandlerVoid(quickWindowShow) impHandlerVoid(mailWindowShow) impHandlerVoid(serverInfoWindowShow) +impHandlerVoid(clanWindowShow) impHandlerVoid(showItems) } // namespace Actions diff --git a/src/progs/manaplus/actions/windows.cpp b/src/progs/manaplus/actions/windows.cpp index 7368ec287..04e0bcb64 100644 --- a/src/progs/manaplus/actions/windows.cpp +++ b/src/progs/manaplus/actions/windows.cpp @@ -30,6 +30,7 @@ #include "gui/dialogsmanager.h" #include "gui/windows/bankwindow.h" +#include "gui/windows/clanwindow.h" #include "gui/windows/skilldialog.h" #include "gui/windows/socialwindow.h" #include "gui/windows/statuswindow.h" @@ -343,6 +344,12 @@ impHandler0(serverInfoWindowShow) return true; } +impHandler0(clanWindowShow) +{ + showHideWindow(clanWindow); + return true; +} + impHandler(showItems) { const std::string args = event.args; diff --git a/src/resources/claninfo.h b/src/resources/claninfo.h index 3e510dcbf..fd96ecf51 100644 --- a/src/resources/claninfo.h +++ b/src/resources/claninfo.h @@ -21,6 +21,8 @@ #ifndef RESOURCES_CLANINFO_H #define RESOURCES_CLANINFO_H +#include "utils/vector.h" + #include <string> #include "localconsts.h" @@ -34,7 +36,7 @@ struct ClanInfo final A_DELETE_COPY(ClanInfo) - std::string stats; + STD_VECTOR<std::string> stats; int id; }; diff --git a/src/resources/db/clandb.cpp b/src/resources/db/clandb.cpp index 977d5439f..e4cf691dd 100644 --- a/src/resources/db/clandb.cpp +++ b/src/resources/db/clandb.cpp @@ -97,7 +97,7 @@ void ClanDb::loadXmlFile(const std::string &fileName, clanInfo->id = id; - readItemStatsString(clanInfo->stats, + readItemStatsVector(clanInfo->stats, clanNode, addFields); diff --git a/src/utils/itemxmlutils.cpp b/src/utils/itemxmlutils.cpp index cbf642c4f..2f849b8ce 100644 --- a/src/utils/itemxmlutils.cpp +++ b/src/utils/itemxmlutils.cpp @@ -54,3 +54,28 @@ void readItemStatsString(std::string &effect, value.c_str())); } } + +void readItemStatsVector(STD_VECTOR<std::string> &effect, + XmlNodeConstPtr node, + const ItemFieldInfos &fields) +{ + if (translator == nullptr) + return; + + FOR_EACH (ItemFieldInfos::const_iterator, it, fields) + { + const std::string fieldName = (*it).first; + const ItemFieldType *const field = (*it).second; + + std::string value = XML::getProperty(node, + fieldName.c_str(), + ""); + if (value.empty()) + continue; + if (field->sign && isDigit(value)) + value = std::string("+").append(value); + const std::string format = translator->getStr(field->description); + effect.push_back(strprintf(format.c_str(), + value.c_str())); + } +} diff --git a/src/utils/itemxmlutils.h b/src/utils/itemxmlutils.h index 66f5d8fcd..c0f2860cb 100644 --- a/src/utils/itemxmlutils.h +++ b/src/utils/itemxmlutils.h @@ -21,6 +21,7 @@ #ifndef UTILS_ITEMXMLUTILS_H #define UTILS_ITEMXMLUTILS_H +#include "utils/vector.h" #include "utils/xml.h" #include "resources/itemfieldinfos.h" @@ -31,4 +32,8 @@ void readItemStatsString(std::string &effect, XmlNodeConstPtr node, const ItemFieldInfos &fields); +void readItemStatsVector(STD_VECTOR<std::string> &effect, + XmlNodeConstPtr node, + const ItemFieldInfos &fields); + #endif // UTILS_ITEMXMLUTILS_H |