summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mana.cbp2
-rw-r--r--mana.files2
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/Makefile.am2
-rw-r--r--src/game.cpp13
-rw-r--r--src/gui/gui.cpp19
-rw-r--r--src/gui/recorder.cpp1
-rw-r--r--src/gui/skilldialog.cpp4
-rw-r--r--src/gui/specialswindow.cpp4
-rw-r--r--src/gui/statuswindow.cpp6
-rw-r--r--src/gui/viewport.cpp56
-rw-r--r--src/gui/viewport.h24
-rw-r--r--src/gui/widgets/popup.cpp23
-rw-r--r--src/gui/widgets/popup.h8
-rw-r--r--src/gui/widgets/window.cpp21
-rw-r--r--src/gui/widgets/window.h6
-rw-r--r--src/gui/widgets/windowcontainer.cpp39
-rw-r--r--src/gui/widgets/windowcontainer.h59
-rw-r--r--src/gui/windowmenu.cpp6
-rw-r--r--src/localplayer.cpp5
-rw-r--r--src/localplayer.h13
-rw-r--r--src/main.h5
22 files changed, 239 insertions, 81 deletions
diff --git a/mana.cbp b/mana.cbp
index 2d6c3139..6b5e6dd8 100644
--- a/mana.cbp
+++ b/mana.cbp
@@ -326,6 +326,8 @@
<Unit filename="src\gui\widgets\whispertab.h" />
<Unit filename="src\gui\widgets\window.cpp" />
<Unit filename="src\gui\widgets\window.h" />
+ <Unit filename="src\gui\widgets\windowcontainer.cpp" />
+ <Unit filename="src\gui\widgets\windowcontainer.h" />
<Unit filename="src\gui\windowmenu.cpp" />
<Unit filename="src\gui\windowmenu.h" />
<Unit filename="src\gui\worldselectdialog.cpp" />
diff --git a/mana.files b/mana.files
index 6488ec55..7f775498 100644
--- a/mana.files
+++ b/mana.files
@@ -270,6 +270,8 @@
./src/gui/widgets/vertcontainer.h
./src/gui/widgets/whispertab.cpp
./src/gui/widgets/whispertab.h
+./src/gui/widgets/windowcontainer.cpp
+./src/gui/widgets/windowcontainer.h
./src/gui/widgets/window.cpp
./src/gui/widgets/window.h
./src/gui/windowmenu.cpp
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 9a27b610..b84e59c6 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -194,6 +194,8 @@ SET(SRCS
gui/widgets/whispertab.h
gui/widgets/window.cpp
gui/widgets/window.h
+ gui/widgets/windowcontainer.cpp
+ gui/widgets/windowcontainer.h
gui/beingpopup.cpp
gui/beingpopup.h
gui/buy.cpp
diff --git a/src/Makefile.am b/src/Makefile.am
index 61e30978..f36fcdf2 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -93,6 +93,8 @@ mana_SOURCES = gui/widgets/avatarlistbox.cpp \
gui/widgets/whispertab.h \
gui/widgets/window.cpp \
gui/widgets/window.h \
+ gui/widgets/windowcontainer.cpp \
+ gui/widgets/windowcontainer.h \
gui/beingpopup.cpp \
gui/beingpopup.h \
gui/buy.cpp \
diff --git a/src/game.cpp b/src/game.cpp
index 8558d421..2b9e932e 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -124,6 +124,7 @@ ChannelManager *channelManager = NULL;
CommandHandler *commandHandler = NULL;
Particle *particleEngine = NULL;
EffectManager *effectManager = NULL;
+Viewport *viewport = NULL; /**< Viewport on the map. */
ChatTab *localChatTab = NULL;
@@ -216,10 +217,19 @@ Game::Game():
disconnectedDialog = NULL;
+ // Create the viewport
+ viewport = new Viewport;
+ viewport->setDimension(gcn::Rectangle(0, 0, graphics->getWidth(),
+ graphics->getHeight()));
+
+ gcn::Container *top = static_cast<gcn::Container*>(gui->getTop());
+ top->add(viewport);
+ viewport->requestMoveToBottom();
+
createGuiWindows();
mWindowMenu = new WindowMenu;
- viewport->add(mWindowMenu);
+ windowContainer->add(mWindowMenu);
initEngines();
@@ -266,6 +276,7 @@ Game::~Game()
delete commandHandler;
delete joystick;
delete particleEngine;
+ delete viewport;
delete mCurrentMap;
map_path = "";
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index c5b77704..1e36523c 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -26,9 +26,9 @@
#include "gui/sdlinput.h"
#include "gui/skin.h"
#include "gui/truetypefont.h"
-#include "gui/viewport.h"
#include "gui/widgets/window.h"
+#include "gui/widgets/windowcontainer.h"
#include "configlistener.h"
#include "configuration.h"
@@ -92,6 +92,15 @@ Gui::Gui(Graphics *graphics):
delete mFocusHandler;
mFocusHandler = new FocusHandler;
+ // Initialize top GUI widget
+ WindowContainer *guiTop = new WindowContainer;
+ guiTop->setFocusable(true);
+ guiTop->setDimension(gcn::Rectangle(0, 0,
+ graphics->getWidth(), graphics->getHeight()));
+ guiTop->setOpaque(false);
+ Window::setWindowContainer(guiTop);
+ setTop(guiTop);
+
ResourceManager *resman = ResourceManager::getInstance();
// Set global font
@@ -124,14 +133,6 @@ Gui::Gui(Graphics *graphics):
gcn::Widget::setGlobalFont(mGuiFont);
- // Initialize top GUI widget
- Viewport *guiTop = new Viewport;
- guiTop->setFocusable(true);
- guiTop->setDimension(gcn::Rectangle(0, 0,
- graphics->getWidth(), graphics->getHeight()));
- guiTop->setOpaque(false);
- setTop(guiTop);
-
// Initialize mouse cursor and listen for changes to the option
setUseCustomCursor(config.getValue("customcursor", 1) == 1);
mConfigListener = new GuiConfigListener(this);
diff --git a/src/gui/recorder.cpp b/src/gui/recorder.cpp
index cbeb435f..257afd7f 100644
--- a/src/gui/recorder.cpp
+++ b/src/gui/recorder.cpp
@@ -27,6 +27,7 @@
#include "gui/widgets/button.h"
#include "gui/widgets/chattab.h"
#include "gui/widgets/layout.h"
+#include "gui/widgets/windowcontainer.h"
#include "utils/gettext.h"
#include "utils/stringutils.h"
diff --git a/src/gui/skilldialog.cpp b/src/gui/skilldialog.cpp
index 2c026036..d53a1867 100644
--- a/src/gui/skilldialog.cpp
+++ b/src/gui/skilldialog.cpp
@@ -26,7 +26,6 @@
#include "gui/setup.h"
#include "gui/skin.h"
-#include "gui/viewport.h"
#include "gui/widgets/button.h"
#include "gui/widgets/container.h"
@@ -37,6 +36,7 @@
#include "gui/widgets/scrollarea.h"
#include "gui/widgets/tab.h"
#include "gui/widgets/tabbedarea.h"
+#include "gui/widgets/windowcontainer.h"
#include "net/net.h"
#include "net/playerhandler.h"
@@ -188,7 +188,7 @@ SkillDialog::SkillDialog():
setCloseButton(true);
setResizable(true);
setSaveVisible(true);
- setDefaultSize(viewport->getWidth() - 280, 30, 275, 425);
+ setDefaultSize(windowContainer->getWidth() - 280, 30, 275, 425);
setupWindow->registerWindowForReset(this);
mTabs = new TabbedArea();
diff --git a/src/gui/specialswindow.cpp b/src/gui/specialswindow.cpp
index 6b5d9afd..3ca0f037 100644
--- a/src/gui/specialswindow.cpp
+++ b/src/gui/specialswindow.cpp
@@ -25,7 +25,6 @@
#include "gui/setup.h"
#include "gui/skin.h"
-#include "gui/viewport.h"
#include "gui/widgets/button.h"
#include "gui/widgets/container.h"
@@ -38,6 +37,7 @@
#include "gui/widgets/tab.h"
#include "gui/widgets/tabbedarea.h"
#include "gui/widgets/flowcontainer.h"
+#include "gui/widgets/windowcontainer.h"
#include "net/net.h"
#include "net/specialhandler.h"
@@ -88,7 +88,7 @@ SpecialsWindow::SpecialsWindow():
setCloseButton(true);
setResizable(true);
setSaveVisible(true);
- setDefaultSize(viewport->getWidth() - 280, 30, 275, 425);
+ setDefaultSize(windowContainer->getWidth() - 280, 30, 275, 425);
setupWindow->registerWindowForReset(this);
mTabs = new TabbedArea();
diff --git a/src/gui/statuswindow.cpp b/src/gui/statuswindow.cpp
index 48e0ef93..7ea2cf18 100644
--- a/src/gui/statuswindow.cpp
+++ b/src/gui/statuswindow.cpp
@@ -26,7 +26,6 @@
#include "gui/ministatus.h"
#include "gui/setup.h"
-#include "gui/viewport.h"
#include "gui/widgets/button.h"
#include "gui/widgets/label.h"
@@ -34,6 +33,7 @@
#include "gui/widgets/progressbar.h"
#include "gui/widgets/scrollarea.h"
#include "gui/widgets/vertcontainer.h"
+#include "gui/widgets/windowcontainer.h"
#include "net/net.h"
#include "net/playerhandler.h"
@@ -89,8 +89,8 @@ StatusWindow::StatusWindow():
setResizable(true);
setCloseButton(true);
setSaveVisible(true);
- setDefaultSize((viewport->getWidth() - 365) / 2,
- (viewport->getHeight() - 255) / 2, 365, 275);
+ setDefaultSize((windowContainer->getWidth() - 365) / 2,
+ (windowContainer->getHeight() - 255) / 2, 365, 275);
// ----------------------
// Status Part
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);
-}
diff --git a/src/gui/viewport.h b/src/gui/viewport.h
index 196070f1..3fab607d 100644
--- a/src/gui/viewport.h
+++ b/src/gui/viewport.h
@@ -25,7 +25,7 @@
#include "configlistener.h"
#include "position.h"
-#include "gui/widgets/container.h"
+#include "gui/widgets/windowcontainer.h"
#include <guichan/mouselistener.hpp>
@@ -50,7 +50,7 @@ const int walkingMouseDelay = 500;
* of it such as NPC messages, which are positioned using map pixel
* coordinates.
*/
-class Viewport : public Container, public gcn::MouseListener,
+class Viewport : public WindowContainer, public gcn::MouseListener,
public ConfigListener
{
public:
@@ -157,12 +157,6 @@ class Viewport : public Container, public gcn::MouseListener,
*/
void hideBeingPopup();
- /**
- * Schedule a widget for deletion. It will be deleted at the start of
- * the next logic update.
- */
- void scheduleDelete(gcn::Widget *widget);
-
private:
/**
* Finds a path from the player to the mouse, and draws it. This is for
@@ -180,13 +174,6 @@ class Viewport : public Container, public gcn::MouseListener,
*/
void _followMouse();
- /**
- * List of widgets that are scheduled to be deleted.
- */
- typedef std::list<gcn::Widget*> Widgets;
- typedef Widgets::iterator WidgetIterator;
- Widgets mDeathList;
-
Map *mMap; /**< The current map. */
int mScrollRadius;
@@ -197,7 +184,10 @@ class Viewport : public Container, public gcn::MouseListener,
int mMouseY; /**< Current mouse position in pixels. */
float mPixelViewX; /**< Current viewpoint in pixels. */
float mPixelViewY; /**< Current viewpoint in pixels. */
+ int mTileViewX; /**< Current viewpoint in tiles. */
+ int mTileViewY; /**< Current viewpoint in tiles. */
int mShowDebugPath; /**< Show a path from player to pointer. */
+ bool mVisibleNames; /**< Show target names. */
bool mPlayerFollowMouse;
@@ -206,9 +196,9 @@ class Viewport : public Container, public gcn::MouseListener,
PopupMenu *mPopupMenu; /**< Popup menu. */
Being *mHoverBeing; /**< Being mouse is currently over. */
FloorItem *mHoverItem; /**< FloorItem mouse is currently over. */
- BeingPopup *mBeingPopup; /**< Being information popup. */
+ BeingPopup *mBeingPopup;
};
-extern Viewport *viewport; /**< The viewport. */
+extern Viewport *viewport; /**< The viewport */
#endif
diff --git a/src/gui/widgets/popup.cpp b/src/gui/widgets/popup.cpp
index 1bfd7fd2..970b21ec 100644
--- a/src/gui/widgets/popup.cpp
+++ b/src/gui/widgets/popup.cpp
@@ -29,6 +29,8 @@
#include "gui/skin.h"
#include "gui/viewport.h"
+#include "gui/widgets/windowcontainer.h"
+
#include "resources/image.h"
#include <guichan/exception.hpp>
@@ -43,16 +45,16 @@ Popup::Popup(const std::string &name, const std::string &skin):
{
logger->log("Popup::Popup(\"%s\")", name.c_str());
- if (!viewport)
- throw GCN_EXCEPTION("Popup::Popup(): no viewport set");
+ if (!windowContainer)
+ throw GCN_EXCEPTION("Popup::Popup(): no windowContainer set");
setPadding(3);
// Loads the skin
mSkin = SkinLoader::instance()->load(skin, mDefaultSkinPath);
- // Add this window to the viewport
- viewport->add(this);
+ // Add this window to the window container
+ windowContainer->add(this);
// Popups are invisible by default
setVisible(false);
@@ -67,6 +69,11 @@ Popup::~Popup()
mSkin->instances--;
}
+void Popup::setWindowContainer(WindowContainer *wc)
+{
+ windowContainer = wc;
+}
+
void Popup::loadPopupConfiguration()
{
if (mPopupName.empty())
@@ -161,7 +168,7 @@ void Popup::setMaxHeight(int height)
void Popup::scheduleDelete()
{
- viewport->scheduleDelete(this);
+ windowContainer->scheduleDelete(this);
}
void Popup::position(int x, int y)
@@ -180,3 +187,9 @@ void Popup::position(int x, int y)
setVisible(true);
requestMoveToTop();
}
+
+void Popup::mouseMoved(gcn::MouseEvent &event)
+{
+ if (viewport)
+ viewport->hideBeingPopup();
+}
diff --git a/src/gui/widgets/popup.h b/src/gui/widgets/popup.h
index dfa9b2fa..5c9164f6 100644
--- a/src/gui/widgets/popup.h
+++ b/src/gui/widgets/popup.h
@@ -31,6 +31,7 @@
#include <guichan/mouselistener.hpp>
class Skin;
+class WindowContainer;
/**
* A light version of the Window class. Particularly suited for popup type
@@ -64,6 +65,11 @@ class Popup : public Container, public gcn::MouseListener
~Popup();
/**
+ * Sets the window container to be used by new popups.
+ */
+ static void setWindowContainer(WindowContainer *windowContainer);
+
+ /**
* Changes the popup's skin to use the skin defined in the saved
* configuration file.
*/
@@ -90,6 +96,8 @@ class Popup : public Container, public gcn::MouseListener
*/
void setLocationRelativeTo(gcn::Widget *widget);
+ void mouseMoved(gcn::MouseEvent &event);
+
/**
* Sets the minimum width of the popup.
*/
diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp
index 4d70df84..83c918cf 100644
--- a/src/gui/widgets/window.cpp
+++ b/src/gui/widgets/window.cpp
@@ -31,6 +31,7 @@
#include "gui/widgets/layout.h"
#include "gui/widgets/resizegrip.h"
+#include "gui/widgets/windowcontainer.h"
#include "resources/image.h"
@@ -62,8 +63,8 @@ Window::Window(const std::string &caption, bool modal, Window *parent,
{
logger->log("Window::Window(\"%s\")", caption.c_str());
- if (!viewport)
- throw GCN_EXCEPTION("Window::Window(): no viewport set");
+ if (!windowContainer)
+ throw GCN_EXCEPTION("Window::Window(): no windowContainer set");
instances++;
@@ -74,8 +75,8 @@ Window::Window(const std::string &caption, bool modal, Window *parent,
// Loads the skin
mSkin = SkinLoader::instance()->load(skin, mDefaultSkinPath);
- // Add this window to the viewport
- viewport->add(this);
+ // Add this window to the window container
+ windowContainer->add(this);
if (mModal)
{
@@ -87,8 +88,6 @@ Window::Window(const std::string &caption, bool modal, Window *parent,
setVisible(false);
addWidgetListener(this);
-
- setFocusable(true);
}
Window::~Window()
@@ -109,6 +108,11 @@ Window::~Window()
mSkin->instances--;
}
+void Window::setWindowContainer(WindowContainer *wc)
+{
+ windowContainer = wc;
+}
+
void Window::draw(gcn::Graphics *graphics)
{
Graphics *g = static_cast<Graphics*>(graphics);
@@ -332,7 +336,7 @@ void Window::setVisible(bool visible, bool forceSticky)
void Window::scheduleDelete()
{
- viewport->scheduleDelete(this);
+ windowContainer->scheduleDelete(this);
}
void Window::mousePressed(gcn::MouseEvent &event)
@@ -427,6 +431,9 @@ void Window::mouseMoved(gcn::MouseEvent &event)
default:
gui->setCursorType(Gui::CURSOR_POINTER);
}
+
+ if (viewport)
+ viewport->hideBeingPopup();
}
void Window::mouseDragged(gcn::MouseEvent &event)
diff --git a/src/gui/widgets/window.h b/src/gui/widgets/window.h
index 3c458efe..b72be9d4 100644
--- a/src/gui/widgets/window.h
+++ b/src/gui/widgets/window.h
@@ -34,6 +34,7 @@ class Layout;
class LayoutCell;
class ResizeGrip;
class Skin;
+class WindowContainer;
/**
* A window. This window can be dragged around and has a title bar. Windows are
@@ -64,6 +65,11 @@ class Window : public gcn::Window, gcn::WidgetListener
~Window();
/**
+ * Sets the window container to be used by new windows.
+ */
+ static void setWindowContainer(WindowContainer *windowContainer);
+
+ /**
* Draws the window.
*/
void draw(gcn::Graphics *graphics);
diff --git a/src/gui/widgets/windowcontainer.cpp b/src/gui/widgets/windowcontainer.cpp
new file mode 100644
index 00000000..7d5ecd37
--- /dev/null
+++ b/src/gui/widgets/windowcontainer.cpp
@@ -0,0 +1,39 @@
+/*
+ * The Mana Client
+ * Copyright (C) 2004-2009 The Mana World Development Team
+ * Copyright (C) 2009-2010 The Mana Developers
+ *
+ * This file is part of The Mana Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "gui/widgets/windowcontainer.h"
+
+#include "utils/dtor.h"
+
+WindowContainer *windowContainer = NULL;
+
+void WindowContainer::logic()
+{
+ delete_all(mDeathList);
+ mDeathList.clear();
+
+ gcn::Container::logic();
+}
+
+void WindowContainer::scheduleDelete(gcn::Widget *widget)
+{
+ mDeathList.push_back(widget);
+}
diff --git a/src/gui/widgets/windowcontainer.h b/src/gui/widgets/windowcontainer.h
new file mode 100644
index 00000000..2ec65d15
--- /dev/null
+++ b/src/gui/widgets/windowcontainer.h
@@ -0,0 +1,59 @@
+/*
+ * The Mana Client
+ * Copyright (C) 2004-2009 The Mana World Development Team
+ * Copyright (C) 2009-2010 The Mana Developers
+ *
+ * This file is part of The Mana Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef WINDOWCONTAINER_H
+#define WINDOWCONTAINER_H
+
+#include "gui/widgets/container.h"
+
+/**
+ * A window container. This container adds functionality for more convenient
+ * widget (windows in particular) destruction.
+ *
+ * \ingroup GUI
+ */
+class WindowContainer : public Container
+{
+ public:
+ /**
+ * Do GUI logic. This functions adds automatic deletion of objects that
+ * volunteered to be deleted.
+ */
+ void logic();
+
+ /**
+ * Schedule a widget for deletion. It will be deleted at the start of
+ * the next logic update.
+ */
+ void scheduleDelete(gcn::Widget *widget);
+
+ private:
+ /**
+ * List of widgets that are scheduled to be deleted.
+ */
+ typedef std::list<gcn::Widget*> Widgets;
+ typedef Widgets::iterator WidgetIterator;
+ Widgets mDeathList;
+};
+
+extern WindowContainer *windowContainer;
+
+#endif
diff --git a/src/gui/windowmenu.cpp b/src/gui/windowmenu.cpp
index 1a497588..81e96fb2 100644
--- a/src/gui/windowmenu.cpp
+++ b/src/gui/windowmenu.cpp
@@ -24,10 +24,10 @@
#include "graphics.h"
#include "gui/emotepopup.h"
-#include "gui/viewport.h"
#include "gui/widgets/button.h"
#include "gui/widgets/window.h"
+#include "gui/widgets/windowcontainer.h"
#include "net/net.h"
#include "net/playerhandler.h"
@@ -103,7 +103,7 @@ void WindowMenu::action(const gcn::ActionEvent &event)
}
else
{
- viewport->scheduleDelete(mEmotePopup);
+ windowContainer->scheduleDelete(mEmotePopup);
mEmotePopup = 0;
}
}
@@ -158,7 +158,7 @@ void WindowMenu::valueChanged(const gcn::SelectionEvent &event)
if (emote)
Net::getPlayerHandler()->emote(emote);
- viewport->scheduleDelete(mEmotePopup);
+ windowContainer->scheduleDelete(mEmotePopup);
mEmotePopup = 0;
}
}
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index 8c918a97..750c8c45 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -103,6 +103,11 @@ LocalPlayer::LocalPlayer(int id, int job):
mLocalWalkTime(-1),
mMessageTime(0)
{
+ // Variable to keep the local player from doing certain actions before a map
+ // is initialized. e.g. drawing a player's name using the TextManager, since
+ // it appears to be dependant upon map coordinates for updating drawing.
+ mMapInitialized = false;
+
mUpdateName = true;
mTextColor = &guiPalette->getColor(Palette::PLAYER);
diff --git a/src/localplayer.h b/src/localplayer.h
index 69fd4d0f..919b5540 100644
--- a/src/localplayer.h
+++ b/src/localplayer.h
@@ -391,6 +391,17 @@ class LocalPlayer : public Player
*/
bool getCheckNameSetting() const { return mUpdateName; }
+ /**
+ * Set if the current map is initialized.
+ */
+ void setMapInitialized(bool initialized)
+ { mMapInitialized = initialized; }
+
+ /**
+ * Tells if the current map is initialized.
+ */
+ bool isMapInitialized() const { return mMapInitialized; }
+
/** Keeps the Equipment related values */
const std::auto_ptr<Equipment> mEquipment;
@@ -399,6 +410,8 @@ class LocalPlayer : public Player
/** Whether or not the name settings have changed */
bool mUpdateName;
+ bool mMapInitialized; /**< Whether or not the map is available yet */
+
virtual void handleStatusEffect(StatusEffect *effect, int effectId);
// Colors don't change for local player
diff --git a/src/main.h b/src/main.h
index ff60508d..3f30ef14 100644
--- a/src/main.h
+++ b/src/main.h
@@ -34,8 +34,9 @@
* \section General General information
*
* During the game, the current Map is displayed by the main Viewport, which
- * also contains all game \link Window Windows\endlink. It is the <i>top</i>
- * widget for Guichan.
+ * is the bottom-most widget in the WindowContainer. Aside the viewport, the
+ * window container keeps track of all the \link Window Windows\endlink
+ * displayed during the game. It is the <i>top</i> widget for Guichan.
*
* A Map is composed of several layers of \link Image Images\endlink (tiles),
* a layer with collision information and \link Sprite Sprites\endlink. The