aboutsummaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/cheatMenu.cpp58
-rw-r--r--src/gui/cheatMenu.h29
2 files changed, 54 insertions, 33 deletions
diff --git a/src/gui/cheatMenu.cpp b/src/gui/cheatMenu.cpp
index 5707ed696..b22b8da30 100644
--- a/src/gui/cheatMenu.cpp
+++ b/src/gui/cheatMenu.cpp
@@ -15,15 +15,14 @@ GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-
+*/
+
#include "cheatMenu.h"
#include "script/scripting_client.h"
#include "client/client.h"
#include "client/fontengine.h"
-CheatMenu::CheatMenu(Client *client):
- m_client(client)
+CheatMenu::CheatMenu(Client *client) : m_client(client)
{
m_font = g_fontengine->getFont(FONT_SIZE_UNSPECIFIED, FM_Fallback);
@@ -38,7 +37,8 @@ CheatMenu::CheatMenu(Client *client):
m_fontsize.Y = MYMAX(m_fontsize.Y, 1);
}
-void CheatMenu::drawEntry(video::IVideoDriver* driver, std::string name, int number, bool selected, bool active, CheatMenuEntryType entry_type)
+void CheatMenu::drawEntry(video::IVideoDriver* driver, std::string name, int number,
+ bool selected, bool active, CheatMenuEntryType entry_type)
{
int x = m_gap, y = m_gap, width = m_entry_width, height = m_entry_height;
video::SColor *bgcolor = &m_bg_color, *fontcolor = &m_font_color;
@@ -47,7 +47,9 @@ void CheatMenu::drawEntry(video::IVideoDriver* driver, std::string name, int num
height = m_head_height;
} else {
bool is_category = entry_type == CHEAT_MENU_ENTRY_TYPE_CATEGORY;
- y += m_gap + m_head_height + (number + (is_category ? 0 : m_selected_category)) * (m_entry_height + m_gap);
+ y += m_gap + m_head_height +
+ (number + (is_category ? 0 : m_selected_category)) *
+ (m_entry_height + m_gap);
x += (is_category ? 0 : m_gap + m_entry_width);
if (active)
bgcolor = &m_active_bg_color;
@@ -56,9 +58,12 @@ void CheatMenu::drawEntry(video::IVideoDriver* driver, std::string name, int num
}
driver->draw2DRectangle(*bgcolor, core::rect<s32>(x, y, x + width, y + height));
if (selected)
- driver->draw2DRectangleOutline(core::rect<s32>(x - 1, y - 1, x + width, y + height), *fontcolor);
+ driver->draw2DRectangleOutline(
+ core::rect<s32>(x - 1, y - 1, x + width, y + height),
+ *fontcolor);
int fx = x + 5, fy = y + (height - m_fontsize.Y) / 2;
- core::rect<s32> fontbounds(fx, fy, fx + m_fontsize.X * name.size(), fy + m_fontsize.Y);
+ core::rect<s32> fontbounds(
+ fx, fy, fx + m_fontsize.X * name.size(), fy + m_fontsize.Y);
m_font->draw(name.c_str(), fontbounds, *fontcolor, false, false);
}
@@ -66,16 +71,22 @@ void CheatMenu::draw(video::IVideoDriver* driver, bool show_debug)
{
CHEAT_MENU_GET_SCRIPTPTR
- if (! show_debug)
- drawEntry(driver, "Dragonfireclient", 0, false, false, CHEAT_MENU_ENTRY_TYPE_HEAD);
+ if (!show_debug)
+ drawEntry(driver, "Dragonfireclient", 0, false, false,
+ CHEAT_MENU_ENTRY_TYPE_HEAD);
int category_count = 0;
- for (auto category = script->m_cheat_categories.begin(); category != script->m_cheat_categories.end(); category++) {
+ for (auto category = script->m_cheat_categories.begin();
+ category != script->m_cheat_categories.end(); category++) {
bool is_selected = category_count == m_selected_category;
- drawEntry(driver, (*category)->m_name, category_count, is_selected, false, CHEAT_MENU_ENTRY_TYPE_CATEGORY);
+ drawEntry(driver, (*category)->m_name, category_count, is_selected, false,
+ CHEAT_MENU_ENTRY_TYPE_CATEGORY);
if (is_selected && m_cheat_layer) {
int cheat_count = 0;
- for (auto cheat = (*category)->m_cheats.begin(); cheat != (*category)->m_cheats.end(); cheat++) {
- drawEntry(driver, (*cheat)->m_name, cheat_count, cheat_count == m_selected_cheat, (*cheat)->is_enabled());
+ for (auto cheat = (*category)->m_cheats.begin();
+ cheat != (*category)->m_cheats.end(); cheat++) {
+ drawEntry(driver, (*cheat)->m_name, cheat_count,
+ cheat_count == m_selected_cheat,
+ (*cheat)->is_enabled());
cheat_count++;
}
}
@@ -87,7 +98,10 @@ void CheatMenu::selectUp()
{
CHEAT_MENU_GET_SCRIPTPTR
- int max = (m_cheat_layer ? script->m_cheat_categories[m_selected_category]->m_cheats.size() : script->m_cheat_categories.size()) - 1;
+ int max = (m_cheat_layer ? script->m_cheat_categories[m_selected_category]
+ ->m_cheats.size()
+ : script->m_cheat_categories.size()) -
+ 1;
int *selected = m_cheat_layer ? &m_selected_cheat : &m_selected_category;
--*selected;
if (*selected < 0)
@@ -98,7 +112,10 @@ void CheatMenu::selectDown()
{
CHEAT_MENU_GET_SCRIPTPTR
- int max = (m_cheat_layer ? script->m_cheat_categories[m_selected_category]->m_cheats.size() : script->m_cheat_categories.size()) - 1;
+ int max = (m_cheat_layer ? script->m_cheat_categories[m_selected_category]
+ ->m_cheats.size()
+ : script->m_cheat_categories.size()) -
+ 1;
int *selected = m_cheat_layer ? &m_selected_cheat : &m_selected_category;
++*selected;
if (*selected > max)
@@ -114,16 +131,17 @@ void CheatMenu::selectRight()
}
void CheatMenu::selectLeft()
-{
- if (! m_cheat_layer)
+{
+ if (!m_cheat_layer)
return;
m_cheat_layer = false;
}
void CheatMenu::selectConfirm()
-{
+{
CHEAT_MENU_GET_SCRIPTPTR
if (m_cheat_layer)
- script->toggle_cheat(script->m_cheat_categories[m_selected_category]->m_cheats[m_selected_cheat]);
+ script->toggle_cheat(script->m_cheat_categories[m_selected_category]
+ ->m_cheats[m_selected_cheat]);
}
diff --git a/src/gui/cheatMenu.h b/src/gui/cheatMenu.h
index aaa433ceb..de369485c 100644
--- a/src/gui/cheatMenu.h
+++ b/src/gui/cheatMenu.h
@@ -15,14 +15,17 @@ GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
+*/
#pragma once
#include "irrlichttypes_extrabloated.h"
#include <string>
-#define CHEAT_MENU_GET_SCRIPTPTR ClientScripting *script = m_client->getScript(); if (! script || ! script->m_cheats_loaded) return;
+#define CHEAT_MENU_GET_SCRIPTPTR \
+ ClientScripting *script = m_client->getScript(); \
+ if (! script || ! script->m_cheats_loaded) \
+ return;
class Client;
@@ -31,42 +34,42 @@ typedef enum
CHEAT_MENU_ENTRY_TYPE_HEAD,
CHEAT_MENU_ENTRY_TYPE_CATEGORY,
CHEAT_MENU_ENTRY_TYPE_ENTRY,
-}
-CheatMenuEntryType;
+} CheatMenuEntryType;
class CheatMenu
{
public:
CheatMenu(Client* client);
-
+
void draw(video::IVideoDriver* driver, bool show_debug);
-
- void drawEntry(video::IVideoDriver* driver, std::string name, int number, bool selected, bool active, CheatMenuEntryType entry_type = CHEAT_MENU_ENTRY_TYPE_ENTRY);
-
+
+ void drawEntry(video::IVideoDriver* driver, std::string name, int number,
+ bool selected, bool active,
+ CheatMenuEntryType entry_type = CHEAT_MENU_ENTRY_TYPE_ENTRY);
+
void selectUp();
void selectDown();
void selectLeft();
void selectRight();
void selectConfirm();
-
+
private:
bool m_cheat_layer = false;
int m_selected_cheat = 0;
int m_selected_category = 0;
-
+
int m_head_height = 50;
int m_entry_height = 40;
int m_entry_width = 200;
int m_gap = 3;
-
+
video::SColor m_bg_color = video::SColor(192, 255, 145, 88);
video::SColor m_active_bg_color = video::SColor(192, 255, 87, 53);
video::SColor m_font_color = video::SColor(255, 0, 0, 0);
video::SColor m_selected_font_color = video::SColor(255, 255, 252, 88);
-
Client *m_client;
-
+
gui::IGUIFont *m_font = nullptr;
v2u32 m_fontsize;
};