From 130d476f6a00416809e0cf89adf5f7e8caa3df08 Mon Sep 17 00:00:00 2001 From: realOneplustwo Date: Tue, 20 Oct 2020 14:22:56 -0700 Subject: Changed Cheat Menu UI --- src/gui/cheatMenu.cpp | 64 +++++++++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 28 deletions(-) (limited to 'src/gui/cheatMenu.cpp') diff --git a/src/gui/cheatMenu.cpp b/src/gui/cheatMenu.cpp index f796fb0ba..c5f01b610 100644 --- a/src/gui/cheatMenu.cpp +++ b/src/gui/cheatMenu.cpp @@ -24,7 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., CheatMenu::CheatMenu(Client *client) : m_client(client) { - m_font = g_fontengine->getFont(FONT_SIZE_UNSPECIFIED, FM_Fallback); + m_font = g_fontengine->getFont(FONT_SIZE_UNSPECIFIED, FM_Mono); if (!m_font) { errorstream << "CheatMenu: Unable to load fallback font" << std::endl; @@ -38,7 +38,7 @@ CheatMenu::CheatMenu(Client *client) : m_client(client) } void CheatMenu::drawEntry(video::IVideoDriver *driver, std::string name, int number, - bool selected, bool active, CheatMenuEntryType entry_type) + bool selected, bool active, int number2, 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,10 +47,8 @@ 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); - x += (is_category ? 0 : m_gap + m_entry_width); + x += m_gap + (is_category? number : number2) * (m_entry_width + m_gap); + y += m_head_height + (is_category ? 0 : number + 1) * (m_entry_height + m_gap); if (active) bgcolor = &m_active_bg_color; if (selected) @@ -72,20 +70,20 @@ void CheatMenu::draw(video::IVideoDriver *driver, bool show_debug) CHEAT_MENU_GET_SCRIPTPTR if (!show_debug) - drawEntry(driver, "Dragonfireclient", 0, false, false, + drawEntry(driver, "Dragonfireclient", 0, false, false, 0, CHEAT_MENU_ENTRY_TYPE_HEAD); int category_count = 0; 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, + drawEntry(driver, (*category)->m_name, category_count, is_selected, false, category_count, 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_count == m_selected_cheat, category_count, (*cheat)->is_enabled()); cheat_count++; } @@ -94,47 +92,57 @@ void CheatMenu::draw(video::IVideoDriver *driver, bool show_debug) } } -void CheatMenu::selectUp() +void CheatMenu::selectLeft() { 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 *selected = m_cheat_layer ? &m_selected_cheat : &m_selected_category; + int max = script->m_cheat_categories.size() - 1; + int *selected = &m_selected_category; --*selected; if (*selected < 0) *selected = max; } -void CheatMenu::selectDown() +void CheatMenu::selectRight() { 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 *selected = m_cheat_layer ? &m_selected_cheat : &m_selected_category; + int max = script->m_cheat_categories.size() - 1; + int *selected = &m_selected_category; ++*selected; if (*selected > max) *selected = 0; } -void CheatMenu::selectRight() +void CheatMenu::selectDown() { - if (m_cheat_layer) - return; + CHEAT_MENU_GET_SCRIPTPTR + m_cheat_layer = true; - m_selected_cheat = 0; + + int max = script->m_cheat_categories[m_selected_category]->m_cheats.size(); + int *selected = &m_selected_cheat; + ++*selected; + if (*selected > max) { + *selected = 1; + } } -void CheatMenu::selectLeft() +void CheatMenu::selectUp() { - if (!m_cheat_layer) + if (!m_cheat_layer) { return; - m_cheat_layer = false; + } + + CHEAT_MENU_GET_SCRIPTPTR + + int *selected = &m_selected_cheat; + --*selected; + + if (*selected < 0) { + m_cheat_layer = false; + *selected = 1; + } } void CheatMenu::selectConfirm() -- cgit v1.2.3 From f605308ee3da739aee2a690c870c5b567d11d859 Mon Sep 17 00:00:00 2001 From: Josiah VanderZee Date: Tue, 20 Oct 2020 18:28:25 -0500 Subject: Improve drawEntry. --- src/gui/cheatMenu.cpp | 49 ++++++++++++++++++++++++++++++++----------------- src/gui/cheatMenu.h | 10 ++++++---- 2 files changed, 38 insertions(+), 21 deletions(-) (limited to 'src/gui/cheatMenu.cpp') diff --git a/src/gui/cheatMenu.cpp b/src/gui/cheatMenu.cpp index c5f01b610..d72a14480 100644 --- a/src/gui/cheatMenu.cpp +++ b/src/gui/cheatMenu.cpp @@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "script/scripting_client.h" #include "client/client.h" #include "client/fontengine.h" +#include CheatMenu::CheatMenu(Client *client) : m_client(client) { @@ -37,25 +38,39 @@ CheatMenu::CheatMenu(Client *client) : m_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, int number2, CheatMenuEntryType entry_type) +void CheatMenu::drawEntry(video::IVideoDriver *driver, std::string name, + std::size_t column_align_index, std::size_t cheat_entry_index, + bool is_selected, bool is_enabled, 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; - if (entry_type == CHEAT_MENU_ENTRY_TYPE_HEAD) { + + // Align with correct column. + x += m_gap + column_align_index * (m_entry_width + m_gap); + + if (is_selected) + fontcolor = &m_selected_font_color; + if (is_enabled) bgcolor = &m_active_bg_color; + + switch (entry_type) + { + case CHEAT_MENU_ENTRY_TYPE_HEAD: height = m_head_height; - } else { - bool is_category = entry_type == CHEAT_MENU_ENTRY_TYPE_CATEGORY; - x += m_gap + (is_category? number : number2) * (m_entry_width + m_gap); - y += m_head_height + (is_category ? 0 : number + 1) * (m_entry_height + m_gap); - if (active) - bgcolor = &m_active_bg_color; - if (selected) - fontcolor = &m_selected_font_color; + break; + case CHEAT_MENU_ENTRY_TYPE_CATEGORY: + y += m_head_height + m_gap; + break; + case CHEAT_MENU_ENTRY_TYPE_ENTRY: + y += m_head_height + (cheat_entry_index + 1) * (m_entry_height + m_gap); + break; + default: + // TODO log an error or something. + break; } + driver->draw2DRectangle(*bgcolor, core::rect(x, y, x + width, y + height)); - if (selected) + if (is_selected) driver->draw2DRectangleOutline( core::rect(x - 1, y - 1, x + width, y + height), *fontcolor); @@ -70,20 +85,20 @@ void CheatMenu::draw(video::IVideoDriver *driver, bool show_debug) CHEAT_MENU_GET_SCRIPTPTR if (!show_debug) - drawEntry(driver, "Dragonfireclient", 0, false, false, 0, + drawEntry(driver, "Dragonfireclient", 0, 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++) { bool is_selected = category_count == m_selected_category; - drawEntry(driver, (*category)->m_name, category_count, is_selected, false, category_count, - CHEAT_MENU_ENTRY_TYPE_CATEGORY); + drawEntry(driver, (*category)->m_name, category_count, 0, 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, category_count, + drawEntry(driver, (*cheat)->m_name, category_count, cheat_count, + cheat_count == m_selected_cheat, (*cheat)->is_enabled()); cheat_count++; } diff --git a/src/gui/cheatMenu.h b/src/gui/cheatMenu.h index 61637b1d4..e7fb4dc93 100644 --- a/src/gui/cheatMenu.h +++ b/src/gui/cheatMenu.h @@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #pragma once #include "irrlichttypes_extrabloated.h" +#include #include #define CHEAT_MENU_GET_SCRIPTPTR \ @@ -29,12 +30,12 @@ with this program; if not, write to the Free Software Foundation, Inc., class Client; -typedef enum +enum CheatMenuEntryType { CHEAT_MENU_ENTRY_TYPE_HEAD, CHEAT_MENU_ENTRY_TYPE_CATEGORY, CHEAT_MENU_ENTRY_TYPE_ENTRY, -} CheatMenuEntryType; +}; class CheatMenu { @@ -43,8 +44,9 @@ public: void draw(video::IVideoDriver *driver, bool show_debug); - void drawEntry(video::IVideoDriver *driver, std::string name, int number, - bool selected, bool active, int category_count, + void drawEntry(video::IVideoDriver *driver, std::string name, + std::size_t column_align_index, std::size_t cheat_entry_index, + bool is_selected, bool is_enabled, CheatMenuEntryType entry_type = CHEAT_MENU_ENTRY_TYPE_ENTRY); void selectUp(); -- cgit v1.2.3 From b211e90ffcabefc3c75cf00ee053970951f01488 Mon Sep 17 00:00:00 2001 From: Josiah Date: Wed, 21 Oct 2020 09:16:32 -0500 Subject: Prepare cheatMenu::draw function for easier UI changes. --- src/gui/cheatMenu.cpp | 19 +++++++++---------- src/gui/cheatMenu.h | 5 +++++ 2 files changed, 14 insertions(+), 10 deletions(-) (limited to 'src/gui/cheatMenu.cpp') diff --git a/src/gui/cheatMenu.cpp b/src/gui/cheatMenu.cpp index d72a14480..9225414a2 100644 --- a/src/gui/cheatMenu.cpp +++ b/src/gui/cheatMenu.cpp @@ -81,25 +81,24 @@ void CheatMenu::drawEntry(video::IVideoDriver *driver, std::string name, } void CheatMenu::draw(video::IVideoDriver *driver, bool show_debug) -{ - CHEAT_MENU_GET_SCRIPTPTR + + ClientScripting *script{ getScript() }; + if (!script || !script->m_cheats_loaded) if (!show_debug) drawEntry(driver, "Dragonfireclient", 0, 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 (const auto &menu_item : m_cheat_categories) { bool is_selected = category_count == m_selected_category; - drawEntry(driver, (*category)->m_name, category_count, 0, is_selected, + drawEntry(driver, menu_item.m_name, category_count, 0, 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, category_count, cheat_count, + for (const auto &sub_menu_item : menu_item.m_cheats) { + drawEntry(driver, sub_menu_item.m_name, category_count, cheat_count, cheat_count == m_selected_cheat, - (*cheat)->is_enabled()); + sub_menu_item.is_enabled()); cheat_count++; } } @@ -132,7 +131,7 @@ void CheatMenu::selectRight() void CheatMenu::selectDown() { CHEAT_MENU_GET_SCRIPTPTR - + m_cheat_layer = true; int max = script->m_cheat_categories[m_selected_category]->m_cheats.size(); diff --git a/src/gui/cheatMenu.h b/src/gui/cheatMenu.h index e7fb4dc93..e42edfbb0 100644 --- a/src/gui/cheatMenu.h +++ b/src/gui/cheatMenu.h @@ -42,6 +42,11 @@ class CheatMenu public: CheatMenu(Client *client); + Client* getScript() + { + return m_client->getScript(); + } + void draw(video::IVideoDriver *driver, bool show_debug); void drawEntry(video::IVideoDriver *driver, std::string name, -- cgit v1.2.3 From 5862410083da5da02a8bc29a76e7bb1f4977e331 Mon Sep 17 00:00:00 2001 From: Josiah Date: Wed, 21 Oct 2020 09:27:39 -0500 Subject: Add missing return. --- src/gui/cheatMenu.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/gui/cheatMenu.cpp') diff --git a/src/gui/cheatMenu.cpp b/src/gui/cheatMenu.cpp index 9225414a2..d5e93038c 100644 --- a/src/gui/cheatMenu.cpp +++ b/src/gui/cheatMenu.cpp @@ -84,10 +84,13 @@ void CheatMenu::draw(video::IVideoDriver *driver, bool show_debug) ClientScripting *script{ getScript() }; if (!script || !script->m_cheats_loaded) + return; + // Draw menu header if debug info is not being drawn. if (!show_debug) drawEntry(driver, "Dragonfireclient", 0, 0, false, false, CHEAT_MENU_ENTRY_TYPE_HEAD); + int category_count = 0; for (const auto &menu_item : m_cheat_categories) { bool is_selected = category_count == m_selected_category; -- cgit v1.2.3 From 1ef72ad9cccd3191b24c064aebe7849a5be6e2e7 Mon Sep 17 00:00:00 2001 From: Josiah Date: Wed, 21 Oct 2020 09:57:08 -0500 Subject: Fix indentation style. --- src/gui/cheatMenu.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gui/cheatMenu.cpp') diff --git a/src/gui/cheatMenu.cpp b/src/gui/cheatMenu.cpp index d5e93038c..440d3abf6 100644 --- a/src/gui/cheatMenu.cpp +++ b/src/gui/cheatMenu.cpp @@ -86,7 +86,7 @@ void CheatMenu::draw(video::IVideoDriver *driver, bool show_debug) if (!script || !script->m_cheats_loaded) return; - // Draw menu header if debug info is not being drawn. + // Draw menu header if debug info is not being drawn. if (!show_debug) drawEntry(driver, "Dragonfireclient", 0, 0, false, false, CHEAT_MENU_ENTRY_TYPE_HEAD); -- cgit v1.2.3 From aea9b36ef70dd35e8dfa370043ae5e3f3c751cb4 Mon Sep 17 00:00:00 2001 From: realOneplustwo Date: Wed, 21 Oct 2020 09:43:26 -0700 Subject: Improved Colours --- src/gui/cheatMenu.cpp | 7 ++----- src/gui/cheatMenu.h | 15 ++++++--------- 2 files changed, 8 insertions(+), 14 deletions(-) (limited to 'src/gui/cheatMenu.cpp') diff --git a/src/gui/cheatMenu.cpp b/src/gui/cheatMenu.cpp index d72a14480..548ddea73 100644 --- a/src/gui/cheatMenu.cpp +++ b/src/gui/cheatMenu.cpp @@ -1,17 +1,14 @@ /* Dragonfire Copyright (C) 2020 Elias Fleckenstein - This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 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. @@ -72,7 +69,7 @@ void CheatMenu::drawEntry(video::IVideoDriver *driver, std::string name, driver->draw2DRectangle(*bgcolor, core::rect(x, y, x + width, y + height)); if (is_selected) driver->draw2DRectangleOutline( - core::rect(x - 1, y - 1, x + width, y + height), + core::rect(x - 2, y - 2, x + width + 1, y + height + 1), *fontcolor); int fx = x + 5, fy = y + (height - m_fontsize.Y) / 2; core::rect fontbounds( @@ -167,4 +164,4 @@ void CheatMenu::selectConfirm() if (m_cheat_layer) script->toggle_cheat(script->m_cheat_categories[m_selected_category] ->m_cheats[m_selected_cheat]); -} +} \ No newline at end of file diff --git a/src/gui/cheatMenu.h b/src/gui/cheatMenu.h index e7fb4dc93..4ffaa177d 100644 --- a/src/gui/cheatMenu.h +++ b/src/gui/cheatMenu.h @@ -1,17 +1,14 @@ /* Dragonfire Copyright (C) 2020 Elias Fleckenstein - This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 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. @@ -62,16 +59,16 @@ private: int m_head_height = 20; int m_entry_height = 20; - int m_entry_width = 200; + int m_entry_width = 150; int m_gap = 3; - video::SColor m_bg_color = video::SColor(39, 38, 51, 173); - video::SColor m_active_bg_color = video::SColor(45, 45, 107, 100); - video::SColor m_font_color = video::SColor(195, 195, 195, 0); - video::SColor m_selected_font_color = video::SColor(255, 255, 252, 88); + video::SColor m_bg_color = video::SColor(173, 45, 45, 68); + video::SColor m_active_bg_color = video::SColor(210, 0, 0, 0); + video::SColor m_font_color = video::SColor(195, 255, 255, 255); + video::SColor m_selected_font_color = video::SColor(235, 255, 255, 255); Client *m_client; gui::IGUIFont *m_font = nullptr; v2u32 m_fontsize; -}; +}; \ No newline at end of file -- cgit v1.2.3 From 7aff09ab232704b0abc8d95d107c07f67f581e2e Mon Sep 17 00:00:00 2001 From: Josiah Date: Wed, 21 Oct 2020 11:47:38 -0500 Subject: Fix overindent! --- src/gui/cheatMenu.cpp | 12 ++++++------ src/gui/cheatMenu.h | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'src/gui/cheatMenu.cpp') diff --git a/src/gui/cheatMenu.cpp b/src/gui/cheatMenu.cpp index 440d3abf6..0afe1051a 100644 --- a/src/gui/cheatMenu.cpp +++ b/src/gui/cheatMenu.cpp @@ -39,8 +39,8 @@ CheatMenu::CheatMenu(Client *client) : m_client(client) } void CheatMenu::drawEntry(video::IVideoDriver *driver, std::string name, - std::size_t column_align_index, std::size_t cheat_entry_index, - bool is_selected, bool is_enabled, CheatMenuEntryType entry_type) + std::size_t column_align_index, std::size_t cheat_entry_index, + bool is_selected, bool is_enabled, 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; @@ -89,19 +89,19 @@ void CheatMenu::draw(video::IVideoDriver *driver, bool show_debug) // Draw menu header if debug info is not being drawn. if (!show_debug) drawEntry(driver, "Dragonfireclient", 0, 0, false, false, - CHEAT_MENU_ENTRY_TYPE_HEAD); + CHEAT_MENU_ENTRY_TYPE_HEAD); int category_count = 0; for (const auto &menu_item : m_cheat_categories) { bool is_selected = category_count == m_selected_category; drawEntry(driver, menu_item.m_name, category_count, 0, is_selected, - false, CHEAT_MENU_ENTRY_TYPE_CATEGORY); + false, CHEAT_MENU_ENTRY_TYPE_CATEGORY); if (is_selected && m_cheat_layer) { int cheat_count = 0; for (const auto &sub_menu_item : menu_item.m_cheats) { drawEntry(driver, sub_menu_item.m_name, category_count, cheat_count, - cheat_count == m_selected_cheat, - sub_menu_item.is_enabled()); + cheat_count == m_selected_cheat, + sub_menu_item.is_enabled()); cheat_count++; } } diff --git a/src/gui/cheatMenu.h b/src/gui/cheatMenu.h index e42edfbb0..5aba306e0 100644 --- a/src/gui/cheatMenu.h +++ b/src/gui/cheatMenu.h @@ -50,9 +50,9 @@ public: void draw(video::IVideoDriver *driver, bool show_debug); void drawEntry(video::IVideoDriver *driver, std::string name, - std::size_t column_align_index, std::size_t cheat_entry_index, - bool is_selected, bool is_enabled, - CheatMenuEntryType entry_type = CHEAT_MENU_ENTRY_TYPE_ENTRY); + std::size_t column_align_index, std::size_t cheat_entry_index, + bool is_selected, bool is_enabled, + CheatMenuEntryType entry_type = CHEAT_MENU_ENTRY_TYPE_ENTRY); void selectUp(); void selectDown(); -- cgit v1.2.3 From f236476af96cfc468d0a76a2f8215f566d1b7de1 Mon Sep 17 00:00:00 2001 From: Josiah VanderZee Date: Wed, 21 Oct 2020 18:53:38 -0500 Subject: Fix errors in cheatMenu. --- src/gui/cheatMenu.cpp | 16 ++++++++-------- src/gui/cheatMenu.h | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) (limited to 'src/gui/cheatMenu.cpp') diff --git a/src/gui/cheatMenu.cpp b/src/gui/cheatMenu.cpp index e37f584fd..9949becc3 100644 --- a/src/gui/cheatMenu.cpp +++ b/src/gui/cheatMenu.cpp @@ -78,7 +78,7 @@ void CheatMenu::drawEntry(video::IVideoDriver *driver, std::string name, } void CheatMenu::draw(video::IVideoDriver *driver, bool show_debug) - +{ ClientScripting *script{ getScript() }; if (!script || !script->m_cheats_loaded) return; @@ -89,16 +89,16 @@ void CheatMenu::draw(video::IVideoDriver *driver, bool show_debug) CHEAT_MENU_ENTRY_TYPE_HEAD); int category_count = 0; - for (const auto &menu_item : m_cheat_categories) { + for (const auto &menu_item : script->m_cheat_categories) { bool is_selected = category_count == m_selected_category; - drawEntry(driver, menu_item.m_name, category_count, 0, is_selected, + drawEntry(driver, menu_item->m_name, category_count, 0, is_selected, false, CHEAT_MENU_ENTRY_TYPE_CATEGORY); if (is_selected && m_cheat_layer) { int cheat_count = 0; - for (const auto &sub_menu_item : menu_item.m_cheats) { - drawEntry(driver, sub_menu_item.m_name, category_count, cheat_count, - cheat_count == m_selected_cheat, - sub_menu_item.is_enabled()); + for (const auto &sub_menu_item : menu_item->m_cheats) { + drawEntry(driver, sub_menu_item->m_name, category_count, + cheat_count, cheat_count == m_selected_cheat, + sub_menu_item->is_enabled()); cheat_count++; } } @@ -166,4 +166,4 @@ void CheatMenu::selectConfirm() if (m_cheat_layer) script->toggle_cheat(script->m_cheat_categories[m_selected_category] ->m_cheats[m_selected_cheat]); -} \ No newline at end of file +} diff --git a/src/gui/cheatMenu.h b/src/gui/cheatMenu.h index 018b63ae0..dfe92798b 100644 --- a/src/gui/cheatMenu.h +++ b/src/gui/cheatMenu.h @@ -16,7 +16,9 @@ with this program; if not, write to the Free Software Foundation, Inc., #pragma once +#include "client/client.h" #include "irrlichttypes_extrabloated.h" +#include "script/scripting_client.h" #include #include @@ -25,8 +27,6 @@ with this program; if not, write to the Free Software Foundation, Inc., if (!script || !script->m_cheats_loaded) \ return; -class Client; - enum CheatMenuEntryType { CHEAT_MENU_ENTRY_TYPE_HEAD, @@ -39,7 +39,7 @@ class CheatMenu public: CheatMenu(Client *client); - Client* getScript() + ClientScripting *getScript() { return m_client->getScript(); } @@ -76,4 +76,4 @@ private: gui::IGUIFont *m_font = nullptr; v2u32 m_fontsize; -}; \ No newline at end of file +}; -- cgit v1.2.3 From b29d6bc196b3a6bafa1b200e8944cf277b0bc9c1 Mon Sep 17 00:00:00 2001 From: realOneplustwo Date: Wed, 21 Oct 2020 17:49:17 -0700 Subject: Make cheat menu color and font configurable via settings --- builtin/settingtypes.txt | 25 +++++++++++++++++++++++++ src/defaultsettings.cpp | 7 +++++++ src/gui/cheatMenu.cpp | 45 ++++++++++++++++++++++++++++++++++++++++++++- src/gui/cheatMenu.h | 3 +++ 4 files changed, 79 insertions(+), 1 deletion(-) (limited to 'src/gui/cheatMenu.cpp') diff --git a/builtin/settingtypes.txt b/builtin/settingtypes.txt index f30a16789..ebd0ad621 100644 --- a/builtin/settingtypes.txt +++ b/builtin/settingtypes.txt @@ -2298,3 +2298,28 @@ autotnt (PlaceOnTop) bool false replace (Replace) bool false crystal_pvp (CrystalPvP) bool false + +[Cheat Menu] + +# Font to use for cheat menu +cheat_menu_font (MenuFont) enum FM_Standard, FM_Mono, FM_Fallback, FM_Simple, FM_SimpleMono, FM_MaxMode, FM_Unspecified + +# (RGB value) +m_bg_color (Cell background color) v3f 45 45 68 + +m_bg_color_alpha (Cell background color alpha) int 173 + +# (RGB value) +m_active_bg_color (Active cell background color) v3f 0 0 0 + +m_active_bg_color_alpha (Active cell background color alpha) int 210 + +# (RGB value) +m_font_color (Font color) v3f 255 255 255 + +m_font_color_alpha (Font color alpha) int 195 + +# (RGB value) +m_selected_font_color (Selected font color) v3f 255 255 255 + +m_selected_font_color_alpha (Selected font color alpha) int 235 \ No newline at end of file diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index 2899f2509..525f94678 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -63,6 +63,13 @@ void set_default_settings(Settings *settings) settings->setDefault("max_out_chat_queue_size", "20"); settings->setDefault("pause_on_lost_focus", "false"); settings->setDefault("enable_register_confirmation", "true"); + + // Cheat Menu + settings->setDefault("cheat_menu_font", "FM_Mono"); + settings->setDefault("m_bg_color_alpha", "173"); + settings->setDefault("m_active_bg_color_alpha", "210"); + settings->setDefault("m_font_color_alpha", "195"); + settings->setDefault("m_selected_font_color_alpha", "235"); // Cheats settings->setDefault("xray", "false"); diff --git a/src/gui/cheatMenu.cpp b/src/gui/cheatMenu.cpp index 548ddea73..7839caaad 100644 --- a/src/gui/cheatMenu.cpp +++ b/src/gui/cheatMenu.cpp @@ -18,11 +18,54 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "script/scripting_client.h" #include "client/client.h" #include "client/fontengine.h" +#include "settings.h" #include +FontMode fontStringToEnum(std::string str) { + if (str == "FM_Standard") + return FM_Standard; + else if (str == "FM_Mono") + return FM_Mono; + else if (str == "FM_Fallback") + return FM_Fallback; + else if (str == "FM_Simple") + return FM_Simple; + else if (str == "FM_SimpleMono") + return FM_SimpleMono; + else if (str == "FM_MaxMode") + return FM_MaxMode; + else if (str == "FM_Unspecified") + return FM_Unspecified; + else + return FM_Standard; +} + CheatMenu::CheatMenu(Client *client) : m_client(client) { - m_font = g_fontengine->getFont(FONT_SIZE_UNSPECIFIED, FM_Mono); + FontMode fontMode = fontStringToEnum(g_settings->get("cheat_menu_font")); + irr::core::vector3df bg_color; + irr::core::vector3df active_bg_color; + irr::core::vector3df font_color; + irr::core::vector3df selected_font_color; + + g_settings->getV3FNoEx("m_bg_color", bg_color); + g_settings->getV3FNoEx("m_active_bg_color", active_bg_color); + g_settings->getV3FNoEx("m_font_color", font_color); + g_settings->getV3FNoEx("m_selected_font_color", selected_font_color); + + m_bg_color = video::SColor(g_settings->getU32("m_bg_color_alpha"), + bg_color.X, bg_color.Y, bg_color.Z); + + m_active_bg_color = video::SColor(g_settings->getU32("m_active_bg_color_alpha"), + active_bg_color.X, active_bg_color.Y, active_bg_color.Z); + + m_font_color = video::SColor(g_settings->getU32("m_font_color_alpha"), + font_color.X, font_color.Y, font_color.Z); + + m_selected_font_color = video::SColor(g_settings->getU32("m_selected_font_color_alpha"), + selected_font_color.X, selected_font_color.Y, selected_font_color.Z); + + m_font = g_fontengine->getFont(FONT_SIZE_UNSPECIFIED, fontMode); if (!m_font) { errorstream << "CheatMenu: Unable to load fallback font" << std::endl; diff --git a/src/gui/cheatMenu.h b/src/gui/cheatMenu.h index 4ffaa177d..350bf9ac3 100644 --- a/src/gui/cheatMenu.h +++ b/src/gui/cheatMenu.h @@ -17,6 +17,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #pragma once #include "irrlichttypes_extrabloated.h" +#include "settings.h" #include #include @@ -67,6 +68,8 @@ private: video::SColor m_font_color = video::SColor(195, 255, 255, 255); video::SColor m_selected_font_color = video::SColor(235, 255, 255, 255); + FontMode fontStringToEnum(std::string str); + Client *m_client; gui::IGUIFont *m_font = nullptr; -- cgit v1.2.3 From 3bdb843f2c11dffd9db6f899c0ba77f52deac290 Mon Sep 17 00:00:00 2001 From: realOneplustwo Date: Wed, 21 Oct 2020 18:00:43 -0700 Subject: Make cheat menu color and font configurable via settings --- src/gui/cheatMenu.cpp | 44 +++++++++++++++++++++++++++++++++++++++++++- src/gui/cheatMenu.h | 2 ++ 2 files changed, 45 insertions(+), 1 deletion(-) (limited to 'src/gui/cheatMenu.cpp') diff --git a/src/gui/cheatMenu.cpp b/src/gui/cheatMenu.cpp index 3f44267e1..27a243357 100644 --- a/src/gui/cheatMenu.cpp +++ b/src/gui/cheatMenu.cpp @@ -20,9 +20,51 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "client/fontengine.h" #include +FontMode fontStringToEnum(std::string str) { + if (str == "FM_Standard") + return FM_Standard; + else if (str == "FM_Mono") + return FM_Mono; + else if (str == "FM_Fallback") + return FM_Fallback; + else if (str == "FM_Simple") + return FM_Simple; + else if (str == "FM_SimpleMono") + return FM_SimpleMono; + else if (str == "FM_MaxMode") + return FM_MaxMode; + else if (str == "FM_Unspecified") + return FM_Unspecified; + else + return FM_Standard; +} + CheatMenu::CheatMenu(Client *client) : m_client(client) { - m_font = g_fontengine->getFont(FONT_SIZE_UNSPECIFIED, FM_Mono); + FontMode fontMode = fontStringToEnum(g_settings->get("cheat_menu_font")); + irr::core::vector3df bg_color; + irr::core::vector3df active_bg_color; + irr::core::vector3df font_color; + irr::core::vector3df selected_font_color; + + g_settings->getV3FNoEx("m_bg_color", bg_color); + g_settings->getV3FNoEx("m_active_bg_color", active_bg_color); + g_settings->getV3FNoEx("m_font_color", font_color); + g_settings->getV3FNoEx("m_selected_font_color", selected_font_color); + + m_bg_color = video::SColor(g_settings->getU32("m_bg_color_alpha"), + bg_color.X, bg_color.Y, bg_color.Z); + + m_active_bg_color = video::SColor(g_settings->getU32("m_active_bg_color_alpha"), + active_bg_color.X, active_bg_color.Y, active_bg_color.Z); + + m_font_color = video::SColor(g_settings->getU32("m_font_color_alpha"), + font_color.X, font_color.Y, font_color.Z); + + m_selected_font_color = video::SColor(g_settings->getU32("m_selected_font_color_alpha"), + selected_font_color.X, selected_font_color.Y, selected_font_color.Z); + + m_font = g_fontengine->getFont(FONT_SIZE_UNSPECIFIED, fontMode); if (!m_font) { errorstream << "CheatMenu: Unable to load fallback font" << std::endl; diff --git a/src/gui/cheatMenu.h b/src/gui/cheatMenu.h index 6ff8d67c6..c25af5ed2 100644 --- a/src/gui/cheatMenu.h +++ b/src/gui/cheatMenu.h @@ -72,6 +72,8 @@ private: video::SColor m_font_color = video::SColor(195, 255, 255, 255); video::SColor m_selected_font_color = video::SColor(235, 255, 255, 255); + FontMode fontStringToEnum(std::string str); + Client *m_client; gui::IGUIFont *m_font = nullptr; -- cgit v1.2.3 From 62cf9b46600ff1f1f2733401f0a670d703fee136 Mon Sep 17 00:00:00 2001 From: realOneplustwo Date: Wed, 21 Oct 2020 19:33:31 -0700 Subject: Fix compile error --- src/gui/cheatMenu.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/gui/cheatMenu.cpp') diff --git a/src/gui/cheatMenu.cpp b/src/gui/cheatMenu.cpp index 27a243357..b7ce7d634 100644 --- a/src/gui/cheatMenu.cpp +++ b/src/gui/cheatMenu.cpp @@ -14,13 +14,13 @@ 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" +#include "cheatMenu.h" #include -FontMode fontStringToEnum(std::string str) { +FontMode CheatMenu::fontStringToEnum(std::string str) { if (str == "FM_Standard") return FM_Standard; else if (str == "FM_Mono") -- cgit v1.2.3 From 3c57074150167eecd5589507de8230261799cfa5 Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein <54945686+EliasFleckenstein03@users.noreply.github.com> Date: Wed, 4 Nov 2020 14:33:27 +0100 Subject: Re-add empty lines --- src/gui/cheatMenu.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/gui/cheatMenu.cpp') diff --git a/src/gui/cheatMenu.cpp b/src/gui/cheatMenu.cpp index b7ce7d634..f4f85c7fe 100644 --- a/src/gui/cheatMenu.cpp +++ b/src/gui/cheatMenu.cpp @@ -1,14 +1,17 @@ /* Dragonfire Copyright (C) 2020 Elias Fleckenstein + This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 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. @@ -208,4 +211,4 @@ void CheatMenu::selectConfirm() if (m_cheat_layer) script->toggle_cheat(script->m_cheat_categories[m_selected_category] ->m_cheats[m_selected_cheat]); -} \ No newline at end of file +} -- cgit v1.2.3