summaryrefslogtreecommitdiff
path: root/src/gui/viewport.cpp
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2010-03-01 15:47:15 -0700
committerJared Adams <jaxad0127@gmail.com>2010-03-01 17:26:24 -0700
commit67e678094b9fddd21fb3c690130e772937ab2746 (patch)
tree75b2ee140dcdc1e5be24f47f38ec724a47df7103 /src/gui/viewport.cpp
parent3acb148b6d5fe3b342e4397e2c7de020de6005ff (diff)
downloadmana-67e678094b9fddd21fb3c690130e772937ab2746.tar.gz
mana-67e678094b9fddd21fb3c690130e772937ab2746.tar.bz2
mana-67e678094b9fddd21fb3c690130e772937ab2746.tar.xz
mana-67e678094b9fddd21fb3c690130e772937ab2746.zip
Merge WindowContainer into Viewport and remove extra members
Reviewed-by: Chuck Miller
Diffstat (limited to 'src/gui/viewport.cpp')
-rw-r--r--src/gui/viewport.cpp68
1 files changed, 39 insertions, 29 deletions
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index 4622c538..99053339 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -43,22 +43,23 @@
#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)
+ mLocalWalkTime(-1),
+ mBeingPopup(0)
{
setOpaque(false);
addMouseListener(this);
@@ -67,21 +68,20 @@ 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);
- config.addListener("visiblenames", this);
+
+ viewport = this;
mPopupMenu = new PopupMenu;
- mBeingPopup = new BeingPopup;
+
+ setFocusable(true);
}
Viewport::~Viewport()
{
delete mPopupMenu;
-
- config.removeListener("visiblenames", this);
}
void Viewport::setMap(Map *map)
@@ -91,6 +91,9 @@ void Viewport::setMap(Map *map)
map->setDebugFlags(mMap->getDebugFlags());
}
mMap = map;
+
+ if (!mBeingPopup)
+ mBeingPopup = new BeingPopup;
}
extern MiniStatusWindow *miniStatusWindow;
@@ -104,15 +107,14 @@ 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)
{
@@ -184,9 +186,6 @@ void Viewport::draw(gcn::Graphics *gcnGraphics)
mPixelViewY = viewYmax;
}
- mTileViewX = (int) (mPixelViewX + 16) / 32;
- mTileViewY = (int) (mPixelViewY + 16) / 32;
-
// Draw tiles and sprites
if (mMap)
{
@@ -228,16 +227,22 @@ void Viewport::draw(gcn::Graphics *gcnGraphics)
miniStatusWindow->drawIcons(graphics);
// Draw contained widgets
- WindowContainer::draw(gcnGraphics);
+ Container::draw(gcnGraphics);
}
void Viewport::logic()
{
- WindowContainer::logic();
+ delete_all(mDeathList);
+ mDeathList.clear();
- // Make the player follow the mouse position
- // if the mouse is dragged elsewhere than in a window.
- _followMouse();
+ if (mMap)
+ {
+ // Make the player follow the mouse position
+ // if the mouse is dragged elsewhere than in a window.
+ _followMouse();
+ }
+
+ gcn::Container::logic();
}
void Viewport::_followMouse()
@@ -423,8 +428,8 @@ void Viewport::mouseDragged(gcn::MouseEvent &event)
if (mLocalWalkTime != player_node->getWalkTime())
{
mLocalWalkTime = player_node->getWalkTime();
- int destX = event.getX() / 32 + mTileViewX;
- int destY = event.getY() / 32 + mTileViewY;
+ int destX = (event.getX() + mPixelViewX) / mMap->getTileWidth();
+ int destY = (event.getY() + mPixelViewY) / mMap->getTileHeight();
player_node->setDestination(destX, destY);
}
}
@@ -454,9 +459,6 @@ 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)
@@ -469,8 +471,10 @@ void Viewport::mouseMoved(gcn::MouseEvent &event)
const int y = (event.getY() + (int) mPixelViewY);
mHoverBeing = beingManager->findBeingByPixel(x, y);
- if (Player *p = dynamic_cast<Player*>(mHoverBeing))
- mBeingPopup->show(getMouseX(), getMouseY(), p);
+ if (mHoverBeing && mHoverBeing->getType() == Being::PLAYER &&
+ event.getSource() == this)
+ mBeingPopup->show(getMouseX(), getMouseY(),
+ static_cast<Player*>(mHoverBeing));
else
mBeingPopup->setVisible(false);
@@ -519,5 +523,11 @@ void Viewport::toggleDebugPath()
void Viewport::hideBeingPopup()
{
- mBeingPopup->setVisible(false);
+ if (mBeingPopup)
+ mBeingPopup->setVisible(false);
+}
+
+void Viewport::scheduleDelete(gcn::Widget *widget)
+{
+ mDeathList.push_back(widget);
}