summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gui/npc.cpp25
-rw-r--r--src/map.cpp12
-rw-r--r--src/map.h11
-rw-r--r--src/resources/mapreader.cpp76
-rw-r--r--src/resources/mapreader.h8
5 files changed, 77 insertions, 55 deletions
diff --git a/src/gui/npc.cpp b/src/gui/npc.cpp
index 73e1393a..4706112b 100644
--- a/src/gui/npc.cpp
+++ b/src/gui/npc.cpp
@@ -33,27 +33,29 @@ NpcListDialog::NpcListDialog():
itemList = new ListBox(this);
scrollArea = new ScrollArea(itemList);
okButton = new Button("OK");
- //cancelButton = new Button("Cancel");
+ cancelButton = new Button("Cancel");
setSize(260, 175);
scrollArea->setDimension(gcn::Rectangle(
5, 5, 250, 160 - okButton->getHeight()));
+ cancelButton->setPosition(
+ 260 - 5 - cancelButton->getWidth(),
+ 175 - 5 - cancelButton->getHeight());
okButton->setPosition(
- 260 - 5 - okButton->getWidth(),
- 175 - 5 - okButton->getHeight());
- //cancelButton->setPosition(208, 145);
+ cancelButton->getX() - 5 - okButton->getWidth(),
+ cancelButton->getY());
itemList->setEventId("item");
okButton->setEventId("ok");
- //cancelButton->setEventId("cancel");
+ cancelButton->setEventId("cancel");
itemList->addActionListener(this);
okButton->addActionListener(this);
- //cancelButton->addActionListener(this);
+ cancelButton->addActionListener(this);
add(scrollArea);
add(okButton);
- //add(cancelButton);
+ add(cancelButton);
setLocationRelativeTo(getParent());
}
@@ -61,7 +63,7 @@ NpcListDialog::NpcListDialog():
NpcListDialog::~NpcListDialog()
{
delete okButton;
- //delete cancelButton;
+ delete cancelButton;
delete itemList;
delete scrollArea;
}
@@ -109,10 +111,13 @@ void NpcListDialog::action(const std::string& eventId)
reset();
}
}
- /*
else if (eventId == "cancel") {
+ // 0xff packet means cancel
+ WFIFOW(0) = net_w_value(0x00b8);
+ WFIFOL(2) = net_l_value(current_npc);
+ WFIFOB(6) = net_b_value(0xff);
+ WFIFOSET(7);
setVisible(false);
reset();
}
- */
}
diff --git a/src/map.cpp b/src/map.cpp
index 2c7524a4..f172ad56 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -89,6 +89,7 @@ bool Location::operator< (const Location &loc) const
Map::Map():
width(0), height(0),
+ tileWidth(32), tileHeight(32),
onClosedList(1), onOpenList(2)
{
tiles = new Tile[width * height];
@@ -96,6 +97,7 @@ Map::Map():
Map::Map(int width, int height):
width(width), height(height),
+ tileWidth(32), tileHeight(32),
onClosedList(1), onOpenList(2)
{
tiles = new Tile[width * height];
@@ -227,6 +229,16 @@ int Map::getHeight()
return height;
}
+int Map::getTileWidth()
+{
+ return tileWidth;
+}
+
+int Map::getTileHeight()
+{
+ return tileHeight;
+}
+
PATH_NODE *Map::findPath(int startX, int startY, int destX, int destY)
{
// Declare open list, a list with open tiles sorted on F cost
diff --git a/src/map.h b/src/map.h
index 957b3b0a..4a131e37 100644
--- a/src/map.h
+++ b/src/map.h
@@ -143,12 +143,23 @@ class Map
int getHeight();
/**
+ * Returns the tile width of this map.
+ */
+ int getTileWidth();
+
+ /**
+ * Returns the tile height used by this map.
+ */
+ int getTileHeight();
+
+ /**
* Find a path from one location to the next.
*/
PATH_NODE *findPath(int startX, int startY, int destX, int destY);
private:
int width, height;
+ int tileWidth, tileHeight;
Tile *tiles;
// Pathfinding members
diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp
index c86f7fe4..31c2cb75 100644
--- a/src/resources/mapreader.cpp
+++ b/src/resources/mapreader.cpp
@@ -23,6 +23,8 @@
#include "mapreader.h"
#include "../log.h"
+#include "resourcemanager.h"
+#include "../graphic/spriteset.h"
#include <iostream>
@@ -91,15 +93,12 @@ Map* MapReader::readMap(xmlNodePtr node, const std::string &path)
for (node = node->xmlChildrenNode; node != NULL; node = node->next)
{
- if (xmlStrEqual(node->name, BAD_CAST "tileset")) {
- /*
- Tileset* set = readTileset(node, path);
- if (set) {
- map->tilesets.push_back(set);
- }
- */
+ if (xmlStrEqual(node->name, BAD_CAST "tileset"))
+ {
+ readTileset(node, path, map);
}
- else if (xmlStrEqual(node->name, BAD_CAST "layer")) {
+ else if (xmlStrEqual(node->name, BAD_CAST "layer"))
+ {
log("- Loading layer %d", layerNr);
readLayer(node, map, layerNr);
layerNr++;
@@ -111,18 +110,14 @@ Map* MapReader::readMap(xmlNodePtr node, const std::string &path)
void MapReader::readLayer(xmlNodePtr node, Map *map, int layer)
{
- // Ignored layer attributes
- //int w = getProperty(node, "width", 0); // Map width is used
- //int h = getProperty(node, "height", 0); // Map height is used
- //xmlChar *name = xmlGetProp(node, BAD_CAST "name");
-
node = node->xmlChildrenNode;
int h = map->getHeight();
int w = map->getWidth();
int x = 0;
int y = 0;
- // Load the tile data
+ // Load the tile data. Layers are assumed to be map size, with (0,0) as
+ // origin.
while (node != NULL)
{
if (xmlStrEqual(node->name, BAD_CAST "tile") && y < h)
@@ -142,44 +137,42 @@ void MapReader::readLayer(xmlNodePtr node, Map *map, int layer)
}
}
-/*
-Tileset* MapReader::readTileset(xmlNodePtr node, const std::string &path)
+void MapReader::readTileset(xmlNodePtr node, const std::string &path, Map *map)
{
- Tileset* set = NULL;
-
xmlChar* prop = xmlGetProp(node, BAD_CAST "source");
if (prop) {
- console.log(CON_LOG, CON_ALWAYS,
- "Warning: External tilesets not supported yet.");
+ log("Warning: External tilesets not supported yet.");
xmlFree(prop);
- return NULL;
+ return;
}
int firstgid = getProperty(node, "firstgid", 0);
- int tw = getProperty(node, "tilewidth", DEFAULT_TILE_WIDTH);
- int th = getProperty(node, "tileheight", DEFAULT_TILE_HEIGHT);
- int ts = getProperty(node, "spacing", 0);
- xmlChar* name = xmlGetProp(node, BAD_CAST "name");
+ int tw = getProperty(node, "tilewidth", map->getTileWidth());
+ int th = getProperty(node, "tileheight", map->getTileHeight());
node = node->xmlChildrenNode;
- while (node != NULL) {
- if (xmlStrEqual(node->name, BAD_CAST "image")) {
+ while (node != NULL)
+ {
+ if (xmlStrEqual(node->name, BAD_CAST "image"))
+ {
xmlChar* source = xmlGetProp(node, BAD_CAST "source");
- if (source) {
- char* srcname = get_filename((char*)source);
- BITMAP* tilebmp = module->findBitmap(srcname);
-
- if (tilebmp) {
- set = new Tileset();
- set->importTileBitmap(tilebmp, (char*)source, tw, th, ts);
- set->setFirstGid(firstgid);
- if (name) { set->setName((char*)name); }
+ if (source)
+ {
+ ResourceManager *resman = ResourceManager::getInstance();
+ Image* tilebmp = resman->getImage(path +
+ std::string((const char*)source));
+
+ if (tilebmp)
+ {
+ Spriteset *set = new Spriteset(tilebmp, tw, th);
+ //set->setFirstGid(firstgid);
+ // TODO: Like uhm, do something with this set!
xmlFree(source);
- } else {
- printf("Warning: Failed to load tileset %s (%s)\n",
- srcname, (char*)name);
+ }
+ else {
+ log("Warning: Failed to load tileset (%s)\n", source);
}
}
@@ -188,12 +181,7 @@ Tileset* MapReader::readTileset(xmlNodePtr node, const std::string &path)
node = node->next;
}
-
- xmlFree(name);
-
- return set;
}
-*/
int MapReader::getProperty(xmlNodePtr node, const char* name, int def)
{
diff --git a/src/resources/mapreader.h b/src/resources/mapreader.h
index cf34f96f..d58fdf90 100644
--- a/src/resources/mapreader.h
+++ b/src/resources/mapreader.h
@@ -47,10 +47,16 @@ class MapReader
private:
/**
- * Helper function that handler reading the map layers.
+ * Helper function that handles reading a map layer.
*/
static void readLayer(xmlNodePtr node, Map *map, int layer);
+ /**
+ * Helper function that handles reading a tile set.
+ */
+ static void readTileset(xmlNodePtr node, const std::string &path,
+ Map *map);
+
static int getProperty(xmlNodePtr node, const char* name, int def);
};