summaryrefslogtreecommitdiff
path: root/src
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
parent4408659ea0f7c25e1d73718576822b562a29d0b4 (diff)
downloadmana-3c214ff26a33555e3744608d7047286eb9eb5780.tar.gz
mana-3c214ff26a33555e3744608d7047286eb9eb5780.tar.bz2
mana-3c214ff26a33555e3744608d7047286eb9eb5780.tar.xz
mana-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')
-rw-r--r--src/being.cpp3
-rw-r--r--src/being.h2
-rw-r--r--src/floor_item.h10
-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
-rw-r--r--src/main.cpp33
-rw-r--r--src/player.h8
-rw-r--r--src/sprite.h2
12 files changed, 78 insertions, 104 deletions
diff --git a/src/being.cpp b/src/being.cpp
index e6077d35..b3cb9906 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -63,6 +63,7 @@ Being::Being(Uint32 id, Uint16 job, Map *map):
mSpeechTime(0),
mDamageTime(0),
mShowSpeech(false), mShowDamage(false),
+ mPx(0), mPy(0),
mSprites(VECTOREND_SPRITE, NULL),
mEquipmentSpriteIDs(VECTOREND_SPRITE, 0)
{
@@ -331,7 +332,7 @@ Being::logic()
}
void
-Being::draw(Graphics *graphics, int offsetX, int offsetY)
+Being::draw(Graphics *graphics, int offsetX, int offsetY) const
{
int px = mPx + offsetX;
int py = mPy + offsetY;
diff --git a/src/being.h b/src/being.h
index 80b07e87..65b501d6 100644
--- a/src/being.h
+++ b/src/being.h
@@ -307,7 +307,7 @@ class Being : public Sprite
* @see Sprite::draw(Graphics, int, int)
*/
virtual void
- draw(Graphics *graphics, Sint32 offsetX, Sint32 offsetY);
+ draw(Graphics *graphics, Sint32 offsetX, Sint32 offsetY) const;
/**
* Returns the pixel X coordinate.
diff --git a/src/floor_item.h b/src/floor_item.h
index 386d0759..36f81585 100644
--- a/src/floor_item.h
+++ b/src/floor_item.h
@@ -53,25 +53,25 @@ class FloorItem : public Sprite
* Returns instance id of this item.
*/
unsigned int
- getId() { return mId; }
+ getId() const { return mId; }
/**
* Returns the item id.
*/
unsigned int
- getItemId() { return mItemId; }
+ getItemId() const { return mItemId; }
/**
* Returns the x coordinate.
*/
unsigned short
- getX() { return mX; }
+ getX() const { return mX; }
/**
* Returns the y coordinate.
*/
unsigned short
- getY() { return mY; }
+ getY() const { return mY; }
/**
* Returns the pixel y coordinate.
@@ -87,7 +87,7 @@ class FloorItem : public Sprite
* @see Sprite::draw(Graphics, int, int)
*/
void
- draw(Graphics *graphics, int offsetX, int offsetY)
+ draw(Graphics *graphics, int offsetX, int offsetY) const
{
graphics->drawImage(mImage,
mX * 32 + offsetX,
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.
*
diff --git a/src/main.cpp b/src/main.cpp
index 6f34e0b8..eebb92bb 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -84,8 +84,6 @@
// Account infos
char n_server, n_character;
-std::vector<Spriteset *> hairset;
-Spriteset *playerset[2];
Graphics *graphics;
// TODO Anyone knows a good location for this? Or a way to make it non-global?
@@ -272,26 +270,6 @@ void init_engine(const Options &options)
// Initialize for drawing
graphics->_beginDraw();
- playerset[0] = resman->getSpriteset(
- "graphics/sprites/player_male_base.png", 64, 64);
- if (!playerset[0]) logger->error("Couldn't load male player spriteset!");
- playerset[1] = resman->getSpriteset(
- "graphics/sprites/player_female_base.png", 64, 64);
- if (!playerset[1]) logger->error("Couldn't load female player spriteset!");
-
-
- for (int i=0; i < NR_HAIR_STYLES; i++)
- {
- Spriteset *tmp = ResourceManager::getInstance()->getSpriteset(
- "graphics/sprites/hairstyle" + toString(i + 1) + ".png",
- 40, 40);
- if (!tmp) {
- logger->error("Unable to load hairstyle");
- } else {
- hairset.push_back(tmp);
- }
- }
-
gui = new Gui(graphics);
state = UPDATE_STATE; /**< Initial game state */
@@ -300,8 +278,8 @@ void init_engine(const Options &options)
if (config.getValue("sound", 0) == 1) {
sound.init();
}
- sound.setSfxVolume((int)config.getValue("sfxVolume", 100));
- sound.setMusicVolume((int)config.getValue("musicVolume", 60));
+ sound.setSfxVolume((int) config.getValue("sfxVolume", 100));
+ sound.setMusicVolume((int) config.getValue("musicVolume", 60));
}
catch (const char *err) {
state = ERROR_STATE;
@@ -322,13 +300,6 @@ void exit_engine()
delete gui;
delete graphics;
- std::for_each(hairset.begin(), hairset.end(),
- std::mem_fun(&Spriteset::decRef));
- hairset.clear();
-
- playerset[0]->decRef();
- playerset[1]->decRef();
-
// Shutdown libxml
xmlCleanupParser();
diff --git a/src/player.h b/src/player.h
index d666a485..4a9bed08 100644
--- a/src/player.h
+++ b/src/player.h
@@ -26,12 +26,14 @@
#include "being.h"
-#include <string>
-
class Graphics;
class Map;
-class AnimatedSprite;
+/**
+ * A player being. Players have their name drawn beneath them. This class also
+ * implements player-specific loading of base sprite, hair sprite and equipment
+ * sprites.
+ */
class Player : public Being
{
public:
diff --git a/src/sprite.h b/src/sprite.h
index 282091cc..51811149 100644
--- a/src/sprite.h
+++ b/src/sprite.h
@@ -47,7 +47,7 @@ class Sprite
* partly with the clipping rectangle support.
*/
virtual void
- draw(Graphics *graphics, int offsetX, int offsetY) = 0;
+ draw(Graphics *graphics, int offsetX, int offsetY) const = 0;
/**
* Returns the pixel Y coordinate of the sprite.