diff options
author | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2010-10-19 23:17:18 +0200 |
---|---|---|
committer | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2010-10-19 23:17:18 +0200 |
commit | 14b048899065054bf2a8171a566616607479c09f (patch) | |
tree | 3e531350fdcff72e33dde66bed3574b2e882bd06 /src | |
parent | 1b21442b5eb6dcc41a585715d07c73ed3ad59a1b (diff) | |
download | mana-client-14b048899065054bf2a8171a566616607479c09f.tar.gz mana-client-14b048899065054bf2a8171a566616607479c09f.tar.bz2 mana-client-14b048899065054bf2a8171a566616607479c09f.tar.xz mana-client-14b048899065054bf2a8171a566616607479c09f.zip |
Heavy GUI fixes related to stats for Manaserv.
Also tested to be compatible with tA.
Now the Status window is much more nicer when using Manaserv.
HP, max hp, ... are now working fine along with corrections made
in the attributes.xml file (in next commit.)
Reviewed-by: Thorbjorn.
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/statuswindow.cpp | 49 | ||||
-rw-r--r-- | src/net/manaserv/attributes.cpp | 104 | ||||
-rw-r--r-- | src/net/manaserv/attributes.h | 7 | ||||
-rw-r--r-- | src/net/manaserv/playerhandler.cpp | 24 |
4 files changed, 144 insertions, 40 deletions
diff --git a/src/gui/statuswindow.cpp b/src/gui/statuswindow.cpp index 6535edf7..022a97c7 100644 --- a/src/gui/statuswindow.cpp +++ b/src/gui/statuswindow.cpp @@ -115,21 +115,22 @@ StatusWindow::StatusWindow(): int max = PlayerInfo::getAttribute(MAX_HP); mHpLabel = new Label(_("HP:")); - mHpBar = new ProgressBar(max ? (float) PlayerInfo::getAttribute(HP) / max: 0, - 80, 15, Theme::PROG_HP); + mHpBar = new ProgressBar(max ? (float) PlayerInfo::getAttribute(HP) / max : + 0, 80, 15, Theme::PROG_HP); max = PlayerInfo::getAttribute(EXP_NEEDED); mXpLabel = new Label(_("Exp:")); - mXpBar = new ProgressBar(max ? (float) PlayerInfo::getAttribute(EXP) / max : 0, - 80, 15, Theme::PROG_EXP); + mXpBar = new ProgressBar(max ? (float) PlayerInfo::getAttribute(EXP) / max : + 0, 80, 15, Theme::PROG_EXP); bool magicBar = Net::getGameHandler()->canUseMagicBar(); if (magicBar) { max = PlayerInfo::getAttribute(MAX_MP); mMpLabel = new Label(_("MP:")); - mMpBar = new ProgressBar(max ? (float) PlayerInfo::getAttribute(MAX_MP) / max : 0, - 80, 15, Net::getPlayerHandler()->canUseMagic() ? + mMpBar = new ProgressBar(max ? + (float) PlayerInfo::getAttribute(MAX_MP) / max : + 0, 80, 15, Net::getPlayerHandler()->canUseMagic() ? Theme::PROG_MP : Theme::PROG_NO_MP); } @@ -140,11 +141,16 @@ StatusWindow::StatusWindow(): place(1, 1, mHpBar, 4); place(5, 1, mXpLabel).setPadding(3); place(6, 1, mXpBar, 5); + + int attributesFirstRow = 2; if (magicBar) { place(0, 2, mMpLabel).setPadding(3); // 5, 2 and 6, 2 Job Progress Bar place(1, 2, mMpBar, 4); + + // We move the attribute row to the next one + attributesFirstRow = 3; } if (Net::getPlayerHandler()->getJobLocation() > 0) @@ -156,35 +162,38 @@ StatusWindow::StatusWindow(): place(5, 0, mJobLvlLabel, 3); place(5, 2, mJobLabel).setPadding(3); place(6, 2, mJobBar, 5); + + // We move the attribute row to the next one + attributesFirstRow = 3; } // ---------------------- // Stats Part // ---------------------- - mAttrCont = new VertContainer(32); + mAttrCont = new VertContainer(28); mAttrScroll = new ScrollArea(mAttrCont); mAttrScroll->setOpaque(false); mAttrScroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER); mAttrScroll->setVerticalScrollPolicy(ScrollArea::SHOW_AUTO); - place(0, 3, mAttrScroll, 5, 3); + place(0, attributesFirstRow, mAttrScroll, 5, 3); - mDAttrCont = new VertContainer(32); + mDAttrCont = new VertContainer(28); mDAttrScroll = new ScrollArea(mDAttrCont); mDAttrScroll->setOpaque(false); mDAttrScroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER); mDAttrScroll->setVerticalScrollPolicy(ScrollArea::SHOW_AUTO); - place(6, 3, mDAttrScroll, 5, 3); + place(6, attributesFirstRow, mDAttrScroll, 5, 3); - getLayout().setRowHeight(3, Layout::AUTO_SET); + getLayout().setRowHeight(attributesFirstRow, Layout::AUTO_SET); - mCharacterPointsLabel = new Label("C"); - place(0, 6, mCharacterPointsLabel, 5); + mCharacterPointsLabel = new Label("Character points: 0"); + place(0, attributesFirstRow + 3, mCharacterPointsLabel, 4); if (Net::getPlayerHandler()->canCorrectAttributes()) { - mCorrectionPointsLabel = new Label("C"); - place(0, 7, mCorrectionPointsLabel, 5); + mCorrectionPointsLabel = new Label("Correction points: 0"); + place(4, attributesFirstRow + 3, mCorrectionPointsLabel, 4); } loadWindowState(); @@ -197,7 +206,7 @@ StatusWindow::StatusWindow(): mMoneyLabel->setCaption(strprintf(_("Money: %s"), - Units::formatCurrency(PlayerInfo::getAttribute(MONEY)).c_str())); + Units::formatCurrency(PlayerInfo::getAttribute(MONEY)).c_str())); mMoneyLabel->adjustSize(); mCharacterPointsLabel->setCaption(strprintf(_("Character points: %d"), PlayerInfo::getAttribute(CHAR_POINTS))); @@ -334,7 +343,8 @@ void StatusWindow::updateHPBar(ProgressBar *bar, bool showMax) float prog = 1.0; if (PlayerInfo::getAttribute(MAX_HP) > 0) - prog = (float) PlayerInfo::getAttribute(HP) / PlayerInfo::getAttribute(MAX_HP); + prog = (float) PlayerInfo::getAttribute(HP) + / PlayerInfo::getAttribute(MAX_HP); bar->setProgress(prog); } @@ -352,7 +362,8 @@ void StatusWindow::updateMPBar(ProgressBar *bar, bool showMax) float prog = 1.0f; if (PlayerInfo::getAttribute(MAX_MP) > 0) - prog = (float) PlayerInfo::getAttribute(MP) / PlayerInfo::getAttribute(MAX_MP); + prog = (float) PlayerInfo::getAttribute(MP) + / PlayerInfo::getAttribute(MAX_MP); if (Net::getPlayerHandler()->canUseMagic()) bar->setProgressPalette(Theme::PROG_MP); @@ -363,7 +374,7 @@ void StatusWindow::updateMPBar(ProgressBar *bar, bool showMax) } void StatusWindow::updateProgressBar(ProgressBar *bar, int value, int max, - bool percent) + bool percent) { if (!bar) return; diff --git a/src/net/manaserv/attributes.cpp b/src/net/manaserv/attributes.cpp index 67c52788..a65dc01f 100644 --- a/src/net/manaserv/attributes.cpp +++ b/src/net/manaserv/attributes.cpp @@ -21,6 +21,7 @@ #include "net/manaserv/attributes.h" #include "log.h" +#include "playerinfo.h" #include "gui/statuswindow.h" @@ -46,20 +47,26 @@ namespace Attributes { unsigned int id; std::string name; std::string description; + /** Whether the attribute value can be modified by the player */ bool modifiable; + /**< Attribute scope. */ + std::string scope; + /** The playerInfo core Id the attribute is linked with or -1 if not */ + int playerInfoId; } Attribute; - // tag -> effect - typedef std::map< std::string, std::string > TagMap; - + /** Map for attributes. */ typedef std::map<unsigned int, Attribute> AttributeMap; - AttributeMap attributes; + static AttributeMap attributes; - TagMap tags; + /** tags = effects on attributes. */ + typedef std::map< std::string, std::string > TagMap; + static TagMap tags; - // List of modifiable attribute names used at character's creation. + /** List of modifiable attribute names used at character's creation. */ static std::vector<std::string> attributeLabels; + /** Characters creation points. */ static unsigned int creationPoints = 0; static unsigned int attributeMinimum = 0; static unsigned int attributeMaximum = 0; @@ -95,11 +102,62 @@ namespace Attributes { for (it = attributes.begin(), it_end = attributes.end(); it != it_end; it++) { - if (it->second.modifiable) + if (it->second.modifiable && + (it->second.scope == "character" || it->second.scope == "being")) attributeLabels.push_back(it->second.name + ":"); } } + /** + * Fills the list of base attribute labels. + */ + static int getPlayerInfoIdFromAttrType(std::string attrType) + { + toLower(attrType); + if (attrType == "level") + return ::LEVEL; + else if (attrType == "hp") + return ::HP; + else if (attrType == "max-hp") + return ::MAX_HP; + else if (attrType == "mp") + return ::MP; + else if (attrType == "max-mp") + return ::MAX_MP; + else if (attrType == "exp") + return ::EXP; + else if (attrType == "exp-needed") + return ::EXP_NEEDED; + else if (attrType == "money") + return ::MONEY; + else if (attrType == "total-weight") + return ::TOTAL_WEIGHT; + else if (attrType == "max-weight") + return ::MAX_WEIGHT; + else if (attrType == "skill-points") + return ::SKILL_POINTS; + else if (attrType == "char-points") + return ::CHAR_POINTS; + else if (attrType == "corr-points") + return ::CORR_POINTS; + else if (attrType == "none") + return -2; // Used to hide the attribute display. + + return -1; // Not linked to a playerinfo stat. + } + + int getPlayerInfoIdFromAttrId(int attrId) + { + AttributeMap::const_iterator it = attributes.find(attrId); + + if (it != attributes.end()) + { + return it->second.playerInfoId; + } + + return -1; + } + static void loadBuiltins() { { @@ -108,6 +166,8 @@ namespace Attributes { a.name = _("Strength"); a.description = ""; a.modifiable = true; + a.scope = "character"; + a.playerInfoId = -1; attributes[a.id] = a; tags.insert(std::make_pair("str", _("Strength %+.1f"))); @@ -119,6 +179,8 @@ namespace Attributes { a.name = _("Agility"); a.description = ""; a.modifiable = true; + a.scope = "character"; + a.playerInfoId = -1; attributes[a.id] = a; tags.insert(std::make_pair("agi", _("Agility %+.1f"))); @@ -130,6 +192,8 @@ namespace Attributes { a.name = _("Dexterity"); a.description = ""; a.modifiable = true; + a.scope = "character"; + a.playerInfoId = -1; attributes[a.id] = a; tags.insert(std::make_pair("dex", _("Dexterity %+.1f"))); @@ -141,6 +205,8 @@ namespace Attributes { a.name = _("Vitality"); a.description = ""; a.modifiable = true; + a.scope = "character"; + a.playerInfoId = -1; attributes[a.id] = a; tags.insert(std::make_pair("vit", _("Vitality %+.1f"))); @@ -152,6 +218,8 @@ namespace Attributes { a.name = _("Intelligence"); a.description = ""; a.modifiable = true; + a.scope = "character"; + a.playerInfoId = -1; attributes[a.id] = a; tags.insert(std::make_pair("int", _("Intelligence %+.1f"))); @@ -163,6 +231,8 @@ namespace Attributes { a.name = _("Willpower"); a.description = ""; a.modifiable = true; + a.scope = "character"; + a.playerInfoId = -1; attributes[a.id] = a; tags.insert(std::make_pair("wil", _("Willpower %+.1f"))); @@ -211,12 +281,15 @@ namespace Attributes { continue; } + // Create the attribute. Attribute a; a.id = id; a.name = name; a.description = XML::getProperty(node, "desc", ""); - a.modifiable = XML::getProperty(node, "modifiable", "false") - == "true"; + a.modifiable = XML::getBoolProperty(node, "modifiable", false); + a.scope = XML::getProperty(node, "scope", "none"); + a.playerInfoId = getPlayerInfoIdFromAttrType( + XML::getProperty(node, "player-info", "")); attributes[id] = a; @@ -319,9 +392,16 @@ namespace Attributes { AttributeMap::const_iterator it, it_end; for (it = attributes.begin(), it_end = attributes.end(); it != it_end; it++) - statusWindow->addAttribute(it->second.id, it->second.name, - it->second.modifiable, - it->second.description); + { + if (it->second.playerInfoId == -1 && + (it->second.scope == "character" || it->second.scope == "being")) + { + statusWindow->addAttribute(it->second.id, + it->second.name, + it->second.modifiable, + it->second.description); + } + } } } // namespace Attributes diff --git a/src/net/manaserv/attributes.h b/src/net/manaserv/attributes.h index 9791d2cb..aced85ec 100644 --- a/src/net/manaserv/attributes.h +++ b/src/net/manaserv/attributes.h @@ -26,6 +26,7 @@ namespace ManaServ { namespace Attributes { + void load(); void unload(); @@ -40,6 +41,12 @@ namespace Attributes { std::vector<std::string>& getLabels(); /** + * Give back the corresponding playerinfo Id from the attribute id + * defined in the xml file. + */ + int getPlayerInfoIdFromAttrId(int attrId); + + /** * Give the attribute points given to a character * at its creation. */ diff --git a/src/net/manaserv/playerhandler.cpp b/src/net/manaserv/playerhandler.cpp index 5bacce49..a579517f 100644 --- a/src/net/manaserv/playerhandler.cpp +++ b/src/net/manaserv/playerhandler.cpp @@ -43,6 +43,7 @@ #include "net/manaserv/messagein.h" #include "net/manaserv/messageout.h" #include "net/manaserv/protocol.h" +#include "net/manaserv/attributes.h" /** * Max. distance we are willing to scroll after a teleport; @@ -112,18 +113,23 @@ void PlayerHandler::handleMessage(Net::MessageIn &msg) { while (msg.getUnreadLength()) { - int attr = msg.readInt16(); + int attrId = msg.readInt16(); double base = msg.readInt32() / 256.0; double value = msg.readInt32() / 256.0; - /* TODO handle HP - if (attr == ATTR_HP) - PlayerInfo::setAttribute(HP, value); - else if (attr == ATTR_MAX_HP) - PlayerInfo::setAttribute(MAX_HP, value);*/ - - PlayerInfo::setStatBase(attr, base); - PlayerInfo::setStatMod(attr, value - base); + // Set the core player attribute the stat + // depending on attribute link. + int playerInfoId = + Attributes::getPlayerInfoIdFromAttrId(attrId); + if (playerInfoId > -1) + { + PlayerInfo::setAttribute(playerInfoId, value); + } + else + { + PlayerInfo::setStatBase(attrId, base); + PlayerInfo::setStatMod(attrId, value - base); + } } } break; |