summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2012-08-02 00:51:58 +0200
committerThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2012-08-02 00:51:58 +0200
commit9654a6554c9a42e13f641f8f52e04246d96882b8 (patch)
tree9bf6cbf82b3e1e074071dbc55d5c7ad540ced79b
parenta61c57070aa618ac749e4a90a2b83c0e3a15e5fd (diff)
downloadmana-9654a6554c9a42e13f641f8f52e04246d96882b8.tar.gz
mana-9654a6554c9a42e13f641f8f52e04246d96882b8.tar.bz2
mana-9654a6554c9a42e13f641f8f52e04246d96882b8.tar.xz
mana-9654a6554c9a42e13f641f8f52e04246d96882b8.zip
Embedded the minimap into the mini status window
-rw-r--r--src/game.cpp18
-rw-r--r--src/game.h2
-rw-r--r--src/gui/minimap.cpp89
-rw-r--r--src/gui/minimap.h14
-rw-r--r--src/gui/ministatuswindow.cpp42
-rw-r--r--src/gui/ministatuswindow.h11
-rw-r--r--src/keyboardconfig.cpp1
-rw-r--r--src/keyboardconfig.h1
8 files changed, 73 insertions, 105 deletions
diff --git a/src/game.cpp b/src/game.cpp
index 07ead33f..0b79e266 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -102,7 +102,6 @@ ChatWindow *chatWindow;
StatusWindow *statusWindow;
InventoryWindow *inventoryWindow;
SkillDialog *skillDialog;
-Minimap *minimap;
EquipmentWindow *equipmentWindow;
TradeWindow *tradeWindow;
HelpWindow *helpWindow;
@@ -149,7 +148,6 @@ static void createGuiWindows()
setupWindow->clearWindowsForReset();
// Create dialogs
- minimap = new Minimap;
chatWindow = new ChatWindow;
tradeWindow = new TradeWindow;
equipmentWindow = new EquipmentWindow(PlayerInfo::getEquipment());
@@ -185,7 +183,6 @@ static void destroyGuiWindows()
del_0(statusWindow)
del_0(inventoryWindow)
del_0(skillDialog)
- del_0(minimap)
del_0(equipmentWindow)
del_0(tradeWindow)
del_0(helpWindow)
@@ -214,16 +211,18 @@ Game::Game():
viewport = new Viewport;
viewport->setSize(graphics->getWidth(), graphics->getHeight());
- gcn::Container *top = static_cast<gcn::Container*>(gui->getTop());
+ WindowContainer *top = static_cast<WindowContainer*>(gui->getTop());
top->add(viewport);
viewport->requestMoveToBottom();
mWindowMenu = new WindowMenu;
mMiniStatusWindow = new MiniStatusWindow;
- windowContainer->place(2, 0, mMiniStatusWindow);
- windowContainer->place(1, 0, mWindowMenu).setHAlign(Layout::RIGHT);
- windowContainer->updateLayout();
+ top->place(1, 0, mWindowMenu)
+ .setHAlign(Layout::RIGHT)
+ .setVAlign(Layout::LEFT);
+ top->place(2, 0, mMiniStatusWindow);
+ top->updateLayout();
createGuiWindows();
@@ -667,9 +666,6 @@ void Game::handleInput()
case KeyboardConfig::KEY_WINDOW_SKILL:
requestedWindow = skillDialog;
break;
- case KeyboardConfig::KEY_WINDOW_MINIMAP:
- minimap->toggle();
- break;
case KeyboardConfig::KEY_WINDOW_CHAT:
requestedWindow = chatWindow;
break;
@@ -936,7 +932,7 @@ void Game::changeMap(const std::string &mapPath)
}
// Notify the minimap and beingManager about the map change
- minimap->setMap(newMap);
+ mMiniStatusWindow->setMap(newMap);
actorSpriteManager->setMap(newMap);
particleEngine->setMap(newMap);
viewport->setMap(newMap);
diff --git a/src/game.h b/src/game.h
index 4986d591..bc542443 100644
--- a/src/game.h
+++ b/src/game.h
@@ -25,8 +25,8 @@
#include <string>
class Map;
-class WindowMenu;
class MiniStatusWindow;
+class WindowMenu;
/**
* The main class responsible for running the game. The game starts after you
diff --git a/src/gui/minimap.cpp b/src/gui/minimap.cpp
index 44df66ae..cd00a5af 100644
--- a/src/gui/minimap.cpp
+++ b/src/gui/minimap.cpp
@@ -39,55 +39,23 @@
#include <guichan/font.hpp>
-bool Minimap::mShow = true;
-
Minimap::Minimap():
- Window(_("Map")),
mMap(0),
mMapImage(0),
mWidthProportion(0.5),
mHeightProportion(0.5)
{
- setWindowName("Minimap");
- mShow = config.getValue(getWindowName() + "Show", true);
- setDefaultSize(5, 25, 150, 150);
- // set this to false as the minimap window size is changed
- //depending on the map size
- setResizable(false);
- setupWindow->registerWindowForReset(this);
-
- setDefaultVisible(true);
- setSaveVisible(true);
-
- setStickyButton(true);
- setSticky(false);
-
- loadWindowState();
- setVisible(mShow, isSticky());
+ setSize(100, 100);
}
Minimap::~Minimap()
{
- config.setValue(getWindowName() + "Show", mShow);
-
if (mMapImage)
mMapImage->decRef();
}
void Minimap::setMap(Map *map)
{
- // Set the title for the Minimap
- std::string caption = "";
- std::string minimapName;
-
- if (map)
- caption = map->getName();
-
- if (caption.empty())
- caption = _("Map");
-
- minimap->setCaption(caption);
-
// Adapt the image
if (mMapImage)
{
@@ -102,7 +70,7 @@ void Minimap::setMap(Map *map)
"graphics/minimaps/" + map->getFilename() + ".png";
ResourceManager *resman = ResourceManager::getInstance();
- minimapName = map->getProperty("minimap");
+ std::string minimapName = map->getProperty("minimap");
if (minimapName.empty() && resman->exists(tempname))
minimapName = tempname;
@@ -113,69 +81,40 @@ void Minimap::setMap(Map *map)
if (mMapImage)
{
- const int offsetX = 2 * getPadding();
- const int offsetY = getTitleBarHeight() + getPadding();
- const int titleWidth = getFont()->getWidth(getCaption()) + 15;
- const int mapWidth = mMapImage->getWidth() < 150 ?
- mMapImage->getWidth() + offsetX : 150;
- const int mapHeight = mMapImage->getHeight() < 150 ?
- mMapImage->getHeight() + offsetY : 150;
-
- setMinWidth(mapWidth > titleWidth ? mapWidth : titleWidth);
- setMinHeight(mapHeight);
-
mWidthProportion = (float) mMapImage->getWidth() / map->getWidth();
mHeightProportion = (float) mMapImage->getHeight() / map->getHeight();
- setMaxWidth(mMapImage->getWidth() > titleWidth ?
- mMapImage->getWidth() + offsetX : titleWidth);
- setMaxHeight(mMapImage->getHeight() + offsetY);
-
- setDefaultSize(getX(), getY(), getWidth(), getHeight());
- resetToDefaultSize();
-
- if (mShow)
- setVisible(true);
+ setVisible(true);
}
else
{
- if (!isSticky())
- setVisible(false);
+ setVisible(true);
}
}
-void Minimap::toggle()
-{
- setVisible(!isVisible(), isSticky());
- mShow = isVisible();
-}
-
void Minimap::draw(gcn::Graphics *graphics)
{
- Window::draw(graphics);
-
- gcn::Rectangle a = getChildrenArea();
- a.width = a.width - 3;
- a.height = a.height - 3;
- graphics->pushClipArea(a);
+ const int width = getWidth();
+ const int height = getHeight();
+ graphics->pushClipArea(gcn::Rectangle(0, 0, width, height));
int mapOriginX = 0;
int mapOriginY = 0;
if (mMapImage && mMap)
{
- if (mMapImage->getWidth() > a.width ||
- mMapImage->getHeight() > a.height)
+
+ if (mMapImage->getWidth() > width ||
+ mMapImage->getHeight() > height)
{
const Vector &p = local_player->getPosition();
- mapOriginX = (int) (((a.width) / 2) - (int) (p.x * mWidthProportion)
+ mapOriginX = (int) ((width / 2) - (int) (p.x * mWidthProportion)
/ mMap->getTileWidth());
- mapOriginY = (int) (((a.height) / 2)
- - (int) (p.y * mHeightProportion)
+ mapOriginY = (int) ((height / 2) - (int) (p.y * mHeightProportion)
/ mMap->getTileHeight());
- const int minOriginX = a.width - mMapImage->getWidth();
- const int minOriginY = a.height - mMapImage->getHeight();
+ const int minOriginX = width - mMapImage->getWidth();
+ const int minOriginY = height - mMapImage->getHeight();
if (mapOriginX < minOriginX)
mapOriginX = minOriginX;
diff --git a/src/gui/minimap.h b/src/gui/minimap.h
index e44753e3..2cb6b5bd 100644
--- a/src/gui/minimap.h
+++ b/src/gui/minimap.h
@@ -22,13 +22,13 @@
#ifndef MINIMAP_H
#define MINIMAP_H
-#include "gui/widgets/window.h"
+#include <guichan/widget.hpp>
class Image;
class Map;
/**
- * Minimap window. Shows a minimap image and the name of the current map.
+ * Shows a minimap image.
*
* The name of the map is defined by the map property "name". The minimap image
* is defined by the map property "minimap". The path to the image should be
@@ -36,7 +36,7 @@ class Map;
*
* \ingroup Interface
*/
-class Minimap : public Window
+class Minimap : public gcn::Widget
{
public:
Minimap();
@@ -48,11 +48,6 @@ class Minimap : public Window
void setMap(Map *map);
/**
- * Toggles the displaying of the minimap.
- */
- void toggle();
-
- /**
* Draws the minimap.
*/
void draw(gcn::Graphics *graphics);
@@ -62,9 +57,6 @@ class Minimap : public Window
Image *mMapImage;
float mWidthProportion;
float mHeightProportion;
- static bool mShow;
};
-extern Minimap *minimap;
-
#endif
diff --git a/src/gui/ministatuswindow.cpp b/src/gui/ministatuswindow.cpp
index 86dd4adf..df8b4aba 100644
--- a/src/gui/ministatuswindow.cpp
+++ b/src/gui/ministatuswindow.cpp
@@ -28,11 +28,14 @@
#include "statuseffect.h"
#include "gui/gui.h"
+#include "gui/minimap.h"
#include "gui/statuswindow.h"
#include "gui/textpopup.h"
-#include "gui/widgets/progressbar.h"
+#include "gui/widgets/label.h"
#include "gui/widgets/layout.h"
+#include "gui/widgets/progressbar.h"
+#include "gui/widgets/spacer.h"
#include "net/net.h"
#include "net/playerhandler.h"
@@ -47,11 +50,17 @@
extern volatile int tick_time;
-MiniStatusWindow::MiniStatusWindow()
+MiniStatusWindow::MiniStatusWindow():
+ mMinimap(new Minimap),
+ mRegionLabel(new Label),
+ mWindowSkin(Theme::instance()->load("window.xml"))
{
listen(Event::AttributesChannel);
listen(Event::ActorSpriteChannel);
+ mRegionLabel->setAlignment(gcn::Graphics::CENTER);
+ mRegionLabel->adjustSize();
+
mHpBar = new ProgressBar(0, 100, 20, Theme::PROG_HP);
StatusWindow::updateHPBar(mHpBar);
@@ -69,9 +78,10 @@ MiniStatusWindow::MiniStatusWindow()
mXpBar = new ProgressBar(0, 100, 20, Theme::PROG_EXP);
StatusWindow::updateXPBar(mXpBar);
- // Add the progressbars to the window
-
int row = 0;
+ place(0, row++, mRegionLabel);
+ place(0, row++, mMinimap);
+ place(0, row++, new Spacer);
place(0, row++, mHpBar);
if (mMpBar)
place(0, row++, mMpBar);
@@ -79,6 +89,7 @@ MiniStatusWindow::MiniStatusWindow()
Layout &layout = getLayout();
layout.setMargin(0);
+ layout.setPadding(7);
int w = 0;
int h = 0;
@@ -235,10 +246,25 @@ void MiniStatusWindow::logic()
mIcons[i]->update(tick_time * 10);
}
+static gcn::Rectangle adjust(const gcn::Rectangle &rect,
+ int left, int top, int right, int bottom)
+{
+ return gcn::Rectangle(rect.x + left,
+ rect.y + top,
+ rect.width - left + right,
+ rect.height - top + bottom);
+}
+
void MiniStatusWindow::draw(gcn::Graphics *graphics)
{
+ Graphics *g = static_cast<Graphics*>(graphics);
+ g->drawImageRect(adjust(mMinimap->getDimension(),
+ -5, -10 - mRegionLabel->getHeight(),
+ 8, 8),
+ mWindowSkin->getBorder());
+
drawChildren(graphics);
- drawIcons(static_cast<Graphics*>(graphics));
+ drawIcons(g);
}
void MiniStatusWindow::mouseMoved(gcn::MouseEvent &event)
@@ -277,3 +303,9 @@ void MiniStatusWindow::mouseExited(gcn::MouseEvent &event)
{
mTextPopup->setVisible(false);
}
+
+void MiniStatusWindow::setMap(Map *map)
+{
+ mMinimap->setMap(map);
+ mRegionLabel->setCaption(map ? map->getName() : std::string());
+}
diff --git a/src/gui/ministatuswindow.h b/src/gui/ministatuswindow.h
index a9939fcd..86e2e4f0 100644
--- a/src/gui/ministatuswindow.h
+++ b/src/gui/ministatuswindow.h
@@ -32,7 +32,11 @@
class AnimatedSprite;
class Graphics;
+class Label;
+class Map;
+class Minimap;
class ProgressBar;
+class Skin;
class TextPopup;
/**
@@ -58,6 +62,8 @@ class MiniStatusWindow : public Container,
void mouseMoved(gcn::MouseEvent &mouseEvent);
void mouseExited(gcn::MouseEvent &event);
+ void setMap(Map *map);
+
private:
bool isInBar(ProgressBar *bar, int x, int y) const;
@@ -68,6 +74,9 @@ class MiniStatusWindow : public Container,
void eraseIcon(int index);
+ Minimap *mMinimap;
+ Label *mRegionLabel;
+
/*
* Mini Status Bars
*/
@@ -76,6 +85,8 @@ class MiniStatusWindow : public Container,
ProgressBar *mXpBar;
TextPopup *mTextPopup;
+ Skin *mWindowSkin;
+
std::vector<int> mStatusEffectIcons;
std::vector<AnimatedSprite *> mIcons;
};
diff --git a/src/keyboardconfig.cpp b/src/keyboardconfig.cpp
index cad41bd6..0f4a46bf 100644
--- a/src/keyboardconfig.cpp
+++ b/src/keyboardconfig.cpp
@@ -72,7 +72,6 @@ static KeyData const keyData[KeyboardConfig::KEY_TOTAL] = {
{"keyWindowInventory", SDLK_F3, _("Inventory Window")},
{"keyWindowEquipment", SDLK_F4, _("Equipment Window")},
{"keyWindowSkill", SDLK_F5, _("Skill Window")},
- {"keyWindowMinimap", SDLK_F6, _("Minimap Window")},
{"keyWindowChat", SDLK_F7, _("Chat Window")},
{"keyWindowShortcut", SDLK_F8, _("Item Shortcut Window")},
{"keyWindowSetup", SDLK_F9, _("Setup Window")},
diff --git a/src/keyboardconfig.h b/src/keyboardconfig.h
index 6f40e03d..8c744123 100644
--- a/src/keyboardconfig.h
+++ b/src/keyboardconfig.h
@@ -187,7 +187,6 @@ class KeyboardConfig
KEY_WINDOW_INVENTORY,
KEY_WINDOW_EQUIPMENT,
KEY_WINDOW_SKILL,
- KEY_WINDOW_MINIMAP,
KEY_WINDOW_CHAT,
KEY_WINDOW_SHORTCUT,
KEY_WINDOW_SETUP,