summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2009-07-19 22:05:41 -0600
committerJared Adams <jaxad0127@gmail.com>2009-07-19 22:30:18 -0600
commit5141dc4a99b74358f2dd0f5f211c5069a630ce1b (patch)
tree647cfb05d179d61759ef3679482eb204a7853d34
parent2e8fca7d471b4e2bf20735a0669e96722c000669 (diff)
downloadmana-client-5141dc4a99b74358f2dd0f5f211c5069a630ce1b.tar.gz
mana-client-5141dc4a99b74358f2dd0f5f211c5069a630ce1b.tar.bz2
mana-client-5141dc4a99b74358f2dd0f5f211c5069a630ce1b.tar.xz
mana-client-5141dc4a99b74358f2dd0f5f211c5069a630ce1b.zip
Merge StatusWindows
Also some other small merges
-rw-r--r--src/CMakeLists.txt6
-rw-r--r--src/Makefile.am6
-rw-r--r--src/game.cpp4
-rw-r--r--src/gui/charselectdialog.cpp6
-rw-r--r--src/gui/ministatus.cpp2
-rw-r--r--src/gui/status.cpp384
-rw-r--r--src/gui/status.h99
-rw-r--r--src/gui/statuswindow.cpp568
-rw-r--r--src/gui/statuswindow.h79
-rw-r--r--src/localplayer.cpp97
-rw-r--r--src/localplayer.h52
-rw-r--r--src/net/ea/charserverhandler.cpp15
-rw-r--r--src/net/ea/generalhandler.cpp6
-rw-r--r--src/net/ea/maphandler.cpp7
-rw-r--r--src/net/ea/playerhandler.cpp43
-rw-r--r--src/net/ea/protocol.h9
-rw-r--r--src/net/tmwserv/generalhandler.cpp6
-rw-r--r--src/net/tmwserv/playerhandler.cpp2
-rw-r--r--tmw.cbp18
19 files changed, 583 insertions, 826 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index a3c817e1..15109185 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -221,6 +221,8 @@ SET(SRCS
gui/skin.h
gui/speechbubble.cpp
gui/speechbubble.h
+ gui/statuswindow.cpp
+ gui/statuswindow.h
gui/storagewindow.cpp
gui/storagewindow.h
gui/table.cpp
@@ -420,8 +422,6 @@ SET(SRCS
)
SET(SRCS_EA
- gui/status.cpp
- gui/status.h
net/ea/gui/partytab.cpp
net/ea/gui/partytab.h
net/ea/adminhandler.cpp
@@ -480,8 +480,6 @@ SET(SRCS_TMW
gui/quitdialog.h
gui/serverdialog.cpp
gui/serverdialog.h
- gui/statuswindow.cpp
- gui/statuswindow.h
gui/unregisterdialog.cpp
gui/unregisterdialog.h
net/tmwserv/accountserver/account.cpp
diff --git a/src/Makefile.am b/src/Makefile.am
index 03d37015..ce00c1b9 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -170,6 +170,8 @@ tmw_SOURCES = gui/widgets/avatar.cpp \
gui/skin.h \
gui/speechbubble.cpp \
gui/speechbubble.h \
+ gui/statuswindow.cpp \
+ gui/statuswindow.h \
gui/storagewindow.cpp \
gui/storagewindow.h \
gui/table.cpp \
@@ -386,8 +388,6 @@ tmw_SOURCES += \
gui/quitdialog.h \
gui/serverdialog.cpp \
gui/serverdialog.h \
- gui/statuswindow.cpp \
- gui/statuswindow.h \
gui/unregisterdialog.cpp \
gui/unregisterdialog.h \
net/tmwserv/accountserver/account.cpp \
@@ -460,8 +460,6 @@ endif
if SERVER_EATHENA
tmw_CXXFLAGS += -DEATHENA_SUPPORT
tmw_SOURCES += \
- gui/status.cpp \
- gui/status.h \
net/ea/gui/partytab.cpp \
net/ea/gui/partytab.h \
net/ea/adminhandler.cpp \
diff --git a/src/game.cpp b/src/game.cpp
index 306d8812..c7a1d4e7 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -63,7 +63,7 @@
#include "gui/sell.h"
#include "gui/setup.h"
#include "gui/skilldialog.h"
-#include "gui/status.h"
+#include "gui/statuswindow.h"
#include "gui/trade.h"
#include "gui/viewport.h"
#include "gui/windowmenu.h"
@@ -224,7 +224,7 @@ static void createGuiWindows()
npcDialog = new NpcDialog;
npcPostDialog = new NpcPostDialog;
storageWindow = new StorageWindow;
- statusWindow = new StatusWindow();
+ statusWindow = new StatusWindow;
miniStatusWindow = new MiniStatusWindow;
inventoryWindow = new InventoryWindow;
skillDialog = new SkillDialog;
diff --git a/src/gui/charselectdialog.cpp b/src/gui/charselectdialog.cpp
index 03371271..1387bce5 100644
--- a/src/gui/charselectdialog.cpp
+++ b/src/gui/charselectdialog.cpp
@@ -36,6 +36,8 @@
#include "gui/changeemaildialog.h"
#include "net/tmwserv/accountserver/account.h"
+#else
+#include "net/ea/protocol.h"
#endif
#include "gui/widgets/button.h"
@@ -296,9 +298,9 @@ void CharSelectDialog::updatePlayerInfo()
mNameLabel->setCaption(strprintf(_("Name: %s"),
pi->getName().c_str()));
mLevelLabel->setCaption(strprintf(_("Level: %d"), pi->getLevel()));
-#ifndef TMWSERV_SUPPORT
+#ifdef EATHENA_SUPPORT
mJobLevelLabel->setCaption(strprintf(_("Job Level: %d"),
- pi->mJobLevel));
+ pi->getAttributeBase(JOB)));
#endif
mMoneyLabel->setCaption(strprintf(_("Money: %s"), mMoney.c_str()));
if (!mCharSelected)
diff --git a/src/gui/ministatus.cpp b/src/gui/ministatus.cpp
index 65d2391d..8aaeb580 100644
--- a/src/gui/ministatus.cpp
+++ b/src/gui/ministatus.cpp
@@ -22,7 +22,7 @@
#include "gui/ministatus.h"
#include "gui/gui.h"
-#include "gui/status.h"
+#include "gui/statuswindow.h"
#include "gui/widgets/progressbar.h"
diff --git a/src/gui/status.cpp b/src/gui/status.cpp
deleted file mode 100644
index 02f3de4e..00000000
--- a/src/gui/status.cpp
+++ /dev/null
@@ -1,384 +0,0 @@
-/*
- * The Mana World
- * Copyright (C) 2004 The Mana World Development Team
- *
- * This file is part of The Mana World.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include "gui/status.h"
-#include "gui/palette.h"
-
-#include "localplayer.h"
-#include "units.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/label.h"
-#include "gui/widgets/layout.h"
-#include "gui/widgets/progressbar.h"
-#include "gui/widgets/windowcontainer.h"
-
-#include "net/net.h"
-#include "net/playerhandler.h"
-#include "net/ea/protocol.h"
-
-#include "utils/gettext.h"
-#include "utils/mathutils.h"
-#include "utils/stringutils.h"
-
-StatusWindow::StatusWindow():
- Window(player_node->getName()),
- mCurrency(0)
-{
- setWindowName("Status");
- setCloseButton(true);
- setSaveVisible(true);
- setDefaultSize(400, 345, ImageRect::CENTER);
-
- // ----------------------
- // Status Part
- // ----------------------
-
- mLvlLabel = new Label(strprintf(_("Level: %d"), 0));
- mJobLvlLabel = new Label(strprintf(_("Job: %d"), 0));
- mGpLabel = new Label(strprintf(_("Money: %s"),
- Units::formatCurrency(mCurrency).c_str()));
-
- mHpLabel = new Label(_("HP:"));
- mHpBar = new ProgressBar(0.0f, 80, 15, gcn::Color(0, 171, 34));
-
- mXpLabel = new Label(_("Exp:"));
- mXpBar = new ProgressBar(0.0f, 80, 15, gcn::Color(143, 192, 211));
-
- mMpLabel = new Label(_("MP:"));
- mMpBar = new ProgressBar(0.0f, 80, 15, gcn::Color(26, 102, 230));
-
- mJobLabel = new Label(_("Job:"));
- mJobBar = new ProgressBar(0.0f, 80, 15, gcn::Color(220, 135, 203));
-
- // ----------------------
- // Stats Part
- // ----------------------
-
- // Static Labels
- gcn::Label *mStatsTitleLabel = new Label(_("Stats"));
- gcn::Label *mStatsTotalLabel = new Label(_("Total"));
- gcn::Label *mStatsCostLabel = new Label(_("Cost"));
- mStatsTotalLabel->setAlignment(gcn::Graphics::CENTER);
-
- // Derived Stats
- 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(attrNames[i]);
- mStatsLabel[i]->setAlignment(gcn::Graphics::CENTER);
- mStatsDisplayLabel[i] = new Label;
- mPointsLabel[i] = new Label("0");
- mPointsLabel[i]->setAlignment(gcn::Graphics::CENTER);
- }
- mRemainingStatsPointsLabel = new Label;
-
- // Set button events Id
- mStatsButton[0] = new Button("+", "STR", this);
- mStatsButton[1] = new Button("+", "AGI", this);
- mStatsButton[2] = new Button("+", "VIT", this);
- mStatsButton[3] = new Button("+", "INT", this);
- mStatsButton[4] = new Button("+", "DEX", this);
- mStatsButton[5] = new Button("+", "LUK", this);
-
- // Assemble
- ContainerPlacer place;
- place = getPlacer(0, 0);
-
- place(0, 0, mLvlLabel, 3);
- place(5, 0, mJobLvlLabel, 3);
- place(8, 0, mGpLabel, 3);
- place(0, 1, mHpLabel).setPadding(3);
- place(1, 1, mHpBar, 4);
- place(5, 1, mXpLabel).setPadding(3);
- place(6, 1, mXpBar, 5);
- place(0, 2, mMpLabel).setPadding(3);
- place(1, 2, mMpBar, 4);
- place(5, 2, mJobLabel).setPadding(3);
- place(6, 2, mJobBar, 5);
- place.getCell().matchColWidth(0, 1);
- place = getPlacer(0, 3);
- place(0, 1, mStatsTitleLabel, 5);
- place(5, 1, mStatsTotalLabel, 5);
- place(12, 1, mStatsCostLabel, 5);
- for (int i = 0; i < 6; i++)
- {
- place(0, 2 + i, mStatsLabel[i], 7).setPadding(5);
- place(7, 2 + i, mStatsDisplayLabel[i]).setPadding(5);
- place(10, 2 + i, mStatsButton[i]);
- place(12, 2 + i, mPointsLabel[i]).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()
-{
- // Status Part
- // -----------
- mLvlLabel->setCaption(strprintf(_("Level: %d"), player_node->getLevel()));
- mLvlLabel->adjustSize();
-
- mJobLvlLabel->setCaption(strprintf(_("Job: %d"), player_node->mJobLevel));
- mJobLvlLabel->adjustSize();
-
- if (mCurrency != player_node->getMoney()) {
- mCurrency = player_node->getMoney();
- mGpLabel->setCaption(strprintf(_("Money: %s"),
- Units::formatCurrency(mCurrency).c_str()));
- mGpLabel->adjustSize();
- }
-
- updateHPBar(mHpBar, true);
-
- updateMPBar(mMpBar, true);
-
- updateXPBar(mXpBar, false);
-
- updateJobBar(mJobBar, false);
-
- // Stats Part
- // ----------
- int statusPoints = player_node->getCharacterPoints();
-
- // Update labels
- for (int i = 0; i < 6; 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)));
-
- mStatsDisplayLabel[i]->adjustSize();
- mPointsLabel[i]->adjustSize();
-
- mStatsButton[i]->setEnabled(player_node->getAttributeBase(i + STR_U)
- <= statusPoints);
- }
- mRemainingStatsPointsLabel->setCaption(
- strprintf(_("Remaining Status Points: %d"), statusPoints));
- mRemainingStatsPointsLabel->adjustSize();
-
- // Derived Stats Points
- 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)
-{
- // Stats Part
- // Net::getPlayerHandler()->increaseStat(?);
- if (event.getId().length() == 3)
- {
- if (event.getId() == "STR")
- Net::getPlayerHandler()->increaseAttribute(STR);
- if (event.getId() == "AGI")
- Net::getPlayerHandler()->increaseAttribute(AGI);
- if (event.getId() == "VIT")
- Net::getPlayerHandler()->increaseAttribute(VIT);
- if (event.getId() == "INT")
- Net::getPlayerHandler()->increaseAttribute(INT);
- if (event.getId() == "DEX")
- Net::getPlayerHandler()->increaseAttribute(DEX);
- if (event.getId() == "LUK")
- Net::getPlayerHandler()->increaseAttribute(LUK);
- }
-}
-
-void StatusWindow::updateHPBar(ProgressBar *bar, bool showMax)
-{
- if (showMax)
- bar->setText(toString(player_node->getHp()) +
- "/" + toString(player_node->getMaxHp()));
- else
- bar->setText(toString(player_node->getHp()));
-
- // HP Bar coloration
- float r1 = 255;
- float g1 = 255;
- float b1 = 255;
-
- float r2 = 255;
- float g2 = 255;
- float b2 = 255;
-
- float weight = 1.0f;
-
- int curHP = player_node->getHp();
- int thresholdLevel = player_node->getMaxHp() / 4;
- int thresholdProgress = curHP % thresholdLevel;
- weight = 1-((float)thresholdProgress) / ((float)thresholdLevel);
-
- if (curHP < (thresholdLevel))
- {
- gcn::Color color1 = guiPalette->getColor(Palette::HPBAR_ONE_HALF);
- gcn::Color color2 = guiPalette->getColor(Palette::HPBAR_ONE_QUARTER);
- r1 = color1.r; r2 = color2.r;
- g1 = color1.g; g2 = color2.g;
- b1 = color1.b; b2 = color2.b;
- }
- else if (curHP < (thresholdLevel*2))
- {
- gcn::Color color1 = guiPalette->getColor(Palette::HPBAR_THREE_QUARTERS);
- gcn::Color color2 = guiPalette->getColor(Palette::HPBAR_ONE_HALF);
- r1 = color1.r; r2 = color2.r;
- g1 = color1.g; g2 = color2.g;
- b1 = color1.b; b2 = color2.b;
- }
- else if (curHP < thresholdLevel*3)
- {
- gcn::Color color1 = guiPalette->getColor(Palette::HPBAR_FULL);
- gcn::Color color2 = guiPalette->getColor(Palette::HPBAR_THREE_QUARTERS);
- r1 = color1.r; r2 = color2.r;
- g1 = color1.g; g2 = color2.g;
- b1 = color1.b; b2 = color2.b;
- }
- else
- {
- gcn::Color color1 = guiPalette->getColor(Palette::HPBAR_FULL);
- gcn::Color color2 = guiPalette->getColor(Palette::HPBAR_FULL);
- r1 = color1.r; r2 = color2.r;
- g1 = color1.g; g2 = color2.g;
- b1 = color1.b; b2 = color2.b;
- }
-
- // Safety checks
- if (weight > 1.0f) weight = 1.0f;
- if (weight < 0.0f) weight = 0.0f;
-
- // Do the color blend
- r1 = (int) weightedAverage(r1, r2,weight);
- g1 = (int) weightedAverage(g1, g2, weight);
- b1 = (int) weightedAverage(b1, b2, weight);
-
- // More safety checks
- if (r1 > 255) r1 = 255;
- if (g1 > 255) g1 = 255;
- if (b1 > 255) b1 = 255;
-
- bar->setColor(r1, g1, b1);
-
- bar->setProgress((float) player_node->getHp() / (float) player_node->getMaxHp());
-}
-
-void StatusWindow::updateMPBar(ProgressBar *bar, bool showMax)
-{
- if (showMax)
- bar->setText(toString(player_node->mMp) +
- "/" + toString(player_node->mMaxMp));
- else
- bar->setText(toString(player_node->mMp));
-
- 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
-
- bar->setProgress((float) player_node->mMp / (float) player_node->mMaxMp);
-}
-
-static void updateProgressBar(ProgressBar *bar, int value, int max,
- bool percent)
-{
- if (max == 0)
- {
- bar->setText(_("Max level"));
- bar->setProgress(1.0);
- }
- else
- {
- float progress = (float) value / max;
-
- if (percent)
- bar->setText(strprintf("%2.2f", 100 * progress) + "%");
- else
- bar->setText(toString(value) + "/" + toString(max));
-
- bar->setProgress(progress);
- }
-}
-
-void StatusWindow::updateXPBar(ProgressBar *bar, bool percent)
-{
- updateProgressBar(bar,
- player_node->getLevelProgress(),
- player_node->mXpForNextLevel,
- percent);
-}
-
-void StatusWindow::updateJobBar(ProgressBar *bar, bool percent)
-{
- updateProgressBar(bar,
- player_node->mJobXp,
- player_node->mJobXpForNextLevel,
- percent);
-}
diff --git a/src/gui/status.h b/src/gui/status.h
deleted file mode 100644
index 6e8371c2..00000000
--- a/src/gui/status.h
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * The Mana World
- * Copyright (C) 2004 The Mana World Development Team
- *
- * This file is part of The Mana World.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#ifndef STATUS_H
-#define STATUS_H
-
-#include "gui/widgets/window.h"
-
-#include <guichan/actionlistener.hpp>
-
-class LocalPlayer;
-class ProgressBar;
-
-/**
- * The player status dialog.
- *
- * \ingroup Interface
- */
-class StatusWindow : public Window, public gcn::ActionListener
-{
- public:
- /**
- * Constructor.
- */
- StatusWindow();
-
- /**
- * Called when receiving actions from widget.
- */
- void action(const gcn::ActionEvent &event);
-
- /**
- * 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);
- static void updateJobBar(ProgressBar *bar, bool percent = true);
-
- private:
- /**
- * Status Part
- */
- gcn::Label *mLvlLabel, *mJobLvlLabel;
- gcn::Label *mGpLabel;
- int mCurrency;
- gcn::Label *mHpLabel, *mMpLabel, *mXpLabel, *mJobLabel;
- ProgressBar *mHpBar, *mMpBar;
- ProgressBar *mXpBar, *mJobBar;
-
- /**
- * Derived Statistics captions
- */
- gcn::Label *mDStatsLabel[7];
- gcn::Label *mDPointsLabel[7];
-
- /**
- * Stats captions.
- */
- gcn::Label *mStatsLabel[6];
- gcn::Label *mPointsLabel[6];
- gcn::Label *mStatsDisplayLabel[6];
- gcn::Label *mRemainingStatsPointsLabel;
-
- /**
- * Stats buttons.
- */
- gcn::Button *mStatsButton[6];
-};
-
-extern StatusWindow *statusWindow;
-
-#endif
diff --git a/src/gui/statuswindow.cpp b/src/gui/statuswindow.cpp
index 4df474a7..ed073440 100644
--- a/src/gui/statuswindow.cpp
+++ b/src/gui/statuswindow.cpp
@@ -23,13 +23,62 @@
#include "gui/widgets/button.h"
#include "gui/widgets/label.h"
+#include "gui/widgets/layouthelper.h"
#include "gui/widgets/progressbar.h"
+#include "gui/widgets/scrollarea.h"
+#include "gui/widgets/vertcontainer.h"
#include "gui/widgets/windowcontainer.h"
#include "localplayer.h"
+#include "units.h"
+#include "net/net.h"
+#include "net/playerhandler.h"
+
+#ifdef EATHENA_SUPPORT
+#include "net/ea/protocol.h"
+#endif
+
+#include "utils/gettext.h"
+#include "utils/mathutils.h"
#include "utils/stringutils.h"
+class AttrDisplay : public Container {
+ public:
+ virtual std::string update();
+
+ protected:
+ AttrDisplay(int id, const std::string &name);
+
+ const int mId;
+ const std::string mName;
+
+ LayoutHelper *mLayout;
+ Label *mLabel;
+ Label *mValue;
+};
+
+class DerDisplay : public AttrDisplay {
+ public:
+ DerDisplay(int id, const std::string &name);
+};
+
+class ChangeDisplay : public AttrDisplay, gcn::ActionListener {
+ public:
+ ChangeDisplay(int id, const std::string &name);
+ std::string update();
+ void setPointsNeeded(int needed);
+
+ private:
+ void action(const gcn::ActionEvent &event);
+
+ int mNeeded;
+
+ Label *mPoints;
+ Button *mDec;
+ Button *mInc;
+};
+
StatusWindow::StatusWindow():
Window(player_node->getName())
{
@@ -39,7 +88,6 @@ StatusWindow::StatusWindow():
setSaveVisible(true);
setDefaultSize((windowContainer->getWidth() - 365) / 2,
(windowContainer->getHeight() - 255) / 2, 365, 275);
- loadWindowState();
// ----------------------
// Status Part
@@ -50,246 +98,396 @@ StatusWindow::StatusWindow():
mHpLabel = new Label("HP:");
mHpBar = new ProgressBar(0.0f, 80, 15, gcn::Color(0, 171, 34));
- mHpValueLabel = new Label;
-
- int y = 3;
- int x = 5;
-
- mLvlLabel->setPosition(x, y);
- x += mLvlLabel->getWidth() + 40;
- mMoneyLabel->setPosition(x, y);
- y += mLvlLabel->getHeight() + 5; // Next Row
- x = 5;
-
- mHpLabel->setPosition(x, y);
- x += mHpLabel->getWidth() + 5;
- mHpBar->setPosition(x, y);
- x += mHpBar->getWidth() + 5;
- mHpValueLabel->setPosition(x, y);
-
- y += mHpLabel->getHeight() + 5; // Next Row
- x = 5;
-
- add(mLvlLabel);
- add(mMoneyLabel);
- add(mHpLabel);
- add(mHpValueLabel);
- add(mHpBar);
+ mXpLabel = new Label(_("Exp:"));
+ mXpBar = new ProgressBar(0.0f, 80, 15, gcn::Color(143, 192, 211));
+
+ mMpLabel = new Label(_("MP:"));
+ mMpBar = new ProgressBar(0.0f, 80, 15, gcn::Color(26, 102, 230));
+
+ place(0, 0, mLvlLabel, 3);
+ // 5, 0 Job Level
+ place(8, 0, mMoneyLabel, 3);
+ place(0, 1, mHpLabel).setPadding(3);
+ place(1, 1, mHpBar, 4);
+ place(5, 1, mXpLabel).setPadding(3);
+ place(6, 1, mXpBar, 5);
+ place(0, 2, mMpLabel).setPadding(3);
+ // 5, 2 and 6, 2 Job Progress Bar
+ place(1, 2, mMpBar, 4);
+
+#ifdef EATHENA_SUPPORT
+ mJobLvlLabel = new Label(strprintf(_("Job: %d"), 0));
+ mJobLabel = new Label(_("Job:"));
+ mJobBar = new ProgressBar(0.0f, 80, 15, gcn::Color(220, 135, 203));
+
+ place(5, 0, mJobLvlLabel, 3);
+ place(5, 2, mJobLabel).setPadding(3);
+ place(6, 2, mJobBar, 5);
+#endif
// ----------------------
// Stats Part
// ----------------------
- // Static Labels
- gcn::Label *mStatsTitleLabel = new Label("Stats");
- gcn::Label *mStatsTotalLabel = new Label("Total");
+ mAttrCont = new VertContainer(32);
+ mAttrScroll = new ScrollArea(mAttrCont);
+ mAttrScroll->setOpaque(false);
+ mAttrScroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
+ mAttrScroll->setVerticalScrollPolicy(ScrollArea::SHOW_AUTO);
+ place(0, 3, mAttrScroll, 5, 3);
- // New labels
- for (int i = 0; i < 6; i++) {
- mStatsLabel[i] = new Label;
- mStatsDisplayLabel[i] = new Label;
- }
- mCharacterPointsLabel = new Label;
- mCorrectionPointsLabel = new Label;
-
- // Set button events Id
- mStatsPlus[0] = new Button("+", "STR+", this);
- mStatsPlus[1] = new Button("+", "AGI+", this);
- mStatsPlus[2] = new Button("+", "DEX+", this);
- mStatsPlus[3] = new Button("+", "VIT+", this);
- mStatsPlus[4] = new Button("+", "INT+", this);
- mStatsPlus[5] = new Button("+", "WIL+", this);
-
- mStatsMinus[0] = new Button("-", "STR-", this);
- mStatsMinus[1] = new Button("-", "AGI-", this);
- mStatsMinus[2] = new Button("-", "DEX-", this);
- mStatsMinus[3] = new Button("-", "VIT-", this);
- 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);
- int totalLabelY = mStatsTotalLabel->getY();
-
- for (int i = 0; i < 6; i++)
- {
- mStatsLabel[i]->setPosition(5,
- mStatsTotalLabel->getY() + (i * 23) + 15);
- mStatsMinus[i]->setPosition(85, totalLabelY + (i * 23) + 15);
- mStatsDisplayLabel[i]->setPosition(125,
- totalLabelY + (i * 23) + 15);
- mStatsPlus[i]->setPosition(185, totalLabelY + (i * 23) + 15);
- }
+ mDAttrCont = new VertContainer(32);
+ mDAttrScroll = new ScrollArea(mDAttrCont);
+ mDAttrScroll->setOpaque(false);
+ mDAttrScroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
+ mDAttrScroll->setVerticalScrollPolicy(ScrollArea::SHOW_AUTO);
+ place(6, 3, mDAttrScroll, 5, 3);
- mCharacterPointsLabel->setPosition(5, mStatsDisplayLabel[5]->getY() + 25);
- mCorrectionPointsLabel->setPosition(5, mStatsDisplayLabel[5]->getY() + 35);
+ getLayout().setRowHeight(3, Layout::AUTO_SET);
- // Assemble
- add(mStatsTitleLabel);
- add(mStatsTotalLabel);
- for(int i = 0; i < 6; i++)
- {
- add(mStatsLabel[i]);
- add(mStatsDisplayLabel[i]);
- add(mStatsPlus[i]);
- add(mStatsMinus[i]);
- }
+ mCharacterPointsLabel = new Label("C");
+ mCorrectionPointsLabel = new Label("C");
+ place(0, 6, mCharacterPointsLabel, 5);
+ place(0, 7, mCorrectionPointsLabel, 5);
- add(mCharacterPointsLabel);
- add(mCorrectionPointsLabel);
+ loadWindowState();
+
+ update(HP);
+ update(MP);
+ update(EXP);
+ update(MONEY);
+ update(CHAR_POINTS); // This also updates all attributes (none atm)
+ update(LEVEL);
+#ifdef EATHENA_SUPPORT
+ update(JOB);
+#endif
}
-void StatusWindow::update()
+std::string StatusWindow::update(int id)
{
- // Status Part
- // -----------
- mLvlLabel->setCaption( "Level: " +
- toString(player_node->getLevel()) +
- " (" +
- toString(player_node->getLevelProgress()) +
- "%)");
- mLvlLabel->adjustSize();
+ if (id == HP)
+ {
+ updateHPBar(mHpBar, true);
+
+ return _("HP");
+ }
+ else if (id == MP)
+ {
+ updateMPBar(mMpBar, true);
- mMoneyLabel->setCaption("Money: " + toString(player_node->getMoney()) + " GP");
- mMoneyLabel->adjustSize();
+ return _("MP");
+ }
+ else if (id == EXP)
+ {
+ updateXPBar(mXpBar, false);
- updateHPBar(mHpBar, true);
+ return _("Exp");
+ }
+ else if (id == MONEY)
+ {
+ int money = player_node->getMoney();
+ mMoneyLabel->setCaption(strprintf(_("Money: %s"),
+ Units::formatCurrency(money).c_str()));
+ mMoneyLabel->adjustSize();
- // Stats Part
- // ----------
- const std::string attrNames[6] = {
- "Strength",
- "Agility",
- "Dexterity",
- "Vitality",
- "Intelligence",
- "Willpower"
- };
- int characterPoints = player_node->getCharacterPoints();
- int correctionPoints = player_node->getCorrectionPoints();
- // Update labels
- for (int i = 0; i < 6; i++)
+ return _("Money");
+ }
+#ifdef EATHENA_SUPPORT
+ else if (id == JOB)
{
- mStatsLabel[i]->setCaption(attrNames[i]);
- mStatsDisplayLabel[i]->setCaption(
- strprintf("%d / %d",
- player_node->getAttributeEffective(CHAR_ATTR_BEGIN + i),
- player_node->getAttributeBase(CHAR_ATTR_BEGIN + i)));
+ mJobLvlLabel->setCaption(strprintf(_("Job: %d"),
+ player_node->getAttributeBase(JOB)));
+ mJobLvlLabel->adjustSize();
- mStatsLabel[i]->adjustSize();
- mStatsDisplayLabel[i]->adjustSize();
+ updateProgressBar(mJobBar, JOB, false);
- mStatsPlus[i]->setEnabled(characterPoints);
- mStatsMinus[i]->setEnabled(correctionPoints);
+ return _("Job");
}
- mCharacterPointsLabel->setCaption("Character Points: " +
- toString(characterPoints));
- mCharacterPointsLabel->adjustSize();
+#endif
+ else if (id == CHAR_POINTS)
+ {
+ mCharacterPointsLabel->setCaption(strprintf(_("Character Points: %d"),
+ player_node->getCharacterPoints()));
+ mCharacterPointsLabel->adjustSize();
+
+ mCorrectionPointsLabel->setCaption(strprintf(_("Correction Points: %d"),
+ player_node->getCorrectionPoints()));
+ mCorrectionPointsLabel->adjustSize();
+
+ for (Attrs::iterator it = mAttrs.begin(); it != mAttrs.end(); it++)
+ {
+ it->second->update();
+ }
+ }
+ else if (id == LEVEL)
+ {
+ mLvlLabel->setCaption(strprintf(_("Level: %d"),
+ player_node->getLevel()));
+ mLvlLabel->adjustSize();
- mCorrectionPointsLabel->setCaption("Correction Points: " +
- toString(correctionPoints));
- mCorrectionPointsLabel->adjustSize();
+ return _("Level");
+ }
+ else
+ {
+ Attrs::iterator it = mAttrs.find(id);
- // Update Second column widgets position
- mMoneyLabel->setPosition(mLvlLabel->getX() + mLvlLabel->getWidth() + 20,
- mLvlLabel->getY());
+ if (it != mAttrs.end())
+ {
+ return it->second->update();
+ }
+ }
- update();
+ return "";
}
-void StatusWindow::update(int id)
+void StatusWindow::setPointsNeeded(int id, int needed)
{
- // TODO: only update what changed
- update();
+ Attrs::iterator it = mAttrs.find(id);
+
+ if (it != mAttrs.end())
+ {
+ ChangeDisplay *disp = dynamic_cast<ChangeDisplay*>(it->second);
+ if (disp)
+ disp->setPointsNeeded(needed);
+ }
}
void StatusWindow::addAttribute(int id, const std::string &name,
bool modifiable)
{
- // future use
-}
-
-void StatusWindow::action(const gcn::ActionEvent &event)
-{
- const std::string &eventId = event.getId();
+ AttrDisplay *disp;
- // Stats Part
- if (eventId == "STR+")
- {
- player_node->raiseAttribute(LocalPlayer::STR);
- }
- else if (eventId == "AGI+")
+ if (modifiable)
{
- player_node->raiseAttribute(LocalPlayer::AGI);
+ disp = new ChangeDisplay(id, name);
+ mAttrCont->add(disp);
}
- else if (eventId == "DEX+")
- {
- player_node->raiseAttribute(LocalPlayer::DEX);
- }
- else if (eventId == "VIT+")
- {
- player_node->raiseAttribute(LocalPlayer::VIT);
- }
- else if (eventId == "INT+")
- {
- player_node->raiseAttribute(LocalPlayer::INT);
- }
- else if (eventId == "WIL+")
+ else
{
- player_node->raiseAttribute(LocalPlayer::WIL);
+ disp = new DerDisplay(id, name);
+ mDAttrCont->add(disp);
}
- else if (eventId == "STR-")
+ mAttrs[id] = disp;
+}
+
+void StatusWindow::updateHPBar(ProgressBar *bar, bool showMax)
+{
+ if (showMax)
+ bar->setText(toString(player_node->getHp()) +
+ "/" + toString(player_node->getMaxHp()));
+ else
+ bar->setText(toString(player_node->getHp()));
+
+ // HP Bar coloration
+ float r1 = 255;
+ float g1 = 255;
+ float b1 = 255;
+
+ float r2 = 255;
+ float g2 = 255;
+ float b2 = 255;
+
+ float weight = 1.0f;
+
+ int curHP = player_node->getHp();
+ int thresholdLevel = player_node->getMaxHp() / 4;
+ int thresholdProgress = curHP % thresholdLevel;
+ if (thresholdLevel)
+ weight = 1 - ((float)thresholdProgress) / ((float)thresholdLevel);
+ else
+ weight = 0;
+
+ if (curHP < (thresholdLevel))
{
- player_node->lowerAttribute(LocalPlayer::STR);
+ gcn::Color color1 = guiPalette->getColor(Palette::HPBAR_ONE_HALF);
+ gcn::Color color2 = guiPalette->getColor(Palette::HPBAR_ONE_QUARTER);
+ r1 = color1.r; r2 = color2.r;
+ g1 = color1.g; g2 = color2.g;
+ b1 = color1.b; b2 = color2.b;
}
- else if (eventId == "AGI-")
+ else if (curHP < (thresholdLevel*2))
{
- player_node->lowerAttribute(LocalPlayer::AGI);
+ gcn::Color color1 = guiPalette->getColor(Palette::HPBAR_THREE_QUARTERS);
+ gcn::Color color2 = guiPalette->getColor(Palette::HPBAR_ONE_HALF);
+ r1 = color1.r; r2 = color2.r;
+ g1 = color1.g; g2 = color2.g;
+ b1 = color1.b; b2 = color2.b;
}
- else if (eventId == "DEX-")
+ else if (curHP < thresholdLevel*3)
{
- player_node->lowerAttribute(LocalPlayer::DEX);
+ gcn::Color color1 = guiPalette->getColor(Palette::HPBAR_FULL);
+ gcn::Color color2 = guiPalette->getColor(Palette::HPBAR_THREE_QUARTERS);
+ r1 = color1.r; r2 = color2.r;
+ g1 = color1.g; g2 = color2.g;
+ b1 = color1.b; b2 = color2.b;
}
- else if (eventId == "VIT-")
+ else
{
- player_node->lowerAttribute(LocalPlayer::VIT);
+ gcn::Color color1 = guiPalette->getColor(Palette::HPBAR_FULL);
+ gcn::Color color2 = guiPalette->getColor(Palette::HPBAR_FULL);
+ r1 = color1.r; r2 = color2.r;
+ g1 = color1.g; g2 = color2.g;
+ b1 = color1.b; b2 = color2.b;
}
- else if (eventId == "INT-")
+
+ // Safety checks
+ if (weight > 1.0f) weight = 1.0f;
+ if (weight < 0.0f) weight = 0.0f;
+
+ // Do the color blend
+ r1 = (int) weightedAverage(r1, r2,weight);
+ g1 = (int) weightedAverage(g1, g2, weight);
+ b1 = (int) weightedAverage(b1, b2, weight);
+
+ // More safety checks
+ if (r1 > 255) r1 = 255;
+ if (g1 > 255) g1 = 255;
+ if (b1 > 255) b1 = 255;
+
+ bar->setColor(r1, g1, b1);
+
+ bar->setProgress((float) player_node->getHp() / (float) player_node->getMaxHp());
+}
+
+void StatusWindow::updateMPBar(ProgressBar *bar, bool showMax)
+{
+ if (showMax)
+ bar->setText(toString(player_node->getMP()) +
+ "/" + toString(player_node->getMaxMP()));
+ else
+ bar->setText(toString(player_node->getMP()));
+
+#ifdef EATHENA_SUPPORT
+ if (player_node->getAttributeEffective(MATK) <= 0)
+ bar->setColor(100, 100, 100); // grey, to indicate that we lack magic
+ else
+#endif
+ bar->setColor(26, 102, 230); // blue, to indicate that we have magic
+
+ bar->setProgress((float) player_node->getMP() /
+ (float) player_node->getMaxMP());
+}
+
+void StatusWindow::updateProgressBar(ProgressBar *bar, int value, int max,
+ bool percent)
+{
+ if (max == 0)
{
- player_node->lowerAttribute(LocalPlayer::INT);
+ bar->setText(_("Max"));
+ bar->setProgress(1.0);
}
- else if (eventId == "WIL-")
+ else
{
- player_node->lowerAttribute(LocalPlayer::WIL);
+ float progress = (float) value / max;
+
+ if (percent)
+ bar->setText(strprintf("%2.2f", 100 * progress) + "%");
+ else
+ bar->setText(toString(value) + "/" + toString(max));
+
+ bar->setProgress(progress);
}
}
-// WARNING: Duplicated method!
+void StatusWindow::updateXPBar(ProgressBar *bar, bool percent)
+{
+ updateProgressBar(bar, player_node->getExp(), player_node->getExpNeeded(),
+ percent);
+}
-void StatusWindow::updateHPBar(ProgressBar *bar, bool showMax)
+void StatusWindow::updateProgressBar(ProgressBar *bar, int id, bool percent)
{
- if (showMax)
- bar->setText(toString(player_node->getHp()) +
- "/" + toString(player_node->getMaxHp()));
- else
- bar->setText(toString(player_node->getHp()));
+ std::pair<int, int> exp = player_node->getExperience(id);
+ updateProgressBar(bar, exp.first, exp.second, percent);
+}
- // HP Bar coloration
- if (player_node->getHp() < player_node->getMaxHp() / 3)
- {
- bar->setColor(223, 32, 32); // Red
- }
- else if (player_node->getHp() < (player_node->getMaxHp() / 3) * 2)
+AttrDisplay::AttrDisplay(int id, const std::string &name):
+ mId(id),
+ mName(name)
+{
+ setSize(100, 32);
+ mLabel = new Label(name);
+ mValue = new Label("1");
+
+ mLabel->setAlignment(Graphics::CENTER);
+ mValue->setAlignment(Graphics::CENTER);
+
+ mLayout = new LayoutHelper(this);
+};
+
+std::string AttrDisplay::update()
+{
+ int base = player_node->getAttributeBase(mId);
+ int bonus = player_node->getAttributeEffective(mId) - base;
+ std::string value = toString(base);
+ if (bonus)
+ value += strprintf(" (%+d)", bonus);
+ mValue->setCaption(value);
+ mValue->adjustSize();
+
+ return mName;
+}
+
+DerDisplay::DerDisplay(int id, const std::string &name):
+ AttrDisplay(id, name)
+{
+ // Do the layout
+ LayoutHelper h(this);
+ ContainerPlacer place = mLayout->getPlacer(0, 0);
+
+ place(0, 0, mLabel, 3);
+ place(3, 0, mValue, 2);
+
+ update();
+};
+
+ChangeDisplay::ChangeDisplay(int id, const std::string &name):
+ AttrDisplay(id, name), mNeeded(1)
+{
+ mPoints = new Label("1");
+ mDec = new Button("-", "-", this);
+ mInc = new Button("+", "+", this);
+ mDec->setWidth(mInc->getWidth());
+
+ // Do the layout
+ ContainerPlacer place = mLayout->getPlacer(0, 0);
+
+ place(0, 0, mLabel, 3);
+ place(3, 0, mDec);
+ place(4, 0, mValue, 2);
+ place(6, 0, mInc);
+ place(7, 0, mPoints);
+
+ update();
+};
+
+std::string ChangeDisplay::update()
+{
+ mPoints->setCaption(toString(mNeeded));
+
+ mDec->setEnabled(player_node->getCorrectionPoints());
+ mInc->setEnabled(player_node->getCharacterPoints() >= mNeeded);
+
+ return AttrDisplay::update();
+}
+
+void ChangeDisplay::setPointsNeeded(int needed)
+{
+ mNeeded = needed;
+
+ update();
+}
+
+void ChangeDisplay::action(const gcn::ActionEvent &event)
+{
+ if (event.getSource() == mDec)
{
- bar->setColor(230, 171, 34); // Orange
+ Net::getPlayerHandler()->decreaseAttribute(mId);
}
- else
+ else if (event.getSource() == mInc)
{
- bar->setColor(0, 171, 34); // Green
+ Net::getPlayerHandler()->increaseAttribute(mId);
}
-
- bar->setProgress((float) player_node->getHp() / (float) player_node->getMaxHp());
}
diff --git a/src/gui/statuswindow.h b/src/gui/statuswindow.h
index b7623806..79382cd5 100644
--- a/src/gui/statuswindow.h
+++ b/src/gui/statuswindow.h
@@ -28,72 +28,71 @@
#include <guichan/actionlistener.hpp>
-class LocalPlayer;
+#include <map>
+
+class AttrDisplay;
class ProgressBar;
+class ScrollArea;
+class VertContainer;
/**
* The player status dialog.
*
* \ingroup Interface
*/
-class StatusWindow : public Window, public gcn::ActionListener
+class StatusWindow : public Window
{
public:
+ enum { // Some update constants
+ HP = -1,
+ MP = -2,
+ EXP = -3,
+ MONEY = -4,
+ CHAR_POINTS = -5,
+ LEVEL = -6
+ };
+
/**
* Constructor.
*/
StatusWindow();
- /**
- * Called when receiving actions from widget.
- */
- void action(const gcn::ActionEvent &event);
-
- /**
- * Updates this dialog with values from PLAYER_INFO *char_info
- */
- void update();
+ std::string update(int id);
- void update(int id);
+ void setPointsNeeded(int id, int needed);
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);
+ static void updateProgressBar(ProgressBar *bar, int value, int max,
+ bool percent);
+ static void updateProgressBar(ProgressBar *bar, int id,
+ bool percent = true);
private:
/**
* Status Part
*/
- gcn::Label *mLvlLabel, *mMoneyLabel, *mHpLabel, *mHpValueLabel;
- ProgressBar *mHpBar;
+ gcn::Label *mLvlLabel, *mMoneyLabel;
+ gcn::Label *mHpLabel, *mMpLabel, *mXpLabel;
+ ProgressBar *mHpBar, *mMpBar, *mXpBar;
- /**
- * 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;
-*/
- /**
- * Stats captions.
- */
- gcn::Label *mStatsLabel[6];
- gcn::Label *mStatsDisplayLabel[6];
- gcn::Label *mCharacterPointsLabel;
- gcn::Label *mCorrectionPointsLabel;
+#ifdef EATHENA_SUPPORT
+ gcn::Label *mJobLvlLabel, *mJobLabel;
+ ProgressBar *mJobBar;
+#endif
- /**
- * Stats buttons.
- */
- gcn::Button *mStatsPlus[6];
- gcn::Button *mStatsMinus[6];
+ VertContainer *mAttrCont;
+ ScrollArea *mAttrScroll;
+ VertContainer *mDAttrCont;
+ ScrollArea *mDAttrScroll;
+
+ gcn::Label *mCharacterPointsLabel, *mCorrectionPointsLabel;
+
+ typedef std::map<int, AttrDisplay*> Attrs;
+ Attrs mAttrs;
};
extern StatusWindow *statusWindow;
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index 970204d0..cba27569 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -40,12 +40,8 @@
#include "gui/ministatus.h"
#include "gui/palette.h"
#include "gui/skilldialog.h"
-#include "gui/storagewindow.h"
-#ifdef TMWSERV_SUPPORT
#include "gui/statuswindow.h"
-#else
-#include "gui/status.h"
-#endif
+#include "gui/storagewindow.h"
#include "gui/widgets/chattab.h"
@@ -83,17 +79,9 @@ const short walkingKeyboardDelay = 40;
LocalPlayer *player_node = NULL;
-#ifdef TMWSERV_SUPPORT
-LocalPlayer::LocalPlayer():
- Player(65535, 0, NULL),
-#else
LocalPlayer::LocalPlayer(int id, int job, Map *map):
Player(id, job, map),
- mCharId(0),
- mJobXp(0),
- mJobLevel(0),
- mXpForNextLevel(0), mJobXpForNextLevel(0),
- mMp(0), mMaxMp(0),
+#ifdef EATHENA_SUPPORT
mAttackRange(0),
#endif
mEquipment(new Equipment),
@@ -102,10 +90,11 @@ LocalPlayer::LocalPlayer(int id, int job, Map *map):
mTargetTime(-1),
#endif
mLastTarget(-1),
- mCharacterPoints(-1),
- mCorrectionPoints(-1),
- mLevelProgress(0),
+ mCharacterPoints(0),
+ mCorrectionPoints(0),
mLevel(1),
+ mExp(0), mExpNeeded(0),
+ mMp(0), mMaxMp(0),
mMoney(0),
mTotalWeight(1), mMaxWeight(1),
mHp(1), mMaxHp(1),
@@ -816,6 +805,22 @@ void LocalPlayer::setAttributeEffective(int num, int value)
statusWindow->update(num);
}
+void LocalPlayer::setCharacterPoints(int n)
+{
+ mCharacterPoints = n;
+
+ if (statusWindow)
+ statusWindow->update(StatusWindow::CHAR_POINTS);
+}
+
+void LocalPlayer::setCorrectionPoints(int n)
+{
+ mCorrectionPoints = n;
+
+ if (statusWindow)
+ statusWindow->update(StatusWindow::CHAR_POINTS);
+}
+
void LocalPlayer::setSkillPoints(int points)
{
mSkillPoints = points;
@@ -846,16 +851,64 @@ std::pair<int, int> LocalPlayer::getExperience(int skill)
return mSkillExp[skill];
}
-void LocalPlayer::setLevelProgress(int percent)
+void LocalPlayer::setHp(int value)
+{
+ mHp = value;
+
+ if (statusWindow)
+ statusWindow->update(StatusWindow::HP);
+}
+
+void LocalPlayer::setMaxHp(int value)
{
- if (mMap && percent > mLevelProgress)
+ mMaxHp = value;
+
+ if (statusWindow)
+ statusWindow->update(StatusWindow::HP);
+}
+
+void LocalPlayer::setLevel(int value)
+{
+ mLevel = value;
+
+ if (statusWindow)
+ statusWindow->update(StatusWindow::LEVEL);
+}
+
+void LocalPlayer::setExp(int value)
+{
+ if (mMap && value > mExp)
{
- addMessageToQueue(toString(percent - mLevelProgress) + " xp");
+ addMessageToQueue(toString(value - mExp) + " xp");
}
- mLevelProgress = percent;
+ mExp = value;
+
+ if (statusWindow)
+ statusWindow->update(StatusWindow::EXP);
+}
+
+void LocalPlayer::setExpNeeded(int value)
+{
+ mExpNeeded = value;
+
+ if (statusWindow)
+ statusWindow->update(StatusWindow::EXP);
+}
+
+int LocalPlayer::setMP(int value)
+{
+ mMp = value;
+
+ if (statusWindow)
+ statusWindow->update(StatusWindow::MP);
+}
+
+int LocalPlayer::setMaxMP(int value)
+{
+ mMaxMp = value;
if (statusWindow)
- statusWindow->update();
+ statusWindow->update(StatusWindow::MP);
}
void LocalPlayer::pickedUp(const ItemInfo &itemInfo, int amount)
diff --git a/src/localplayer.h b/src/localplayer.h
index 4bcd43a3..1c57abaf 100644
--- a/src/localplayer.h
+++ b/src/localplayer.h
@@ -102,11 +102,7 @@ class LocalPlayer : public Player
/**
* Constructor.
*/
-#ifdef TMWSERV_SUPPORT
- LocalPlayer();
-#else
- LocalPlayer(int id, int job, Map *map);
-#endif
+ LocalPlayer(int id= 65535, int job = 0, Map *map = NULL);
/**
* Destructor.
@@ -272,13 +268,6 @@ class LocalPlayer : public Player
void setInStorage(bool inStorage);
#ifdef EATHENA_SUPPORT
- Uint32 mCharId; /**< Used only during character selection. */
-
- Uint32 mJobXp;
- Uint32 mJobLevel;
- Uint32 mXpForNextLevel, mJobXpForNextLevel;
- Uint16 mMp, mMaxMp;
-
Uint16 mAttackRange;
#endif
@@ -288,22 +277,34 @@ class LocalPlayer : public Player
int getMaxHp() const
{ return mMaxHp; }
- void setHp(int value)
- { mHp = value; }
+ void setHp(int value);
- void setMaxHp(int value)
- { mMaxHp = value; }
+ void setMaxHp(int value);
int getLevel() const
{ return mLevel; }
- void setLevel(int value)
- { mLevel = value; }
+ void setLevel(int value);
+
+ void setExp(int value);
+
+ int getExp() const
+ { return mExp, mExpNeeded; }
+
+ void setExpNeeded(int value);
+
+ int getExpNeeded() const
+ { return mExpNeeded; }
+
+ int setMP(int value);
+
+ int getMP() const
+ { return mMp; }
- void setLevelProgress(int percent);
+ int setMaxMP(int value);
- int getLevelProgress() const
- { return mLevelProgress; }
+ int getMaxMP() const
+ { return mMaxMp; }
int getMoney() const
{ return mMoney; }
@@ -336,14 +337,12 @@ class LocalPlayer : public Player
int getCharacterPoints() const
{ return mCharacterPoints; }
- void setCharacterPoints(int n)
- { mCharacterPoints = n; }
+ void setCharacterPoints(int n);
int getCorrectionPoints() const
{ return mCorrectionPoints; }
- void setCorrectionPoints(int n)
- { mCorrectionPoints = n; }
+ void setCorrectionPoints(int n);
int getSkillPoints() const
{ return mSkillPoints; }
@@ -380,8 +379,9 @@ class LocalPlayer : public Player
std::map<int, std::pair<int, int> > mSkillExp;
int mCharacterPoints;
int mCorrectionPoints;
- int mLevelProgress;
int mLevel;
+ int mExp, mExpNeeded;
+ int mMp, mMaxMp;
int mMoney;
int mTotalWeight;
int mMaxWeight;
diff --git a/src/net/ea/charserverhandler.cpp b/src/net/ea/charserverhandler.cpp
index a09f11f9..d8429d5e 100644
--- a/src/net/ea/charserverhandler.cpp
+++ b/src/net/ea/charserverhandler.cpp
@@ -169,14 +169,13 @@ void CharServerHandler::handleMessage(MessageIn &msg)
LocalPlayer *CharServerHandler::readPlayerData(MessageIn &msg, int &slot)
{
- LocalPlayer *tempPlayer = new LocalPlayer(mLoginData->account_ID, 0, NULL);
+ LocalPlayer *tempPlayer = new LocalPlayer(msg.readInt32(), 0, NULL);
tempPlayer->setGender(mLoginData->sex);
- tempPlayer->mCharId = msg.readInt32();
- tempPlayer->setLevelProgress(msg.readInt32());
+ tempPlayer->setExp(msg.readInt32());
tempPlayer->setMoney(msg.readInt32());
- tempPlayer->mJobXp = msg.readInt32();
- tempPlayer->mJobLevel = msg.readInt32();
+ tempPlayer->setExperience(JOB, msg.readInt32(), 1);
+ tempPlayer->setAttributeBase(JOB, msg.readInt32());
tempPlayer->setSprite(Being::SHOE_SPRITE, msg.readInt16());
tempPlayer->setSprite(Being::GLOVES_SPRITE, msg.readInt16());
tempPlayer->setSprite(Being::CAPE_SPRITE, msg.readInt16());
@@ -187,8 +186,8 @@ LocalPlayer *CharServerHandler::readPlayerData(MessageIn &msg, int &slot)
msg.skip(2); // unknown
tempPlayer->setHp(msg.readInt16());
tempPlayer->setMaxHp(msg.readInt16());
- tempPlayer->mMp = msg.readInt16();
- tempPlayer->mMaxMp = msg.readInt16();
+ tempPlayer->setMP(msg.readInt16());
+ tempPlayer->setMaxMP(msg.readInt16());
msg.readInt16(); // speed
msg.readInt16(); // class
int hairStyle = msg.readInt16();
@@ -272,7 +271,7 @@ void CharServerHandler::newCharacter(const std::string &name, int slot,
void CharServerHandler::deleteCharacter(int slot, LocalPlayer* character)
{
MessageOut outMsg(CMSG_CHAR_DELETE);
- outMsg.writeInt32(character->mCharId);
+ outMsg.writeInt32(character->getId());
outMsg.writeString("a@a.com", 40);
}
diff --git a/src/net/ea/generalhandler.cpp b/src/net/ea/generalhandler.cpp
index bbadd44f..06481824 100644
--- a/src/net/ea/generalhandler.cpp
+++ b/src/net/ea/generalhandler.cpp
@@ -23,7 +23,7 @@
#include "gui/inventorywindow.h"
#include "gui/skilldialog.h"
-#include "gui/status.h"
+#include "gui/statuswindow.h"
#include "net/ea/network.h"
#include "net/ea/protocol.h"
@@ -205,7 +205,7 @@ void GeneralHandler::guiWindowsLoaded()
inventoryWindow->setSplitAllowed(false);
skillDialog->loadSkills("ea-skills.xml");
- /*statusWindow->addAttribute(STR, _("Strength"), true);
+ statusWindow->addAttribute(STR, _("Strength"), true);
statusWindow->addAttribute(AGI, _("Agility"), true);
statusWindow->addAttribute(VIT, _("Vitality"), true);
statusWindow->addAttribute(INT, _("Intelligence"), true);
@@ -217,7 +217,7 @@ void GeneralHandler::guiWindowsLoaded()
statusWindow->addAttribute(MATK, _("M.Attack"), false);
statusWindow->addAttribute(MDEF, _("M.Defense"), false);
statusWindow->addAttribute(HIT, _("% Accuracy"), false);
- statusWindow->addAttribute(FLEE, _("% Evade"), false);*/
+ statusWindow->addAttribute(FLEE, _("% Evade"), false);
}
void GeneralHandler::guiWindowsUnloaded()
diff --git a/src/net/ea/maphandler.cpp b/src/net/ea/maphandler.cpp
index 6f8a9827..a466e022 100644
--- a/src/net/ea/maphandler.cpp
+++ b/src/net/ea/maphandler.cpp
@@ -82,16 +82,21 @@ void MapHandler::handleMessage(MessageIn &msg)
}
}
+#include <fstream>
+
void MapHandler::connect(LoginData *loginData)
{
// Send login infos
MessageOut outMsg(CMSG_MAP_SERVER_CONNECT);
outMsg.writeInt32(loginData->account_ID);
- outMsg.writeInt32(player_node->mCharId);
+ outMsg.writeInt32(player_node->getId());
outMsg.writeInt32(loginData->session_ID1);
outMsg.writeInt32(loginData->session_ID2);
outMsg.writeInt8((loginData->sex == GENDER_MALE) ? 1 : 0);
+ // Change the player's ID to the account ID to match what eAthena uses
+ player_node->setId(loginData->account_ID);
+
// We get 4 useless bytes before the real answer comes in (what are these?)
mNetwork->skip(4);
}
diff --git a/src/net/ea/playerhandler.cpp b/src/net/ea/playerhandler.cpp
index c2a1ecf1..60c7e2c1 100644
--- a/src/net/ea/playerhandler.cpp
+++ b/src/net/ea/playerhandler.cpp
@@ -37,6 +37,7 @@
#include "gui/gui.h"
#include "gui/okdialog.h"
#include "gui/sell.h"
+#include "gui/statuswindow.h"
#include "gui/storagewindow.h"
#include "gui/viewport.h"
@@ -229,8 +230,8 @@ void PlayerHandler::handleMessage(MessageIn &msg)
case 0x0004: break; // manner
case 0x0005: player_node->setHp(value); break;
case 0x0006: player_node->setMaxHp(value); break;
- case 0x0007: player_node->mMp = value; break;
- case 0x0008: player_node->mMaxMp = value; break;
+ case 0x0007: player_node->setMP(value); break;
+ case 0x0008: player_node->setMaxMP(value); break;
case 0x0009: player_node->setCharacterPoints(value); break;
case 0x000b: player_node->setLevel(value); break;
case 0x000c: player_node->setSkillPoints(value); break;
@@ -288,7 +289,8 @@ void PlayerHandler::handleMessage(MessageIn &msg)
player_node->setAttributeEffective(CRIT, value); break;
case 0x0035: player_node->mAttackSpeed = value; break;
- case 0x0037: player_node->mJobLevel = value; break;
+ case 0x0037:
+ player_node->setAttributeBase(JOB, value); break;
case 500: player_node->setGMLevel(value); break;
}
@@ -305,10 +307,11 @@ void PlayerHandler::handleMessage(MessageIn &msg)
case SMSG_PLAYER_STAT_UPDATE_2:
switch (msg.readInt16()) {
case 0x0001:
- player_node->setLevelProgress(msg.readInt32());
+ player_node->setExp(msg.readInt32());
break;
case 0x0002:
- player_node->mJobXp = msg.readInt32();
+ player_node->setExperience(JOB, msg.readInt32(),
+ player_node->getExperience(JOB).second);
break;
case 0x0014: {
int curGp = player_node->getMoney();
@@ -320,10 +323,12 @@ void PlayerHandler::handleMessage(MessageIn &msg)
}
break;
case 0x0016:
- player_node->mXpForNextLevel = msg.readInt32();
+ player_node->setExpNeeded(msg.readInt32());
break;
case 0x0017:
- player_node->mJobXpForNextLevel = msg.readInt32();
+ player_node->setExperience(JOB,
+ player_node->getExperience(JOB).first,
+ msg.readInt32());
break;
}
break;
@@ -363,32 +368,32 @@ void PlayerHandler::handleMessage(MessageIn &msg)
int val = msg.readInt8();
player_node->setAttributeEffective(STR, val + ATTR_BONUS(STR));
player_node->setAttributeBase(STR, val);
- player_node->setAttributeBase(STR, msg.readInt8());
+ statusWindow->setPointsNeeded(STR, msg.readInt8());
val = msg.readInt8();
player_node->setAttributeEffective(AGI, val + ATTR_BONUS(AGI));
player_node->setAttributeBase(AGI, val);
- player_node->setAttributeBase(AGI_U, msg.readInt8());
+ statusWindow->setPointsNeeded(AGI, msg.readInt8());
val = msg.readInt8();
player_node->setAttributeEffective(VIT, val + ATTR_BONUS(VIT));
player_node->setAttributeBase(VIT, val);
- player_node->setAttributeBase(VIT_U, msg.readInt8());
+ statusWindow->setPointsNeeded(VIT, msg.readInt8());
val = msg.readInt8();
player_node->setAttributeEffective(INT, val + ATTR_BONUS(INT));
player_node->setAttributeBase(INT, val);
- player_node->setAttributeBase(INT_U, msg.readInt8());
+ statusWindow->setPointsNeeded(INT, msg.readInt8());
val = msg.readInt8();
player_node->setAttributeEffective(DEX, val + ATTR_BONUS(DEX));
player_node->setAttributeBase(DEX, val);
- player_node->setAttributeBase(DEX_U, msg.readInt8());
+ statusWindow->setPointsNeeded(DEX, msg.readInt8());
val = msg.readInt8();
player_node->setAttributeEffective(LUK, val + ATTR_BONUS(LUK));
player_node->setAttributeBase(LUK, val);
- player_node->setAttributeBase(LUK_U, msg.readInt8());
+ statusWindow->setPointsNeeded(LUK, msg.readInt8());
val = msg.readInt16(); // ATK
player_node->setAttributeBase(ATK, val);
@@ -430,22 +435,22 @@ void PlayerHandler::handleMessage(MessageIn &msg)
case SMSG_PLAYER_STAT_UPDATE_6:
switch (msg.readInt16()) {
case 0x0020:
- player_node->setAttributeBase(STR_U, msg.readInt8());
+ statusWindow->setPointsNeeded(STR, msg.readInt8());
break;
case 0x0021:
- player_node->setAttributeBase(AGI_U, msg.readInt8());
+ statusWindow->setPointsNeeded(AGI, msg.readInt8());
break;
case 0x0022:
- player_node->setAttributeBase(VIT_U, msg.readInt8());
+ statusWindow->setPointsNeeded(VIT, msg.readInt8());
break;
case 0x0023:
- player_node->setAttributeBase(INT_U, msg.readInt8());
+ statusWindow->setPointsNeeded(INT, msg.readInt8());
break;
case 0x0024:
- player_node->setAttributeBase(DEX_U, msg.readInt8());
+ statusWindow->setPointsNeeded(DEX, msg.readInt8());
break;
case 0x0025:
- player_node->setAttributeBase(LUK_U, msg.readInt8());
+ statusWindow->setPointsNeeded(LUK, msg.readInt8());
break;
}
break;
diff --git a/src/net/ea/protocol.h b/src/net/ea/protocol.h
index 268c8c67..279e4c2f 100644
--- a/src/net/ea/protocol.h
+++ b/src/net/ea/protocol.h
@@ -23,6 +23,8 @@
#define EA_PROTOCOL_H
enum {
+ JOB = 0xa,
+
STR = 0xd,
AGI,
VIT,
@@ -30,13 +32,6 @@ enum {
DEX,
LUK,
- STR_U,
- AGI_U,
- VIT_U,
- INT_U,
- DEX_U,
- LUK_U,
-
ATK,
DEF,
MATK,
diff --git a/src/net/tmwserv/generalhandler.cpp b/src/net/tmwserv/generalhandler.cpp
index c04df973..d643586b 100644
--- a/src/net/tmwserv/generalhandler.cpp
+++ b/src/net/tmwserv/generalhandler.cpp
@@ -150,12 +150,14 @@ void GeneralHandler::guiWindowsLoaded()
partyWindow->clearPartyName();
skillDialog->loadSkills("tmw-skills.xml");
- /*statusWindow->addAttribute(16, _("Strength"), true);
+ player_node->setExpNeeded(100);
+
+ statusWindow->addAttribute(16, _("Strength"), true);
statusWindow->addAttribute(17, _("Agility"), true);
statusWindow->addAttribute(18, _("Dexterity"), true);
statusWindow->addAttribute(19, _("Vitality"), true);
statusWindow->addAttribute(20, _("Intelligence"), true);
- statusWindow->addAttribute(21, _("Willpower"), true);*/
+ statusWindow->addAttribute(21, _("Willpower"), true);
}
void GeneralHandler::guiWindowsUnloaded()
diff --git a/src/net/tmwserv/playerhandler.cpp b/src/net/tmwserv/playerhandler.cpp
index 413fbeaf..91b6dd8a 100644
--- a/src/net/tmwserv/playerhandler.cpp
+++ b/src/net/tmwserv/playerhandler.cpp
@@ -176,7 +176,7 @@ void PlayerHandler::handleMessage(MessageIn &msg)
case GPMSG_LEVEL_PROGRESS:
{
logger->log("Level Progress Update");
- player_node->setLevelProgress(msg.readInt8());
+ player_node->setExp(msg.readInt8());
} break;
diff --git a/tmw.cbp b/tmw.cbp
index a0616ec0..ba1e0dad 100644
--- a/tmw.cbp
+++ b/tmw.cbp
@@ -355,22 +355,8 @@
<Unit filename="src/gui/skin.h" />
<Unit filename="src/gui/speechbubble.cpp" />
<Unit filename="src/gui/speechbubble.h" />
- <Unit filename="src/gui/status.cpp">
- <Option target="eAthena" />
- <Option target="UNIX eAthena" />
- </Unit>
- <Unit filename="src/gui/status.h">
- <Option target="eAthena" />
- <Option target="UNIX eAthena" />
- </Unit>
- <Unit filename="src/gui/statuswindow.cpp">
- <Option target="TMWServ" />
- <Option target="Unix TMWSERV" />
- </Unit>
- <Unit filename="src/gui/statuswindow.h">
- <Option target="TMWServ" />
- <Option target="Unix TMWSERV" />
- </Unit>
+ <Unit filename="src/gui/statuswindow.cpp" />
+ <Unit filename="src/gui/statuswindow.h" />
<Unit filename="src/gui/storagewindow.cpp" />
<Unit filename="src/gui/storagewindow.h" />
<Unit filename="src/gui/table.cpp" />