Page 1 of 1

Continuous mouse move patch

Posted: 09 Nov 2006, 18:53
by Saphy
As suggested in the wiki, it would be nice if the character can walk continuously instead of click on area again and again. Thus, I have prepared a patch that implement this UI feature.

Code: Select all

diff -Naur src/gui/gui.cpp src/gui/gui.cpp.orig
--- src/gui/gui.cpp.orig   2006-10-29 17:17:41.000000000 -0500
+++ src/gui/gui.cpp     2006-11-09 13:39:18.000000000 -0500
@@ -170,6 +170,7 @@
     config.addListener("customcursor", mConfigListener);

     mPopup = new PopupMenu();
+    buttonState = 0;
 }

 Gui::~Gui()
@@ -331,6 +332,40 @@
             player_node->setTarget(target);
         }
     }
+
+    buttonState = button;
+}
+
+void Gui::mouseMotion(int mx, int my) {
+    // Mouse moved on window container (basically, the map)
+
+    // Only detect mouse motion when LEFT is pressed last
+    if (buttonState != gcn::MouseInput::LEFT)
+       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;
+
+    //Only continue to walk when player has been walking or standing
+    if ((player_node->mAction == Being::WALK || player_node->mAction == Being::STAND) &&
+       engine->getCurrentMap()->getWalk(tilex, tiley))
+    {
+       player_node->setDestination(tilex, tiley);
+       player_node->stopAttack();
+    }
+}
+
+void Gui::mouseRelease(int x, int y, int button)
+{
+    buttonState = 0;
 }

 void
diff -Naur src/gui/gui.h src/gui/gui.h
--- src/gui/gui.orig     2006-10-29 17:17:41.000000000 -0500
+++ src/gui/gui.h       2006-11-09 13:07:57.000000000 -0500
@@ -81,6 +81,8 @@
          */
         void
         mousePress(int mx, int my, int button);
+       void mouseMotion(int mx, int my);
+       void mouseRelease(int x, int y, int button);

         /**
          * Return game font
@@ -122,6 +124,7 @@

         PopupMenu *mPopup;                    /**< Popup window */
         bool mPopupActive;
+       int buttonState;
 };

 extern Gui *gui;                              /**< The GUI system */
Is there a bugzilla where I can submit this patch instead?

Posted: 09 Nov 2006, 20:29
by Crush
you can find the patch tracker here:
http://sourceforge.net/tracker/?group_i ... tid=645620

although patchs tend to be ignored when you don't make some promotion for them on #tmwdev.

Posted: 09 Nov 2006, 21:38
by Saphy
Well, the patch isn't perfect due to limitation of the design. The mouse must move in order for SDL to detect mouseMotion event, so the character will not continue to move if the mouse stopped moving. Where is #tmvdev?

Posted: 09 Nov 2006, 22:09
by Crush
#tmwdev is one of our three IRC chat channels. It is the one that is about the code development. For an explanation how to access our IRC channels please read:
http://forums.themanaworld.org/viewtopic.php?t=747

Posted: 09 Nov 2006, 22:13
by Madcap
Hey Saphy!

#tmvdev is on IRC.freenode.net. If I wasn't so new at using it, I'd post the exact link. But I think it's in a thread somewhere....maybe job postings?

.....there you go....Crush beat me to it.

Posted: 11 Nov 2006, 07:30
by Saphy
Thanks. I have updated my patch again to reduce CPU usage to absolute minimum and it is now possible to move without mouse moving. It is possible afterall. :D

Here's the new patch:

http://sourceforge.net/tracker/download ... id=1594603

Posted: 12 Nov 2006, 04:24
by Saphy
Patch is now updated so that people with crazy video game with fast CPU will not hog the server.

http://sourceforge.net/tracker/download ... id=1594603