From c3f7f72f37adad5103587069ff549798fc9d652d Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Wed, 18 Feb 2009 20:14:23 +0100 Subject: Introduced a toLower method and grouped string utils The string utility methods are now grouped together in the stringutils.h header. Also, a toLower method was added for convenience. --- src/gui/chat.cpp | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) (limited to 'src/gui/chat.cpp') diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 0e8810ac..91e410ce 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -47,8 +47,7 @@ #include "../utils/gettext.h" #include "../utils/strprintf.h" -#include "../utils/tostring.h" -#include "../utils/trim.h" +#include "../utils/stringutils.h" ChatWindow::ChatWindow(Network * network): Window(""), mNetwork(network), mTmpVisible(false) @@ -336,15 +335,8 @@ void ChatWindow::whisper(const std::string &nick, std::string msg) std::string playerName = player_node->getName(); std::string tempNick = recvnick; - for (unsigned int i = 0; i < playerName.size(); i++) - { - playerName[i] = (char) tolower(playerName[i]); - } - - for (unsigned int i = 0; i < tempNick.size(); i++) - { - tempNick[i] = (char) tolower(tempNick[i]); - } + toLower(playerName); + toLower(tempNick); if (tempNick.compare(playerName) == 0 || msg.empty()) return; @@ -405,14 +397,9 @@ void ChatWindow::chatSend(const std::string &nick, std::string msg) start = msg.find('[', start + 1); } - std::string temp = msg.substr(start+1, end - start - 1); - - trim(temp); + std::string temp = msg.substr(start + 1, end - start - 1); - for (unsigned int i = 0; i < temp.size(); i++) - { - temp[i] = (char) tolower(temp[i]); - } + toLower(trim(temp)); const ItemInfo itemInfo = ItemDB::get(temp); if (itemInfo.getName() != _("Unknown item")) -- cgit v1.2.3-70-g09d2 From a65570a60c1d2f58d2f3fe01a4a54cd08a90d932 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Sat, 28 Feb 2009 10:49:55 -0700 Subject: Allow chatting while talking to NPCs --- src/game.cpp | 40 ++++++++++++---------------------------- src/gui/chat.cpp | 7 ++++++- src/gui/chat.h | 5 ++++- 3 files changed, 22 insertions(+), 30 deletions(-) (limited to 'src/gui/chat.cpp') diff --git a/src/game.cpp b/src/game.cpp index 6bff0025..d6445ecc 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -513,58 +513,42 @@ void Game::handleInput() } } - if (keyboard.isKeyActive(keyboard.KEY_TOGGLE_CHAT) || - keyboard.isKeyActive(keyboard.KEY_OK)) - { - // Input chat window - if (!(chatWindow->isInputFocused() || - deathNotice || - weightNotice)) + if (!(chatWindow->isInputFocused() || deathNotice || weightNotice)) + if (keyboard.isKeyActive(keyboard.KEY_OK)) { - // Quit by pressing Enter if the exit confirm is there if (exitConfirm && keyboard.isKeyActive(keyboard.KEY_TOGGLE_CHAT)) done = true; // Close the Browser if opened else if (helpWindow->isVisible() && - keyboard.isKeyActive(keyboard.KEY_OK)) + keyboard.isKeyActive(keyboard.KEY_OK)) helpWindow->setVisible(false); // Close the config window, cancelling changes if opened else if (setupWindow->isVisible() && - keyboard.isKeyActive(keyboard.KEY_OK)) + keyboard.isKeyActive(keyboard.KEY_OK)) setupWindow->action(gcn::ActionEvent(NULL, "cancel")); // Submits the text and proceeds to the next dialog else if (npcStringDialog->isVisible() && - keyboard.isKeyActive(keyboard.KEY_OK)) + keyboard.isKeyActive(keyboard.KEY_OK)) npcStringDialog->action(gcn::ActionEvent(NULL, "ok")); // Proceed to the next dialog option, or close the window else if (npcTextDialog->isVisible() && - keyboard.isKeyActive(keyboard.KEY_OK)) + keyboard.isKeyActive(keyboard.KEY_OK)) npcTextDialog->action(gcn::ActionEvent(NULL, "ok")); // Choose the currently highlighted dialogue option else if (npcListDialog->isVisible() && - keyboard.isKeyActive(keyboard.KEY_OK)) + keyboard.isKeyActive(keyboard.KEY_OK)) npcListDialog->action(gcn::ActionEvent(NULL, "ok")); // Submits the text and proceeds to the next dialog else if (npcIntegerDialog->isVisible() && - keyboard.isKeyActive(keyboard.KEY_OK)) + keyboard.isKeyActive(keyboard.KEY_OK)) npcIntegerDialog->action(gcn::ActionEvent(NULL, "ok")); - else if (!(keyboard.getKeyValue( - KeyboardConfig::KEY_TOGGLE_CHAT) == - keyboard.getKeyValue( - KeyboardConfig::KEY_OK) && - (helpWindow->isVisible() || - setupWindow->isVisible() || - npcStringDialog->isVisible() || - npcTextDialog->isVisible() || - npcListDialog->isVisible() || - npcIntegerDialog->isVisible()))) - { - chatWindow->requestChatFocus(); + } + if (keyboard.isKeyActive(keyboard.KEY_TOGGLE_CHAT)) + { + if (chatWindow->requestChatFocus()) used = true; - } } - } const int tKey = keyboard.getKeyIndex(event.key.keysym.sym); switch (tKey) diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index ac13355c..20d0213b 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -284,7 +284,7 @@ void ChatWindow::action(const gcn::ActionEvent &event) } } -void ChatWindow::requestChatFocus() +bool ChatWindow::requestChatFocus() { // Make sure chatWindow is visible if (!isVisible()) @@ -299,9 +299,14 @@ void ChatWindow::requestChatFocus() mTmpVisible = true; } + // Don't do anything else if the input is already visible and has focus + if (mChatInput->isVisible() && mChatInput->isFocused()) + return false; + // Give focus to the chat input mChatInput->setVisible(true); mChatInput->requestFocus(); + return true; } bool ChatWindow::isInputFocused() diff --git a/src/gui/chat.h b/src/gui/chat.h index 2fadb014..6002fed3 100644 --- a/src/gui/chat.h +++ b/src/gui/chat.h @@ -138,8 +138,11 @@ class ChatWindow : public Window, public gcn::ActionListener, /** * Request focus for typing chat message. + * + * \returns true if the input was shown + * false otherwise */ - void requestChatFocus(); + bool requestChatFocus(); /** * Checks whether ChatWindow is Focused or not. -- cgit v1.2.3-70-g09d2 From 881f3c693e2ac4d17f2e7109a809d1bd4c2f62c6 Mon Sep 17 00:00:00 2001 From: Kess Vargavind Date: Mon, 16 Feb 2009 17:22:38 +0100 Subject: Expand the scope where item links work This patch makes item links work in any chatLog() message, not only chatSend() as before. I enabled it for the "You picked " message by explicitly adding [] around the item name in the string. --- src/gui/chat.cpp | 62 ++++++++++++++++++++++---------------------- src/net/inventoryhandler.cpp | 2 +- 2 files changed, 32 insertions(+), 32 deletions(-) (limited to 'src/gui/chat.cpp') diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 20d0213b..26eaf488 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -223,6 +223,37 @@ void ChatWindow::chatLog(std::string line, int own, bool ignoreRecord) << (int) ((t / 60) % 60) << "] "; + // Check for item link + std::string::size_type start = msg.find('['); + while (start != std::string::npos && msg[start+1] != '@') + { + std::string::size_type end = msg.find(']', start); + if (start+1 != end && end != std::string::npos) + { + // Catch multiple embeds and ignore them + // so it doesn't crash the client. + while ((msg.find('[', start + 1) != std::string::npos) && + (msg.find('[', start + 1) < end)) + { + start = msg.find('[', start + 1); + } + + std::string temp = msg.substr(start + 1, end - start - 1); + + toLower(trim(temp)); + + const ItemInfo itemInfo = ItemDB::get(temp); + if (itemInfo.getName() != _("Unknown item")) + { + msg.insert(end, "@@"); + msg.insert(start+1, "|"); + msg.insert(start+1, toString(itemInfo.getId())); + msg.insert(start+1, "@@"); + } + } + start = msg.find('[', start + 1); + } + line = lineColor + timeStr.str() + tmp.nick + tmp.text; // We look if the Vertical Scroll Bar is set at the max before @@ -389,37 +420,6 @@ void ChatWindow::chatSend(const std::string &nick, std::string msg) return; } - // Check for item link - std::string::size_type start = msg.find('['); - while (start != std::string::npos && msg[start+1] != '@') - { - std::string::size_type end = msg.find(']', start); - if (start+1 != end && end != std::string::npos) - { - // Catch multiple embeds and ignore them - // so it doesn't crash the client. - while ((msg.find('[', start + 1) != std::string::npos) && - (msg.find('[', start + 1) < end)) - { - start = msg.find('[', start + 1); - } - - std::string temp = msg.substr(start + 1, end - start - 1); - - toLower(trim(temp)); - - const ItemInfo itemInfo = ItemDB::get(temp); - if (itemInfo.getName() != _("Unknown item")) - { - msg.insert(end, "@@"); - msg.insert(start+1, "|"); - msg.insert(start+1, toString(itemInfo.getId())); - msg.insert(start+1, "@@"); - } - } - start = msg.find('[', start + 1); - } - // Prepare ordinary message if (msg.substr(0, 1) != "/") { diff --git a/src/net/inventoryhandler.cpp b/src/net/inventoryhandler.cpp index 243d1e79..7d33b419 100644 --- a/src/net/inventoryhandler.cpp +++ b/src/net/inventoryhandler.cpp @@ -163,7 +163,7 @@ void InventoryHandler::handleMessage(MessageIn *msg) const std::string amountStr = (amount > 1) ? toString(amount) : "a"; if (config.getValue("showpickupchat", true)) { - chatWindow->chatLog(strprintf(_("You picked up %s %s"), + chatWindow->chatLog(strprintf(_("You picked up %s [%s]"), amountStr.c_str(), itemInfo.getName().c_str()), BY_SERVER); } -- cgit v1.2.3-70-g09d2 From 9e7dfd7397ed2c282015f4cc13c42598b6bb1f39 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 10 Mar 2009 05:15:20 -0600 Subject: Remove some tabs and trailing whitespace --- src/gui/chat.cpp | 16 ++++++++-------- src/gui/confirm_dialog.cpp | 4 ++-- src/gui/debugwindow.cpp | 2 +- src/gui/listbox.cpp | 2 +- src/gui/ok_dialog.cpp | 6 +++--- src/gui/setup_players.cpp | 4 ++-- src/gui/shop.h | 2 +- src/gui/widgets/dropdown.cpp | 6 +++--- src/map.cpp | 2 +- src/shopitem.h | 2 +- 10 files changed, 23 insertions(+), 23 deletions(-) (limited to 'src/gui/chat.cpp') diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 26eaf488..702327a5 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -140,12 +140,12 @@ void ChatWindow::chatLog(std::string line, int own, bool ignoreRecord) // *implements actions in a backwards compatible way* if (own == BY_PLAYER && - tmp.text.at(0) == '*' && - tmp.text.at(tmp.text.length()-1) == '*') + tmp.text.at(0) == '*' && + tmp.text.at(tmp.text.length()-1) == '*') { - tmp.text[0] = ' '; - tmp.text.erase(tmp.text.length() - 1); - own = ACT_IS; + tmp.text[0] = ' '; + tmp.text.erase(tmp.text.length() - 1); + own = ACT_IS; } std::string lineColor = "##C"; @@ -622,9 +622,9 @@ void ChatWindow::chatSend(const std::string &nick, std::string msg) } else if (command == "me") { - std::stringstream actionStr; - actionStr << "*" << msg << "*"; - chatSend(player_node->getName(), actionStr.str()); + std::stringstream actionStr; + actionStr << "*" << msg << "*"; + chatSend(player_node->getName(), actionStr.str()); } else { diff --git a/src/gui/confirm_dialog.cpp b/src/gui/confirm_dialog.cpp index fbbc6101..0d41525a 100644 --- a/src/gui/confirm_dialog.cpp +++ b/src/gui/confirm_dialog.cpp @@ -56,7 +56,7 @@ ConfirmDialog::ConfirmDialog(const std::string &title, const std::string &msg, { // fontHeight == height of each line of text (based on font heights) // 14 == row top + bottom graphic pixel heights - setContentSize(mTextBox->getMinWidth() + fontHeight, ((numRows + 1) * + setContentSize(mTextBox->getMinWidth() + fontHeight, ((numRows + 1) * fontHeight) + noButton->getHeight()); mTextArea->setDimension(gcn::Rectangle(4, 5, mTextBox->getMinWidth() + 5, 3 + (numRows * fontHeight))); @@ -67,7 +67,7 @@ ConfirmDialog::ConfirmDialog(const std::string &title, const std::string &msg, width = getFont()->getWidth(msg); if (width < inWidth) width = inWidth; - setContentSize(width + fontHeight, (2 * fontHeight) + + setContentSize(width + fontHeight, (2 * fontHeight) + noButton->getHeight()); mTextArea->setDimension(gcn::Rectangle(4, 5, width + 5, 17)); } diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp index 33304944..cf2f9613 100644 --- a/src/gui/debugwindow.cpp +++ b/src/gui/debugwindow.cpp @@ -70,7 +70,7 @@ void DebugWindow::logic() mFPSLabel->setCaption(toString(fps) + " FPS"); - mTileMouseLabel->setCaption("Tile: (" + toString(mouseTileX) + ", " + + mTileMouseLabel->setCaption("Tile: (" + toString(mouseTileX) + ", " + toString(mouseTileY) + ")"); Map *currentMap = engine->getCurrentMap(); diff --git a/src/gui/listbox.cpp b/src/gui/listbox.cpp index 2f7d2f7f..cd5aa736 100644 --- a/src/gui/listbox.cpp +++ b/src/gui/listbox.cpp @@ -111,7 +111,7 @@ void ListBox::keyPressed(gcn::KeyEvent& keyEvent) } else if (key.getValue() == gcn::Key::UP) { - setSelected(mSelected - 1); + setSelected(mSelected - 1); keyEvent.consume(); } else if (key.getValue() == gcn::Key::DOWN) diff --git a/src/gui/ok_dialog.cpp b/src/gui/ok_dialog.cpp index d73c7d7c..4f4f1117 100644 --- a/src/gui/ok_dialog.cpp +++ b/src/gui/ok_dialog.cpp @@ -52,10 +52,10 @@ OkDialog::OkDialog(const std::string &title, const std::string &msg, if (numRows > 1) { // 14 == row top + bottom graphic pixel heights - setContentSize(mTextBox->getMinWidth() + fontHeight, ((numRows + 1) * + setContentSize(mTextBox->getMinWidth() + fontHeight, ((numRows + 1) * fontHeight) + okButton->getHeight()); - mTextArea->setDimension(gcn::Rectangle(4, 5, mTextBox->getMinWidth() + 5, - 3 + (numRows * fontHeight))); + mTextArea->setDimension(gcn::Rectangle(4, 5, + mTextBox->getMinWidth() + 5, 3 + (numRows * fontHeight))); } else { diff --git a/src/gui/setup_players.cpp b/src/gui/setup_players.cpp index 96792436..84dbed55 100644 --- a/src/gui/setup_players.cpp +++ b/src/gui/setup_players.cpp @@ -329,7 +329,7 @@ void Setup_Players::apply() ~(PlayerRelation::TRADE | PlayerRelation::WHISPER); player_relations.setDefault(old_default_relations - | (mDefaultTrading->isSelected() ? + | (mDefaultTrading->isSelected() ? PlayerRelation::TRADE : 0) | (mDefaultWhisper->isSelected() ? PlayerRelation::WHISPER : 0)); @@ -341,7 +341,7 @@ void Setup_Players::cancel() void Setup_Players::action(const gcn::ActionEvent &event) { - if (event.getId() == ACTION_TABLE) + if (event.getId() == ACTION_TABLE) { // temporarily eliminate ourselves: we are fully aware of this change, // so there is no need for asynchronous updates. (In fact, thouse diff --git a/src/gui/shop.h b/src/gui/shop.h index faffe7e3..0c900d9d 100644 --- a/src/gui/shop.h +++ b/src/gui/shop.h @@ -37,7 +37,7 @@ class ShopItem; * The addItem routine can automatically check, if an item already exists and * only adds duplicates to the old item, if one is found. The original * distribution of the duplicates can be retrieved from the item. - * + * * This functionality can be enabled in the constructor. */ class ShopItems : public gcn::ListModel diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp index eef9ae33..e1a24cb7 100644 --- a/src/gui/widgets/dropdown.cpp +++ b/src/gui/widgets/dropdown.cpp @@ -78,10 +78,10 @@ DropDown::DropDown(gcn::ListModel *listModel, gcn::ScrollArea *scrollArea, { for (x = 0; x < 3; x++) { - skin.grid[a] = boxBorder->getSubImage(gridx[x], gridy[y], - gridx[x + 1] - + skin.grid[a] = boxBorder->getSubImage(gridx[x], gridy[y], + gridx[x + 1] - gridx[x] + 1, - gridy[y + 1] - + gridy[y + 1] - gridy[y] + 1); skin.grid[a]->setAlpha(mAlpha); a++; diff --git a/src/map.cpp b/src/map.cpp index 814b4225..39e6d0a5 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -85,7 +85,7 @@ void TileAnimation::update() Image *img = mAnimation->getCurrentImage(); if (img != mLastImage) { - for (std::list >::iterator i = + for (std::list >::iterator i = mAffected.begin(); i != mAffected.end(); i++) { i->first->setTile(i->second, img); diff --git a/src/shopitem.h b/src/shopitem.h index 3b00a3c8..cbe0a06f 100644 --- a/src/shopitem.h +++ b/src/shopitem.h @@ -95,7 +95,7 @@ class ShopItem : public Item * Reduces the quantity of the topmost duplicate by the specified * amount. Also reduces the total quantity of this DuplicateItem. * Empty duplicates are automatically removed. - * + * * If the amount is bigger than the quantity of the current topmost, * only sell as much as possible. Returns the amount actually sold (do * not ignore the return value!) -- cgit v1.2.3-70-g09d2 From a872eb3364eec4a9778692a1e529aa506c9e09ca Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 10 Mar 2009 05:25:49 -0600 Subject: Fix typo in item link parsing --- src/gui/chat.cpp | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'src/gui/chat.cpp') diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 702327a5..8ecb5f63 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -224,34 +224,39 @@ void ChatWindow::chatLog(std::string line, int own, bool ignoreRecord) << "] "; // Check for item link - std::string::size_type start = msg.find('['); - while (start != std::string::npos && msg[start+1] != '@') + std::string::size_type start = tmp.text.find('['); + while (start != std::string::npos && tmp.text[start+1] != '@') { - std::string::size_type end = msg.find(']', start); + std::string::size_type end = tmp.text.find(']', start); if (start+1 != end && end != std::string::npos) { // Catch multiple embeds and ignore them // so it doesn't crash the client. - while ((msg.find('[', start + 1) != std::string::npos) && - (msg.find('[', start + 1) < end)) + while ((tmp.text.find('[', start + 1) != std::string::npos) && + (tmp.text.find('[', start + 1) < end)) { - start = msg.find('[', start + 1); + start = tmp.text.find('[', start + 1); } - std::string temp = msg.substr(start + 1, end - start - 1); + std::string temp = tmp.text.substr(start+1, end - start - 1); - toLower(trim(temp)); + trim(temp); + + for (unsigned int i = 0; i < temp.size(); i++) + { + temp[i] = (char) tolower(temp[i]); + } const ItemInfo itemInfo = ItemDB::get(temp); if (itemInfo.getName() != _("Unknown item")) { - msg.insert(end, "@@"); - msg.insert(start+1, "|"); - msg.insert(start+1, toString(itemInfo.getId())); - msg.insert(start+1, "@@"); + tmp.text.insert(end, "@@"); + tmp.text.insert(start+1, "|"); + tmp.text.insert(start+1, toString(itemInfo.getId())); + tmp.text.insert(start+1, "@@"); } } - start = msg.find('[', start + 1); + start = tmp.text.find('[', start + 1); } line = lineColor + timeStr.str() + tmp.nick + tmp.text; -- cgit v1.2.3-70-g09d2 From 2d6e867ba8306bc662b9cf42dd403f2ebcb140a6 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 10 Mar 2009 05:15:20 -0600 Subject: Remove some tabs and trailing whitespace --- src/gui/chat.cpp | 16 ++++++++-------- src/gui/confirm_dialog.cpp | 4 ++-- src/gui/debugwindow.cpp | 2 +- src/gui/listbox.cpp | 2 +- src/gui/ok_dialog.cpp | 6 +++--- src/gui/setup_players.cpp | 4 ++-- src/gui/shop.h | 2 +- src/gui/widgets/dropdown.cpp | 6 +++--- src/map.cpp | 2 +- src/shopitem.h | 2 +- 10 files changed, 23 insertions(+), 23 deletions(-) (limited to 'src/gui/chat.cpp') diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 91e410ce..47fadc8d 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -141,12 +141,12 @@ void ChatWindow::chatLog(std::string line, int own, bool ignoreRecord) // *implements actions in a backwards compatible way* if (own == BY_PLAYER && - tmp.text.at(0) == '*' && - tmp.text.at(tmp.text.length()-1) == '*') + tmp.text.at(0) == '*' && + tmp.text.at(tmp.text.length()-1) == '*') { - tmp.text[0] = ' '; - tmp.text.erase(tmp.text.length() - 1); - own = ACT_IS; + tmp.text[0] = ' '; + tmp.text.erase(tmp.text.length() - 1); + own = ACT_IS; } std::string lineColor = "##C"; @@ -615,9 +615,9 @@ void ChatWindow::chatSend(const std::string &nick, std::string msg) } else if (command == "me") { - std::stringstream actionStr; - actionStr << "*" << msg << "*"; - chatSend(player_node->getName(), actionStr.str()); + std::stringstream actionStr; + actionStr << "*" << msg << "*"; + chatSend(player_node->getName(), actionStr.str()); } else { diff --git a/src/gui/confirm_dialog.cpp b/src/gui/confirm_dialog.cpp index 2bc330c0..f4b49251 100644 --- a/src/gui/confirm_dialog.cpp +++ b/src/gui/confirm_dialog.cpp @@ -57,7 +57,7 @@ ConfirmDialog::ConfirmDialog(const std::string &title, const std::string &msg, { // fontHeight == height of each line of text (based on font heights) // 14 == row top + bottom graphic pixel heights - setContentSize(mTextBox->getMinWidth() + fontHeight, ((numRows + 1) * + setContentSize(mTextBox->getMinWidth() + fontHeight, ((numRows + 1) * fontHeight) + noButton->getHeight()); mTextArea->setDimension(gcn::Rectangle(4, 5, mTextBox->getMinWidth() + 5, 3 + (numRows * fontHeight))); @@ -68,7 +68,7 @@ ConfirmDialog::ConfirmDialog(const std::string &title, const std::string &msg, width = getFont()->getWidth(msg); if (width < inWidth) width = inWidth; - setContentSize(width + fontHeight, (2 * fontHeight) + + setContentSize(width + fontHeight, (2 * fontHeight) + noButton->getHeight()); mTextArea->setDimension(gcn::Rectangle(4, 5, width + 5, 17)); } diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp index 1a805dd4..dafd604a 100644 --- a/src/gui/debugwindow.cpp +++ b/src/gui/debugwindow.cpp @@ -71,7 +71,7 @@ void DebugWindow::logic() mFPSLabel->setCaption(toString(fps) + " FPS"); - mTileMouseLabel->setCaption("Tile: (" + toString(mouseTileX) + ", " + + mTileMouseLabel->setCaption("Tile: (" + toString(mouseTileX) + ", " + toString(mouseTileY) + ")"); Map *currentMap = engine->getCurrentMap(); diff --git a/src/gui/listbox.cpp b/src/gui/listbox.cpp index 6d5c0ca8..82011239 100644 --- a/src/gui/listbox.cpp +++ b/src/gui/listbox.cpp @@ -112,7 +112,7 @@ void ListBox::keyPressed(gcn::KeyEvent& keyEvent) } else if (key.getValue() == gcn::Key::UP) { - setSelected(mSelected - 1); + setSelected(mSelected - 1); keyEvent.consume(); } else if (key.getValue() == gcn::Key::DOWN) diff --git a/src/gui/ok_dialog.cpp b/src/gui/ok_dialog.cpp index 9621b389..d3e7bec6 100644 --- a/src/gui/ok_dialog.cpp +++ b/src/gui/ok_dialog.cpp @@ -53,10 +53,10 @@ OkDialog::OkDialog(const std::string &title, const std::string &msg, if (numRows > 1) { // 14 == row top + bottom graphic pixel heights - setContentSize(mTextBox->getMinWidth() + fontHeight, ((numRows + 1) * + setContentSize(mTextBox->getMinWidth() + fontHeight, ((numRows + 1) * fontHeight) + okButton->getHeight()); - mTextArea->setDimension(gcn::Rectangle(4, 5, mTextBox->getMinWidth() + 5, - 3 + (numRows * fontHeight))); + mTextArea->setDimension(gcn::Rectangle(4, 5, + mTextBox->getMinWidth() + 5, 3 + (numRows * fontHeight))); } else { diff --git a/src/gui/setup_players.cpp b/src/gui/setup_players.cpp index 9105d44a..faf80640 100644 --- a/src/gui/setup_players.cpp +++ b/src/gui/setup_players.cpp @@ -330,7 +330,7 @@ void Setup_Players::apply() ~(PlayerRelation::TRADE | PlayerRelation::WHISPER); player_relations.setDefault(old_default_relations - | (mDefaultTrading->isSelected() ? + | (mDefaultTrading->isSelected() ? PlayerRelation::TRADE : 0) | (mDefaultWhisper->isSelected() ? PlayerRelation::WHISPER : 0)); @@ -342,7 +342,7 @@ void Setup_Players::cancel() void Setup_Players::action(const gcn::ActionEvent &event) { - if (event.getId() == ACTION_TABLE) + if (event.getId() == ACTION_TABLE) { // temporarily eliminate ourselves: we are fully aware of this change, // so there is no need for asynchronous updates. (In fact, thouse diff --git a/src/gui/shop.h b/src/gui/shop.h index 26a9429d..118847f9 100644 --- a/src/gui/shop.h +++ b/src/gui/shop.h @@ -38,7 +38,7 @@ class ShopItem; * The addItem routine can automatically check, if an item already exists and * only adds duplicates to the old item, if one is found. The original * distribution of the duplicates can be retrieved from the item. - * + * * This functionality can be enabled in the constructor. */ class ShopItems : public gcn::ListModel diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp index 9fcf173c..035ce5d7 100644 --- a/src/gui/widgets/dropdown.cpp +++ b/src/gui/widgets/dropdown.cpp @@ -79,10 +79,10 @@ DropDown::DropDown(gcn::ListModel *listModel, gcn::ScrollArea *scrollArea, { for (x = 0; x < 3; x++) { - skin.grid[a] = boxBorder->getSubImage(gridx[x], gridy[y], - gridx[x + 1] - + skin.grid[a] = boxBorder->getSubImage(gridx[x], gridy[y], + gridx[x + 1] - gridx[x] + 1, - gridy[y + 1] - + gridy[y + 1] - gridy[y] + 1); skin.grid[a]->setAlpha(mAlpha); a++; diff --git a/src/map.cpp b/src/map.cpp index b780b5cc..bda618e2 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -86,7 +86,7 @@ void TileAnimation::update() Image *img = mAnimation->getCurrentImage(); if (img != mLastImage) { - for (std::list >::iterator i = + for (std::list >::iterator i = mAffected.begin(); i != mAffected.end(); i++) { i->first->setTile(i->second, img); diff --git a/src/shopitem.h b/src/shopitem.h index 18608a94..afc48bf5 100644 --- a/src/shopitem.h +++ b/src/shopitem.h @@ -96,7 +96,7 @@ class ShopItem : public Item * Reduces the quantity of the topmost duplicate by the specified * amount. Also reduces the total quantity of this DuplicateItem. * Empty duplicates are automatically removed. - * + * * If the amount is bigger than the quantity of the current topmost, * only sell as much as possible. Returns the amount actually sold (do * not ignore the return value!) -- cgit v1.2.3-70-g09d2 From ec838fe4abf3d1003c654d3b6902a4f145d0fb5a Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Tue, 10 Mar 2009 07:29:56 -0600 Subject: Fixed an indentation error in the last commit. Signed-off-by: Ira Rice --- src/gui/chat.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/gui/chat.cpp') diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 47fadc8d..9ae1be2c 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -141,12 +141,12 @@ void ChatWindow::chatLog(std::string line, int own, bool ignoreRecord) // *implements actions in a backwards compatible way* if (own == BY_PLAYER && - tmp.text.at(0) == '*' && - tmp.text.at(tmp.text.length()-1) == '*') + tmp.text.at(0) == '*' && + tmp.text.at(tmp.text.length()-1) == '*') { - tmp.text[0] = ' '; - tmp.text.erase(tmp.text.length() - 1); - own = ACT_IS; + tmp.text[0] = ' '; + tmp.text.erase(tmp.text.length() - 1); + own = ACT_IS; } std::string lineColor = "##C"; @@ -615,9 +615,9 @@ void ChatWindow::chatSend(const std::string &nick, std::string msg) } else if (command == "me") { - std::stringstream actionStr; - actionStr << "*" << msg << "*"; - chatSend(player_node->getName(), actionStr.str()); + std::stringstream actionStr; + actionStr << "*" << msg << "*"; + chatSend(player_node->getName(), actionStr.str()); } else { -- cgit v1.2.3-70-g09d2 From 3f322e9eec45751686c59ec89bee46d1da34c885 Mon Sep 17 00:00:00 2001 From: Kess Vargavind Date: Mon, 16 Feb 2009 17:22:38 +0100 Subject: Expand the scope where item links work This patch makes item links work in any chatLog() message, not only chatSend() as before. I enabled it for the "You picked " message by explicitly adding [] around the item name in the string. --- src/gui/chat.cpp | 62 ++++++++++++++++++++++---------------------- src/net/inventoryhandler.cpp | 2 +- 2 files changed, 32 insertions(+), 32 deletions(-) (limited to 'src/gui/chat.cpp') diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 9ae1be2c..fd2b05e4 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -221,6 +221,37 @@ void ChatWindow::chatLog(std::string line, int own, bool ignoreRecord) << (int) ((t / 60) % 60) << "] "; + // Check for item link + std::string::size_type start = msg.find('['); + while (start != std::string::npos && msg[start+1] != '@') + { + std::string::size_type end = msg.find(']', start); + if (start+1 != end && end != std::string::npos) + { + // Catch multiple embeds and ignore them + // so it doesn't crash the client. + while ((msg.find('[', start + 1) != std::string::npos) && + (msg.find('[', start + 1) < end)) + { + start = msg.find('[', start + 1); + } + + std::string temp = msg.substr(start + 1, end - start - 1); + + toLower(trim(temp)); + + const ItemInfo itemInfo = ItemDB::get(temp); + if (itemInfo.getName() != _("Unknown item")) + { + msg.insert(end, "@@"); + msg.insert(start+1, "|"); + msg.insert(start+1, toString(itemInfo.getId())); + msg.insert(start+1, "@@"); + } + } + start = msg.find('[', start + 1); + } + line = lineColor + timeStr.str() + tmp.nick + tmp.text; // We look if the Vertical Scroll Bar is set at the max before @@ -382,37 +413,6 @@ void ChatWindow::chatSend(const std::string &nick, std::string msg) return; } - // Check for item link - std::string::size_type start = msg.find('['); - while (start != std::string::npos && msg[start+1] != '@') - { - std::string::size_type end = msg.find(']', start); - if (start+1 != end && end != std::string::npos) - { - // Catch multiple embeds and ignore them - // so it doesn't crash the client. - while ((msg.find('[', start + 1) != std::string::npos) && - (msg.find('[', start + 1) < end)) - { - start = msg.find('[', start + 1); - } - - std::string temp = msg.substr(start + 1, end - start - 1); - - toLower(trim(temp)); - - const ItemInfo itemInfo = ItemDB::get(temp); - if (itemInfo.getName() != _("Unknown item")) - { - msg.insert(end, "@@"); - msg.insert(start+1, "|"); - msg.insert(start+1, toString(itemInfo.getId())); - msg.insert(start+1, "@@"); - } - } - start = msg.find('[', start + 1); - } - // Prepare ordinary message if (msg.substr(0, 1) != "/") { diff --git a/src/net/inventoryhandler.cpp b/src/net/inventoryhandler.cpp index 553ec8fd..9fcfedf1 100644 --- a/src/net/inventoryhandler.cpp +++ b/src/net/inventoryhandler.cpp @@ -164,7 +164,7 @@ void InventoryHandler::handleMessage(MessageIn *msg) const std::string amountStr = (amount > 1) ? toString(amount) : "a"; if (config.getValue("showpickupchat", true)) { - chatWindow->chatLog(strprintf(_("You picked up %s %s"), + chatWindow->chatLog(strprintf(_("You picked up %s [%s]"), amountStr.c_str(), itemInfo.getName().c_str()), BY_SERVER); } -- cgit v1.2.3-70-g09d2 From 0fb4dc37c61341a237bab30896bd2c457222ed03 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 10 Mar 2009 05:25:49 -0600 Subject: Fix typo in item link parsing --- src/gui/chat.cpp | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'src/gui/chat.cpp') diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index fd2b05e4..5cf8b739 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -222,34 +222,39 @@ void ChatWindow::chatLog(std::string line, int own, bool ignoreRecord) << "] "; // Check for item link - std::string::size_type start = msg.find('['); - while (start != std::string::npos && msg[start+1] != '@') + std::string::size_type start = tmp.text.find('['); + while (start != std::string::npos && tmp.text[start+1] != '@') { - std::string::size_type end = msg.find(']', start); + std::string::size_type end = tmp.text.find(']', start); if (start+1 != end && end != std::string::npos) { // Catch multiple embeds and ignore them // so it doesn't crash the client. - while ((msg.find('[', start + 1) != std::string::npos) && - (msg.find('[', start + 1) < end)) + while ((tmp.text.find('[', start + 1) != std::string::npos) && + (tmp.text.find('[', start + 1) < end)) { - start = msg.find('[', start + 1); + start = tmp.text.find('[', start + 1); } - std::string temp = msg.substr(start + 1, end - start - 1); + std::string temp = tmp.text.substr(start+1, end - start - 1); - toLower(trim(temp)); + trim(temp); + + for (unsigned int i = 0; i < temp.size(); i++) + { + temp[i] = (char) tolower(temp[i]); + } const ItemInfo itemInfo = ItemDB::get(temp); if (itemInfo.getName() != _("Unknown item")) { - msg.insert(end, "@@"); - msg.insert(start+1, "|"); - msg.insert(start+1, toString(itemInfo.getId())); - msg.insert(start+1, "@@"); + tmp.text.insert(end, "@@"); + tmp.text.insert(start+1, "|"); + tmp.text.insert(start+1, toString(itemInfo.getId())); + tmp.text.insert(start+1, "@@"); } } - start = msg.find('[', start + 1); + start = tmp.text.find('[', start + 1); } line = lineColor + timeStr.str() + tmp.nick + tmp.text; -- cgit v1.2.3-70-g09d2 From 58ee835c3763e7bf088fa6c7e31dda1d687589cc Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Tue, 10 Mar 2009 11:50:27 -0600 Subject: Extended window layout to take relative positions, as well as offsets to that position. This makes it so that when resolutions are changed, the default locations stay relative to the window's position, and not the 800x600 screen resolution. Signed-off-by: Ira Rice --- src/graphics.cpp | 30 ++++++-------- src/graphics.h | 13 ++++++ src/gui/buy.cpp | 3 +- src/gui/buysell.cpp | 1 - src/gui/chat.cpp | 2 +- src/gui/debugwindow.cpp | 2 +- src/gui/emotewindow.cpp | 2 +- src/gui/equipmentwindow.cpp | 2 +- src/gui/inventorywindow.cpp | 3 +- src/gui/npc_text.cpp | 3 +- src/gui/npcintegerdialog.cpp | 7 +++- src/gui/npclistdialog.cpp | 3 +- src/gui/npcstringdialog.cpp | 7 +++- src/gui/recorder.cpp | 8 ++-- src/gui/sell.cpp | 3 +- src/gui/shortcutwindow.cpp | 13 ++---- src/gui/skill.cpp | 2 +- src/gui/status.cpp | 3 +- src/gui/storagewindow.cpp | 3 +- src/gui/trade.cpp | 2 +- src/gui/window.cpp | 99 ++++++++++++++++++++++++++++++++++++++++++++ src/gui/window.h | 16 ++++++- src/openglgraphics.cpp | 42 ++++++++++--------- 23 files changed, 194 insertions(+), 75 deletions(-) (limited to 'src/gui/chat.cpp') diff --git a/src/graphics.cpp b/src/graphics.cpp index 3c507f4b..48fd1340 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -50,30 +50,25 @@ bool Graphics::setVideoMode(int w, int h, int bpp, bool fs, bool hwaccel) mFullscreen = fs; mHWAccel = hwaccel; - if (fs) { + if (fs) displayFlags |= SDL_FULLSCREEN; - } - if (hwaccel) { + if (hwaccel) displayFlags |= SDL_HWSURFACE | SDL_DOUBLEBUF; - } else { + else displayFlags |= SDL_SWSURFACE; - } mScreen = SDL_SetVideoMode(w, h, bpp, displayFlags); - if (!mScreen) { + if (!mScreen) return false; - } char videoDriverName[64]; - if (SDL_VideoDriverName(videoDriverName, 64)) { + if (SDL_VideoDriverName(videoDriverName, 64)) logger->log("Using video driver: %s", videoDriverName); - } - else { + else logger->log("Using video driver: unknown"); - } const SDL_VideoInfo *vi = SDL_GetVideoInfo(); @@ -104,9 +99,8 @@ bool Graphics::setVideoMode(int w, int h, int bpp, bool fs, bool hwaccel) bool Graphics::setFullscreen(bool fs) { - if (mFullscreen == fs) { + if (mFullscreen == fs) return true; - } return setVideoMode(mScreen->w, mScreen->h, mScreen->format->BitsPerPixel, fs, mHWAccel); @@ -128,7 +122,7 @@ bool Graphics::drawImage(Image *image, int x, int y) } bool Graphics::drawImage(Image *image, int srcX, int srcY, int dstX, int dstY, - int width, int height, bool) + int width, int height, bool) { // Check that preconditions for blitting are met. if (!mScreen || !image || !image->mImage) return false; @@ -150,7 +144,7 @@ bool Graphics::drawImage(Image *image, int srcX, int srcY, int dstX, int dstY, } void Graphics::drawImage(gcn::Image const *image, int srcX, int srcY, - int dstX, int dstY, int width, int height) + int dstX, int dstY, int width, int height) { ProxyImage const *srcImage = dynamic_cast< ProxyImage const * >(image); @@ -167,8 +161,10 @@ void Graphics::drawImagePattern(Image *image, int x, int y, int w, int h) int px = 0; // X position on pattern plane int py = 0; // Y position on pattern plane - while (py < h) { - while (px < w) { + while (py < h) + { + while (px < w) + { int dw = (px + iw >= w) ? w - px : iw; int dh = (py + ih >= h) ? h - py : ih; drawImage(image, 0, 0, x + px, y + py, dw, dh); diff --git a/src/graphics.h b/src/graphics.h index 3ad3b85c..ec0b5e9c 100644 --- a/src/graphics.h +++ b/src/graphics.h @@ -49,6 +49,19 @@ struct SDL_Surface; */ struct ImageRect { + enum ImagePosition + { + UPPER_LEFT = 0, + UPPER_CENTER = 1, + UPPER_RIGHT = 2, + LEFT = 3, + CENTER = 4, + RIGHT = 5, + LOWER_LEFT = 6, + LOWER_CENTER = 7, + LOWER_RIGHT = 8, + }; + Image *grid[9]; }; diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index 5a57dcc6..2b5aeeb7 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -47,7 +47,7 @@ BuyDialog::BuyDialog(Network *network): setResizable(true); setMinWidth(260); setMinHeight(230); - setDefaultSize(0, 0, 260, 230); + setDefaultSize(260, 230, ImageRect::CENTER); mShopItems = new ShopItems; @@ -90,7 +90,6 @@ BuyDialog::BuyDialog(Network *network): layout.setRowHeight(0, Layout::AUTO_SET); loadWindowState(); - setLocationRelativeTo(getParent()); } BuyDialog::~BuyDialog() diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp index dc7deef6..f7684670 100644 --- a/src/gui/buysell.cpp +++ b/src/gui/buysell.cpp @@ -50,7 +50,6 @@ BuySellDialog::BuySellDialog(Network *network): buyButton->requestFocus(); setContentSize(x, 2 * y + buyButton->getHeight()); - setLocationRelativeTo(getParent()); requestFocus(); } diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 5cf8b739..098d4e46 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -55,7 +55,7 @@ Window(""), mNetwork(network), mTmpVisible(false) setWindowName(_("Chat")); setResizable(true); - setDefaultSize(0, windowContainer->getHeight() - 123, 600, 123); + setDefaultSize(600, 123, ImageRect::LOWER_LEFT); setMinWidth(150); setMinHeight(90); diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp index dafd604a..71855977 100644 --- a/src/gui/debugwindow.cpp +++ b/src/gui/debugwindow.cpp @@ -41,7 +41,7 @@ DebugWindow::DebugWindow(): setResizable(true); setCloseButton(true); - setDefaultSize(0, 0, 400, 60); + setDefaultSize(400, 60, ImageRect::CENTER); mFPSLabel = new gcn::Label("0 FPS"); mMusicFileLabel = new gcn::Label("Music: "); diff --git a/src/gui/emotewindow.cpp b/src/gui/emotewindow.cpp index 30129941..77168993 100644 --- a/src/gui/emotewindow.cpp +++ b/src/gui/emotewindow.cpp @@ -40,7 +40,7 @@ EmoteWindow::EmoteWindow(): setCloseButton(true); setMinWidth(80); setMinHeight(130); - setDefaultSize(115, 25, 322, 200); + setDefaultSize(322, 200, ImageRect::CENTER); mUseButton = new Button(_("Use"), "use", this); diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index 27ea38ff..0d2097f8 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -71,7 +71,7 @@ EquipmentWindow::EquipmentWindow(): setWindowName("Equipment"); setCloseButton(true); - setDefaultSize(5, 195, 180, 300); + setDefaultSize(180, 300, ImageRect::CENTER); loadWindowState(); mUnequip = new Button(_("Unequip"), "unequip", this); diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index 226b3178..7e75411e 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -57,7 +57,7 @@ InventoryWindow::InventoryWindow(int invSize): setCloseButton(true); // If you adjust these defaults, don't forget to adjust the trade window's. - setDefaultSize(115, 25, 375, 300); + setDefaultSize(375, 300, ImageRect::CENTER); std::string longestUseString = getFont()->getWidth(_("Equip")) > getFont()->getWidth(_("Use")) ? @@ -103,7 +103,6 @@ InventoryWindow::InventoryWindow(int invSize): layout.setRowHeight(0, mDropButton->getHeight()); loadWindowState(); - setLocationRelativeTo(getParent()); } InventoryWindow::~InventoryWindow() diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp index 58aa0c5e..f524f8ea 100644 --- a/src/gui/npc_text.cpp +++ b/src/gui/npc_text.cpp @@ -43,7 +43,7 @@ NpcTextDialog::NpcTextDialog(Network *network): setMinWidth(200); setMinHeight(150); - setDefaultSize(0, 0, 260, 200); + setDefaultSize(260, 200, ImageRect::CENTER); mTextBox = new TextBox; mTextBox->setEditable(false); @@ -63,7 +63,6 @@ NpcTextDialog::NpcTextDialog(Network *network): layout.setRowHeight(0, Layout::AUTO_SET); loadWindowState(); - setLocationRelativeTo(getParent()); } void NpcTextDialog::setText(const std::string &text) diff --git a/src/gui/npcintegerdialog.cpp b/src/gui/npcintegerdialog.cpp index 132a7608..5b3e05aa 100644 --- a/src/gui/npcintegerdialog.cpp +++ b/src/gui/npcintegerdialog.cpp @@ -37,6 +37,9 @@ NpcIntegerDialog::NpcIntegerDialog(Network *network): Window(_("NPC Number Request")), mNetwork(network) { mValueField = new IntTextField(); + setWindowName("NPCInput"); + + setDefaultSize(175, 75, ImageRect::CENTER); mDecButton = new Button("-", "decvalue", this); mIncButton = new Button("+", "incvalue", this); @@ -58,9 +61,9 @@ NpcIntegerDialog::NpcIntegerDialog(Network *network): place(0, 0, resetButton); place(2, 0, cancelButton); place(3, 0, okButton); - reflowLayout(175, 0); + //reflowLayout(175, 0); - setLocationRelativeTo(getParent()); + loadWindowState(); } void NpcIntegerDialog::setRange(const int min, const int max) diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp index f049cba7..505912ac 100644 --- a/src/gui/npclistdialog.cpp +++ b/src/gui/npclistdialog.cpp @@ -45,7 +45,7 @@ NpcListDialog::NpcListDialog(Network *network): setMinWidth(200); setMinHeight(150); - setDefaultSize(0, 0, 260, 200); + setDefaultSize(260, 200, ImageRect::CENTER); mItemList = new ListBox(this); mItemList->setWrappingEnabled(true); @@ -66,7 +66,6 @@ NpcListDialog::NpcListDialog(Network *network): layout.setRowHeight(0, Layout::AUTO_SET); loadWindowState(); - setLocationRelativeTo(getParent()); } int NpcListDialog::getNumberOfElements() diff --git a/src/gui/npcstringdialog.cpp b/src/gui/npcstringdialog.cpp index f2c7434c..58a5c0c8 100644 --- a/src/gui/npcstringdialog.cpp +++ b/src/gui/npcstringdialog.cpp @@ -36,17 +36,20 @@ NpcStringDialog::NpcStringDialog(Network *network): Window(_("NPC Text Request")), mNetwork(network) { + setWindowName("NPCInput"); mValueField = new TextField(""); + setDefaultSize(175, 75, ImageRect::CENTER); + okButton = new Button(_("OK"), "ok", this); cancelButton = new Button(_("Cancel"), "cancel", this); place(0, 0, mValueField, 3); place(1, 1, cancelButton); place(2, 1, okButton); - reflowLayout(175, 0); + //reflowLayout(175, 0); - setLocationRelativeTo(getParent()); + loadWindowState(); } std::string NpcStringDialog::getValue() diff --git a/src/gui/recorder.cpp b/src/gui/recorder.cpp index ff8825ef..9320e020 100644 --- a/src/gui/recorder.cpp +++ b/src/gui/recorder.cpp @@ -40,9 +40,11 @@ Recorder::Recorder(ChatWindow *chat, const std::string &title, mChat = chat; Button *button = new Button(buttonTxt, "activate", this); - setDefaultSize(0, windowContainer->getHeight() - 123 - button->getHeight() - - offsetY, button->getWidth() + offsetX, button->getHeight() + - offsetY); + + // 123 is the default chat window height. If you change this in Chat, please + // change it here as well + setDefaultSize(button->getWidth() + offsetX, button->getHeight() + + offsetY, ImageRect::LOWER_LEFT, 0, 123); place(0, 0, button); diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index 154d1a57..397e29a6 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -48,7 +48,7 @@ SellDialog::SellDialog(Network *network): setResizable(true); setMinWidth(260); setMinHeight(230); - setDefaultSize(0, 0, 260, 230); + setDefaultSize(260, 230, ImageRect::CENTER); // Create a ShopItems instance, that is aware of duplicate entries. mShopItems = new ShopItems(true); @@ -94,7 +94,6 @@ SellDialog::SellDialog(Network *network): layout.setRowHeight(0, Layout::AUTO_SET); loadWindowState(); - setLocationRelativeTo(getParent()); } SellDialog::~SellDialog() diff --git a/src/gui/shortcutwindow.cpp b/src/gui/shortcutwindow.cpp index ee32ca70..c2df1f9c 100644 --- a/src/gui/shortcutwindow.cpp +++ b/src/gui/shortcutwindow.cpp @@ -40,22 +40,17 @@ ShortcutWindow::ShortcutWindow(const char *title, ShortcutContainer *content) mItems = content; - mInstances++; - const int border = SCROLL_PADDING * 2 + getPadding() * 2; setMinWidth(mItems->getBoxWidth() + border); setMinHeight(mItems->getBoxHeight() + border); setMaxWidth(mItems->getBoxWidth() * mItems->getMaxItems() + border); setMaxHeight(mItems->getBoxHeight() * mItems->getMaxItems() + border); - const int width = (int) config.getValue("screenwidth", 800); - const int height = (int) config.getValue("screenheight", 600); + setDefaultSize(mItems->getBoxWidth() + border, (mItems->getBoxHeight() * + mItems->getMaxItems()) + border, ImageRect::LOWER_RIGHT, + mInstances * mItems->getBoxWidth(), 0); - setDefaultSize(width - (mInstances * mItems->getBoxWidth()) - - (mInstances * border), height - (mItems->getBoxHeight() * - mItems->getMaxItems()) - border, mItems->getBoxWidth() + - border, (mItems->getBoxHeight() * mItems->getMaxItems()) + - border); + mInstances++; mScrollArea = new ScrollArea(mItems); mScrollArea->setPosition(SCROLL_PADDING, SCROLL_PADDING); diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp index 42ac4d86..a8250fce 100644 --- a/src/gui/skill.cpp +++ b/src/gui/skill.cpp @@ -135,7 +135,7 @@ SkillDialog::SkillDialog(): setWindowName(_("Skills")); setCloseButton(true); - setDefaultSize(windowContainer->getWidth() - 260, 25, 255, 260); + setDefaultSize(255, 260, ImageRect::CENTER); setMinHeight(50 + mTableModel->getHeight()); setMinWidth(200); diff --git a/src/gui/status.cpp b/src/gui/status.cpp index 6419eabb..e534edb8 100644 --- a/src/gui/status.cpp +++ b/src/gui/status.cpp @@ -41,8 +41,7 @@ StatusWindow::StatusWindow(LocalPlayer *player): { setWindowName(_("Status")); setCloseButton(true); - setDefaultSize((windowContainer->getWidth() - 365) / 2, - (windowContainer->getHeight() - 255) / 2, 400, 345); + setDefaultSize(400, 345, ImageRect::CENTER); // ---------------------- // Status Part diff --git a/src/gui/storagewindow.cpp b/src/gui/storagewindow.cpp index d3bc7ef8..ca7a547f 100644 --- a/src/gui/storagewindow.cpp +++ b/src/gui/storagewindow.cpp @@ -62,7 +62,7 @@ StorageWindow::StorageWindow(Network *network, int invSize): setCloseButton(true); // If you adjust these defaults, don't forget to adjust the trade window's. - setDefaultSize(115, 25, 375, 300); + setDefaultSize(375, 300, ImageRect::CENTER); mStoreButton = new Button(_("Store"), "store", this); mRetrieveButton = new Button(_("Retrieve"), "retrieve", this); @@ -92,7 +92,6 @@ StorageWindow::StorageWindow(Network *network, int invSize): layout.setRowHeight(0, mStoreButton->getHeight()); loadWindowState(); - setLocationRelativeTo(getParent()); } StorageWindow::~StorageWindow() diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp index 76795688..a28ff0f9 100644 --- a/src/gui/trade.cpp +++ b/src/gui/trade.cpp @@ -53,7 +53,7 @@ TradeWindow::TradeWindow(Network *network): mPartnerInventory(new Inventory(INVENTORY_SIZE, 2)) { setWindowName(_("Trade")); - setDefaultSize(115, 227, 342, 209); + setDefaultSize(342, 209, ImageRect::CENTER); setResizable(true); setMinWidth(342); diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 5253dd2e..f1316b4c 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -220,6 +220,53 @@ void Window::setLocationRelativeTo(gcn::Widget *widget) getY() + (wy + (widget->getHeight() - getHeight()) / 2 - y)); } +void Window::setLocationRelativeTo(ImageRect::ImagePosition position) +{ + int x = 0, y = 0; + + if (position == ImageRect::UPPER_LEFT) + { + } + else if (position == ImageRect::UPPER_CENTER) + { + x = (windowContainer->getWidth() - getWidth()) / 2; + } + else if (position == ImageRect::UPPER_RIGHT) + { + x = windowContainer->getWidth() - getWidth(); + } + else if (position == ImageRect::LEFT) + { + y = (windowContainer->getHeight() - getHeight()) / 2; + } + else if (position == ImageRect::CENTER) + { + x = (windowContainer->getWidth() - getWidth()) / 2; + y = (windowContainer->getHeight() - getHeight()) / 2; + } + else if (position == ImageRect::RIGHT) + { + x = windowContainer->getWidth() - getWidth(); + y = (windowContainer->getHeight() - getHeight()) / 2; + } + else if (position == ImageRect::LOWER_LEFT) + { + y = windowContainer->getHeight() - getHeight(); + } + else if (position == ImageRect::LOWER_CENTER) + { + x = (windowContainer->getWidth() - getWidth()) / 2; + y = windowContainer->getHeight() - getHeight(); + } + else if (position == ImageRect::LOWER_RIGHT) + { + x = windowContainer->getWidth() - getWidth(); + y = windowContainer->getHeight() - getHeight(); + } + + setPosition(x, y); +} + void Window::setMinWidth(unsigned int width) { mMinWinWidth = width; @@ -540,6 +587,58 @@ void Window::setDefaultSize(int defaultX, int defaultY, mDefaultHeight = defaultHeight; } +void Window::setDefaultSize(int defaultWidth, int defaultHeight, + ImageRect::ImagePosition position, + int offsetX, int offsetY) +{ + int x = 0, y = 0; + + if (position == ImageRect::UPPER_LEFT) + { + } + else if (position == ImageRect::UPPER_CENTER) + { + x = (windowContainer->getWidth() - defaultWidth) / 2; + } + else if (position == ImageRect::UPPER_RIGHT) + { + x = windowContainer->getWidth() - defaultWidth; + } + else if (position == ImageRect::LEFT) + { + y = (windowContainer->getHeight() - defaultHeight) / 2; + } + else if (position == ImageRect::CENTER) + { + x = (windowContainer->getWidth() - defaultWidth) / 2; + y = (windowContainer->getHeight() - defaultHeight) / 2; + } + else if (position == ImageRect::RIGHT) + { + x = windowContainer->getWidth() - defaultWidth; + y = (windowContainer->getHeight() - defaultHeight) / 2; + } + else if (position == ImageRect::LOWER_LEFT) + { + y = windowContainer->getHeight() - defaultHeight; + } + else if (position == ImageRect::LOWER_CENTER) + { + x = (windowContainer->getWidth() - defaultWidth) / 2; + y = windowContainer->getHeight() - defaultHeight; + } + else if (position == ImageRect::LOWER_RIGHT) + { + x = windowContainer->getWidth() - defaultWidth; + y = windowContainer->getHeight() - defaultHeight; + } + + mDefaultX = x - offsetX; + mDefaultY = y - offsetY; + mDefaultWidth = defaultWidth; + mDefaultHeight = defaultHeight; +} + void Window::resetToDefaultSize() { setPosition(mDefaultX, mDefaultY); diff --git a/src/gui/window.h b/src/gui/window.h index bf15dedb..c24bde76 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -34,7 +34,6 @@ class ConfigListener; class GCContainer; class ContainerPlacer; class Image; -class ImageRect; class Layout; class LayoutCell; class ResizeGrip; @@ -90,6 +89,11 @@ class Window : public gcn::Window, gcn::WidgetListener */ void setLocationRelativeTo(gcn::Widget *widget); + /** + * Sets the location relative to the given enumerated position. + */ + void setLocationRelativeTo(ImageRect::ImagePosition position); + /** * Sets whether or not the window can be resized. */ @@ -246,6 +250,16 @@ class Window : public gcn::Window, gcn::WidgetListener void setDefaultSize(int defaultX, int defaultY, int defaultWidth, int defaultHeight); + /** + * Set the default win pos and size. + * (which can be different of the actual ones.) + * This version of setDefaultSize sets the window's position based + * on a relative enumerated position, rather than a coordinate position. + */ + void setDefaultSize(int defaultWidth, int defaultHeight, + ImageRect::ImagePosition position, + int offsetx = 0, int offsetY = 0); + /** * Reset the win pos and size to default. Don't forget to set defaults * first. diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp index 71ab2fe3..9bd3ab2f 100644 --- a/src/openglgraphics.cpp +++ b/src/openglgraphics.cpp @@ -63,18 +63,17 @@ bool OpenGLGraphics::setVideoMode(int w, int h, int bpp, bool fs, bool hwaccel) mFullscreen = fs; mHWAccel = hwaccel; - if (fs) { + if (fs) displayFlags |= SDL_FULLSCREEN; - } SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - if (!(mScreen = SDL_SetVideoMode(w, h, bpp, displayFlags))) { + if (!(mScreen = SDL_SetVideoMode(w, h, bpp, displayFlags))) return false; - } #ifdef __APPLE__ - if (mSync) { + if (mSync) + { const GLint VBL = 1; CGLSetParameter(CGLGetCurrentContext(), kCGLCPSwapInterval, &VBL); } @@ -158,9 +157,7 @@ bool OpenGLGraphics::drawImage(Image *image, int srcX, int srcY, glEnd(); if (!useColor) - { glColor4ub(mColor.r, mColor.g, mColor.b, mColor.a); - } return true; } @@ -206,9 +203,8 @@ SDL_Surface* OpenGLGraphics::getScreenshot() w, h, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000); - if (SDL_MUSTLOCK(screenshot)) { + if (SDL_MUSTLOCK(screenshot)) SDL_LockSurface(screenshot); - } // Grap the pixel buffer and write it to the SDL surface glPixelStorei(GL_PACK_ALIGNMENT, 1); @@ -230,9 +226,8 @@ SDL_Surface* OpenGLGraphics::getScreenshot() free(buf); - if (SDL_MUSTLOCK(screenshot)) { + if (SDL_MUSTLOCK(screenshot)) SDL_UnlockSurface(screenshot); - } return screenshot; } @@ -242,7 +237,8 @@ bool OpenGLGraphics::pushClipArea(gcn::Rectangle area) int transX = 0; int transY = 0; - if (!mClipStack.empty()) { + if (!mClipStack.empty()) + { transX = -mClipStack.top().xOffset; transY = -mClipStack.top().yOffset; } @@ -267,9 +263,7 @@ void OpenGLGraphics::popClipArea() gcn::Graphics::popClipArea(); if (mClipStack.empty()) - { return; - } glPopMatrix(); glScissor(mClipStack.top().x, @@ -325,8 +319,10 @@ void OpenGLGraphics::setTargetPlane(int width, int height) void OpenGLGraphics::setTexturingAndBlending(bool enable) { - if (enable) { - if (!mTexture) { + if (enable) + { + if (!mTexture) + { glEnable(Image::mTextureType); mTexture = true; } @@ -336,16 +332,22 @@ void OpenGLGraphics::setTexturingAndBlending(bool enable) glEnable(GL_BLEND); mAlpha = true; } - } else { - if (mAlpha && !mColorAlpha) { + } + else + { + if (mAlpha && !mColorAlpha) + { glDisable(GL_BLEND); mAlpha = false; - } else if (!mAlpha && mColorAlpha) { + } + else if (!mAlpha && mColorAlpha) + { glEnable(GL_BLEND); mAlpha = true; } - if (mTexture) { + if (mTexture) + { glDisable(Image::mTextureType); mTexture = false; } -- cgit v1.2.3-70-g09d2 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/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/chat.cpp') diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index 73fa683a..23d91526 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -54,6 +54,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 6c0e0fda..d0690798 100644 --- a/src/beingmanager.h +++ b/src/beingmanager.h @@ -36,6 +36,8 @@ class BeingManager public: BeingManager(Network *network); + ~BeingManager(); + /** * Sets the map on which beings are created */ @@ -112,7 +114,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 74a52ddf..ae708adf 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); @@ -341,11 +340,12 @@ Game::Game(Network *network): msg.writeInt32(tick_time); engine->changeMap(map_path); + + setupWindow->setInGame(true); } Game::~Game() { - delete player_node; destroyGuiWindows(); delete beingManager; @@ -353,6 +353,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 8ecb5f63..55bc2696 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -108,6 +108,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 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 diff --git a/src/gui/setup.h b/src/gui/setup.h index e4eb0902..075c88bf 100644 --- a/src/gui/setup.h +++ b/src/gui/setup.h @@ -31,6 +31,7 @@ #include "../guichanfwd.h" class SetupTab; +class Button; /** * The setup dialog. @@ -50,6 +51,8 @@ class Setup : public Window, public gcn::ActionListener */ ~Setup(); + void setInGame(bool inGame); + /** * Event handling method. */ @@ -57,6 +60,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 49c99996..2610be03 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 61bb9ce9..6112f0e3 100644 --- a/src/gui/skill.cpp +++ b/src/gui/skill.cpp @@ -163,7 +163,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 1371a78e..274f9a48 100644 --- a/src/gui/table.cpp +++ b/src/gui/table.cpp @@ -98,6 +98,7 @@ GuiTable::GuiTable(TableModel *initial_model, gcn::Color background, GuiTable::~GuiTable() { + uninstallActionListeners(); delete mModel; } diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 8eaaf31d..be63ff21 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -142,6 +142,8 @@ Window::~Window() delete(w); } + removeWidgetListener(this); + instances--; // Clean up static resources diff --git a/src/main.cpp b/src/main.cpp index 2c2ff0b6..06093946 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1027,7 +1027,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 c82876e1..14df3f01 100644 --- a/src/player_relations.cpp +++ b/src/player_relations.cpp @@ -28,6 +28,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 @@ -37,7 +39,6 @@ #define IGNORE_EMOTE_TIME 100 - // (De)serialisation class class PlayerConfSerialiser : public ConfigurationListManager, std::map *> @@ -92,6 +93,11 @@ PlayerRelationsManager::PlayerRelationsManager() : { } +PlayerRelationsManager::~PlayerRelationsManager() +{ + delete_all(mIgnoreStrategies); +} + void PlayerRelationsManager::clear() { std::vector *names = getPlayers(); @@ -345,24 +351,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 1eb4ede6..dd363d41 100644 --- a/src/player_relations.h +++ b/src/player_relations.h @@ -94,6 +94,7 @@ class PlayerRelationsManager { public: PlayerRelationsManager(); + ~PlayerRelationsManager(); /** * Initialise player relations manager (load config file etc.) @@ -232,6 +233,7 @@ private: PlayerIgnoreStrategy *mIgnoreStrategy; std::map mRelations; std::list mListeners; + std::vector mIgnoreStrategies; }; -- 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/chat.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 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/chat.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 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/chat.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/chat.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