summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2005-02-20 20:56:59 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2005-02-20 20:56:59 +0000
commit7ce021a8e4fce72af6e79cad22243bdd50bb8656 (patch)
tree06f9eadde06667d640f94e8ecc8b526a45af402d /src
parent368c9002365118212d9ef9b6bb00f9148522770f (diff)
downloadmana-client-7ce021a8e4fce72af6e79cad22243bdd50bb8656.tar.gz
mana-client-7ce021a8e4fce72af6e79cad22243bdd50bb8656.tar.bz2
mana-client-7ce021a8e4fce72af6e79cad22243bdd50bb8656.tar.xz
mana-client-7ce021a8e4fce72af6e79cad22243bdd50bb8656.zip
Reverted changes to skill dialog, a new one will be developed alongside it so
that the current one remains working for now. Also XML maps now can load but not the base64 or gzip kind yet.
Diffstat (limited to 'src')
-rw-r--r--src/game.cpp7
-rw-r--r--src/gui/skill.cpp102
-rw-r--r--src/gui/skill.h34
-rw-r--r--src/gui/window.cpp2
-rw-r--r--src/main.cpp3
-rw-r--r--src/resources/mapreader.cpp16
6 files changed, 126 insertions, 38 deletions
diff --git a/src/game.cpp b/src/game.cpp
index be2eacb8..e9edee54 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -33,6 +33,7 @@
#include "gui/stats.h"
#include "gui/ok_dialog.h"
#include "graphic/graphic.h"
+#include "resources/mapreader.h"
#include "sound.h"
#include <SDL.h>
@@ -123,6 +124,7 @@ void game() {
void do_init()
{
tiledMap = Map::load(map_path);
+ //tiledMap = MapReader::readMap("map/desert.tmx");
if (!tiledMap) {
error("Could not find map file");
}
@@ -707,6 +709,7 @@ void do_parse() {
break;
case 0x000c:
char_info->skill_point = RFIFOW(4);
+ skillDialog->setPoints(char_info->skill_point);
break;
case 0x0037:
char_info->job_lv = RFIFOW(4);
@@ -926,7 +929,7 @@ void do_parse() {
int n_skills = (len - 4) / 37;
for (int k = 0; k < n_skills; k++)
{
- /*if (RFIFOW(4 + k * 37 + 6) != 0 ||
+ if (RFIFOW(4 + k * 37 + 6) != 0 ||
RFIFOB(4 + k * 37 + 36)!=0)
{
int skillId = RFIFOW(4 + k * 37);
@@ -941,7 +944,7 @@ void do_parse() {
RFIFOW(4 + k * 37 + 6),
RFIFOW(4 + k * 37 + 8));
}
- }*/
+ }
}
} break;
// MVP experience
diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp
index 3d6d7768..4c3feedf 100644
--- a/src/gui/skill.cpp
+++ b/src/gui/skill.cpp
@@ -29,22 +29,22 @@
char *skill_db[] = {
// 0-99
- /* weapons 0-9 */ "Short Blades", "Long Blades", "Hammers", "Archery", "Exotic", "Throwing", "Piercing", "Hand to Hand", "", "",
- /* magic 10-19 */ "Djin (Fire)", "Niksa (Water)", "Kerub (Earth)", "Ariel (Air)", "Paradin (Light)", "Tharsis (Dark)", "Crono (Time)", "Astra (Space)", "Gen (Mana)", "",
- /* craft 20-29 */ "Smithy", "Jeweler", "Alchemist", "Cook", "Tailor", "Artisan", "", "", "", "",
- /* general 30-39 */ "Running", "Searching", "Sneak", "Trading", "Intimidate", "", "", "", "", "",
+ "", "Basic", "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "",
- // 100-199
"", "", "", "", "", "", "", "", "", "",
+ // 100-199
"", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "",
+ "", "", "First aid", "Play as dead", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "",
@@ -52,15 +52,11 @@ char *skill_db[] = {
"", "", "", "", "", "", "", "", "", "",
};
-// pointer to the info struct the
-// dialog is concerned with (to insure future flexibility)
-PLAYER_INFO** SkillList = &char_info;
-
SkillDialog::SkillDialog():
Window("Skills")
{
- /*skillListBox = new ListBox(this);
+ skillListBox = new ListBox(this);
skillScrollArea = new ScrollArea(skillListBox);
pointsLabel = new gcn::Label("Skill Points:");
incButton = new Button(" Up ");
@@ -83,23 +79,99 @@ SkillDialog::SkillDialog():
incButton->addActionListener(this);
closeButton->addActionListener(this);
- setLocationRelativeTo(getParent());*/
-
+ setLocationRelativeTo(getParent());
}
SkillDialog::~SkillDialog()
{
- /* delete skillListBox;
+ delete skillListBox;
delete skillScrollArea;
delete pointsLabel;
delete incButton;
- delete closeButton;*/
+ delete closeButton;
+ for (int i = skillList.size() - 1; i >= 0; i--)
+ {
+ delete skillList[i];
+ skillList.pop_back();
+ }
}
void SkillDialog::action(const std::string& eventId)
{
- // GUI design
+ if (eventId == "inc")
+ {
+ // 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")
+ {
+ setVisible(false);
+ }
+}
+
+void SkillDialog::setPoints(int i)
+{
+ char tmp[128];
+ sprintf(tmp, "Skill points: %i", i);
+ if (pointsLabel != NULL) {
+ pointsLabel->setCaption(tmp);
+ }
+}
+
+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 6ee511cc..5db90f04 100644
--- a/src/gui/skill.h
+++ b/src/gui/skill.h
@@ -24,28 +24,21 @@
#ifndef _TMW_SKILL_H
#define _TMW_SKILL_H
-
#include <guichan.hpp>
#include "window.h"
-#include <vector>
+
+struct SKILL {
+ short id; /**< Index into "skill_db" array */
+ short lv, sp;
+};
+
/**
* The skill dialog.
*
* \ingroup GUI
*/
-
-// skill struct, by Kyokai
-// skill names are stored in a table elsewhere. (SkillDialog.cpp)
-typedef struct {
- short level; // level of the skill
- short exp; // exp value
- double mod; // value of the modifier (0,0.5,1,2,4)
- // next value can be calculated when needed by the function:
- // 20 * level^1.2
- } SKILL;
-
-class SkillDialog : public Window, public gcn::ActionListener
-// public gcn::ListModel
+class SkillDialog : public Window, public gcn::ActionListener,
+ public gcn::ListModel
{
private:
gcn::ListBox *skillListBox;
@@ -54,6 +47,8 @@ class SkillDialog : public Window, public gcn::ActionListener
gcn::Button *incButton;
gcn::Button *closeButton;
+ std::vector<SKILL*> skillList;
+
public:
/**
* Constructor.
@@ -66,6 +61,15 @@ class SkillDialog : public Window, public gcn::ActionListener
~SkillDialog();
void action(const std::string&);
+
+ 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/gui/window.cpp b/src/gui/window.cpp
index c17e4c76..399cb73f 100644
--- a/src/gui/window.cpp
+++ b/src/gui/window.cpp
@@ -227,10 +227,12 @@ void Window::mouseMotion(int mx, int my)
if (y + winHeight > screen->h) y = screen->h - winHeight;
// Snap window to edges
+ /*
if (x < snapSize) x = 0;
if (y < snapSize) y = 0;
if (x + winWidth + snapSize > screen->w) x = screen->w - winWidth;
if (y + winHeight + snapSize > screen->h) y = screen->h - winHeight;
+ */
this->setPosition(x, y);
}
diff --git a/src/main.cpp b/src/main.cpp
index 686763ba..4b5b745c 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -393,6 +393,7 @@ int main(int argc, char *argv[])
// This function also increases the XP of the skill by the given parameter.
// Call n_base to return the actual value, regardless of equipment modifiers.
// ---by Kyokai
+/*
int PLAYER_INFO::GetSkill(int n_ID, int n_XP, int n_base)
{
if (n_ID > N_SKILLS || n_ID < 0) // out of cheese error, abort function
@@ -418,4 +419,4 @@ int PLAYER_INFO::GetSkill(int n_ID, int n_XP, int n_base)
return r; // return the value
}
-
+*/
diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp
index 98160ff8..32b71d9c 100644
--- a/src/resources/mapreader.cpp
+++ b/src/resources/mapreader.cpp
@@ -47,9 +47,11 @@ int Tileset::getFirstGid()
Map *MapReader::readMap(const std::string &filename)
{
- std::cout << "Attempting to parse XML map data";
+ log("Attempting to parse XML map data");
- FILE* f = fopen(filename.c_str(), "rb");
+ std::string name = std::string("data/") + filename;
+
+ FILE* f = fopen(name.c_str(), "rb");
char *map_string;
if (!f) {
@@ -72,7 +74,7 @@ Map *MapReader::readMap(const std::string &filename)
delete[] map_string;
if (doc) {
- std::cout << "Looking for root node";
+ log("Looking for root node");
xmlNodePtr node = xmlDocGetRootElement(doc);
if (!node || !xmlStrEqual(node->name, BAD_CAST "map")) {
@@ -80,7 +82,7 @@ Map *MapReader::readMap(const std::string &filename)
return NULL;
}
- std::cout << "Loading map from XML tree";
+ log("Loading map from XML tree");
return readMap(node, filename);
xmlFreeDoc(doc);
} else {
@@ -93,6 +95,9 @@ Map *MapReader::readMap(const std::string &filename)
Map* MapReader::readMap(xmlNodePtr node, const std::string &path)
{
xmlChar *prop;
+
+ // Take the filename off the path
+ std::string pathDir = path.substr(0, path.rfind("/") + 1);
prop = xmlGetProp(node, BAD_CAST "version");
#ifndef WIN32
@@ -111,7 +116,7 @@ Map* MapReader::readMap(xmlNodePtr node, const std::string &path)
{
if (xmlStrEqual(node->name, BAD_CAST "tileset"))
{
- Tileset *tileset = readTileset(node, path, map);
+ Tileset *tileset = readTileset(node, pathDir, map);
if (tileset) {
tilesets.push_back(tileset);
}
@@ -162,6 +167,7 @@ void MapReader::readLayer(xmlNodePtr node, Map *map, int layer)
}
}
+ if (layer == 0) map->setWalk(x, y, true);
map->setTile(x, y, layer, img);
x++;