diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2009-05-10 20:29:14 +0200 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2009-05-10 21:24:20 +0200 |
commit | 3c912139aef92a3e070ade966c91c297b7a5310c (patch) | |
tree | 2628e66b9cfe3cd494bb33641ac995db949c01fb /src | |
parent | 6e3a3c345a2cad8308738b8b7b5292b9002c1a6e (diff) | |
download | mana-3c912139aef92a3e070ade966c91c297b7a5310c.tar.gz mana-3c912139aef92a3e070ade966c91c297b7a5310c.tar.bz2 mana-3c912139aef92a3e070ade966c91c297b7a5310c.tar.xz mana-3c912139aef92a3e070ade966c91c297b7a5310c.zip |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/npcdialog.cpp | 3 | ||||
-rw-r--r-- | src/gui/partywindow.cpp | 25 | ||||
-rw-r--r-- | src/gui/partywindow.h | 22 | ||||
-rw-r--r-- | src/gui/widgets/avatar.cpp | 14 | ||||
-rw-r--r-- | src/gui/widgets/avatar.h | 7 | ||||
-rw-r--r-- | src/gui/widgets/window.cpp | 18 | ||||
-rw-r--r-- | src/gui/widgets/window.h | 9 | ||||
-rw-r--r-- | 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. * @@ -61,11 +66,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. */ PartyMember *findMember(int id) const; @@ -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); } |