From a57d736348be038bcc1371b05dbc89459f87d045 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 29 Jul 2012 17:31:17 +0300 Subject: Add icons to quests window. Fix memory leak in extendednamesmodel. --- data/graphics/gui/CMakeLists.txt | 2 + data/graphics/gui/Makefile.am | 2 + data/graphics/gui/complete_icon.xml | 5 +++ data/graphics/gui/incomplete_icon.xml | 5 +++ src/gui/questswindow.cpp | 76 +++++++++++++++++++++++++++++----- src/gui/questswindow.h | 4 ++ src/gui/widgets/extendednamesmodel.cpp | 4 +- 7 files changed, 86 insertions(+), 12 deletions(-) create mode 100644 data/graphics/gui/complete_icon.xml create mode 100644 data/graphics/gui/incomplete_icon.xml diff --git a/data/graphics/gui/CMakeLists.txt b/data/graphics/gui/CMakeLists.txt index 4fdc0f805..c192fc4af 100644 --- a/data/graphics/gui/CMakeLists.txt +++ b/data/graphics/gui/CMakeLists.txt @@ -11,12 +11,14 @@ SET (FILES circle-off.xml circle-on.xml colors.xml + complete_icon.xml dropdown.xml dropdown_background.xml dropdown_pressed.xml emote_selection.xml equipment_playerbox.xml equipmentbox.png + incomplete_icon.xml item_selection.xml item_shortcut_background.xml mouse.png diff --git a/data/graphics/gui/Makefile.am b/data/graphics/gui/Makefile.am index 5d442eebf..4718081a4 100644 --- a/data/graphics/gui/Makefile.am +++ b/data/graphics/gui/Makefile.am @@ -14,12 +14,14 @@ gui_DATA = \ circle-off.xml \ circle-on.xml \ colors.xml \ + complete_icon.xml \ dropdown.xml \ dropdown_background.xml \ dropdown_pressed.xml \ emote_selection.xml \ equipment_playerbox.xml \ equipmentbox.png \ + incomplete_icon.xml \ item_selection.xml \ item_shortcut_background.xml \ mouse.png \ diff --git a/data/graphics/gui/complete_icon.xml b/data/graphics/gui/complete_icon.xml new file mode 100644 index 000000000..344503247 --- /dev/null +++ b/data/graphics/gui/complete_icon.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/data/graphics/gui/incomplete_icon.xml b/data/graphics/gui/incomplete_icon.xml new file mode 100644 index 000000000..23e97ec28 --- /dev/null +++ b/data/graphics/gui/incomplete_icon.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/src/gui/questswindow.cpp b/src/gui/questswindow.cpp index f97bac1b4..94e42fd87 100644 --- a/src/gui/questswindow.cpp +++ b/src/gui/questswindow.cpp @@ -23,6 +23,8 @@ #include "logger.h" #include "gui/gui.h" +#include "gui/sdlfont.h" +#include "gui/theme.h" #include "gui/widgets/browserbox.h" #include "gui/widgets/button.h" @@ -74,7 +76,15 @@ class QuestsModel : public ExtendedNamesModel }; QuestsWindow::QuestsWindow() : - Window(_("Quests Window"), false, nullptr, "quest.xml") + Window(_("Quests Window"), false, nullptr, "quest.xml"), + mQuestsModel(new QuestsModel), + mQuestsListBox(new ExtendedListBox(mQuestsModel)), + mQuestScrollArea(new ScrollArea(mQuestsListBox)), + mText(new BrowserBox(BrowserBox::AUTO_WRAP)), + mTextScrollArea(new ScrollArea(mText)), + mCloseButton(new Button(_("Close"), "close", this)), + mCompleteIcon(Theme::getImageFromThemeXml("complete_icon.xml")), + mIncompleteIcon(Theme::getImageFromThemeXml("incomplete_icon.xml")) { setWindowName("Quests"); setResizable(true); @@ -85,20 +95,17 @@ QuestsWindow::QuestsWindow() : setMinWidth(400); setMinHeight(350); - mQuestsModel = new QuestsModel; - mQuestsListBox = new ExtendedListBox(mQuestsModel); mQuestsListBox->setActionEventId("select"); mQuestsListBox->addActionListener(this); - mQuestScrollArea = new ScrollArea(mQuestsListBox); mQuestScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); - mText = new BrowserBox; mText->setOpaque(false); - mTextScrollArea = new ScrollArea(mText); mTextScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); mQuestsListBox->setWidth(500); - - mCloseButton = new Button(_("Close"), "close", this); + if (gui->getNpcFont()->getHeight() < 20) + mQuestsListBox->setRowHeight(20); + else + mQuestsListBox->setRowHeight(gui->getNpcFont()->getHeight()); ContainerPlacer placer; placer = getPlacer(0, 0); @@ -114,6 +121,35 @@ QuestsWindow::QuestsWindow() : layout.setRowHeight(0, Layout::AUTO_SET); } +QuestsWindow::~QuestsWindow() +{ + delete mQuestsModel; + mQuestsModel = nullptr; + + for (std::map>::iterator it = mQuests.begin(), + it_end = mQuests.end(); it != it_end; ++ it) + { + std::vector &quests = (*it).second; + for (std::vector::iterator it2 = quests.begin(), + it2_end = quests.end(); it2 != it2_end; ++ it2) + { + delete *it2; + } + } + mQuests.clear(); + mQuestLinks.clear(); + if (mCompleteIcon) + { + mCompleteIcon->decRef(); + mCompleteIcon = nullptr; + } + if (mIncompleteIcon) + { + mIncompleteIcon->decRef(); + mIncompleteIcon = nullptr; + } +} + void QuestsWindow::loadXml() { XML::Document doc("quests.xml"); @@ -201,6 +237,7 @@ void QuestsWindow::rebuild() { mQuestsModel->clear(); StringVect &names = mQuestsModel->getNames(); + std::vector &images = mQuestsModel->getImages(); for (std::map::const_iterator it = mVars.begin(), it_end = mVars.end(); it != it_end; ++ it) @@ -216,17 +253,34 @@ void QuestsWindow::rebuild() QuestItem *quest = *it2; if (quest->complete.find(val) != quest->complete.end()) { - names.push_back(quest->name + _("[complete]")); mQuestLinks.push_back(quest); + names.push_back(quest->name); + if (mCompleteIcon) + { + mCompleteIcon->incRef(); + images.push_back(mCompleteIcon); + } + else + { + images.push_back(nullptr); + } } else if (quest->incomplete.find(val) != quest->incomplete.end()) { - names.push_back(quest->name); mQuestLinks.push_back(quest); + names.push_back(quest->name); + if (mIncompleteIcon) + { + mIncompleteIcon->incRef(); + images.push_back(mIncompleteIcon); + } + else + { + images.push_back(nullptr); + } } } } -// mQuestsListBox->adjustSize(); } void QuestsWindow::showQuest(QuestItem *quest) diff --git a/src/gui/questswindow.h b/src/gui/questswindow.h index c35e395bd..8454b80f5 100644 --- a/src/gui/questswindow.h +++ b/src/gui/questswindow.h @@ -49,6 +49,8 @@ class QuestsWindow : public Window, public gcn::ActionListener */ QuestsWindow(); + ~QuestsWindow(); + /** * Called when receiving actions from the widgets. */ @@ -74,6 +76,8 @@ class QuestsWindow : public Window, public gcn::ActionListener std::map mVars; std::map> mQuests; std::vector mQuestLinks; + Image *mCompleteIcon; + Image *mIncompleteIcon; }; extern QuestsWindow *questsWindow; diff --git a/src/gui/widgets/extendednamesmodel.cpp b/src/gui/widgets/extendednamesmodel.cpp index 1cc6561dc..11c594321 100644 --- a/src/gui/widgets/extendednamesmodel.cpp +++ b/src/gui/widgets/extendednamesmodel.cpp @@ -65,6 +65,8 @@ void ExtendedNamesModel::clear() for (std::vector::iterator it = mImages.begin(), it_end = mImages.end(); it != it_end; ++ it) { - (*it)->decRef(); + if (*it) + (*it)->decRef(); } + mImages.clear(); } -- cgit v1.2.3-60-g2f50