diff options
author | Stefan Dombrowski <stefan@uni-bonn.de> | 2011-05-25 19:33:31 +0200 |
---|---|---|
committer | Stefan Dombrowski <stefan@uni-bonn.de> | 2011-05-25 19:33:31 +0200 |
commit | 6d9936d160b197fe68c5bb21972b197fb1b64ba4 (patch) | |
tree | 6d432d9a359b63c281fca4fad8d98014d378364e /src/gui | |
parent | ed330a647d303152256f12917f18ece19332f683 (diff) | |
download | mana-6d9936d160b197fe68c5bb21972b197fb1b64ba4.tar.gz mana-6d9936d160b197fe68c5bb21972b197fb1b64ba4.tar.bz2 mana-6d9936d160b197fe68c5bb21972b197fb1b64ba4.tar.xz mana-6d9936d160b197fe68c5bb21972b197fb1b64ba4.zip |
Refining switches in the debug view
Reviewed-by: Bjorn
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/debugwindow.cpp | 128 | ||||
-rw-r--r-- | src/gui/viewport.cpp | 131 | ||||
-rw-r--r-- | src/gui/viewport.h | 2 |
3 files changed, 150 insertions, 111 deletions
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<Being*>(*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 { |