diff options
author | Jared Adams <jaxad0127@gmail.com> | 2009-07-15 14:43:16 -0600 |
---|---|---|
committer | Jared Adams <jaxad0127@gmail.com> | 2009-07-15 14:47:24 -0600 |
commit | 18aaa873abcaa617bbd296f73138d062423662b8 (patch) | |
tree | cfdcf6d3a5750549c01df38cda27f0ea14b47279 /src/gui | |
parent | fa6d39d9f56e09abfb6b48bacdd66ddbad20c641 (diff) | |
download | mana-client-18aaa873abcaa617bbd296f73138d062423662b8.tar.gz mana-client-18aaa873abcaa617bbd296f73138d062423662b8.tar.bz2 mana-client-18aaa873abcaa617bbd296f73138d062423662b8.tar.xz mana-client-18aaa873abcaa617bbd296f73138d062423662b8.zip |
Merge and cleanup attribute code
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/status.cpp | 161 | ||||
-rw-r--r-- | src/gui/status.h | 22 | ||||
-rw-r--r-- | src/gui/statuswindow.cpp | 101 | ||||
-rw-r--r-- | src/gui/statuswindow.h | 9 |
4 files changed, 89 insertions, 204 deletions
diff --git a/src/gui/status.cpp b/src/gui/status.cpp index 497eef79..02f3de4e 100644 --- a/src/gui/status.cpp +++ b/src/gui/status.cpp @@ -32,7 +32,8 @@ #include "gui/widgets/windowcontainer.h" #include "net/net.h" -#include "net/ea/playerhandler.h" +#include "net/playerhandler.h" +#include "net/ea/protocol.h" #include "utils/gettext.h" #include "utils/mathutils.h" @@ -79,29 +80,38 @@ StatusWindow::StatusWindow(): mStatsTotalLabel->setAlignment(gcn::Graphics::CENTER); // Derived Stats - mStatsAttackLabel = new Label(_("Attack:")); - mStatsDefenseLabel= new Label(_("Defense:")); - mStatsMagicAttackLabel = new Label(_("M.Attack:")); - mStatsMagicDefenseLabel = new Label(_("M.Defense:")); - // Gettext flag for next line: xgettext:no-c-format - mStatsAccuracyLabel = new Label(_("% Accuracy:")); - // Gettext flag for next line: xgettext:no-c-format - mStatsEvadeLabel = new Label(_("% Evade:")); - // Gettext flag for next line: xgettext:no-c-format - mStatsReflexLabel = new Label(_("% Reflex:")); - - mStatsAttackPoints = new Label; - mStatsDefensePoints = new Label; - mStatsMagicAttackPoints = new Label; - mStatsMagicDefensePoints = new Label; - mStatsAccuracyPoints = new Label; - mStatsEvadePoints = new Label; - mStatsReflexPoints = new Label; - - // New labels + static const char *dAttrNames[7] = { + _("Attack"), + _("Defense"), + _("M.Attack"), + _("M.Defense"), + // Gettext flag for next line: xgettext:no-c-format + _("% Accuracy"), + // Gettext flag for next line: xgettext:no-c-format + _("% Evade"), + // Gettext flag for next line: xgettext:no-c-format + _("% Crit Chance") + }; + + for (int i = 0; i < 7; i++) + { + mDStatsLabel[i] = new Label(dAttrNames[i]); + mDPointsLabel[i] = new Label; + } + + // Stats labels + static const char *attrNames[6] = { + _("Strength"), + _("Agility"), + _("Vitality"), + _("Intelligence"), + _("Dexterity"), + _("Luck") + }; + for (int i = 0; i < 6; i++) { - mStatsLabel[i] = new Label("0"); + mStatsLabel[i] = new Label(attrNames[i]); mStatsLabel[i]->setAlignment(gcn::Graphics::CENTER); mStatsDisplayLabel[i] = new Label; mPointsLabel[i] = new Label("0"); @@ -144,26 +154,19 @@ StatusWindow::StatusWindow(): place(10, 2 + i, mStatsButton[i]); place(12, 2 + i, mPointsLabel[i]).setPadding(5); } - place(14, 2, mStatsAttackLabel, 7).setPadding(5); - place(14, 3, mStatsDefenseLabel, 7).setPadding(5); - place(14, 4, mStatsMagicAttackLabel, 7).setPadding(5); - place(14, 5, mStatsMagicDefenseLabel, 7).setPadding(5); - place(14, 6, mStatsAccuracyLabel, 7).setPadding(5); - place(14, 7, mStatsEvadeLabel, 7).setPadding(5); - place(14, 8, mStatsReflexLabel, 7).setPadding(5); - place(21, 2, mStatsAttackPoints, 3).setPadding(5); - place(21, 3, mStatsDefensePoints, 3).setPadding(5); - place(21, 4, mStatsMagicAttackPoints, 3).setPadding(5); - place(21, 5, mStatsMagicDefensePoints, 3).setPadding(5); - place(21, 6, mStatsAccuracyPoints, 3).setPadding(5); - place(21, 7, mStatsEvadePoints, 3).setPadding(5); - place(21, 8, mStatsReflexPoints, 3).setPadding(5); + for (int i = 0; i < 7; i++) + { + place(14, 2 + i, mDStatsLabel[i], 7).setPadding(5); + place(21, 2 + i, mDPointsLabel[i], 3).setPadding(5); + } + place(0, 8, mRemainingStatsPointsLabel, 3).setPadding(5); Layout &layout = getLayout(); layout.setRowHeight(0, Layout::AUTO_SET); loadWindowState(); + update(); } void StatusWindow::update() @@ -193,73 +196,41 @@ void StatusWindow::update() // Stats Part // ---------- - static const char *attrNames[6] = { - N_("Strength"), - N_("Agility"), - N_("Vitality"), - N_("Intelligence"), - N_("Dexterity"), - N_("Luck") - }; int statusPoints = player_node->getCharacterPoints(); // Update labels for (int i = 0; i < 6; i++) { - mStatsLabel[i]->setCaption(gettext(attrNames[i])); - mStatsDisplayLabel[i]->setCaption(toString((int) player_node->mAttr[i])); - mPointsLabel[i]->setCaption(toString((int) player_node->mAttrUp[i])); + int base = player_node->getAttributeBase(i + STR); + int bonus = player_node->getAttributeEffective(i + STR) - base; + std::string value = toString(base); + if (bonus) + value += strprintf(" (%+d)", bonus); + mStatsDisplayLabel[i]->setCaption(value); + mPointsLabel[i]->setCaption(toString(player_node-> + getAttributeBase(i + STR_U))); - mStatsLabel[i]->adjustSize(); mStatsDisplayLabel[i]->adjustSize(); mPointsLabel[i]->adjustSize(); - mStatsButton[i]->setEnabled(player_node->mAttrUp[i] <= statusPoints); + mStatsButton[i]->setEnabled(player_node->getAttributeBase(i + STR_U) + <= statusPoints); } mRemainingStatsPointsLabel->setCaption( strprintf(_("Remaining Status Points: %d"), statusPoints)); mRemainingStatsPointsLabel->adjustSize(); // Derived Stats Points - - // Attack TODO: Count equipped Weapons and items attack bonuses - mStatsAttackPoints->setCaption( - toString(player_node->ATK + player_node->ATK_BONUS)); - mStatsAttackPoints->adjustSize(); - - // Defense TODO: Count equipped Armors and items defense bonuses - mStatsDefensePoints->setCaption( - toString(player_node->DEF + player_node->DEF_BONUS)); - mStatsDefensePoints->adjustSize(); - - // Magic Attack TODO: Count equipped items M.Attack bonuses - mStatsMagicAttackPoints->setCaption( - toString(player_node->MATK + player_node->MATK_BONUS)); - mStatsMagicAttackPoints->adjustSize(); - - // Magic Defense TODO: Count equipped items M.Defense bonuses - mStatsMagicDefensePoints->setCaption( - toString(player_node->MDEF + player_node->MDEF_BONUS)); - mStatsMagicDefensePoints->adjustSize(); - - // Accuracy % - mStatsAccuracyPoints->setCaption(toString(player_node->HIT)); - mStatsAccuracyPoints->adjustSize(); - - // Evasion % - mStatsEvadePoints->setCaption(toString(player_node->FLEE)); - mStatsEvadePoints->adjustSize(); - - // Reflex % - mStatsReflexPoints->setCaption(toString(player_node->DEX / 4)); // + counter - mStatsReflexPoints->adjustSize(); -} - -void StatusWindow::draw(gcn::Graphics *g) -{ - update(); - - Window::draw(g); + for (int i = 0; i < 7; i++) + { + int base = player_node->getAttributeBase(i + ATK); + int bonus = player_node->getAttributeEffective(i + ATK) - base; + std::string value = toString(base); + if (bonus) + value += strprintf(" (%+d)", bonus); + mDPointsLabel[i]->setCaption(value); + mDPointsLabel[i]->adjustSize(); + } } void StatusWindow::action(const gcn::ActionEvent &event) @@ -269,17 +240,17 @@ void StatusWindow::action(const gcn::ActionEvent &event) if (event.getId().length() == 3) { if (event.getId() == "STR") - Net::getPlayerHandler()->increaseAttribute(LocalPlayer::STR); + Net::getPlayerHandler()->increaseAttribute(STR); if (event.getId() == "AGI") - Net::getPlayerHandler()->increaseAttribute(LocalPlayer::AGI); + Net::getPlayerHandler()->increaseAttribute(AGI); if (event.getId() == "VIT") - Net::getPlayerHandler()->increaseAttribute(LocalPlayer::VIT); + Net::getPlayerHandler()->increaseAttribute(VIT); if (event.getId() == "INT") - Net::getPlayerHandler()->increaseAttribute(LocalPlayer::INT); + Net::getPlayerHandler()->increaseAttribute(INT); if (event.getId() == "DEX") - Net::getPlayerHandler()->increaseAttribute(LocalPlayer::DEX); + Net::getPlayerHandler()->increaseAttribute(DEX); if (event.getId() == "LUK") - Net::getPlayerHandler()->increaseAttribute(LocalPlayer::LUK); + Net::getPlayerHandler()->increaseAttribute(LUK); } } @@ -367,7 +338,7 @@ void StatusWindow::updateMPBar(ProgressBar *bar, bool showMax) else bar->setText(toString(player_node->mMp)); - if (player_node->MATK <= 0) + if (player_node->getAttributeEffective(MATK) <= 0) bar->setColor(100, 100, 100); // grey, to indicate that we lack magic else bar->setColor(26, 102, 230); // blue, to indicate that we have magic diff --git a/src/gui/status.h b/src/gui/status.h index 3e5df917..6e8371c2 100644 --- a/src/gui/status.h +++ b/src/gui/status.h @@ -48,15 +48,16 @@ class StatusWindow : public Window, public gcn::ActionListener void action(const gcn::ActionEvent &event); /** - * Draw this window - */ - void draw(gcn::Graphics *graphics); - - /** * Updates this dialog with values from PLAYER_INFO *char_info */ void update(); + // TODO: only update what changed + std::string update(int id) { update(); return ""; } + + // future use + void addAttribute(int id, const std::string &name, bool modifiable) {} + static void updateHPBar(ProgressBar *bar, bool showMax = false); static void updateMPBar(ProgressBar *bar, bool showMax = false); static void updateXPBar(ProgressBar *bar, bool percent = true); @@ -76,15 +77,8 @@ class StatusWindow : public Window, public gcn::ActionListener /** * Derived Statistics captions */ - gcn::Label *mStatsAttackLabel, *mStatsDefenseLabel; - gcn::Label *mStatsMagicAttackLabel, *mStatsMagicDefenseLabel; - gcn::Label *mStatsAccuracyLabel, *mStatsEvadeLabel; - gcn::Label *mStatsReflexLabel; - - gcn::Label *mStatsAttackPoints, *mStatsDefensePoints; - gcn::Label *mStatsMagicAttackPoints, *mStatsMagicDefensePoints; - gcn::Label *mStatsAccuracyPoints, *mStatsEvadePoints; - gcn::Label *mStatsReflexPoints; + gcn::Label *mDStatsLabel[7]; + gcn::Label *mDPointsLabel[7]; /** * Stats captions. diff --git a/src/gui/statuswindow.cpp b/src/gui/statuswindow.cpp index 5f29e5a5..e8706a82 100644 --- a/src/gui/statuswindow.cpp +++ b/src/gui/statuswindow.cpp @@ -85,24 +85,6 @@ StatusWindow::StatusWindow(): gcn::Label *mStatsTitleLabel = new Label("Stats"); gcn::Label *mStatsTotalLabel = new Label("Total"); - // Derived Stats -/* - mStatsAttackLabel = new Label("Attack:"); - mStatsDefenseLabel= new Label("Defense:"); - mStatsMagicAttackLabel = new Label("M.Attack:"); - mStatsMagicDefenseLabel = new Label("M.Defense:"); - mStatsAccuracyLabel = new Label("% Accuracy:"); - mStatsEvadeLabel = new Label("% Evade:"); - mStatsReflexLabel = new Label("% Reflex:"); - - mStatsAttackPoints = new Label; - mStatsDefensePoints = new Label; - mStatsMagicAttackPoints = new Label; - mStatsMagicDefensePoints = new Label; - mStatsAccuracyPoints = new Label("% Accuracy:"); - mStatsEvadePoints = new Label("% Evade:"); - mStatsReflexPoints = new Label("% Reflex:"); -*/ // New labels for (int i = 0; i < 6; i++) { mStatsLabel[i] = new Label; @@ -126,8 +108,6 @@ StatusWindow::StatusWindow(): mStatsMinus[4] = new Button("-", "INT-", this); mStatsMinus[5] = new Button("-", "WIL-", this); - - // Set position mStatsTitleLabel->setPosition(mHpLabel->getX(), mHpLabel->getY() + 23 ); mStatsTotalLabel->setPosition(110, mStatsTitleLabel->getY() + 15); @@ -145,23 +125,7 @@ StatusWindow::StatusWindow(): mCharacterPointsLabel->setPosition(5, mStatsDisplayLabel[5]->getY() + 25); mCorrectionPointsLabel->setPosition(5, mStatsDisplayLabel[5]->getY() + 35); -/* - mStatsAttackLabel->setPosition(220, mStatsLabel[0]->getY()); - mStatsDefenseLabel->setPosition(220, mStatsLabel[1]->getY()); - mStatsMagicAttackLabel->setPosition(220, mStatsLabel[2]->getY()); - mStatsMagicDefenseLabel->setPosition(220, mStatsLabel[3]->getY()); - mStatsAccuracyLabel->setPosition(220, mStatsLabel[4]->getY()); - mStatsEvadeLabel->setPosition(220, mStatsLabel[5]->getY()); - mStatsReflexLabel->setPosition(220, mStatsLabel[6]->getY()); - - mStatsAttackPoints->setPosition(310, mStatsLabel[0]->getY()); - mStatsDefensePoints->setPosition(310, mStatsLabel[1]->getY()); - mStatsMagicAttackPoints->setPosition(310, mStatsLabel[2]->getY()); - mStatsMagicDefensePoints->setPosition(310, mStatsLabel[3]->getY()); - mStatsAccuracyPoints->setPosition(310, mStatsLabel[4]->getY()); - mStatsEvadePoints->setPosition(310, mStatsLabel[5]->getY()); - mStatsReflexPoints->setPosition(310, mStatsLabel[6]->getY()); -*/ + // Assemble add(mStatsTitleLabel); add(mStatsTotalLabel); @@ -171,22 +135,7 @@ StatusWindow::StatusWindow(): add(mStatsDisplayLabel[i]); add(mStatsPlus[i]); add(mStatsMinus[i]); - }/* - add(mStatsAttackLabel); - add(mStatsDefenseLabel); - add(mStatsMagicAttackLabel); - add(mStatsMagicDefenseLabel); - add(mStatsAccuracyLabel); - add(mStatsEvadeLabel); - add(mStatsReflexLabel); - - add(mStatsAttackPoints); - add(mStatsDefensePoints); - add(mStatsMagicAttackPoints); - add(mStatsMagicDefensePoints); - add(mStatsAccuracyPoints); - add(mStatsEvadePoints); - add(mStatsReflexPoints);*/ + } add(mCharacterPointsLabel); add(mCorrectionPointsLabel); @@ -242,52 +191,24 @@ void StatusWindow::update() mCorrectionPointsLabel->setCaption("Correction Points: " + toString(correctionPoints)); mCorrectionPointsLabel->adjustSize(); -/* - // Derived Stats Points - - // Attack TODO: Count equipped Weapons and items attack bonuses - mStatsAttackPoints->setCaption( - toString(player_node->ATK + player_node->ATK_BONUS)); - mStatsAttackPoints->adjustSize(); - - // Defense TODO: Count equipped Armors and items defense bonuses - mStatsDefensePoints->setCaption( - toString(player_node->DEF + player_node->DEF_BONUS)); - mStatsDefensePoints->adjustSize(); - - // Magic Attack TODO: Count equipped items M.Attack bonuses - mStatsMagicAttackPoints->setCaption( - toString(player_node->MATK + player_node->MATK_BONUS)); - mStatsMagicAttackPoints->adjustSize(); - - // Magic Defense TODO: Count equipped items M.Defense bonuses - mStatsMagicDefensePoints->setCaption( - toString(player_node->MDEF + player_node->MDEF_BONUS)); - mStatsMagicDefensePoints->adjustSize(); - - // Accuracy % - mStatsAccuracyPoints->setCaption(toString(player_node->HIT)); - mStatsAccuracyPoints->adjustSize(); - - // Evasion % - mStatsEvadePoints->setCaption(toString(player_node->FLEE)); - mStatsEvadePoints->adjustSize(); - - // Reflex % - mStatsReflexPoints->setCaption(toString(player_node->DEX / 4)); // + counter - mStatsReflexPoints->adjustSize(); -*/ + // Update Second column widgets position mMoneyLabel->setPosition(mLvlLabel->getX() + mLvlLabel->getWidth() + 20, mLvlLabel->getY()); + update(); } -void StatusWindow::draw(gcn::Graphics *g) +std::string StatusWindow::update(int id) { + // TODO: only update what changed update(); +} - Window::draw(g); +void StatusWindow::addAttribute(int id, const std::string &name, + bool modifiable) +{ + // future use } void StatusWindow::action(const gcn::ActionEvent &event) diff --git a/src/gui/statuswindow.h b/src/gui/statuswindow.h index 7b3b8ae0..d5bd8fd6 100644 --- a/src/gui/statuswindow.h +++ b/src/gui/statuswindow.h @@ -50,15 +50,14 @@ class StatusWindow : public Window, public gcn::ActionListener void action(const gcn::ActionEvent &event); /** - * Draw this window - */ - void draw(gcn::Graphics *graphics); - - /** * Updates this dialog with values from PLAYER_INFO *char_info */ void update(); + std::string update(int id); + + void addAttribute(int id, const std::string &name, bool modifiable); + static void updateHPBar(ProgressBar *bar, bool showMax = false); private: |