diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/being.cpp | 1 | ||||
-rw-r--r-- | src/gui/chat.cpp | 12 | ||||
-rw-r--r-- | src/gui/setup_video.cpp | 22 | ||||
-rw-r--r-- | src/gui/setup_video.h | 2 | ||||
-rw-r--r-- | src/gui/viewport.cpp | 11 | ||||
-rw-r--r-- | src/localplayer.cpp | 44 | ||||
-rw-r--r-- | src/localplayer.h | 32 | ||||
-rw-r--r-- | src/main.cpp | 1 | ||||
-rw-r--r-- | src/player.cpp | 15 | ||||
-rw-r--r-- | src/player.h | 19 |
10 files changed, 124 insertions, 35 deletions
diff --git a/src/being.cpp b/src/being.cpp index aff52757..ba3107db 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -69,6 +69,7 @@ Being::Being(int id, int job, Map *map): mWalkSpeed(150), mDirection(DOWN), mMap(NULL), + mName(""), mIsGM(false), mParticleEffects(config.getValue("particleeffects", 1)), mEquippedWeapon(NULL), diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 35976963..d4818504 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -95,8 +95,7 @@ ChatWindow::~ChatWindow() delete mRecorder; } -void - ChatWindow::logic() +void ChatWindow::logic() { // todo: only do this when the size changes (updateWidgets?) @@ -296,6 +295,15 @@ void ChatWindow::chatSend(const std::string &nick, std::string msg) } // Prepare ordinary message if (msg.substr(0, 1) != "/") { + // The server never tells you about your own GM status, so work around + // this for now by intercepting it here. NOTE: This assumes that the + // assert works, when it's not guaranteed to. + + std::size_t space = msg.find(" "); + const std::string command = msg.substr(1, space); + if (msg.at(0) == '@' && command == "assert") + player_node->setGM(); + msg = nick + " : " + msg; MessageOut outMsg(mNetwork); diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index 724ce8b4..a23f5923 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -38,6 +38,7 @@ #include "../configuration.h" #include "../graphics.h" +#include "../localplayer.h" #include "../log.h" #include "../main.h" #include "../particle.h" @@ -106,6 +107,7 @@ Setup_Video::Setup_Video(): mCustomCursorEnabled(config.getValue("customcursor", 1)), mParticleEffectsEnabled(config.getValue("particleeffects", 1)), mSpeechBubbleEnabled(config.getValue("speechbubble", 1)), + mNameEnabled(config.getValue("showownname", 0)), mOpacity(config.getValue("guialpha", 0.8)), mFps((int) config.getValue("fpslimit", 0)), mModeListModel(new ModeListModel), @@ -115,6 +117,7 @@ Setup_Video::Setup_Video(): mCustomCursorCheckBox(new CheckBox(_("Custom cursor"), mCustomCursorEnabled)), mParticleEffectsCheckBox(new CheckBox(_("Particle effects"), mParticleEffectsEnabled)), mSpeechBubbleCheckBox(new CheckBox(_("Speech bubbles"), mSpeechBubbleEnabled)), + mNameCheckBox(new CheckBox(_("Show name"), mNameEnabled)), mAlphaSlider(new Slider(0.2, 1.0)), mFpsCheckBox(new CheckBox(_("FPS Limit:"))), mFpsSlider(new Slider(10, 200)), @@ -145,8 +148,9 @@ Setup_Video::Setup_Video(): mModeList->setDimension(gcn::Rectangle(0, 0, 60, 70)); scrollArea->setDimension(gcn::Rectangle(10, 10, 90, 70)); mFsCheckBox->setPosition(110, 10); + mNameCheckBox->setPosition(195, 10); mOpenGLCheckBox->setPosition(110, 30); - mParticleEffectsCheckBox->setPosition(175, 30); + mParticleEffectsCheckBox->setPosition(180, 30); mCustomCursorCheckBox->setPosition(110, 50); mSpeechBubbleCheckBox->setPosition(110, 70); mAlphaSlider->setDimension(gcn::Rectangle(10, 100, 75, 10)); @@ -170,6 +174,7 @@ Setup_Video::Setup_Video(): mCustomCursorCheckBox->setActionEventId("customcursor"); mParticleEffectsCheckBox->setActionEventId("particleeffects"); mSpeechBubbleCheckBox->setActionEventId("speechbubble"); + mNameCheckBox->setActionEventId("showownname"); mAlphaSlider->setActionEventId("guialpha"); mFpsCheckBox->setActionEventId("fpslimitcheckbox"); mFpsSlider->setActionEventId("fpslimitslider"); @@ -186,6 +191,7 @@ Setup_Video::Setup_Video(): mCustomCursorCheckBox->addActionListener(this); mParticleEffectsCheckBox->addActionListener(this); mSpeechBubbleCheckBox->addActionListener(this); + mNameCheckBox->addActionListener(this); mAlphaSlider->addActionListener(this); mFpsCheckBox->addActionListener(this); mFpsSlider->addActionListener(this); @@ -262,6 +268,7 @@ Setup_Video::Setup_Video(): add(mCustomCursorCheckBox); add(mParticleEffectsCheckBox); add(mSpeechBubbleCheckBox); + add(mNameCheckBox); add(mAlphaSlider); add(alphaLabel); add(mFpsCheckBox); @@ -344,6 +351,7 @@ void Setup_Video::apply() mCustomCursorEnabled = config.getValue("customcursor", 1); mParticleEffectsEnabled = config.getValue("particleeffects", 1); mSpeechBubbleEnabled = config.getValue("speechbubble", 1); + mNameEnabled = config.getValue("showownname", 0); mOpacity = config.getValue("guialpha", 0.8); mOverlayDetail = (int)config.getValue("OverlayDetail", 2); mOpenGLEnabled = config.getValue("opengl", 0); @@ -375,6 +383,9 @@ void Setup_Video::cancel() mFsCheckBox->setSelected(mFullScreenEnabled); mOpenGLCheckBox->setSelected(mOpenGLEnabled); mCustomCursorCheckBox->setSelected(mCustomCursorEnabled); + mParticleEffectsCheckBox->setSelected(mParticleEffectsEnabled); + mSpeechBubbleCheckBox->setSelected(mSpeechBubbleEnabled); + mNameCheckBox->setSelected(mNameEnabled); mAlphaSlider->setValue(mOpacity); mOverlayDetailSlider->setValue(mOverlayDetail); mParticleDetailSlider->setValue(mParticleDetail); @@ -388,6 +399,7 @@ void Setup_Video::cancel() config.setValue("customcursor", mCustomCursorEnabled ? 1 : 0); config.setValue("particleeffects", mParticleEffectsEnabled ? 1 : 0); config.setValue("speechbubble", mSpeechBubbleEnabled ? 1 : 0); + config.setValue("showownname", mNameEnabled ? 1 : 0); config.setValue("guialpha", mOpacity); config.setValue("opengl", mOpenGLEnabled ? 1 : 0); } @@ -445,6 +457,14 @@ void Setup_Video::action(const gcn::ActionEvent &event) config.setValue("speechbubble", mSpeechBubbleCheckBox->isSelected() ? 1 : 0); } + else if (event.getId() == "showownname") + { + // Notify the local player that settings have changed for the name + // and requires an update + player_node->mUpdateName = true; + config.setValue("showownname", + mNameCheckBox->isSelected() ? 1 : 0); + } else if (event.getId() == "fpslimitslider") { mFps = (int) mFpsSlider->getValue(); diff --git a/src/gui/setup_video.h b/src/gui/setup_video.h index 4103c5ef..dfc3da38 100644 --- a/src/gui/setup_video.h +++ b/src/gui/setup_video.h @@ -51,6 +51,7 @@ class Setup_Video : public SetupTab, public gcn::ActionListener, bool mCustomCursorEnabled; bool mParticleEffectsEnabled; bool mSpeechBubbleEnabled; + bool mNameEnabled; double mOpacity; int mFps; @@ -62,6 +63,7 @@ class Setup_Video : public SetupTab, public gcn::ActionListener, gcn::CheckBox *mCustomCursorCheckBox; gcn::CheckBox *mParticleEffectsCheckBox; gcn::CheckBox *mSpeechBubbleCheckBox; + gcn::CheckBox *mNameCheckBox; gcn::Slider *mAlphaSlider; gcn::CheckBox *mFpsCheckBox; diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 080ebddc..75b756f5 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -93,6 +93,10 @@ Viewport::draw(gcn::Graphics *gcnGraphics) Graphics *graphics = static_cast<Graphics*>(gcnGraphics); + // Ensure the client doesn't freak out if a feature localplayer uses + // is dependent on a map. + player_node->mMapInitialized = true; + // Avoid freaking out when tick_time overflows if (tick_time < lastTick) { @@ -196,6 +200,13 @@ Viewport::draw(gcn::Graphics *gcnGraphics) } } + if (player_node->mUpdateName) + { + player_node->mUpdateName = false; + player_node->setName(player_node->getName()); + } + + // Draw text if (textManager) { diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 24b50d03..fb568d20 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -20,6 +20,7 @@ */ #include <cassert> +#include "configuration.h" #include "equipment.h" #include "floor_item.h" #include "game.h" @@ -44,6 +45,9 @@ LocalPlayer *player_node = NULL; +static const int NAME_X_OFFSET = 15; +static const int NAME_Y_OFFSET = 30; + LocalPlayer::LocalPlayer(Uint32 id, Uint16 job, Map *map): Player(id, job, map), mCharId(0), @@ -68,6 +72,13 @@ LocalPlayer::LocalPlayer(Uint32 id, Uint16 job, Map *map): mInventory(new Inventory(INVENTORY_SIZE)), mStorage(new Inventory(STORAGE_SIZE)) { + // Variable to keep the local player from doing certain actions before a map + // is initialized. e.g. drawing a player's name using the TextManager, since + // it appears to be dependant upon map coordinates for updating drawing. + mMapInitialized = false; + + mUpdateName = true; + initTargetCursor(); } @@ -75,6 +86,7 @@ LocalPlayer::~LocalPlayer() { delete mInventory; delete mStorage; + delete mName; for (int i = Being::TC_SMALL; i < Being::NUM_TC; i++) { @@ -158,6 +170,38 @@ void LocalPlayer::logic() Being::logic(); } +void LocalPlayer::setGM() +{ + mIsGM = !mIsGM; + setName(getName()); +} + +void LocalPlayer::setName(const std::string &name) +{ + if (mName) + { + delete mName; + mName = 0; + } + + if (config.getValue("showownname", false) && mMapInitialized) + { + Player::setName(name); + } + else + { + Being::setName(name); + } +} + +void LocalPlayer::updateCoords() +{ + if (mName) + { + mName->adviseXY(mPx + NAME_X_OFFSET, mPy + NAME_Y_OFFSET); + } +} + void LocalPlayer::nextStep() { if (mPath.empty()) diff --git a/src/localplayer.h b/src/localplayer.h index 0760f226..28551a22 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -57,7 +57,7 @@ class LocalPlayer : public Player */ ~LocalPlayer(); - void setName(const std::string &name) {Being::setName(name); } + virtual void setName(const std::string &name); void setNetwork(Network *network) { mNetwork = network; } Network *getNetwork() {return mNetwork; } virtual void logic(); @@ -126,6 +126,14 @@ class LocalPlayer : public Player void attack(Being *target = NULL, bool keep = false); + /** + * Triggers whether or not to show the name as a GM name. + * NOTE: This doesn't mean that just anyone can use this. + * If the server doesn't acknowlege you, you won't be shown + * as a GM on other people's clients. + */ + virtual void setGM(); + void stopAttack(); Being* getTarget() const; @@ -212,6 +220,10 @@ class LocalPlayer : public Player Uint16 mStatPoint, mSkillPoint; Uint16 mStatsPointsToAttribute; + bool mUpdateName; /** Whether or not the name settings have changed */ + + bool mMapInitialized; /** Whether or not the map is available yet */ + float mLastAttackTime; /**< Used to synchronize the charge dialog */ void drawTargetCursor(Graphics *graphics, int offsetX, int offsetY); @@ -232,15 +244,15 @@ class LocalPlayer : public Player FloorItem *mPickUpTarget; bool mTrading; - bool mInStorage; /**< Whether storage is currently accessible */ + bool mInStorage; /**< Whether storage is currently accessible */ bool mGoingToTarget; - bool mKeepAttacking;/** Whether or not to continue to attack */ - int mTargetTime; /** How long the being has been targeted **/ - int mLastAction; /**< Time stamp of the last action, -1 if none. */ - int mLastTarget; /** Time stamp of last targeting action, -1 if none. */ - int mWalkingDir; /**< The direction the player is walking in. */ - int mDestX; /**< X coordinate of destination. */ - int mDestY; /**< Y coordinate of destination. */ + bool mKeepAttacking; /** Whether or not to continue to attack */ + int mTargetTime; /** How long the being has been targeted **/ + int mLastAction; /**< Time stamp of the last action, -1 if none. */ + int mLastTarget; /** Time stamp of last targeting action, -1 if none. */ + int mWalkingDir; /**< The direction the player is walking in. */ + int mDestX; /**< X coordinate of destination. */ + int mDestY; /**< Y coordinate of destination. */ Inventory *mInventory; Inventory *mStorage; @@ -259,6 +271,8 @@ class LocalPlayer : public Player // Load the target cursors into memory void initTargetCursor(); + + virtual void updateCoords(); }; extern LocalPlayer *player_node; diff --git a/src/main.cpp b/src/main.cpp index 5f508c52..d9ebaefa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -968,6 +968,7 @@ int main(int argc, char *argv[]) if (options.chooseDefault) ((CharSelectDialog*) currentDialog)->action( gcn::ActionEvent(NULL, "ok")); + break; case GAME_STATE: diff --git a/src/player.cpp b/src/player.cpp index 47275c81..ca728bef 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -41,15 +41,11 @@ Player::Player(int id, int job, Map *map): Being(id, job, map) { mName = 0; - mIsGM = false; } Player::~Player() { - if (mName) - { - delete mName; - } + delete mName; } void Player::setName(const std::string &name) @@ -69,8 +65,7 @@ void Player::setName(const std::string &name) } } -void -Player::logic() +void Player::logic() { switch (mAction) { case STAND: @@ -109,14 +104,12 @@ Player::logic() Being::logic(); } -Being::Type -Player::getType() const +Being::Type Player::getType() const { return PLAYER; } -void -Player::flash(int time) +void Player::flash(int time) { if (mName) { diff --git a/src/player.h b/src/player.h index 97ff15d9..a082a92b 100644 --- a/src/player.h +++ b/src/player.h @@ -43,17 +43,13 @@ class Player : public Being /** * Set up mName to be the character's name */ - virtual void - setName(const std::string &name); + virtual void setName(const std::string &name); - virtual void - logic(); + virtual void logic(); - virtual Type - getType() const; + virtual Type getType() const; - virtual void - setGender(Gender gender); + virtual void setGender(Gender gender); /** * Sets the hair style and color for this player. @@ -70,8 +66,7 @@ class Player : public Being /** * Sets visible equipments for this player. */ - virtual void - setSprite(int slot, int id, std::string color = ""); + virtual void setSprite(int slot, int id, std::string color = ""); /** * Flash the player's name @@ -79,8 +74,8 @@ class Player : public Being void flash(int time); protected: - void updateCoords(); - private: + virtual void updateCoords(); + FlashText *mName; }; |