diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2006-12-04 11:20:54 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2006-12-04 11:20:54 +0000 |
commit | eccafb8d815068d908b998bb6c0b581b076dc78f (patch) | |
tree | 6967d3ca5fa1dc77b177c2f735469503ca04cd14 /src/gui/gui.cpp | |
parent | 061b9e817ffe73acca163510b276e6ca7dd8f6c2 (diff) | |
download | mana-client-eccafb8d815068d908b998bb6c0b581b076dc78f.tar.gz mana-client-eccafb8d815068d908b998bb6c0b581b076dc78f.tar.bz2 mana-client-eccafb8d815068d908b998bb6c0b581b076dc78f.tar.xz mana-client-eccafb8d815068d908b998bb6c0b581b076dc78f.zip |
Introduced a new class Viewport which combines the drawing code from Engine
with the (rather misplaced) input handling from the Gui class. Also, it's a
Container itself which should allow for extending it to show Guichan widgets on
map coordinates.
Diffstat (limited to 'src/gui/gui.cpp')
-rw-r--r-- | src/gui/gui.cpp | 177 |
1 files changed, 9 insertions, 168 deletions
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index cceba658..8d323fb8 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -35,22 +35,14 @@ #endif #include "focushandler.h" -#include "popupmenu.h" #include "window.h" #include "windowcontainer.h" +#include "viewport.h" -#include "../being.h" -#include "../beingmanager.h" #include "../configlistener.h" #include "../configuration.h" -#include "../engine.h" -#include "../flooritemmanager.h" #include "../graphics.h" -#include "../localplayer.h" #include "../log.h" -#include "../main.h" -#include "../map.h" -#include "../npc.h" #include "../resources/image.h" #include "../resources/resourcemanager.h" @@ -58,7 +50,8 @@ // Guichan stuff Gui *gui; -gcn::SDLInput *guiInput; // GUI input +Viewport *viewport; /**< Viewport on the map. */ +gcn::SDLInput *guiInput; /**< GUI input. */ // Fonts used in showing hits gcn::Font *hitRedFont; @@ -88,10 +81,7 @@ class GuiConfigListener : public ConfigListener Gui::Gui(Graphics *graphics): mHostImageLoader(NULL), mMouseCursor(NULL), - mCustomCursor(false), - mPopupActive(false), - mPlayerFollowMouse(false), - mWalkTime(0) + mCustomCursor(false) { logger->log("Initializing GUI..."); // Set graphics @@ -122,7 +112,6 @@ Gui::Gui(Graphics *graphics): guiTop->setDimension(gcn::Rectangle(0, 0, graphics->getWidth(), graphics->getHeight())); guiTop->setOpaque(false); - guiTop->addMouseListener(this); Window::setWindowContainer(guiTop); setTop(guiTop); @@ -172,13 +161,15 @@ Gui::Gui(Graphics *graphics): mConfigListener = new GuiConfigListener(this); config.addListener("customcursor", mConfigListener); - mPopup = new PopupMenu(); + // Create the viewport + viewport = new Viewport(); + viewport->setDimension(gcn::Rectangle(0, 0, + graphics->getWidth(), graphics->getHeight())); + guiTop->add(viewport); } Gui::~Gui() { - delete mPopup; - config.removeListener("customcursor", mConfigListener); delete mConfigListener; @@ -208,16 +199,6 @@ Gui::logic() // Work around Guichan bug of only applying focus on mouse or keyboard // events. mFocusHandler->applyChanges(); - - int mouseX, mouseY; - Uint8 button = SDL_GetMouseState(&mouseX, &mouseY); - - if ( mPlayerFollowMouse && button & SDL_BUTTON(1) && - mWalkTime != player_node -> mWalkTime) - { - player_node->setDestination(mouseX / 32 + camera_x, mouseY / 32 + camera_y); - mWalkTime = player_node -> mWalkTime; - } } void @@ -241,128 +222,6 @@ Gui::draw() } void -Gui::mousePress(int mx, int my, int button) -{ - // Mouse pressed on window container (basically, the map) - mPlayerFollowMouse = false; - - // Are we in-game yet? - if (state != GAME_STATE) - return; - - // Check if we are alive and kickin' - if (!player_node || player_node->mAction == Being::DEAD) - return; - - // Check if we are busy - if (current_npc) - return; - - int tilex = mx / 32 + camera_x; - int tiley = my / 32 + camera_y; - - // Right click might open a popup - if (button == gcn::MouseInput::RIGHT) - { - Being *being; - FloorItem *floorItem; - - if ((being = beingManager->findBeing(tilex, tiley)) && - being->getType() != Being::LOCALPLAYER) - { - showPopup(mx, my, being); - return; - } - else if((floorItem = floorItemManager->findByCoordinates(tilex, tiley))) - { - showPopup(mx, my, floorItem); - return; - } - } - - // If a popup is active, just remove it - if (mPopupActive) - { - mPopup->setVisible(false); - mPopupActive = false; - return; - } - - // Left click can cause different actions - if (button == gcn::MouseInput::LEFT) - { - Being *being; - FloorItem *item; - - // Interact with some being - if ((being = beingManager->findBeing(tilex, tiley))) - { - switch (being->getType()) - { - case Being::NPC: - dynamic_cast<NPC*>(being)->talk(); - break; - - case Being::MONSTER: - case Being::PLAYER: - if (being->mAction == Being::DEAD) - break; - - player_node->attack(being, true); - break; - - default: - break; - } - } - // Pick up some item - else if ((item = floorItemManager->findByCoordinates(tilex, tiley))) - { - player_node->pickUp(item); - } - // Just walk around - else if (engine->getCurrentMap()->getWalk(tilex, tiley)) - { - // XXX XXX XXX REALLY UGLY! - Uint8 *keys = SDL_GetKeyState(NULL); - if (!(keys[SDLK_LSHIFT] || keys[SDLK_RSHIFT])) - { - player_node->setDestination(tilex, tiley); - player_node->stopAttack(); - } - mPlayerFollowMouse = true; - } - } - - if (button == gcn::MouseInput::MIDDLE) - { - // Find the being nearest to the clicked position - Being *target = beingManager->findNearestLivingBeing( - tilex, tiley, - 20, Being::MONSTER); - - if (target) - { - player_node->setTarget(target); - } - } -} - -void -Gui::mouseMotion(int mx, int my) -{ - if (mPlayerFollowMouse && mWalkTime == player_node -> mWalkTime) - player_node->setDestination(mx / 32 + camera_x, my / 32 + camera_y); -} - -void -Gui::mouseRelease(int mx, int my, int button) -{ - mPlayerFollowMouse = false; -} - - -void Gui::setUseCustomCursor(bool customCursor) { if (customCursor != mCustomCursor) @@ -394,21 +253,3 @@ Gui::setUseCustomCursor(bool customCursor) } } } - -void Gui::showPopup(int x, int y, Item *item) -{ - mPopup->showPopup(x, y, item); - mPopupActive = true; -} - -void Gui::showPopup(int x, int y, FloorItem *floorItem) -{ - mPopup->showPopup(x, y, floorItem); - mPopupActive = true; -} - -void Gui::showPopup(int x, int y, Being *being) -{ - mPopup->showPopup(x, y, being); - mPopupActive = true; -} |