diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-12-16 18:50:20 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-12-16 22:33:53 +0300 |
commit | 0fa3de24e2e6931a07cbc1fb3dadfff9091250cf (patch) | |
tree | cf8829ca7d273b2464f724308c2fd419f407cc61 /src | |
parent | ade168344165534061b8f184866e2808af7f5d48 (diff) | |
download | plus-0fa3de24e2e6931a07cbc1fb3dadfff9091250cf.tar.gz plus-0fa3de24e2e6931a07cbc1fb3dadfff9091250cf.tar.bz2 plus-0fa3de24e2e6931a07cbc1fb3dadfff9091250cf.tar.xz plus-0fa3de24e2e6931a07cbc1fb3dadfff9091250cf.zip |
Separate in skills skill info and skill data for future usage.
Diffstat (limited to 'src')
-rw-r--r-- | src/being.cpp | 6 | ||||
-rw-r--r-- | src/gui/skilldialog.cpp | 133 | ||||
-rw-r--r-- | src/gui/skilldialog.h | 36 | ||||
-rw-r--r-- | src/gui/widgets/itemshortcutcontainer.cpp | 4 |
4 files changed, 100 insertions, 79 deletions
diff --git a/src/being.cpp b/src/being.cpp index c425f89a4..fa7b3ee85 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->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->soundHit, mX, mY); + sound.playSfx(skill->data.soundHit, mX, mY); else - sound.playSfx(skill->soundMiss, mX, mY); + sound.playSfx(skill->data.soundMiss, mX, mY); } else { diff --git a/src/gui/skilldialog.cpp b/src/gui/skilldialog.cpp index 97e2fbdf1..6cce3b85e 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)->name; + return getSkillAt(i)->data.name; else return ""; } @@ -178,7 +178,7 @@ class SkillListBox final : public ListBox return; mPopup->show(viewport->getMouseX(), viewport->getMouseY(), - skill->dispName); + skill->data.dispName); } void mouseExited(gcn::MouseEvent &event A_UNUSED) @@ -337,7 +337,7 @@ std::string SkillDialog::update(const int id) if (info) { info->update(); - return info->name; + return info->data.name; } } @@ -396,9 +396,9 @@ void SkillDialog::loadSkills() SkillInfo *const skill = new SkillInfo; skill->id = 1; - skill->name = _("basic"); - skill->dispName = _("Skill: basic, Id: 1"); - skill->shortName = "bas"; + skill->data.name = _("basic"); + skill->data.dispName = _("Skill: basic, Id: 1"); + skill->data.shortName = "bas"; skill->setIcon(""); skill->modifiable = true; skill->visible = true; @@ -451,17 +451,20 @@ void SkillDialog::loadSkills() SkillInfo *const skill = new SkillInfo; skill->id = static_cast<short unsigned>(id); - skill->name = name; - skill->dispName = strprintf(_("Skill: %s, Id: %d"), + skill->data.name = name; + skill->data.dispName = strprintf(_("Skill: %s, Id: %d"), name.c_str(), skill->id); - skill->shortName = XML::langProperty(node, + skill->data.shortName = XML::langProperty(node, "shortName", name.substr(0, 3)); skill->setIcon(icon); skill->modifiable = false; skill->visible = false; - skill->particle = XML::getProperty(node, "particle", ""); - skill->soundHit = XML::getProperty(node, "soundHit", ""); - skill->soundMiss = XML::getProperty(node, "soundMiss", ""); + skill->data.particle = XML::getProperty( + node, "particle", ""); + skill->data.soundHit = XML::getProperty( + node, "soundHit", ""); + skill->data.soundMiss = XML::getProperty( + node, "soundMiss", ""); skill->model = model; skill->update(); @@ -516,8 +519,8 @@ 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->name = "Unknown skill Id: " + toString(id); - skill->dispName = "Unknown skill Id: " + toString(id); + skill->data.name = "Unknown skill Id: " + toString(id); + skill->data.dispName = "Unknown skill Id: " + toString(id); skill->setIcon(""); skill->modifiable = modifiable; skill->visible = false; @@ -547,34 +550,69 @@ void SkillModel::updateVisibilities() } } -SkillInfo::SkillInfo() : - id(0), name(""), shortName(""), dispName(""), icon(nullptr), - modifiable(false), visible(false), model(nullptr), level(0), - skillLevel(""), skillLevelWidth(0), skillExp(""), progress(0.0f), range(0), - particle(""), soundHit(""), soundMiss("") + +SkillInfo* SkillDialog::getSkill(int id) { + return mSkills[id]; } -SkillInfo::~SkillInfo() +void SkillDialog::widgetResized(const gcn::Event &event) { - if (icon) + Window::widgetResized(event); + + if (mTabs) + mTabs->fixSize(); +} + +void SkillDialog::useItem(const int itemId) +{ + const SkillInfo *const info = mSkills[itemId - SKILL_MIN_ID]; + if (info && player_node && player_node->getTarget()) { - icon->decRef(); - icon = nullptr; + const Being *const being = player_node->getTarget(); + if (being) + { + Net::getSpecialHandler()->useBeing(info->level, + info->id, being->getId()); + } } } +void SkillDialog::updateTabSelection() +{ + const SkillTab *const tab = static_cast<SkillTab*>( + mTabs->getSelectedTab()); + if (tab) + { + if (const SkillInfo *const info = tab->getSelectedInfo()) + mUseButton->setEnabled(info->range > 0); + else + mUseButton->setEnabled(false); + } +} + +SkillInfo::SkillInfo() : + level(0), skillLevel(""), skillLevelWidth(0), id(0), + modifiable(false), visible(false), model(nullptr), + skillExp(""), progress(0.0f), range(0) +{ +} + +SkillInfo::~SkillInfo() +{ +} + void SkillInfo::setIcon(const std::string &iconPath) { ResourceManager *const res = ResourceManager::getInstance(); if (!iconPath.empty()) { - icon = res->getImage(iconPath); + data.icon = res->getImage(iconPath); } - if (!icon) + if (!data.icon) { - icon = Theme::getImageFromTheme( + data.icon = Theme::getImageFromTheme( paths.getStringValue("unknownItemFile")); } } @@ -641,8 +679,8 @@ void SkillInfo::draw(Graphics *const graphics, const int padding, const int paddingText, const int y, const int width) { const int yPad = y + padding; - graphics->drawImage(icon, padding, yPad); - graphics->drawText(name, paddingText, yPad); + graphics->drawImage(data.icon, padding, yPad); + graphics->drawText(data.name, paddingText, yPad); if (skillLevelWidth < 0) { @@ -653,42 +691,17 @@ void SkillInfo::draw(Graphics *const graphics, const int padding, graphics->drawText(skillLevel, width - skillLevelWidth, yPad); } -SkillInfo* SkillDialog::getSkill(int id) -{ - return mSkills[id]; -} - -void SkillDialog::widgetResized(const gcn::Event &event) +SkillData::SkillData() : + name(""), shortName(""), dispName(""), icon(nullptr), + particle(""), soundHit(""), soundMiss("") { - Window::widgetResized(event); - - if (mTabs) - mTabs->fixSize(); } -void SkillDialog::useItem(const int itemId) +SkillData::~SkillData() { - const SkillInfo *const info = mSkills[itemId - SKILL_MIN_ID]; - if (info && player_node && player_node->getTarget()) - { - const Being *const being = player_node->getTarget(); - if (being) - { - Net::getSpecialHandler()->useBeing(info->level, - info->id, being->getId()); - } - } -} - -void SkillDialog::updateTabSelection() -{ - const SkillTab *const tab = static_cast<SkillTab*>( - mTabs->getSelectedTab()); - if (tab) + if (icon) { - if (const SkillInfo *const info = tab->getSelectedInfo()) - mUseButton->setEnabled(info->range > 0); - else - mUseButton->setEnabled(false); + icon->decRef(); + icon = nullptr; } } diff --git a/src/gui/skilldialog.h b/src/gui/skilldialog.h index 945ae318d..45a5a8a43 100644 --- a/src/gui/skilldialog.h +++ b/src/gui/skilldialog.h @@ -40,41 +40,49 @@ class SkillModel; class Tab; class TabbedArea; -struct SkillInfo final +struct SkillData final { - unsigned short id; std::string name; std::string shortName; std::string dispName; Image *icon; - bool modifiable; - bool visible; - SkillModel *model; + + std::string particle; + std::string soundHit; + std::string soundMiss; + + SkillData(); + A_DELETE_COPY(SkillData) + ~SkillData(); +}; + +struct SkillInfo final +{ int level; std::string skillLevel; int skillLevelWidth; - + unsigned short id; + bool modifiable; + bool visible; + SkillModel *model; std::string skillExp; float progress; - gcn::Color color; int range; - std::string particle; - std::string soundHit; - std::string soundMiss; + gcn::Color color; - SkillInfo(); + SkillData data; + SkillInfo(); A_DELETE_COPY(SkillInfo) - ~SkillInfo(); - void setIcon(const std::string &iconPath); - void update(); void draw(Graphics *const graphics, const int padding, const int paddingText, const int y, const int width); + + void setIcon(const std::string &iconPath); }; typedef std::vector<SkillInfo*> SkillList; diff --git a/src/gui/widgets/itemshortcutcontainer.cpp b/src/gui/widgets/itemshortcutcontainer.cpp index c11d2a2e0..520a92ea6 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->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->shortName, itemX + 2, + g->drawText(skill->data.shortName, itemX + 2, itemY + mBoxHeight / 2, gcn::Graphics::LEFT); } } |