diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-07-29 17:31:17 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-07-29 17:45:48 +0300 |
commit | a57d736348be038bcc1371b05dbc89459f87d045 (patch) | |
tree | 17b07752ede14f4e3ac2ef1a3d11284a0bbcaddf /src | |
parent | 9234bf25b145995d5395f98a1f5dd030783d25d6 (diff) | |
download | manaverse-a57d736348be038bcc1371b05dbc89459f87d045.tar.gz manaverse-a57d736348be038bcc1371b05dbc89459f87d045.tar.bz2 manaverse-a57d736348be038bcc1371b05dbc89459f87d045.tar.xz manaverse-a57d736348be038bcc1371b05dbc89459f87d045.zip |
Add icons to quests window.
Fix memory leak in extendednamesmodel.
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/questswindow.cpp | 76 | ||||
-rw-r--r-- | src/gui/questswindow.h | 4 | ||||
-rw-r--r-- | src/gui/widgets/extendednamesmodel.cpp | 4 |
3 files changed, 72 insertions, 12 deletions
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<int, std::vector<QuestItem*>>::iterator it = mQuests.begin(), + it_end = mQuests.end(); it != it_end; ++ it) + { + std::vector<QuestItem*> &quests = (*it).second; + for (std::vector<QuestItem*>::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<Image*> &images = mQuestsModel->getImages(); for (std::map<int, int>::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<int, int> mVars; std::map<int, std::vector<QuestItem*>> mQuests; std::vector<QuestItem*> 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<Image*>::iterator it = mImages.begin(), it_end = mImages.end(); it != it_end; ++ it) { - (*it)->decRef(); + if (*it) + (*it)->decRef(); } + mImages.clear(); } |