summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2010-03-02 21:55:47 +0100
committerThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2010-03-02 22:02:52 +0100
commit4f422bd50c51d812fb9e50f2610c2cd37ead8ef2 (patch)
tree5c257b7c611e7bd519265bcfcb33a882804acf35
parent2a70d4ba6e789075cd9bee1fea4f757186d68f76 (diff)
downloadmana-4f422bd50c51d812fb9e50f2610c2cd37ead8ef2.tar.gz
mana-4f422bd50c51d812fb9e50f2610c2cd37ead8ef2.tar.bz2
mana-4f422bd50c51d812fb9e50f2610c2cd37ead8ef2.tar.xz
mana-4f422bd50c51d812fb9e50f2610c2cd37ead8ef2.zip
Fixed crash when trying to increase non-selected skill
Reviewed-by: Jared Adams Reviewed-by: Bertram
-rw-r--r--src/gui/skilldialog.cpp29
-rw-r--r--src/gui/widgets/checkbox.cpp8
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();