summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/npc_text.cpp11
-rw-r--r--src/gui/npc_text.h13
-rw-r--r--src/gui/npclistdialog.cpp6
-rw-r--r--src/gui/npclistdialog.h3
-rw-r--r--src/gui/window.cpp41
-rw-r--r--src/gui/window.h6
6 files changed, 60 insertions, 20 deletions
diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp
index ec8a4b6e..58aa0c5e 100644
--- a/src/gui/npc_text.cpp
+++ b/src/gui/npc_text.cpp
@@ -35,10 +35,10 @@
#include "../utils/gettext.h"
NpcTextDialog::NpcTextDialog(Network *network):
- Window(_("NPC")), mNetwork(network)
+ Window("NPC"), mNetwork(network)
{
+ setWindowName(_("NPC"));
setResizable(true);
- setCloseButton(true);
setMinWidth(200);
setMinHeight(150);
@@ -89,6 +89,7 @@ void NpcTextDialog::action(const gcn::ActionEvent &event)
{
clearText();
setVisible(false);
+ saveWindowState();
if (current_npc)
nextDialog();
@@ -118,3 +119,9 @@ void NpcTextDialog::widgetResized(const gcn::Event &event)
setText(mText);
}
+void NpcTextDialog::requestFocus()
+{
+ loadWindowState();
+ setVisible(true);
+}
+
diff --git a/src/gui/npc_text.h b/src/gui/npc_text.h
index 615902db..f01e3602 100644
--- a/src/gui/npc_text.h
+++ b/src/gui/npc_text.h
@@ -74,11 +74,24 @@ class NpcTextDialog : public Window, public gcn::ActionListener
*/
void addText(const std::string &string);
+ /**
+ * Notifies the server that the client has performed a next action.
+ */
void nextDialog(int npcID = current_npc);
+ /**
+ * Notifies the server that the client has performed a close action.
+ */
void closeDialog(int npcID = current_npc);
/**
+ * Initializes window width to the last known setting. Since the dialog
+ * doesn't need any extra focus outside of what it's given in the Game
+ * class, this is all it does for now.
+ */
+ void requestFocus();
+
+ /**
* Called when resizing the window.
*
* @param event The calling event
diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp
index c639411d..f049cba7 100644
--- a/src/gui/npclistdialog.cpp
+++ b/src/gui/npclistdialog.cpp
@@ -37,8 +37,9 @@
#include "../utils/gettext.h"
NpcListDialog::NpcListDialog(Network *network):
- Window(_("NPC")), mNetwork(network)
+ Window("NPC"), mNetwork(network)
{
+ setWindowName(_("NPC"));
setResizable(true);
setMinWidth(200);
@@ -114,6 +115,7 @@ void NpcListDialog::action(const gcn::ActionEvent &event)
if (choice)
{
setVisible(false);
+ saveWindowState();
reset();
MessageOut outMsg(mNetwork);
@@ -129,4 +131,6 @@ void NpcListDialog::requestFocus()
{
mItemList->requestFocus();
mItemList->setSelected(0);
+ loadWindowState();
+ setVisible(true);
}
diff --git a/src/gui/npclistdialog.h b/src/gui/npclistdialog.h
index 0a0e9813..e3cf375b 100644
--- a/src/gui/npclistdialog.h
+++ b/src/gui/npclistdialog.h
@@ -76,7 +76,8 @@ class NpcListDialog : public Window, public gcn::ActionListener,
void reset();
/**
- * Requests the listbox to take focus for input.
+ * Requests the listbox to take focus for input and sets window width
+ * to the last known setting.
*/
void requestFocus();
diff --git a/src/gui/window.cpp b/src/gui/window.cpp
index 2b422f86..8faf63a0 100644
--- a/src/gui/window.cpp
+++ b/src/gui/window.cpp
@@ -118,21 +118,8 @@ Window::Window(const std::string& caption, bool modal, Window *parent, const std
Window::~Window()
{
logger->log("Window::~Window(\"%s\")", getCaption().c_str());
- const std::string &name = mWindowName;
- // Saving X, Y and Width and Height for resizables in the config
- if (!name.empty())
- {
- config.setValue(name + "WinX", getX());
- config.setValue(name + "WinY", getY());
- config.setValue(name + "Visible", isVisible());
-
- if (mGrip)
- {
- config.setValue(name + "WinWidth", getWidth());
- config.setValue(name + "WinHeight", getHeight());
- }
- }
+ saveWindowState();
delete mLayout;
@@ -478,8 +465,13 @@ void Window::loadWindowState()
if (mGrip)
{
- setSize((int) config.getValue(name + "WinWidth", mDefaultWidth),
- (int) config.getValue(name + "WinHeight", mDefaultHeight));
+ const int width = (int) config.getValue(name + "WinWidth",
+ mDefaultWidth);
+ const int height = (int) config.getValue(name + "WinHeight",
+ mDefaultHeight);
+
+ setSize(width < getMinWidth() ? getMinWidth() : width,
+ height < getMinHeight() ? getMinHeight() : height);
}
else
{
@@ -487,6 +479,23 @@ void Window::loadWindowState()
}
}
+void Window::saveWindowState()
+{
+ // Saving X, Y and Width and Height for resizables in the config
+ if (!mWindowName.empty())
+ {
+ config.setValue(mWindowName + "WinX", getX());
+ config.setValue(mWindowName + "WinY", getY());
+ config.setValue(mWindowName + "Visible", isVisible());
+
+ if (mGrip)
+ {
+ config.setValue(mWindowName + "WinWidth", getWidth());
+ config.setValue(mWindowName + "WinHeight", getHeight());
+ }
+ }
+}
+
void Window::setDefaultSize(int defaultX, int defaultY,
int defaultWidth, int defaultHeight)
{
diff --git a/src/gui/window.h b/src/gui/window.h
index 3a92ac17..bf15dedb 100644
--- a/src/gui/window.h
+++ b/src/gui/window.h
@@ -234,6 +234,12 @@ class Window : public gcn::Window, gcn::WidgetListener
void loadWindowState();
/**
+ * Saves the window state so that when the window is reloaded, it'll
+ * maintain its previous state and location.
+ */
+ void saveWindowState();
+
+ /**
* Set the default win pos and size.
* (which can be different of the actual ones.)
*/