summaryrefslogtreecommitdiff
path: root/src/gui/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/widgets')
-rw-r--r--src/gui/widgets/itemshortcutcontainer.cpp2
-rw-r--r--src/gui/widgets/skilldata.cpp63
-rw-r--r--src/gui/widgets/skilldata.h50
-rw-r--r--src/gui/widgets/skillinfo.cpp131
-rw-r--r--src/gui/widgets/skillinfo.h68
-rw-r--r--src/gui/widgets/skillmodel.cpp90
-rw-r--r--src/gui/widgets/skillmodel.h86
7 files changed, 490 insertions, 0 deletions
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