From d4b405c509b6f65df32f13df0d4be9b77e3c8fac Mon Sep 17 00:00:00 2001 From: Mateusz Kaduk Date: Wed, 22 Dec 2004 10:46:24 +0000 Subject: Setup has create_setup() method that creates only one instance. --- src/game.cpp | 6 ++++-- src/gui/setup.cpp | 35 ++++++++++++++++++----------------- src/gui/setup.h | 12 +++++++----- 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/src/game.cpp b/src/game.cpp index 0d6e95f9..bc9377cf 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -48,6 +48,7 @@ volatile int tick_time; volatile bool refresh = false, action_time = false; int current_npc, server_tick; extern unsigned char screen_mode; +Setup *setup; #define MAX_TIME 10000 @@ -237,8 +238,9 @@ void do_input() { error(allegro_error); } - if(key[KEY_F11] && action_time==true) - create_setup(); + if(key[KEY_F9] && action_time==true) { + setup = Setup::create_setup(); + } // Emotions, Skill dialog if(key_shifts & KB_ALT_FLAG && action_time == true) { diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index 8e6e23d6..3c48986a 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -18,9 +18,9 @@ Setup::Setup(gcn::Container *parent) cancelButton = new gcn::Button("Cancel"); /* Set dimension */ - displayLabel->setDimension(gcn::Rectangle(0,0,128, 16)); - applyButton->setDimension(gcn::Rectangle(0,0,128, 16)); - cancelButton->setDimension(gcn::Rectangle(0,0,128, 16)); + displayLabel->setDimension(gcn::Rectangle(0,0,80, 16)); + applyButton->setDimension(gcn::Rectangle(0,0,80, 16)); + cancelButton->setDimension(gcn::Rectangle(0,0,80, 16)); /* Set events */ applyButton->setEventId("apply"); @@ -28,8 +28,8 @@ Setup::Setup(gcn::Container *parent) /* Set position */ displayLabel->setPosition(10,10); - applyButton->setPosition(10,100); - cancelButton->setPosition(100,100); + applyButton->setPosition(10,190); + cancelButton->setPosition(150,190); /* Listen for actions */ applyButton->addActionListener(this); @@ -42,6 +42,9 @@ Setup::Setup(gcn::Container *parent) setSize(240,216); setLocationRelativeTo(getParent()); + + /* Is hidden */ + //setVisible(false); } Setup::~Setup() { @@ -52,22 +55,20 @@ Setup::~Setup() { void Setup::action(const std::string& eventId) { - if(eventId == "apply") { - puts("apply"); + setVisible(false); } else if(eventId == "cancel") { - puts("cancel"); + setVisible(false); } } -void create_setup() { - Setup *setup; - setup = new Setup(guiTop); - - while(!key[KEY_ESC] && !key[KEY_ENTER]) { - gui_update(NULL); - } - - delete setup; +Setup * Setup::ptr = NULL; +Setup * Setup::create_setup() { + if(ptr == NULL) + ptr = new Setup(guiTop); + else + ptr->setVisible(true); + + return ptr; } diff --git a/src/gui/setup.h b/src/gui/setup.h index d94069a9..b6b83717 100644 --- a/src/gui/setup.h +++ b/src/gui/setup.h @@ -19,15 +19,17 @@ class Setup : public Window, public gcn::ActionListener { gcn::Label *displayLabel; gcn::Button *applyButton; gcn::Button *cancelButton; + + /* Setup dialog */ + static Setup *ptr; - public: + /* Methods */ Setup(gcn::Container *parent); - ~Setup(); + virtual ~Setup(); + public: void action(const std::string& eventId); - + static Setup * create_setup(); }; -void create_setup(); - #endif -- cgit v1.2.3-70-g09d2