Make cheat menu color and font configurable via settings
This commit is contained in:
commit
19143bedf4
@ -18,54 +18,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include "script/scripting_client.h"
|
#include "script/scripting_client.h"
|
||||||
#include "client/client.h"
|
#include "client/client.h"
|
||||||
#include "client/fontengine.h"
|
#include "client/fontengine.h"
|
||||||
#include "settings.h"
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
|
||||||
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)
|
CheatMenu::CheatMenu(Client *client) : m_client(client)
|
||||||
{
|
{
|
||||||
FontMode fontMode = fontStringToEnum(g_settings->get("cheat_menu_font"));
|
m_font = g_fontengine->getFont(FONT_SIZE_UNSPECIFIED, FM_Mono);
|
||||||
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) {
|
if (!m_font) {
|
||||||
errorstream << "CheatMenu: Unable to load fallback font" << std::endl;
|
errorstream << "CheatMenu: Unable to load fallback font" << std::endl;
|
||||||
@ -79,8 +36,8 @@ CheatMenu::CheatMenu(Client *client) : m_client(client)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CheatMenu::drawEntry(video::IVideoDriver *driver, std::string name,
|
void CheatMenu::drawEntry(video::IVideoDriver *driver, std::string name,
|
||||||
std::size_t column_align_index, std::size_t cheat_entry_index,
|
std::size_t column_align_index, std::size_t cheat_entry_index,
|
||||||
bool is_selected, bool is_enabled, CheatMenuEntryType entry_type)
|
bool is_selected, bool is_enabled, CheatMenuEntryType entry_type)
|
||||||
{
|
{
|
||||||
int x = m_gap, y = m_gap, width = m_entry_width, height = m_entry_height;
|
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;
|
video::SColor *bgcolor = &m_bg_color, *fontcolor = &m_font_color;
|
||||||
@ -122,24 +79,26 @@ void CheatMenu::drawEntry(video::IVideoDriver *driver, std::string name,
|
|||||||
|
|
||||||
void CheatMenu::draw(video::IVideoDriver *driver, bool show_debug)
|
void CheatMenu::draw(video::IVideoDriver *driver, bool show_debug)
|
||||||
{
|
{
|
||||||
CHEAT_MENU_GET_SCRIPTPTR
|
ClientScripting *script{ getScript() };
|
||||||
|
if (!script || !script->m_cheats_loaded)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Draw menu header if debug info is not being drawn.
|
||||||
if (!show_debug)
|
if (!show_debug)
|
||||||
drawEntry(driver, "Dragonfireclient", 0, 0, false, false,
|
drawEntry(driver, "Dragonfireclient", 0, 0, false, false,
|
||||||
CHEAT_MENU_ENTRY_TYPE_HEAD);
|
CHEAT_MENU_ENTRY_TYPE_HEAD);
|
||||||
|
|
||||||
int category_count = 0;
|
int category_count = 0;
|
||||||
for (auto category = script->m_cheat_categories.begin();
|
for (const auto &menu_item : script->m_cheat_categories) {
|
||||||
category != script->m_cheat_categories.end(); category++) {
|
|
||||||
bool is_selected = category_count == m_selected_category;
|
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);
|
false, CHEAT_MENU_ENTRY_TYPE_CATEGORY);
|
||||||
if (is_selected && m_cheat_layer) {
|
if (is_selected && m_cheat_layer) {
|
||||||
int cheat_count = 0;
|
int cheat_count = 0;
|
||||||
for (auto cheat = (*category)->m_cheats.begin();
|
for (const auto &sub_menu_item : menu_item->m_cheats) {
|
||||||
cheat != (*category)->m_cheats.end(); cheat++) {
|
drawEntry(driver, sub_menu_item->m_name, category_count,
|
||||||
drawEntry(driver, (*cheat)->m_name, category_count, cheat_count,
|
cheat_count, cheat_count == m_selected_cheat,
|
||||||
cheat_count == m_selected_cheat,
|
sub_menu_item->is_enabled());
|
||||||
(*cheat)->is_enabled());
|
|
||||||
cheat_count++;
|
cheat_count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -172,7 +131,7 @@ void CheatMenu::selectRight()
|
|||||||
void CheatMenu::selectDown()
|
void CheatMenu::selectDown()
|
||||||
{
|
{
|
||||||
CHEAT_MENU_GET_SCRIPTPTR
|
CHEAT_MENU_GET_SCRIPTPTR
|
||||||
|
|
||||||
m_cheat_layer = true;
|
m_cheat_layer = true;
|
||||||
|
|
||||||
int max = script->m_cheat_categories[m_selected_category]->m_cheats.size();
|
int max = script->m_cheat_categories[m_selected_category]->m_cheats.size();
|
||||||
|
@ -16,8 +16,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "client/client.h"
|
||||||
#include "irrlichttypes_extrabloated.h"
|
#include "irrlichttypes_extrabloated.h"
|
||||||
#include "settings.h"
|
#include "script/scripting_client.h"
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
@ -26,8 +27,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
if (!script || !script->m_cheats_loaded) \
|
if (!script || !script->m_cheats_loaded) \
|
||||||
return;
|
return;
|
||||||
|
|
||||||
class Client;
|
|
||||||
|
|
||||||
enum CheatMenuEntryType
|
enum CheatMenuEntryType
|
||||||
{
|
{
|
||||||
CHEAT_MENU_ENTRY_TYPE_HEAD,
|
CHEAT_MENU_ENTRY_TYPE_HEAD,
|
||||||
@ -40,12 +39,17 @@ class CheatMenu
|
|||||||
public:
|
public:
|
||||||
CheatMenu(Client *client);
|
CheatMenu(Client *client);
|
||||||
|
|
||||||
|
ClientScripting *getScript()
|
||||||
|
{
|
||||||
|
return m_client->getScript();
|
||||||
|
}
|
||||||
|
|
||||||
void draw(video::IVideoDriver *driver, bool show_debug);
|
void draw(video::IVideoDriver *driver, bool show_debug);
|
||||||
|
|
||||||
void drawEntry(video::IVideoDriver *driver, std::string name,
|
void drawEntry(video::IVideoDriver *driver, std::string name,
|
||||||
std::size_t column_align_index, std::size_t cheat_entry_index,
|
std::size_t column_align_index, std::size_t cheat_entry_index,
|
||||||
bool is_selected, bool is_enabled,
|
bool is_selected, bool is_enabled,
|
||||||
CheatMenuEntryType entry_type = CHEAT_MENU_ENTRY_TYPE_ENTRY);
|
CheatMenuEntryType entry_type = CHEAT_MENU_ENTRY_TYPE_ENTRY);
|
||||||
|
|
||||||
void selectUp();
|
void selectUp();
|
||||||
void selectDown();
|
void selectDown();
|
||||||
@ -68,8 +72,6 @@ private:
|
|||||||
video::SColor m_font_color = video::SColor(195, 255, 255, 255);
|
video::SColor m_font_color = video::SColor(195, 255, 255, 255);
|
||||||
video::SColor m_selected_font_color = video::SColor(235, 255, 255, 255);
|
video::SColor m_selected_font_color = video::SColor(235, 255, 255, 255);
|
||||||
|
|
||||||
FontMode fontStringToEnum(std::string str);
|
|
||||||
|
|
||||||
Client *m_client;
|
Client *m_client;
|
||||||
|
|
||||||
gui::IGUIFont *m_font = nullptr;
|
gui::IGUIFont *m_font = nullptr;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user