summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2012-01-03 23:11:20 +0100
committerYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2012-01-09 23:40:16 +0100
commitf5172d4fcc10be73b72c1033cf9357a4dfe3544d (patch)
treea0fe53924fd3c82769a2a55cbbf7c01a045c435a
parent91306f28b85b553254853cc5e07e4beffbc15dea (diff)
downloadmana-client-f5172d4fcc10be73b72c1033cf9357a4dfe3544d.tar.gz
mana-client-f5172d4fcc10be73b72c1033cf9357a4dfe3544d.tar.bz2
mana-client-f5172d4fcc10be73b72c1033cf9357a4dfe3544d.tar.xz
mana-client-f5172d4fcc10be73b72c1033cf9357a4dfe3544d.zip
Added a close button to the npc dialog window.
The close button will only display when the window is waiting for the server, so that crashed windows can be closed without restarting the client. Pushing the QUIT key (Escape by default) will also close the crashed windows in that case. I also fixed a memleak with the "next" button. Resolves: Mana-Mantis #72, 93, 389. Reviewed-by: Ablu.
-rw-r--r--src/game.cpp14
-rw-r--r--src/gui/npcdialog.cpp48
-rw-r--r--src/gui/npcdialog.h8
3 files changed, 44 insertions, 26 deletions
diff --git a/src/game.cpp b/src/game.cpp
index 813253ce..226d275a 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -601,11 +601,21 @@ void Game::handleInput()
}
used = true;
break;
- // Quitting confirmation dialog
- case KeyboardConfig::KEY_QUIT:
+ case KeyboardConfig::KEY_QUIT:
+ {
+ // Close possible stuck NPC dialogs.
+ NpcDialog *npcDialog = NpcDialog::getActive();
+ if (npcDialog && npcDialog->isWaitingForTheServer())
+ {
+ npcDialog->close();
+ return;
+ }
+
+ // Otherwise, show the quit confirmation dialog.
quitDialog = new QuitDialog(&quitDialog);
quitDialog->requestMoveToTop();
return;
+ }
default:
break;
}
diff --git a/src/gui/npcdialog.cpp b/src/gui/npcdialog.cpp
index ec863c79..f5c7698d 100644
--- a/src/gui/npcdialog.cpp
+++ b/src/gui/npcdialog.cpp
@@ -81,7 +81,7 @@ NpcDialog::NpcDialog(int npcId)
// Basic Window Setup
setWindowName("NpcText");
setResizable(true);
- //setupWindow->registerWindowForReset(this);
+ setCloseButton(false);
setFocusable(true);
setMinWidth(200);
@@ -119,18 +119,18 @@ NpcDialog::NpcDialog(int npcId)
mClearButton = new Button(_("Clear log"), "clear", this);
// Setup button
- mButton = new Button("", "ok", this);
+ mNextButton = new Button("", "ok", this);
//Setup more and less buttons (int input)
mPlusButton = new Button(_("+"), "inc", this);
mMinusButton = new Button(_("-"), "dec", this);
- int width = std::max(mButton->getFont()->getWidth(CAPTION_WAITING),
- mButton->getFont()->getWidth(CAPTION_NEXT));
- width = std::max(width, mButton->getFont()->getWidth(CAPTION_CLOSE));
- width = std::max(width, mButton->getFont()->getWidth(CAPTION_SUBMIT));
+ int width = std::max(mNextButton->getFont()->getWidth(CAPTION_WAITING),
+ mNextButton->getFont()->getWidth(CAPTION_NEXT));
+ width = std::max(width, mNextButton->getFont()->getWidth(CAPTION_CLOSE));
+ width = std::max(width, mNextButton->getFont()->getWidth(CAPTION_SUBMIT));
- mButton->setWidth(8 + width);
+ mNextButton->setWidth(8 + width);
mResetButton = new Button(_("Reset"), "reset", this);
@@ -159,6 +159,7 @@ NpcDialog::~NpcDialog()
delete mResetButton;
delete mPlusButton;
delete mMinusButton;
+ delete mNextButton;
instances.remove(this);
@@ -210,7 +211,7 @@ void NpcDialog::action(const gcn::ActionEvent &event)
}
else if (mActionState == NPC_ACTION_CLOSE)
{
- closeDialog();
+ close();
}
else if (mActionState == NPC_ACTION_INPUT)
{
@@ -278,10 +279,10 @@ void NpcDialog::nextDialog()
Net::getNpcHandler()->nextDialog(mNpcId);
}
-void NpcDialog::closeDialog()
+void NpcDialog::close()
{
Net::getNpcHandler()->closeDialog(mNpcId);
- close();
+ Window::close();
}
int NpcDialog::getNumberOfElements()
@@ -410,12 +411,13 @@ void NpcDialog::mouseClicked(gcn::MouseEvent &mouseEvent)
if (mouseEvent.getSource() == mItemList &&
isDoubleClick(mItemList->getSelected()))
{
- action(gcn::ActionEvent(mButton, mButton->getActionEventId()));
+ action(gcn::ActionEvent(mNextButton, mNextButton->getActionEventId()));
}
if (mouseEvent.getSource() == mTextBox && isDoubleClick((int)(long)mTextBox))
{
if (mActionState == NPC_ACTION_NEXT || mActionState == NPC_ACTION_CLOSE)
- action(gcn::ActionEvent(mButton, mButton->getActionEventId()));
+ action(gcn::ActionEvent(mNextButton,
+ mNextButton->getActionEventId()));
}
}
@@ -435,7 +437,7 @@ NpcDialog *NpcDialog::getActive()
}
}
- return NULL;
+ return 0;
}
void NpcDialog::closeAll()
@@ -467,32 +469,32 @@ void NpcDialog::buildLayout()
{
if (mActionState == NPC_ACTION_WAIT)
{
- mButton->setCaption(CAPTION_WAITING);
+ mNextButton->setCaption(CAPTION_WAITING);
}
else if (mActionState == NPC_ACTION_NEXT)
{
- mButton->setCaption(CAPTION_NEXT);
+ mNextButton->setCaption(CAPTION_NEXT);
}
else if (mActionState == NPC_ACTION_CLOSE)
{
- mButton->setCaption(CAPTION_CLOSE);
+ mNextButton->setCaption(CAPTION_CLOSE);
}
place(0, 0, mScrollArea, 5, 3);
place(3, 3, mClearButton);
- place(4, 3, mButton);
+ place(4, 3, mNextButton);
}
else if (mInputState != NPC_INPUT_NONE)
{
if (!mLogInteraction)
setText(mNewText);
- mButton->setCaption(CAPTION_SUBMIT);
+ mNextButton->setCaption(CAPTION_SUBMIT);
if (mInputState == NPC_INPUT_LIST)
{
place(0, 0, mScrollArea, 6, 3);
place(0, 3, mListScrollArea, 6, 3);
place(2, 6, mClearButton, 2);
- place(4, 6, mButton, 2);
+ place(4, 6, mNextButton, 2);
mItemList->setSelected(-1);
}
@@ -502,7 +504,7 @@ void NpcDialog::buildLayout()
place(0, 3, mTextField, 6);
place(0, 4, mResetButton, 2);
place(2, 4, mClearButton, 2);
- place(4, 4, mButton, 2);
+ place(4, 4, mNextButton, 2);
}
else if (mInputState == NPC_INPUT_INTEGER)
{
@@ -512,14 +514,16 @@ void NpcDialog::buildLayout()
place(5, 3, mPlusButton, 1);
place(0, 4, mResetButton, 2);
place(2, 4, mClearButton, 2);
- place(4, 4, mButton, 2);
+ place(4, 4, mNextButton, 2);
}
}
Layout &layout = getLayout();
layout.setRowHeight(0, Layout::AUTO_SET);
- mButton->setEnabled(mActionState != NPC_ACTION_WAIT);
+ bool waitState = isWaitingForTheServer();
+ mNextButton->setEnabled(!waitState);
+ setCloseButton(waitState);
redraw();
diff --git a/src/gui/npcdialog.h b/src/gui/npcdialog.h
index abea5753..07e1abb1 100644
--- a/src/gui/npcdialog.h
+++ b/src/gui/npcdialog.h
@@ -92,8 +92,9 @@ class NpcDialog : public Window,
/**
* Notifies the server that the client has performed a close action.
+ * @overrides Window::close()
*/
- void closeDialog();
+ void close();
/**
* Returns the number of items in the choices list.
@@ -157,6 +158,9 @@ class NpcDialog : public Window,
*/
static NpcDialog *getActive();
+ bool isWaitingForTheServer() const
+ { return mActionState == NPC_ACTION_WAIT; }
+
/**
* Closes all instances.
*/
@@ -196,7 +200,7 @@ class NpcDialog : public Window,
Button *mClearButton;
// Used for the button
- Button *mButton;
+ Button *mNextButton;
// Will reset the text and integer input to the provided default
Button *mResetButton;