From d32203d2e6539aa22953b9c04df000f79e85bf66 Mon Sep 17 00:00:00 2001 From: idiomatic Date: Sun, 28 Feb 2010 21:52:22 -0700 Subject: Add some new mousers and simplify related code Signed-off-by: Jared Adams --- src/gui/viewport.cpp | 71 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 46 insertions(+), 25 deletions(-) (limited to 'src/gui/viewport.cpp') diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 763d0c43..0ebf0cb9 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -312,25 +312,18 @@ void Viewport::mousePressed(gcn::MouseEvent &event) const int pixelX = event.getX() + (int) mPixelViewX; const int pixelY = event.getY() + (int) mPixelViewY; - const int tileX = pixelX / mMap->getTileWidth(); - const int tileY = pixelY / mMap->getTileHeight(); // Right click might open a popup if (event.getButton() == gcn::MouseEvent::RIGHT) { - Being *being; - FloorItem *floorItem; - - if ((being = beingManager->findBeingByPixel(pixelX, pixelY)) && - being != player_node) + if (mHoverBeing && mHoverBeing != player_node) { - mPopupMenu->showPopup(event.getX(), event.getY(), being); + mPopupMenu->showPopup(event.getX(), event.getY(), mHoverBeing); return; } - else if ((floorItem = floorItemManager->findByCoordinates(tileX, - tileY))) + else if (mHoverItem) { - mPopupMenu->showPopup(event.getX(), event.getY(), floorItem); + mPopupMenu->showPopup(event.getX(), event.getY(), mHoverItem); return; } } @@ -345,35 +338,32 @@ void Viewport::mousePressed(gcn::MouseEvent &event) // Left click can cause different actions if (event.getButton() == gcn::MouseEvent::LEFT) { - FloorItem *item; - Being *being; - // Interact with some being - if ((being = beingManager->findBeingByPixel(pixelX, pixelY))) + if (mHoverBeing) { - switch (being->getType()) + switch (mHoverBeing->getType()) { // Talk to NPCs case Being::NPC: - dynamic_cast(being)->talk(); + static_cast(mHoverBeing)->talk(); break; // Attack or walk to monsters or players case Being::MONSTER: case Being::PLAYER: // Ignore it if its dead - if (!being->isAlive()) + if (!mHoverBeing->isAlive()) break; - if (player_node->withinAttackRange(being) || + if (player_node->withinAttackRange(mHoverBeing) || keyboard.isKeyActive(keyboard.KEY_ATTACK)) { - player_node->attack(being, + player_node->attack(mHoverBeing, !keyboard.isKeyActive(keyboard.KEY_TARGET)); } else { - player_node->setGotoTarget(being); + player_node->setGotoTarget(mHoverBeing); } break; default: @@ -381,9 +371,9 @@ void Viewport::mousePressed(gcn::MouseEvent &event) } // Picks up a item if we clicked on one } - else if ((item = floorItemManager->findByCoordinates(tileX, tileY))) + else if (mHoverItem) { - player_node->pickUp(item); + player_node->pickUp(mHoverItem); } else if (player_node->getCurrentAction() == Being::SIT) { @@ -478,11 +468,42 @@ void Viewport::mouseMoved(gcn::MouseEvent &event) const int x = (event.getX() + (int) mPixelViewX); const int y = (event.getY() + (int) mPixelViewY); - mSelectedBeing = beingManager->findBeingByPixel(x, y); - if (Player *p = dynamic_cast(mSelectedBeing)) + mHoverBeing = beingManager->findBeingByPixel(x, y); + if (Player *p = dynamic_cast(mHoverBeing)) mBeingPopup->show(getMouseX(), getMouseY(), p); else mBeingPopup->setVisible(false); + + mHoverItem = floorItemManager->findByCoordinates(x / mMap->getTileWidth(), + y / mMap->getTileHeight()); + + if (mHoverBeing) + { + switch (mHoverBeing->getType()) + { + // NPCs + case Being::NPC: + gui->setCursorType(Gui::CURSOR_TALK); + break; + + // Monsters + case Being::MONSTER: + gui->setCursorType(Gui::CURSOR_FIGHT); + break; + default: + gui->setCursorType(Gui::CURSOR_POINTER); + break; + } + // Item mouseover + } + else if (mHoverItem) + { + gui->setCursorType(Gui::CURSOR_PICKUP); + } + else + { + gui->setCursorType(Gui::CURSOR_POINTER); + } } void Viewport::toggleDebugPath() -- cgit v1.2.3-70-g09d2 From 452b02cb1b6e1675323d89e5f2c4946b2868a584 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Mon, 1 Mar 2010 07:46:59 -0700 Subject: Hide BeingPopup when mouseover Windows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-by: Thorbjørn Lindeijer Reviewed-by: Chuck Miller --- src/gui/emotepopup.cpp | 2 ++ src/gui/emotepopup.h | 3 +-- src/gui/itempopup.cpp | 2 ++ src/gui/itempopup.h | 3 +-- src/gui/viewport.cpp | 4 ++++ src/gui/viewport.h | 5 +++++ src/gui/widgets/popup.cpp | 7 +++++++ src/gui/widgets/popup.h | 6 +++++- src/gui/widgets/window.cpp | 4 ++++ 9 files changed, 31 insertions(+), 5 deletions(-) (limited to 'src/gui/viewport.cpp') diff --git a/src/gui/emotepopup.cpp b/src/gui/emotepopup.cpp index e0c0a409..2161e04c 100644 --- a/src/gui/emotepopup.cpp +++ b/src/gui/emotepopup.cpp @@ -119,6 +119,8 @@ void EmotePopup::mousePressed(gcn::MouseEvent &event) void EmotePopup::mouseMoved(gcn::MouseEvent &event) { + Popup::mouseMoved(event); + mHoveredEmoteIndex = getIndexAt(event.getX(), event.getY()); } diff --git a/src/gui/emotepopup.h b/src/gui/emotepopup.h index de957925..62a3f24a 100644 --- a/src/gui/emotepopup.h +++ b/src/gui/emotepopup.h @@ -42,8 +42,7 @@ namespace gcn { * * \ingroup GUI */ -class EmotePopup : public Popup, - public gcn::MouseListener +class EmotePopup : public Popup { public: /** diff --git a/src/gui/itempopup.cpp b/src/gui/itempopup.cpp index c22a9c33..1d41449d 100644 --- a/src/gui/itempopup.cpp +++ b/src/gui/itempopup.cpp @@ -168,6 +168,8 @@ gcn::Color ItemPopup::getColor(ItemType type) void ItemPopup::mouseMoved(gcn::MouseEvent &event) { + Popup::mouseMoved(event); + // When the mouse moved on top of the popup, hide it setVisible(false); } diff --git a/src/gui/itempopup.h b/src/gui/itempopup.h index 79aba523..67d1eb2f 100644 --- a/src/gui/itempopup.h +++ b/src/gui/itempopup.h @@ -34,8 +34,7 @@ class TextBox; /** * A popup that displays information about an item. */ -class ItemPopup : public Popup, - public gcn::MouseListener +class ItemPopup : public Popup { public: /** diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 0ebf0cb9..4622c538 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -517,3 +517,7 @@ void Viewport::toggleDebugPath() } } +void Viewport::hideBeingPopup() +{ + mBeingPopup->setVisible(false); +} diff --git a/src/gui/viewport.h b/src/gui/viewport.h index c4fcece4..3fab607d 100644 --- a/src/gui/viewport.h +++ b/src/gui/viewport.h @@ -152,6 +152,11 @@ class Viewport : public WindowContainer, public gcn::MouseListener, */ Map *getCurrentMap() const { return mMap; } + /** + * Hides the BeingPopup. + */ + void hideBeingPopup(); + private: /** * Finds a path from the player to the mouse, and draws it. This is for diff --git a/src/gui/widgets/popup.cpp b/src/gui/widgets/popup.cpp index 391b0eed..970b21ec 100644 --- a/src/gui/widgets/popup.cpp +++ b/src/gui/widgets/popup.cpp @@ -27,6 +27,7 @@ #include "log.h" #include "gui/skin.h" +#include "gui/viewport.h" #include "gui/widgets/windowcontainer.h" @@ -186,3 +187,9 @@ void Popup::position(int x, int y) setVisible(true); requestMoveToTop(); } + +void Popup::mouseMoved(gcn::MouseEvent &event) +{ + if (viewport) + viewport->hideBeingPopup(); +} diff --git a/src/gui/widgets/popup.h b/src/gui/widgets/popup.h index 207a9857..5c9164f6 100644 --- a/src/gui/widgets/popup.h +++ b/src/gui/widgets/popup.h @@ -28,6 +28,8 @@ #include "gui/widgets/container.h" +#include + class Skin; class WindowContainer; @@ -43,7 +45,7 @@ class WindowContainer; * * \ingroup GUI */ -class Popup : public Container +class Popup : public Container, public gcn::MouseListener { public: /** @@ -94,6 +96,8 @@ class Popup : public Container */ void setLocationRelativeTo(gcn::Widget *widget); + void mouseMoved(gcn::MouseEvent &event); + /** * Sets the minimum width of the popup. */ diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp index 8505f552..83c918cf 100644 --- a/src/gui/widgets/window.cpp +++ b/src/gui/widgets/window.cpp @@ -27,6 +27,7 @@ #include "gui/gui.h" #include "gui/palette.h" #include "gui/skin.h" +#include "gui/viewport.h" #include "gui/widgets/layout.h" #include "gui/widgets/resizegrip.h" @@ -430,6 +431,9 @@ void Window::mouseMoved(gcn::MouseEvent &event) default: gui->setCursorType(Gui::CURSOR_POINTER); } + + if (viewport) + viewport->hideBeingPopup(); } void Window::mouseDragged(gcn::MouseEvent &event) -- cgit v1.2.3-70-g09d2 From 67e678094b9fddd21fb3c690130e772937ab2746 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Mon, 1 Mar 2010 15:47:15 -0700 Subject: Merge WindowContainer into Viewport and remove extra members Reviewed-by: Chuck Miller --- mana.cbp | 2 -- mana.files | 2 -- src/CMakeLists.txt | 2 -- src/Makefile.am | 2 -- src/game.cpp | 13 +------ src/gui/gui.cpp | 5 ++- src/gui/recorder.cpp | 1 - src/gui/skilldialog.cpp | 4 +-- src/gui/specialswindow.cpp | 4 +-- src/gui/statuswindow.cpp | 6 ++-- src/gui/viewport.cpp | 68 +++++++++++++++++++++---------------- src/gui/viewport.h | 24 +++++++++---- src/gui/widgets/popup.cpp | 23 +++---------- src/gui/widgets/popup.h | 8 ----- src/gui/widgets/window.cpp | 21 ++++-------- src/gui/widgets/window.h | 6 ---- src/gui/widgets/windowcontainer.cpp | 39 --------------------- src/gui/widgets/windowcontainer.h | 59 -------------------------------- src/gui/windowmenu.cpp | 6 ++-- src/localplayer.cpp | 5 --- src/localplayer.h | 13 ------- src/main.h | 5 ++- 22 files changed, 83 insertions(+), 235 deletions(-) delete mode 100644 src/gui/widgets/windowcontainer.cpp delete mode 100644 src/gui/widgets/windowcontainer.h (limited to 'src/gui/viewport.cpp') diff --git a/mana.cbp b/mana.cbp index 6b5e6dd8..2d6c3139 100644 --- a/mana.cbp +++ b/mana.cbp @@ -326,8 +326,6 @@ - - diff --git a/mana.files b/mana.files index 7f775498..6488ec55 100644 --- a/mana.files +++ b/mana.files @@ -270,8 +270,6 @@ ./src/gui/widgets/vertcontainer.h ./src/gui/widgets/whispertab.cpp ./src/gui/widgets/whispertab.h -./src/gui/widgets/windowcontainer.cpp -./src/gui/widgets/windowcontainer.h ./src/gui/widgets/window.cpp ./src/gui/widgets/window.h ./src/gui/windowmenu.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b84e59c6..9a27b610 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -194,8 +194,6 @@ SET(SRCS gui/widgets/whispertab.h gui/widgets/window.cpp gui/widgets/window.h - gui/widgets/windowcontainer.cpp - gui/widgets/windowcontainer.h gui/beingpopup.cpp gui/beingpopup.h gui/buy.cpp diff --git a/src/Makefile.am b/src/Makefile.am index f36fcdf2..61e30978 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -93,8 +93,6 @@ mana_SOURCES = gui/widgets/avatarlistbox.cpp \ gui/widgets/whispertab.h \ gui/widgets/window.cpp \ gui/widgets/window.h \ - gui/widgets/windowcontainer.cpp \ - gui/widgets/windowcontainer.h \ gui/beingpopup.cpp \ gui/beingpopup.h \ gui/buy.cpp \ diff --git a/src/game.cpp b/src/game.cpp index 2b9e932e..8558d421 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -124,7 +124,6 @@ ChannelManager *channelManager = NULL; CommandHandler *commandHandler = NULL; Particle *particleEngine = NULL; EffectManager *effectManager = NULL; -Viewport *viewport = NULL; /**< Viewport on the map. */ ChatTab *localChatTab = NULL; @@ -217,19 +216,10 @@ Game::Game(): disconnectedDialog = NULL; - // Create the viewport - viewport = new Viewport; - viewport->setDimension(gcn::Rectangle(0, 0, graphics->getWidth(), - graphics->getHeight())); - - gcn::Container *top = static_cast(gui->getTop()); - top->add(viewport); - viewport->requestMoveToBottom(); - createGuiWindows(); mWindowMenu = new WindowMenu; - windowContainer->add(mWindowMenu); + viewport->add(mWindowMenu); initEngines(); @@ -276,7 +266,6 @@ Game::~Game() delete commandHandler; delete joystick; delete particleEngine; - delete viewport; delete mCurrentMap; map_path = ""; diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index bc3eb675..2a6e1ce3 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -29,7 +29,6 @@ #include "gui/viewport.h" #include "gui/widgets/window.h" -#include "gui/widgets/windowcontainer.h" #include "configlistener.h" #include "configuration.h" @@ -94,11 +93,11 @@ Gui::Gui(Graphics *graphics): mFocusHandler = new FocusHandler; // Initialize top GUI widget - WindowContainer *guiTop = new WindowContainer; + Viewport *guiTop = new Viewport; + guiTop->setFocusable(true); guiTop->setDimension(gcn::Rectangle(0, 0, graphics->getWidth(), graphics->getHeight())); guiTop->setOpaque(false); - Window::setWindowContainer(guiTop); setTop(guiTop); ResourceManager *resman = ResourceManager::getInstance(); diff --git a/src/gui/recorder.cpp b/src/gui/recorder.cpp index 257afd7f..cbeb435f 100644 --- a/src/gui/recorder.cpp +++ b/src/gui/recorder.cpp @@ -27,7 +27,6 @@ #include "gui/widgets/button.h" #include "gui/widgets/chattab.h" #include "gui/widgets/layout.h" -#include "gui/widgets/windowcontainer.h" #include "utils/gettext.h" #include "utils/stringutils.h" diff --git a/src/gui/skilldialog.cpp b/src/gui/skilldialog.cpp index d53a1867..2c026036 100644 --- a/src/gui/skilldialog.cpp +++ b/src/gui/skilldialog.cpp @@ -26,6 +26,7 @@ #include "gui/setup.h" #include "gui/skin.h" +#include "gui/viewport.h" #include "gui/widgets/button.h" #include "gui/widgets/container.h" @@ -36,7 +37,6 @@ #include "gui/widgets/scrollarea.h" #include "gui/widgets/tab.h" #include "gui/widgets/tabbedarea.h" -#include "gui/widgets/windowcontainer.h" #include "net/net.h" #include "net/playerhandler.h" @@ -188,7 +188,7 @@ SkillDialog::SkillDialog(): setCloseButton(true); setResizable(true); setSaveVisible(true); - setDefaultSize(windowContainer->getWidth() - 280, 30, 275, 425); + setDefaultSize(viewport->getWidth() - 280, 30, 275, 425); setupWindow->registerWindowForReset(this); mTabs = new TabbedArea(); diff --git a/src/gui/specialswindow.cpp b/src/gui/specialswindow.cpp index 3ca0f037..6b5d9afd 100644 --- a/src/gui/specialswindow.cpp +++ b/src/gui/specialswindow.cpp @@ -25,6 +25,7 @@ #include "gui/setup.h" #include "gui/skin.h" +#include "gui/viewport.h" #include "gui/widgets/button.h" #include "gui/widgets/container.h" @@ -37,7 +38,6 @@ #include "gui/widgets/tab.h" #include "gui/widgets/tabbedarea.h" #include "gui/widgets/flowcontainer.h" -#include "gui/widgets/windowcontainer.h" #include "net/net.h" #include "net/specialhandler.h" @@ -88,7 +88,7 @@ SpecialsWindow::SpecialsWindow(): setCloseButton(true); setResizable(true); setSaveVisible(true); - setDefaultSize(windowContainer->getWidth() - 280, 30, 275, 425); + setDefaultSize(viewport->getWidth() - 280, 30, 275, 425); setupWindow->registerWindowForReset(this); mTabs = new TabbedArea(); diff --git a/src/gui/statuswindow.cpp b/src/gui/statuswindow.cpp index 7ea2cf18..48e0ef93 100644 --- a/src/gui/statuswindow.cpp +++ b/src/gui/statuswindow.cpp @@ -26,6 +26,7 @@ #include "gui/ministatus.h" #include "gui/setup.h" +#include "gui/viewport.h" #include "gui/widgets/button.h" #include "gui/widgets/label.h" @@ -33,7 +34,6 @@ #include "gui/widgets/progressbar.h" #include "gui/widgets/scrollarea.h" #include "gui/widgets/vertcontainer.h" -#include "gui/widgets/windowcontainer.h" #include "net/net.h" #include "net/playerhandler.h" @@ -89,8 +89,8 @@ StatusWindow::StatusWindow(): setResizable(true); setCloseButton(true); setSaveVisible(true); - setDefaultSize((windowContainer->getWidth() - 365) / 2, - (windowContainer->getHeight() - 255) / 2, 365, 275); + setDefaultSize((viewport->getWidth() - 365) / 2, + (viewport->getHeight() - 255) / 2, 365, 275); // ---------------------- // Status Part diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 4622c538..99053339 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -43,22 +43,23 @@ #include "resources/monsterinfo.h" #include "resources/resourcemanager.h" +#include "utils/dtor.h" #include "utils/stringutils.h" extern volatile int tick_time; +Viewport *viewport = NULL; + Viewport::Viewport(): mMap(0), mMouseX(0), mMouseY(0), mPixelViewX(0.0f), mPixelViewY(0.0f), - mTileViewX(0), - mTileViewY(0), mShowDebugPath(false), - mVisibleNames(false), mPlayerFollowMouse(false), - mLocalWalkTime(-1) + mLocalWalkTime(-1), + mBeingPopup(0) { setOpaque(false); addMouseListener(this); @@ -67,21 +68,20 @@ Viewport::Viewport(): mScrollRadius = (int) config.getValue("ScrollRadius", 0); mScrollCenterOffsetX = (int) config.getValue("ScrollCenterOffsetX", 0); mScrollCenterOffsetY = (int) config.getValue("ScrollCenterOffsetY", 0); - mVisibleNames = config.getValue("visiblenames", 1); config.addListener("ScrollLaziness", this); config.addListener("ScrollRadius", this); - config.addListener("visiblenames", this); + + viewport = this; mPopupMenu = new PopupMenu; - mBeingPopup = new BeingPopup; + + setFocusable(true); } Viewport::~Viewport() { delete mPopupMenu; - - config.removeListener("visiblenames", this); } void Viewport::setMap(Map *map) @@ -91,6 +91,9 @@ void Viewport::setMap(Map *map) map->setDebugFlags(mMap->getDebugFlags()); } mMap = map; + + if (!mBeingPopup) + mBeingPopup = new BeingPopup; } extern MiniStatusWindow *miniStatusWindow; @@ -104,15 +107,14 @@ void Viewport::draw(gcn::Graphics *gcnGraphics) gcnGraphics->setColor(gcn::Color(64, 64, 64)); gcnGraphics->fillRectangle( gcn::Rectangle(0, 0, getWidth(), getHeight())); + + // Draw contained widgets + Container::draw(gcnGraphics); return; } Graphics *graphics = static_cast(gcnGraphics); - // Ensure the client doesn't freak out if a feature localplayer uses - // is dependent on a map. - player_node->setMapInitialized(true); - // Avoid freaking out when tick_time overflows if (tick_time < lastTick) { @@ -184,9 +186,6 @@ void Viewport::draw(gcn::Graphics *gcnGraphics) mPixelViewY = viewYmax; } - mTileViewX = (int) (mPixelViewX + 16) / 32; - mTileViewY = (int) (mPixelViewY + 16) / 32; - // Draw tiles and sprites if (mMap) { @@ -228,16 +227,22 @@ void Viewport::draw(gcn::Graphics *gcnGraphics) miniStatusWindow->drawIcons(graphics); // Draw contained widgets - WindowContainer::draw(gcnGraphics); + Container::draw(gcnGraphics); } void Viewport::logic() { - WindowContainer::logic(); + delete_all(mDeathList); + mDeathList.clear(); - // Make the player follow the mouse position - // if the mouse is dragged elsewhere than in a window. - _followMouse(); + if (mMap) + { + // Make the player follow the mouse position + // if the mouse is dragged elsewhere than in a window. + _followMouse(); + } + + gcn::Container::logic(); } void Viewport::_followMouse() @@ -423,8 +428,8 @@ void Viewport::mouseDragged(gcn::MouseEvent &event) if (mLocalWalkTime != player_node->getWalkTime()) { mLocalWalkTime = player_node->getWalkTime(); - int destX = event.getX() / 32 + mTileViewX; - int destY = event.getY() / 32 + mTileViewY; + int destX = (event.getX() + mPixelViewX) / mMap->getTileWidth(); + int destY = (event.getY() + mPixelViewY) / mMap->getTileHeight(); player_node->setDestination(destX, destY); } } @@ -454,9 +459,6 @@ void Viewport::optionChanged(const std::string &name) { mScrollLaziness = (int) config.getValue("ScrollLaziness", 32); mScrollRadius = (int) config.getValue("ScrollRadius", 32); - - if (name == "visiblenames") - mVisibleNames = config.getValue("visiblenames", 1); } void Viewport::mouseMoved(gcn::MouseEvent &event) @@ -469,8 +471,10 @@ void Viewport::mouseMoved(gcn::MouseEvent &event) const int y = (event.getY() + (int) mPixelViewY); mHoverBeing = beingManager->findBeingByPixel(x, y); - if (Player *p = dynamic_cast(mHoverBeing)) - mBeingPopup->show(getMouseX(), getMouseY(), p); + if (mHoverBeing && mHoverBeing->getType() == Being::PLAYER && + event.getSource() == this) + mBeingPopup->show(getMouseX(), getMouseY(), + static_cast(mHoverBeing)); else mBeingPopup->setVisible(false); @@ -519,5 +523,11 @@ void Viewport::toggleDebugPath() void Viewport::hideBeingPopup() { - mBeingPopup->setVisible(false); + if (mBeingPopup) + mBeingPopup->setVisible(false); +} + +void Viewport::scheduleDelete(gcn::Widget *widget) +{ + mDeathList.push_back(widget); } diff --git a/src/gui/viewport.h b/src/gui/viewport.h index 3fab607d..196070f1 100644 --- a/src/gui/viewport.h +++ b/src/gui/viewport.h @@ -25,7 +25,7 @@ #include "configlistener.h" #include "position.h" -#include "gui/widgets/windowcontainer.h" +#include "gui/widgets/container.h" #include @@ -50,7 +50,7 @@ const int walkingMouseDelay = 500; * of it such as NPC messages, which are positioned using map pixel * coordinates. */ -class Viewport : public WindowContainer, public gcn::MouseListener, +class Viewport : public Container, public gcn::MouseListener, public ConfigListener { public: @@ -157,6 +157,12 @@ class Viewport : public WindowContainer, public gcn::MouseListener, */ void hideBeingPopup(); + /** + * Schedule a widget for deletion. It will be deleted at the start of + * the next logic update. + */ + void scheduleDelete(gcn::Widget *widget); + private: /** * Finds a path from the player to the mouse, and draws it. This is for @@ -174,6 +180,13 @@ class Viewport : public WindowContainer, public gcn::MouseListener, */ void _followMouse(); + /** + * List of widgets that are scheduled to be deleted. + */ + typedef std::list Widgets; + typedef Widgets::iterator WidgetIterator; + Widgets mDeathList; + Map *mMap; /**< The current map. */ int mScrollRadius; @@ -184,10 +197,7 @@ class Viewport : public WindowContainer, public gcn::MouseListener, int mMouseY; /**< Current mouse position in pixels. */ float mPixelViewX; /**< Current viewpoint in pixels. */ float mPixelViewY; /**< Current viewpoint in pixels. */ - int mTileViewX; /**< Current viewpoint in tiles. */ - int mTileViewY; /**< Current viewpoint in tiles. */ int mShowDebugPath; /**< Show a path from player to pointer. */ - bool mVisibleNames; /**< Show target names. */ bool mPlayerFollowMouse; @@ -196,9 +206,9 @@ class Viewport : public WindowContainer, public gcn::MouseListener, PopupMenu *mPopupMenu; /**< Popup menu. */ Being *mHoverBeing; /**< Being mouse is currently over. */ FloorItem *mHoverItem; /**< FloorItem mouse is currently over. */ - BeingPopup *mBeingPopup; + BeingPopup *mBeingPopup; /**< Being information popup. */ }; -extern Viewport *viewport; /**< The viewport */ +extern Viewport *viewport; /**< The viewport. */ #endif diff --git a/src/gui/widgets/popup.cpp b/src/gui/widgets/popup.cpp index 970b21ec..1bfd7fd2 100644 --- a/src/gui/widgets/popup.cpp +++ b/src/gui/widgets/popup.cpp @@ -29,8 +29,6 @@ #include "gui/skin.h" #include "gui/viewport.h" -#include "gui/widgets/windowcontainer.h" - #include "resources/image.h" #include @@ -45,16 +43,16 @@ Popup::Popup(const std::string &name, const std::string &skin): { logger->log("Popup::Popup(\"%s\")", name.c_str()); - if (!windowContainer) - throw GCN_EXCEPTION("Popup::Popup(): no windowContainer set"); + if (!viewport) + throw GCN_EXCEPTION("Popup::Popup(): no viewport set"); setPadding(3); // Loads the skin mSkin = SkinLoader::instance()->load(skin, mDefaultSkinPath); - // Add this window to the window container - windowContainer->add(this); + // Add this window to the viewport + viewport->add(this); // Popups are invisible by default setVisible(false); @@ -69,11 +67,6 @@ Popup::~Popup() mSkin->instances--; } -void Popup::setWindowContainer(WindowContainer *wc) -{ - windowContainer = wc; -} - void Popup::loadPopupConfiguration() { if (mPopupName.empty()) @@ -168,7 +161,7 @@ void Popup::setMaxHeight(int height) void Popup::scheduleDelete() { - windowContainer->scheduleDelete(this); + viewport->scheduleDelete(this); } void Popup::position(int x, int y) @@ -187,9 +180,3 @@ void Popup::position(int x, int y) setVisible(true); requestMoveToTop(); } - -void Popup::mouseMoved(gcn::MouseEvent &event) -{ - if (viewport) - viewport->hideBeingPopup(); -} diff --git a/src/gui/widgets/popup.h b/src/gui/widgets/popup.h index 5c9164f6..dfa9b2fa 100644 --- a/src/gui/widgets/popup.h +++ b/src/gui/widgets/popup.h @@ -31,7 +31,6 @@ #include class Skin; -class WindowContainer; /** * A light version of the Window class. Particularly suited for popup type @@ -64,11 +63,6 @@ class Popup : public Container, public gcn::MouseListener */ ~Popup(); - /** - * Sets the window container to be used by new popups. - */ - static void setWindowContainer(WindowContainer *windowContainer); - /** * Changes the popup's skin to use the skin defined in the saved * configuration file. @@ -96,8 +90,6 @@ class Popup : public Container, public gcn::MouseListener */ void setLocationRelativeTo(gcn::Widget *widget); - void mouseMoved(gcn::MouseEvent &event); - /** * Sets the minimum width of the popup. */ diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp index 83c918cf..4d70df84 100644 --- a/src/gui/widgets/window.cpp +++ b/src/gui/widgets/window.cpp @@ -31,7 +31,6 @@ #include "gui/widgets/layout.h" #include "gui/widgets/resizegrip.h" -#include "gui/widgets/windowcontainer.h" #include "resources/image.h" @@ -63,8 +62,8 @@ Window::Window(const std::string &caption, bool modal, Window *parent, { logger->log("Window::Window(\"%s\")", caption.c_str()); - if (!windowContainer) - throw GCN_EXCEPTION("Window::Window(): no windowContainer set"); + if (!viewport) + throw GCN_EXCEPTION("Window::Window(): no viewport set"); instances++; @@ -75,8 +74,8 @@ Window::Window(const std::string &caption, bool modal, Window *parent, // Loads the skin mSkin = SkinLoader::instance()->load(skin, mDefaultSkinPath); - // Add this window to the window container - windowContainer->add(this); + // Add this window to the viewport + viewport->add(this); if (mModal) { @@ -88,6 +87,8 @@ Window::Window(const std::string &caption, bool modal, Window *parent, setVisible(false); addWidgetListener(this); + + setFocusable(true); } Window::~Window() @@ -108,11 +109,6 @@ Window::~Window() mSkin->instances--; } -void Window::setWindowContainer(WindowContainer *wc) -{ - windowContainer = wc; -} - void Window::draw(gcn::Graphics *graphics) { Graphics *g = static_cast(graphics); @@ -336,7 +332,7 @@ void Window::setVisible(bool visible, bool forceSticky) void Window::scheduleDelete() { - windowContainer->scheduleDelete(this); + viewport->scheduleDelete(this); } void Window::mousePressed(gcn::MouseEvent &event) @@ -431,9 +427,6 @@ void Window::mouseMoved(gcn::MouseEvent &event) default: gui->setCursorType(Gui::CURSOR_POINTER); } - - if (viewport) - viewport->hideBeingPopup(); } void Window::mouseDragged(gcn::MouseEvent &event) diff --git a/src/gui/widgets/window.h b/src/gui/widgets/window.h index b72be9d4..3c458efe 100644 --- a/src/gui/widgets/window.h +++ b/src/gui/widgets/window.h @@ -34,7 +34,6 @@ class Layout; class LayoutCell; class ResizeGrip; class Skin; -class WindowContainer; /** * A window. This window can be dragged around and has a title bar. Windows are @@ -64,11 +63,6 @@ class Window : public gcn::Window, gcn::WidgetListener */ ~Window(); - /** - * Sets the window container to be used by new windows. - */ - static void setWindowContainer(WindowContainer *windowContainer); - /** * Draws the window. */ diff --git a/src/gui/widgets/windowcontainer.cpp b/src/gui/widgets/windowcontainer.cpp deleted file mode 100644 index 7d5ecd37..00000000 --- a/src/gui/widgets/windowcontainer.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - * The Mana Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * - * This file is part of The Mana Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "gui/widgets/windowcontainer.h" - -#include "utils/dtor.h" - -WindowContainer *windowContainer = NULL; - -void WindowContainer::logic() -{ - delete_all(mDeathList); - mDeathList.clear(); - - gcn::Container::logic(); -} - -void WindowContainer::scheduleDelete(gcn::Widget *widget) -{ - mDeathList.push_back(widget); -} diff --git a/src/gui/widgets/windowcontainer.h b/src/gui/widgets/windowcontainer.h deleted file mode 100644 index 2ec65d15..00000000 --- a/src/gui/widgets/windowcontainer.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * The Mana Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * - * This file is part of The Mana Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef WINDOWCONTAINER_H -#define WINDOWCONTAINER_H - -#include "gui/widgets/container.h" - -/** - * A window container. This container adds functionality for more convenient - * widget (windows in particular) destruction. - * - * \ingroup GUI - */ -class WindowContainer : public Container -{ - public: - /** - * Do GUI logic. This functions adds automatic deletion of objects that - * volunteered to be deleted. - */ - void logic(); - - /** - * Schedule a widget for deletion. It will be deleted at the start of - * the next logic update. - */ - void scheduleDelete(gcn::Widget *widget); - - private: - /** - * List of widgets that are scheduled to be deleted. - */ - typedef std::list Widgets; - typedef Widgets::iterator WidgetIterator; - Widgets mDeathList; -}; - -extern WindowContainer *windowContainer; - -#endif diff --git a/src/gui/windowmenu.cpp b/src/gui/windowmenu.cpp index 81e96fb2..1a497588 100644 --- a/src/gui/windowmenu.cpp +++ b/src/gui/windowmenu.cpp @@ -24,10 +24,10 @@ #include "graphics.h" #include "gui/emotepopup.h" +#include "gui/viewport.h" #include "gui/widgets/button.h" #include "gui/widgets/window.h" -#include "gui/widgets/windowcontainer.h" #include "net/net.h" #include "net/playerhandler.h" @@ -103,7 +103,7 @@ void WindowMenu::action(const gcn::ActionEvent &event) } else { - windowContainer->scheduleDelete(mEmotePopup); + viewport->scheduleDelete(mEmotePopup); mEmotePopup = 0; } } @@ -158,7 +158,7 @@ void WindowMenu::valueChanged(const gcn::SelectionEvent &event) if (emote) Net::getPlayerHandler()->emote(emote); - windowContainer->scheduleDelete(mEmotePopup); + viewport->scheduleDelete(mEmotePopup); mEmotePopup = 0; } } diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 750c8c45..8c918a97 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -103,11 +103,6 @@ LocalPlayer::LocalPlayer(int id, int job): mLocalWalkTime(-1), mMessageTime(0) { - // 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; mTextColor = &guiPalette->getColor(Palette::PLAYER); diff --git a/src/localplayer.h b/src/localplayer.h index 919b5540..69fd4d0f 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -391,17 +391,6 @@ class LocalPlayer : public Player */ bool getCheckNameSetting() const { return mUpdateName; } - /** - * Set if the current map is initialized. - */ - void setMapInitialized(bool initialized) - { mMapInitialized = initialized; } - - /** - * Tells if the current map is initialized. - */ - bool isMapInitialized() const { return mMapInitialized; } - /** Keeps the Equipment related values */ const std::auto_ptr mEquipment; @@ -410,8 +399,6 @@ class LocalPlayer : public Player /** Whether or not the name settings have changed */ bool mUpdateName; - bool mMapInitialized; /**< Whether or not the map is available yet */ - virtual void handleStatusEffect(StatusEffect *effect, int effectId); // Colors don't change for local player diff --git a/src/main.h b/src/main.h index 3f30ef14..ff60508d 100644 --- a/src/main.h +++ b/src/main.h @@ -34,9 +34,8 @@ * \section General General information * * During the game, the current Map is displayed by the main Viewport, which - * is the bottom-most widget in the WindowContainer. Aside the viewport, the - * window container keeps track of all the \link Window Windows\endlink - * displayed during the game. It is the top widget for Guichan. + * also contains all game \link Window Windows\endlink. It is the top + * widget for Guichan. * * A Map is composed of several layers of \link Image Images\endlink (tiles), * a layer with collision information and \link Sprite Sprites\endlink. The -- cgit v1.2.3-70-g09d2 From 76b306a5a2eff9f9a6bb65b3d784cc8e31ba6cce Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Mon, 1 Mar 2010 20:41:41 -0700 Subject: Simplify BeignPopup and therefore Viewport --- src/gui/beingpopup.cpp | 21 ++++++++++++--------- src/gui/beingpopup.h | 8 +++----- src/gui/gui.cpp | 16 ++++++++-------- src/gui/viewport.cpp | 10 +++------- 4 files changed, 26 insertions(+), 29 deletions(-) (limited to 'src/gui/viewport.cpp') diff --git a/src/gui/beingpopup.cpp b/src/gui/beingpopup.cpp index 7fd99371..33fdff44 100644 --- a/src/gui/beingpopup.cpp +++ b/src/gui/beingpopup.cpp @@ -27,7 +27,7 @@ #include "gui/gui.h" #include "gui/palette.h" -#include "gui/widgets/textbox.h" +#include "gui/widgets/label.h" #include "utils/gettext.h" #include "utils/stringutils.h" @@ -39,14 +39,14 @@ BeingPopup::BeingPopup(): Popup("BeingPopup") { // Being Name - mBeingName = new TextBox(); + mBeingName = new Label("A"); mBeingName->setFont(boldFont); mBeingName->setPosition(getPadding(), getPadding()); - const int fontHeight = getFont()->getHeight(); + const int fontHeight = mBeingName->getHeight() + getPadding(); // Being's party - mBeingParty = new TextBox(); + mBeingParty = new Label("A"); mBeingParty->setPosition(getPadding(), fontHeight); add(mBeingName); @@ -69,12 +69,15 @@ void BeingPopup::show(int x, int y, Player *p) if (!(p->getPartyName().empty())) { - mBeingName->setTextWrapped(p->getName(), 196); - mBeingParty->setTextWrapped(strprintf(_("Party: %s"), - p->getPartyName().c_str()), 196); + mBeingName->setCaption(p->getName()); + mBeingName->adjustSize(); - int minWidth = std::max(mBeingName->getMinWidth(), - mBeingParty->getMinWidth()); + mBeingParty->setCaption(strprintf(_("Party: %s"), + p->getPartyName().c_str())); + mBeingParty->adjustSize(); + + int minWidth = std::max(mBeingName->getWidth(), + mBeingParty->getWidth()); const int height = getFont()->getHeight(); diff --git a/src/gui/beingpopup.h b/src/gui/beingpopup.h index 078b84d9..71d9dd2a 100644 --- a/src/gui/beingpopup.h +++ b/src/gui/beingpopup.h @@ -23,10 +23,8 @@ #include "gui/widgets/popup.h" -#include - +class Label; class Player; -class TextBox; /** * A popup that displays information about a being. @@ -52,8 +50,8 @@ class BeingPopup : public Popup // TODO: Add a version for monsters, NPCs, etc? private: - TextBox *mBeingName; - TextBox *mBeingParty; + Label *mBeingName; + Label *mBeingParty; static gcn::Color getColor(); }; diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 2a6e1ce3..c5b77704 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -92,14 +92,6 @@ Gui::Gui(Graphics *graphics): delete mFocusHandler; mFocusHandler = new FocusHandler; - // Initialize top GUI widget - Viewport *guiTop = new Viewport; - guiTop->setFocusable(true); - guiTop->setDimension(gcn::Rectangle(0, 0, - graphics->getWidth(), graphics->getHeight())); - guiTop->setOpaque(false); - setTop(guiTop); - ResourceManager *resman = ResourceManager::getInstance(); // Set global font @@ -132,6 +124,14 @@ Gui::Gui(Graphics *graphics): gcn::Widget::setGlobalFont(mGuiFont); + // Initialize top GUI widget + Viewport *guiTop = new Viewport; + guiTop->setFocusable(true); + guiTop->setDimension(gcn::Rectangle(0, 0, + graphics->getWidth(), graphics->getHeight())); + guiTop->setOpaque(false); + setTop(guiTop); + // Initialize mouse cursor and listen for changes to the option setUseCustomCursor(config.getValue("customcursor", 1) == 1); mConfigListener = new GuiConfigListener(this); diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 99053339..a36f91cf 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -58,8 +58,7 @@ Viewport::Viewport(): mPixelViewY(0.0f), mShowDebugPath(false), mPlayerFollowMouse(false), - mLocalWalkTime(-1), - mBeingPopup(0) + mLocalWalkTime(-1) { setOpaque(false); addMouseListener(this); @@ -75,6 +74,7 @@ Viewport::Viewport(): viewport = this; mPopupMenu = new PopupMenu; + mBeingPopup = new BeingPopup; setFocusable(true); } @@ -91,9 +91,6 @@ void Viewport::setMap(Map *map) map->setDebugFlags(mMap->getDebugFlags()); } mMap = map; - - if (!mBeingPopup) - mBeingPopup = new BeingPopup; } extern MiniStatusWindow *miniStatusWindow; @@ -523,8 +520,7 @@ void Viewport::toggleDebugPath() void Viewport::hideBeingPopup() { - if (mBeingPopup) - mBeingPopup->setVisible(false); + mBeingPopup->setVisible(false); } void Viewport::scheduleDelete(gcn::Widget *widget) -- cgit v1.2.3-70-g09d2 From d194ea8220658b6ef84522f01fa3cf0d0200545e Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Mon, 1 Mar 2010 21:19:31 -0700 Subject: Fix using custom cursors --- src/gui/viewport.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/gui/viewport.cpp') diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index a36f91cf..9633cbd5 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -468,8 +468,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 && - event.getSource() == this) + if (mHoverBeing && mHoverBeing->getType() == Being::PLAYER) mBeingPopup->show(getMouseX(), getMouseY(), static_cast(mHoverBeing)); else @@ -478,6 +477,10 @@ void Viewport::mouseMoved(gcn::MouseEvent &event) mHoverItem = floorItemManager->findByCoordinates(x / mMap->getTileWidth(), y / mMap->getTileHeight()); + // Don't change the cursor if the mouse is over something else + if (event.getSource() != this) + return; + if (mHoverBeing) { switch (mHoverBeing->getType()) -- cgit v1.2.3-70-g09d2 From 4ff5c3b854215b1f55e70106a4c53225fc953619 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 2 Mar 2010 13:34:11 +0000 Subject: Revert "Fix using custom cursors" This reverts commit d194ea8220658b6ef84522f01fa3cf0d0200545e. --- src/gui/viewport.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'src/gui/viewport.cpp') diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 9633cbd5..a36f91cf 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -468,7 +468,8 @@ void Viewport::mouseMoved(gcn::MouseEvent &event) const int y = (event.getY() + (int) mPixelViewY); mHoverBeing = beingManager->findBeingByPixel(x, y); - if (mHoverBeing && mHoverBeing->getType() == Being::PLAYER) + if (mHoverBeing && mHoverBeing->getType() == Being::PLAYER && + event.getSource() == this) mBeingPopup->show(getMouseX(), getMouseY(), static_cast(mHoverBeing)); else @@ -477,10 +478,6 @@ void Viewport::mouseMoved(gcn::MouseEvent &event) mHoverItem = floorItemManager->findByCoordinates(x / mMap->getTileWidth(), y / mMap->getTileHeight()); - // Don't change the cursor if the mouse is over something else - if (event.getSource() != this) - return; - if (mHoverBeing) { switch (mHoverBeing->getType()) -- cgit v1.2.3-70-g09d2 From 0c8c8cf7ea63def0d454f30227584a5f3062c013 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 2 Mar 2010 13:42:14 +0000 Subject: Revert "Merge WindowContainer into Viewport and remove extra members" This reverts commit 67e678094b9fddd21fb3c690130e772937ab2746. Conflicts: src/gui/gui.cpp src/gui/viewport.cpp --- mana.cbp | 2 ++ mana.files | 2 ++ src/CMakeLists.txt | 2 ++ src/Makefile.am | 2 ++ src/game.cpp | 13 +++++++- src/gui/gui.cpp | 19 ++++++------ src/gui/recorder.cpp | 1 + src/gui/skilldialog.cpp | 4 +-- src/gui/specialswindow.cpp | 4 +-- src/gui/statuswindow.cpp | 6 ++-- src/gui/viewport.cpp | 56 ++++++++++++++++------------------- src/gui/viewport.h | 24 +++++---------- src/gui/widgets/popup.cpp | 23 +++++++++++---- src/gui/widgets/popup.h | 8 +++++ src/gui/widgets/window.cpp | 21 ++++++++----- src/gui/widgets/window.h | 6 ++++ src/gui/widgets/windowcontainer.cpp | 39 ++++++++++++++++++++++++ src/gui/widgets/windowcontainer.h | 59 +++++++++++++++++++++++++++++++++++++ src/gui/windowmenu.cpp | 6 ++-- src/localplayer.cpp | 5 ++++ src/localplayer.h | 13 ++++++++ src/main.h | 5 ++-- 22 files changed, 239 insertions(+), 81 deletions(-) create mode 100644 src/gui/widgets/windowcontainer.cpp create mode 100644 src/gui/widgets/windowcontainer.h (limited to 'src/gui/viewport.cpp') diff --git a/mana.cbp b/mana.cbp index 2d6c3139..6b5e6dd8 100644 --- a/mana.cbp +++ b/mana.cbp @@ -326,6 +326,8 @@ + + diff --git a/mana.files b/mana.files index 6488ec55..7f775498 100644 --- a/mana.files +++ b/mana.files @@ -270,6 +270,8 @@ ./src/gui/widgets/vertcontainer.h ./src/gui/widgets/whispertab.cpp ./src/gui/widgets/whispertab.h +./src/gui/widgets/windowcontainer.cpp +./src/gui/widgets/windowcontainer.h ./src/gui/widgets/window.cpp ./src/gui/widgets/window.h ./src/gui/windowmenu.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9a27b610..b84e59c6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -194,6 +194,8 @@ SET(SRCS gui/widgets/whispertab.h gui/widgets/window.cpp gui/widgets/window.h + gui/widgets/windowcontainer.cpp + gui/widgets/windowcontainer.h gui/beingpopup.cpp gui/beingpopup.h gui/buy.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 61e30978..f36fcdf2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -93,6 +93,8 @@ mana_SOURCES = gui/widgets/avatarlistbox.cpp \ gui/widgets/whispertab.h \ gui/widgets/window.cpp \ gui/widgets/window.h \ + gui/widgets/windowcontainer.cpp \ + gui/widgets/windowcontainer.h \ gui/beingpopup.cpp \ gui/beingpopup.h \ gui/buy.cpp \ diff --git a/src/game.cpp b/src/game.cpp index 8558d421..2b9e932e 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -124,6 +124,7 @@ ChannelManager *channelManager = NULL; CommandHandler *commandHandler = NULL; Particle *particleEngine = NULL; EffectManager *effectManager = NULL; +Viewport *viewport = NULL; /**< Viewport on the map. */ ChatTab *localChatTab = NULL; @@ -216,10 +217,19 @@ Game::Game(): disconnectedDialog = NULL; + // Create the viewport + viewport = new Viewport; + viewport->setDimension(gcn::Rectangle(0, 0, graphics->getWidth(), + graphics->getHeight())); + + gcn::Container *top = static_cast(gui->getTop()); + top->add(viewport); + viewport->requestMoveToBottom(); + createGuiWindows(); mWindowMenu = new WindowMenu; - viewport->add(mWindowMenu); + windowContainer->add(mWindowMenu); initEngines(); @@ -266,6 +276,7 @@ Game::~Game() delete commandHandler; delete joystick; delete particleEngine; + delete viewport; delete mCurrentMap; map_path = ""; diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index c5b77704..1e36523c 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -26,9 +26,9 @@ #include "gui/sdlinput.h" #include "gui/skin.h" #include "gui/truetypefont.h" -#include "gui/viewport.h" #include "gui/widgets/window.h" +#include "gui/widgets/windowcontainer.h" #include "configlistener.h" #include "configuration.h" @@ -92,6 +92,15 @@ Gui::Gui(Graphics *graphics): delete mFocusHandler; mFocusHandler = new FocusHandler; + // Initialize top GUI widget + WindowContainer *guiTop = new WindowContainer; + guiTop->setFocusable(true); + guiTop->setDimension(gcn::Rectangle(0, 0, + graphics->getWidth(), graphics->getHeight())); + guiTop->setOpaque(false); + Window::setWindowContainer(guiTop); + setTop(guiTop); + ResourceManager *resman = ResourceManager::getInstance(); // Set global font @@ -124,14 +133,6 @@ Gui::Gui(Graphics *graphics): gcn::Widget::setGlobalFont(mGuiFont); - // Initialize top GUI widget - Viewport *guiTop = new Viewport; - guiTop->setFocusable(true); - guiTop->setDimension(gcn::Rectangle(0, 0, - graphics->getWidth(), graphics->getHeight())); - guiTop->setOpaque(false); - setTop(guiTop); - // Initialize mouse cursor and listen for changes to the option setUseCustomCursor(config.getValue("customcursor", 1) == 1); mConfigListener = new GuiConfigListener(this); diff --git a/src/gui/recorder.cpp b/src/gui/recorder.cpp index cbeb435f..257afd7f 100644 --- a/src/gui/recorder.cpp +++ b/src/gui/recorder.cpp @@ -27,6 +27,7 @@ #include "gui/widgets/button.h" #include "gui/widgets/chattab.h" #include "gui/widgets/layout.h" +#include "gui/widgets/windowcontainer.h" #include "utils/gettext.h" #include "utils/stringutils.h" diff --git a/src/gui/skilldialog.cpp b/src/gui/skilldialog.cpp index 2c026036..d53a1867 100644 --- a/src/gui/skilldialog.cpp +++ b/src/gui/skilldialog.cpp @@ -26,7 +26,6 @@ #include "gui/setup.h" #include "gui/skin.h" -#include "gui/viewport.h" #include "gui/widgets/button.h" #include "gui/widgets/container.h" @@ -37,6 +36,7 @@ #include "gui/widgets/scrollarea.h" #include "gui/widgets/tab.h" #include "gui/widgets/tabbedarea.h" +#include "gui/widgets/windowcontainer.h" #include "net/net.h" #include "net/playerhandler.h" @@ -188,7 +188,7 @@ SkillDialog::SkillDialog(): setCloseButton(true); setResizable(true); setSaveVisible(true); - setDefaultSize(viewport->getWidth() - 280, 30, 275, 425); + setDefaultSize(windowContainer->getWidth() - 280, 30, 275, 425); setupWindow->registerWindowForReset(this); mTabs = new TabbedArea(); diff --git a/src/gui/specialswindow.cpp b/src/gui/specialswindow.cpp index 6b5d9afd..3ca0f037 100644 --- a/src/gui/specialswindow.cpp +++ b/src/gui/specialswindow.cpp @@ -25,7 +25,6 @@ #include "gui/setup.h" #include "gui/skin.h" -#include "gui/viewport.h" #include "gui/widgets/button.h" #include "gui/widgets/container.h" @@ -38,6 +37,7 @@ #include "gui/widgets/tab.h" #include "gui/widgets/tabbedarea.h" #include "gui/widgets/flowcontainer.h" +#include "gui/widgets/windowcontainer.h" #include "net/net.h" #include "net/specialhandler.h" @@ -88,7 +88,7 @@ SpecialsWindow::SpecialsWindow(): setCloseButton(true); setResizable(true); setSaveVisible(true); - setDefaultSize(viewport->getWidth() - 280, 30, 275, 425); + setDefaultSize(windowContainer->getWidth() - 280, 30, 275, 425); setupWindow->registerWindowForReset(this); mTabs = new TabbedArea(); diff --git a/src/gui/statuswindow.cpp b/src/gui/statuswindow.cpp index 48e0ef93..7ea2cf18 100644 --- a/src/gui/statuswindow.cpp +++ b/src/gui/statuswindow.cpp @@ -26,7 +26,6 @@ #include "gui/ministatus.h" #include "gui/setup.h" -#include "gui/viewport.h" #include "gui/widgets/button.h" #include "gui/widgets/label.h" @@ -34,6 +33,7 @@ #include "gui/widgets/progressbar.h" #include "gui/widgets/scrollarea.h" #include "gui/widgets/vertcontainer.h" +#include "gui/widgets/windowcontainer.h" #include "net/net.h" #include "net/playerhandler.h" @@ -89,8 +89,8 @@ StatusWindow::StatusWindow(): setResizable(true); setCloseButton(true); setSaveVisible(true); - setDefaultSize((viewport->getWidth() - 365) / 2, - (viewport->getHeight() - 255) / 2, 365, 275); + setDefaultSize((windowContainer->getWidth() - 365) / 2, + (windowContainer->getHeight() - 255) / 2, 365, 275); // ---------------------- // Status Part diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index a36f91cf..73dee40b 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -43,20 +43,20 @@ #include "resources/monsterinfo.h" #include "resources/resourcemanager.h" -#include "utils/dtor.h" #include "utils/stringutils.h" extern volatile int tick_time; -Viewport *viewport = NULL; - Viewport::Viewport(): mMap(0), mMouseX(0), mMouseY(0), mPixelViewX(0.0f), mPixelViewY(0.0f), + mTileViewX(0), + mTileViewY(0), mShowDebugPath(false), + mVisibleNames(false), mPlayerFollowMouse(false), mLocalWalkTime(-1) { @@ -67,11 +67,11 @@ Viewport::Viewport(): mScrollRadius = (int) config.getValue("ScrollRadius", 0); mScrollCenterOffsetX = (int) config.getValue("ScrollCenterOffsetX", 0); mScrollCenterOffsetY = (int) config.getValue("ScrollCenterOffsetY", 0); + mVisibleNames = config.getValue("visiblenames", 1); config.addListener("ScrollLaziness", this); config.addListener("ScrollRadius", this); - - viewport = this; + config.addListener("visiblenames", this); mPopupMenu = new PopupMenu; mBeingPopup = new BeingPopup; @@ -82,6 +82,8 @@ Viewport::Viewport(): Viewport::~Viewport() { delete mPopupMenu; + + config.removeListener("visiblenames", this); } void Viewport::setMap(Map *map) @@ -104,14 +106,15 @@ void Viewport::draw(gcn::Graphics *gcnGraphics) gcnGraphics->setColor(gcn::Color(64, 64, 64)); gcnGraphics->fillRectangle( gcn::Rectangle(0, 0, getWidth(), getHeight())); - - // Draw contained widgets - Container::draw(gcnGraphics); return; } Graphics *graphics = static_cast(gcnGraphics); + // Ensure the client doesn't freak out if a feature localplayer uses + // is dependent on a map. + player_node->setMapInitialized(true); + // Avoid freaking out when tick_time overflows if (tick_time < lastTick) { @@ -183,6 +186,9 @@ void Viewport::draw(gcn::Graphics *gcnGraphics) mPixelViewY = viewYmax; } + mTileViewX = (int) (mPixelViewX + 16) / 32; + mTileViewY = (int) (mPixelViewY + 16) / 32; + // Draw tiles and sprites if (mMap) { @@ -224,22 +230,16 @@ void Viewport::draw(gcn::Graphics *gcnGraphics) miniStatusWindow->drawIcons(graphics); // Draw contained widgets - Container::draw(gcnGraphics); + WindowContainer::draw(gcnGraphics); } void Viewport::logic() { - delete_all(mDeathList); - mDeathList.clear(); - - if (mMap) - { - // Make the player follow the mouse position - // if the mouse is dragged elsewhere than in a window. - _followMouse(); - } + WindowContainer::logic(); - gcn::Container::logic(); + // Make the player follow the mouse position + // if the mouse is dragged elsewhere than in a window. + _followMouse(); } void Viewport::_followMouse() @@ -425,8 +425,8 @@ void Viewport::mouseDragged(gcn::MouseEvent &event) if (mLocalWalkTime != player_node->getWalkTime()) { mLocalWalkTime = player_node->getWalkTime(); - int destX = (event.getX() + mPixelViewX) / mMap->getTileWidth(); - int destY = (event.getY() + mPixelViewY) / mMap->getTileHeight(); + int destX = event.getX() / 32 + mTileViewX; + int destY = event.getY() / 32 + mTileViewY; player_node->setDestination(destX, destY); } } @@ -456,6 +456,9 @@ void Viewport::optionChanged(const std::string &name) { mScrollLaziness = (int) config.getValue("ScrollLaziness", 32); mScrollRadius = (int) config.getValue("ScrollRadius", 32); + + if (name == "visiblenames") + mVisibleNames = config.getValue("visiblenames", 1); } void Viewport::mouseMoved(gcn::MouseEvent &event) @@ -468,10 +471,8 @@ void Viewport::mouseMoved(gcn::MouseEvent &event) const int y = (event.getY() + (int) mPixelViewY); mHoverBeing = beingManager->findBeingByPixel(x, y); - if (mHoverBeing && mHoverBeing->getType() == Being::PLAYER && - event.getSource() == this) - mBeingPopup->show(getMouseX(), getMouseY(), - static_cast(mHoverBeing)); + if (Player *p = dynamic_cast(mHoverBeing)) + mBeingPopup->show(getMouseX(), getMouseY(), p); else mBeingPopup->setVisible(false); @@ -522,8 +523,3 @@ void Viewport::hideBeingPopup() { mBeingPopup->setVisible(false); } - -void Viewport::scheduleDelete(gcn::Widget *widget) -{ - mDeathList.push_back(widget); -} diff --git a/src/gui/viewport.h b/src/gui/viewport.h index 196070f1..3fab607d 100644 --- a/src/gui/viewport.h +++ b/src/gui/viewport.h @@ -25,7 +25,7 @@ #include "configlistener.h" #include "position.h" -#include "gui/widgets/container.h" +#include "gui/widgets/windowcontainer.h" #include @@ -50,7 +50,7 @@ const int walkingMouseDelay = 500; * of it such as NPC messages, which are positioned using map pixel * coordinates. */ -class Viewport : public Container, public gcn::MouseListener, +class Viewport : public WindowContainer, public gcn::MouseListener, public ConfigListener { public: @@ -157,12 +157,6 @@ class Viewport : public Container, public gcn::MouseListener, */ void hideBeingPopup(); - /** - * Schedule a widget for deletion. It will be deleted at the start of - * the next logic update. - */ - void scheduleDelete(gcn::Widget *widget); - private: /** * Finds a path from the player to the mouse, and draws it. This is for @@ -180,13 +174,6 @@ class Viewport : public Container, public gcn::MouseListener, */ void _followMouse(); - /** - * List of widgets that are scheduled to be deleted. - */ - typedef std::list Widgets; - typedef Widgets::iterator WidgetIterator; - Widgets mDeathList; - Map *mMap; /**< The current map. */ int mScrollRadius; @@ -197,7 +184,10 @@ class Viewport : public Container, public gcn::MouseListener, int mMouseY; /**< Current mouse position in pixels. */ float mPixelViewX; /**< Current viewpoint in pixels. */ float mPixelViewY; /**< Current viewpoint in pixels. */ + int mTileViewX; /**< Current viewpoint in tiles. */ + int mTileViewY; /**< Current viewpoint in tiles. */ int mShowDebugPath; /**< Show a path from player to pointer. */ + bool mVisibleNames; /**< Show target names. */ bool mPlayerFollowMouse; @@ -206,9 +196,9 @@ class Viewport : public Container, public gcn::MouseListener, PopupMenu *mPopupMenu; /**< Popup menu. */ Being *mHoverBeing; /**< Being mouse is currently over. */ FloorItem *mHoverItem; /**< FloorItem mouse is currently over. */ - BeingPopup *mBeingPopup; /**< Being information popup. */ + BeingPopup *mBeingPopup; }; -extern Viewport *viewport; /**< The viewport. */ +extern Viewport *viewport; /**< The viewport */ #endif diff --git a/src/gui/widgets/popup.cpp b/src/gui/widgets/popup.cpp index 1bfd7fd2..970b21ec 100644 --- a/src/gui/widgets/popup.cpp +++ b/src/gui/widgets/popup.cpp @@ -29,6 +29,8 @@ #include "gui/skin.h" #include "gui/viewport.h" +#include "gui/widgets/windowcontainer.h" + #include "resources/image.h" #include @@ -43,16 +45,16 @@ Popup::Popup(const std::string &name, const std::string &skin): { logger->log("Popup::Popup(\"%s\")", name.c_str()); - if (!viewport) - throw GCN_EXCEPTION("Popup::Popup(): no viewport set"); + if (!windowContainer) + throw GCN_EXCEPTION("Popup::Popup(): no windowContainer set"); setPadding(3); // Loads the skin mSkin = SkinLoader::instance()->load(skin, mDefaultSkinPath); - // Add this window to the viewport - viewport->add(this); + // Add this window to the window container + windowContainer->add(this); // Popups are invisible by default setVisible(false); @@ -67,6 +69,11 @@ Popup::~Popup() mSkin->instances--; } +void Popup::setWindowContainer(WindowContainer *wc) +{ + windowContainer = wc; +} + void Popup::loadPopupConfiguration() { if (mPopupName.empty()) @@ -161,7 +168,7 @@ void Popup::setMaxHeight(int height) void Popup::scheduleDelete() { - viewport->scheduleDelete(this); + windowContainer->scheduleDelete(this); } void Popup::position(int x, int y) @@ -180,3 +187,9 @@ void Popup::position(int x, int y) setVisible(true); requestMoveToTop(); } + +void Popup::mouseMoved(gcn::MouseEvent &event) +{ + if (viewport) + viewport->hideBeingPopup(); +} diff --git a/src/gui/widgets/popup.h b/src/gui/widgets/popup.h index dfa9b2fa..5c9164f6 100644 --- a/src/gui/widgets/popup.h +++ b/src/gui/widgets/popup.h @@ -31,6 +31,7 @@ #include class Skin; +class WindowContainer; /** * A light version of the Window class. Particularly suited for popup type @@ -63,6 +64,11 @@ class Popup : public Container, public gcn::MouseListener */ ~Popup(); + /** + * Sets the window container to be used by new popups. + */ + static void setWindowContainer(WindowContainer *windowContainer); + /** * Changes the popup's skin to use the skin defined in the saved * configuration file. @@ -90,6 +96,8 @@ class Popup : public Container, public gcn::MouseListener */ void setLocationRelativeTo(gcn::Widget *widget); + void mouseMoved(gcn::MouseEvent &event); + /** * Sets the minimum width of the popup. */ diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp index 4d70df84..83c918cf 100644 --- a/src/gui/widgets/window.cpp +++ b/src/gui/widgets/window.cpp @@ -31,6 +31,7 @@ #include "gui/widgets/layout.h" #include "gui/widgets/resizegrip.h" +#include "gui/widgets/windowcontainer.h" #include "resources/image.h" @@ -62,8 +63,8 @@ Window::Window(const std::string &caption, bool modal, Window *parent, { logger->log("Window::Window(\"%s\")", caption.c_str()); - if (!viewport) - throw GCN_EXCEPTION("Window::Window(): no viewport set"); + if (!windowContainer) + throw GCN_EXCEPTION("Window::Window(): no windowContainer set"); instances++; @@ -74,8 +75,8 @@ Window::Window(const std::string &caption, bool modal, Window *parent, // Loads the skin mSkin = SkinLoader::instance()->load(skin, mDefaultSkinPath); - // Add this window to the viewport - viewport->add(this); + // Add this window to the window container + windowContainer->add(this); if (mModal) { @@ -87,8 +88,6 @@ Window::Window(const std::string &caption, bool modal, Window *parent, setVisible(false); addWidgetListener(this); - - setFocusable(true); } Window::~Window() @@ -109,6 +108,11 @@ Window::~Window() mSkin->instances--; } +void Window::setWindowContainer(WindowContainer *wc) +{ + windowContainer = wc; +} + void Window::draw(gcn::Graphics *graphics) { Graphics *g = static_cast(graphics); @@ -332,7 +336,7 @@ void Window::setVisible(bool visible, bool forceSticky) void Window::scheduleDelete() { - viewport->scheduleDelete(this); + windowContainer->scheduleDelete(this); } void Window::mousePressed(gcn::MouseEvent &event) @@ -427,6 +431,9 @@ void Window::mouseMoved(gcn::MouseEvent &event) default: gui->setCursorType(Gui::CURSOR_POINTER); } + + if (viewport) + viewport->hideBeingPopup(); } void Window::mouseDragged(gcn::MouseEvent &event) diff --git a/src/gui/widgets/window.h b/src/gui/widgets/window.h index 3c458efe..b72be9d4 100644 --- a/src/gui/widgets/window.h +++ b/src/gui/widgets/window.h @@ -34,6 +34,7 @@ class Layout; class LayoutCell; class ResizeGrip; class Skin; +class WindowContainer; /** * A window. This window can be dragged around and has a title bar. Windows are @@ -63,6 +64,11 @@ class Window : public gcn::Window, gcn::WidgetListener */ ~Window(); + /** + * Sets the window container to be used by new windows. + */ + static void setWindowContainer(WindowContainer *windowContainer); + /** * Draws the window. */ diff --git a/src/gui/widgets/windowcontainer.cpp b/src/gui/widgets/windowcontainer.cpp new file mode 100644 index 00000000..7d5ecd37 --- /dev/null +++ b/src/gui/widgets/windowcontainer.cpp @@ -0,0 +1,39 @@ +/* + * The Mana Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * + * This file is part of The Mana Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "gui/widgets/windowcontainer.h" + +#include "utils/dtor.h" + +WindowContainer *windowContainer = NULL; + +void WindowContainer::logic() +{ + delete_all(mDeathList); + mDeathList.clear(); + + gcn::Container::logic(); +} + +void WindowContainer::scheduleDelete(gcn::Widget *widget) +{ + mDeathList.push_back(widget); +} diff --git a/src/gui/widgets/windowcontainer.h b/src/gui/widgets/windowcontainer.h new file mode 100644 index 00000000..2ec65d15 --- /dev/null +++ b/src/gui/widgets/windowcontainer.h @@ -0,0 +1,59 @@ +/* + * The Mana Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * + * This file is part of The Mana Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef WINDOWCONTAINER_H +#define WINDOWCONTAINER_H + +#include "gui/widgets/container.h" + +/** + * A window container. This container adds functionality for more convenient + * widget (windows in particular) destruction. + * + * \ingroup GUI + */ +class WindowContainer : public Container +{ + public: + /** + * Do GUI logic. This functions adds automatic deletion of objects that + * volunteered to be deleted. + */ + void logic(); + + /** + * Schedule a widget for deletion. It will be deleted at the start of + * the next logic update. + */ + void scheduleDelete(gcn::Widget *widget); + + private: + /** + * List of widgets that are scheduled to be deleted. + */ + typedef std::list Widgets; + typedef Widgets::iterator WidgetIterator; + Widgets mDeathList; +}; + +extern WindowContainer *windowContainer; + +#endif diff --git a/src/gui/windowmenu.cpp b/src/gui/windowmenu.cpp index 1a497588..81e96fb2 100644 --- a/src/gui/windowmenu.cpp +++ b/src/gui/windowmenu.cpp @@ -24,10 +24,10 @@ #include "graphics.h" #include "gui/emotepopup.h" -#include "gui/viewport.h" #include "gui/widgets/button.h" #include "gui/widgets/window.h" +#include "gui/widgets/windowcontainer.h" #include "net/net.h" #include "net/playerhandler.h" @@ -103,7 +103,7 @@ void WindowMenu::action(const gcn::ActionEvent &event) } else { - viewport->scheduleDelete(mEmotePopup); + windowContainer->scheduleDelete(mEmotePopup); mEmotePopup = 0; } } @@ -158,7 +158,7 @@ void WindowMenu::valueChanged(const gcn::SelectionEvent &event) if (emote) Net::getPlayerHandler()->emote(emote); - viewport->scheduleDelete(mEmotePopup); + windowContainer->scheduleDelete(mEmotePopup); mEmotePopup = 0; } } diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 8c918a97..750c8c45 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -103,6 +103,11 @@ LocalPlayer::LocalPlayer(int id, int job): mLocalWalkTime(-1), mMessageTime(0) { + // 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; mTextColor = &guiPalette->getColor(Palette::PLAYER); diff --git a/src/localplayer.h b/src/localplayer.h index 69fd4d0f..919b5540 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -391,6 +391,17 @@ class LocalPlayer : public Player */ bool getCheckNameSetting() const { return mUpdateName; } + /** + * Set if the current map is initialized. + */ + void setMapInitialized(bool initialized) + { mMapInitialized = initialized; } + + /** + * Tells if the current map is initialized. + */ + bool isMapInitialized() const { return mMapInitialized; } + /** Keeps the Equipment related values */ const std::auto_ptr mEquipment; @@ -399,6 +410,8 @@ class LocalPlayer : public Player /** Whether or not the name settings have changed */ bool mUpdateName; + bool mMapInitialized; /**< Whether or not the map is available yet */ + virtual void handleStatusEffect(StatusEffect *effect, int effectId); // Colors don't change for local player diff --git a/src/main.h b/src/main.h index ff60508d..3f30ef14 100644 --- a/src/main.h +++ b/src/main.h @@ -34,8 +34,9 @@ * \section General General information * * During the game, the current Map is displayed by the main Viewport, which - * also contains all game \link Window Windows\endlink. It is the top - * widget for Guichan. + * is the bottom-most widget in the WindowContainer. Aside the viewport, the + * window container keeps track of all the \link Window Windows\endlink + * displayed during the game. It is the top widget for Guichan. * * A Map is composed of several layers of \link Image Images\endlink (tiles), * a layer with collision information and \link Sprite Sprites\endlink. The -- cgit v1.2.3-70-g09d2 From aa676123c375096043721487088bda40ce7653fe Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 2 Mar 2010 14:02:27 +0000 Subject: Remove some unused members Reviewed-by: Chuck Miller --- src/gui/viewport.cpp | 20 +++++--------------- src/gui/viewport.h | 7 ++----- src/localplayer.cpp | 5 ----- src/localplayer.h | 13 ------------- 4 files changed, 7 insertions(+), 38 deletions(-) (limited to 'src/gui/viewport.cpp') diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 73dee40b..a5212e81 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -53,10 +53,7 @@ Viewport::Viewport(): mMouseY(0), mPixelViewX(0.0f), mPixelViewY(0.0f), - mTileViewX(0), - mTileViewY(0), mShowDebugPath(false), - mVisibleNames(false), mPlayerFollowMouse(false), mLocalWalkTime(-1) { @@ -67,11 +64,9 @@ Viewport::Viewport(): mScrollRadius = (int) config.getValue("ScrollRadius", 0); mScrollCenterOffsetX = (int) config.getValue("ScrollCenterOffsetX", 0); mScrollCenterOffsetY = (int) config.getValue("ScrollCenterOffsetY", 0); - mVisibleNames = config.getValue("visiblenames", 1); config.addListener("ScrollLaziness", this); config.addListener("ScrollRadius", this); - config.addListener("visiblenames", this); mPopupMenu = new PopupMenu; mBeingPopup = new BeingPopup; @@ -82,8 +77,7 @@ Viewport::Viewport(): Viewport::~Viewport() { delete mPopupMenu; - - config.removeListener("visiblenames", this); + delete mBeingPopup; } void Viewport::setMap(Map *map) @@ -186,9 +180,6 @@ void Viewport::draw(gcn::Graphics *gcnGraphics) mPixelViewY = viewYmax; } - mTileViewX = (int) (mPixelViewX + 16) / 32; - mTileViewY = (int) (mPixelViewY + 16) / 32; - // Draw tiles and sprites if (mMap) { @@ -425,8 +416,10 @@ void Viewport::mouseDragged(gcn::MouseEvent &event) if (mLocalWalkTime != player_node->getWalkTime()) { mLocalWalkTime = player_node->getWalkTime(); - int destX = event.getX() / 32 + mTileViewX; - int destY = event.getY() / 32 + mTileViewY; + int destX = (event.getX() + mPixelViewX + 16) / + mMap->getTileWidth(); + int destY = (event.getY() + mPixelViewY + 16) / + mMap->getTileHeight(); player_node->setDestination(destX, destY); } } @@ -456,9 +449,6 @@ void Viewport::optionChanged(const std::string &name) { mScrollLaziness = (int) config.getValue("ScrollLaziness", 32); mScrollRadius = (int) config.getValue("ScrollRadius", 32); - - if (name == "visiblenames") - mVisibleNames = config.getValue("visiblenames", 1); } void Viewport::mouseMoved(gcn::MouseEvent &event) diff --git a/src/gui/viewport.h b/src/gui/viewport.h index 3fab607d..e4944cd6 100644 --- a/src/gui/viewport.h +++ b/src/gui/viewport.h @@ -184,10 +184,7 @@ class Viewport : public WindowContainer, public gcn::MouseListener, int mMouseY; /**< Current mouse position in pixels. */ float mPixelViewX; /**< Current viewpoint in pixels. */ float mPixelViewY; /**< Current viewpoint in pixels. */ - int mTileViewX; /**< Current viewpoint in tiles. */ - int mTileViewY; /**< Current viewpoint in tiles. */ int mShowDebugPath; /**< Show a path from player to pointer. */ - bool mVisibleNames; /**< Show target names. */ bool mPlayerFollowMouse; @@ -196,9 +193,9 @@ class Viewport : public WindowContainer, public gcn::MouseListener, PopupMenu *mPopupMenu; /**< Popup menu. */ Being *mHoverBeing; /**< Being mouse is currently over. */ FloorItem *mHoverItem; /**< FloorItem mouse is currently over. */ - BeingPopup *mBeingPopup; + BeingPopup *mBeingPopup; /**< Being information popup. */ }; -extern Viewport *viewport; /**< The viewport */ +extern Viewport *viewport; /**< The viewport. */ #endif diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 750c8c45..8c918a97 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -103,11 +103,6 @@ LocalPlayer::LocalPlayer(int id, int job): mLocalWalkTime(-1), mMessageTime(0) { - // 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; mTextColor = &guiPalette->getColor(Palette::PLAYER); diff --git a/src/localplayer.h b/src/localplayer.h index 919b5540..69fd4d0f 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -391,17 +391,6 @@ class LocalPlayer : public Player */ bool getCheckNameSetting() const { return mUpdateName; } - /** - * Set if the current map is initialized. - */ - void setMapInitialized(bool initialized) - { mMapInitialized = initialized; } - - /** - * Tells if the current map is initialized. - */ - bool isMapInitialized() const { return mMapInitialized; } - /** Keeps the Equipment related values */ const std::auto_ptr mEquipment; @@ -410,8 +399,6 @@ class LocalPlayer : public Player /** Whether or not the name settings have changed */ bool mUpdateName; - bool mMapInitialized; /**< Whether or not the map is available yet */ - virtual void handleStatusEffect(StatusEffect *effect, int effectId); // Colors don't change for local player -- cgit v1.2.3-70-g09d2 From 54ec49e124f84f68f4eedf923fc23db0c3385899 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 2 Mar 2010 14:08:04 +0000 Subject: Forgot a method call --- src/gui/viewport.cpp | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/gui/viewport.cpp') diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index a5212e81..1451b935 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -105,10 +105,6 @@ void Viewport::draw(gcn::Graphics *gcnGraphics) Graphics *graphics = static_cast(gcnGraphics); - // Ensure the client doesn't freak out if a feature localplayer uses - // is dependent on a map. - player_node->setMapInitialized(true); - // Avoid freaking out when tick_time overflows if (tick_time < lastTick) { -- cgit v1.2.3-70-g09d2