diff options
author | Jared Adams <jaxad0127@gmail.com> | 2010-02-22 00:02:09 -0700 |
---|---|---|
committer | Jared Adams <jaxad0127@gmail.com> | 2010-02-22 00:02:09 -0700 |
commit | 4406b2fd90a5d4656bc923bf5c751e4c5250a0d2 (patch) | |
tree | bf25813b8711fb1dd51a77104a63a9c9647a60df /src | |
parent | 7c925545419eeda0b0b26b290a9ec0412960fbd8 (diff) | |
download | mana-4406b2fd90a5d4656bc923bf5c751e4c5250a0d2.tar.gz mana-4406b2fd90a5d4656bc923bf5c751e4c5250a0d2.tar.bz2 mana-4406b2fd90a5d4656bc923bf5c751e4c5250a0d2.tar.xz mana-4406b2fd90a5d4656bc923bf5c751e4c5250a0d2.zip |
Cleanup some popup-related code and make sure BeingPopup is included
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/beingmanager.h | 8 | ||||
-rw-r--r-- | src/gui/beingpopup.cpp | 45 | ||||
-rw-r--r-- | src/gui/beingpopup.h | 15 | ||||
-rw-r--r-- | src/gui/equipmentwindow.cpp | 2 | ||||
-rw-r--r-- | src/gui/itemamount.cpp | 2 | ||||
-rw-r--r-- | src/gui/itempopup.cpp | 17 | ||||
-rw-r--r-- | src/gui/itempopup.h | 5 | ||||
-rw-r--r-- | src/gui/popupmenu.h | 6 | ||||
-rw-r--r-- | src/gui/speechbubble.h | 5 | ||||
-rw-r--r-- | src/gui/viewport.cpp | 5 | ||||
-rw-r--r-- | src/gui/widgets/itemcontainer.cpp | 2 | ||||
-rw-r--r-- | src/gui/widgets/itemlinkhandler.cpp | 2 | ||||
-rw-r--r-- | src/gui/widgets/itemshortcutcontainer.cpp | 2 | ||||
-rw-r--r-- | src/gui/widgets/popup.cpp | 16 | ||||
-rw-r--r-- | src/gui/widgets/popup.h | 8 | ||||
-rw-r--r-- | src/gui/widgets/shoplistbox.cpp | 2 |
17 files changed, 57 insertions, 87 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4f90d0a2..0a7458ac 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -190,6 +190,8 @@ SET(SRCS gui/widgets/window.h gui/widgets/windowcontainer.cpp gui/widgets/windowcontainer.h + gui/beingpopup.cpp + gui/beingpopup.h gui/buy.cpp gui/buy.h gui/buysell.cpp diff --git a/src/beingmanager.h b/src/beingmanager.h index 7be9f3f8..83c7da44 100644 --- a/src/beingmanager.h +++ b/src/beingmanager.h @@ -87,12 +87,12 @@ class BeingManager * larger, no being is returned. * @param type The type of being to look for. */ - Being *findNearestLivingBeing(Being *aroundBeing, int maxTileDist, + Being *findNearestLivingBeing(Being *aroundBeing, int maxTileDist, Being::Type type = Being::UNKNOWN) const; - /** - * Finds a being by name and (optionally) by type. - */ + /** + * Finds a being by name and (optionally) by type. + */ Being *findBeingByName(const std::string &name, Being::Type type = Being::UNKNOWN) const; diff --git a/src/gui/beingpopup.cpp b/src/gui/beingpopup.cpp index 89933067..3d60589f 100644 --- a/src/gui/beingpopup.cpp +++ b/src/gui/beingpopup.cpp @@ -1,8 +1,6 @@ /* * The Mana Client - * Copyright (C) 2008 The Legend of Mazzeroth Development Team - * Copyright (C) 2008-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2010 The Mana Developers * * This file is part of The Mana Client. * @@ -23,10 +21,9 @@ #include "gui/beingpopup.h" #include "graphics.h" +#include "player.h" #include "units.h" -#include "being.h" - #include "gui/gui.h" #include "gui/palette.h" @@ -62,29 +59,28 @@ BeingPopup::~BeingPopup() { } -void BeingPopup::setBeing(int x, int y, Being *b) +void BeingPopup::show(int x, int y, Player *p) { - if (!b) + if (!p) { setVisible(false); return; } - if (!(b->getPartyName().empty())) + if (!(p->getPartyName().empty())) { - mBeingName->setTextWrapped(b->getName(), 196); - mBeingParty->setTextWrapped(strprintf(_("Party: %s"),b->getPartyName().c_str()), 196); - - int minWidth = mBeingName->getMinWidth(); + mBeingName->setTextWrapped(p->getName(), 196); + mBeingParty->setTextWrapped(strprintf(_("Party: %s"), + p->getPartyName().c_str()), 196); - if (mBeingParty->getMinWidth() > minWidth) - minWidth = mBeingParty->getMinWidth(); + int minWidth = std::max(mBeingName->getMinWidth(), + mBeingParty->getMinWidth()); const int height = getFont()->getHeight(); - setContentSize(minWidth, (height * 2) + 10); + setContentSize(minWidth + 10, (height * 2) + 10); - view(x, y); + position(x, y); return; } @@ -95,20 +91,3 @@ gcn::Color BeingPopup::getColor() { return guiPalette->getColor(Palette::GENERIC); } - -void BeingPopup::view(int x, int y) -{ - const int distance = 20; - - int posX = std::max(0, x - getWidth() / 2); - int posY = y + distance; - - if (posX > graphics->getWidth() - getWidth()) - posX = graphics->getWidth() - getWidth(); - if (posY > graphics->getHeight() - getHeight()) - posY = y - getHeight() - distance; - - setPosition(posX, posY); - setVisible(true); - requestMoveToTop(); -} diff --git a/src/gui/beingpopup.h b/src/gui/beingpopup.h index 964235bb..b803aacf 100644 --- a/src/gui/beingpopup.h +++ b/src/gui/beingpopup.h @@ -1,8 +1,6 @@ /* * The Mana Client - * Copyright (C) 2008 The Legend of Mazzeroth Development Team - * Copyright (C) 2008-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2010 The Mana Developers * * This file is part of The Mana Client. * @@ -27,8 +25,8 @@ #include <guichan/mouselistener.hpp> +class Player; class TextBox; -class Being; /** * A popup that displays information about an item. @@ -47,14 +45,11 @@ class BeingPopup : public Popup ~BeingPopup(); /** - * Sets the info to be displayed given a particular item. + * Sets the info to be displayed given a particular player. */ - void setBeing(int x, int y, Being *b); + void show(int x, int y, Player *p); - /** - * Sets the location to display the item popup. - */ - void view(int x, int y); + // TODO: Add a version for monsters, NPCs, etc? private: TextBox *mBeingName; diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index 93cce79a..4400c9f5 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -226,7 +226,7 @@ void EquipmentWindow::mouseMoved(gcn::MouseEvent &event) SDL_GetMouseState(&mouseX, &mouseY); mItemPopup->setItem(item->getInfo()); - mItemPopup->view(x + getX(), y + getY()); + mItemPopup->position(x + getX(), y + getY()); } else { diff --git a/src/gui/itemamount.cpp b/src/gui/itemamount.cpp index 73dfa5b2..c4c38a9d 100644 --- a/src/gui/itemamount.cpp +++ b/src/gui/itemamount.cpp @@ -159,7 +159,7 @@ void ItemAmountWindow::mouseMoved(gcn::MouseEvent &event) if (event.getSource() == mItemIcon) { mItemPopup->setItem(mItem->getInfo()); - mItemPopup->view(viewport->getMouseX(), viewport->getMouseY()); + mItemPopup->position(viewport->getMouseX(), viewport->getMouseY()); } } diff --git a/src/gui/itempopup.cpp b/src/gui/itempopup.cpp index a24d3a75..c22a9c33 100644 --- a/src/gui/itempopup.cpp +++ b/src/gui/itempopup.cpp @@ -166,23 +166,6 @@ gcn::Color ItemPopup::getColor(ItemType type) } } -void ItemPopup::view(int x, int y) -{ - const int distance = 20; - - int posX = std::max(0, x - getWidth() / 2); - int posY = y + distance; - - if (posX > graphics->getWidth() - getWidth()) - posX = graphics->getWidth() - getWidth(); - if (posY > graphics->getHeight() - getHeight()) - posY = y - getHeight() - distance; - - setPosition(posX, posY); - setVisible(true); - requestMoveToTop(); -} - void ItemPopup::mouseMoved(gcn::MouseEvent &event) { // When the mouse moved on top of the popup, hide it diff --git a/src/gui/itempopup.h b/src/gui/itempopup.h index 23c5f828..79aba523 100644 --- a/src/gui/itempopup.h +++ b/src/gui/itempopup.h @@ -53,11 +53,6 @@ class ItemPopup : public Popup, */ void setItem(const ItemInfo &item); - /** - * Sets the location to display the item popup. - */ - void view(int x, int y); - void mouseMoved(gcn::MouseEvent &mouseEvent); private: diff --git a/src/gui/popupmenu.h b/src/gui/popupmenu.h index 57cd5ee1..3299694f 100644 --- a/src/gui/popupmenu.h +++ b/src/gui/popupmenu.h @@ -59,12 +59,6 @@ class PopupMenu : public Popup, public LinkHandler void showPopup(int x, int y, Item *item, bool isInventory); /** - * Just shows general information about a being - */ - void showPopupBeing(int x, int y, Being *being); - - - /** * Handles link action. */ void handleLink(const std::string &link); diff --git a/src/gui/speechbubble.h b/src/gui/speechbubble.h index eec88049..6d393d74 100644 --- a/src/gui/speechbubble.h +++ b/src/gui/speechbubble.h @@ -49,11 +49,6 @@ class SpeechBubble : public Popup */ void setText(const std::string &text, bool showName = true); - /** - * Sets the location in which the speech bubble will be displayed. - */ - void setLocation(int x, int y); - private: std::string mText; gcn::Label *mCaption; diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 543082e7..b3d0b059 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -478,7 +478,10 @@ void Viewport::mouseMoved(gcn::MouseEvent &event) const int y = (event.getY() + (int) mPixelViewY); mSelectedBeing = beingManager->findBeingByPixel(x, y); - mBeingPopup->setBeing(getMouseX(), getMouseY(), mSelectedBeing); + if (Player *p = dynamic_cast<Player*>(mSelectedBeing)) + { + mBeingPopup->show(getMouseX(), getMouseY(), p); + } } void Viewport::toggleDebugPath() diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp index 4f5d417d..f801822c 100644 --- a/src/gui/widgets/itemcontainer.cpp +++ b/src/gui/widgets/itemcontainer.cpp @@ -320,7 +320,7 @@ void ItemContainer::mouseMoved(gcn::MouseEvent &event) if (item) { mItemPopup->setItem(item->getInfo()); - mItemPopup->view(viewport->getMouseX(), viewport->getMouseY()); + mItemPopup->position(viewport->getMouseX(), viewport->getMouseY()); } else { diff --git a/src/gui/widgets/itemlinkhandler.cpp b/src/gui/widgets/itemlinkhandler.cpp index 0baa4d1e..0c51aeb3 100644 --- a/src/gui/widgets/itemlinkhandler.cpp +++ b/src/gui/widgets/itemlinkhandler.cpp @@ -56,6 +56,6 @@ void ItemLinkHandler::handleLink(const std::string &link) if (mItemPopup->isVisible()) mItemPopup->setVisible(false); else - mItemPopup->view(viewport->getMouseX(), viewport->getMouseY()); + mItemPopup->position(viewport->getMouseX(), viewport->getMouseY()); } } diff --git a/src/gui/widgets/itemshortcutcontainer.cpp b/src/gui/widgets/itemshortcutcontainer.cpp index 7a81c097..b2ddcf0c 100644 --- a/src/gui/widgets/itemshortcutcontainer.cpp +++ b/src/gui/widgets/itemshortcutcontainer.cpp @@ -239,7 +239,7 @@ void ItemShortcutContainer::mouseMoved(gcn::MouseEvent &event) if (item) { mItemPopup->setItem(item->getInfo()); - mItemPopup->view(viewport->getMouseX(), viewport->getMouseY()); + mItemPopup->position(viewport->getMouseX(), viewport->getMouseY()); } else { diff --git a/src/gui/widgets/popup.cpp b/src/gui/widgets/popup.cpp index 6f551317..391b0eed 100644 --- a/src/gui/widgets/popup.cpp +++ b/src/gui/widgets/popup.cpp @@ -170,3 +170,19 @@ void Popup::scheduleDelete() windowContainer->scheduleDelete(this); } +void Popup::position(int x, int y) +{ + const int distance = 20; + + int posX = std::max(0, x - getWidth() / 2); + int posY = y + distance; + + if (posX > graphics->getWidth() - getWidth()) + posX = graphics->getWidth() - getWidth(); + if (posY > graphics->getHeight() - getHeight()) + posY = y - getHeight() - distance; + + setPosition(posX, posY); + setVisible(true); + requestMoveToTop(); +} diff --git a/src/gui/widgets/popup.h b/src/gui/widgets/popup.h index a77ec2c8..449c2f7b 100644 --- a/src/gui/widgets/popup.h +++ b/src/gui/widgets/popup.h @@ -152,6 +152,14 @@ class Popup : public Container virtual gcn::Rectangle getChildrenArea(); + /** + * Sets the location to display the popup. Tries to horizontally center + * the popup and provide a vertical buffer between the given point and + * the popup. Prevents the popup from extending off-screen, if + * possible. + */ + void position(int x, int y); + private: std::string mPopupName; /**< Name of the popup */ std::string mDefaultSkinPath; /**< Default skin path for this popup */ diff --git a/src/gui/widgets/shoplistbox.cpp b/src/gui/widgets/shoplistbox.cpp index 1f735feb..fc9fc4d4 100644 --- a/src/gui/widgets/shoplistbox.cpp +++ b/src/gui/widgets/shoplistbox.cpp @@ -159,7 +159,7 @@ void ShopListBox::mouseMoved(gcn::MouseEvent &event) if (item) { mItemPopup->setItem(item->getInfo()); - mItemPopup->view(viewport->getMouseX(), viewport->getMouseY()); + mItemPopup->position(viewport->getMouseX(), viewport->getMouseY()); } else { |