diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-09-18 17:49:18 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-09-18 17:49:18 +0300 |
commit | 70b520b1e876f9698bb95baa2d274ea289a0c6bd (patch) | |
tree | 152c7519b0d9b8fb424af2373ec48db823a85575 /src/gui/viewport.cpp | |
parent | 62ec17f6e489ec50f17219444468aeb8969dc961 (diff) | |
parent | 3b999f51c740d0541c53d223518e5e4bb482d996 (diff) | |
download | manaverse-70b520b1e876f9698bb95baa2d274ea289a0c6bd.tar.gz manaverse-70b520b1e876f9698bb95baa2d274ea289a0c6bd.tar.bz2 manaverse-70b520b1e876f9698bb95baa2d274ea289a0c6bd.tar.xz manaverse-70b520b1e876f9698bb95baa2d274ea289a0c6bd.zip |
Merge branch 'master' into strippedstripped1.1.9.18
Conflicts:
src/guichan/cliprectangle.cpp
src/guichan/focushandler.cpp
src/guichan/gui.cpp
src/guichan/include/guichan/cliprectangle.hpp
src/guichan/include/guichan/inputevent.hpp
src/guichan/include/guichan/keyevent.hpp
src/guichan/include/guichan/mouseevent.hpp
src/guichan/include/guichan/widgets/button.hpp
src/guichan/include/guichan/widgets/checkbox.hpp
src/guichan/include/guichan/widgets/dropdown.hpp
src/guichan/include/guichan/widgets/radiobutton.hpp
src/guichan/include/guichan/widgets/slider.hpp
src/guichan/include/guichan/widgets/tab.hpp
src/guichan/include/guichan/widgets/tabbedarea.hpp
src/guichan/include/guichan/widgets/textfield.hpp
src/guichan/include/guichan/widgets/window.hpp
src/guichan/inputevent.cpp
src/guichan/keyevent.cpp
src/guichan/mouseevent.cpp
src/guichan/widget.cpp
src/guichan/widgets/button.cpp
src/guichan/widgets/checkbox.cpp
src/guichan/widgets/dropdown.cpp
src/guichan/widgets/radiobutton.cpp
src/guichan/widgets/slider.cpp
src/guichan/widgets/tab.cpp
src/guichan/widgets/tabbedarea.cpp
src/guichan/widgets/textfield.cpp
src/guichan/widgets/window.cpp
Diffstat (limited to 'src/gui/viewport.cpp')
-rw-r--r-- | src/gui/viewport.cpp | 108 |
1 files changed, 63 insertions, 45 deletions
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index b6e09c011..461dd581d 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -80,11 +80,13 @@ Viewport::Viewport(): mScrollCenterOffsetY = config.getIntValue("ScrollCenterOffsetY"); mShowBeingPopup = config.getBoolValue("showBeingPopup"); mSelfMouseHeal = config.getBoolValue("selfMouseHeal"); + mEnableLazyScrolling = config.getBoolValue("enableLazyScrolling"); config.addListener("ScrollLaziness", this); config.addListener("ScrollRadius", this); config.addListener("showBeingPopup", this); config.addListener("selfMouseHeal", this); + config.addListener("enableLazyScrolling", this); mPopupMenu = new PopupMenu; mBeingPopup = new BeingPopup; @@ -99,6 +101,7 @@ Viewport::~Viewport() config.removeListener("ScrollRadius", this); config.removeListener("showBeingPopup", this); config.removeListener("selfMouseHeal", this); + config.removeListener("enableLazyScrolling", this); delete mPopupMenu; mPopupMenu = 0; @@ -150,59 +153,67 @@ void Viewport::draw(gcn::Graphics *gcnGraphics) int cnt = 0; - // Apply lazy scrolling - while (lastTick < tick_time && cnt < 32) + if (mEnableLazyScrolling) { - if (player_x > static_cast<int>(mPixelViewX) + mScrollRadius) + // Apply lazy scrolling + while (lastTick < tick_time && cnt < 32) { - mPixelViewX += static_cast<float>(player_x - - static_cast<int>(mPixelViewX) - mScrollRadius) / + if (player_x > static_cast<int>(mPixelViewX) + mScrollRadius) + { + mPixelViewX += static_cast<float>(player_x + - static_cast<int>(mPixelViewX) - mScrollRadius) / + static_cast<float>(mScrollLaziness); + } + if (player_x < static_cast<int>(mPixelViewX) - mScrollRadius) + { + mPixelViewX += static_cast<float>(player_x + - static_cast<int>(mPixelViewX) + mScrollRadius) / + static_cast<float>(mScrollLaziness); + } + if (player_y > static_cast<int>(mPixelViewY) + mScrollRadius) + { + mPixelViewY += static_cast<float>(player_y + - static_cast<int>(mPixelViewY) - mScrollRadius) / static_cast<float>(mScrollLaziness); - } - if (player_x < static_cast<int>(mPixelViewX) - mScrollRadius) - { - mPixelViewX += static_cast<float>(player_x - - static_cast<int>(mPixelViewX) + mScrollRadius) / + } + if (player_y < static_cast<int>(mPixelViewY) - mScrollRadius) + { + mPixelViewY += static_cast<float>(player_y + - static_cast<int>(mPixelViewY) + mScrollRadius) / static_cast<float>(mScrollLaziness); + } + lastTick ++; + cnt ++; } - if (player_y > static_cast<int>(mPixelViewY) + mScrollRadius) - { - mPixelViewY += static_cast<float>(player_y - - static_cast<int>(mPixelViewY) - mScrollRadius) / - static_cast<float>(mScrollLaziness); - } - if (player_y < static_cast<int>(mPixelViewY) - mScrollRadius) - { - mPixelViewY += static_cast<float>(player_y - - static_cast<int>(mPixelViewY) + mScrollRadius) / - static_cast<float>(mScrollLaziness); - } - lastTick ++; - cnt ++; - } - // Auto center when player is off screen - 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) + // Auto center when player is off screen + 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 (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) + if (player_x <= 0 || player_y <= 0) { - logger->log("tile position: %d, %d", - player_node->getTileX(), player_node->getTileY()); + 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); } + } + else + { mPixelViewX = static_cast<float>(player_x); mPixelViewY = static_cast<float>(player_y); - }; + } // Don't move camera so that the end of the map is on screen const int viewXmax = @@ -478,7 +489,7 @@ void Viewport::mousePressed(gcn::MouseEvent &event) if (actorSpriteManager) { if (player_node != mHoverBeing || mSelfMouseHeal) - actorSpriteManager->heal(player_node, mHoverBeing); + actorSpriteManager->heal(mHoverBeing); } } else if (player_node->withinAttackRange(mHoverBeing) || @@ -693,9 +704,16 @@ void Viewport::closePopupMenu() void Viewport::optionChanged(const std::string &name A_UNUSED) { - mScrollLaziness = config.getIntValue("ScrollLaziness"); - mScrollRadius = config.getIntValue("ScrollRadius"); - mShowBeingPopup = config.getBoolValue("showBeingPopup"); + if (name == "ScrollLaziness") + mScrollLaziness = config.getIntValue("ScrollLaziness"); + else if (name == "ScrollRadius") + mScrollRadius = config.getIntValue("ScrollRadius"); + else if (name == "showBeingPopup") + mShowBeingPopup = config.getBoolValue("showBeingPopup"); + else if (name == "selfMouseHeal") + mSelfMouseHeal = config.getBoolValue("selfMouseHeal"); + else if (name == "enableLazyScrolling") + mEnableLazyScrolling = config.getBoolValue("enableLazyScrolling"); } void Viewport::mouseMoved(gcn::MouseEvent &event A_UNUSED) |