summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorBjörn Steinbrink <B.Steinbrink@gmx.de>2005-10-20 09:01:12 +0000
committerBjörn Steinbrink <B.Steinbrink@gmx.de>2005-10-20 09:01:12 +0000
commit5acb9213cc2ee949a252a5c08a9a9a13542b94d5 (patch)
tree40d29fd38eeb692ec948c69f15f5ca27067fa7fb /src/gui
parent2415d3b14cdec975a28ccef46d5234f70b06d3b0 (diff)
downloadmana-client-5acb9213cc2ee949a252a5c08a9a9a13542b94d5.tar.gz
mana-client-5acb9213cc2ee949a252a5c08a9a9a13542b94d5.tar.bz2
mana-client-5acb9213cc2ee949a252a5c08a9a9a13542b94d5.tar.xz
mana-client-5acb9213cc2ee949a252a5c08a9a9a13542b94d5.zip
Various cleanups and refactorisations.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/confirm_dialog.cpp6
-rw-r--r--src/gui/confirm_dialog.h3
-rw-r--r--src/gui/connection.cpp23
-rw-r--r--src/gui/connection.h3
-rw-r--r--src/gui/debugwindow.cpp6
-rw-r--r--src/gui/debugwindow.h1
-rw-r--r--src/gui/item_amount.cpp44
-rw-r--r--src/gui/item_amount.h4
-rw-r--r--src/gui/menuwindow.cpp67
-rw-r--r--src/gui/menuwindow.h22
-rw-r--r--src/gui/ok_dialog.cpp4
-rw-r--r--src/gui/ok_dialog.h3
12 files changed, 88 insertions, 98 deletions
diff --git a/src/gui/confirm_dialog.cpp b/src/gui/confirm_dialog.cpp
index 7e1ef983..dc710961 100644
--- a/src/gui/confirm_dialog.cpp
+++ b/src/gui/confirm_dialog.cpp
@@ -45,9 +45,9 @@ ConfirmDialog::ConfirmDialog(Window *parent, const std::string &title,
void ConfirmDialog::init(const std::string &msg, gcn::ActionListener *listener)
{
- userLabel = new gcn::Label(msg);
- yesButton = new Button("Yes");
- noButton = new Button("No");
+ gcn::Label *userLabel = new gcn::Label(msg);
+ Button *yesButton = new Button("Yes");
+ Button *noButton = new Button("No");
int w = userLabel->getWidth() + 20;
int inWidth = yesButton->getWidth() + noButton->getWidth() + 5;
diff --git a/src/gui/confirm_dialog.h b/src/gui/confirm_dialog.h
index fd31b389..fd220828 100644
--- a/src/gui/confirm_dialog.h
+++ b/src/gui/confirm_dialog.h
@@ -65,9 +65,6 @@ class ConfirmDialog : public Window, public gcn::ActionListener {
* Initializes the dialog.
*/
void init(const std::string &msg, gcn::ActionListener *listener);
-
- gcn::Label *userLabel;
- gcn::Button *yesButton, *noButton;
};
#endif
diff --git a/src/gui/connection.cpp b/src/gui/connection.cpp
index 012bf444..3cff4abd 100644
--- a/src/gui/connection.cpp
+++ b/src/gui/connection.cpp
@@ -41,18 +41,23 @@ ConnectionDialog::ConnectionDialog():
Window("Info"), mProgress(0), mStatus(NET_CONNECTING)
{
setContentSize(200, 100);
- mCancelButton = new Button("Cancel");
- mCancelButton->setPosition(5, 100 - 5 - mCancelButton->getHeight());
- mCancelButton->setEventId("cancel");
- mCancelButton->addActionListener(this);
- mProgressBar = new ProgressBar(0.0, 5, mCancelButton->getY() - 25,
+
+ Button *cancelButton;
+ cancelButton = new Button("Cancel");
+ cancelButton->setPosition(5, 100 - 5 - cancelButton->getHeight());
+ cancelButton->setEventId("cancel");
+ cancelButton->addActionListener(this);
+
+ mProgressBar = new ProgressBar(0.0, 5, cancelButton->getY() - 25,
200 - 10, 20, 128, 128, 128);
- mLabel = new gcn::Label("Connecting...");
- mLabel->setPosition(5, mProgressBar->getY() - 25);
+ gcn::Label *label;
+ label = new gcn::Label("Connecting...");
+ label->setPosition(5, mProgressBar->getY() - 25);
- add(mLabel);
- add(mCancelButton);
+ add(label);
+ add(cancelButton);
add(mProgressBar);
+
setLocationRelativeTo(getParent());
const char *host = iptostring(map_address);
diff --git a/src/gui/connection.h b/src/gui/connection.h
index 1686668a..baf8e1d8 100644
--- a/src/gui/connection.h
+++ b/src/gui/connection.h
@@ -32,7 +32,6 @@
#include "../guichanfwd.h"
-class Button;
class ProgressBar;
/**
@@ -57,8 +56,6 @@ class ConnectionDialog : public Window, public gcn::ActionListener {
void logic();
private:
- gcn::Label *mLabel;
- Button *mCancelButton;
ProgressBar *mProgressBar;
float mProgress;
int mStatus;
diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp
index 1ffae37f..eebfc29d 100644
--- a/src/gui/debugwindow.cpp
+++ b/src/gui/debugwindow.cpp
@@ -48,13 +48,17 @@ DebugWindow::DebugWindow():
FPSLabel = new gcn::Label("[0 FPS]");
FPSLabel->setPosition(0,0);
+
musicFileLabel = new gcn::Label("Music File: ");
musicFileLabel->setPosition(0, 20);
+
mapFileLabel = new gcn::Label("Mini-Map File: ");
mapFileLabel->setPosition(0, 40);
+
tileMouseLabel = new gcn::Label("[Mouse: 0, 0]");
tileMouseLabel->setPosition(100, 0);
- closeButton = new Button("Close");
+
+ Button *closeButton = new Button("Close");
closeButton->setEventId("close");
closeButton->setPosition(5, 60);
closeButton->addActionListener(this);
diff --git a/src/gui/debugwindow.h b/src/gui/debugwindow.h
index ec60cb13..7d2ee6c1 100644
--- a/src/gui/debugwindow.h
+++ b/src/gui/debugwindow.h
@@ -59,7 +59,6 @@ class DebugWindow : public Window, public gcn::ActionListener
private:
gcn::Label *musicFileLabel, *mapFileLabel;
gcn::Label *tileMouseLabel, *FPSLabel;
- gcn::Button *closeButton;
Map *mCurrentMap;
};
diff --git a/src/gui/item_amount.cpp b/src/gui/item_amount.cpp
index 4620ed81..f308b7ab 100644
--- a/src/gui/item_amount.cpp
+++ b/src/gui/item_amount.cpp
@@ -41,55 +41,55 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item):
mItemAmountTextBox = new IntTextBox(1);
// New buttons
- mItemAmountMinusButton = new Button("-");
- mItemAmountPlusButton = new Button("+");
+ Button *minusButton = new Button("-");
+ Button *plusButton = new Button("+");
mItemAmountSlide = new Slider(1.0);
- mItemAmountOkButton = new Button("Okay");
- mItemAmountCancelButton = new Button("Cancel");
+ Button *okButton = new Button("Okay");
+ Button *cancelButton = new Button("Cancel");
mItemAmountTextBox->setRange(1, mItem->getQuantity());
mItemAmountSlide->setDimension(gcn::Rectangle(5, 120, 180, 10));
// Set button events Id
- mItemAmountMinusButton->setEventId("Minus");
- mItemAmountPlusButton->setEventId("Plus");
+ minusButton->setEventId("Minus");
+ plusButton->setEventId("Plus");
mItemAmountSlide->setEventId("Slide");
- mItemAmountOkButton->setEventId("Drop");
- mItemAmountCancelButton->setEventId("Cancel");
+ okButton->setEventId("Drop");
+ cancelButton->setEventId("Cancel");
// Set position
mItemAmountTextBox->setPosition(35, 10);
mItemAmountTextBox->setSize(24, 16);
- mItemAmountPlusButton->setPosition(60, 5);
- mItemAmountMinusButton->setPosition(10, 5);
+ plusButton->setPosition(60, 5);
+ minusButton->setPosition(10, 5);
mItemAmountSlide->setPosition(10, 35);
- mItemAmountOkButton->setPosition(10, 50);
- mItemAmountCancelButton->setPosition(60, 50);
+ okButton->setPosition(10, 50);
+ cancelButton->setPosition(60, 50);
// Assemble
add(mItemAmountTextBox);
- add(mItemAmountPlusButton);
- add(mItemAmountMinusButton);
+ add(plusButton);
+ add(minusButton);
add(mItemAmountSlide);
- add(mItemAmountOkButton);
- add(mItemAmountCancelButton);
+ add(okButton);
+ add(cancelButton);
- mItemAmountPlusButton->addActionListener(this);
- mItemAmountMinusButton->addActionListener(this);
+ plusButton->addActionListener(this);
+ minusButton->addActionListener(this);
mItemAmountSlide->addActionListener(this);
- mItemAmountOkButton->addActionListener(this);
- mItemAmountCancelButton->addActionListener(this);
+ okButton->addActionListener(this);
+ cancelButton->addActionListener(this);
resetAmount();
switch (usage) {
case AMOUNT_TRADE_ADD:
setCaption("Select amount of items to trade.");
- mItemAmountOkButton->setEventId("AddTrade");
+ okButton->setEventId("AddTrade");
break;
case AMOUNT_ITEM_DROP:
setCaption("Select amount of items to drop.");
- mItemAmountOkButton->setEventId("Drop");
+ okButton->setEventId("Drop");
break;
default:
break;
diff --git a/src/gui/item_amount.h b/src/gui/item_amount.h
index f7e466fb..ad1e18d6 100644
--- a/src/gui/item_amount.h
+++ b/src/gui/item_amount.h
@@ -68,11 +68,7 @@ class ItemAmountWindow : public Window, public gcn::ActionListener
/**
* Item Amount buttons.
*/
- gcn::Button *mItemAmountPlusButton;
- gcn::Button *mItemAmountMinusButton;
gcn::Slider *mItemAmountSlide;
- gcn::Button *mItemAmountOkButton;
- gcn::Button *mItemAmountCancelButton;
};
#endif /* _TMW_ITEM_AMOUNT_WINDOW_H */
diff --git a/src/gui/menuwindow.cpp b/src/gui/menuwindow.cpp
index 21498468..cf917116 100644
--- a/src/gui/menuwindow.cpp
+++ b/src/gui/menuwindow.cpp
@@ -23,19 +23,25 @@
#include "menuwindow.h"
-#include <guichan/widgets/label.hpp>
-#include <sstream>
+#include <string>
+
+#include <guichan/actionlistener.hpp>
#include "button.h"
-#include "equipmentwindow.h"
-#include "inventorywindow.h"
-#include "status.h"
-#include "skill.h"
#include "../graphics.h"
extern Graphics *graphics;
-extern Window *setupWindow;
+extern Window *setupWindow, *inventoryWindow, *equipmentWindow,
+ *skillDialog, *statusWindow;
+
+class MenuWindowListener : public gcn::ActionListener
+{
+ /**
+ * Called when receiving actions from widget.
+ */
+ void action(const std::string& eventId);
+} menuWindowListener;
MenuWindow::MenuWindow():
Window("")
@@ -47,33 +53,36 @@ MenuWindow::MenuWindow():
// Buttons
// ------------
+ gcn::Button *statusButton, *equipmentButton, *skillsButton,
+ *inventoryButton, *setupButton;
+
statusButton = new Button("Status");
statusButton->setEventId("Status");
- statusButton->addActionListener(this);
+ statusButton->addActionListener(&menuWindowListener);
statusButton->setPosition(0, 3);
add(statusButton);
equipmentButton = new Button("Equipment");
equipmentButton->setEventId("Equipment");
- equipmentButton->addActionListener(this);
+ equipmentButton->addActionListener(&menuWindowListener);
equipmentButton->setPosition(statusButton->getX() + statusButton->getWidth() + 3, statusButton->getY());
add(equipmentButton);
inventoryButton = new Button("Inventory");
inventoryButton->setEventId("Inventory");
- inventoryButton->addActionListener(this);
+ inventoryButton->addActionListener(&menuWindowListener);
inventoryButton->setPosition(equipmentButton->getX() + equipmentButton->getWidth() + 3, statusButton->getY());
add(inventoryButton);
skillsButton = new Button("Skills");
skillsButton->setEventId("Skills");
- skillsButton->addActionListener(this);
+ skillsButton->addActionListener(&menuWindowListener);
skillsButton->setPosition(inventoryButton->getX() + inventoryButton->getWidth() + 3, statusButton->getY());
add(skillsButton);
setupButton = new Button("Setup");
setupButton->setEventId("Setup");
- setupButton->addActionListener(this);
+ setupButton->addActionListener(&menuWindowListener);
setupButton->setPosition(skillsButton->getX() + skillsButton->getWidth() + 3, statusButton->getY());
add(setupButton);
@@ -88,31 +97,35 @@ void MenuWindow::draw(gcn::Graphics *g)
Window::drawContent(g);
}
-void MenuWindow::action(const std::string& eventId)
+
+void MenuWindowListener::action(const std::string& eventId)
{
+ Window *window;
if (eventId == "Status")
{
- statusWindow->setVisible(!statusWindow->isVisible());
- if (statusWindow->isVisible()) statusWindow->requestMoveToTop();
+ window = statusWindow;
}
- if (eventId == "Equipment")
+ else if (eventId == "Equipment")
{
- equipmentWindow->setVisible(!equipmentWindow->isVisible());
- if (equipmentWindow->isVisible()) equipmentWindow->requestMoveToTop();
+ window = equipmentWindow;
}
- if (eventId == "Inventory")
+ else if (eventId == "Inventory")
{
- inventoryWindow->setVisible(!inventoryWindow->isVisible());
- if (inventoryWindow->isVisible()) inventoryWindow->requestMoveToTop();
+ window = inventoryWindow;
}
- if (eventId == "Skills")
+ else if (eventId == "Skills")
{
- skillDialog->setVisible(!skillDialog->isVisible());
- if (skillDialog->isVisible()) skillDialog->requestMoveToTop();
+ window = skillDialog;
}
- if (eventId == "Setup")
+ else if (eventId == "Setup")
{
- setupWindow->setVisible(!setupWindow->isVisible());
- if (setupWindow->isVisible()) setupWindow->requestMoveToTop();
+ window = setupWindow;
+ }
+
+ if (window) {
+ window->setVisible(!window->isVisible());
+ if (window->isVisible()) {
+ window->requestMoveToTop();
+ }
}
}
diff --git a/src/gui/menuwindow.h b/src/gui/menuwindow.h
index 0585748d..945bca94 100644
--- a/src/gui/menuwindow.h
+++ b/src/gui/menuwindow.h
@@ -24,10 +24,6 @@
#ifndef _TMW_MENU_H
#define _TMW_MENU_H
-#include <iosfwd>
-
-#include <guichan/actionlistener.hpp>
-
#include "window.h"
#include "../guichanfwd.h"
@@ -37,33 +33,19 @@
*
* \ingroup Interface
*/
-class MenuWindow : public Window, public gcn::ActionListener {
+class MenuWindow : public Window
+{
public:
/**
* Constructor.
*/
MenuWindow();
- /**
- * Called when receiving actions from widget.
- */
- void action(const std::string& eventId);
-
/**
* Draw this window
*/
void draw(gcn::Graphics *graphics);
-
- private:
-
- /**
- * System Buttons
- */
- gcn::Button *statusButton, *equipmentButton;
- gcn::Button *skillsButton, *inventoryButton, *setupButton;
};
-extern MenuWindow *menuWindow;
-
#endif
diff --git a/src/gui/ok_dialog.cpp b/src/gui/ok_dialog.cpp
index 8984c213..794bc723 100644
--- a/src/gui/ok_dialog.cpp
+++ b/src/gui/ok_dialog.cpp
@@ -48,8 +48,8 @@ OkDialog::~OkDialog()
void OkDialog::init(const std::string &msg, gcn::ActionListener *listener)
{
- userLabel = new gcn::Label(msg);
- okButton = new Button("OK");
+ gcn::Label *userLabel = new gcn::Label(msg);
+ Button *okButton = new Button("OK");
int w = userLabel->getWidth() + 20;
int h = userLabel->getHeight() + 25 + okButton->getHeight();
diff --git a/src/gui/ok_dialog.h b/src/gui/ok_dialog.h
index 3dfc18c8..d444bcd8 100644
--- a/src/gui/ok_dialog.h
+++ b/src/gui/ok_dialog.h
@@ -69,9 +69,6 @@ class OkDialog : public Window, public gcn::ActionListener {
* Initializes the dialog.
*/
void init(const std::string &msg, gcn::ActionListener *listener);
-
- gcn::Label *userLabel;
- gcn::Button *okButton;
};
#endif