From faa6c2a26deb18469066a74b2d6c76fdae5931c7 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 19 Jan 2012 18:38:02 +0300 Subject: Prevent adding double attributes to status window. --- src/gui/statuswindow.cpp | 12 +++++++++++- src/gui/statuswindow.h | 2 ++ src/gui/widgets/vertcontainer.cpp | 1 + src/net/tmwa/generalhandler.cpp | 3 +++ 4 files changed, 17 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/gui/statuswindow.cpp b/src/gui/statuswindow.cpp index b3e3f38f3..20a017a41 100644 --- a/src/gui/statuswindow.cpp +++ b/src/gui/statuswindow.cpp @@ -431,10 +431,20 @@ void StatusWindow::addAttribute(int id, const std::string &name, disp = new DerDisplay(id, name); mDAttrCont->add(disp); } - mAttrs[id] = disp; } +void StatusWindow::clearAttributes() +{ + mAttrCont->clear(); + mDAttrCont->clear(); + Attrs::iterator it = mAttrs.begin(); + Attrs::iterator it_end = mAttrs.end(); + for (; it != it_end; ++ it) + delete (*it).second; + mAttrs.clear(); +} + void StatusWindow::updateHPBar(ProgressBar *bar, bool showMax) { if (!bar) diff --git a/src/gui/statuswindow.h b/src/gui/statuswindow.h index 87107694f..8e110a354 100644 --- a/src/gui/statuswindow.h +++ b/src/gui/statuswindow.h @@ -75,6 +75,8 @@ class StatusWindow : public Window, void action(const gcn::ActionEvent &event); + void clearAttributes(); + private: static std::string translateLetter(const char* letters); diff --git a/src/gui/widgets/vertcontainer.cpp b/src/gui/widgets/vertcontainer.cpp index 36daf7676..305343d1a 100644 --- a/src/gui/widgets/vertcontainer.cpp +++ b/src/gui/widgets/vertcontainer.cpp @@ -69,6 +69,7 @@ void VertContainer::clear() Container::clear(); mCount = 0; + mNextY = 0; } void VertContainer::widgetResized(const gcn::Event &event A_UNUSED) diff --git a/src/net/tmwa/generalhandler.cpp b/src/net/tmwa/generalhandler.cpp index ea44ec206..09c216ed3 100644 --- a/src/net/tmwa/generalhandler.cpp +++ b/src/net/tmwa/generalhandler.cpp @@ -259,6 +259,9 @@ void GeneralHandler::processEvent(Mana::Channels channel, if (!statusWindow) return; + // protection against double addition attributes. + statusWindow->clearAttributes(); + statusWindow->addAttribute(STR, _("Strength"), true, ""); statusWindow->addAttribute(AGI, _("Agility"), true, ""); statusWindow->addAttribute(VIT, _("Vitality"), true, ""); -- cgit v1.2.3-70-g09d2