diff options
author | Jared Adams <jaxad0127@gmail.com> | 2010-05-17 19:16:11 -0600 |
---|---|---|
committer | Jared Adams <jaxad0127@gmail.com> | 2010-05-17 21:49:16 -0600 |
commit | 3b4e7795c9ab3036988a1a7dfe6f5ed2ad12199d (patch) | |
tree | ed0e8cc5b608c31ac79e6d1de03d9ddfc74fa339 /src/gui | |
parent | 51945aa1af6f2a6dc15027ef40cf0ccf424d46e1 (diff) | |
download | mana-3b4e7795c9ab3036988a1a7dfe6f5ed2ad12199d.tar.gz mana-3b4e7795c9ab3036988a1a7dfe6f5ed2ad12199d.tar.bz2 mana-3b4e7795c9ab3036988a1a7dfe6f5ed2ad12199d.tar.xz mana-3b4e7795c9ab3036988a1a7dfe6f5ed2ad12199d.zip |
Remove Monster, Player, and NPC classes
Instead of having these three subclasses with minor differences, this
commit merges them back into Being. In the future, we can make Beings
that are talkable to some, attackable by others, etc. This also puts
back support for monster equipment.
Also changes remaining references to Being::Type and the constants to
refer to ActorSprite::Type.
Reviewed-by: Freeyorp
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/beingpopup.cpp | 12 | ||||
-rw-r--r-- | src/gui/beingpopup.h | 4 | ||||
-rw-r--r-- | src/gui/buy.cpp | 7 | ||||
-rw-r--r-- | src/gui/buysell.cpp | 2 | ||||
-rw-r--r-- | src/gui/charcreatedialog.cpp | 2 | ||||
-rw-r--r-- | src/gui/charcreatedialog.h | 4 | ||||
-rw-r--r-- | src/gui/charselectdialog.h | 2 | ||||
-rw-r--r-- | src/gui/chat.cpp | 2 | ||||
-rw-r--r-- | src/gui/minimap.cpp | 56 | ||||
-rw-r--r-- | src/gui/npcdialog.cpp | 1 | ||||
-rw-r--r-- | src/gui/npcdialog.h | 1 | ||||
-rw-r--r-- | src/gui/npcpostdialog.cpp | 2 | ||||
-rw-r--r-- | src/gui/popupmenu.cpp | 38 | ||||
-rw-r--r-- | src/gui/register.h | 2 | ||||
-rw-r--r-- | src/gui/sell.cpp | 1 | ||||
-rw-r--r-- | src/gui/socialwindow.cpp | 2 | ||||
-rw-r--r-- | src/gui/viewport.cpp | 44 | ||||
-rw-r--r-- | src/gui/widgets/playerbox.cpp | 12 | ||||
-rw-r--r-- | src/gui/widgets/playerbox.h | 8 |
19 files changed, 83 insertions, 119 deletions
diff --git a/src/gui/beingpopup.cpp b/src/gui/beingpopup.cpp index 687b20c2..ee9fd66d 100644 --- a/src/gui/beingpopup.cpp +++ b/src/gui/beingpopup.cpp @@ -20,8 +20,8 @@ #include "gui/beingpopup.h" +#include "being.h" #include "graphics.h" -#include "player.h" #include "units.h" #include "gui/gui.h" @@ -57,21 +57,21 @@ BeingPopup::~BeingPopup() { } -void BeingPopup::show(int x, int y, Player *p) +void BeingPopup::show(int x, int y, Being *b) { - if (!p) + if (!b) { setVisible(false); return; } - if (!(p->getPartyName().empty())) + if (!(b->getPartyName().empty())) { - mBeingName->setCaption(p->getName()); + mBeingName->setCaption(b->getName()); mBeingName->adjustSize(); mBeingParty->setCaption(strprintf(_("Party: %s"), - p->getPartyName().c_str())); + b->getPartyName().c_str())); mBeingParty->adjustSize(); int minWidth = std::max(mBeingName->getWidth(), diff --git a/src/gui/beingpopup.h b/src/gui/beingpopup.h index f397e374..514a6e7e 100644 --- a/src/gui/beingpopup.h +++ b/src/gui/beingpopup.h @@ -23,8 +23,8 @@ #include "gui/widgets/popup.h" +class Being; class Label; -class Player; /** * A popup that displays information about a being. @@ -45,7 +45,7 @@ class BeingPopup : public Popup /** * Sets the info to be displayed given a particular player. */ - void show(int x, int y, Player *p); + void show(int x, int y, Being *b); // TODO: Add a version for monsters, NPCs, etc? diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index 031c53dd..a214c075 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -21,6 +21,9 @@ #include "gui/buy.h" +#include "shopitem.h" +#include "units.h" + #include "gui/setup.h" #include "gui/widgets/button.h" @@ -31,10 +34,6 @@ #include "gui/widgets/shoplistbox.h" #include "gui/widgets/slider.h" -#include "npc.h" -#include "shopitem.h" -#include "units.h" - #include "net/net.h" #include "net/npchandler.h" diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp index c6b4ef41..3e810a4a 100644 --- a/src/gui/buysell.cpp +++ b/src/gui/buysell.cpp @@ -21,8 +21,6 @@ #include "buysell.h" -#include "npc.h" - #include "gui/setup.h" #include "gui/widgets/button.h" diff --git a/src/gui/charcreatedialog.cpp b/src/gui/charcreatedialog.cpp index e4a5fd01..a2cb2efb 100644 --- a/src/gui/charcreatedialog.cpp +++ b/src/gui/charcreatedialog.cpp @@ -54,7 +54,7 @@ CharCreateDialog::CharCreateDialog(CharSelectDialog *parent, int slot): mCharSelectDialog(parent), mSlot(slot) { - mPlayer = new Player(0, 0, NULL); + mPlayer = new Being(0, ActorSprite::PLAYER, 0, NULL); mPlayer->setGender(GENDER_MALE); int numberOfHairColors = ColorDB::size(); diff --git a/src/gui/charcreatedialog.h b/src/gui/charcreatedialog.h index 902e650e..018de3f5 100644 --- a/src/gui/charcreatedialog.h +++ b/src/gui/charcreatedialog.h @@ -22,7 +22,7 @@ #ifndef CHAR_CREATE_DIALOG_H #define CHAR_CREATE_DIALOG_H -#include "player.h" +#include "being.h" #include "guichanfwd.h" #include "gui/charselectdialog.h" @@ -110,7 +110,7 @@ class CharCreateDialog : public Window, public gcn::ActionListener gcn::Button *mCreateButton; gcn::Button *mCancelButton; - Player *mPlayer; + Being *mPlayer; PlayerBox *mPlayerBox; int mHairStyle; diff --git a/src/gui/charselectdialog.h b/src/gui/charselectdialog.h index b6e71715..6d565135 100644 --- a/src/gui/charselectdialog.h +++ b/src/gui/charselectdialog.h @@ -22,9 +22,9 @@ #ifndef CHAR_SELECT_H #define CHAR_SELECT_H +#include "being.h" #include "guichanfwd.h" #include "main.h" -#include "player.h" #include "gui/widgets/window.h" diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index d53bcf0a..83aaed26 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -273,7 +273,7 @@ void ChatWindow::doPresent() for (Beings::const_iterator bi = beings.begin(), be = beings.end(); bi != be; ++bi) { - if ((*bi)->getType() == Being::PLAYER) + if ((*bi)->getType() == ActorSprite::PLAYER) { if (!response.empty()) { diff --git a/src/gui/minimap.cpp b/src/gui/minimap.cpp index 53d58d2e..b4445d94 100644 --- a/src/gui/minimap.cpp +++ b/src/gui/minimap.cpp @@ -28,7 +28,6 @@ #include "localplayer.h" #include "log.h" #include "map.h" -#include "player.h" #include "gui/setup.h" #include "gui/userpalette.h" @@ -195,44 +194,35 @@ void Minimap::draw(gcn::Graphics *graphics) const Being *being = (*bi); int dotSize = 2; - switch (being->getType()) + int type = UserPalette::PC; + + if (being == player_node) + { + type = UserPalette::SELF; + dotSize = 3; + } + else if (being->isGM()) + type = UserPalette::GM; + else if (being->isInParty()) + type = UserPalette::PARTY; + else { - case Being::PLAYER: - { - const Player *player = static_cast<const Player*>(being); - - int type = UserPalette::PC; - - if (being == player_node) - { - type = UserPalette::SELF; - dotSize = 3; - } - else if (player->isGM()) - { - type = UserPalette::GM; - } - else if (player->isInParty()) - { - type = UserPalette::PARTY; - } - - graphics->setColor(userPalette->getColor(type)); + switch (being->getType()) + { + case ActorSprite::MONSTER: + graphics->setColor(userPalette->getColor(UserPalette::MONSTER)); break; - } - case Being::MONSTER: - graphics->setColor(userPalette->getColor(UserPalette::MONSTER)); - break; - - case Being::NPC: - graphics->setColor(userPalette->getColor(UserPalette::NPC)); - break; + case ActorSprite::NPC: + graphics->setColor(userPalette->getColor(UserPalette::NPC)); + break; - default: - continue; + default: + continue; + } } + graphics->setColor(userPalette->getColor(type)); const int offsetHeight = (int) ((dotSize - 1) * mHeightProportion); const int offsetWidth = (int) ((dotSize - 1) * mWidthProportion); diff --git a/src/gui/npcdialog.cpp b/src/gui/npcdialog.cpp index 6d3995a7..4e9c0b01 100644 --- a/src/gui/npcdialog.cpp +++ b/src/gui/npcdialog.cpp @@ -22,7 +22,6 @@ #include "gui/npcdialog.h" #include "configuration.h" -#include "npc.h" #include "gui/setup.h" diff --git a/src/gui/npcdialog.h b/src/gui/npcdialog.h index a8521ce9..26ff9c1a 100644 --- a/src/gui/npcdialog.h +++ b/src/gui/npcdialog.h @@ -23,7 +23,6 @@ #define NPCDIALOG_H #include "configlistener.h" -#include "npc.h" #include "gui/widgets/window.h" diff --git a/src/gui/npcpostdialog.cpp b/src/gui/npcpostdialog.cpp index 19d0cf61..68a91f36 100644 --- a/src/gui/npcpostdialog.cpp +++ b/src/gui/npcpostdialog.cpp @@ -21,8 +21,6 @@ #include "gui/npcpostdialog.h" -#include "npc.h" - #include "gui/widgets/button.h" #include "gui/widgets/chattab.h" #include "gui/widgets/label.h" diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index 77e919a9..0dae4f4b 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -28,7 +28,6 @@ #include "item.h" #include "localplayer.h" #include "log.h" -#include "npc.h" #include "playerrelations.h" #include "gui/chat.h" @@ -76,7 +75,7 @@ void PopupMenu::showPopup(int x, int y, Being *being) switch (being->getType()) { - case Being::PLAYER: + case ActorSprite::PLAYER: { // Players can be traded with. mBrowserBox->addRow(strprintf("@@trade|%s@@", @@ -145,7 +144,7 @@ void PopupMenu::showPopup(int x, int y, Being *being) } break; - case Being::NPC: + case ActorSprite::NPC: // NPCs can be talked to (single option, candidate for removal // unless more options would be added) mBrowserBox->addRow(strprintf("@@talk|%s@@", @@ -153,7 +152,7 @@ void PopupMenu::showPopup(int x, int y, Being *being) name.c_str()).c_str())); break; - case Being::MONSTER: + case ActorSprite::MONSTER: { // Monsters can be attacked mBrowserBox->addRow(strprintf("@@attack|%s@@", @@ -203,13 +202,14 @@ void PopupMenu::handleLink(const std::string &link) Being *being = beingManager->findBeing(mBeingId); // Talk To action - if (link == "talk" && being && being->getType() == Being::NPC) + if (link == "talk" && being && being->canTalk()) { - static_cast<NPC*>(being)->talk(); + being->talkTo(); } // Trade action - else if (link == "trade" && being && being->getType() == Being::PLAYER) + else if (link == "trade" && being && + being->getType() == ActorSprite::PLAYER) { Net::getTradeHandler()->request(being); tradePartnerName = being->getName(); @@ -223,27 +223,32 @@ void PopupMenu::handleLink(const std::string &link) { chatWindow->addInputText("/w \"" + being->getName() + "\" "); } - else if (link == "unignore" && being && being->getType() == Being::PLAYER) + else if (link == "unignore" && being && + being->getType() == ActorSprite::PLAYER) { player_relations.setRelation(being->getName(), PlayerRelation::NEUTRAL); } - else if (link == "ignore" && being && being->getType() == Being::PLAYER) + else if (link == "ignore" && being && + being->getType() == ActorSprite::PLAYER) { player_relations.setRelation(being->getName(), PlayerRelation::IGNORED); } - else if (link == "disregard" && being && being->getType() == Being::PLAYER) + else if (link == "disregard" && being && + being->getType() == ActorSprite::PLAYER) { player_relations.setRelation(being->getName(), PlayerRelation::DISREGARDED); } - else if (link == "friend" && being && being->getType() == Being::PLAYER) + else if (link == "friend" && being && + being->getType() == ActorSprite::PLAYER) { player_relations.setRelation(being->getName(), PlayerRelation::FRIEND); } // Guild action - else if (link == "guild" && being && being->getType() == Being::PLAYER) + else if (link == "guild" && being && + being->getType() == ActorSprite::PLAYER) { player_node->inviteToGuild(being); } @@ -313,9 +318,10 @@ void PopupMenu::handleLink(const std::string &link) mItem); } - else if (link == "party" && being && being->getType() == Being::PLAYER) + else if (link == "party" && being && + being->getType() == ActorSprite::PLAYER) { - Net::getPartyHandler()->invite(static_cast<Player*>(being)); + Net::getPartyHandler()->invite(being); } else if (link == "name" && being) @@ -326,8 +332,8 @@ void PopupMenu::handleLink(const std::string &link) else if (link == "admin-kick" && being && - (being->getType() == Being::PLAYER || - being->getType() == Being::MONSTER)) + (being->getType() == ActorSprite::PLAYER || + being->getType() == ActorSprite::MONSTER)) { Net::getAdminHandler()->kick(being->getId()); } diff --git a/src/gui/register.h b/src/gui/register.h index 645b0be8..3c65695b 100644 --- a/src/gui/register.h +++ b/src/gui/register.h @@ -22,8 +22,6 @@ #ifndef REGISTER_H #define REGISTER_H -#include "player.h" - #include "gui/widgets/window.h" #include <guichan/actionlistener.hpp> diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index 69ff7ed2..a4109033 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -21,7 +21,6 @@ #include "gui/sell.h" -#include "npc.h" #include "shopitem.h" #include "units.h" diff --git a/src/gui/socialwindow.cpp b/src/gui/socialwindow.cpp index 10ed680e..8d833123 100644 --- a/src/gui/socialwindow.cpp +++ b/src/gui/socialwindow.cpp @@ -20,11 +20,9 @@ #include "gui/socialwindow.h" -#include "beingmanager.h" #include "guild.h" #include "localplayer.h" #include "party.h" -#include "player.h" #include "gui/confirmdialog.h" #include "gui/okdialog.h" diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 99325db8..1c793cdd 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -29,8 +29,6 @@ #include "keyboardconfig.h" #include "localplayer.h" #include "map.h" -#include "monster.h" -#include "npc.h" #include "textmanager.h" #include "gui/gui.h" @@ -40,7 +38,6 @@ #include "net/net.h" -#include "resources/monsterinfo.h" #include "resources/resourcemanager.h" #include "utils/stringutils.h" @@ -345,7 +342,7 @@ void Viewport::mousePressed(gcn::MouseEvent &event) return; // Check if we are busy - if (NPC::isTalking()) + if (Being::isTalking()) return; mPlayerFollowMouse = false; @@ -381,33 +378,20 @@ void Viewport::mousePressed(gcn::MouseEvent &event) // Interact with some being if (mHoverBeing) { - switch (mHoverBeing->getType()) + if (mHoverBeing->canTalk()) + mHoverBeing->talkTo(); + else { - // Talk to NPCs - case Being::NPC: - static_cast<NPC*>(mHoverBeing)->talk(); - break; - - // Attack or walk to monsters or players - case Being::MONSTER: - case Being::PLAYER: - // Ignore it if its dead - if (!mHoverBeing->isAlive()) - break; - + // Ignore it if its dead + if (mHoverBeing->isAlive()) + { if (player_node->withinAttackRange(mHoverBeing) || keyboard.isKeyActive(keyboard.KEY_ATTACK)) - { player_node->attack(mHoverBeing, !keyboard.isKeyActive(keyboard.KEY_TARGET)); - } else - { player_node->setGotoTarget(mHoverBeing); - } - break; - default: - break; + } } // Picks up a item if we clicked on one } @@ -434,7 +418,7 @@ void Viewport::mousePressed(gcn::MouseEvent &event) { // Find the being nearest to the clicked position Being *target = beingManager->findNearestLivingBeing( - pixelX, pixelY, 20, Being::MONSTER); + pixelX, pixelY, 20, ActorSprite::MONSTER); if (target) player_node->setTarget(target); @@ -508,11 +492,7 @@ void Viewport::mouseMoved(gcn::MouseEvent &event) const int y = (event.getY() + (int) mPixelViewY); mHoverBeing = beingManager->findBeingByPixel(x, y); - if (mHoverBeing && mHoverBeing->getType() == Being::PLAYER) - mBeingPopup->show(getMouseX(), getMouseY(), - static_cast<Player*>(mHoverBeing)); - else - mBeingPopup->setVisible(false); + mBeingPopup->show(getMouseX(), getMouseY(), mHoverBeing); mHoverItem = floorItemManager->findByCoordinates(x / mMap->getTileWidth(), y / mMap->getTileHeight()); @@ -522,12 +502,12 @@ void Viewport::mouseMoved(gcn::MouseEvent &event) switch (mHoverBeing->getType()) { // NPCs - case Being::NPC: + case ActorSprite::NPC: gui->setCursorType(Gui::CURSOR_TALK); break; // Monsters - case Being::MONSTER: + case ActorSprite::MONSTER: gui->setCursorType(Gui::CURSOR_FIGHT); break; default: diff --git a/src/gui/widgets/playerbox.cpp b/src/gui/widgets/playerbox.cpp index a953f474..468c77f5 100644 --- a/src/gui/widgets/playerbox.cpp +++ b/src/gui/widgets/playerbox.cpp @@ -22,9 +22,9 @@ #include "gui/widgets/playerbox.h" #include "animatedsprite.h" +#include "being.h" #include "configuration.h" #include "graphics.h" -#include "player.h" #include "gui/theme.h" @@ -36,8 +36,8 @@ int PlayerBox::instances = 0; float PlayerBox::mAlpha = 1.0; ImageRect PlayerBox::background; -PlayerBox::PlayerBox(const Player *player): - mPlayer(player) +PlayerBox::PlayerBox(const Being *being): + mBeing(being) { setFrameSize(2); @@ -72,7 +72,7 @@ PlayerBox::~PlayerBox() { instances--; - mPlayer = 0; + mBeing = 0; if (instances == 0) { @@ -82,13 +82,13 @@ PlayerBox::~PlayerBox() void PlayerBox::draw(gcn::Graphics *graphics) { - if (mPlayer) + if (mBeing) { // Draw character const int bs = getFrameSize(); const int x = getWidth() / 2 + bs - 16; const int y = getHeight() - bs - 32; - mPlayer->drawSpriteAt(static_cast<Graphics*>(graphics), x, y); + mBeing->drawSpriteAt(static_cast<Graphics*>(graphics), x, y); } if (config.getValue("guialpha", 0.8) != mAlpha) diff --git a/src/gui/widgets/playerbox.h b/src/gui/widgets/playerbox.h index 33b4a628..4505367f 100644 --- a/src/gui/widgets/playerbox.h +++ b/src/gui/widgets/playerbox.h @@ -24,8 +24,8 @@ #include <guichan/widgets/scrollarea.hpp> +class Being; class ImageRect; -class Player; /** * A box showing a player character. @@ -39,7 +39,7 @@ class PlayerBox : public gcn::ScrollArea * Constructor. Takes the initial player character that this box should * display, which defaults to <code>NULL</code>. */ - PlayerBox(const Player *player = 0); + PlayerBox(const Being *being = 0); /** * Destructor. @@ -51,7 +51,7 @@ class PlayerBox : public gcn::ScrollArea * player to <code>NULL</code> causes the box not to draw any * character. */ - void setPlayer(const Player *player) { mPlayer = player; } + void setPlayer(const Being *being) { mBeing = being; } /** * Draws the scroll area. @@ -64,7 +64,7 @@ class PlayerBox : public gcn::ScrollArea void drawFrame(gcn::Graphics *graphics); private: - const Player *mPlayer; /**< The character used for display */ + const Being *mBeing; /**< The character used for display */ static float mAlpha; static int instances; |