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 +++++++++---------- 1 file changed, 9 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(); -- 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 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