summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2006-12-09 01:44:18 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2006-12-09 01:44:18 +0000
commit3c214ff26a33555e3744608d7047286eb9eb5780 (patch)
tree46f5dce9cee082509cfa588b4cf93e7eb937e931 /src/gui
parent4408659ea0f7c25e1d73718576822b562a29d0b4 (diff)
downloadmana-client-3c214ff26a33555e3744608d7047286eb9eb5780.tar.gz
mana-client-3c214ff26a33555e3744608d7047286eb9eb5780.tar.bz2
mana-client-3c214ff26a33555e3744608d7047286eb9eb5780.tar.xz
mana-client-3c214ff26a33555e3744608d7047286eb9eb5780.zip
Use new animation system in character selection/creation. Shows equipment and
allowed for some cleanup. Had a bit of help from the patch by VictorSan.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/char_select.cpp47
-rw-r--r--src/gui/char_select.h11
-rw-r--r--src/gui/passwordfield.h4
-rw-r--r--src/gui/playerbox.cpp37
-rw-r--r--src/gui/playerbox.h24
-rw-r--r--src/gui/textfield.h1
6 files changed, 62 insertions, 62 deletions
diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp
index d91019e3..604d7244 100644
--- a/src/gui/char_select.cpp
+++ b/src/gui/char_select.cpp
@@ -86,7 +86,7 @@ CharSelectDialog::CharSelectDialog(Network *network,
mLevelLabel = new gcn::Label("Level");
mJobLevelLabel = new gcn::Label("Job Level");
mMoneyLabel = new gcn::Label("Money");
- mPlayerBox = new PlayerBox(sex);
+ mPlayerBox = new PlayerBox();
int w = 195;
int h = 220;
@@ -176,7 +176,8 @@ void CharSelectDialog::updatePlayerInfo()
{
LocalPlayer *pi = mCharInfo->getEntry();
- if (pi) {
+ if (pi)
+ {
mNameLabel->setCaption(pi->getName());
mLevelLabel->setCaption("Lvl: " + toString(pi->mLevel));
mJobLevelLabel->setCaption("Job Lvl: " + toString(pi->mJobLevel));
@@ -187,10 +188,8 @@ void CharSelectDialog::updatePlayerInfo()
mDelCharButton->setEnabled(true);
mSelectButton->setEnabled(true);
}
- mPlayerBox->mHairStyle = pi->getHairStyle() - 1;
- mPlayerBox->mHairColor = pi->getHairColor() - 1;
- mPlayerBox->mShowPlayer = true;
- } else {
+ }
+ else {
mNameLabel->setCaption("Name");
mLevelLabel->setCaption("Level");
mJobLevelLabel->setCaption("Job Level");
@@ -198,11 +197,9 @@ void CharSelectDialog::updatePlayerInfo()
mNewCharButton->setEnabled(true);
mDelCharButton->setEnabled(false);
mSelectButton->setEnabled(false);
-
- mPlayerBox->mHairStyle = 0;
- mPlayerBox->mHairColor = 0;
- mPlayerBox->mShowPlayer = false;
}
+
+ mPlayerBox->setPlayer(pi);
}
void CharSelectDialog::attemptCharDelete()
@@ -260,6 +257,11 @@ CharCreateDialog::CharCreateDialog(Window *parent, int slot, Network *network,
unsigned char sex):
Window("Create Character", true, parent), mNetwork(network), mSlot(slot)
{
+ mPlayer = new Player(0, 0, NULL);
+ mPlayer->setSex(sex);
+ mPlayer->setHairStyle(rand() % NR_HAIR_STYLES + 1);
+ mPlayer->setHairColor(rand() % NR_HAIR_COLORS + 1);
+
mNameField = new TextField("");
mNameLabel = new gcn::Label("Name:");
mNextHairColorButton = new Button(">", "nextcolor", this);
@@ -270,8 +272,7 @@ CharCreateDialog::CharCreateDialog(Window *parent, int slot, Network *network,
mHairStyleLabel = new gcn::Label("Hair Style:");
mCreateButton = new Button("Create", "create", this);
mCancelButton = new Button("Cancel", "cancel", this);
- mPlayerBox = new PlayerBox(sex);
- mPlayerBox->mShowPlayer = true;
+ mPlayerBox = new PlayerBox(mPlayer);
mNameField->setEventId("create");
@@ -313,6 +314,11 @@ CharCreateDialog::CharCreateDialog(Window *parent, int slot, Network *network,
setVisible(true);
}
+CharCreateDialog::~CharCreateDialog()
+{
+ delete mPlayer;
+}
+
void CharCreateDialog::action(const std::string& eventId, gcn::Widget* widget)
{
if (eventId == "create") {
@@ -331,20 +337,19 @@ void CharCreateDialog::action(const std::string& eventId, gcn::Widget* widget)
scheduleDelete();
}
else if (eventId == "nextcolor") {
- mPlayerBox->mHairColor++;
+ mPlayer->setHairColor(mPlayer->getHairColor() % NR_HAIR_COLORS + 1);
}
else if (eventId == "prevcolor") {
- mPlayerBox->mHairColor += NR_HAIR_COLORS - 1;
+ int prevColor = mPlayer->getHairColor() + NR_HAIR_COLORS - 2;
+ mPlayer->setHairColor(prevColor % NR_HAIR_COLORS + 1);
}
else if (eventId == "nextstyle") {
- mPlayerBox->mHairStyle++;
+ mPlayer->setHairStyle(mPlayer->getHairStyle() % NR_HAIR_STYLES + 1);
}
else if (eventId == "prevstyle") {
- mPlayerBox->mHairStyle += NR_HAIR_STYLES - 1;
+ int prevStyle = mPlayer->getHairStyle() + NR_HAIR_STYLES - 2;
+ mPlayer->setHairStyle(prevStyle % NR_HAIR_STYLES + 1);
}
-
- mPlayerBox->mHairColor %= NR_HAIR_COLORS;
- mPlayerBox->mHairStyle %= NR_HAIR_STYLES;
}
std::string CharCreateDialog::getName()
@@ -365,6 +370,6 @@ void CharCreateDialog::attemptCharCreate()
outMsg.writeInt8(5);
outMsg.writeInt8(5);
outMsg.writeInt8(mSlot);
- outMsg.writeInt16(mPlayerBox->mHairColor + 1);
- outMsg.writeInt16(mPlayerBox->mHairStyle + 1);
+ outMsg.writeInt16(mPlayer->getHairColor());
+ outMsg.writeInt16(mPlayer->getHairStyle());
}
diff --git a/src/gui/char_select.h b/src/gui/char_select.h
index 0a1b5eac..9fc5fabf 100644
--- a/src/gui/char_select.h
+++ b/src/gui/char_select.h
@@ -31,6 +31,7 @@
#include <guichan/actionlistener.hpp>
+class Player;
class LocalPlayer;
class Network;
class PlayerBox;
@@ -51,7 +52,7 @@ class CharSelectDialog : public Window, public gcn::ActionListener
LockedArray<LocalPlayer*> *charInfo,
unsigned char sex);
- void action(const std::string& eventId, gcn::Widget* widget);
+ void action(const std::string &eventId, gcn::Widget *widget);
void updatePlayerInfo();
@@ -110,7 +111,12 @@ class CharCreateDialog : public Window, public gcn::ActionListener
CharCreateDialog(Window *parent, int slot, Network *network,
unsigned char sex);
- void action(const std::string& eventId, gcn::Widget* widget);
+ /**
+ * Destructor.
+ */
+ ~CharCreateDialog();
+
+ void action(const std::string &eventId, gcn::Widget *widget);
std::string getName();
@@ -127,6 +133,7 @@ class CharCreateDialog : public Window, public gcn::ActionListener
gcn::Button *mCreateButton;
gcn::Button *mCancelButton;
+ Player *mPlayer;
PlayerBox *mPlayerBox;
int mSlot;
diff --git a/src/gui/passwordfield.h b/src/gui/passwordfield.h
index 15ca85c9..cae1f92e 100644
--- a/src/gui/passwordfield.h
+++ b/src/gui/passwordfield.h
@@ -21,8 +21,8 @@
* $Id$
*/
-#ifndef __PASSWORDFIELD_H__
-#define __PASSWORDFIELD_H__
+#ifndef _TMW_PASSWORDFIELD_H_
+#define _TMW_PASSWORDFIELD_H_
#include "textfield.h"
diff --git a/src/gui/playerbox.cpp b/src/gui/playerbox.cpp
index 0a155573..907e9a2d 100644
--- a/src/gui/playerbox.cpp
+++ b/src/gui/playerbox.cpp
@@ -23,7 +23,7 @@
#include "playerbox.h"
-#include "../being.h"
+#include "../player.h"
#include "../graphics.h"
#include "../graphic/imagerect.h"
@@ -34,17 +34,11 @@
#include "../utils/dtor.h"
-extern std::vector<Spriteset *> hairset;
-extern Spriteset *playerset[2];
-
int PlayerBox::instances = 0;
ImageRect PlayerBox::background;
-PlayerBox::PlayerBox(unsigned char sex):
- mHairColor(0),
- mHairStyle(0),
- mSex(sex),
- mShowPlayer(false)
+PlayerBox::PlayerBox(const Player *player):
+ mPlayer(player)
{
setBorderSize(2);
@@ -83,29 +77,18 @@ PlayerBox::~PlayerBox()
}
}
-void PlayerBox::draw(gcn::Graphics *graphics)
+void
+PlayerBox::draw(gcn::Graphics *graphics)
{
- if (!mShowPlayer) {
- return;
- }
-
- // Draw character
- dynamic_cast<Graphics*>(graphics)->drawImage(
- playerset[mSex]->get(0), 23, 12);
-
- // Draw his hair
- if (mHairColor >= 0 && mHairStyle >= 0 &&
- mHairColor < NR_HAIR_COLORS && mHairStyle < NR_HAIR_STYLES)
+ if (mPlayer)
{
- int hf = 5 * mHairColor;
- if (hf >= 0 && hf < (int)hairset[mHairStyle]->size()) {
- dynamic_cast<Graphics*>(graphics)->drawImage(
- hairset[mHairStyle]->get(hf), 35, 7);
- }
+ // Draw character
+ mPlayer->draw(dynamic_cast<Graphics*>(graphics), 40, 42);
}
}
-void PlayerBox::drawBorder(gcn::Graphics *graphics)
+void
+PlayerBox::drawBorder(gcn::Graphics *graphics)
{
int w, h, bs;
bs = getBorderSize();
diff --git a/src/gui/playerbox.h b/src/gui/playerbox.h
index 79f7c2aa..6bba1b51 100644
--- a/src/gui/playerbox.h
+++ b/src/gui/playerbox.h
@@ -27,10 +27,10 @@
#include <guichan/widgets/scrollarea.hpp>
class ImageRect;
+class Player;
/**
- * A box showing a player. Draws the various hair styles a player can have
- * currently.
+ * A box showing a player character.
*
* \ingroup GUI
*/
@@ -38,9 +38,10 @@ class PlayerBox : public gcn::ScrollArea
{
public:
/**
- * Constructor.
+ * Constructor. Takes the initial player character that this box should
+ * display, which defaults to <code>NULL</code>.
*/
- PlayerBox(unsigned char sex);
+ PlayerBox(const Player *player = NULL);
/**
* Destructor.
@@ -48,6 +49,14 @@ class PlayerBox : public gcn::ScrollArea
~PlayerBox();
/**
+ * Sets a new player character to be displayed by this box. Setting the
+ * player to <code>NULL</code> causes the box not to draw any
+ * character.
+ */
+ void
+ setPlayer(const Player *player) { mPlayer = player; }
+
+ /**
* Draws the scroll area.
*/
void draw(gcn::Graphics *graphics);
@@ -57,12 +66,9 @@ class PlayerBox : public gcn::ScrollArea
*/
void drawBorder(gcn::Graphics *graphics);
- int mHairColor; /**< The hair color index */
- int mHairStyle; /**< The hair style index */
- unsigned char mSex; /**< Sex */
- bool mShowPlayer; /**< Wether to show the player or not */
-
private:
+ const Player *mPlayer; /**< The character used for display */
+
static int instances;
static ImageRect background;
};
diff --git a/src/gui/textfield.h b/src/gui/textfield.h
index 1ed802d7..4748830c 100644
--- a/src/gui/textfield.h
+++ b/src/gui/textfield.h
@@ -28,7 +28,6 @@
class ImageRect;
-
/**
* A text field.
*