diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-05-21 23:17:42 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-05-21 23:18:46 +0300 |
commit | e8ea0251867c12ed1f6122a37b21044279774be5 (patch) | |
tree | 78426d0aeee6fda9bfd85047e241884f3f6c232a | |
parent | cff8c1925f426dafaeb32def5fc56f170bafba39 (diff) | |
download | manaplus-e8ea0251867c12ed1f6122a37b21044279774be5.tar.gz manaplus-e8ea0251867c12ed1f6122a37b21044279774be5.tar.bz2 manaplus-e8ea0251867c12ed1f6122a37b21044279774be5.tar.xz manaplus-e8ea0251867c12ed1f6122a37b21044279774be5.zip |
improve skilldialog class.
split skilldialog file.
-rw-r--r-- | src/CMakeLists.txt | 6 | ||||
-rw-r--r-- | src/Makefile.am | 6 | ||||
-rw-r--r-- | src/being.cpp | 1 | ||||
-rw-r--r-- | src/gui/skilldialog.cpp | 243 | ||||
-rw-r--r-- | src/gui/skilldialog.h | 68 | ||||
-rw-r--r-- | src/gui/widgets/itemshortcutcontainer.cpp | 2 | ||||
-rw-r--r-- | src/gui/widgets/skilldata.cpp | 63 | ||||
-rw-r--r-- | src/gui/widgets/skilldata.h | 50 | ||||
-rw-r--r-- | src/gui/widgets/skillinfo.cpp | 131 | ||||
-rw-r--r-- | src/gui/widgets/skillinfo.h | 68 | ||||
-rw-r--r-- | src/gui/widgets/skillmodel.cpp | 90 | ||||
-rw-r--r-- | src/gui/widgets/skillmodel.h | 86 | ||||
-rw-r--r-- | src/localplayer.h | 2 |
13 files changed, 523 insertions, 293 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a90dbc212..1349ea994 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -206,6 +206,12 @@ SET(SRCS gui/widgets/shoplistbox.h gui/widgets/shortcutcontainer.cpp gui/widgets/shortcutcontainer.h + gui/widgets/skilldata.cpp + gui/widgets/skilldata.h + gui/widgets/skillinfo.cpp + gui/widgets/skillinfo.h + gui/widgets/skillmodel.cpp + gui/widgets/skillmodel.h gui/widgets/slider.cpp gui/widgets/slider.h gui/widgets/sliderlist.cpp diff --git a/src/Makefile.am b/src/Makefile.am index afef46e1b..211164a0c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -207,6 +207,12 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ gui/widgets/shoplistbox.h \ gui/widgets/shortcutcontainer.cpp \ gui/widgets/shortcutcontainer.h \ + gui/widgets/skilldata.cpp \ + gui/widgets/skilldata.h \ + gui/widgets/skillinfo.cpp \ + gui/widgets/skillinfo.h \ + gui/widgets/skillmodel.cpp \ + gui/widgets/skillmodel.h \ gui/widgets/slider.cpp \ gui/widgets/slider.h \ gui/widgets/sliderlist.cpp \ diff --git a/src/being.cpp b/src/being.cpp index efbfa35c6..309069a5a 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -57,6 +57,7 @@ #include "resources/resourcemanager.h" #include "gui/widgets/langtab.h" +#include "gui/widgets/skillinfo.h" #include "utils/gettext.h" diff --git a/src/gui/skilldialog.cpp b/src/gui/skilldialog.cpp index 44d9d0283..693dc6c8b 100644 --- a/src/gui/skilldialog.cpp +++ b/src/gui/skilldialog.cpp @@ -22,81 +22,12 @@ #include "gui/skilldialog.h" -#include "configuration.h" -#include "effectmanager.h" -#include "itemshortcut.h" -#include "localplayer.h" -#include "playerinfo.h" - -#include "gui/setup.h" -#include "gui/shortcutwindow.h" -#include "gui/textpopup.h" -#include "gui/viewport.h" - -#include "gui/widgets/label.h" -#include "gui/widgets/layouthelper.h" -#include "gui/widgets/listbox.h" -#include "gui/widgets/progressbar.h" -#include "gui/widgets/scrollarea.h" -#include "gui/widgets/tab.h" - -#include "net/net.h" -#include "net/playerhandler.h" -#include "net/skillhandler.h" - -#include "resources/image.h" -#include "resources/resourcemanager.h" - -#include "utils/dtor.h" -#include "utils/gettext.h" - -#include <guichan/font.hpp> - -#include <set> -#include <string> +#include "gui/widgets/skillmodel.h" #include "debug.h" -class SkillModel; class SkillEntry; -class SkillModel final : public gcn::ListModel -{ - public: - SkillModel() : - mSkills(), - mVisibleSkills() - { - } - - int getNumberOfElements() - { return static_cast<int>(mVisibleSkills.size()); } - - SkillInfo *getSkillAt(const int i) const - { - if (i < 0 || i >= static_cast<int>(mVisibleSkills.size())) - return nullptr; - return mVisibleSkills.at(i); - } - - std::string getElementAt(int i) - { - if (getSkillAt(i)) - return getSkillAt(i)->data->name; - else - return ""; - } - - void updateVisibilities(); - - void addSkill(SkillInfo *const info) - { mSkills.push_back(info); } - - private: - SkillList mSkills; - SkillList mVisibleSkills; -}; - class SkillListBox final : public ListBox { public: @@ -137,7 +68,7 @@ class SkillListBox final : public ListBox return static_cast<SkillModel*>(mListModel)->getSkillAt(selected); } - void draw(gcn::Graphics *gcnGraphics) + void draw(gcn::Graphics *gcnGraphics) override { if (!mListModel) return; @@ -193,10 +124,10 @@ class SkillListBox final : public ListBox } } - unsigned int getRowHeight() const + unsigned int getRowHeight() const override { return mRowHeight; } - void mouseMoved(gcn::MouseEvent &event) + void mouseMoved(gcn::MouseEvent &event) override { ListBox::mouseMoved(event); if (!viewport) @@ -213,7 +144,7 @@ class SkillListBox final : public ListBox skill->data->dispName, skill->data->description); } - void mouseExited(gcn::MouseEvent &event A_UNUSED) + void mouseExited(gcn::MouseEvent &event A_UNUSED) override { mPopup->hide(); } @@ -257,7 +188,7 @@ class SkillTab final : public Tab } protected: - void setCurrent() + void setCurrent() override { if (skillDialog) skillDialog->updateTabSelection(); @@ -304,7 +235,6 @@ SkillDialog::SkillDialog() : SkillDialog::~SkillDialog() { - // Clear gui clearSkills(); } @@ -622,19 +552,7 @@ void SkillDialog::addSkill(const int id, const int level, const int range, } } -void SkillModel::updateVisibilities() -{ - mVisibleSkills.clear(); - - FOR_EACH (SkillList::const_iterator, it, mSkills) - { - if ((*it) && (*it)->visible) - mVisibleSkills.push_back((*it)); - } -} - - -SkillInfo* SkillDialog::getSkill(int id) +SkillInfo* SkillDialog::getSkill(const int id) { return mSkills[id]; } @@ -647,9 +565,14 @@ void SkillDialog::widgetResized(const gcn::Event &event) mTabs->fixSize(); } -void SkillDialog::useItem(const int itemId) +void SkillDialog::useItem(const int itemId) const { - const SkillInfo *const info = mSkills[itemId - SKILL_MIN_ID]; + const std::map<int, SkillInfo*>::const_iterator + it = mSkills.find(itemId - SKILL_MIN_ID); + if (it == mSkills.end()) + return; + + const SkillInfo *const info = (*it).second; if (info && player_node && player_node->getTarget()) { const Being *const being = player_node->getTarget(); @@ -696,7 +619,7 @@ void SkillDialog::updateQuest(const int var, const int val) } } -void SkillDialog::playUpdateEffect(const int id) +void SkillDialog::playUpdateEffect(const int id) const { const int effectId = paths.getIntValue("skillLevelUpEffectId"); if (!effectManager || effectId == -1) @@ -708,139 +631,3 @@ void SkillDialog::playUpdateEffect(const int id) effectManager->trigger(effectId, player_node); } } - -SkillInfo::SkillInfo() : - level(0), - skillLevel(), - skillLevelWidth(0), - id(0), - modifiable(false), - visible(false), - model(nullptr), - skillExp(), - progress(0.0f), - range(0), - color(), - data(nullptr), - dataMap() -{ - dataMap[0] = new SkillData(); - data = dataMap[0]; -} - -SkillInfo::~SkillInfo() -{ - FOR_EACH (SkillDataMapIter, it, dataMap) - delete (*it).second; - dataMap.clear(); -} - -void SkillInfo::update() -{ - const int baseLevel = PlayerInfo::getSkillLevel(id); - const std::pair<int, int> exp = PlayerInfo::getStatExperience(id); - - if (!modifiable && baseLevel == 0 && exp.second == 0) - { - if (visible) - { - visible = false; - if (model) - model->updateVisibilities(); - } - return; - } - - const bool updateVisibility = !visible; - visible = true; - - if (baseLevel == 0) - { - skillLevel.clear(); - } - else - { - // TRANSLATORS: skills dialog. skill level - skillLevel = strprintf(_("Lvl: %d"), baseLevel); - } - - level = baseLevel; - skillLevelWidth = -1; - - if (exp.second) - { - skillExp = strprintf("%d / %d", exp.first, exp.second); - progress = static_cast<float>(exp.first) - / static_cast<float>(exp.second); - } - else - { - skillExp.clear(); - progress = 0.0f; - } - - color = Theme::getProgressColor(Theme::PROG_EXP, progress); - - if (updateVisibility && model) - model->updateVisibilities(); - - data = getData(level); - if (!data) - data = dataMap[0]; -} - - -void SkillInfo::addData(const int level1, SkillData *const data1) -{ - dataMap[level1] = data1; -} - -SkillData *SkillInfo::getData(const int level1) -{ - SkillDataMapIter it = dataMap.find(level1); - if (it == dataMap.end()) - return nullptr; - return (*it).second; -} - -SkillData *SkillInfo::getData1(const int lev) -{ - SkillDataMapIter it = dataMap.find(lev); - if (it == dataMap.end()) - return dataMap[0]; - return (*it).second; -} - -SkillData::SkillData() : - name(), - shortName(), - dispName(), - description(), - icon(nullptr), - particle(), - soundHit("", 0), - soundMiss("", 0) -{ -} - -SkillData::~SkillData() -{ - if (icon) - { - icon->decRef(); - icon = nullptr; - } -} - -void SkillData::setIcon(const std::string &iconPath) -{ - ResourceManager *const res = ResourceManager::getInstance(); - if (!iconPath.empty()) - icon = res->getImage(iconPath); - - if (!icon) - { - icon = Theme::getImageFromTheme( - paths.getStringValue("unknownItemFile")); - } -} diff --git a/src/gui/skilldialog.h b/src/gui/skilldialog.h index 2a9f69a77..ad3df5f8b 100644 --- a/src/gui/skilldialog.h +++ b/src/gui/skilldialog.h @@ -25,13 +25,7 @@ #include "gui/widgets/window.h" -#include "resources/soundinfo.h" - #include <guichan/actionlistener.hpp> -#include <guichan/mouselistener.hpp> - -#include <map> -#include <vector> const int SKILL_MIN_ID = 200000; const unsigned int SKILL_VAR_MIN_ID = 1000000; @@ -43,61 +37,7 @@ class SkillModel; class Tab; class TabbedArea; -struct SkillData final -{ - std::string name; - std::string shortName; - std::string dispName; - std::string description; - Image *icon; - - std::string particle; - SoundInfo soundHit; - SoundInfo soundMiss; - - SkillData(); - A_DELETE_COPY(SkillData) - ~SkillData(); - - void setIcon(const std::string &iconPath); -}; - -typedef std::map<int, SkillData*> SkillDataMap; -typedef SkillDataMap::iterator SkillDataMapIter; -typedef SkillDataMap::const_iterator SkillDataMapCIter; - -struct SkillInfo final -{ - int level; - std::string skillLevel; - int skillLevelWidth; - unsigned int id; - bool modifiable; - bool visible; - SkillModel *model; - std::string skillExp; - float progress; - int range; - gcn::Color color; - - SkillData *data; - SkillDataMap dataMap; - - SkillInfo(); - A_DELETE_COPY(SkillInfo) - ~SkillInfo(); - - void update(); - - SkillData *getData(const int level); - - SkillData *getData1(const int level); - - void addData(const int level, SkillData *const data); -}; - -typedef std::vector<SkillInfo*> SkillList; -typedef SkillList::iterator SkillListIter; +struct SkillInfo; /** * The skill dialog. @@ -137,20 +77,20 @@ class SkillDialog final : public Window, public gcn::ActionListener void addSkill(const int id, const int level, const int range, const bool modifiable); - SkillInfo* getSkill(int id) A_WARN_UNUSED; + SkillInfo* getSkill(const int id) A_WARN_UNUSED; bool hasSkills() const A_WARN_UNUSED { return !mSkills.empty(); } void widgetResized(const gcn::Event &event) override; - void useItem(const int itemId); + void useItem(const int itemId) const; void updateTabSelection(); void updateQuest(const int var, const int val); - void playUpdateEffect(const int id); + void playUpdateEffect(const int id) const; private: typedef std::map<int, SkillInfo*> SkillMap; diff --git a/src/gui/widgets/itemshortcutcontainer.cpp b/src/gui/widgets/itemshortcutcontainer.cpp index ff36d8805..3cfe52393 100644 --- a/src/gui/widgets/itemshortcutcontainer.cpp +++ b/src/gui/widgets/itemshortcutcontainer.cpp @@ -39,6 +39,8 @@ #include "gui/spellpopup.h" #include "gui/viewport.h" +#include "gui/widgets/skillinfo.h" + #include "resources/image.h" #include <guichan/font.hpp> diff --git a/src/gui/widgets/skilldata.cpp b/src/gui/widgets/skilldata.cpp new file mode 100644 index 000000000..a0d804660 --- /dev/null +++ b/src/gui/widgets/skilldata.cpp @@ -0,0 +1,63 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2013 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/skilldata.h" + +#include "configuration.h" + +#include "resources/resourcemanager.h" + +#include "debug.h" + +SkillData::SkillData() : + name(), + shortName(), + dispName(), + description(), + icon(nullptr), + particle(), + soundHit("", 0), + soundMiss("", 0) +{ +} + +SkillData::~SkillData() +{ + if (icon) + { + icon->decRef(); + icon = nullptr; + } +} + +void SkillData::setIcon(const std::string &iconPath) +{ + ResourceManager *const res = ResourceManager::getInstance(); + if (!iconPath.empty()) + icon = res->getImage(iconPath); + + if (!icon) + { + icon = Theme::getImageFromTheme( + paths.getStringValue("unknownItemFile")); + } +} diff --git a/src/gui/widgets/skilldata.h b/src/gui/widgets/skilldata.h new file mode 100644 index 000000000..63a73abed --- /dev/null +++ b/src/gui/widgets/skilldata.h @@ -0,0 +1,50 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2013 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 SKILLDATA_H +#define SKILLDATA_H + +#include "gui/theme.h" + +#include "resources/image.h" +#include "resources/soundinfo.h" + +struct SkillData final +{ + std::string name; + std::string shortName; + std::string dispName; + std::string description; + Image *icon; + + std::string particle; + SoundInfo soundHit; + SoundInfo soundMiss; + + SkillData(); + A_DELETE_COPY(SkillData) + ~SkillData(); + + void setIcon(const std::string &iconPath); +}; + +#endif diff --git a/src/gui/widgets/skillinfo.cpp b/src/gui/widgets/skillinfo.cpp new file mode 100644 index 000000000..2b7060c31 --- /dev/null +++ b/src/gui/widgets/skillinfo.cpp @@ -0,0 +1,131 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2013 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/skillinfo.h" + +#include "playerinfo.h" + +#include "gui/widgets/skillmodel.h" + +#include "debug.h" + +SkillInfo::SkillInfo() : + level(0), + skillLevel(), + skillLevelWidth(0), + id(0), + modifiable(false), + visible(false), + model(nullptr), + skillExp(), + progress(0.0f), + range(0), + color(), + data(nullptr), + dataMap() +{ + dataMap[0] = new SkillData(); + data = dataMap[0]; +} + +SkillInfo::~SkillInfo() +{ + FOR_EACH (SkillDataMapIter, it, dataMap) + delete (*it).second; + dataMap.clear(); +} + +void SkillInfo::update() +{ + const int baseLevel = PlayerInfo::getSkillLevel(id); + const std::pair<int, int> exp = PlayerInfo::getStatExperience(id); + + if (!modifiable && baseLevel == 0 && exp.second == 0) + { + if (visible) + { + visible = false; + if (model) + model->updateVisibilities(); + } + return; + } + + const bool updateVisibility = !visible; + visible = true; + + if (baseLevel == 0) + { + skillLevel.clear(); + } + else + { + // TRANSLATORS: skills dialog. skill level + skillLevel = strprintf(_("Lvl: %d"), baseLevel); + } + + level = baseLevel; + skillLevelWidth = -1; + + if (exp.second) + { + skillExp = strprintf("%d / %d", exp.first, exp.second); + progress = static_cast<float>(exp.first) + / static_cast<float>(exp.second); + } + else + { + skillExp.clear(); + progress = 0.0f; + } + + color = Theme::getProgressColor(Theme::PROG_EXP, progress); + + if (updateVisibility && model) + model->updateVisibilities(); + + data = getData(level); + if (!data) + data = dataMap[0]; +} + + +void SkillInfo::addData(const int level1, SkillData *const data1) +{ + dataMap[level1] = data1; +} + +SkillData *SkillInfo::getData(const int level1) const +{ + SkillDataMapCIter it = dataMap.find(level1); + if (it == dataMap.end()) + return nullptr; + return (*it).second; +} + +SkillData *SkillInfo::getData1(const int lev) const +{ + SkillDataMapCIter it = dataMap.find(lev); + if (it == dataMap.end()) + return (*dataMap.begin()).second; + return (*it).second; +} diff --git a/src/gui/widgets/skillinfo.h b/src/gui/widgets/skillinfo.h new file mode 100644 index 000000000..21c310ea1 --- /dev/null +++ b/src/gui/widgets/skillinfo.h @@ -0,0 +1,68 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2013 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 SKILLINFO_H +#define SKILLINFO_H + +#include "gui/widgets/skilldata.h" + +#include <map> + +class SkillModel; + +typedef std::map<int, SkillData*> SkillDataMap; +typedef SkillDataMap::iterator SkillDataMapIter; +typedef SkillDataMap::const_iterator SkillDataMapCIter; + +struct SkillInfo final +{ + int level; + std::string skillLevel; + int skillLevelWidth; + unsigned int id; + bool modifiable; + bool visible; + SkillModel *model; + std::string skillExp; + float progress; + int range; + gcn::Color color; + + SkillData *data; + SkillDataMap dataMap; + + SkillInfo(); + A_DELETE_COPY(SkillInfo) + ~SkillInfo(); + + void update(); + + SkillData *getData(const int level) const; + SkillData *getData1(const int level) const; + + void addData(const int level, SkillData *const data); +}; + +typedef std::vector<SkillInfo*> SkillList; +typedef SkillList::iterator SkillListIter; + +#endif diff --git a/src/gui/widgets/skillmodel.cpp b/src/gui/widgets/skillmodel.cpp new file mode 100644 index 000000000..f13604dea --- /dev/null +++ b/src/gui/widgets/skillmodel.cpp @@ -0,0 +1,90 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2013 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/skillmodel.h" + +#include "configuration.h" +#include "effectmanager.h" +#include "itemshortcut.h" +#include "localplayer.h" +#include "playerinfo.h" + +#include "gui/setup.h" +#include "gui/shortcutwindow.h" +#include "gui/textpopup.h" +#include "gui/viewport.h" + +#include "gui/widgets/label.h" +#include "gui/widgets/layouthelper.h" +#include "gui/widgets/listbox.h" +#include "gui/widgets/progressbar.h" +#include "gui/widgets/scrollarea.h" +#include "gui/widgets/tab.h" + +#include "net/net.h" +#include "net/playerhandler.h" +#include "net/skillhandler.h" + +#include "resources/image.h" +#include "resources/resourcemanager.h" + +#include "utils/dtor.h" +#include "utils/gettext.h" + +#include <guichan/font.hpp> + +#include <set> +#include <string> + +#include "debug.h" + +SkillModel::SkillModel() : + mSkills(), + mVisibleSkills() +{ +} + +SkillInfo *SkillModel::getSkillAt(const int i) const +{ + if (i < 0 || i >= static_cast<int>(mVisibleSkills.size())) + return nullptr; + return mVisibleSkills.at(i); +} + +std::string SkillModel::getElementAt(int i) +{ + if (getSkillAt(i)) + return getSkillAt(i)->data->name; + else + return ""; +} + +void SkillModel::updateVisibilities() +{ + mVisibleSkills.clear(); + + FOR_EACH (SkillList::const_iterator, it, mSkills) + { + if ((*it) && (*it)->visible) + mVisibleSkills.push_back((*it)); + } +} diff --git a/src/gui/widgets/skillmodel.h b/src/gui/widgets/skillmodel.h new file mode 100644 index 000000000..7bd113a18 --- /dev/null +++ b/src/gui/widgets/skillmodel.h @@ -0,0 +1,86 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2013 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 SKILLMODEL_H +#define SKILLMODEL_H + +#include "configuration.h" +#include "effectmanager.h" +#include "itemshortcut.h" +#include "localplayer.h" +#include "playerinfo.h" + +#include "gui/setup.h" +#include "gui/shortcutwindow.h" +#include "gui/textpopup.h" +#include "gui/viewport.h" + +#include "gui/widgets/label.h" +#include "gui/widgets/layouthelper.h" +#include "gui/widgets/listbox.h" +#include "gui/widgets/progressbar.h" +#include "gui/widgets/scrollarea.h" +#include "gui/widgets/skillinfo.h" +#include "gui/widgets/tab.h" + +#include "net/net.h" +#include "net/playerhandler.h" +#include "net/skillhandler.h" + +#include "resources/image.h" +#include "resources/resourcemanager.h" + +#include "utils/dtor.h" +#include "utils/gettext.h" + +#include <guichan/font.hpp> + +#include <set> +#include <string> + +#include "localconsts.h" + +struct SkillInfo; + +class SkillModel final : public gcn::ListModel +{ + public: + SkillModel(); + + SkillInfo *getSkillAt(const int i) const; + + std::string getElementAt(int i) override; + + int getNumberOfElements() override + { return static_cast<int>(mVisibleSkills.size()); } + + void addSkill(SkillInfo *const info) + { mSkills.push_back(info); } + + void updateVisibilities(); + + private: + SkillList mSkills; + SkillList mVisibleSkills; +}; + +#endif diff --git a/src/localplayer.h b/src/localplayer.h index 8f5a16367..0e6f2bf8c 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -41,7 +41,7 @@ class ImageSet; class Item; class Map; class OkDialog; -struct SkillInfo; +//struct SkillInfo; class AwayListener final : public gcn::ActionListener { |