X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;ds=sidebyside;f=src%2Fgui%2FcheatMenu.cpp;h=b7ce7d634028d7d92a82075bd6bff8bffa71f994;hb=6652d7ac2a463581aa53c1599b7b93762422ff0f;hp=440d3abf62ec99a357206294a923c411cc474cb3;hpb=1ef72ad9cccd3191b24c064aebe7849a5be6e2e7;p=dragonfireclient.git diff --git a/src/gui/cheatMenu.cpp b/src/gui/cheatMenu.cpp index 440d3abf6..b7ce7d634 100644 --- a/src/gui/cheatMenu.cpp +++ b/src/gui/cheatMenu.cpp @@ -1,31 +1,70 @@ /* 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. */ -#include "cheatMenu.h" #include "script/scripting_client.h" #include "client/client.h" #include "client/fontengine.h" +#include "cheatMenu.h" #include +FontMode CheatMenu::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; @@ -39,8 +78,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; @@ -72,7 +111,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( @@ -81,7 +120,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,19 +128,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) { + 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, - false, CHEAT_MENU_ENTRY_TYPE_CATEGORY); + 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++; } } @@ -169,4 +208,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