summaryrefslogtreecommitdiff
path: root/src/gui
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 /src/gui
parent5bbb89e2dbcafb80f33030ba2ffef6d2515b9209 (diff)
downloadmana-38d84edf098551793b78b845156e7de240d0d8b0.tar.gz
mana-38d84edf098551793b78b845156e7de240d0d8b0.tar.bz2
mana-38d84edf098551793b78b845156e7de240d0d8b0.tar.xz
mana-38d84edf098551793b78b845156e7de240d0d8b0.zip
Skills patch by roderic, mantis id=209
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/skill.cpp110
-rw-r--r--src/gui/skill.h58
2 files changed, 125 insertions, 43 deletions
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;
-
+
};