summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-12-16 22:03:21 +0300
committerAndrei Karas <akaras@inbox.ru>2012-12-16 22:33:53 +0300
commit4520aa5631f5dfa9d941231a11c2ba782f456dd0 (patch)
treea01027e50987230d63aaeeccc65c074c3a6dca7c
parent99fc034012a3c97805014d578c8bb910beabfbc5 (diff)
downloadmanaverse-4520aa5631f5dfa9d941231a11c2ba782f456dd0.tar.gz
manaverse-4520aa5631f5dfa9d941231a11c2ba782f456dd0.tar.bz2
manaverse-4520aa5631f5dfa9d941231a11c2ba782f456dd0.tar.xz
manaverse-4520aa5631f5dfa9d941231a11c2ba782f456dd0.zip
Allow different skill images/names etc for each skill level.
-rw-r--r--src/being.cpp6
-rw-r--r--src/gui/skilldialog.cpp127
-rw-r--r--src/gui/skilldialog.h14
-rw-r--r--src/gui/widgets/itemshortcutcontainer.cpp4
4 files changed, 97 insertions, 54 deletions
diff --git a/src/being.cpp b/src/being.cpp
index fa7b3ee85..6f530f9e8 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -772,7 +772,7 @@ void Being::handleSkill(Being *const victim, const int damage,
const SkillInfo *const skill = skillDialog->getSkill(skillId);
if (skill)
- fireMissile(victim, skill->data.particle);
+ fireMissile(victim, skill->data->particle);
#ifdef MANASERV_SUPPORT
if (Net::getNetworkType() != ServerInfo::MANASERV)
@@ -795,9 +795,9 @@ void Being::handleSkill(Being *const victim, const int damage,
if (skill)
{
if (damage > 0)
- sound.playSfx(skill->data.soundHit, mX, mY);
+ sound.playSfx(skill->data->soundHit, mX, mY);
else
- sound.playSfx(skill->data.soundMiss, mX, mY);
+ sound.playSfx(skill->data->soundMiss, mX, mY);
}
else
{
diff --git a/src/gui/skilldialog.cpp b/src/gui/skilldialog.cpp
index 8447ed27d..26050585c 100644
--- a/src/gui/skilldialog.cpp
+++ b/src/gui/skilldialog.cpp
@@ -75,7 +75,7 @@ class SkillModel final : public gcn::ListModel
std::string getElementAt(int i)
{
if (getSkillAt(i))
- return getSkillAt(i)->data.name;
+ return getSkillAt(i)->data->name;
else
return "";
}
@@ -185,7 +185,7 @@ class SkillListBox final : public ListBox
return;
mPopup->show(viewport->getMouseX(), viewport->getMouseY(),
- skill->data.dispName);
+ skill->data->dispName);
}
void mouseExited(gcn::MouseEvent &event A_UNUSED)
@@ -346,7 +346,7 @@ std::string SkillDialog::update(const int id)
if (info)
{
info->update();
- return info->data.name;
+ return info->data->name;
}
}
@@ -405,11 +405,11 @@ void SkillDialog::loadSkills()
SkillInfo *const skill = new SkillInfo;
skill->id = 1;
- skill->data.name = _("basic");
- skill->data.description = "";
- skill->data.dispName = _("Skill: basic, Id: 1");
- skill->data.shortName = "bas";
- skill->setIcon("");
+ skill->data->name = _("basic");
+ skill->data->description = "";
+ skill->data->dispName = _("Skill: basic, Id: 1");
+ skill->data->shortName = "bas";
+ skill->data->setIcon("");
skill->modifiable = true;
skill->visible = true;
skill->model = model;
@@ -455,34 +455,44 @@ void SkillDialog::loadSkills()
{
const int id = atoi(XML::getProperty(
node, "id", "-1").c_str());
+
+ SkillInfo *skill = getSkill(id);
+ if (!skill)
+ {
+ skill = new SkillInfo;
+ skill->id = static_cast<short unsigned>(id);
+ skill->modifiable = false;
+ skill->visible = false;
+ skill->model = model;
+ skill->update();
+ model->addSkill(skill);
+ mSkills[id] = skill;
+ }
+
std::string name = XML::langProperty(node, "name",
strprintf(_("Skill %d"), id));
std::string icon = XML::getProperty(node, "icon", "");
-
- SkillInfo *const skill = new SkillInfo;
- skill->id = static_cast<short unsigned>(id);
- skill->data.name = name;
- skill->data.dispName = strprintf(_("Skill: %s, Id: %d"),
+ const int level = XML::getProperty(node, "level", 0);
+ SkillData *data = skill->getData(level);
+ if (!data)
+ data = new SkillData();
+
+ data->name = name;
+ data->setIcon(icon);
+ data->dispName = strprintf(_("Skill: %s, Id: %d"),
name.c_str(), skill->id);
- skill->data.shortName = XML::langProperty(node,
+ data->shortName = XML::langProperty(node,
"shortName", name.substr(0, 3));
- skill->data.description = XML::langProperty(
+ data->description = XML::langProperty(
node, "description", "");
- skill->setIcon(icon);
- skill->modifiable = false;
- skill->visible = false;
- skill->data.particle = XML::getProperty(
+ data->particle = XML::getProperty(
node, "particle", "");
- skill->data.soundHit = XML::getProperty(
+ data->soundHit = XML::getProperty(
node, "soundHit", "");
- skill->data.soundMiss = XML::getProperty(
+ data->soundMiss = XML::getProperty(
node, "soundMiss", "");
- skill->model = model;
- skill->update();
-
- model->addSkill(skill);
- mSkills[id] = skill;
+ skill->addData(level, data);
}
}
@@ -531,10 +541,10 @@ void SkillDialog::addSkill(const int id, const int level, const int range,
{
SkillInfo *const skill = new SkillInfo;
skill->id = static_cast<short unsigned>(id);
- skill->data.name = "Unknown skill Id: " + toString(id);
- skill->data.dispName = "Unknown skill Id: " + toString(id);
- skill->data.description = "";
- skill->setIcon("");
+ skill->data->name = "Unknown skill Id: " + toString(id);
+ skill->data->dispName = "Unknown skill Id: " + toString(id);
+ skill->data->description = "";
+ skill->data->setIcon("");
skill->modifiable = modifiable;
skill->visible = false;
skill->model = mDefaultModel;
@@ -608,25 +618,18 @@ SkillInfo::SkillInfo() :
level(0), skillLevelWidth(0), id(0), modifiable(false),
visible(false), model(nullptr), progress(0.0f), range(0)
{
+ dataMap[0] = new SkillData();
+ data = dataMap[0];
}
SkillInfo::~SkillInfo()
{
-}
-
-void SkillInfo::setIcon(const std::string &iconPath)
-{
- ResourceManager *const res = ResourceManager::getInstance();
- if (!iconPath.empty())
- {
- data.icon = res->getImage(iconPath);
- }
-
- if (!data.icon)
+ for (SkillDataMapIter it = dataMap.begin(), it_end = dataMap.end();
+ it != it_end; ++ it)
{
- data.icon = Theme::getImageFromTheme(
- paths.getStringValue("unknownItemFile"));
+ delete (*it).second;
}
+ dataMap.clear();
}
void SkillInfo::update()
@@ -685,6 +688,10 @@ void SkillInfo::update()
if (updateVisibility && model)
model->updateVisibilities();
+
+ data = getData(level);
+ if (!data)
+ data = dataMap[0];
}
void SkillInfo::draw(Graphics *const graphics, const int padding,
@@ -692,10 +699,10 @@ void SkillInfo::draw(Graphics *const graphics, const int padding,
const int y, const int width)
{
const int yPad = y + padding;
- graphics->drawImage(data.icon, padding, yPad);
- graphics->drawText(data.name, paddingText, yPad);
- if (!data.description.empty())
- graphics->drawText(data.description, paddingText, yPad + spacingText);
+ graphics->drawImage(data->icon, padding, yPad);
+ graphics->drawText(data->name, paddingText, yPad);
+ if (!data->description.empty())
+ graphics->drawText(data->description, paddingText, yPad + spacingText);
if (skillLevelWidth < 0)
{
@@ -706,6 +713,19 @@ void SkillInfo::draw(Graphics *const graphics, const int padding,
graphics->drawText(skillLevel, width - skillLevelWidth, yPad);
}
+void SkillInfo::addData(const int l, SkillData *const d)
+{
+ dataMap[l] = d;
+}
+
+SkillData *SkillInfo::getData(const int l)
+{
+ SkillDataMapIter it = dataMap.find(l);
+ if (it == dataMap.end())
+ return nullptr;
+ return (*it).second;
+}
+
SkillData::SkillData() :
icon(nullptr)
{
@@ -719,3 +739,16 @@ SkillData::~SkillData()
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 e77bde935..3cfff0c84 100644
--- a/src/gui/skilldialog.h
+++ b/src/gui/skilldialog.h
@@ -55,8 +55,14 @@ struct SkillData final
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;
@@ -71,7 +77,8 @@ struct SkillInfo final
int range;
gcn::Color color;
- SkillData data;
+ SkillData *data;
+ SkillDataMap dataMap;
SkillInfo();
A_DELETE_COPY(SkillInfo)
@@ -83,10 +90,13 @@ struct SkillInfo final
const int paddingText, const int spacingText,
const int y, const int width);
- void setIcon(const std::string &iconPath);
+ SkillData *getData(const int level);
+
+ void addData(const int level, SkillData *const data);
};
typedef std::vector<SkillInfo*> SkillList;
+typedef SkillList::iterator SkillListIter;
/**
* The skill dialog.
diff --git a/src/gui/widgets/itemshortcutcontainer.cpp b/src/gui/widgets/itemshortcutcontainer.cpp
index 520a92ea6..2e3d60d65 100644
--- a/src/gui/widgets/itemshortcutcontainer.cpp
+++ b/src/gui/widgets/itemshortcutcontainer.cpp
@@ -200,7 +200,7 @@ void ItemShortcutContainer::draw(gcn::Graphics *graphics)
itemId - SKILL_MIN_ID);
if (skill)
{
- Image *const image = skill->data.icon;
+ Image *const image = skill->data->icon;
if (image)
{
@@ -208,7 +208,7 @@ void ItemShortcutContainer::draw(gcn::Graphics *graphics)
g->drawImage(image, itemX, itemY);
}
- g->drawText(skill->data.shortName, itemX + 2,
+ g->drawText(skill->data->shortName, itemX + 2,
itemY + mBoxHeight / 2, gcn::Graphics::LEFT);
}
}