Mana
Loading...
Searching...
No Matches
debugwindow.cpp
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2004-2009 The Mana World Development Team
4 * Copyright (C) 2009-2012 The Mana Developers
5 *
6 * This file is part of The Mana Client.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#include "gui/debugwindow.h"
23
24#include "client.h"
25#include "game.h"
26#include "particle.h"
27#include "map.h"
28#include "gui.h"
29
30#include "gui/setup.h"
31#include "gui/viewport.h"
32
34#include "gui/widgets/label.h"
35#include "gui/widgets/layout.h"
38#include "gui/widgets/tab.h"
40
41#include "resources/image.h"
42
43#include "utils/gettext.h"
44#include "utils/stringutils.h"
45
46
47class DebugInfo : public Container
48{
49public:
51 {
52#ifdef USE_OPENGL
53 if (Image::getLoadAsOpenGL())
54 {
55 mFPSText = _("%d FPS (OpenGL)");
56 }
57 else
58#endif
59 {
60 mFPSText = _("%d FPS");
61 }
62
63 mFPSLabel = new Label(std::string());
64 mMusicFileLabel = new Label(std::string());
65 mMapLabel = new Label(std::string());
66 mMinimapLabel = new Label(std::string());
67 mTileMouseLabel = new Label(std::string());
68 mParticleCountLabel = new Label(std::string());
69
70 LayoutHelper h(this);
72
73 place(0, 0, mFPSLabel, 1);
74 place(0, 1, mMusicFileLabel, 1);
75 place(0, 2, mMapLabel, 1);
76 place(0, 3, mMinimapLabel, 1);
77 place(0, 4, mTileMouseLabel, 1);
78 place(0, 5, mParticleCountLabel, 1);
79
80 h.reflowLayout(0, 0);
81 }
82
83 void logic() override
84 {
85 if (!isVisible())
86 return;
87
88 mFPSLabel->setCaption(strprintf(mFPSText.c_str(), fps));
89
90 if (const Map *map = Game::instance()->getCurrentMap())
91 {
92 // Get the current mouse position
93 const int mouseTileX = (viewport->getMouseX() +
94 viewport->getCameraX()) / map->getTileWidth();
95 const int mouseTileY = (viewport->getMouseY() +
96 viewport->getCameraY()) / map->getTileHeight();
97 mTileMouseLabel->setCaption(strprintf(_("Cursor: (%d, %d)"),
98 mouseTileX, mouseTileY));
99
100 mMusicFileLabel->setCaption(strprintf(
101 _("Music: %s"), map->getProperty("music").c_str()));
102 mMinimapLabel->setCaption(strprintf(_("Minimap: %s"),
103 map->getProperty("minimap").c_str()));
104 mMapLabel->setCaption(strprintf(_("Map: %s"),
105 map->getProperty("_filename").c_str()));
106 }
107
108 mParticleCountLabel->setCaption(strprintf(_("Particle count: %d"),
110
111 mFPSLabel->adjustSize();
112 mMusicFileLabel->adjustSize();
113 mMapLabel->adjustSize();
114 mMinimapLabel->adjustSize();
115 mTileMouseLabel->adjustSize();
116 mParticleCountLabel->adjustSize();
117 }
118
119private:
120 std::string mFPSText;
127};
128
129class DebugSwitches : public Container, public gcn::ActionListener
130{
131public:
133 {
134 auto *showLabel = new Label(_("Show:"));
135 mGrid = new CheckBox(_("Grid"));
136 mCollisionTiles = new CheckBox(_("Collision tiles"));
137 mBeingCollisionRadius = new CheckBox(_("Being collision radius"));
138 mBeingPosition = new CheckBox(_("Being positions"));
139 mBeingPath = new CheckBox(_("Being path"));
140 mMousePath = new CheckBox(_("Mouse path"));
141 mBeingIds = new CheckBox(_("Being Ids"));
142 mGuiDebug = new CheckBox(_("GUI debug"));
143
144 auto *specialsLabel = new Label(_("Specials:"));
145 mSpecialNormal = new RadioButton(_("Normal"), "mapdebug");
146 mSpecial1 = new RadioButton(_("Special 1"), "mapdebug");
147 mSpecial2 = new RadioButton(_("Special 2"), "mapdebug");
148 mSpecial3 = new RadioButton(_("Special 3"), "mapdebug");
149
150 LayoutHelper h(this);
152
153 place(0, 0, showLabel, 1);
154 place(0, 1, mGrid, 1);
155 place(0, 2, mCollisionTiles, 1);
157 place(0, 4, mBeingPosition, 1);
158 place(0, 5, mBeingPath, 1);
159 place(0, 6, mMousePath, 1);
160 place(0, 7, mBeingIds, 1);
161 place(0, 8, mGuiDebug, 1);
162 place(1, 0, specialsLabel, 1);
163 place(1, 1, mSpecialNormal, 1);
164 place(1, 2, mSpecial1, 1);
165 place(1, 3, mSpecial2, 1);
166 place(1, 4, mSpecial3, 1);
167
168 h.reflowLayout(0, 0);
169
170 mSpecialNormal->setSelected(true);
171
172 mGrid->addActionListener(this);
173 mCollisionTiles->addActionListener(this);
174 mBeingCollisionRadius->addActionListener(this);
175 mBeingPosition->addActionListener(this);
176 mBeingPath->addActionListener(this);
177 mMousePath->addActionListener(this);
178 mBeingIds->addActionListener(this);
179 mGuiDebug->addActionListener(this);
180 mSpecialNormal->addActionListener(this);
181 mSpecial1->addActionListener(this);
182 mSpecial2->addActionListener(this);
183 mSpecial3->addActionListener(this);
184 }
185
186 void action(const gcn::ActionEvent &event) override
187 {
188 int flags = 0;
189
190 if (mGrid->isSelected())
191 flags |= Map::DEBUG_GRID;
192 if (mCollisionTiles->isSelected())
194 if (mBeingCollisionRadius->isSelected())
196 if (mBeingPosition->isSelected())
198 if (mBeingPath->isSelected())
199 flags |= Map::DEBUG_BEING_PATH;
200 if (mMousePath->isSelected())
201 flags |= Map::DEBUG_MOUSE_PATH;
202 if (mBeingIds->isSelected())
203 flags |= Map::DEBUG_BEING_IDS;
204 if (mSpecial1->isSelected())
205 flags |= Map::DEBUG_SPECIAL1;
206 if (mSpecial2->isSelected())
207 flags |= Map::DEBUG_SPECIAL2;
208 if (mSpecial3->isSelected())
209 flags |= Map::DEBUG_SPECIAL3;
210
211 viewport->setDebugFlags(flags);
212
213 Gui::debugDraw = mGuiDebug->isSelected();
214 }
215
216private:
229};
230
232 : Window(_("Debug"))
233{
235
236 setWindowName("Debug");
237 setResizable(true);
238 setCloseButton(true);
239 setMinWidth(100);
240 setMinHeight(100);
241 setDefaultSize(0, 120, 300, 190);
242
243 auto *tabs = new TabbedArea;
244 place(0, 0, tabs, 2, 2);
246
247 mInfoTab = std::make_unique<Tab>();
248 mInfoTab->setCaption(_("Info"));
249 mInfoWidget = std::make_unique<DebugInfo>();
250 tabs->addTab(mInfoTab.get(), mInfoWidget.get());
251
252 mSwitchesTab = std::make_unique<Tab>();
253 mSwitchesTab->setCaption(_("Switches"));
254 mSwitchesWidget = std::make_unique<DebugSwitches>();
255 tabs->addTab(mSwitchesTab.get(), mSwitchesWidget.get());
256}
257
258DebugWindow::~DebugWindow() = default;
Check box widget.
Definition checkbox.h:32
This class is a helper for adding widgets to nested tables in a window.
Definition layout.h:34
A widget container.
Definition container.h:41
LayoutCell & place(int x, int y, gcn::Widget *wg, int w=1, int h=1)
Adds a widget to the container and sets it at given cell.
Definition container.cpp:46
Label * mTileMouseLabel
Label * mMinimapLabel
Label * mMapLabel
void logic() override
Label * mParticleCountLabel
Label * mMusicFileLabel
Label * mFPSLabel
std::string mFPSText
CheckBox * mGuiDebug
void action(const gcn::ActionEvent &event) override
CheckBox * mMousePath
RadioButton * mSpecialNormal
RadioButton * mSpecial1
CheckBox * mBeingPath
CheckBox * mGrid
CheckBox * mCollisionTiles
RadioButton * mSpecial3
CheckBox * mBeingPosition
CheckBox * mBeingCollisionRadius
RadioButton * mSpecial2
CheckBox * mBeingIds
~DebugWindow() override
std::unique_ptr< gcn::Widget > mInfoWidget
Definition debugwindow.h:44
std::unique_ptr< Tab > mSwitchesTab
Definition debugwindow.h:43
std::unique_ptr< gcn::Widget > mSwitchesWidget
Definition debugwindow.h:45
std::unique_ptr< Tab > mInfoTab
Definition debugwindow.h:42
static Game * instance()
Provides access to the game instance.
Definition game.h:53
static bool debugDraw
Definition gui.h:141
Label widget.
Definition label.h:34
A helper class for adding a layout to a Guichan container widget.
ContainerPlacer getPlacer(int x, int y)
Returns a proxy for adding widgets in an inner table of the layout.
void reflowLayout(int w=0, int h=0)
Computes the position of the widgets according to the current layout.
A tile map.
Definition map.h:147
@ DEBUG_BEING_IDS
Definition map.h:175
@ DEBUG_BEING_COLLISION_RADIUS
Definition map.h:171
@ DEBUG_MOUSE_PATH
Definition map.h:174
@ DEBUG_SPECIAL3
Definition map.h:178
@ DEBUG_BEING_POSITION
Definition map.h:172
@ DEBUG_GRID
Definition map.h:169
@ DEBUG_SPECIAL2
Definition map.h:177
@ DEBUG_COLLISION_TILES
Definition map.h:170
@ DEBUG_SPECIAL1
Definition map.h:176
@ DEBUG_BEING_PATH
Definition map.h:173
static int particleCount
Current number of particles.
Definition particle.h:56
Guichan based RadioButton with custom look.
Definition radiobutton.h:30
void registerWindowForReset(Window *window)
Enables the Reset Windows button.
Definition setup.cpp:108
A tabbed area, the same as the guichan tabbed area in 0.8, but extended.
Definition tabbedarea.h:40
int getMouseY() const
Returns mouse y in pixels.
Definition viewport.h:136
int getMouseX() const
Returns mouse x in pixels.
Definition viewport.h:131
int getCameraY() const
Returns camera y offset in pixels.
Definition viewport.h:126
void setDebugFlags(int debugFlags)
Sets which debug flags (see Map::DebugFlags) should be enabled.
Definition viewport.cpp:593
int getCameraX() const
Returns camera x offset in pixels.
Definition viewport.h:121
A window.
Definition window.h:59
void setMinHeight(int height)
Sets the minimum height of the window.
Definition window.cpp:197
void setWindowName(const std::string &name)
Sets the name of the window.
Definition window.h:272
void setResizable(bool resize)
Sets whether or not the window can be resized.
Definition window.cpp:212
LayoutCell & place(int x, int y, gcn::Widget *, int w=1, int h=1)
Adds a widget to the window and sets it at given cell.
Definition window.cpp:737
void setCloseButton(bool flag)
Sets whether or not the window has a close button.
Definition window.cpp:262
void setDefaultSize()
Set the default win pos and size to the current ones.
Definition window.cpp:545
void loadWindowState()
Reads the position (and the size for resizable windows) in the configuration based on the given strin...
Definition window.cpp:467
void setMinWidth(int width)
Sets the minimum width of the window.
Definition window.cpp:192
volatile int fps
Frames counted in the last second.
Definition client.cpp:111
Viewport * viewport
Viewport on the map.
Definition game.cpp:115
#define _(s)
Definition gettext.h:38
Setup * setupWindow
Definition setup.cpp:120
std::string strprintf(char const *format,...)
A safe version of sprintf that returns a std::string of the result.