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.cpp56
1 files changed, 26 insertions, 30 deletions
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index a36f91cf..73dee40b 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -43,20 +43,20 @@
#include "resources/monsterinfo.h"
#include "resources/resourcemanager.h"
-#include "utils/dtor.h"
#include "utils/stringutils.h"
extern volatile int tick_time;
-Viewport *viewport = NULL;
-
Viewport::Viewport():
mMap(0),
mMouseX(0),
mMouseY(0),
mPixelViewX(0.0f),
mPixelViewY(0.0f),
+ mTileViewX(0),
+ mTileViewY(0),
mShowDebugPath(false),
+ mVisibleNames(false),
mPlayerFollowMouse(false),
mLocalWalkTime(-1)
{
@@ -67,11 +67,11 @@ Viewport::Viewport():
mScrollRadius = (int) config.getValue("ScrollRadius", 0);
mScrollCenterOffsetX = (int) config.getValue("ScrollCenterOffsetX", 0);
mScrollCenterOffsetY = (int) config.getValue("ScrollCenterOffsetY", 0);
+ mVisibleNames = config.getValue("visiblenames", 1);
config.addListener("ScrollLaziness", this);
config.addListener("ScrollRadius", this);
-
- viewport = this;
+ config.addListener("visiblenames", this);
mPopupMenu = new PopupMenu;
mBeingPopup = new BeingPopup;
@@ -82,6 +82,8 @@ Viewport::Viewport():
Viewport::~Viewport()
{
delete mPopupMenu;
+
+ config.removeListener("visiblenames", this);
}
void Viewport::setMap(Map *map)
@@ -104,14 +106,15 @@ void Viewport::draw(gcn::Graphics *gcnGraphics)
gcnGraphics->setColor(gcn::Color(64, 64, 64));
gcnGraphics->fillRectangle(
gcn::Rectangle(0, 0, getWidth(), getHeight()));
-
- // Draw contained widgets
- Container::draw(gcnGraphics);
return;
}
Graphics *graphics = static_cast<Graphics*>(gcnGraphics);
+ // Ensure the client doesn't freak out if a feature localplayer uses
+ // is dependent on a map.
+ player_node->setMapInitialized(true);
+
// Avoid freaking out when tick_time overflows
if (tick_time < lastTick)
{
@@ -183,6 +186,9 @@ void Viewport::draw(gcn::Graphics *gcnGraphics)
mPixelViewY = viewYmax;
}
+ mTileViewX = (int) (mPixelViewX + 16) / 32;
+ mTileViewY = (int) (mPixelViewY + 16) / 32;
+
// Draw tiles and sprites
if (mMap)
{
@@ -224,22 +230,16 @@ void Viewport::draw(gcn::Graphics *gcnGraphics)
miniStatusWindow->drawIcons(graphics);
// Draw contained widgets
- Container::draw(gcnGraphics);
+ WindowContainer::draw(gcnGraphics);
}
void Viewport::logic()
{
- delete_all(mDeathList);
- mDeathList.clear();
-
- if (mMap)
- {
- // Make the player follow the mouse position
- // if the mouse is dragged elsewhere than in a window.
- _followMouse();
- }
+ WindowContainer::logic();
- gcn::Container::logic();
+ // Make the player follow the mouse position
+ // if the mouse is dragged elsewhere than in a window.
+ _followMouse();
}
void Viewport::_followMouse()
@@ -425,8 +425,8 @@ void Viewport::mouseDragged(gcn::MouseEvent &event)
if (mLocalWalkTime != player_node->getWalkTime())
{
mLocalWalkTime = player_node->getWalkTime();
- int destX = (event.getX() + mPixelViewX) / mMap->getTileWidth();
- int destY = (event.getY() + mPixelViewY) / mMap->getTileHeight();
+ int destX = event.getX() / 32 + mTileViewX;
+ int destY = event.getY() / 32 + mTileViewY;
player_node->setDestination(destX, destY);
}
}
@@ -456,6 +456,9 @@ void Viewport::optionChanged(const std::string &name)
{
mScrollLaziness = (int) config.getValue("ScrollLaziness", 32);
mScrollRadius = (int) config.getValue("ScrollRadius", 32);
+
+ if (name == "visiblenames")
+ mVisibleNames = config.getValue("visiblenames", 1);
}
void Viewport::mouseMoved(gcn::MouseEvent &event)
@@ -468,10 +471,8 @@ void Viewport::mouseMoved(gcn::MouseEvent &event)
const int y = (event.getY() + (int) mPixelViewY);
mHoverBeing = beingManager->findBeingByPixel(x, y);
- if (mHoverBeing && mHoverBeing->getType() == Being::PLAYER &&
- event.getSource() == this)
- mBeingPopup->show(getMouseX(), getMouseY(),
- static_cast<Player*>(mHoverBeing));
+ if (Player *p = dynamic_cast<Player*>(mHoverBeing))
+ mBeingPopup->show(getMouseX(), getMouseY(), p);
else
mBeingPopup->setVisible(false);
@@ -522,8 +523,3 @@ void Viewport::hideBeingPopup()
{
mBeingPopup->setVisible(false);
}
-
-void Viewport::scheduleDelete(gcn::Widget *widget)
-{
- mDeathList.push_back(widget);
-}