Added cheat Menu
This commit is contained in:
parent
344fddc172
commit
f7a042223f
30
builtin/client/cheats.lua
Normal file
30
builtin/client/cheats.lua
Normal file
@ -0,0 +1,30 @@
|
||||
core.cheats = {
|
||||
["Combat"] = {
|
||||
["Killaura"] = "killaura",
|
||||
["AntiKnockback"] = "antiknockback",
|
||||
["NoFallDamage"] = "prevent_natural_damage",
|
||||
["AutoRespawn"] = "autorespawn",
|
||||
},
|
||||
["Movement"] = {
|
||||
["DragonRider"] = "entity_speed",
|
||||
["Freecam"] = "freecam",
|
||||
["PrivBypass"] = "priv_bypass",
|
||||
},
|
||||
["Render"] = {
|
||||
["Xray"] = "xray",
|
||||
["Fullbright"] = "fullbright",
|
||||
["HUDBypass"] = "hud_flags_bypass",
|
||||
["NoHurtCam"] = "no_hurt_cam"
|
||||
},
|
||||
["World"] = {
|
||||
["FastDig"] = "fastdig",
|
||||
["AutoDig"] = "autodig",
|
||||
["IncreasedRange"] = "increase_tool_range",
|
||||
["UnlimitedRange"] = "increase_tool_range_plus",
|
||||
},
|
||||
["Misc"] = {
|
||||
["Enderchest"] = function()
|
||||
minetest.open_special_inventory()
|
||||
end,
|
||||
}
|
||||
}
|
@ -9,4 +9,5 @@ dofile(commonpath .. "chatcommands.lua")
|
||||
dofile(commonpath .. "vector.lua")
|
||||
dofile(clientpath .. "util.lua")
|
||||
dofile(clientpath .. "chatcommands.lua")
|
||||
dofile(clientpath .. "cheats.lua")
|
||||
|
||||
|
@ -2252,5 +2252,3 @@ hud_flags_bypass (HUDBypass) bool true
|
||||
antiknockback (AntiKnockback) bool false
|
||||
|
||||
autorespawn (AutoRespawn) bool false
|
||||
|
||||
show_cheat_hud (CheatHUD) bool true
|
||||
|
@ -206,6 +206,8 @@ void Client::loadMods()
|
||||
// Run a callback when mods are loaded
|
||||
m_script->on_mods_loaded();
|
||||
|
||||
m_script->init_cheats();
|
||||
|
||||
// Create objects if they're ready
|
||||
if (m_state == LC_Ready)
|
||||
m_script->on_client_ready(m_env.getLocalPlayer());
|
||||
|
@ -593,11 +593,20 @@ bool Game::initGui()
|
||||
// Chat backend and console
|
||||
gui_chat_console = new GUIChatConsole(guienv, guienv->getRootGUIElement(),
|
||||
-1, chat_backend, client, &g_menumgr);
|
||||
|
||||
if (!gui_chat_console) {
|
||||
*error_message = "Could not allocate memory for chat console";
|
||||
errorstream << *error_message << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
m_cheat_menu = new CheatMenu(client);
|
||||
|
||||
if (!m_cheat_menu) {
|
||||
*error_message = "Could not allocate memory for cheat menu";
|
||||
errorstream << *error_message << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef HAVE_TOUCHSCREENGUI
|
||||
|
||||
@ -1084,6 +1093,16 @@ void Game::processKeyInput()
|
||||
toggleKillaura();
|
||||
} else if (wasKeyDown(KeyType::FREECAM)) {
|
||||
toggleFreecam();
|
||||
} else if (wasKeyDown(KeyType::SELECT_UP)) {
|
||||
m_cheat_menu->selectUp();
|
||||
} else if (wasKeyDown(KeyType::SELECT_DOWN)) {
|
||||
m_cheat_menu->selectDown();
|
||||
} else if (wasKeyDown(KeyType::SELECT_LEFT)) {
|
||||
m_cheat_menu->selectLeft();
|
||||
} else if (wasKeyDown(KeyType::SELECT_RIGHT)) {
|
||||
m_cheat_menu->selectRight();
|
||||
} else if (wasKeyDown(KeyType::SELECT_CONFIRM)) {
|
||||
m_cheat_menu->selectConfirm();
|
||||
#if USE_SOUND
|
||||
} else if (wasKeyDown(KeyType::MUTE)) {
|
||||
if (g_settings->getBool("enable_sound")) {
|
||||
@ -1137,6 +1156,8 @@ void Game::processKeyInput()
|
||||
m_game_ui->toggleChat();
|
||||
} else if (wasKeyDown(KeyType::TOGGLE_FOG)) {
|
||||
toggleFog();
|
||||
} else if (wasKeyDown(KeyType::TOGGLE_CHEAT_MENU)) {
|
||||
m_game_ui->toggleCheatMenu();
|
||||
} else if (wasKeyDown(KeyType::TOGGLE_UPDATE_CAMERA)) {
|
||||
toggleUpdateCamera();
|
||||
} else if (wasKeyDown(KeyType::TOGGLE_DEBUG)) {
|
||||
@ -2272,7 +2293,7 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud, bool show_debug)
|
||||
if (g_settings->getBool("increase_tool_range"))
|
||||
d++;
|
||||
if (g_settings->getBool("increase_tool_range_plus"))
|
||||
d = 500;
|
||||
d = 1000;
|
||||
|
||||
core::line3d<f32> shootline;
|
||||
|
||||
@ -3186,14 +3207,20 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
|
||||
if (m_game_ui->m_flags.show_profiler_graph)
|
||||
graph->draw(10, screensize.Y - 10, driver, g_fontengine->getFont());
|
||||
|
||||
/*
|
||||
Cheat menu
|
||||
*/
|
||||
|
||||
if (m_game_ui->m_flags.show_cheat_menu && ! gui_chat_console->isOpen())
|
||||
m_cheat_menu->draw(driver, m_game_ui->m_flags.show_debug);
|
||||
|
||||
/*
|
||||
Damage flash
|
||||
*/
|
||||
if (runData.damage_flash > 0.0f && ! g_settings->getBool("no_hurt_cam")) {
|
||||
if (runData.damage_flash > 0.0f) {
|
||||
video::SColor color(runData.damage_flash, 180, 0, 0);
|
||||
driver->draw2DRectangle(color,
|
||||
core::rect<s32>(0, 0, screensize.X, screensize.Y),
|
||||
NULL);
|
||||
if (! g_settings->getBool("no_hurt_cam"))
|
||||
driver->draw2DRectangle(color, core::rect<s32>(0, 0, screensize.X, screensize.Y), NULL);
|
||||
|
||||
runData.damage_flash -= 384.0f * dtime;
|
||||
}
|
||||
|
@ -41,6 +41,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
#include "log.h"
|
||||
#include "filesys.h"
|
||||
#include "gettext.h"
|
||||
#include "gui/cheatMenu.h"
|
||||
#include "gui/guiChatConsole.h"
|
||||
#include "gui/guiConfirmRegistration.h"
|
||||
#include "gui/guiFormSpecMenu.h"
|
||||
@ -855,7 +856,7 @@ public:
|
||||
ISoundManager *sound = nullptr;
|
||||
bool sound_is_dummy = false;
|
||||
SoundMaker *soundmaker = nullptr;
|
||||
|
||||
|
||||
ChatBackend *chat_backend = nullptr;
|
||||
LogOutputBuffer m_chat_log_buf;
|
||||
|
||||
@ -865,6 +866,7 @@ public:
|
||||
|
||||
std::unique_ptr<GameUI> m_game_ui;
|
||||
GUIChatConsole *gui_chat_console = nullptr; // Free using ->Drop()
|
||||
CheatMenu *m_cheat_menu = nullptr;
|
||||
MapDrawControl *draw_control = nullptr;
|
||||
Camera *camera = nullptr;
|
||||
Clouds *clouds = nullptr; // Free using ->Drop()
|
||||
|
@ -275,6 +275,15 @@ void GameUI::toggleChat()
|
||||
showTranslatedStatusText("Chat hidden");
|
||||
}
|
||||
|
||||
void GameUI::toggleCheatMenu()
|
||||
{
|
||||
m_flags.show_cheat_menu = !m_flags.show_cheat_menu;
|
||||
if (m_flags.show_cheat_menu)
|
||||
showTranslatedStatusText("Cheat Menu shown");
|
||||
else
|
||||
showTranslatedStatusText("Cheat Menu hidden");
|
||||
}
|
||||
|
||||
void GameUI::toggleHud()
|
||||
{
|
||||
m_flags.show_hud = !m_flags.show_hud;
|
||||
|
@ -59,6 +59,7 @@ public:
|
||||
bool show_minimap = false;
|
||||
bool show_debug = true;
|
||||
bool show_profiler_graph = false;
|
||||
bool show_cheat_menu = true;
|
||||
};
|
||||
|
||||
void init();
|
||||
@ -91,6 +92,7 @@ public:
|
||||
void updateProfiler();
|
||||
|
||||
void toggleChat();
|
||||
void toggleCheatMenu();
|
||||
void toggleHud();
|
||||
void toggleProfiler();
|
||||
|
||||
|
@ -62,6 +62,7 @@ void KeyCache::populate()
|
||||
key[KeyType::TOGGLE_HUD] = getKeySetting("keymap_toggle_hud");
|
||||
key[KeyType::TOGGLE_CHAT] = getKeySetting("keymap_toggle_chat");
|
||||
key[KeyType::TOGGLE_FOG] = getKeySetting("keymap_toggle_fog");
|
||||
key[KeyType::TOGGLE_CHEAT_MENU] = getKeySetting("keymap_toggle_cheat_menu");
|
||||
key[KeyType::TOGGLE_UPDATE_CAMERA] = getKeySetting("keymap_toggle_update_camera");
|
||||
key[KeyType::TOGGLE_DEBUG] = getKeySetting("keymap_toggle_debug");
|
||||
key[KeyType::TOGGLE_PROFILER] = getKeySetting("keymap_toggle_profiler");
|
||||
@ -76,6 +77,11 @@ void KeyCache::populate()
|
||||
key[KeyType::FULLBRIGHT] = getKeySetting("keymap_toggle_fullbright");
|
||||
key[KeyType::KILLAURA] = getKeySetting("keymap_toggle_killaura");
|
||||
key[KeyType::FREECAM] = getKeySetting("keymap_toggle_freecam");
|
||||
key[KeyType::SELECT_UP] = getKeySetting("keymap_select_up");
|
||||
key[KeyType::SELECT_DOWN] = getKeySetting("keymap_select_down");
|
||||
key[KeyType::SELECT_LEFT] = getKeySetting("keymap_select_left");
|
||||
key[KeyType::SELECT_RIGHT] = getKeySetting("keymap_select_right");
|
||||
key[KeyType::SELECT_CONFIRM] = getKeySetting("keymap_select_confirm");
|
||||
|
||||
key[KeyType::QUICKTUNE_NEXT] = getKeySetting("keymap_quicktune_next");
|
||||
key[KeyType::QUICKTUNE_PREV] = getKeySetting("keymap_quicktune_prev");
|
||||
|
@ -61,6 +61,7 @@ public:
|
||||
TOGGLE_HUD,
|
||||
TOGGLE_CHAT,
|
||||
TOGGLE_FOG,
|
||||
TOGGLE_CHEAT_MENU,
|
||||
TOGGLE_UPDATE_CAMERA,
|
||||
TOGGLE_DEBUG,
|
||||
TOGGLE_PROFILER,
|
||||
@ -73,6 +74,11 @@ public:
|
||||
FULLBRIGHT,
|
||||
KILLAURA,
|
||||
FREECAM,
|
||||
SELECT_UP,
|
||||
SELECT_DOWN,
|
||||
SELECT_LEFT,
|
||||
SELECT_RIGHT,
|
||||
SELECT_CONFIRM,
|
||||
|
||||
QUICKTUNE_NEXT,
|
||||
QUICKTUNE_PREV,
|
||||
|
@ -79,6 +79,7 @@ void set_default_settings(Settings *settings)
|
||||
settings->setDefault("antiknockback", "false");
|
||||
settings->setDefault("entity_speed", "false");
|
||||
settings->setDefault("autodig", "false");
|
||||
settings->setDefault("autorespawn", "false");
|
||||
|
||||
// Keymap
|
||||
settings->setDefault("remote_port", "30000");
|
||||
@ -113,6 +114,7 @@ void set_default_settings(Settings *settings)
|
||||
settings->setDefault("keymap_toggle_hud", "KEY_F1");
|
||||
settings->setDefault("keymap_toggle_chat", "KEY_F2");
|
||||
settings->setDefault("keymap_toggle_fog", "KEY_F3");
|
||||
settings->setDefault("keymap_toggle_cheat_menu", "KEY_F8");
|
||||
#if DEBUG
|
||||
settings->setDefault("keymap_toggle_update_camera", "KEY_F4");
|
||||
#else
|
||||
@ -128,6 +130,11 @@ void set_default_settings(Settings *settings)
|
||||
settings->setDefault("keymap_toggle_fullbright", "KEY_KEY_F");
|
||||
settings->setDefault("keymap_toggle_killaura", "KEY_KEY_G");
|
||||
settings->setDefault("keymap_toggle_freecam", "KEY_KEY_L");
|
||||
settings->setDefault("keymap_select_up", "KEY_UP");
|
||||
settings->setDefault("keymap_select_down", "KEY_DOWN");
|
||||
settings->setDefault("keymap_select_left", "KEY_LEFT");
|
||||
settings->setDefault("keymap_select_right", "KEY_RIGHT");
|
||||
settings->setDefault("keymap_select_confirm", "KEY_RETURN");
|
||||
settings->setDefault("keymap_slot1", "KEY_KEY_1");
|
||||
settings->setDefault("keymap_slot2", "KEY_KEY_2");
|
||||
settings->setDefault("keymap_slot3", "KEY_KEY_3");
|
||||
|
@ -1,4 +1,5 @@
|
||||
set(gui_SRCS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cheatMenu.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/guiAnimatedImage.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/guiBackgroundImage.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/guiBox.cpp
|
||||
@ -6,7 +7,6 @@ set(gui_SRCS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/guiButtonImage.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/guiButtonItemImage.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/guiChatConsole.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/guiCheatMenu.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/guiConfirmRegistration.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/guiEditBoxWithScrollbar.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/guiEngine.cpp
|
||||
|
129
src/gui/cheatMenu.cpp
Normal file
129
src/gui/cheatMenu.cpp
Normal file
@ -0,0 +1,129 @@
|
||||
/*
|
||||
Dragonfire
|
||||
Copyright (C) 2020 Elias Fleckenstein <eliasfleckenstein@web.de>
|
||||
|
||||
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"
|
||||
|
||||
CheatMenu::CheatMenu(Client *client):
|
||||
m_client(client)
|
||||
{
|
||||
m_font = g_fontengine->getFont(FONT_SIZE_UNSPECIFIED, FM_Fallback);
|
||||
|
||||
if (!m_font) {
|
||||
errorstream << "CheatMenu: Unable to load fallback font" << std::endl;
|
||||
} else {
|
||||
core::dimension2d<u32> dim = m_font->getDimension(L"M");
|
||||
m_fontsize = v2u32(dim.Width, dim.Height);
|
||||
m_font->grab();
|
||||
}
|
||||
m_fontsize.X = MYMAX(m_fontsize.X, 1);
|
||||
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)
|
||||
{
|
||||
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) {
|
||||
bgcolor = &m_active_bg_color;
|
||||
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);
|
||||
if (active)
|
||||
bgcolor = &m_active_bg_color;
|
||||
if (selected)
|
||||
fontcolor = &m_selected_font_color;
|
||||
}
|
||||
core::rect<s32> bounds(x, y, x + width, y + height);
|
||||
driver->draw2DRectangle(*bgcolor, bounds);
|
||||
driver->draw2DRectangleOutline(bounds, *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);
|
||||
m_font->draw(name.c_str(), fontbounds, *fontcolor, false, false);
|
||||
}
|
||||
|
||||
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);
|
||||
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, 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());
|
||||
cheat_count++;
|
||||
}
|
||||
}
|
||||
category_count++;
|
||||
}
|
||||
}
|
||||
|
||||
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 *selected = m_cheat_layer ? &m_selected_cheat : &m_selected_category;
|
||||
--*selected;
|
||||
if (*selected < 0)
|
||||
*selected = max;
|
||||
}
|
||||
|
||||
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 *selected = m_cheat_layer ? &m_selected_cheat : &m_selected_category;
|
||||
++*selected;
|
||||
if (*selected > max)
|
||||
*selected = 0;
|
||||
}
|
||||
|
||||
void CheatMenu::selectRight()
|
||||
{
|
||||
if (m_cheat_layer)
|
||||
return;
|
||||
m_cheat_layer = true;
|
||||
m_selected_cheat = 0;
|
||||
}
|
||||
|
||||
void CheatMenu::selectLeft()
|
||||
{
|
||||
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]);
|
||||
}
|
71
src/gui/cheatMenu.h
Normal file
71
src/gui/cheatMenu.h
Normal file
@ -0,0 +1,71 @@
|
||||
/*
|
||||
Dragonfire
|
||||
Copyright (C) 2020 Elias Fleckenstein <eliasfleckenstein@web.de>
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
#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;
|
||||
|
||||
class Client;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
CHEAT_MENU_ENTRY_TYPE_HEAD,
|
||||
CHEAT_MENU_ENTRY_TYPE_CATEGORY,
|
||||
CHEAT_MENU_ENTRY_TYPE_ENTRY,
|
||||
}
|
||||
CheatMenuEntryType;
|
||||
|
||||
class CheatMenu
|
||||
{
|
||||
public:
|
||||
CheatMenu(Client* client);
|
||||
|
||||
virtual 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 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 = 2;
|
||||
|
||||
video::SColor m_bg_color = video::SColor(192, 255, 175, 191);
|
||||
video::SColor m_active_bg_color = video::SColor(192, 255, 32, 76);
|
||||
video::SColor m_font_color = video::SColor(255, 89, 0, 65);
|
||||
video::SColor m_selected_font_color = video::SColor(255, 87, 0, 242);
|
||||
|
||||
Client *m_client;
|
||||
|
||||
gui::IGUIFont *m_font = nullptr;
|
||||
v2u32 m_fontsize;
|
||||
};
|
@ -1,19 +0,0 @@
|
||||
/*
|
||||
Dragonfire
|
||||
Copyright (C) 2020 Elias Fleckenstein <eliasfleckenstein@web.de>
|
||||
|
||||
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.
|
||||
*/
|
||||
|
@ -1,34 +0,0 @@
|
||||
/*
|
||||
Dragonfire
|
||||
Copyright (C) 2020 Elias Fleckenstein <eliasfleckenstein@web.de>
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "irrlichttypes_extrabloated.h"
|
||||
#include "modalMenu.h"
|
||||
#include "config.h"
|
||||
|
||||
class GUICheatMenuEntry : public gui::IGUIElement
|
||||
{
|
||||
GUICheatMenu(gui::IGUIEnvironment* env,
|
||||
gui::IGUIElement* parent,
|
||||
s32 id,
|
||||
Client* client,
|
||||
IMenuManager* menumgr);
|
||||
|
||||
};
|
@ -73,13 +73,19 @@ enum
|
||||
GUI_ID_KEY_CHATLOG_BUTTON,
|
||||
GUI_ID_KEY_HUD_BUTTON,
|
||||
GUI_ID_KEY_FOG_BUTTON,
|
||||
GUI_ID_KEY_CHEAT_MENU_BUTTON,
|
||||
GUI_ID_KEY_DEC_RANGE_BUTTON,
|
||||
GUI_ID_KEY_INC_RANGE_BUTTON,
|
||||
GUI_ID_KEY_AUTOFWD_BUTTON,
|
||||
GUI_ID_KEY_XRAY,
|
||||
GUI_ID_KEY_FULLBRIGHT,
|
||||
GUI_ID_KEY_KILLAURA,
|
||||
GUI_ID_KEY_FREECAM,
|
||||
GUI_ID_KEY_XRAY_BUTTON,
|
||||
GUI_ID_KEY_FULLBRIGHT_BUTTON,
|
||||
GUI_ID_KEY_KILLAURA_BUTTON,
|
||||
GUI_ID_KEY_FREECAM_BUTTON,
|
||||
GUI_ID_KEY_SELECT_UP_BUTTON,
|
||||
GUI_ID_KEY_SELECT_DOWN_BUTTON,
|
||||
GUI_ID_KEY_SELECT_LEFT_BUTTON,
|
||||
GUI_ID_KEY_SELECT_RIGHT_BUTTON,
|
||||
GUI_ID_KEY_SELECT_CONFIRM_BUTTON,
|
||||
// other
|
||||
GUI_ID_CB_AUX1_DESCENDS,
|
||||
GUI_ID_CB_DOUBLETAP_JUMP,
|
||||
@ -451,8 +457,14 @@ void GUIKeyChangeMenu::init_keys()
|
||||
this->add_key(GUI_ID_KEY_HUD_BUTTON, wgettext("Toggle HUD"), "keymap_toggle_hud");
|
||||
this->add_key(GUI_ID_KEY_CHATLOG_BUTTON, wgettext("Toggle chat log"), "keymap_toggle_chat");
|
||||
this->add_key(GUI_ID_KEY_FOG_BUTTON, wgettext("Toggle fog"), "keymap_toggle_fog");
|
||||
this->add_key(GUI_ID_KEY_XRAY, wgettext("Toggle X-Ray"), "keymap_toggle_xray");
|
||||
this->add_key(GUI_ID_KEY_FULLBRIGHT, wgettext("Toggle Fullbr."), "keymap_toggle_fullbright");
|
||||
this->add_key(GUI_ID_KEY_KILLAURA, wgettext("Toggle Killaura"), "keymap_toggle_killaura");
|
||||
this->add_key(GUI_ID_KEY_FREECAM, wgettext("Toggle Freec."), "keymap_toggle_freecam");
|
||||
this->add_key(GUI_ID_KEY_CHEAT_MENU_BUTTON,wgettext("Toggle C. Menu"),"keymap_toggle_cheat_menu");
|
||||
this->add_key(GUI_ID_KEY_XRAY_BUTTON, wgettext("Toggle X-Ray"), "keymap_toggle_xray");
|
||||
this->add_key(GUI_ID_KEY_FULLBRIGHT_BUTTON,wgettext("Toggle Fullbr."), "keymap_toggle_fullbright");
|
||||
this->add_key(GUI_ID_KEY_KILLAURA_BUTTON, wgettext("Toggle Killaura"), "keymap_toggle_killaura");
|
||||
this->add_key(GUI_ID_KEY_FREECAM_BUTTON, wgettext("Toggle Freec."), "keymap_toggle_freecam");
|
||||
this->add_key(GUI_ID_KEY_SELECT_UP_BUTTON, wgettext("C. Menu Up"), "keymap_select_up");
|
||||
this->add_key(GUI_ID_KEY_SELECT_DOWN_BUTTON,wgettext("C. Menu Down"), "keymap_select_down");
|
||||
this->add_key(GUI_ID_KEY_SELECT_LEFT_BUTTON,wgettext("C. Menu Left"), "keymap_select_left");
|
||||
this->add_key(GUI_ID_KEY_SELECT_RIGHT_BUTTON,wgettext("C. Menu Right"),"keymap_select_right");
|
||||
this->add_key(GUI_ID_KEY_SELECT_CONFIRM_BUTTON,wgettext("C. Menu Enter"),"keymap_select_confirm");
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ set(common_SCRIPT_CPP_API_SRCS
|
||||
|
||||
set(client_SCRIPT_CPP_API_SRCS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/s_client.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/s_cheats.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/s_mainmenu.cpp
|
||||
PARENT_SCOPE)
|
||||
|
||||
|
121
src/script/cpp_api/s_cheats.cpp
Normal file
121
src/script/cpp_api/s_cheats.cpp
Normal file
@ -0,0 +1,121 @@
|
||||
/*
|
||||
Dragonfire
|
||||
Copyright (C) 2020 Elias Fleckenstein <eliasfleckenstein@web.de>
|
||||
|
||||
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 "cpp_api/s_cheats.h"
|
||||
#include "cpp_api/s_base.h"
|
||||
#include "cpp_api/s_internal.h"
|
||||
#include "settings.h"
|
||||
|
||||
ScriptApiCheatsCheat::ScriptApiCheatsCheat(const std::string &name, const std::string &setting) :
|
||||
m_name(name),
|
||||
m_setting(setting),
|
||||
m_function_ref(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
ScriptApiCheatsCheat::ScriptApiCheatsCheat(const std::string &name, const int &function) :
|
||||
m_name(name),
|
||||
m_setting(""),
|
||||
m_function_ref(function)
|
||||
{
|
||||
}
|
||||
|
||||
bool ScriptApiCheatsCheat::is_enabled()
|
||||
{
|
||||
return ! m_function_ref && g_settings->getBool(m_setting);
|
||||
}
|
||||
|
||||
void ScriptApiCheatsCheat::toggle(lua_State *L, int error_handler)
|
||||
{
|
||||
if (m_function_ref) {
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, m_function_ref);
|
||||
lua_pcall(L, 0, 0, error_handler);
|
||||
} else
|
||||
g_settings->setBool(m_setting, !g_settings->getBool(m_setting));
|
||||
}
|
||||
|
||||
ScriptApiCheatsCategory::ScriptApiCheatsCategory(const std::string &name) :
|
||||
m_name(name)
|
||||
{
|
||||
}
|
||||
|
||||
ScriptApiCheatsCategory::~ScriptApiCheatsCategory()
|
||||
{
|
||||
for (auto i = m_cheats.begin(); i != m_cheats.end(); i++)
|
||||
delete *i;
|
||||
}
|
||||
|
||||
void ScriptApiCheatsCategory::read_cheats(lua_State *L)
|
||||
{
|
||||
lua_pushnil(L);
|
||||
while (lua_next(L, -2)) {
|
||||
ScriptApiCheatsCheat *cheat = nullptr;
|
||||
std::string name = lua_tostring(L, -2);
|
||||
if (lua_isstring(L, -1))
|
||||
cheat = new ScriptApiCheatsCheat(name, lua_tostring(L, -1));
|
||||
else if (lua_isfunction(L, -1)) {
|
||||
cheat = new ScriptApiCheatsCheat(name, luaL_ref(L, LUA_REGISTRYINDEX));
|
||||
lua_pushnil(L);
|
||||
}
|
||||
if (cheat)
|
||||
m_cheats.push_back(cheat);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
}
|
||||
|
||||
ScriptApiCheats::~ScriptApiCheats()
|
||||
{
|
||||
for (auto i = m_cheat_categories.begin(); i != m_cheat_categories.end(); i++)
|
||||
delete *i;
|
||||
}
|
||||
|
||||
void ScriptApiCheats::init_cheats()
|
||||
{
|
||||
SCRIPTAPI_PRECHECKHEADER
|
||||
|
||||
lua_getglobal(L, "core");
|
||||
lua_getfield(L, -1, "cheats");
|
||||
if (! lua_istable(L, -1)) {
|
||||
lua_pop(L, 2);
|
||||
return;
|
||||
}
|
||||
lua_pushnil(L);
|
||||
while (lua_next(L, -2)) {
|
||||
if (lua_istable(L, -1)) {
|
||||
ScriptApiCheatsCategory *category = new ScriptApiCheatsCategory(lua_tostring(L, -2));
|
||||
category->read_cheats(L);
|
||||
m_cheat_categories.push_back(category);
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
lua_pop(L, 2);
|
||||
m_cheats_loaded = true;
|
||||
}
|
||||
|
||||
void ScriptApiCheats::toggle_cheat(ScriptApiCheatsCheat *cheat)
|
||||
{
|
||||
SCRIPTAPI_PRECHECKHEADER
|
||||
|
||||
PUSH_ERROR_HANDLER(L);
|
||||
int error_handler = lua_gettop(L) - 1;
|
||||
lua_insert(L, error_handler);
|
||||
|
||||
cheat->toggle(L, error_handler);
|
||||
}
|
57
src/script/cpp_api/s_cheats.h
Normal file
57
src/script/cpp_api/s_cheats.h
Normal file
@ -0,0 +1,57 @@
|
||||
/*
|
||||
Dragonfire
|
||||
Copyright (C) 2020 Elias Fleckenstein <eliasfleckenstein@web.de>
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cpp_api/s_base.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
class ScriptApiCheatsCheat
|
||||
{
|
||||
public:
|
||||
ScriptApiCheatsCheat(const std::string &name, const std::string &setting);
|
||||
ScriptApiCheatsCheat(const std::string &name, const int &function);
|
||||
std::string m_name;
|
||||
bool is_enabled();
|
||||
void toggle(lua_State *L, int error_handler);
|
||||
private:
|
||||
std::string m_setting;
|
||||
int m_function_ref;
|
||||
};
|
||||
|
||||
class ScriptApiCheatsCategory
|
||||
{
|
||||
public:
|
||||
ScriptApiCheatsCategory(const std::string &name);
|
||||
~ScriptApiCheatsCategory();
|
||||
std::string m_name;
|
||||
void read_cheats(lua_State *L);
|
||||
std::vector<ScriptApiCheatsCheat*> m_cheats;
|
||||
};
|
||||
|
||||
class ScriptApiCheats : virtual public ScriptApiBase
|
||||
{
|
||||
public:
|
||||
virtual ~ScriptApiCheats();
|
||||
void init_cheats();
|
||||
void toggle_cheat(ScriptApiCheatsCheat *cheat);
|
||||
bool m_cheats_loaded = false;
|
||||
std::vector<ScriptApiCheatsCategory*> m_cheat_categories;
|
||||
};
|
@ -22,6 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
|
||||
#include "cpp_api/s_base.h"
|
||||
#include "cpp_api/s_client.h"
|
||||
#include "cpp_api/s_cheats.h"
|
||||
#include "cpp_api/s_modchannels.h"
|
||||
#include "cpp_api/s_security.h"
|
||||
|
||||
@ -34,7 +35,8 @@ class ClientScripting:
|
||||
virtual public ScriptApiBase,
|
||||
public ScriptApiSecurity,
|
||||
public ScriptApiClient,
|
||||
public ScriptApiModChannels
|
||||
public ScriptApiModChannels,
|
||||
public ScriptApiCheats
|
||||
{
|
||||
public:
|
||||
ClientScripting(Client *client);
|
||||
|
Loading…
x
Reference in New Issue
Block a user