summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Athay <ko2fan@gmail.com>2008-04-28 17:30:00 +0000
committerDavid Athay <ko2fan@gmail.com>2008-04-28 17:30:00 +0000
commit38d84edf098551793b78b845156e7de240d0d8b0 (patch)
treeaf4d295e7c0c1c220ebf863d27694318d9081935
parent5bbb89e2dbcafb80f33030ba2ffef6d2515b9209 (diff)
downloadmana-38d84edf098551793b78b845156e7de240d0d8b0.tar.gz
mana-38d84edf098551793b78b845156e7de240d0d8b0.tar.bz2
mana-38d84edf098551793b78b845156e7de240d0d8b0.tar.xz
mana-38d84edf098551793b78b845156e7de240d0d8b0.zip
Skills patch by roderic, mantis id=209
-rw-r--r--ChangeLog2
-rw-r--r--src/gui/skill.cpp110
-rw-r--r--src/gui/skill.h58
-rw-r--r--src/localplayer.cpp34
-rw-r--r--src/localplayer.h7
5 files changed, 150 insertions, 61 deletions
diff --git a/ChangeLog b/ChangeLog
index 504938d7..b864ae01 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,8 @@
* src/gui/partywindow.h, src/gui/partywindow.cpp,
src/net/partyhandler.cpp, src/net/protocol.h,
src/net/chatserver/party.cpp, tmw.cbp: Added party invite dialog.
+ * src/localplayer.cpp, src/localplayer.h, src/gui/skills.cpp,
+ src/gui/skills.h: Skills patch by roderic, mantis id=209.
2008-04-26 Yohann Ferreira <bertram@cegetel.net>
diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp
index 48d64202..58ec8043 100644
--- a/src/gui/skill.cpp
+++ b/src/gui/skill.cpp
@@ -53,6 +53,7 @@ SkillDialog::SkillDialog():
Skill_Tab* tab;
+ // Add each type of skill tab to the panel
tab = new Skill_Tab("Weapon");
panel->addTab(tab, _("Weapons"));
mTabs.push_back(tab);
@@ -103,26 +104,15 @@ void SkillDialog::update()
Skill_Tab::Skill_Tab(std::string type): type(type)
{
- int skillNum = 0;
-
- if (type == "Weapon")
- {
- skillNum = CHAR_SKILL_WEAPON_NB;
- }
- else if (type == "Magic")
- {
- skillNum = CHAR_SKILL_MAGIC_NB;
- }
- else if (type == "Craft")
- {
- skillNum = CHAR_SKILL_CRAFT_NB;
- }
+ setOpaque(false);
+ int skillNum = getSkillNum();
mSkillNameLabels.resize(skillNum);
mSkillLevelLabels.resize(skillNum);
mSkillExpLabels.resize(skillNum);
mSkillProgress.resize(skillNum);
+ // Set the initial positions of the skill information
for (int a=0; a < skillNum; a++)
{
mSkillNameLabels.at(a) = new gcn::Label("");
@@ -146,33 +136,74 @@ Skill_Tab::Skill_Tab(std::string type): type(type)
}
-void Skill_Tab::update()
+int Skill_Tab::getSkillNum()
{
- setOpaque(false);
int skillNum = 0;
- int skillBegin;
if (type == "Weapon")
{
skillNum = CHAR_SKILL_WEAPON_NB;
- skillBegin = CHAR_SKILL_WEAPON_BEGIN - CHAR_SKILL_BEGIN;
+ return skillNum;
}
else if (type == "Magic")
{
skillNum = CHAR_SKILL_MAGIC_NB;
- skillBegin = CHAR_SKILL_MAGIC_BEGIN - CHAR_SKILL_BEGIN;
+ return skillNum;
}
else if (type == "Craft")
{
skillNum = CHAR_SKILL_CRAFT_NB;
- skillBegin = CHAR_SKILL_CRAFT_BEGIN - CHAR_SKILL_BEGIN;
+ return skillNum;
}
+ else return skillNum;
+}
- for (int a = 0; a < skillNum; a++)
+int Skill_Tab::getSkillBegin()
+{
+ int skillBegin = 0;
+
+ if (type == "Weapon")
{
- int baseLevel = player_node->getAttributeBase(a + skillBegin + CHAR_SKILL_BEGIN);
- int effLevel = player_node->getAttributeEffective(a + skillBegin + CHAR_SKILL_BEGIN);
+ skillBegin = CHAR_SKILL_WEAPON_BEGIN - CHAR_SKILL_BEGIN;
+ return skillBegin;
+ }
+ else if (type == "Magic")
+ {
+ skillBegin = CHAR_SKILL_MAGIC_BEGIN - CHAR_SKILL_BEGIN;
+ return skillBegin;
+ }
+ else if (type == "Craft")
+ {
+ skillBegin = CHAR_SKILL_CRAFT_BEGIN - CHAR_SKILL_BEGIN;
+ return skillBegin;
+ }
+ else return skillBegin;
+}
+
+void Skill_Tab::updateSkill(int index)
+{
+ int skillBegin = getSkillBegin();
+ int baseLevel = player_node->getAttributeBase(index +
+ skillBegin +
+ CHAR_SKILL_BEGIN);
+
+ int effLevel = player_node->getAttributeEffective(index +
+ skillBegin +
+ CHAR_SKILL_BEGIN);
+ if(baseLevel <= 0)
+ {
+ mSkillProgress.at(index)->setVisible(false);
+ mSkillExpLabels.at(index)->setVisible(false);
+ mSkillLevelLabels.at(index)->setVisible(false);
+ mSkillNameLabels.at(index)->setVisible(false);
+ }
+ else
+ {
+ mSkillProgress.at(index)->setVisible(true);
+ mSkillExpLabels.at(index)->setVisible(true);
+ mSkillLevelLabels.at(index)->setVisible(true);
+ mSkillNameLabels.at(index)->setVisible(true);
std::string skillLevel("Lvl: " + toString(baseLevel));
if (effLevel < baseLevel)
{
@@ -182,22 +213,33 @@ void Skill_Tab::update()
{
skillLevel.append(" + " + toString(effLevel - baseLevel));
}
- mSkillLevelLabels.at(a)->setCaption(skillLevel);
+ mSkillLevelLabels.at(index)->setCaption(skillLevel);
- std::pair<int, int> exp = player_node->getExperience(a + skillBegin);
+ std::pair<int, int> exp = player_node->getExperience(index + skillBegin);
std::string sExp (toString(exp.first) + " / " + toString(exp.second));
- mSkillNameLabels.at(a)->setCaption(LocalPlayer::getSkillName(a + skillBegin));
- mSkillNameLabels.at(a)->adjustSize();
- mSkillLevelLabels.at(a)->adjustSize();
- mSkillExpLabels.at(a)->setCaption(sExp);
- mSkillExpLabels.at(a)->adjustSize();
- mSkillExpLabels.at(a)->setAlignment(gcn::Graphics::RIGHT);
+ mSkillNameLabels.at(index)->setCaption(LocalPlayer::getSkillInfo(index + skillBegin).name);
+ mSkillNameLabels.at(index)->adjustSize();
+ mSkillLevelLabels.at(index)->adjustSize();
+ mSkillExpLabels.at(index)->setCaption(sExp);
+ mSkillExpLabels.at(index)->adjustSize();
+ mSkillExpLabels.at(index)->setAlignment(gcn::Graphics::RIGHT);
- // more intense red as exp grows
+ // More intense red as exp grows
int color = 150 - (int)(150 * ((float) exp.first / exp.second));
- mSkillProgress.at(a)->setColor(244, color, color);
- mSkillProgress.at(a)->setProgress((float) exp.first / exp.second);
+ mSkillProgress.at(index)->setColor(244, color, color);
+ mSkillProgress.at(index)->setProgress((float) exp.first / exp.second);
+ }
+}
+
+void Skill_Tab::update()
+{
+ int skillNum = getSkillNum();
+
+ // Update the skill information for reach skill
+ for (int a = 0; a < skillNum; a++)
+ {
+ updateSkill(a);
}
}
diff --git a/src/gui/skill.h b/src/gui/skill.h
index bf32fe64..99011e75 100644
--- a/src/gui/skill.h
+++ b/src/gui/skill.h
@@ -40,19 +40,51 @@ class ProgressBar;
class Skill_Tab : public GCContainer, public gcn::ActionListener
{
public:
+ /**
+ * The type of this skill tab
+ */
const std::string type;
+
+ /**
+ * Constructor
+ */
Skill_Tab(std::string type);
+
+ /**
+ * Update this tab
+ */
void update();
+
+ /**
+ * Called when receiving actions from widget.
+ */
void action(const gcn::ActionEvent &event) {}
-
- protected:
-
+
+ private:
+ /**
+ * Update the information of a skill at
+ * the given index
+ */
+ void updateSkill(int index);
+
+ /**
+ * Gets the number of skills in this particular
+ * type of tab.
+ */
+ int getSkillNum();
+
+ /**
+ * Get the first enumeration of this skill tab's
+ * skill type.
+ */
+ int getSkillBegin();
+
std::vector<gcn::Label *> mSkillNameLabels;
std::vector<gcn::Label *> mSkillLevelLabels;
std::vector<gcn::Label *> mSkillExpLabels;
std::vector<ProgressBar *> mSkillProgress;
-};
-
+};
+
/**
* The skill dialog.
@@ -72,18 +104,26 @@ class SkillDialog : public Window, public gcn::ActionListener
*/
~SkillDialog();
+ /**
+ * Called when receiving actions from widget.
+ */
void action(const gcn::ActionEvent &event);
+ /**
+ * Update the tabs in this dialog
+ */
void update();
- void setExp(int id, int exp);
-
+ /**
+ * Draw this window.
+ */
void draw(gcn::Graphics *g);
private:
-
+
+
std::list<Skill_Tab*> mTabs;
-
+
};
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index 1e61e59d..5bf6ec0e 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -421,24 +421,24 @@ void LocalPlayer::lowerAttribute(size_t attr)
Net::GameServer::Player::lowerAttribute(attr + CHAR_ATTR_BEGIN);
}
-const std::string& LocalPlayer::getSkillName(int skill)
+const struct LocalPlayer::skillInfo& LocalPlayer::getSkillInfo(int skill)
{
- static const std::string skills[CHAR_SKILL_NB + 1] =
+ static const skillInfo skills[CHAR_SKILL_NB + 1] =
{
- _("Unarmed"), // CHAR_SKILL_WEAPON_NONE
- _("Knife"), // CHAR_SKILL_WEAPON_KNIFE
- _("Sword"), // CHAR_SKILL_WEAPON_SWORD
- _("Polearm"), // CHAR_SKILL_WEAPON_POLEARM
- _("Staff"), // CHAR_SKILL_WEAPON_STAFF
- _("Whip"), // CHAR_SKILL_WEAPON_WHIP
- _("Bow"), // CHAR_SKILL_WEAPON_BOW
- _("Shooting"), // CHAR_SKILL_WEAPON_SHOOTING
- _("Mace"), // CHAR_SKILL_WEAPON_MACE
- _("Axe"), // CHAR_SKILL_WEAPON_AXE
- _("Thrown"), // CHAR_SKILL_WEAPON_THROWN
- _("Magic"), // CHAR_SKILL_MAGIC_IAMJUSTAPLACEHOLDER
- _("Craft"), // CHAR_SKILL_CRAFT_IAMJUSTAPLACEHOLDER
- _("Unknown Skill")
+ { _("Unarmed"), "graphics/gui/unarmed.png" }, // CHAR_SKILL_WEAPON_NONE
+ { _("Knife"), "graphics/gui/knife.png" }, // CHAR_SKILL_WEAPON_KNIFE
+ { _("Sword"), "graphics/gui/sword.png" }, // CHAR_SKILL_WEAPON_SWORD
+ { _("Polearm"), "graphics/gui/polearm.png" }, // CHAR_SKILL_WEAPON_POLEARM
+ { _("Staff"), "graphics/gui/staff.png" }, // CHAR_SKILL_WEAPON_STAFF
+ { _("Whip"), "graphics/gui/whip.png" }, // CHAR_SKILL_WEAPON_WHIP
+ { _("Bow"), "graphics/gui/bow.png" }, // CHAR_SKILL_WEAPON_BOW
+ { _("Shooting"), "graphics/gui/shooting.png" }, // CHAR_SKILL_WEAPON_SHOOTING
+ { _("Mace"), "graphics/gui/mace.png" }, // CHAR_SKILL_WEAPON_MACE
+ { _("Axe"), "graphics/gui/axe.png" }, // CHAR_SKILL_WEAPON_AXE
+ { _("Thrown"), "graphics/gui/thrown.png" }, // CHAR_SKILL_WEAPON_THROWN
+ { _("Magic"), "graphics/gui/magic.png " }, // CHAR_SKILL_MAGIC_IAMJUSTAPLACEHOLDER
+ { _("Craft"), "graphics/gui/craft.png" }, // CHAR_SKILL_CRAFT_IAMJUSTAPLACEHOLDER
+ { _("Unknown Skill"), "graphics/gui/unknown-item.png" }
};
if ((skill < 0) || (skill > CHAR_SKILL_NB))
@@ -457,7 +457,7 @@ void LocalPlayer::setExperience(int skill, int current, int next)
int diff = current - mExpCurrent.at(skill);
if (mMap && mExpCurrent.at(skill) != -1 && diff > 0)
{
- const std::string text = toString(diff) + " " + getSkillName(skill) + " xp";
+ const std::string text = toString(diff) + " " + getSkillInfo(skill).name + " xp";
mExpMessages.push_back(text);
}
diff --git a/src/localplayer.h b/src/localplayer.h
index 099a5f81..be8c020c 100644
--- a/src/localplayer.h
+++ b/src/localplayer.h
@@ -337,7 +337,12 @@ class LocalPlayer : public Player
void setExperience(int skill, int current, int next);
- static const std::string& getSkillName(int skill);
+ struct skillInfo {
+ std::string name;
+ std::string icon;
+ };
+
+ static const struct skillInfo& getSkillInfo(int skill);
std::pair<int, int> getExperience(int skill);