diff options
-rw-r--r-- | src/gui/skilldialog.cpp | 29 | ||||
-rw-r--r-- | src/gui/widgets/checkbox.cpp | 8 |
2 files changed, 28 insertions, 9 deletions
diff --git a/src/gui/skilldialog.cpp b/src/gui/skilldialog.cpp index d53a1867..09c7ccb2 100644 --- a/src/gui/skilldialog.cpp +++ b/src/gui/skilldialog.cpp @@ -77,7 +77,7 @@ struct SkillInfo icon->decRef(); } - void setIcon(std::string iconPath) + void setIcon(const std::string &iconPath) { ResourceManager *res = ResourceManager::getInstance(); if (!iconPath.empty()) @@ -100,11 +100,19 @@ typedef std::vector<SkillInfo*> SkillList; class SkillModel : public gcn::ListModel { public: - int getNumberOfElements() { return mVisibleSkills.size(); } - SkillInfo *getSkillAt(int i) { return mVisibleSkills.at(i); } - std::string getElementAt(int i) { return getSkillAt(i)->name; } + int getNumberOfElements() + { return mVisibleSkills.size(); } + + SkillInfo *getSkillAt(int i) const + { return mVisibleSkills.at(i); } + + std::string getElementAt(int i) + { return getSkillAt(i)->name; } + void updateVisibilities(); - void addSkill(SkillInfo *info) { mSkills.push_back(info); } + + void addSkill(SkillInfo *info) + { mSkills.push_back(info); } private: SkillList mSkills; @@ -120,7 +128,11 @@ public: SkillInfo *getSelectedInfo() { - return static_cast<SkillModel*>(mListModel)->getSkillAt(getSelected()); + const int selected = getSelected(); + if (selected < 0 || selected > mListModel->getNumberOfElements()) + return 0; + + return static_cast<SkillModel*>(mListModel)->getSkillAt(selected); } void draw(gcn::Graphics *gcnGraphics) @@ -217,9 +229,8 @@ void SkillDialog::action(const gcn::ActionEvent &event) if (tab) { - SkillInfo *info = tab->getSelectedInfo(); - - Net::getPlayerHandler()->increaseSkill(info->id); + if (SkillInfo *info = tab->getSelectedInfo()) + Net::getPlayerHandler()->increaseSkill(info->id); } } else if (event.getId() == "close") diff --git a/src/gui/widgets/checkbox.cpp b/src/gui/widgets/checkbox.cpp index d5253d7c..0fefbfe9 100644 --- a/src/gui/widgets/checkbox.cpp +++ b/src/gui/widgets/checkbox.cpp @@ -112,21 +112,29 @@ void CheckBox::drawBox(gcn::Graphics* graphics) Image *box; if (isEnabled()) + { if (isSelected()) + { if (mHasMouse) box = checkBoxCheckedHi; else box = checkBoxChecked; + } else + { if (mHasMouse) box = checkBoxNormalHi; else box = checkBoxNormal; + } + } else + { if (isSelected()) box = checkBoxDisabledChecked; else box = checkBoxDisabled; + } updateAlpha(); |