From 3c912139aef92a3e070ade966c91c297b7a5310c Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Sun, 10 May 2009 20:29:14 +0200 Subject: Fixed the resize grip of the party window It wasn't re-added after doing a clear. Also, don't leak all the PartyMember and Avatar instances. --- src/gui/npcdialog.cpp | 3 --- src/gui/partywindow.cpp | 25 ++++++++++++++++--------- src/gui/partywindow.h | 22 +++++++++++----------- src/gui/widgets/avatar.cpp | 14 ++++---------- src/gui/widgets/avatar.h | 7 +------ src/gui/widgets/window.cpp | 18 +++++++++++------- src/gui/widgets/window.h | 9 ++++----- src/net/ea/partyhandler.cpp | 4 ++-- 8 files changed, 49 insertions(+), 53 deletions(-) diff --git a/src/gui/npcdialog.cpp b/src/gui/npcdialog.cpp index bb53ceb1..eeb76b88 100644 --- a/src/gui/npcdialog.cpp +++ b/src/gui/npcdialog.cpp @@ -25,7 +25,6 @@ #include "gui/widgets/inttextfield.h" #include "gui/widgets/layout.h" #include "gui/widgets/listbox.h" -#include "gui/widgets/resizegrip.h" #include "gui/widgets/scrollarea.h" #include "gui/widgets/textbox.h" #include "gui/widgets/textfield.h" @@ -293,8 +292,6 @@ void NpcDialog::buildLayout() { clearLayout(); - add(mGrip); - if (mActionState != NPC_ACTION_INPUT) { if (mActionState == NPC_ACTION_WAIT) diff --git a/src/gui/partywindow.cpp b/src/gui/partywindow.cpp index 5172f4bb..0479f0fe 100644 --- a/src/gui/partywindow.cpp +++ b/src/gui/partywindow.cpp @@ -30,7 +30,19 @@ #include "utils/gettext.h" #include "utils/stringutils.h" -PartyWindow::PartyWindow() : Window(_("Party")) +PartyMember::PartyMember(): + avatar(new Avatar) +{ +} + +PartyMember::~PartyMember() +{ + delete avatar; +} + + +PartyWindow::PartyWindow() : + Window(_("Party")) { setWindowName("Party"); setVisible(false); @@ -50,11 +62,6 @@ PartyWindow::~PartyWindow() delete_all(mMembers); } -void PartyWindow::draw(gcn::Graphics *graphics) -{ - Window::draw(graphics); -} - PartyMember *PartyWindow::findMember(int id) const { PartyList::const_iterator it = mMembers.find(id); @@ -71,7 +78,6 @@ PartyMember *PartyWindow::findOrCreateMember(int id) if (!member) { member = new PartyMember; - member->avatar = new Avatar(""); mMembers[id] = member; add(member->avatar, 0, (mMembers.size() - 1) * 14); } @@ -195,9 +201,10 @@ void PartyWindow::action(const gcn::ActionEvent &event) } } -void PartyWindow::clear() +void PartyWindow::clearMembers() { - Window::clear(); + clearLayout(); + delete_all(mMembers); mMembers.clear(); } diff --git a/src/gui/partywindow.h b/src/gui/partywindow.h index 6a8cc4fc..65e8d772 100644 --- a/src/gui/partywindow.h +++ b/src/gui/partywindow.h @@ -37,14 +37,19 @@ * Party Member * Used for storing players in the party */ -struct PartyMember +class PartyMember { - std::string name; - bool leader; - bool online; - Avatar *avatar; + public: + PartyMember(); + ~PartyMember(); + + std::string name; + bool leader; + bool online; + Avatar *avatar; }; + /** * Party window. * @@ -60,11 +65,6 @@ class PartyWindow : public Window, gcn::ActionListener */ ~PartyWindow(); - /** - * Draws the party window. - */ - void draw(gcn::Graphics *graphics); - /** * Find a party member based on ID. Returns NULL if not found. */ @@ -113,7 +113,7 @@ class PartyWindow : public Window, gcn::ActionListener */ void action(const gcn::ActionEvent &event); - void clear(); + void clearMembers(); private: /** diff --git a/src/gui/widgets/avatar.cpp b/src/gui/widgets/avatar.cpp index 43910106..a6434f2e 100644 --- a/src/gui/widgets/avatar.cpp +++ b/src/gui/widgets/avatar.cpp @@ -40,13 +40,12 @@ namespace { int avatarCount = 0; } -Avatar::Avatar(const std::string &name): - mName(name) +Avatar::Avatar(): + mHpState("???"), + mMaxHpState("???") { setOpaque(false); setSize(200, 12); - mHpState = "???"; - mMaxHpState = "???"; if (avatarCount == 0) { @@ -61,12 +60,7 @@ Avatar::Avatar(const std::string &name): mStatus = new Icon(avatarStatusOffline); mStatus->setSize(12, 12); add(mStatus, 1, 0); - mAvatarLabel.str(""); - if (mName != player_node->getName()) - mAvatarLabel << mName << " " << mHpState << "/" + mMaxHpState; - else - mAvatarLabel << mName << " " << player_node->getHp() << "/" << player_node->getMaxHp(); - mLabel = new Label(mAvatarLabel.str()); + mLabel = new Label; mLabel->setSize(174, 12); add(mLabel, 16, 0); } diff --git a/src/gui/widgets/avatar.h b/src/gui/widgets/avatar.h index 69f7ed37..ff718cc6 100644 --- a/src/gui/widgets/avatar.h +++ b/src/gui/widgets/avatar.h @@ -35,12 +35,7 @@ class Icon; class Avatar : public Container { public: - /** - * Constructor. - * @param name Character name - */ - Avatar(const std::string &name); - + Avatar(); ~Avatar(); /** diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp index 87051686..19d80671 100644 --- a/src/gui/widgets/window.cpp +++ b/src/gui/widgets/window.cpp @@ -683,21 +683,25 @@ int Window::getGuiAlpha() Layout &Window::getLayout() { - if (!mLayout) mLayout = new Layout; + if (!mLayout) + mLayout = new Layout; return *mLayout; } void Window::clearLayout() { - clear(); // This removes widgets from the container + clear(); - while (!mWidgets.empty()) - delete mWidgets.front(); + // Restore the resize grip + if (mGrip) + add(mGrip); - if (!mLayout) + // Recreate layout instance when one is present + if (mLayout) + { delete mLayout; - mLayout = new Layout; - + mLayout = new Layout; + } } LayoutCell &Window::place(int x, int y, gcn::Widget *wg, int w, int h) diff --git a/src/gui/widgets/window.h b/src/gui/widgets/window.h index f980b96a..153602ba 100644 --- a/src/gui/widgets/window.h +++ b/src/gui/widgets/window.h @@ -295,7 +295,8 @@ class Window : public gcn::Window, gcn::WidgetListener Layout &getLayout(); /** - * Clears the Window's layout (useful for redesigning the window) + * Clears the window's layout (useful for redesigning the window). Does + * not delete the widgets! */ void clearLayout(); @@ -336,9 +337,6 @@ class Window : public gcn::Window, gcn::WidgetListener */ int getGuiAlpha(); - protected: - ResizeGrip *mGrip; /**< Resize grip */ - private: enum ResizeHandles { @@ -357,6 +355,7 @@ class Window : public gcn::Window, gcn::WidgetListener */ int getResizeHandles(gcn::MouseEvent &event); + ResizeGrip *mGrip; /**< Resize grip */ Window *mParent; /**< The parent window */ Layout *mLayout; /**< Layout handler */ std::string mWindowName; /**< Name of the window */ @@ -380,7 +379,7 @@ class Window : public gcn::Window, gcn::WidgetListener static int mouseResize; /**< Active resize handles */ static int instances; /**< Number of Window instances */ - Skin* mSkin; /**< Skin in use by this window */ + Skin *mSkin; /**< Skin in use by this window */ /** * The width of the resize border. Is independent of the actual window diff --git a/src/net/ea/partyhandler.cpp b/src/net/ea/partyhandler.cpp index c906eaef..e5b20a38 100644 --- a/src/net/ea/partyhandler.cpp +++ b/src/net/ea/partyhandler.cpp @@ -86,7 +86,7 @@ void PartyHandler::handleMessage(MessageIn &msg) if (!partyWindow) break; - partyWindow->clear(); + partyWindow->clearMembers(); int length = msg.readInt16(); std::string party = msg.readString(24); @@ -231,7 +231,7 @@ void PartyHandler::handleMessage(MessageIn &msg) if (id == player_node->getId()) { player_node->setInParty(false); - partyWindow->clear(); + partyWindow->clearMembers(); partyWindow->setVisible(false); partyTab->chatLog(_("You have left the party."), BY_SERVER); } -- cgit v1.2.3-70-g09d2