summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2005-01-04 14:16:59 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2005-01-04 14:16:59 +0000
commitdd2d81690185e789d435d5b1839c04bd8e77dea4 (patch)
tree7adb0d14f47242747a1af492e69fa5431aa13d99 /src
parent52b6be101b78990d5b4523dd5c6523dc5c7c6709 (diff)
downloadmana-dd2d81690185e789d435d5b1839c04bd8e77dea4.tar.gz
mana-dd2d81690185e789d435d5b1839c04bd8e77dea4.tar.bz2
mana-dd2d81690185e789d435d5b1839c04bd8e77dea4.tar.xz
mana-dd2d81690185e789d435d5b1839c04bd8e77dea4.zip
Use custom ListBox and ScrollArea for skill dialog.
Diffstat (limited to 'src')
-rw-r--r--src/gui/skill.cpp36
-rw-r--r--src/gui/skill.h29
2 files changed, 40 insertions, 25 deletions
diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp
index d3308aa5..3abc6eb1 100644
--- a/src/gui/skill.cpp
+++ b/src/gui/skill.cpp
@@ -22,6 +22,8 @@
*/
#include "skill.h"
+#include "listbox.h"
+#include "scrollarea.h"
extern PLAYER_INFO *char_info;
@@ -53,7 +55,6 @@ char *skill_db[] = {
SkillListModel::SkillListModel()
{
- //
}
SkillListModel::~SkillListModel()
@@ -72,7 +73,6 @@ int SkillListModel::getNumberOfElements()
std::string SkillListModel::getElementAt(int i)
{
- //
if (i >= 0 && i < skillList.size())
{
//return skill_db[skillList[i]->id];
@@ -85,9 +85,11 @@ std::string SkillListModel::getElementAt(int i)
bool SkillListModel::hasSkill(int id)
{
- for (int i = 0; i < skillList.size(); i++)
- if (skillList[i]->id == id)
+ for (unsigned int i = 0; i < skillList.size(); i++) {
+ if (skillList[i]->id == id) {
return true;
+ }
+ }
return false;
}
@@ -102,20 +104,20 @@ void SkillListModel::addSkill(int id, int lv, int sp)
void SkillListModel::setSkill(int id, int lv, int sp)
{
- if (!hasSkill(id))
+ if (!hasSkill(id)) {
return;
+ }
skillList[id]->lv = lv;
skillList[id]->sp = sp;
}
-//
SkillDialog::SkillDialog(gcn::Container *parent)
: Window(parent, "Skills")
{
- skills = new SkillListModel;
-
- skillListBox = new gcn::ListBox(skills);
+ skills = new SkillListModel();
+ skillListBox = new ListBox(skills);
+ skillScrollArea = new ScrollArea(skillListBox);
pointsLabel = new gcn::Label("Skill Points:");
incButton = new Button(" Up ");
closeButton = new Button("Close");
@@ -123,15 +125,12 @@ SkillDialog::SkillDialog(gcn::Container *parent)
incButton->setEventId("inc");
closeButton->setEventId("close");
- skillListBox->setDimension(gcn::Rectangle(0, 0, 200, 180));
- pointsLabel->setDimension(gcn::Rectangle(0, 0, 200, 16));
-
- skillListBox->setPosition(8, 4);
- pointsLabel->setPosition(8, 190);
+ skillScrollArea->setDimension(gcn::Rectangle(8, 4, 200, 180));
+ pointsLabel->setDimension(gcn::Rectangle(8, 190, 200, 16));
incButton->setPosition(64, 210);
closeButton->setPosition(160, 210);
- add(skillListBox);
+ add(skillScrollArea);
add(pointsLabel);
add(incButton);
add(closeButton);
@@ -146,6 +145,7 @@ SkillDialog::SkillDialog(gcn::Container *parent)
SkillDialog::~SkillDialog()
{
delete skillListBox;
+ delete skillScrollArea;
delete pointsLabel;
delete incButton;
delete closeButton;
@@ -158,7 +158,8 @@ void SkillDialog::action(const std::string& eventId)
if (eventId == "inc")
{
//increment skill
- } else if (eventId == "close")
+ }
+ else if (eventId == "close")
{
setVisible(false);
}
@@ -168,7 +169,8 @@ void SkillDialog::setPoints(int i)
{
char tmp[128];
sprintf(tmp, "Skill points: %i", i);
- if (pointsLabel != NULL)
+ if (pointsLabel != NULL) {
pointsLabel->setCaption(tmp);
+ }
}
diff --git a/src/gui/skill.h b/src/gui/skill.h
index 21f76212..78f48e30 100644
--- a/src/gui/skill.h
+++ b/src/gui/skill.h
@@ -21,8 +21,8 @@
* $Id$
*/
-#ifndef _SKILL_H
-#define _SKILL_H
+#ifndef _TMW_SKILL_H
+#define _TMW_SKILL_H
#include <allegro.h>
#include "button.h"
@@ -33,12 +33,17 @@ struct SKILL {
short lv, sp;
};
+/**
+ * The skill list model.
+ *
+ * \ingroup GUI
+ */
class SkillListModel : public gcn::ListModel
{
std::vector<SKILL*> skillList;
public:
SkillListModel();
- ~SkillListModel();
+ virtual ~SkillListModel();
int getNumberOfElements();
std::string getElementAt(int);
@@ -48,14 +53,22 @@ class SkillListModel : public gcn::ListModel
void setSkill(int id, int lv, int sp);
};
+/**
+ * The skill dialog.
+ *
+ * \ingroup GUI
+ */
class SkillDialog : public Window, public gcn::ActionListener
{
- gcn::ListBox *skillListBox;
- SkillListModel *skills;
- gcn::Label *pointsLabel;
+ private:
+ gcn::ListBox *skillListBox;
+ gcn::ScrollArea *skillScrollArea;
+ SkillListModel *skills;
+ gcn::Label *pointsLabel;
+
+ Button *incButton;
+ Button *closeButton;
- Button *incButton;
- Button *closeButton;
public:
SkillDialog(gcn::Container *);
~SkillDialog();