diff options
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | src/gui/gui.cpp | 30 | ||||
-rw-r--r-- | src/gui/gui.h | 14 |
3 files changed, 51 insertions, 2 deletions
@@ -1,3 +1,10 @@ +2006-11-17 Wai Ling Tsang <simotsa@gmail.com> + + * src/gui/gui.cpp: Added mouse following ability/feature under + logic(). + * src/gui/gui.h: Added mouseMotion(), mouseRelease() and private + variables for mouse following. + 2006-11-05 Philipp Sehmisch <tmw@crushnet.org> * data/graphics/tiles/Woodland_village.png, @@ -3386,4 +3393,4 @@ restore some doxygen comments, improved size adaption and made the window a shorter. * data/graphics/images/login_wallpaper.png: New login wallpaper by - Momotaro.
\ No newline at end of file + Momotaro. diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index b7f64274..df2bbaf0 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -89,7 +89,9 @@ Gui::Gui(Graphics *graphics): mHostImageLoader(NULL), mMouseCursor(NULL), mCustomCursor(false), - mPopupActive(false) + mPopupActive(false), + mPlayerFollowMouse(false), + mWalkTime(0) { // Set graphics setGraphics(graphics); @@ -205,6 +207,16 @@ 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 @@ -231,6 +243,7 @@ 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) @@ -316,6 +329,7 @@ Gui::mousePress(int mx, int my, int button) player_node->setDestination(tilex, tiley); player_node->stopAttack(); } + mPlayerFollowMouse = true; } } @@ -334,6 +348,20 @@ Gui::mousePress(int mx, int my, int button) } 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) diff --git a/src/gui/gui.h b/src/gui/gui.h index c4c47a88..0cb3f60b 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -83,6 +83,18 @@ class Gui : public gcn::Gui, public gcn::MouseListener mousePress(int mx, int my, int button); /** + * Handles mouse move on map + */ + void + mouseMotion(int mx, int my); + + /** + * Handles mouse button release on map. + */ + void + mouseRelease(int mx, int my, int button); + + /** * Return game font */ gcn::Font* @@ -122,6 +134,8 @@ class Gui : public gcn::Gui, public gcn::MouseListener PopupMenu *mPopup; /**< Popup window */ bool mPopupActive; + bool mPlayerFollowMouse; + int mWalkTime; }; extern Gui *gui; /**< The GUI system */ |