summaryrefslogtreecommitdiff
path: root/src/gui/viewport.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/viewport.cpp')
-rw-r--r--src/gui/viewport.cpp48
1 files changed, 36 insertions, 12 deletions
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index 70d02b016..b6e09c011 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -79,10 +79,12 @@ Viewport::Viewport():
mScrollCenterOffsetX = config.getIntValue("ScrollCenterOffsetX");
mScrollCenterOffsetY = config.getIntValue("ScrollCenterOffsetY");
mShowBeingPopup = config.getBoolValue("showBeingPopup");
+ mSelfMouseHeal = config.getBoolValue("selfMouseHeal");
config.addListener("ScrollLaziness", this);
config.addListener("ScrollRadius", this);
config.addListener("showBeingPopup", this);
+ config.addListener("selfMouseHeal", this);
mPopupMenu = new PopupMenu;
mBeingPopup = new BeingPopup;
@@ -96,6 +98,7 @@ Viewport::~Viewport()
config.removeListener("ScrollLaziness", this);
config.removeListener("ScrollRadius", this);
config.removeListener("showBeingPopup", this);
+ config.removeListener("selfMouseHeal", this);
delete mPopupMenu;
mPopupMenu = 0;
@@ -145,8 +148,10 @@ void Viewport::draw(gcn::Graphics *gcnGraphics)
if (mScrollLaziness < 1)
mScrollLaziness = 1; // Avoids division by zero
+ int cnt = 0;
+
// Apply lazy scrolling
- while (lastTick < tick_time)
+ while (lastTick < tick_time && cnt < 32)
{
if (player_x > static_cast<int>(mPixelViewX) + mScrollRadius)
{
@@ -172,17 +177,29 @@ void Viewport::draw(gcn::Graphics *gcnGraphics)
- static_cast<int>(mPixelViewY) + mScrollRadius) /
static_cast<float>(mScrollLaziness);
}
- lastTick++;
+ lastTick ++;
+ cnt ++;
}
// Auto center when player is off screen
- if (player_x - static_cast<int>(mPixelViewX) > graphics->mWidth / 2
- || static_cast<int>(mPixelViewX) - player_x > graphics->mWidth / 2
- || static_cast<int>(mPixelViewY) - player_y
- > graphics->getHeight() / 2
- || player_y - static_cast<int>(mPixelViewY)
- > graphics->getHeight() / 2)
+ if (cnt > 30 || player_x - static_cast<int>(mPixelViewX)
+ > graphics->mWidth / 2 || static_cast<int>(mPixelViewX)
+ - player_x > graphics->mWidth / 2 || static_cast<int>(mPixelViewY)
+ - player_y > graphics->getHeight() / 2 || player_y
+ - static_cast<int>(mPixelViewY) > graphics->getHeight() / 2)
{
+ if (player_x <= 0 || player_y <= 0)
+ {
+ if (debugChatTab)
+ debugChatTab->chatLog("incorrect player position!");
+ logger->log("incorrect player position: %d, %d, %d, %d",
+ player_x, player_y, (int)mPixelViewX, (int)mPixelViewY);
+ if (player_node)
+ {
+ logger->log("tile position: %d, %d",
+ player_node->getTileX(), player_node->getTileY());
+ }
+ }
mPixelViewX = static_cast<float>(player_x);
mPixelViewY = static_cast<float>(player_y);
};
@@ -459,17 +476,24 @@ void Viewport::mousePressed(gcn::MouseEvent &event)
if (mHoverBeing->getType() == ActorSprite::PLAYER)
{
if (actorSpriteManager)
- actorSpriteManager->heal(player_node, mHoverBeing);
+ {
+ if (player_node != mHoverBeing || mSelfMouseHeal)
+ actorSpriteManager->heal(player_node, mHoverBeing);
+ }
}
else if (player_node->withinAttackRange(mHoverBeing) ||
keyboard.isKeyActive(keyboard.KEY_ATTACK))
{
- player_node->attack(mHoverBeing,
- !keyboard.isKeyActive(keyboard.KEY_TARGET));
+ if (player_node != mHoverBeing)
+ {
+ player_node->attack(mHoverBeing,
+ !keyboard.isKeyActive(keyboard.KEY_TARGET));
+ }
}
else if (!keyboard.isKeyActive(keyboard.KEY_ATTACK))
{
- player_node->setGotoTarget(mHoverBeing);
+ if (player_node != mHoverBeing)
+ player_node->setGotoTarget(mHoverBeing);
}
}
// Picks up a item if we clicked on one