From 17f9d5abcb05da185486ccfba293f3a8c9eab437 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 10 Mar 2009 12:23:50 -0600 Subject: Fix some mem leaks --- src/gui/setup.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/gui/setup.cpp') diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index 148e8b75..62d79d4d 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -64,9 +64,9 @@ Setup::Setup(): btn->setPosition(x, height - btn->getHeight() - 5); add(btn); - // Disable this button when the windows aren't created yet + // Store this button, as it needs to be enabled/disabled if (!strcmp(*curBtn, "Reset Windows")) - btn->setEnabled(statusWindow != NULL); + mResetWindows = btn; } TabbedArea *panel = new TabbedArea; @@ -101,6 +101,8 @@ Setup::Setup(): add(panel); setLocationRelativeTo(getParent()); + + setInGame(false); } Setup::~Setup() @@ -140,3 +142,8 @@ void Setup::action(const gcn::ActionEvent &event) tradeWindow->resetToDefaultSize(); } } + +void Setup::setInGame(bool inGame) +{ + mResetWindows->setEnabled(inGame); +} \ No newline at end of file -- cgit v1.2.3-70-g09d2 From 75fc8e62d25ff1d39408588f76d95df4a9a7e663 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 10 Mar 2009 12:23:50 -0600 Subject: Fix some mem leaks --- src/beingmanager.cpp | 5 +++++ src/beingmanager.h | 4 +++- src/game.cpp | 5 +++-- src/gui/chat.cpp | 2 ++ src/gui/setup.cpp | 11 +++++++++-- src/gui/setup.h | 4 ++++ src/gui/setup_colors.cpp | 5 ++--- src/gui/skill.cpp | 2 +- src/gui/table.cpp | 1 + src/gui/window.cpp | 2 ++ src/main.cpp | 1 - src/player_relations.cpp | 24 ++++++++++++++---------- src/player_relations.h | 2 ++ 13 files changed, 48 insertions(+), 20 deletions(-) (limited to 'src/gui/setup.cpp') diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index 0c7a310a..e5836aa7 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -52,6 +52,11 @@ BeingManager::BeingManager(Network *network): { } +BeingManager::~BeingManager() +{ + clear(); +} + void BeingManager::setMap(Map *map) { mMap = map; diff --git a/src/beingmanager.h b/src/beingmanager.h index 472e2c83..3284ce16 100644 --- a/src/beingmanager.h +++ b/src/beingmanager.h @@ -37,6 +37,8 @@ class BeingManager public: BeingManager(Network *network); + ~BeingManager(); + /** * Sets the map on which beings are created */ @@ -113,7 +115,7 @@ class BeingManager void logic(); /** - * Destroys all beings except the local player and current NPC (if any) + * Destroys all beings except the local player */ void clear(); diff --git a/src/game.cpp b/src/game.cpp index 144b059f..3e626d87 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -205,7 +205,6 @@ void createGuiWindows(Network *network) npcListDialog = new NpcListDialog(network); npcStringDialog = new NpcStringDialog(network); skillDialog = new SkillDialog(); - setupWindow = new Setup(); minimap = new Minimap(); equipmentWindow = new EquipmentWindow(); tradeWindow = new TradeWindow(network); @@ -339,11 +338,12 @@ Game::Game(Network *network): msg.writeInt32(tick_time); engine->changeMap(map_path); + + setupWindow->setInGame(true); } Game::~Game() { - delete player_node; destroyGuiWindows(); delete beingManager; @@ -351,6 +351,7 @@ Game::~Game() delete joystick; delete particleEngine; delete engine; + delete player_node; beingManager = NULL; floorItemManager = NULL; diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 098d4e46..44e08052 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -109,6 +109,8 @@ ChatWindow::~ChatWindow() config.setValue("PartyPrefix", partyPrefix); config.setValue("ReturnToggles", mReturnToggles ? "1" : "0"); delete mRecorder; + delete mItemLinkHandler; + delete mParty; } void ChatWindow::chatLog(std::string line, int own, bool ignoreRecord) diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index 4798f598..b24aeb5d 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -65,9 +65,9 @@ Setup::Setup(): btn->setPosition(x, height - btn->getHeight() - 5); add(btn); - // Disable this button when the windows aren't created yet + // Store this button, as it needs to be enabled/disabled if (!strcmp(*curBtn, "Reset Windows")) - btn->setEnabled(statusWindow != NULL); + mResetWindows = btn; } TabbedArea *panel = new TabbedArea(); @@ -102,6 +102,8 @@ Setup::Setup(): add(panel); setLocationRelativeTo(getParent()); + + setInGame(false); } Setup::~Setup() @@ -141,3 +143,8 @@ void Setup::action(const gcn::ActionEvent &event) tradeWindow->resetToDefaultSize(); } } + +void Setup::setInGame(bool inGame) +{ + mResetWindows->setEnabled(inGame); +} \ No newline at end of file diff --git a/src/gui/setup.h b/src/gui/setup.h index 9f1bafc7..d798162c 100644 --- a/src/gui/setup.h +++ b/src/gui/setup.h @@ -32,6 +32,7 @@ #include "../guichanfwd.h" class SetupTab; +class Button; /** * The setup dialog. @@ -51,6 +52,8 @@ class Setup : public Window, public gcn::ActionListener */ ~Setup(); + void setInGame(bool inGame); + /** * Event handling method. */ @@ -58,6 +61,7 @@ class Setup : public Window, public gcn::ActionListener private: std::list mTabs; + gcn::Button *mResetWindows; }; #endif diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp index 31b56b51..ecb5bcf7 100644 --- a/src/gui/setup_colors.cpp +++ b/src/gui/setup_colors.cpp @@ -57,9 +57,8 @@ Setup_Colors::Setup_Colors() : mPreview = new BrowserBox(BrowserBox::AUTO_WRAP); mPreview->setOpaque(false); - // Replace this later with a more appropriate link handler. For now, this'll - // do, as it'll do nothing when clicked on. - mPreview->setLinkHandler(new ItemLinkHandler()); + // don't do anything with links + mPreview->setLinkHandler(NULL); mPreviewBox = new ScrollArea(mPreview); mPreviewBox->setHeight(20); diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp index a8250fce..c29b70ab 100644 --- a/src/gui/skill.cpp +++ b/src/gui/skill.cpp @@ -162,7 +162,7 @@ SkillDialog::SkillDialog(): SkillDialog::~SkillDialog() { - delete mTable; + delete_all(mSkillList); } void SkillDialog::action(const gcn::ActionEvent &event) diff --git a/src/gui/table.cpp b/src/gui/table.cpp index b2571495..7d0fd48a 100644 --- a/src/gui/table.cpp +++ b/src/gui/table.cpp @@ -99,6 +99,7 @@ GuiTable::GuiTable(TableModel *initial_model, gcn::Color background, GuiTable::~GuiTable(void) { + uninstallActionListeners(); delete mModel; } diff --git a/src/gui/window.cpp b/src/gui/window.cpp index bf1ec01c..b0bf1c59 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -130,6 +130,8 @@ Window::~Window() delete(w); } + removeWidgetListener(this); + instances--; // Clean up static resources diff --git a/src/main.cpp b/src/main.cpp index f7468d84..a43544bc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1015,7 +1015,6 @@ int main(int argc, char *argv[]) delete progressBar; delete progressLabel; delete setup; - delete setupWindow; progressBar = NULL; progressLabel = NULL; currentDialog = NULL; diff --git a/src/player_relations.cpp b/src/player_relations.cpp index 1c1ba669..65219626 100644 --- a/src/player_relations.cpp +++ b/src/player_relations.cpp @@ -29,6 +29,8 @@ #include "player.h" #include "player_relations.h" +#include "utils/dtor.h" + #define PLAYER_IGNORE_STRATEGY_NOP "nop" #define PLAYER_IGNORE_STRATEGY_EMOTE0 "emote0" #define DEFAULT_IGNORE_STRATEGY PLAYER_IGNORE_STRATEGY_EMOTE0 @@ -38,7 +40,6 @@ #define IGNORE_EMOTE_TIME 100 - // (De)serialisation class class PlayerConfSerialiser : public ConfigurationListManager, std::map *> @@ -93,6 +94,11 @@ PlayerRelationsManager::PlayerRelationsManager() : { } +PlayerRelationsManager::~PlayerRelationsManager() +{ + delete_all(mIgnoreStrategies); +} + void PlayerRelationsManager::clear() { std::vector *names = getPlayers(); @@ -346,24 +352,22 @@ private: -static std::vector player_ignore_strategies; - std::vector * PlayerRelationsManager::getPlayerIgnoreStrategies() { - if (player_ignore_strategies.size() == 0) { + if (mIgnoreStrategies.size() == 0) { // not initialised yet? - player_ignore_strategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE, + mIgnoreStrategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE, "floating '...' bubble", PLAYER_IGNORE_STRATEGY_EMOTE0)); - player_ignore_strategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE + 1, + mIgnoreStrategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE + 1, "floating bubble", "emote1")); - player_ignore_strategies.push_back(new PIS_nothing()); - player_ignore_strategies.push_back(new PIS_dotdotdot()); - player_ignore_strategies.push_back(new PIS_blinkname()); + mIgnoreStrategies.push_back(new PIS_nothing()); + mIgnoreStrategies.push_back(new PIS_dotdotdot()); + mIgnoreStrategies.push_back(new PIS_blinkname()); } - return &player_ignore_strategies; + return &mIgnoreStrategies; } diff --git a/src/player_relations.h b/src/player_relations.h index 0440cace..edfa9b28 100644 --- a/src/player_relations.h +++ b/src/player_relations.h @@ -95,6 +95,7 @@ class PlayerRelationsManager { public: PlayerRelationsManager(); + ~PlayerRelationsManager(); /** * Initialise player relations manager (load config file etc.) @@ -233,6 +234,7 @@ private: PlayerIgnoreStrategy *mIgnoreStrategy; std::map mRelations; std::list mListeners; + std::vector mIgnoreStrategies; }; -- cgit v1.2.3-70-g09d2 From e2e30710a646965a506444cc0dc8a91e1a718002 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 10 Mar 2009 12:43:56 -0600 Subject: Remove some SetupWindow weirdness --- src/game.cpp | 2 -- src/gui/setup.cpp | 10 ++++++++-- src/gui/setup.h | 2 ++ src/main.cpp | 3 --- 4 files changed, 10 insertions(+), 7 deletions(-) (limited to 'src/gui/setup.cpp') diff --git a/src/game.cpp b/src/game.cpp index ae708adf..6e513eec 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -121,7 +121,6 @@ NpcListDialog *npcListDialog; NpcTextDialog *npcTextDialog; NpcStringDialog *npcStringDialog; SkillDialog *skillDialog; -Setup* setupWindow; Minimap *minimap; EquipmentWindow *equipmentWindow; TradeWindow *tradeWindow; @@ -261,7 +260,6 @@ void destroyGuiWindows() delete npcTextDialog; delete npcStringDialog; delete skillDialog; - delete setupWindow; delete minimap; delete equipmentWindow; delete tradeWindow; diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index 62d79d4d..8062ac06 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -65,10 +65,14 @@ Setup::Setup(): add(btn); // Store this button, as it needs to be enabled/disabled - if (!strcmp(*curBtn, "Reset Windows")) + if (!strcmp(*curBtn, "Reset Windows")) { mResetWindows = btn; + printf("!\n"); + } } + if (mResetWindows) printf("!\n"); + TabbedArea *panel = new TabbedArea; panel->setDimension(gcn::Rectangle(5, 5, width - 10, height - 40)); @@ -146,4 +150,6 @@ void Setup::action(const gcn::ActionEvent &event) void Setup::setInGame(bool inGame) { mResetWindows->setEnabled(inGame); -} \ No newline at end of file +} + +Setup* setupWindow; diff --git a/src/gui/setup.h b/src/gui/setup.h index 075c88bf..919445b7 100644 --- a/src/gui/setup.h +++ b/src/gui/setup.h @@ -63,4 +63,6 @@ class Setup : public Window, public gcn::ActionListener gcn::Button *mResetWindows; }; +extern Setup* setupWindow; + #endif diff --git a/src/main.cpp b/src/main.cpp index 06093946..32ff3ac3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -101,8 +101,6 @@ namespace { - Window *setupWindow = 0; - struct SetupListener : public gcn::ActionListener { /** @@ -1031,7 +1029,6 @@ int main(int argc, char *argv[]) progressLabel = NULL; currentDialog = NULL; setup = NULL; - setupWindow = NULL; login_wallpaper->decRef(); login_wallpaper = NULL; -- cgit v1.2.3-70-g09d2 From cabb9735f2e31b9f1f64b2496e1775d54861da36 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 10 Mar 2009 12:23:50 -0600 Subject: Fix some mem leaks --- src/beingmanager.cpp | 5 ----- src/beingmanager.h | 4 +--- src/game.cpp | 5 ++--- src/gui/chat.cpp | 2 -- src/gui/setup.cpp | 11 ++--------- src/gui/setup.h | 4 ---- src/gui/setup_colors.cpp | 5 +++-- src/gui/skill.cpp | 2 +- src/gui/table.cpp | 1 - src/gui/window.cpp | 2 -- src/main.cpp | 1 + src/player_relations.cpp | 24 ++++++++++-------------- src/player_relations.h | 2 -- 13 files changed, 20 insertions(+), 48 deletions(-) (limited to 'src/gui/setup.cpp') diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index e5836aa7..0c7a310a 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -52,11 +52,6 @@ BeingManager::BeingManager(Network *network): { } -BeingManager::~BeingManager() -{ - clear(); -} - void BeingManager::setMap(Map *map) { mMap = map; diff --git a/src/beingmanager.h b/src/beingmanager.h index 3284ce16..472e2c83 100644 --- a/src/beingmanager.h +++ b/src/beingmanager.h @@ -37,8 +37,6 @@ class BeingManager public: BeingManager(Network *network); - ~BeingManager(); - /** * Sets the map on which beings are created */ @@ -115,7 +113,7 @@ class BeingManager void logic(); /** - * Destroys all beings except the local player + * Destroys all beings except the local player and current NPC (if any) */ void clear(); diff --git a/src/game.cpp b/src/game.cpp index 3e626d87..144b059f 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -205,6 +205,7 @@ void createGuiWindows(Network *network) npcListDialog = new NpcListDialog(network); npcStringDialog = new NpcStringDialog(network); skillDialog = new SkillDialog(); + setupWindow = new Setup(); minimap = new Minimap(); equipmentWindow = new EquipmentWindow(); tradeWindow = new TradeWindow(network); @@ -338,12 +339,11 @@ Game::Game(Network *network): msg.writeInt32(tick_time); engine->changeMap(map_path); - - setupWindow->setInGame(true); } Game::~Game() { + delete player_node; destroyGuiWindows(); delete beingManager; @@ -351,7 +351,6 @@ Game::~Game() delete joystick; delete particleEngine; delete engine; - delete player_node; beingManager = NULL; floorItemManager = NULL; diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 44e08052..098d4e46 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -109,8 +109,6 @@ ChatWindow::~ChatWindow() config.setValue("PartyPrefix", partyPrefix); config.setValue("ReturnToggles", mReturnToggles ? "1" : "0"); delete mRecorder; - delete mItemLinkHandler; - delete mParty; } void ChatWindow::chatLog(std::string line, int own, bool ignoreRecord) diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index b24aeb5d..4798f598 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -65,9 +65,9 @@ Setup::Setup(): btn->setPosition(x, height - btn->getHeight() - 5); add(btn); - // Store this button, as it needs to be enabled/disabled + // Disable this button when the windows aren't created yet if (!strcmp(*curBtn, "Reset Windows")) - mResetWindows = btn; + btn->setEnabled(statusWindow != NULL); } TabbedArea *panel = new TabbedArea(); @@ -102,8 +102,6 @@ Setup::Setup(): add(panel); setLocationRelativeTo(getParent()); - - setInGame(false); } Setup::~Setup() @@ -143,8 +141,3 @@ void Setup::action(const gcn::ActionEvent &event) tradeWindow->resetToDefaultSize(); } } - -void Setup::setInGame(bool inGame) -{ - mResetWindows->setEnabled(inGame); -} \ No newline at end of file diff --git a/src/gui/setup.h b/src/gui/setup.h index d798162c..9f1bafc7 100644 --- a/src/gui/setup.h +++ b/src/gui/setup.h @@ -32,7 +32,6 @@ #include "../guichanfwd.h" class SetupTab; -class Button; /** * The setup dialog. @@ -52,8 +51,6 @@ class Setup : public Window, public gcn::ActionListener */ ~Setup(); - void setInGame(bool inGame); - /** * Event handling method. */ @@ -61,7 +58,6 @@ class Setup : public Window, public gcn::ActionListener private: std::list mTabs; - gcn::Button *mResetWindows; }; #endif diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp index ecb5bcf7..31b56b51 100644 --- a/src/gui/setup_colors.cpp +++ b/src/gui/setup_colors.cpp @@ -57,8 +57,9 @@ Setup_Colors::Setup_Colors() : mPreview = new BrowserBox(BrowserBox::AUTO_WRAP); mPreview->setOpaque(false); - // don't do anything with links - mPreview->setLinkHandler(NULL); + // Replace this later with a more appropriate link handler. For now, this'll + // do, as it'll do nothing when clicked on. + mPreview->setLinkHandler(new ItemLinkHandler()); mPreviewBox = new ScrollArea(mPreview); mPreviewBox->setHeight(20); diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp index c29b70ab..a8250fce 100644 --- a/src/gui/skill.cpp +++ b/src/gui/skill.cpp @@ -162,7 +162,7 @@ SkillDialog::SkillDialog(): SkillDialog::~SkillDialog() { - delete_all(mSkillList); + delete mTable; } void SkillDialog::action(const gcn::ActionEvent &event) diff --git a/src/gui/table.cpp b/src/gui/table.cpp index 7d0fd48a..b2571495 100644 --- a/src/gui/table.cpp +++ b/src/gui/table.cpp @@ -99,7 +99,6 @@ GuiTable::GuiTable(TableModel *initial_model, gcn::Color background, GuiTable::~GuiTable(void) { - uninstallActionListeners(); delete mModel; } diff --git a/src/gui/window.cpp b/src/gui/window.cpp index b0bf1c59..bf1ec01c 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -130,8 +130,6 @@ Window::~Window() delete(w); } - removeWidgetListener(this); - instances--; // Clean up static resources diff --git a/src/main.cpp b/src/main.cpp index a43544bc..f7468d84 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1015,6 +1015,7 @@ int main(int argc, char *argv[]) delete progressBar; delete progressLabel; delete setup; + delete setupWindow; progressBar = NULL; progressLabel = NULL; currentDialog = NULL; diff --git a/src/player_relations.cpp b/src/player_relations.cpp index 65219626..1c1ba669 100644 --- a/src/player_relations.cpp +++ b/src/player_relations.cpp @@ -29,8 +29,6 @@ #include "player.h" #include "player_relations.h" -#include "utils/dtor.h" - #define PLAYER_IGNORE_STRATEGY_NOP "nop" #define PLAYER_IGNORE_STRATEGY_EMOTE0 "emote0" #define DEFAULT_IGNORE_STRATEGY PLAYER_IGNORE_STRATEGY_EMOTE0 @@ -40,6 +38,7 @@ #define IGNORE_EMOTE_TIME 100 + // (De)serialisation class class PlayerConfSerialiser : public ConfigurationListManager, std::map *> @@ -94,11 +93,6 @@ PlayerRelationsManager::PlayerRelationsManager() : { } -PlayerRelationsManager::~PlayerRelationsManager() -{ - delete_all(mIgnoreStrategies); -} - void PlayerRelationsManager::clear() { std::vector *names = getPlayers(); @@ -352,22 +346,24 @@ private: +static std::vector player_ignore_strategies; + std::vector * PlayerRelationsManager::getPlayerIgnoreStrategies() { - if (mIgnoreStrategies.size() == 0) { + if (player_ignore_strategies.size() == 0) { // not initialised yet? - mIgnoreStrategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE, + player_ignore_strategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE, "floating '...' bubble", PLAYER_IGNORE_STRATEGY_EMOTE0)); - mIgnoreStrategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE + 1, + player_ignore_strategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE + 1, "floating bubble", "emote1")); - mIgnoreStrategies.push_back(new PIS_nothing()); - mIgnoreStrategies.push_back(new PIS_dotdotdot()); - mIgnoreStrategies.push_back(new PIS_blinkname()); + player_ignore_strategies.push_back(new PIS_nothing()); + player_ignore_strategies.push_back(new PIS_dotdotdot()); + player_ignore_strategies.push_back(new PIS_blinkname()); } - return &mIgnoreStrategies; + return &player_ignore_strategies; } diff --git a/src/player_relations.h b/src/player_relations.h index edfa9b28..0440cace 100644 --- a/src/player_relations.h +++ b/src/player_relations.h @@ -95,7 +95,6 @@ class PlayerRelationsManager { public: PlayerRelationsManager(); - ~PlayerRelationsManager(); /** * Initialise player relations manager (load config file etc.) @@ -234,7 +233,6 @@ private: PlayerIgnoreStrategy *mIgnoreStrategy; std::map mRelations; std::list mListeners; - std::vector mIgnoreStrategies; }; -- cgit v1.2.3-70-g09d2 From 4676d0fe6ee938031ce13a65927718f9b53810cf Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 10 Mar 2009 12:43:56 -0600 Subject: Remove some SetupWindow weirdness --- src/game.cpp | 2 -- src/gui/setup.cpp | 13 ++++++++++--- src/gui/setup.h | 8 ++++++++ src/main.cpp | 3 --- 4 files changed, 18 insertions(+), 8 deletions(-) (limited to 'src/gui/setup.cpp') diff --git a/src/game.cpp b/src/game.cpp index 144b059f..3b621acd 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -122,7 +122,6 @@ NpcListDialog *npcListDialog; NpcTextDialog *npcTextDialog; NpcStringDialog *npcStringDialog; SkillDialog *skillDialog; -Setup* setupWindow; Minimap *minimap; EquipmentWindow *equipmentWindow; TradeWindow *tradeWindow; @@ -261,7 +260,6 @@ void destroyGuiWindows() delete npcTextDialog; delete npcStringDialog; delete skillDialog; - delete setupWindow; delete minimap; delete equipmentWindow; delete tradeWindow; diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index 4798f598..f1e7a6d9 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -65,12 +65,12 @@ Setup::Setup(): btn->setPosition(x, height - btn->getHeight() - 5); add(btn); - // Disable this button when the windows aren't created yet + // Store this button, as it needs to be enabled/disabled if (!strcmp(*curBtn, "Reset Windows")) - btn->setEnabled(statusWindow != NULL); + mResetWindows = btn; } - TabbedArea *panel = new TabbedArea(); + TabbedArea *panel = new TabbedArea; panel->setDimension(gcn::Rectangle(5, 5, width - 10, height - 40)); SetupTab *tab; @@ -141,3 +141,10 @@ void Setup::action(const gcn::ActionEvent &event) tradeWindow->resetToDefaultSize(); } } + +void Setup::setInGame(bool inGame) +{ + mResetWindows->setEnabled(inGame); +} + +Setup* setupWindow; diff --git a/src/gui/setup.h b/src/gui/setup.h index 9f1bafc7..663bdfcb 100644 --- a/src/gui/setup.h +++ b/src/gui/setup.h @@ -56,8 +56,16 @@ class Setup : public Window, public gcn::ActionListener */ void action(const gcn::ActionEvent &event); + /** + * Enables the reset button when in game. + */ + void setInGame(bool inGame); + private: std::list mTabs; + gcn::Button* mResetWindows; }; +extern Setup* setupWindow; + #endif diff --git a/src/main.cpp b/src/main.cpp index f7468d84..9e7c91c0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -101,8 +101,6 @@ namespace { - Window *setupWindow = 0; - struct SetupListener : public gcn::ActionListener { /** @@ -1020,7 +1018,6 @@ int main(int argc, char *argv[]) progressLabel = NULL; currentDialog = NULL; setup = NULL; - setupWindow = NULL; login_wallpaper->decRef(); login_wallpaper = NULL; -- cgit v1.2.3-70-g09d2 From 7af746a8ce0c64932923419c5a35a25a5b8c4005 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 10 Mar 2009 16:36:34 -0600 Subject: Delete local player earlier and fix a rare crash Rare crash is in KeyboardConfig, where the active keys array is accessed before it's initialized. Also remove some debug prints that made it into a previous commit. --- src/game.cpp | 2 +- src/gui/setup.cpp | 3 --- src/keyboardconfig.cpp | 1 + 3 files changed, 2 insertions(+), 4 deletions(-) (limited to 'src/gui/setup.cpp') diff --git a/src/game.cpp b/src/game.cpp index 6e513eec..e04a5ee8 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -347,11 +347,11 @@ Game::~Game() destroyGuiWindows(); delete beingManager; + delete player_node; delete floorItemManager; delete joystick; delete particleEngine; delete engine; - delete player_node; beingManager = NULL; floorItemManager = NULL; diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index 8062ac06..68bc3a4b 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -67,12 +67,9 @@ Setup::Setup(): // Store this button, as it needs to be enabled/disabled if (!strcmp(*curBtn, "Reset Windows")) { mResetWindows = btn; - printf("!\n"); } } - if (mResetWindows) printf("!\n"); - TabbedArea *panel = new TabbedArea; panel->setDimension(gcn::Rectangle(5, 5, width - 10, height - 40)); diff --git a/src/keyboardconfig.cpp b/src/keyboardconfig.cpp index 73c0fe0a..06ce4ac7 100644 --- a/src/keyboardconfig.cpp +++ b/src/keyboardconfig.cpp @@ -197,6 +197,7 @@ int KeyboardConfig::getKeyEmoteOffset(int keyValue) const bool KeyboardConfig::isKeyActive(int index) { + if (!mActiveKeys) return false; return mActiveKeys[mKey[index].value]; } -- cgit v1.2.3-70-g09d2 From 73fa81961d141b7592862a50993cd998fbd4de31 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Sat, 14 Mar 2009 21:50:58 -0600 Subject: Exposed a few more windows to the reset window button under the setup dialog. Signed-off-by: Ira Rice --- src/gui/npcstringdialog.cpp | 1 - src/gui/setup.cpp | 6 ++++++ 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'src/gui/setup.cpp') diff --git a/src/gui/npcstringdialog.cpp b/src/gui/npcstringdialog.cpp index 58a5c0c8..f50136ba 100644 --- a/src/gui/npcstringdialog.cpp +++ b/src/gui/npcstringdialog.cpp @@ -47,7 +47,6 @@ NpcStringDialog::NpcStringDialog(Network *network): place(0, 0, mValueField, 3); place(1, 1, cancelButton); place(2, 1, okButton); - //reflowLayout(175, 0); loadWindowState(); } diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index f1e7a6d9..5fe35a6c 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -45,6 +45,9 @@ extern Window *itemShortcutWindow; extern Window *emoteShortcutWindow; extern Window *emoteWindow; extern Window *tradeWindow; +extern Window *npcTextDialog; +extern Window *npcStringDialog; +extern Window *storageWindow; Setup::Setup(): Window(_("Setup")) @@ -139,6 +142,9 @@ void Setup::action(const gcn::ActionEvent &event) emoteShortcutWindow->resetToDefaultSize(); emoteWindow->resetToDefaultSize(); tradeWindow->resetToDefaultSize(); + npcTextDialog->resetToDefaultSize(); + npcStringDialog->resetToDefaultSize(); + storageWindow->resetToDefaultSize(); } } -- cgit v1.2.3-70-g09d2 From a9a1ed080289185cc5e71a127d7fdf35c920de8a Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Sat, 14 Mar 2009 22:03:30 -0600 Subject: Exposed a few more windows to the reset button on the setup window. These windows required an external declaration to reset. Signed-off-by: Ira Rice --- src/gui/buy.h | 2 ++ src/gui/chat.h | 12 ++++++------ src/gui/debugwindow.h | 2 ++ src/gui/sell.h | 2 ++ src/gui/setup.cpp | 36 +++++++++++++++++++++--------------- 5 files changed, 33 insertions(+), 21 deletions(-) (limited to 'src/gui/setup.cpp') diff --git a/src/gui/buy.h b/src/gui/buy.h index 9029fe9d..17ab6e19 100644 --- a/src/gui/buy.h +++ b/src/gui/buy.h @@ -117,4 +117,6 @@ class BuyDialog : public Window, public gcn::ActionListener, Uint32 mMaxItems; }; +extern BuyDialog *buyDialog; + #endif diff --git a/src/gui/chat.h b/src/gui/chat.h index 45d0c92f..28408b93 100644 --- a/src/gui/chat.h +++ b/src/gui/chat.h @@ -236,12 +236,12 @@ class ChatWindow : public Window, public gcn::ActionListener, typedef std::list History; typedef History::iterator HistoryIterator; History mHistory; /**< Command history */ - HistoryIterator mCurHist; /**< History iterator */ - Recorder *mRecorder; /**< Recording class */ - char mPartyPrefix; /**< Messages beginning with the prefix are sent to - the party */ - bool mReturnToggles; /**< Marks whether toggles the chat log - or not */ + HistoryIterator mCurHist; /**< History iterator */ + Recorder *mRecorder; /**< Recording class */ + char mPartyPrefix; /**< Messages beginning with the prefix are + sent to the party */ + bool mReturnToggles; /**< Marks whether toggles the chat + log or not */ Party *mParty; }; extern ChatWindow *chatWindow; diff --git a/src/gui/debugwindow.h b/src/gui/debugwindow.h index 95e8b5e4..c82521f9 100644 --- a/src/gui/debugwindow.h +++ b/src/gui/debugwindow.h @@ -51,4 +51,6 @@ class DebugWindow : public Window gcn::Label *mParticleCountLabel; }; +extern DebugWindow *debugWindow; + #endif diff --git a/src/gui/sell.h b/src/gui/sell.h index 3776477f..5fb94c4e 100644 --- a/src/gui/sell.h +++ b/src/gui/sell.h @@ -108,4 +108,6 @@ class SellDialog : public Window, gcn::ActionListener, gcn::SelectionListener int mAmountItems; }; +extern SellDialog *sellDialog; + #endif diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index 5fe35a6c..ab0b2245 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -35,18 +35,21 @@ #include "../utils/gettext.h" extern Window *chatWindow; -extern Window *equipmentWindow; -extern Window *helpWindow; -extern Window *inventoryWindow; -extern Window *minimap; -extern Window *skillDialog; extern Window *statusWindow; -extern Window *itemShortcutWindow; -extern Window *emoteShortcutWindow; +extern Window *buyDialog; +extern Window *sellDialog; +extern Window *inventoryWindow; extern Window *emoteWindow; -extern Window *tradeWindow; extern Window *npcTextDialog; extern Window *npcStringDialog; +extern Window *skillDialog; +extern Window *minimap; +extern Window *equipmentWindow; +extern Window *tradeWindow; +extern Window *helpWindow; +extern Window *debugWindow; +extern Window *itemShortcutWindow; +extern Window *emoteShortcutWindow; extern Window *storageWindow; Setup::Setup(): @@ -131,19 +134,22 @@ void Setup::action(const gcn::ActionEvent &event) if (!statusWindow) return; - statusWindow->resetToDefaultSize(); - minimap->resetToDefaultSize(); chatWindow->resetToDefaultSize(); + statusWindow->resetToDefaultSize(); + buyDialog->resetToDefaultSize(); + sellDialog->resetToDefaultSize(); inventoryWindow->resetToDefaultSize(); + emoteWindow->resetToDefaultSize(); + npcTextDialog->resetToDefaultSize(); + npcStringDialog->resetToDefaultSize(); + skillDialog->resetToDefaultSize(); + minimap->resetToDefaultSize(); equipmentWindow->resetToDefaultSize(); + tradeWindow->resetToDefaultSize(); helpWindow->resetToDefaultSize(); - skillDialog->resetToDefaultSize(); + debugWindow->resetToDefaultSize(); itemShortcutWindow->resetToDefaultSize(); emoteShortcutWindow->resetToDefaultSize(); - emoteWindow->resetToDefaultSize(); - tradeWindow->resetToDefaultSize(); - npcTextDialog->resetToDefaultSize(); - npcStringDialog->resetToDefaultSize(); storageWindow->resetToDefaultSize(); } } -- cgit v1.2.3-70-g09d2 From d6f89802e5aa32f266e881e43d6005e821040c57 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 10 Mar 2009 12:23:50 -0600 Subject: Fix some mem leaks --- src/beingmanager.cpp | 5 +++++ src/beingmanager.h | 4 +++- src/game.cpp | 3 ++- src/gui/chat.cpp | 2 ++ src/gui/setup.cpp | 2 ++ src/gui/setup_colors.cpp | 5 ++--- src/gui/skill.cpp | 2 +- src/gui/table.cpp | 1 + src/gui/window.cpp | 2 ++ src/main.cpp | 1 - src/player_relations.cpp | 31 +++++++++++++++++++------------ src/player_relations.h | 6 +++--- 12 files changed, 42 insertions(+), 22 deletions(-) (limited to 'src/gui/setup.cpp') diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index 0c7a310a..e5836aa7 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -52,6 +52,11 @@ BeingManager::BeingManager(Network *network): { } +BeingManager::~BeingManager() +{ + clear(); +} + void BeingManager::setMap(Map *map) { mMap = map; diff --git a/src/beingmanager.h b/src/beingmanager.h index 472e2c83..3284ce16 100644 --- a/src/beingmanager.h +++ b/src/beingmanager.h @@ -37,6 +37,8 @@ class BeingManager public: BeingManager(Network *network); + ~BeingManager(); + /** * Sets the map on which beings are created */ @@ -113,7 +115,7 @@ class BeingManager void logic(); /** - * Destroys all beings except the local player and current NPC (if any) + * Destroys all beings except the local player */ void clear(); diff --git a/src/game.cpp b/src/game.cpp index 47f4ffd2..a346616f 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -204,7 +204,6 @@ void createGuiWindows(Network *network) npcListDialog = new NpcListDialog(network); npcStringDialog = new NpcStringDialog(network); skillDialog = new SkillDialog(); - setupWindow = new Setup(); minimap = new Minimap(); equipmentWindow = new EquipmentWindow(); tradeWindow = new TradeWindow(network); @@ -337,6 +336,8 @@ Game::Game(Network *network): msg.writeInt32(tick_time); engine->changeMap(map_path); + + setupWindow->setInGame(true); } Game::~Game() diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 098d4e46..44e08052 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -109,6 +109,8 @@ ChatWindow::~ChatWindow() config.setValue("PartyPrefix", partyPrefix); config.setValue("ReturnToggles", mReturnToggles ? "1" : "0"); delete mRecorder; + delete mItemLinkHandler; + delete mParty; } void ChatWindow::chatLog(std::string line, int own, bool ignoreRecord) diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index ab0b2245..dc232296 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -108,6 +108,8 @@ Setup::Setup(): add(panel); setLocationRelativeTo(getParent()); + + setInGame(false); } Setup::~Setup() diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp index 760fdc1f..148fd679 100644 --- a/src/gui/setup_colors.cpp +++ b/src/gui/setup_colors.cpp @@ -62,9 +62,8 @@ Setup_Colors::Setup_Colors() : mPreview = new BrowserBox(BrowserBox::AUTO_WRAP); mPreview->setOpaque(false); - // Replace this later with a more appropriate link handler. For now, this'll - // do, as it'll do nothing when clicked on. - mPreview->setLinkHandler(new ItemLinkHandler()); + // don't do anything with links + mPreview->setLinkHandler(NULL); mPreviewBox = new ScrollArea(mPreview); mPreviewBox->setHeight(20); diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp index 64214ff5..9fbae7a6 100644 --- a/src/gui/skill.cpp +++ b/src/gui/skill.cpp @@ -161,7 +161,7 @@ SkillDialog::SkillDialog(): SkillDialog::~SkillDialog() { - delete mTable; + delete_all(mSkillList); } void SkillDialog::action(const gcn::ActionEvent &event) diff --git a/src/gui/table.cpp b/src/gui/table.cpp index 144e7e21..fa801865 100644 --- a/src/gui/table.cpp +++ b/src/gui/table.cpp @@ -99,6 +99,7 @@ GuiTable::GuiTable(TableModel *initial_model, gcn::Color background, GuiTable::~GuiTable(void) { + uninstallActionListeners(); delete mModel; } diff --git a/src/gui/window.cpp b/src/gui/window.cpp index e6e79b45..404f5746 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -124,6 +124,8 @@ Window::~Window() delete(w); } + removeWidgetListener(this); + instances--; mSkin->instances--; diff --git a/src/main.cpp b/src/main.cpp index 60a4d500..7ee2f6b4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1021,7 +1021,6 @@ int main(int argc, char *argv[]) delete progressBar; delete progressLabel; delete setup; - delete setupWindow; progressBar = NULL; progressLabel = NULL; currentDialog = NULL; diff --git a/src/player_relations.cpp b/src/player_relations.cpp index 1c1ba669..eec4153c 100644 --- a/src/player_relations.cpp +++ b/src/player_relations.cpp @@ -29,6 +29,8 @@ #include "player.h" #include "player_relations.h" +#include "utils/dtor.h" + #define PLAYER_IGNORE_STRATEGY_NOP "nop" #define PLAYER_IGNORE_STRATEGY_EMOTE0 "emote0" #define DEFAULT_IGNORE_STRATEGY PLAYER_IGNORE_STRATEGY_EMOTE0 @@ -38,7 +40,6 @@ #define IGNORE_EMOTE_TIME 100 - // (De)serialisation class class PlayerConfSerialiser : public ConfigurationListManager, std::map *> @@ -93,6 +94,11 @@ PlayerRelationsManager::PlayerRelationsManager() : { } +PlayerRelationsManager::~PlayerRelationsManager() +{ + delete_all(mIgnoreStrategies); +} + void PlayerRelationsManager::clear() { std::vector *names = getPlayers(); @@ -351,19 +357,20 @@ static std::vector player_ignore_strategies; std::vector * PlayerRelationsManager::getPlayerIgnoreStrategies() { - if (player_ignore_strategies.size() == 0) { + if (mIgnoreStrategies.size() == 0) + { // not initialised yet? - player_ignore_strategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE, - "floating '...' bubble", - PLAYER_IGNORE_STRATEGY_EMOTE0)); - player_ignore_strategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE + 1, - "floating bubble", - "emote1")); - player_ignore_strategies.push_back(new PIS_nothing()); - player_ignore_strategies.push_back(new PIS_dotdotdot()); - player_ignore_strategies.push_back(new PIS_blinkname()); + mIgnoreStrategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE, + "floating '...' bubble", + PLAYER_IGNORE_STRATEGY_EMOTE0)); + mIgnoreStrategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE + 1, + "floating bubble", + "emote1")); + mIgnoreStrategies.push_back(new PIS_nothing()); + mIgnoreStrategies.push_back(new PIS_dotdotdot()); + mIgnoreStrategies.push_back(new PIS_blinkname()); } - return &player_ignore_strategies; + return &mIgnoreStrategies; } diff --git a/src/player_relations.h b/src/player_relations.h index 0440cace..f4860e08 100644 --- a/src/player_relations.h +++ b/src/player_relations.h @@ -96,6 +96,8 @@ class PlayerRelationsManager public: PlayerRelationsManager(); + ~PlayerRelationsManager(); + /** * Initialise player relations manager (load config file etc.) */ @@ -143,7 +145,6 @@ public: */ void removePlayer(const std::string &name); - /** * Retrieves the default permissions. */ @@ -154,8 +155,6 @@ public: */ void setDefault(unsigned int permissions); - - /** * Retrieves all known player ignore strategies. * @@ -233,6 +232,7 @@ private: PlayerIgnoreStrategy *mIgnoreStrategy; std::map mRelations; std::list mListeners; + std::vector mIgnoreStrategies; }; -- cgit v1.2.3-70-g09d2 From a9b1eccdd2c719f86475c6ce01d4b8eea7dede6c Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Sun, 15 Mar 2009 13:56:40 -0600 Subject: Overrode the reset window function in the chat window to also reset the position of the recorder, as well as fixed resetting the help window, and exposing the buy/sell window to being resettable, as well as remembering its previous position. All windows should now be covered by the reset button on the setup pane. Signed-off-by: Ira Rice --- src/gui/buysell.cpp | 5 +++-- src/gui/buysell.h | 2 ++ src/gui/chat.cpp | 6 ++++++ src/gui/chat.h | 6 ++++++ src/gui/help.cpp | 13 +++++++------ src/gui/setup.cpp | 2 ++ src/gui/window.h | 2 +- 7 files changed, 27 insertions(+), 9 deletions(-) (limited to 'src/gui/setup.cpp') diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp index 2022b040..4ac06220 100644 --- a/src/gui/buysell.cpp +++ b/src/gui/buysell.cpp @@ -49,9 +49,10 @@ BuySellDialog::BuySellDialog(Network *network): } buyButton->requestFocus(); - setContentSize(x, 2 * y + buyButton->getHeight()); + setDefaultSize(x + getPadding(), (2 * y + buyButton->getHeight() + + getTitleBarHeight()), ImageRect::CENTER); - setLocationRelativeTo(ImageRect::CENTER); + loadWindowState(); requestFocus(); } diff --git a/src/gui/buysell.h b/src/gui/buysell.h index 747066a7..0842c0e1 100644 --- a/src/gui/buysell.h +++ b/src/gui/buysell.h @@ -54,4 +54,6 @@ class BuySellDialog : public Window, public gcn::ActionListener Network *mNetwork; }; +extern BuySellDialog *buySellDialog; + #endif diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 44e08052..5ff9ed46 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -113,6 +113,12 @@ ChatWindow::~ChatWindow() delete mParty; } +void ChatWindow::resetToDefaultSize() +{ + mRecorder->resetToDefaultSize(); + Window::resetToDefaultSize(); +} + void ChatWindow::chatLog(std::string line, int own, bool ignoreRecord) { // Trim whitespace diff --git a/src/gui/chat.h b/src/gui/chat.h index 28408b93..8b710dc8 100644 --- a/src/gui/chat.h +++ b/src/gui/chat.h @@ -119,6 +119,12 @@ class ChatWindow : public Window, public gcn::ActionListener, */ ~ChatWindow(); + /** + * Reset the chat window and recorder window attached to it to their + * default positions. + */ + void resetToDefaultSize(); + /** * Adds a line of text to our message list. Parameters: * diff --git a/src/gui/help.cpp b/src/gui/help.cpp index fec39199..0974abf7 100644 --- a/src/gui/help.cpp +++ b/src/gui/help.cpp @@ -40,16 +40,17 @@ HelpWindow::HelpWindow(): setWindowName(_("Help")); setResizable(true); + setDefaultSize(500, 400, ImageRect::CENTER); + mBrowserBox = new BrowserBox(); mBrowserBox->setOpaque(false); mScrollArea = new ScrollArea(mBrowserBox); Button *okButton = new Button(_("Close"), "close", this); - mScrollArea->setDimension(gcn::Rectangle( - 5, 5, 445, 335 - okButton->getHeight())); - okButton->setPosition( - 450 - okButton->getWidth(), - 345 - okButton->getHeight()); + mScrollArea->setDimension(gcn::Rectangle(5, 5, 445, + 335 - okButton->getHeight())); + okButton->setPosition(450 - okButton->getWidth(), + 345 - okButton->getHeight()); mBrowserBox->setLinkHandler(this); @@ -59,7 +60,7 @@ HelpWindow::HelpWindow(): Layout &layout = getLayout(); layout.setRowHeight(0, Layout::AUTO_SET); - setLocationRelativeTo(getParent()); + loadWindowState(); } void HelpWindow::action(const gcn::ActionEvent &event) diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index dc232296..ca6b4010 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -38,6 +38,7 @@ extern Window *chatWindow; extern Window *statusWindow; extern Window *buyDialog; extern Window *sellDialog; +extern Window *buySellDialog; extern Window *inventoryWindow; extern Window *emoteWindow; extern Window *npcTextDialog; @@ -140,6 +141,7 @@ void Setup::action(const gcn::ActionEvent &event) statusWindow->resetToDefaultSize(); buyDialog->resetToDefaultSize(); sellDialog->resetToDefaultSize(); + buySellDialog->resetToDefaultSize(); inventoryWindow->resetToDefaultSize(); emoteWindow->resetToDefaultSize(); npcTextDialog->resetToDefaultSize(); diff --git a/src/gui/window.h b/src/gui/window.h index e04fcfc3..518e1ec2 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -266,7 +266,7 @@ class Window : public gcn::Window, gcn::WidgetListener * Reset the win pos and size to default. Don't forget to set defaults * first. */ - void resetToDefaultSize(); + virtual void resetToDefaultSize(); /** * Gets the layout handler for this window. -- cgit v1.2.3-70-g09d2 From 61f4e3b9838ac7a0e06cd066ea07224670f1b851 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Thu, 19 Mar 2009 16:27:51 -0600 Subject: Make sure positionable dialogs start out centered --- src/gui/buy.cpp | 1 + src/gui/buysell.cpp | 6 ++++-- src/gui/char_select.cpp | 4 ++-- src/gui/char_server.cpp | 2 +- src/gui/confirm_dialog.cpp | 2 +- src/gui/connection.cpp | 2 +- src/gui/help.cpp | 2 +- src/gui/itempopup.cpp | 2 +- src/gui/login.cpp | 2 +- src/gui/npc_text.cpp | 1 + src/gui/npcintegerdialog.cpp | 4 ++++ src/gui/npclistdialog.cpp | 1 + src/gui/npcstringdialog.cpp | 4 ++++ src/gui/ok_dialog.cpp | 2 +- src/gui/register.cpp | 2 +- src/gui/sell.cpp | 1 + src/gui/setup.cpp | 2 +- src/gui/skill.cpp | 2 +- src/gui/speechbubble.cpp | 2 +- src/gui/storagewindow.cpp | 1 + src/gui/updatewindow.cpp | 2 +- src/gui/window.cpp | 20 ++++++++++++++++---- src/gui/window.h | 10 ++++++++++ 23 files changed, 57 insertions(+), 20 deletions(-) (limited to 'src/gui/setup.cpp') diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index 3107c529..7e03c591 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -90,6 +90,7 @@ BuyDialog::BuyDialog(Network *network): Layout &layout = getLayout(); layout.setRowHeight(0, Layout::AUTO_SET); + center(); loadWindowState(); } diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp index 75c49b1f..e6dc7c1f 100644 --- a/src/gui/buysell.cpp +++ b/src/gui/buysell.cpp @@ -49,9 +49,11 @@ BuySellDialog::BuySellDialog(Network *network): } buyButton->requestFocus(); - loadWindowState(); - setContentSize(x, 2 * y + buyButton->getHeight()); + + center(); + setDefaultSize(); + loadWindowState(); } void BuySellDialog::logic() diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index 6d5e082a..709988a3 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -127,7 +127,7 @@ CharSelectDialog::CharSelectDialog(Network *network, reflowLayout(250, 0); - setLocationRelativeTo(getParent()); + center(); setVisible(true); mSelectButton->requestFocus(); updatePlayerInfo(); @@ -306,7 +306,7 @@ CharCreateDialog::CharCreateDialog(Window *parent, int slot, Network *network, reflowLayout(225, 0); - setLocationRelativeTo(getParent()); + center(); setVisible(true); mNameField->requestFocus(); } diff --git a/src/gui/char_server.cpp b/src/gui/char_server.cpp index 89bfa93a..22b0e7aa 100644 --- a/src/gui/char_server.cpp +++ b/src/gui/char_server.cpp @@ -85,7 +85,7 @@ ServerSelectDialog::ServerSelectDialog(LoginData *loginData, int nextState): // Select first server mServerList->setSelected(1); - setLocationRelativeTo(getParent()); + center(); setVisible(true); mOkButton->requestFocus(); } diff --git a/src/gui/confirm_dialog.cpp b/src/gui/confirm_dialog.cpp index 0d41525a..a40593e3 100644 --- a/src/gui/confirm_dialog.cpp +++ b/src/gui/confirm_dialog.cpp @@ -85,7 +85,7 @@ ConfirmDialog::ConfirmDialog(const std::string &title, const std::string &msg, if (getParent()) { - setLocationRelativeTo(getParent()); + center(); getParent()->moveToTop(this); } setVisible(true); diff --git a/src/gui/connection.cpp b/src/gui/connection.cpp index a69698e9..981100f9 100644 --- a/src/gui/connection.cpp +++ b/src/gui/connection.cpp @@ -56,7 +56,7 @@ ConnectionDialog::ConnectionDialog(): add(cancelButton); add(mProgressBar); - setLocationRelativeTo(getParent()); + center(); setVisible(true); } diff --git a/src/gui/help.cpp b/src/gui/help.cpp index 30c6a9c4..78b3c93a 100644 --- a/src/gui/help.cpp +++ b/src/gui/help.cpp @@ -58,7 +58,7 @@ HelpWindow::HelpWindow(): Layout &layout = getLayout(); layout.setRowHeight(0, Layout::AUTO_SET); - setLocationRelativeTo(getParent()); + center(); } void HelpWindow::action(const gcn::ActionEvent &event) diff --git a/src/gui/itempopup.cpp b/src/gui/itempopup.cpp index 0e0dd9e6..efbee6b0 100644 --- a/src/gui/itempopup.cpp +++ b/src/gui/itempopup.cpp @@ -89,7 +89,7 @@ ItemPopup::ItemPopup(): add(mItemEffectScroll); add(mItemWeightScroll); - setLocationRelativeTo(getParent()); + center(); } ItemPopup::~ItemPopup() diff --git a/src/gui/login.cpp b/src/gui/login.cpp index e91f7616..414de40e 100644 --- a/src/gui/login.cpp +++ b/src/gui/login.cpp @@ -110,7 +110,7 @@ LoginDialog::LoginDialog(LoginData *loginData): place(3, 6, mOkButton); reflowLayout(250, 0); - setLocationRelativeTo(getParent()); + center(); setVisible(true); if (mUserField->getText().empty()) { diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp index 53c64a54..5bc654b8 100644 --- a/src/gui/npc_text.cpp +++ b/src/gui/npc_text.cpp @@ -61,6 +61,7 @@ NpcTextDialog::NpcTextDialog(Network *network): Layout &layout = getLayout(); layout.setRowHeight(0, Layout::AUTO_SET); + center(); loadWindowState(); } diff --git a/src/gui/npcintegerdialog.cpp b/src/gui/npcintegerdialog.cpp index c1460f8d..643a7ef8 100644 --- a/src/gui/npcintegerdialog.cpp +++ b/src/gui/npcintegerdialog.cpp @@ -61,6 +61,10 @@ NpcIntegerDialog::NpcIntegerDialog(Network *network): place(2, 0, cancelButton); place(3, 0, okButton); reflowLayout(175, 0); + + center(); + setDefaultSize(); + loadWindowState(); } void NpcIntegerDialog::setRange(int min, int max) diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp index 3960cb21..d280a982 100644 --- a/src/gui/npclistdialog.cpp +++ b/src/gui/npclistdialog.cpp @@ -66,6 +66,7 @@ NpcListDialog::NpcListDialog(Network *network): Layout &layout = getLayout(); layout.setRowHeight(0, Layout::AUTO_SET); + center(); loadWindowState(); } diff --git a/src/gui/npcstringdialog.cpp b/src/gui/npcstringdialog.cpp index 4d170208..7ae2d5ed 100644 --- a/src/gui/npcstringdialog.cpp +++ b/src/gui/npcstringdialog.cpp @@ -47,6 +47,10 @@ NpcStringDialog::NpcStringDialog(Network *network): place(1, 1, cancelButton); place(2, 1, okButton); reflowLayout(175, 0); + + center(); + setDefaultSize(); + loadWindowState(); } std::string NpcStringDialog::getValue() diff --git a/src/gui/ok_dialog.cpp b/src/gui/ok_dialog.cpp index 4f4f1117..f1a97b49 100644 --- a/src/gui/ok_dialog.cpp +++ b/src/gui/ok_dialog.cpp @@ -74,7 +74,7 @@ OkDialog::OkDialog(const std::string &title, const std::string &msg, add(mTextArea); add(okButton); - setLocationRelativeTo(getParent()); + center(); setVisible(true); okButton->requestFocus(); } diff --git a/src/gui/register.cpp b/src/gui/register.cpp index c2190501..25c97713 100644 --- a/src/gui/register.cpp +++ b/src/gui/register.cpp @@ -130,7 +130,7 @@ RegisterDialog::RegisterDialog(LoginData *loginData): mServerField->addActionListener(this); mPortField->addActionListener(this); - setLocationRelativeTo(getParent()); + center(); setVisible(true); mUserField->requestFocus(); mUserField->setCaretPosition(mUserField->getText().length()); diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index 4cdabe68..e1b15bac 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -93,6 +93,7 @@ SellDialog::SellDialog(Network *network): Layout &layout = getLayout(); layout.setRowHeight(0, Layout::AUTO_SET); + center(); loadWindowState(); } diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index 68bc3a4b..872596b0 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -101,7 +101,7 @@ Setup::Setup(): add(panel); - setLocationRelativeTo(getParent()); + center(); setInGame(false); } diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp index 6112f0e3..ed374a31 100644 --- a/src/gui/skill.cpp +++ b/src/gui/skill.cpp @@ -157,7 +157,7 @@ SkillDialog::SkillDialog(): Layout &layout = getLayout(); layout.setRowHeight(0, Layout::AUTO_SET); - setLocationRelativeTo(getParent()); + center(); loadWindowState(); } diff --git a/src/gui/speechbubble.cpp b/src/gui/speechbubble.cpp index 5f05971d..fb0d7684 100644 --- a/src/gui/speechbubble.cpp +++ b/src/gui/speechbubble.cpp @@ -58,7 +58,7 @@ SpeechBubble::SpeechBubble(): add(mCaption); add(mSpeechArea); - setLocationRelativeTo(getParent()); + center(); } void SpeechBubble::setCaption(const std::string &name, const gcn::Color *color) diff --git a/src/gui/storagewindow.cpp b/src/gui/storagewindow.cpp index 5981f121..663ad784 100644 --- a/src/gui/storagewindow.cpp +++ b/src/gui/storagewindow.cpp @@ -92,6 +92,7 @@ StorageWindow::StorageWindow(Network *network, int invSize): Layout &layout = getLayout(); layout.setRowHeight(0, mStoreButton->getHeight()); + center(); loadWindowState(); } diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp index 6ec62337..df0a1f80 100644 --- a/src/gui/updatewindow.cpp +++ b/src/gui/updatewindow.cpp @@ -131,7 +131,7 @@ UpdaterWindow::UpdaterWindow(const std::string &updateHost, Layout &layout = getLayout(); layout.setRowHeight(0, Layout::AUTO_SET); - setLocationRelativeTo(getParent()); + center(); setVisible(true); mCancelButton->requestFocus(); diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 4bc0e4d0..d4665427 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -67,10 +67,9 @@ Window::Window(const std::string& caption, bool modal, Window *parent, const std mModal(modal), mCloseButton(false), mSticky(false), - mMinWinWidth(100), - mMinWinHeight(40), - mMaxWinWidth(INT_MAX), - mMaxWinHeight(INT_MAX), + mMinWinWidth(100), mDefaultWidth(100), mMaxWinWidth(INT_MAX), + mMinWinHeight(40), mDefaultHeight(40), mMaxWinHeight(INT_MAX), + mDefaultX(100), mDefaultY(100), mSkin(skin) { logger->log("Window::Window(\"%s\")", caption.c_str()); @@ -492,6 +491,14 @@ void Window::setDefaultSize(int defaultX, int defaultY, mDefaultHeight = defaultHeight; } +void Window::setDefaultSize() +{ + mDefaultX = getX(); + mDefaultY = getY(); + mDefaultWidth = getWidth(); + mDefaultHeight = getHeight(); +} + void Window::resetToDefaultSize(bool changePosition) { if (changePosition) setPosition(mDefaultX, mDefaultY); @@ -733,3 +740,8 @@ void Window::reflowLayout(int w, int h) mLayout = NULL; setContentSize(w, h); } + +void Window::center() +{ + setLocationRelativeTo(getParent()); +} diff --git a/src/gui/window.h b/src/gui/window.h index 9977aff4..95fe2174 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -239,6 +239,11 @@ class Window : public gcn::Window, gcn::WidgetListener void setDefaultSize(int defaultX, int defaultY, int defaultWidth, int defaultHeight); + /** + * Set the default win pos and size tot he current ones. + */ + void setDefaultSize(); + /** * Reset the win pos and size to default. Don't forget to set defaults * first. @@ -275,6 +280,11 @@ class Window : public gcn::Window, gcn::WidgetListener */ ContainerPlacer getPlacer(int x, int y); + /** + * Positions the window in the center of it's parent. + */ + void center(); + protected: /** The window container windows add themselves to. */ static WindowContainer *windowContainer; -- cgit v1.2.3-70-g09d2