summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2005-01-15 19:08:49 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2005-01-15 19:08:49 +0000
commit13f82f10d92816d0239db56b7936fd2403f50897 (patch)
tree8609c90794dc8bcba1f613c6cac9907e7e58d4e4
parent8ed926ea15e8f151b8b81f93a5dccd0d53cf7ca1 (diff)
downloadmana-13f82f10d92816d0239db56b7936fd2403f50897.tar.gz
mana-13f82f10d92816d0239db56b7936fd2403f50897.tar.bz2
mana-13f82f10d92816d0239db56b7936fd2403f50897.tar.xz
mana-13f82f10d92816d0239db56b7936fd2403f50897.zip
Fixed upping skills.
-rw-r--r--src/game.cpp6
-rw-r--r--src/gui/skill.cpp186
-rw-r--r--src/gui/skill.h49
-rw-r--r--src/main.h4
4 files changed, 102 insertions, 143 deletions
diff --git a/src/game.cpp b/src/game.cpp
index 142cfbe2..b38f1368 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -890,13 +890,13 @@ void do_parse() {
RFIFOB(4 + k * 37 + 36)!=0)
{
int skillId = RFIFOW(4 + k * 37);
- if (skillDialog->getModel()->hasSkill(skillId)) {
- skillDialog->getModel()->setSkill(skillId,
+ if (skillDialog->hasSkill(skillId)) {
+ skillDialog->setSkill(skillId,
RFIFOW(4 + k * 37 + 6),
RFIFOW(4 + k * 37 + 36));
}
else {
- skillDialog->getModel()->addSkill(
+ skillDialog->addSkill(
RFIFOW(4 + k * 37),
RFIFOW(4 + k * 37 + 6),
RFIFOW(4 + k * 37 + 8));
diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp
index 65214e4a..4c3feedf 100644
--- a/src/gui/skill.cpp
+++ b/src/gui/skill.cpp
@@ -28,99 +28,35 @@
#include "../main.h"
char *skill_db[] = {
- // 0-99
- "", "Basic", "", "", "", "", "", "", "", "",
- "", "", "", "", "", "", "", "", "", "",
- "", "", "", "", "", "", "", "", "", "",
- "", "", "", "", "", "", "", "", "", "",
- "", "", "", "", "", "", "", "", "", "",
- "", "", "", "", "", "", "", "", "", "",
- "", "", "", "", "", "", "", "", "", "",
- "", "", "", "", "", "", "", "", "", "",
- "", "", "", "", "", "", "", "", "", "",
- "", "", "", "", "", "", "", "", "", "",
- // 100-199
- "", "", "", "", "", "", "", "", "", "",
- "", "", "", "", "", "", "", "", "", "",
- "", "", "", "", "", "", "", "", "", "",
- "", "", "", "", "", "", "", "", "", "",
- "", "", "First aid", "Play as dead", "", "", "", "", "", "",
- "", "", "", "", "", "", "", "", "", "",
- "", "", "", "", "", "", "", "", "", "",
- "", "", "", "", "", "", "", "", "", "",
- "", "", "", "", "", "", "", "", "", "",
- "", "", "", "", "", "", "", "", "", "",
+ // 0-99
+ "", "Basic", "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "", "",
+ // 100-199
+ "", "", "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "", "",
+ "", "", "First aid", "Play as dead", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "", "",
};
-SkillListModel::SkillListModel()
-{
-}
-
-SkillListModel::~SkillListModel()
-{
- for (int i = skillList.size() - 1; i >= 0; i--)
- {
- delete skillList[i];
- skillList.pop_back();
- }
-}
-
-int SkillListModel::getNumberOfElements()
-{
- return skillList.size();
-}
-
-std::string SkillListModel::getElementAt(int i)
-{
- if (i >= 0 && i < (int)skillList.size())
- {
- //return skill_db[skillList[i]->id];
- char tmp[128];
- sprintf(tmp, "%s Lv: %i Sp: %i",
- skill_db[skillList[i]->id],
- skillList[i]->lv,
- skillList[i]->sp);
- return tmp;
- }
- return "";
-}
-
-bool SkillListModel::hasSkill(int id)
-{
- for (unsigned int i = 0; i < skillList.size(); i++) {
- if (skillList[i]->id == id) {
- return true;
- }
- }
- return false;
-}
-
-void SkillListModel::addSkill(int id, int lv, int sp)
-{
- SKILL *tmp = new SKILL;
- tmp->id = id;
- tmp->lv = lv;
- tmp->sp = sp;
- skillList.push_back(tmp);
-}
-
-void SkillListModel::setSkill(int id, int lv, int sp)
-{
- for (unsigned int i = 0; i < skillList.size(); i++) {
- if (skillList[i]->id == id) {
- skillList[i]->lv = lv;
- skillList[i]->sp = sp;
- }
- }
-}
-
-
SkillDialog::SkillDialog():
Window("Skills")
{
- skills = new SkillListModel();
- skillListBox = new ListBox(skills);
+ skillListBox = new ListBox(this);
skillScrollArea = new ScrollArea(skillListBox);
pointsLabel = new gcn::Label("Skill Points:");
incButton = new Button(" Up ");
@@ -154,20 +90,27 @@ SkillDialog::~SkillDialog()
delete incButton;
delete closeButton;
- delete skills;
+ for (int i = skillList.size() - 1; i >= 0; i--)
+ {
+ delete skillList[i];
+ skillList.pop_back();
+ }
}
void SkillDialog::action(const std::string& eventId)
{
if (eventId == "inc")
{
- //increment skill
- //if (char_info->skill_point > 0) {
- // WFIFOW(0) = net_w_value(0x0112);
- // WFIFOW(2) = net_w_value(
- // get_skill_id(skill_list_dialog[3].d1));
- // WFIFOSET(4);
- //}
+ // Increment skill
+ int selectedSkill = skillListBox->getSelected();
+ std::cout << "SkillDialog::action(" << selectedSkill << ")\n";
+ if (char_info->skill_point > 0 && selectedSkill >= 0) {
+ std::cout << "Sending upgrade of id " << skillList[selectedSkill]->id << "\n";
+ WFIFOW(0) = net_w_value(0x0112);
+ WFIFOW(2) = net_w_value(
+ skillList[selectedSkill]->id);
+ WFIFOSET(4);
+ }
}
else if (eventId == "close")
{
@@ -175,11 +118,6 @@ void SkillDialog::action(const std::string& eventId)
}
}
-SkillListModel* SkillDialog::getModel()
-{
- return skills;
-}
-
void SkillDialog::setPoints(int i)
{
char tmp[128];
@@ -189,3 +127,51 @@ void SkillDialog::setPoints(int i)
}
}
+int SkillDialog::getNumberOfElements()
+{
+ return skillList.size();
+}
+
+std::string SkillDialog::getElementAt(int i)
+{
+ if (i >= 0 && i < (int)skillList.size())
+ {
+ char tmp[128];
+ sprintf(tmp, "%s Lv: %i Sp: %i",
+ skill_db[skillList[i]->id],
+ skillList[i]->lv,
+ skillList[i]->sp);
+ return tmp;
+ }
+ return "";
+}
+
+bool SkillDialog::hasSkill(int id)
+{
+ for (unsigned int i = 0; i < skillList.size(); i++) {
+ if (skillList[i]->id == id) {
+ return true;
+ }
+ }
+ return false;
+}
+
+void SkillDialog::addSkill(int id, int lv, int sp)
+{
+ SKILL *tmp = new SKILL();
+ tmp->id = id;
+ tmp->lv = lv;
+ tmp->sp = sp;
+ skillList.push_back(tmp);
+}
+
+void SkillDialog::setSkill(int id, int lv, int sp)
+{
+ for (unsigned int i = 0; i < skillList.size(); i++) {
+ if (skillList[i]->id == id) {
+ skillList[i]->lv = lv;
+ skillList[i]->sp = sp;
+ }
+ }
+}
+
diff --git a/src/gui/skill.h b/src/gui/skill.h
index 1d68bffe..5db90f04 100644
--- a/src/gui/skill.h
+++ b/src/gui/skill.h
@@ -24,59 +24,31 @@
#ifndef _TMW_SKILL_H
#define _TMW_SKILL_H
-#include <allegro.h>
+#include <guichan.hpp>
#include "window.h"
struct SKILL {
- short id; //index into "skill_db" array
+ short id; /**< Index into "skill_db" array */
short lv, sp;
};
/**
- * The skill list model.
- *
- * \ingroup GUI
- */
-class SkillListModel : public gcn::ListModel
-{
- private:
- std::vector<SKILL*> skillList;
-
- public:
- /**
- * Constructor.
- */
- SkillListModel();
-
- /**
- * Destructor.
- */
- virtual ~SkillListModel();
-
- int getNumberOfElements();
- std::string getElementAt(int);
-
- bool hasSkill(int id);
- void addSkill(int id, int lv, int sp);
- void setSkill(int id, int lv, int sp);
-};
-
-/**
* The skill dialog.
*
* \ingroup GUI
*/
-class SkillDialog : public Window, public gcn::ActionListener
+class SkillDialog : public Window, public gcn::ActionListener,
+ public gcn::ListModel
{
private:
gcn::ListBox *skillListBox;
gcn::ScrollArea *skillScrollArea;
- SkillListModel *skills;
gcn::Label *pointsLabel;
-
gcn::Button *incButton;
gcn::Button *closeButton;
+ std::vector<SKILL*> skillList;
+
public:
/**
* Constructor.
@@ -90,9 +62,14 @@ class SkillDialog : public Window, public gcn::ActionListener
void action(const std::string&);
- SkillListModel* getModel();
-
void setPoints(int i);
+
+ int getNumberOfElements();
+ std::string getElementAt(int);
+
+ bool hasSkill(int id);
+ void addSkill(int id, int lv, int sp);
+ void setSkill(int id, int lv, int sp);
};
#endif
diff --git a/src/main.h b/src/main.h
index d95be88b..099d9a3d 100644
--- a/src/main.h
+++ b/src/main.h
@@ -24,10 +24,6 @@
#ifndef _TMW_MAIN_H
#define _TMW_MAIN_H
-#ifdef WIN32
- #pragma warning (disable:4312)
-#endif
-
#include <guichan.hpp>
#include <guichan/allegro.hpp>