From d283db70abe904fddd8aefbd52b35d6e066dd98f Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Tue, 14 Jun 2005 14:24:28 +0000 Subject: Added background to minimap. Only used in Tonori Desert map for now, and its style is up for discussion. --- ChangeLog | 1 + src/being.cpp | 8 +++++- src/engine.cpp | 42 ++++++++++++++++++++-------- src/engine.h | 34 ++++++++++++++++++++--- src/game.cpp | 28 ++++++++++--------- src/game.h | 2 ++ src/gui/button.cpp | 3 +- src/gui/gui.cpp | 6 ++-- src/gui/minimap.cpp | 80 +++++++++++++++++++++++++++++++++++++++++++++-------- src/gui/minimap.h | 17 +++++++++++- src/gui/window.cpp | 1 + src/main.cpp | 1 - src/main.h | 1 - 13 files changed, 177 insertions(+), 47 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5af93464..90d0989c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,6 @@ 0.0.14 (3 July 2005) - Added support for map properties (to be used for music and minimap settings) +- Added background image to minimap 0.0.13 (5 June 2005) - Added ability to trade items and money diff --git a/src/being.cpp b/src/being.cpp index 80de74e1..7ed73b8f 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -203,7 +203,13 @@ void Being::setDestination(int destX, int destY) { this->destX = destX; this->destY = destY; - setPath(tiledMap->findPath(x, y, destX, destY)); + + Map *map = engine->getCurrentMap(); + + if (map != NULL) + { + setPath(map->findPath(x, y, destX, destY)); + } } void Being::setHairColor(int color) diff --git a/src/engine.cpp b/src/engine.cpp index 9c39b3aa..bca79219 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -137,7 +137,8 @@ int get_y_offset(Being *being) return offset; } -Engine::Engine() +Engine::Engine(): + mCurrentMap(NULL) { // Initializes GUI debugInfo = new gcn::Label(); @@ -265,6 +266,17 @@ Engine::~Engine() delete itemset; } +Map *Engine::getCurrentMap() +{ + return mCurrentMap; +} + +void Engine::setCurrentMap(Map *newMap) +{ + mCurrentMap = newMap; + minimap->setMap(mCurrentMap); +} + void Engine::logic() { // Update beings @@ -309,9 +321,10 @@ void Engine::draw() frame++; // Draw tiles below nodes - if (tiledMap) { - tiledMap->draw(guiGraphics, map_x, map_y, 0); - tiledMap->draw(guiGraphics, map_x, map_y, 1); + if (mCurrentMap != NULL) + { + mCurrentMap->draw(guiGraphics, map_x, map_y, 0); + mCurrentMap->draw(guiGraphics, map_x, map_y, 1); } // Draw items @@ -439,15 +452,16 @@ void Engine::draw() } // Draw tiles below nodes - if (tiledMap) { - tiledMap->draw(guiGraphics, map_x, map_y, 2); + if (mCurrentMap != NULL) + { + mCurrentMap->draw(guiGraphics, map_x, map_y, 2); } // Find a path from the player to the mouse, and draw it. This is for debug // purposes. - if (displayPathToMouse) + if (displayPathToMouse && mCurrentMap != NULL) { - std::list debugPath = tiledMap->findPath( + std::list debugPath = mCurrentMap->findPath( player_node->x, player_node->y, mouseX / 32 + camera_x, mouseY / 32 + camera_y); @@ -461,7 +475,7 @@ void Engine::draw() guiGraphics->setColor(gcn::Color(255, 0, 0)); guiGraphics->fillRectangle(gcn::Rectangle(squareX, squareY, 8, 8)); - MetaTile *tile = tiledMap->getMetaTile(node.x, node.y); + MetaTile *tile = mCurrentMap->getMetaTile(node.x, node.y); std::stringstream cost; cost << tile->Gcost; @@ -492,8 +506,14 @@ void Engine::draw() std::stringstream debugStream; debugStream << "[" << fps << " fps] " << (mouseX / 32 + camera_x) << ", " << (mouseY / 32 + camera_y); - debugStream << " [music: " << tiledMap->getProperty("music") << "]"; - debugStream << " [minimap: " << tiledMap->getProperty("minimap") << "]"; + + if (mCurrentMap != NULL) + { + debugStream + << " [music: " << mCurrentMap->getProperty("music") << "]" + << " [minimap: " << mCurrentMap->getProperty("minimap") << "]"; + } + debugInfo->setCaption(debugStream.str()); debugInfo->adjustSize(); } diff --git a/src/engine.h b/src/engine.h index 48015b89..f5b24869 100644 --- a/src/engine.h +++ b/src/engine.h @@ -81,16 +81,42 @@ char get_y_offset(char, char); /** * Game engine that does the main drawing. */ -class Engine { - private: - Spriteset *emotionset, *npcset, *weaponset, *itemset; - +class Engine +{ public: + /** + * Constructor. + */ Engine(); + + /** + * Destructor. + */ ~Engine(); + /** + * Returns the currently active map. + */ + Map *getCurrentMap(); + + /** + * Sets the currently active map. + */ + void setCurrentMap(Map *newMap); + + /** + * Performs engine logic. + */ void logic(); + + /** + * Draws everything on the screen. + */ void draw(); + + private: + Spriteset *emotionset, *npcset, *weaponset, *itemset; + Map *mCurrentMap; }; #endif diff --git a/src/game.cpp b/src/game.cpp index 7e7cf4e3..f6a2133f 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -55,7 +55,8 @@ int fps = 0, frame = 0, current_npc = 0; bool displayPathToMouse = false; int startX = 0, startY = 0; int gameTime = 0; -Being* autoTarget = NULL; +Being *autoTarget = NULL; +Engine *engine = NULL; OkDialog *deathNotice = NULL; ConfirmDialog *exitConfirm = NULL; @@ -122,8 +123,8 @@ int get_elapsed_time(int start_time) void game() { + engine = new Engine(); do_init(); - Engine *engine = new Engine(); gameTime = tick_time; @@ -165,20 +166,17 @@ void do_init() std::string path(map_path); std::string pathDir = path.substr(0, path.rfind(".")); - // Try .tmx map file - pathDir.insert(pathDir.size(), ".tmx"); - tiledMap = MapReader::readMap(pathDir); + // Try .tmx.gz map file + pathDir.insert(pathDir.size(), ".tmx.gz"); + Map *tiledMap = MapReader::readMap(pathDir); if (!tiledMap) { - // Try .tmx.gz map file - pathDir.insert(pathDir.size(), ".gz"); - tiledMap = MapReader::readMap(pathDir); - - if (!tiledMap) - { - logger->error("Could not find map file!"); - } + logger->error("Could not find map file!"); + } + else + { + engine->setCurrentMap(tiledMap); } // Start playing background music @@ -529,6 +527,8 @@ void do_input() Direction = SW; } + Map *tiledMap = engine->getCurrentMap(); + // Prevent skipping corners over colliding tiles if (xDirection != 0 && tiledMap->tileCollides(x + xDirection, y)) { xDirection = 0; @@ -587,6 +587,7 @@ void do_parse() Being *being = NULL; FloorItem *floorItem = NULL; int len, n_items; + Map *tiledMap = engine->getCurrentMap(); // We need at least 2 bytes to identify a packet if (in_size >= 2) { @@ -1011,6 +1012,7 @@ void do_parse() WFIFOW(0) = net_w_value(0x007d); WFIFOSET(2); while (out_size > 0) flush(); + engine->setCurrentMap(tiledMap); } else { logger->error("Could not find map file"); diff --git a/src/game.h b/src/game.h index 54d11b01..c70ec094 100644 --- a/src/game.h +++ b/src/game.h @@ -26,6 +26,7 @@ #include "main.h" #include "being.h" +#include "engine.h" #include "./gui/gui.h" #include "./gui/skill.h" #include @@ -64,6 +65,7 @@ extern int server_tick; extern bool displayPathToMouse; extern int startX, startY; extern Being* autoTarget; +extern Engine *engine; /** * Main game loop diff --git a/src/gui/button.cpp b/src/gui/button.cpp index c95ab968..10fbe625 100644 --- a/src/gui/button.cpp +++ b/src/gui/button.cpp @@ -85,7 +85,8 @@ Button::~Button() } } -void Button::draw(gcn::Graphics* graphics) { +void Button::draw(gcn::Graphics* graphics) +{ int mode; if (!isEnabled()) { diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 73e77073..b6562b77 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -28,6 +28,7 @@ #include "../engine.h" #include "../net/protocol.h" #include "../main.h" +#include "../game.h" // Guichan stuff Gui *gui; @@ -126,6 +127,7 @@ void Gui::mousePress(int mx, int my, int button) if (player_node && player_node->action != DEAD && current_npc == 0 && button == gcn::MouseInput::LEFT) { + Map *tiledMap = engine->getCurrentMap(); int tilex = mx / 32 + camera_x; int tiley = my / 32 + camera_y; @@ -133,7 +135,7 @@ void Gui::mousePress(int mx, int my, int button) walk(tilex, tiley, 0); player_node->setDestination(tilex, tiley); } - - autoTarget = 0; + + autoTarget = NULL; } } diff --git a/src/gui/minimap.cpp b/src/gui/minimap.cpp index 719266d1..8941a390 100644 --- a/src/gui/minimap.cpp +++ b/src/gui/minimap.cpp @@ -23,29 +23,85 @@ #include "minimap.h" #include "../being.h" +#include "../resources/resourcemanager.h" +#include "../graphics.h" -Minimap::Minimap() +Minimap::Minimap(): + Window("Map"), + mMapImage(NULL) { setContentSize(100, 100); setPosition(20, 20); } +Minimap::~Minimap() +{ + if (mMapImage) + { + mMapImage->decRef(); + } +} + +void Minimap::setMap(Map *map) +{ + if (mMapImage) + { + mMapImage->decRef(); + } + + if (map->hasProperty("minimap")) + { + ResourceManager *resman = ResourceManager::getInstance(); + mMapImage = resman->getImage(map->getProperty("minimap"), IMG_ALPHA); + mMapImage->setAlpha(0.7); + } + else + { + mMapImage = NULL; + } +} + void Minimap::draw(gcn::Graphics *graphics) { - int x, y; + Window::draw(graphics); + int x, y; getAbsolutePosition(x, y); - // Transparent background - graphics->setColor(gcn::Color(52, 149, 210, 120)); - graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight())); + if (mMapImage != NULL) + { + mMapImage->draw(screen, x + getPadding(), y + getTitleBarHeight()); + } + + std::list::iterator bi; - // Black border - graphics->setColor(gcn::Color(0, 0, 0)); - graphics->drawRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight())); + for (bi = beings.begin(); bi != beings.end(); bi++) + { + Being *being = (*bi); - // Player dot - graphics->setColor(gcn::Color(209, 52, 61)); - graphics->fillRectangle(gcn::Rectangle(player_node->x / 2, - player_node->y / 2, 3, 3)); + if (being == player_node) + { + // Player dot + graphics->setColor(gcn::Color(209, 52, 61)); + graphics->fillRectangle(gcn::Rectangle( + being->x / 2 + getPadding() - 1, + being->y / 2 + getTitleBarHeight() - 1, 3, 3)); + } + else if (being->isPlayer()) + { + // Other player dot + graphics->setColor(gcn::Color(61, 52, 209)); + graphics->fillRectangle(gcn::Rectangle( + being->x / 2 + getPadding(), + being->y / 2 + getTitleBarHeight(), 1, 1)); + } + else if (being->isMonster()) + { + // Enemy dot + graphics->setColor(gcn::Color(209, 52, 61)); + graphics->fillRectangle(gcn::Rectangle( + being->x / 2 + getPadding(), + being->y / 2 + getTitleBarHeight(), 1, 1)); + } + } } diff --git a/src/gui/minimap.h b/src/gui/minimap.h index 8e75a78c..3710332c 100644 --- a/src/gui/minimap.h +++ b/src/gui/minimap.h @@ -24,6 +24,7 @@ #ifndef _TMW_MINIMAP_H #define _TMW_MINIMAP_H +#include "../map.h" #include "gui.h" #include "window.h" @@ -32,17 +33,31 @@ * * \ingroup Interface */ -class Minimap : public Window { +class Minimap : public Window +{ public: /** * Constructor. */ Minimap(); + /** + * Destructor. + */ + ~Minimap(); + + /** + * Sets the map that should be displayed. + */ + void setMap(Map *map); + /** * Draws the minimap. */ void draw(gcn::Graphics *graphics); + + private: + Image *mMapImage; }; #endif diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 95965960..c5ef7a54 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -64,6 +64,7 @@ Window::Window(const std::string& caption, bool modal, Window *parent): setBorderSize(0); setPadding(3); + setTitleBarHeight(20); // Add chrome chrome = new gcn::Container(); diff --git a/src/main.cpp b/src/main.cpp index 5b8f4244..f9441fbd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -58,7 +58,6 @@ PLAYER_INFO *char_info = new PLAYER_INFO; Spriteset *hairset = NULL, *playerset = NULL; Image *login_wallpaper = NULL; Graphics *graphics; -Map *tiledMap; char username[LEN_USERNAME]; char password[LEN_PASSWORD]; diff --git a/src/main.h b/src/main.h index bac5ce43..36deae9d 100644 --- a/src/main.h +++ b/src/main.h @@ -106,7 +106,6 @@ extern PLAYER_INFO *char_info; extern unsigned char state; extern Configuration config; extern Sound sound; -extern Map *tiledMap; extern Logger *logger; extern int screenW, screenH, bitDepth, displayFlags; extern bool useOpenGL; -- cgit v1.2.3-60-g2f50