From 5f6a6445d0156cb9728878688e09884b6a2b0188 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Mon, 16 May 2005 15:55:33 +0000 Subject: Made a dialog from exit confirmation. --- src/engine.cpp | 22 ++-------------------- src/game.cpp | 25 +++++++++++++++++++++++-- src/gui/confirm_dialog.cpp | 3 +-- 3 files changed, 26 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/engine.cpp b/src/engine.cpp index f01a19ed..adda6d06 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -65,25 +65,9 @@ EquipmentWindow *equipmentWindow; ChargeDialog *chargeDialog; TradeWindow *tradeWindow; RequestTradeDialog *requestTradeDialog; -ConfirmDialog *quitDialog; BuddyWindow *buddyWindow; std::map monsterset; -/** - * Listener used for exitting handling. - */ -class ExitListener : public gcn::ActionListener { - void action(const std::string &eventId) { - if (eventId == "yes") { - state = EXIT; - } - else - { - quitDialog->setVisible(false); - } - } -} exitListener; - char hairtable[16][4][2] = { // S(x,y) W(x,y) N(x,y) E(x,y) { { 0, 0}, {-1, 2}, {-1, 2}, { 0, 2} }, // STAND @@ -181,8 +165,7 @@ Engine::Engine() tradeWindow = new TradeWindow(); buddyWindow = new BuddyWindow(); requestTradeDialog = new RequestTradeDialog(); - quitDialog = new ConfirmDialog("Quit", "Are you sure you want to quit ?", - (gcn::ActionListener*)&exitListener); + // Initialize window posisitons chatWindow->setPosition(0, screen->h - chatWindow->getHeight()); statusWindow->setPosition(screen->w - statusWindow->getWidth() - 5, 5); @@ -226,7 +209,7 @@ Engine::Engine() tradeWindow->setVisible(false); buddyWindow->setVisible(false); requestTradeDialog->setVisible(false); - quitDialog->setVisible(false); + // Do not focus any text field gui->focusNone(); @@ -272,7 +255,6 @@ Engine::~Engine() delete tradeWindow; delete buddyWindow; delete requestTradeDialog; - delete quitDialog; // Delete sprite sets //delete monsterset; diff --git a/src/game.cpp b/src/game.cpp index 8c90f329..a8166fae 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -54,10 +54,14 @@ int startX = 0, startY = 0; int gameTime = 0; OkDialog *deathNotice = NULL; +ConfirmDialog *exitConfirm = NULL; #define EMOTION_TIME 150 #define MAX_TIME 10000 +/** + * Listener used for handling death message. + */ class DeatchNoticeListener : public gcn::ActionListener { public: void action(const std::string &eventId) { @@ -68,6 +72,18 @@ class DeatchNoticeListener : public gcn::ActionListener { } } deathNoticeListener; +/** + * Listener used for exitting handling. + */ +class ExitListener : public gcn::ActionListener { + void action(const std::string &eventId) { + if (eventId == "yes") { + state = EXIT; + } + exitConfirm = NULL; + } +} exitListener; + /** * Advances game logic counter. */ @@ -284,8 +300,13 @@ void do_input() if (event.key.keysym.sym == SDLK_ESCAPE) { - quitDialog->setVisible(true); - quitDialog->requestMoveToTop(); + // Spawn confirm dialog for quitting + if (!exitConfirm) + { + exitConfirm = new ConfirmDialog( + "Quit", "Are you sure you want to quit?", + (gcn::ActionListener*)&exitListener); + } } if (keysym.sym == SDLK_g && !chatWindow->isFocused()) diff --git a/src/gui/confirm_dialog.cpp b/src/gui/confirm_dialog.cpp index 967355a6..61c4b009 100644 --- a/src/gui/confirm_dialog.cpp +++ b/src/gui/confirm_dialog.cpp @@ -91,7 +91,6 @@ ConfirmDialog::~ConfirmDialog() void ConfirmDialog::action(const std::string &eventId) { if (eventId == "yes" || eventId == "no") { - // I prefer it to be a window, not a dialog - //windowContainer->scheduleDelete(this); + windowContainer->scheduleDelete(this); } } -- cgit v1.2.3-60-g2f50