summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gui/viewport.cpp26
-rw-r--r--src/gui/viewport.h4
-rw-r--r--src/localplayer.cpp18
-rw-r--r--src/localplayer.h9
4 files changed, 24 insertions, 33 deletions
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index 1b6cfa1c..a8fd452c 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -49,13 +49,15 @@
#include <cassert>
extern volatile int tick_time;
+extern int get_elapsed_time(int start_time);
Viewport::Viewport():
mMap(0),
mViewX(0.0f),
mViewY(0.0f),
mShowDebugPath(false),
- mPlayerFollowMouse(false)
+ mPlayerFollowMouse(false),
+ mLocalWalkTime(-1)
{
setOpaque(false);
addMouseListener(this);
@@ -251,11 +253,12 @@ Viewport::logic()
Uint8 button = SDL_GetMouseState(&mouseX, &mouseY);
if (mPlayerFollowMouse && button & SDL_BUTTON(1) &&
- mWalkTime != player_node->mWalkTime)
+ mWalkTime != player_node->mWalkTime &&
+ get_elapsed_time(mLocalWalkTime) >= walkingMouseDelay)
{
+ mLocalWalkTime = tick_time;
player_node->setDestination(mouseX + (int) mViewX,
- mouseY + (int) mViewY,
- BY_MOUSE);
+ mouseY + (int) mViewY);
mWalkTime = player_node->mWalkTime;
}
@@ -399,12 +402,12 @@ Viewport::mousePressed(gcn::MouseEvent &event)
{
// FIXME: REALLY UGLY!
Uint8 *keys = SDL_GetKeyState(NULL);
- if (!(keys[SDLK_LSHIFT] || keys[SDLK_RSHIFT]))
+ if (!(keys[SDLK_LSHIFT] || keys[SDLK_RSHIFT]) &&
+ get_elapsed_time(mLocalWalkTime) >= walkingMouseDelay)
{
-
+ mLocalWalkTime = tick_time;
player_node->setDestination(event.getX() + (int) mViewX,
- event.getY() + (int) mViewY,
- BY_MOUSE);
+ event.getY() + (int) mViewY);
}
mPlayerFollowMouse = true;
}
@@ -429,11 +432,12 @@ Viewport::mouseDragged(gcn::MouseEvent &event)
if (!mMap || !player_node)
return;
- if (mPlayerFollowMouse && mWalkTime == player_node->mWalkTime)
+ if (mPlayerFollowMouse && mWalkTime == player_node->mWalkTime
+ && get_elapsed_time(mLocalWalkTime) >= walkingMouseDelay)
{
+ mLocalWalkTime = tick_time;
player_node->setDestination(event.getX() + (int) mViewX,
- event.getY() + (int) mViewY,
- BY_MOUSE);
+ event.getY() + (int) mViewY);
}
}
diff --git a/src/gui/viewport.h b/src/gui/viewport.h
index c8f7a9ec..cb47b5fe 100644
--- a/src/gui/viewport.h
+++ b/src/gui/viewport.h
@@ -39,6 +39,9 @@ class PopupMenu;
class Graphics;
class SimpleAnimation;
+/** Delay between two mouse calls when dragging mouse and move the player */
+const int walkingMouseDelay = 500;
+
/**
* The viewport on the map. Displays the current map and handles mouse input
* and the popup menu.
@@ -182,6 +185,7 @@ class Viewport : public WindowContainer, public gcn::MouseListener,
bool mPlayerFollowMouse;
int mWalkTime;
+ int mLocalWalkTime; /**< Timestamp before the next walk can be sent. */
PopupMenu *mPopupMenu; /**< Popup menu. */
};
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index e4c2624e..78dac6f8 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -66,7 +66,6 @@ LocalPlayer::LocalPlayer():
mTrading(false),
mLastAction(-1), mWalkingDir(0),
mDestX(0), mDestY(0),
- mLocalWalkTime(-1),
mExpMessageTime(0)
{
}
@@ -223,8 +222,7 @@ void LocalPlayer::pickUp(FloorItem *item)
Net::GameServer::Player::pickUp(id >> 16, id & 0xFFFF);
mPickUpTarget = NULL;
} else {
- setDestination(item->getX() * 32 + 16, item->getY() * 32 + 16,
- BY_SYSTEM);
+ setDestination(item->getX() * 32 + 16, item->getY() * 32 + 16);
mPickUpTarget = item;
}
}
@@ -264,7 +262,7 @@ void LocalPlayer::walk(unsigned char dir)
// Walk to where the player can actually go
if ((dx || dy) && mMap->getWalk((mX + dx) / 32, (mY + dy) / 32, getWalkMask()))
{
- setDestination(mX + dx, mY + dy, BY_SYSTEM);
+ setDestination(mX + dx, mY + dy);
}
else if (dir)
{
@@ -274,7 +272,7 @@ void LocalPlayer::walk(unsigned char dir)
}
}
-void LocalPlayer::setDestination(Uint16 x, Uint16 y, InputType inputType)
+void LocalPlayer::setDestination(Uint16 x, Uint16 y)
{
// Fix coordinates so that the player does not seem to dig into walls.
int tx = x / 32, ty = y / 32, fx = x % 32, fy = y % 32;
@@ -287,14 +285,6 @@ void LocalPlayer::setDestination(Uint16 x, Uint16 y, InputType inputType)
// Only send a new message to the server when destination changes
if (x != mDestX || y != mDestY)
{
- // Using mouse, Walkings are allowed twice per second
- if (inputType == BY_MOUSE && get_elapsed_time(mLocalWalkTime) < 500) return;
-
- // Using keyboard, Walkings are allowed ten times per second
- if (inputType == BY_KEYBOARD && get_elapsed_time(mLocalWalkTime) < 100) return;
-
- mLocalWalkTime = tick_time;
-
mDestX = x;
mDestY = y;
@@ -302,8 +292,8 @@ void LocalPlayer::setDestination(Uint16 x, Uint16 y, InputType inputType)
particleEngine->addEffect("graphics/particles/hit.particle.xml", x, y);
}
- Being::setDestination(x, y);
mPickUpTarget = NULL;
+ Being::setDestination(x, y);
}
void LocalPlayer::setWalkingDir(int dir)
diff --git a/src/localplayer.h b/src/localplayer.h
index 2813ca77..75a1af7d 100644
--- a/src/localplayer.h
+++ b/src/localplayer.h
@@ -115,11 +115,6 @@ enum
NB_CHARACTER_ATTRIBUTES = CHAR_SKILL_END
};
-enum InputType {
- BY_MOUSE = 0, BY_KEYBOARD, BY_SYSTEM
-};
-
-
/**
* The local player character.
*/
@@ -249,7 +244,7 @@ class LocalPlayer : public Player
/**
* Sets a new destination for this being to walk to.
*/
- void setDestination(Uint16 x, Uint16 y, InputType inputType);
+ void setDestination(Uint16 x, Uint16 y);
/**
* Sets a new direction to keep walking in.
@@ -372,8 +367,6 @@ class LocalPlayer : public Player
int mWalkingDir; /**< The direction the player is walking in. */
int mDestX; /**< X coordinate of destination. */
int mDestY; /**< Y coordinate of destination. */
- int mLocalWalkTime; /**< Time in millisecs before the next walk
- can be sent when using mouse. */
std::list<std::string> mExpMessages; /**< Queued exp messages*/
int mExpMessageTime;