summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2012-07-31 20:05:33 +0200
committerThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2012-08-01 23:05:45 +0200
commita61c57070aa618ac749e4a90a2b83c0e3a15e5fd (patch)
tree797bf52349e73aaeb2d46e421e8a798478deecb7
parent9dd1d4339fd186927b35b64024ee88ba615f2a25 (diff)
downloadmana-a61c57070aa618ac749e4a90a2b83c0e3a15e5fd.tar.gz
mana-a61c57070aa618ac749e4a90a2b83c0e3a15e5fd.tar.bz2
mana-a61c57070aa618ac749e4a90a2b83c0e3a15e5fd.tar.xz
mana-a61c57070aa618ac749e4a90a2b83c0e3a15e5fd.zip
Some positioning changes in the game UI
Moved player status bars to the top-right, next to the window menu. Used the layout for dynamic adjustments to screen resolution.
-rw-r--r--src/game.cpp28
-rw-r--r--src/game.h8
-rw-r--r--src/gui/ministatuswindow.cpp55
-rw-r--r--src/gui/ministatuswindow.h13
-rw-r--r--src/gui/viewport.cpp5
-rw-r--r--src/gui/widgets/container.cpp8
-rw-r--r--src/gui/widgets/container.h7
-rw-r--r--src/gui/widgets/popup.cpp5
-rw-r--r--src/gui/widgets/popup.h5
-rw-r--r--src/gui/windowmenu.cpp8
10 files changed, 78 insertions, 64 deletions
diff --git a/src/game.cpp b/src/game.cpp
index aa4be543..07ead33f 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -64,10 +64,12 @@
#include "gui/textdialog.h"
#include "gui/tradewindow.h"
#include "gui/viewport.h"
+#include "gui/windowmenu.h"
#include "gui/widgets/chattab.h"
#include "gui/widgets/emoteshortcutcontainer.h"
#include "gui/widgets/itemshortcutcontainer.h"
+#include "gui/widgets/layout.h"
#include "net/gamehandler.h"
#include "net/generalhandler.h"
@@ -98,7 +100,6 @@ QuitDialog *quitDialog = NULL;
ChatWindow *chatWindow;
StatusWindow *statusWindow;
-MiniStatusWindow *miniStatusWindow;
InventoryWindow *inventoryWindow;
SkillDialog *skillDialog;
Minimap *minimap;
@@ -148,7 +149,6 @@ static void createGuiWindows()
setupWindow->clearWindowsForReset();
// Create dialogs
- miniStatusWindow = new MiniStatusWindow;
minimap = new Minimap;
chatWindow = new ChatWindow;
tradeWindow = new TradeWindow;
@@ -160,9 +160,9 @@ static void createGuiWindows()
debugWindow = new DebugWindow;
itemShortcutWindow = new ShortcutWindow("ItemShortcut",
new ItemShortcutContainer);
- outfitWindow = new OutfitWindow();
- specialsWindow = new SpecialsWindow();
- socialWindow = new SocialWindow();
+ outfitWindow = new OutfitWindow;
+ specialsWindow = new SpecialsWindow;
+ socialWindow = new SocialWindow;
localChatTab = new ChatTab(_("General"));
@@ -183,7 +183,6 @@ static void destroyGuiWindows()
del_0(localChatTab) // Need to do this first, so it can remove itself
del_0(chatWindow)
del_0(statusWindow)
- del_0(miniStatusWindow)
del_0(inventoryWindow)
del_0(skillDialog)
del_0(minimap)
@@ -219,10 +218,14 @@ Game::Game():
top->add(viewport);
viewport->requestMoveToBottom();
- createGuiWindows();
-
mWindowMenu = new WindowMenu;
- windowContainer->add(mWindowMenu);
+ mMiniStatusWindow = new MiniStatusWindow;
+
+ windowContainer->place(2, 0, mMiniStatusWindow);
+ windowContainer->place(1, 0, mWindowMenu).setHAlign(Layout::RIGHT);
+ windowContainer->updateLayout();
+
+ createGuiWindows();
initEngines();
@@ -245,6 +248,7 @@ Game::~Game()
Event::trigger(Event::GameChannel, Event::Destructing);
delete mWindowMenu;
+ delete mMiniStatusWindow;
destroyGuiWindows();
@@ -976,8 +980,12 @@ int Game::getCurrentTileHeight() const
return DEFAULT_TILE_LENGTH;
}
+void Game::updateWindowMenuCaptions()
+{
+ mWindowMenu->updatePopUpCaptions();
+}
+
void Game::videoResized(int width, int height)
{
viewport->setSize(width, height);
- mWindowMenu->setPosition(width - 3 - mWindowMenu->getWidth(), 3);
}
diff --git a/src/game.h b/src/game.h
index 3287ff43..4986d591 100644
--- a/src/game.h
+++ b/src/game.h
@@ -24,9 +24,9 @@
#include <string>
-#include "gui/windowmenu.h"
-
class Map;
+class WindowMenu;
+class MiniStatusWindow;
/**
* The main class responsible for running the game. The game starts after you
@@ -77,8 +77,7 @@ class Game
/**
* Update the key shortcuts in the window menu.
*/
- void updateWindowMenuCaptions()
- { mWindowMenu->updatePopUpCaptions(); }
+ void updateWindowMenuCaptions();
void videoResized(int width, int height);
@@ -87,6 +86,7 @@ class Game
bool mDisconnected;
WindowMenu *mWindowMenu;
+ MiniStatusWindow *mMiniStatusWindow;
Map *mCurrentMap;
std::string mMapName;
diff --git a/src/gui/ministatuswindow.cpp b/src/gui/ministatuswindow.cpp
index 9c55a9c8..86dd4adf 100644
--- a/src/gui/ministatuswindow.cpp
+++ b/src/gui/ministatuswindow.cpp
@@ -32,6 +32,7 @@
#include "gui/textpopup.h"
#include "gui/widgets/progressbar.h"
+#include "gui/widgets/layout.h"
#include "net/net.h"
#include "net/playerhandler.h"
@@ -46,8 +47,7 @@
extern volatile int tick_time;
-MiniStatusWindow::MiniStatusWindow():
- Popup("MiniStatus")
+MiniStatusWindow::MiniStatusWindow()
{
listen(Event::AttributesChannel);
listen(Event::ActorSpriteChannel);
@@ -71,23 +71,22 @@ MiniStatusWindow::MiniStatusWindow():
// Add the progressbars to the window
- mHpBar->setPosition(0, 3);
+ int row = 0;
+ place(0, row++, mHpBar);
if (mMpBar)
- mMpBar->setPosition(mHpBar->getWidth() + 3, 3);
- mXpBar->setPosition(mMpBar ? mMpBar->getX() + mMpBar->getWidth() + 3 :
- mHpBar->getX() + mHpBar->getWidth() + 3, 3);
+ place(0, row++, mMpBar);
+ place(0, row++, mXpBar);
- add(mHpBar);
- if (mMpBar)
- add(mMpBar);
- add(mXpBar);
-
- setContentSize(mXpBar->getX() + mXpBar->getWidth(),
- mXpBar->getY() + mXpBar->getHeight());
+ Layout &layout = getLayout();
+ layout.setMargin(0);
- setVisible((bool) config.getValue(getPopupName() + "Visible", true));
+ int w = 0;
+ int h = 0;
+ layout.reflow(w, h);
+ setSize(w, h);
- mTextPopup = new TextPopup();
+ mTextPopup = new TextPopup;
+ setVisible(true);
addMouseListener(this);
}
@@ -173,14 +172,18 @@ void MiniStatusWindow::event(Event::Channel channel,
{
// delete sprite, if necessary
for (unsigned int i = 0; i < mStatusEffectIcons.size();)
+ {
if (mStatusEffectIcons[i] == index)
{
mStatusEffectIcons.erase(mStatusEffectIcons.begin()
+ i);
- miniStatusWindow->eraseIcon(i);
+ eraseIcon(i);
}
else
- i++;
+ {
+ ++i;
+ }
+ }
}
else
{
@@ -189,17 +192,19 @@ void MiniStatusWindow::event(Event::Channel channel,
for (unsigned int i = 0; i < mStatusEffectIcons.size();
i++)
+ {
if (mStatusEffectIcons[i] == index)
{
- miniStatusWindow->setIcon(i, sprite);
+ setIcon(i, sprite);
found = true;
break;
}
+ }
if (!found)
{ // add new
int offset = mStatusEffectIcons.size();
- miniStatusWindow->setIcon(offset, sprite);
+ setIcon(offset, sprite);
mStatusEffectIcons.push_back(index);
}
}
@@ -210,7 +215,7 @@ void MiniStatusWindow::event(Event::Channel channel,
void MiniStatusWindow::logic()
{
- Popup::logic();
+ Container::logic();
// Displays the number of monsters to next lvl
// (disabled for now but interesting idea)
@@ -230,10 +235,14 @@ void MiniStatusWindow::logic()
mIcons[i]->update(tick_time * 10);
}
-void MiniStatusWindow::mouseMoved(gcn::MouseEvent &event)
+void MiniStatusWindow::draw(gcn::Graphics *graphics)
{
- Popup::mouseMoved(event);
+ drawChildren(graphics);
+ drawIcons(static_cast<Graphics*>(graphics));
+}
+void MiniStatusWindow::mouseMoved(gcn::MouseEvent &event)
+{
const int x = event.getX();
const int y = event.getY();
@@ -266,7 +275,5 @@ void MiniStatusWindow::mouseMoved(gcn::MouseEvent &event)
void MiniStatusWindow::mouseExited(gcn::MouseEvent &event)
{
- Popup::mouseExited(event);
-
mTextPopup->setVisible(false);
}
diff --git a/src/gui/ministatuswindow.h b/src/gui/ministatuswindow.h
index b4392b6f..a9939fcd 100644
--- a/src/gui/ministatuswindow.h
+++ b/src/gui/ministatuswindow.h
@@ -24,7 +24,9 @@
#include "eventlistener.h"
-#include "gui/widgets/popup.h"
+#include "gui/widgets/container.h"
+
+#include <guichan/mouselistener.hpp>
#include <vector>
@@ -38,7 +40,9 @@ class TextPopup;
*
* \ingroup Interface
*/
-class MiniStatusWindow : public Popup, public EventListener
+class MiniStatusWindow : public Container,
+ public EventListener,
+ public gcn::MouseListener
{
public:
MiniStatusWindow();
@@ -49,8 +53,7 @@ class MiniStatusWindow : public Popup, public EventListener
void logic(); // Updates icons
- void draw(gcn::Graphics *graphics)
- { drawChildren(graphics); }
+ void draw(gcn::Graphics *graphics);
void mouseMoved(gcn::MouseEvent &mouseEvent);
void mouseExited(gcn::MouseEvent &event);
@@ -77,6 +80,4 @@ class MiniStatusWindow : public Popup, public EventListener
std::vector<AnimatedSprite *> mIcons;
};
-extern MiniStatusWindow *miniStatusWindow;
-
#endif
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index 0aab399c..e93c285d 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -179,7 +179,7 @@ void Viewport::draw(gcn::Graphics *gcnGraphics)
{
mPixelViewX = player_x;
mPixelViewY = player_y;
- };
+ }
// Don't move camera so that the end of the map is on screen
const int mapWidthPixels = mMap->getWidth() * mMap->getTileWidth();
@@ -249,9 +249,6 @@ void Viewport::draw(gcn::Graphics *gcnGraphics)
b->drawSpeech((int) mPixelViewX, (int) mPixelViewY);
}
- if (miniStatusWindow)
- miniStatusWindow->drawIcons(graphics);
-
// Draw contained widgets
WindowContainer::draw(gcnGraphics);
}
diff --git a/src/gui/widgets/container.cpp b/src/gui/widgets/container.cpp
index e1b99af7..a2b3ee78 100644
--- a/src/gui/widgets/container.cpp
+++ b/src/gui/widgets/container.cpp
@@ -54,3 +54,11 @@ ContainerPlacer Container::getPlacer(int x, int y)
{
return ContainerPlacer(this, &getLayout().at(x, y));
}
+
+void Container::updateLayout()
+{
+ const gcn::Rectangle area = getChildrenArea();
+ int w = area.width;
+ int h = area.height;
+ getLayout().reflow(w, h);
+}
diff --git a/src/gui/widgets/container.h b/src/gui/widgets/container.h
index 46b719a1..2b8039f4 100644
--- a/src/gui/widgets/container.h
+++ b/src/gui/widgets/container.h
@@ -44,7 +44,6 @@ class Container : public gcn::Container
Container();
~Container();
- protected:
/**
* Gets the layout handler for this container.
*/
@@ -60,6 +59,12 @@ class Container : public gcn::Container
*/
ContainerPlacer getPlacer(int x, int y);
+ /**
+ * Updates the layout to match the available size in the container
+ * (happens automatically on resizes).
+ */
+ void updateLayout();
+
private:
LayoutHelper *mLayoutHelper;
};
diff --git a/src/gui/widgets/popup.cpp b/src/gui/widgets/popup.cpp
index 3b80fe5e..f71714ed 100644
--- a/src/gui/widgets/popup.cpp
+++ b/src/gui/widgets/popup.cpp
@@ -66,11 +66,6 @@ Popup::~Popup()
mSkin->instances--;
}
-void Popup::setWindowContainer(WindowContainer *wc)
-{
- windowContainer = wc;
-}
-
void Popup::draw(gcn::Graphics *graphics)
{
Graphics *g = static_cast<Graphics*>(graphics);
diff --git a/src/gui/widgets/popup.h b/src/gui/widgets/popup.h
index 5ec6ecd0..0f062ef5 100644
--- a/src/gui/widgets/popup.h
+++ b/src/gui/widgets/popup.h
@@ -65,11 +65,6 @@ class Popup : public Container, public gcn::MouseListener
~Popup();
/**
- * Sets the window container to be used by new popups.
- */
- static void setWindowContainer(WindowContainer *windowContainer);
-
- /**
* Draws the popup.
*/
void draw(gcn::Graphics *graphics);
diff --git a/src/gui/windowmenu.cpp b/src/gui/windowmenu.cpp
index f503c84c..abb5d04f 100644
--- a/src/gui/windowmenu.cpp
+++ b/src/gui/windowmenu.cpp
@@ -58,9 +58,8 @@ WindowMenu::WindowMenu():
addButton(N_("Equipment"), x, h, "button-icon-equipment.png",
KeyboardConfig::KEY_WINDOW_EQUIPMENT);
- if (skillDialog->hasSkills())
- addButton(N_("Skills"), x, h, "button-icon-skills.png",
- KeyboardConfig::KEY_WINDOW_SKILL);
+ addButton(N_("Skills"), x, h, "button-icon-skills.png",
+ KeyboardConfig::KEY_WINDOW_SKILL);
addButton(N_("Specials"), x, h, "button-icon-specials.png");
@@ -71,8 +70,7 @@ WindowMenu::WindowMenu():
addButton(N_("Setup"), x, h, "button-icon-setup.png",
KeyboardConfig::KEY_WINDOW_SETUP);
- setDimension(gcn::Rectangle(graphics->getWidth() - x, 3,
- x - 3, h));
+ setSize(x - 3, h);
setVisible(true);
}