From 6d9936d160b197fe68c5bb21972b197fb1b64ba4 Mon Sep 17 00:00:00 2001 From: Stefan Dombrowski Date: Wed, 25 May 2011 19:33:31 +0200 Subject: Refining switches in the debug view Reviewed-by: Bjorn --- src/gui/debugwindow.cpp | 128 +++++++++++++++++++++++++++++----------------- src/gui/viewport.cpp | 131 +++++++++++++++++++++++++----------------------- src/gui/viewport.h | 2 +- src/map.cpp | 16 +++--- src/map.h | 16 +++--- 5 files changed, 169 insertions(+), 124 deletions(-) (limited to 'src') diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp index bd69437d..f1b24a49 100644 --- a/src/gui/debugwindow.cpp +++ b/src/gui/debugwindow.cpp @@ -29,6 +29,7 @@ #include "gui/setup.h" #include "gui/viewport.h" +#include "gui/widgets/checkbox.h" #include "gui/widgets/label.h" #include "gui/widgets/layout.h" #include "gui/widgets/layouthelper.h" @@ -129,79 +130,112 @@ class DebugSwitches : public Container, public gcn::ActionListener public: DebugSwitches() { - mapNormal = new RadioButton(_("Normal"), "mapdebug"); - mapDebug = new RadioButton(_("Debug"), "mapdebug"); - mapSpecial = new RadioButton(_("Special"), "mapdebug"); - mapSpecial2 = new RadioButton(_("Special 2"), "mapdebug"); - mapSpecial3 = new RadioButton(_("Special 3"), "mapdebug"); + Label *showLabel = new Label(_("Show:")); + mGrid = new CheckBox(_("Grid")); + mCollisionTiles = new CheckBox(_("Collision tiles")); + mBeingCollisionRadius = new CheckBox(_("Being collision radius")); + mBeingPosition = new CheckBox(_("Being positions")); + mBeingPath = new CheckBox(_("Being path")); + mMousePath = new CheckBox(_("Mouse path")); + + Label *specialsLabel = new Label(_("Specials:")); + mSpecialNormal = new RadioButton(_("Normal"), "mapdebug"); + mSpecial1 = new RadioButton(_("Special 1"), "mapdebug"); + mSpecial2 = new RadioButton(_("Special 2"), "mapdebug"); + mSpecial3 = new RadioButton(_("Special 3"), "mapdebug"); LayoutHelper h = (this); ContainerPlacer place = h.getPlacer(0, 0); - place(0, 0, mapNormal, 1); - place(0, 1, mapDebug, 1); - place(0, 2, mapSpecial, 1); - place(0, 3, mapSpecial2, 1); - place(0, 4, mapSpecial3, 1); + place(0, 0, showLabel, 1); + place(0, 1, mGrid, 1); + place(0, 2, mCollisionTiles, 1); + place(0, 3, mBeingCollisionRadius, 1); + place(0, 4, mBeingPosition, 1); + place(0, 5, mBeingPath, 1); + place(0, 6, mMousePath, 1); + place(1, 0, specialsLabel, 1); + place(1, 1, mSpecialNormal, 1); + place(1, 2, mSpecial1, 1); + place(1, 3, mSpecial2, 1); + place(1, 4, mSpecial3, 1); h.reflowLayout(0, 0); - mapNormal->setSelected(true); - - mapNormal->addActionListener(this); - mapDebug->addActionListener(this); - mapSpecial->addActionListener(this); - mapSpecial2->addActionListener(this); - mapSpecial3->addActionListener(this); + mSpecialNormal->setSelected(true); + + mGrid->addActionListener(this); + mCollisionTiles->addActionListener(this); + mBeingCollisionRadius->addActionListener(this); + mBeingPosition->addActionListener(this); + mBeingPath->addActionListener(this); + mMousePath->addActionListener(this); + mSpecialNormal->addActionListener(this); + mSpecial1->addActionListener(this); + mSpecial2->addActionListener(this); + mSpecial3->addActionListener(this); } void action(const gcn::ActionEvent &event) { - if (mapNormal->isSelected()) - viewport->setShowDebugPath(Map::MAP_NORMAL); - else if (mapDebug->isSelected()) - viewport->setShowDebugPath(Map::MAP_DEBUG); - else if (mapSpecial->isSelected()) - viewport->setShowDebugPath(Map::MAP_SPECIAL); - else if (mapSpecial2->isSelected()) - viewport->setShowDebugPath(Map::MAP_SPECIAL2); - else if (mapSpecial3->isSelected()) - viewport->setShowDebugPath(Map::MAP_SPECIAL3); + int flags = 0; + + if (mGrid->isSelected()) + flags |= Map::MAP_GRID; + if (mCollisionTiles->isSelected()) + flags |= Map::MAP_COLLISION_TILES; + if (mBeingCollisionRadius->isSelected()) + flags |= Map::MAP_BEING_COLLISION_RADIUS; + if (mBeingPosition->isSelected()) + flags |= Map::MAP_BEING_POSITION; + if (mBeingPath->isSelected()) + flags |= Map::MAP_BEING_PATH; + if (mMousePath->isSelected()) + flags |= Map::MAP_MOUSE_PATH; + if (mSpecial1->isSelected()) + flags |= Map::MAP_SPECIAL1; + if (mSpecial2->isSelected()) + flags |= Map::MAP_SPECIAL2; + if (mSpecial3->isSelected()) + flags |= Map::MAP_SPECIAL3; + + viewport->setShowDebugPath(flags); } private: - RadioButton *mapNormal; - RadioButton *mapDebug; - RadioButton *mapSpecial; - RadioButton *mapSpecial2; - RadioButton *mapSpecial3; + CheckBox *mGrid; + CheckBox *mCollisionTiles; + CheckBox *mBeingCollisionRadius; + CheckBox *mBeingPosition; + CheckBox *mBeingPath; + CheckBox *mMousePath; + RadioButton *mSpecialNormal; + RadioButton *mSpecial1; + RadioButton *mSpecial2; + RadioButton *mSpecial3; }; -DebugWindow::DebugWindow(): - Window(_("Debug")) +DebugWindow::DebugWindow() + : Window(_("Debug")) { setupWindow->registerWindowForReset(this); setResizable(true); setCloseButton(true); - setMinWidth(100); setMinHeight(100); - setDefaultSize(0, 120, 300, 180); - + setDefaultSize(0, 120, 300, 190); loadWindowState(); - TabbedArea *mTabs = new TabbedArea; - - place(0, 0, mTabs, 2, 2); - + TabbedArea *tabs = new TabbedArea; + place(0, 0, tabs, 2, 2); widgetResized(NULL); - Tab *tabInfo = new Tab(); - tabInfo->setCaption("Info"); - mTabs->addTab(tabInfo, new DebugInfo); + Tab *tabInfo = new Tab; + tabInfo->setCaption(_("Info")); + tabs->addTab(tabInfo, new DebugInfo); - Tab *tabSwitches = new Tab(); - tabSwitches->setCaption("Switches"); - mTabs->addTab(tabSwitches, new DebugSwitches); + Tab *tabSwitches = new Tab; + tabSwitches->setCaption(_("Switches")); + tabs->addTab(tabSwitches, new DebugSwitches); } diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 427b539f..e10a1a60 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -53,7 +53,7 @@ Viewport::Viewport(): mMouseY(0), mPixelViewX(0.0f), mPixelViewY(0.0f), - mShowDebugPath(false), + mDebugFlags(0), mPlayerFollowMouse(false), mLocalWalkTime(-1), mHoverBeing(0), @@ -199,14 +199,15 @@ void Viewport::draw(gcn::Graphics *gcnGraphics) { mMap->draw(graphics, (int) mPixelViewX, (int) mPixelViewY); - if (mShowDebugPath) + if (mDebugFlags) { - mMap->drawCollision(graphics, - (int) mPixelViewX, - (int) mPixelViewY, - mShowDebugPath); - if (mShowDebugPath == Map::MAP_DEBUG) - _drawDebugPath(graphics); + if (mDebugFlags & (Map::MAP_GRID | Map::MAP_COLLISION_TILES)) + { + mMap->drawCollision(graphics, (int) mPixelViewX, + (int) mPixelViewY, mDebugFlags); + } + + _drawDebugPath(graphics); } } @@ -293,83 +294,88 @@ void Viewport::_followMouse() void Viewport::_drawDebugPath(Graphics *graphics) { - // Get the current mouse position - SDL_GetMouseState(&mMouseX, &mMouseY); - - // Prepare the walkmask corresponding to the protocol - unsigned char walkMask = 0; - switch (Net::getNetworkType()) + if (mDebugFlags & Map::MAP_MOUSE_PATH) { - case ServerInfo::TMWATHENA: - walkMask = Map::BLOCKMASK_WALL | Map::BLOCKMASK_CHARACTER; - break; - case ServerInfo::MANASERV: - default: - walkMask = Map::BLOCKMASK_WALL; - break; - } - - static Path debugPath; - static Vector lastMouseDestination = Vector(0.0f, 0.0f); - Vector mouseDestination(mMouseX + (int) mPixelViewX, - mMouseY + (int) mPixelViewY); + // Get the current mouse position + SDL_GetMouseState(&mMouseX, &mMouseY); - if (mouseDestination.x != lastMouseDestination.x - || mouseDestination.y != lastMouseDestination.y) - { - const Vector &playerPos = player_node->getPosition(); - - // Adapt the path finding to the precision requested - if (Net::getPlayerHandler()->usePixelPrecision()) + // Prepare the walkmask corresponding to the protocol + unsigned char walkMask; + switch (Net::getNetworkType()) { - debugPath = mMap->findPixelPath((int) playerPos.x, - (int) playerPos.y, - mouseDestination.x, - mouseDestination.y, - player_node->getCollisionRadius(), - walkMask); + case ServerInfo::TMWATHENA: + walkMask = Map::BLOCKMASK_WALL | Map::BLOCKMASK_CHARACTER; + break; + case ServerInfo::MANASERV: + default: + walkMask = Map::BLOCKMASK_WALL; + break; } - else + + static Path debugPath; + static Vector lastMouseDestination = Vector(0.0f, 0.0f); + Vector mouseDestination(mMouseX + (int) mPixelViewX, + mMouseY + (int) mPixelViewY); + + if (mouseDestination.x != lastMouseDestination.x + || mouseDestination.y != lastMouseDestination.y) { - debugPath = mMap->findTilePath((int) playerPos.x, - (int) playerPos.y, - mouseDestination.x, - mouseDestination.y, - walkMask); + const Vector &playerPos = player_node->getPosition(); + + // Adapt the path finding to the precision requested + if (Net::getPlayerHandler()->usePixelPrecision()) + { + debugPath = mMap->findPixelPath((int) playerPos.x, + (int) playerPos.y, + mouseDestination.x, + mouseDestination.y, + player_node->getCollisionRadius(), + walkMask); + } + else + { + debugPath = mMap->findTilePath((int) playerPos.x, + (int) playerPos.y, + mouseDestination.x, + mouseDestination.y, + walkMask); + } + + lastMouseDestination = mouseDestination; } - lastMouseDestination = mouseDestination; + _drawPath(graphics, debugPath, gcn::Color(128, 0, 128, 150)); } - // We draw the path proposed by mouse - _drawPath(graphics, debugPath, gcn::Color(128, 0, 128, 150)); - // Draw the path debug information for every beings. ActorSpritesConstIterator it, it_end; const ActorSprites &actors = actorSpriteManager->getAll(); for (it = actors.begin(), it_end = actors.end() ; it != it_end; it++) { Being *being = dynamic_cast(*it); - if (being) - { - const Vector &beingPos = being->getPosition(); - int radius = being->getCollisionRadius(); - Path beingPath = being->getPath(); + if (!being) + continue; + + const Vector &beingPos = being->getPosition(); + graphics->setColor(gcn::Color(128, 128, 0, 150)); - // Draw being collision rectangle - graphics->setColor(gcn::Color(128, 128, 0, 150)); + if (mDebugFlags & Map::MAP_BEING_COLLISION_RADIUS) + { + const int radius = being->getCollisionRadius(); graphics->fillRectangle(gcn::Rectangle( (int) beingPos.x - (int) mPixelViewX - radius, (int) beingPos.y - (int) mPixelViewY - radius, radius * 2, radius * 2)); + } - _drawPath(graphics, - beingPath, - gcn::Color(0, 0, 255, 150)); + if (mDebugFlags & Map::MAP_BEING_PATH) + _drawPath(graphics, being->getPath(), gcn::Color(0, 0, 255, 150)); - // Draw also the absolute x, y position using a cross. + if (mDebugFlags & Map::MAP_BEING_POSITION) + { + // Draw the absolute x, y position using a cross. graphics->setColor(gcn::Color(0, 0, 255, 255)); graphics->drawLine((int) beingPos.x - (int) mPixelViewX - 4, (int) beingPos.y - (int) mPixelViewY - 4, @@ -379,7 +385,6 @@ void Viewport::_drawDebugPath(Graphics *graphics) (int) beingPos.y - (int) mPixelViewY - 4, (int) beingPos.x - (int) mPixelViewX - 4, (int) beingPos.y - (int) mPixelViewY + 4); - } } } @@ -585,7 +590,7 @@ void Viewport::updateCursorType() void Viewport::setShowDebugPath(int debugFlags) { - mShowDebugPath = debugFlags; + mDebugFlags = debugFlags; if (mMap) mMap->setDebugFlags(debugFlags); } diff --git a/src/gui/viewport.h b/src/gui/viewport.h index 0725e505..5814f08e 100644 --- a/src/gui/viewport.h +++ b/src/gui/viewport.h @@ -200,7 +200,7 @@ class Viewport : public WindowContainer, public gcn::MouseListener, int mMouseY; /**< Current mouse position in pixels. */ float mPixelViewX; /**< Current viewpoint in pixels. */ float mPixelViewY; /**< Current viewpoint in pixels. */ - int mShowDebugPath; /**< Show a path from player to pointer. */ + int mDebugFlags; /**< Flags for showing debug graphics. */ struct ShakeEffect { diff --git a/src/map.cpp b/src/map.cpp index 8b1d7b26..0ffdb2ac 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -153,7 +153,7 @@ void MapLayer::draw(Graphics *graphics, int startX, int startY, } } - if (debugFlags != Map::MAP_SPECIAL3) + if (!(debugFlags & Map::MAP_SPECIAL3)) { const int py0 = y32 + dy; @@ -164,8 +164,7 @@ void MapLayer::draw(Graphics *graphics, int startX, int startY, { const int px = (x * 32) + dx; const int py = py0 - img->getHeight(); - if ((debugFlags != Map::MAP_SPECIAL - && debugFlags != Map::MAP_SPECIAL2) + if (!(debugFlags & (Map::MAP_SPECIAL1 | Map::MAP_SPECIAL2)) || img->getHeight() <= 32) { int width = 0; @@ -217,7 +216,7 @@ Map::Map(int width, int height, int tileWidth, int tileHeight): mWidth(width), mHeight(height), mTileWidth(tileWidth), mTileHeight(tileHeight), mMaxTileHeight(height), - mDebugFlags(MAP_NORMAL), + mDebugFlags(0), mOnClosedList(1), mOnOpenList(2), mLastScrollX(0.0f), mLastScrollY(0.0f) { @@ -363,7 +362,7 @@ void Map::draw(Graphics *graphics, int scrollX, int scrollY) bool overFringe = false; - if (mDebugFlags == MAP_SPECIAL3) + if (mDebugFlags & MAP_SPECIAL3) { for (; layeri != mLayers.end(); ++layeri) { @@ -380,7 +379,7 @@ void Map::draw(Graphics *graphics, int scrollX, int scrollY) { for (; layeri != mLayers.end() && !overFringe; ++layeri) { - if ((*layeri)->isFringeLayer() && mDebugFlags == MAP_SPECIAL2) + if ((*layeri)->isFringeLayer() && (mDebugFlags & MAP_SPECIAL2)) overFringe = true; (*layeri)->draw(graphics, @@ -436,7 +435,7 @@ void Map::drawCollision(Graphics *graphics, int scrollX, int scrollY, { graphics->setColor(gcn::Color(0, 0, 0, 64)); - if (debugFlags < MAP_SPECIAL) + if (debugFlags & MAP_GRID) { graphics->drawRectangle(gcn::Rectangle( x * mTileWidth - scrollX, @@ -444,6 +443,9 @@ void Map::drawCollision(Graphics *graphics, int scrollX, int scrollY, 33, 33)); } + if (!(debugFlags & MAP_COLLISION_TILES)) + continue; + if (!getWalk(x, y, BLOCKMASK_WALL)) { graphics->setColor(gcn::Color(0, 0, 200, 64)); diff --git a/src/map.h b/src/map.h index 32644299..7dbc14af 100644 --- a/src/map.h +++ b/src/map.h @@ -156,13 +156,17 @@ class Map : public Properties BLOCKMASK_MONSTER = 0x02 // = bin 0000 0010 }; - enum DebugType + enum DebugFlags { - MAP_NORMAL = 0, - MAP_DEBUG = 1, - MAP_SPECIAL = 2, - MAP_SPECIAL2 = 3, - MAP_SPECIAL3 = 4 + MAP_GRID = 0x1, + MAP_COLLISION_TILES = 0x2, + MAP_BEING_COLLISION_RADIUS = 0x4, + MAP_BEING_POSITION = 0x8, + MAP_BEING_PATH = 0x10, + MAP_MOUSE_PATH = 0x20, + MAP_SPECIAL1 = 0x40, + MAP_SPECIAL2 = 0x80, + MAP_SPECIAL3 = 0x100 }; /** -- cgit v1.2.3-70-g09d2