Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: Cheat menu under land information menu and 'cheat' console command #8207

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cheat_func.h
Expand Up @@ -14,7 +14,7 @@

extern Cheats _cheats;

void ShowCheatWindow();
bool ShowCheatWindow();

bool CheatHasBeenUsed();

Expand Down
12 changes: 11 additions & 1 deletion src/cheat_gui.cpp
Expand Up @@ -13,6 +13,7 @@
#include "company_base.h"
#include "company_func.h"
#include "date_func.h"
#include "openttd.h"
#include "saveload/saveload.h"
#include "textbuf_gui.h"
#include "window_gui.h"
Expand All @@ -23,6 +24,7 @@
#include "settings_gui.h"
#include "company_gui.h"
#include "linkgraph/linkgraphschedule.h"
#include "network/network.h"
#include "map_func.h"
#include "tile_map.h"
#include "newgrf.h"
Expand Down Expand Up @@ -413,8 +415,16 @@ static WindowDesc _cheats_desc(
);

/** Open cheat window. */
void ShowCheatWindow()
bool ShowCheatWindow()
{
/* Not to open in multiplayer or intro game. */
if (_networking || _game_mode == GM_MENU)
{
ShowErrorMessage(STR_ERROR_CAN_T_OPEN_CHEAT, INVALID_STRING_ID, WL_ERROR);
return false;
}

DeleteWindowById(WC_CHEATS, 0);
new CheatWindow(&_cheats_desc);
return true;
}
14 changes: 14 additions & 0 deletions src/console_cmds.cpp
Expand Up @@ -1072,6 +1072,19 @@ DEF_CONSOLE_CMD(ConRestart)
return true;
}

DEF_CONSOLE_CMD(ConOpenCheats)
{
if (argc == 0) {
IConsoleHelp("Just open the cheat window. Usage: 'cheat'");
return true;
}

extern bool ShowCheatWindow();
ShowCheatWindow();

return true;
}

/**
* Print a text buffer line by line to the console. Lines are separated by '\n'.
* @param buf The buffer to print.
Expand Down Expand Up @@ -2097,6 +2110,7 @@ void IConsoleStdLibRegister()
IConsoleCmdRegister("reset_enginepool", ConResetEnginePool, ConHookNoNetwork);
IConsoleCmdRegister("return", ConReturn);
IConsoleCmdRegister("screenshot", ConScreenShot);
IConsoleCmdRegister("cheat", ConOpenCheats, ConHookNoNetwork);
IConsoleCmdRegister("script", ConScript);
IConsoleCmdRegister("scrollto", ConScrollToTile);
IConsoleCmdRegister("alias", ConAlias);
Expand Down
4 changes: 4 additions & 0 deletions src/lang/english.txt
Expand Up @@ -476,6 +476,7 @@ STR_NEWS_MENU_DELETE_ALL_MESSAGES :Delete all mess
STR_ABOUT_MENU_LAND_BLOCK_INFO :Land area information
STR_ABOUT_MENU_SEPARATOR :
STR_ABOUT_MENU_TOGGLE_CONSOLE :Toggle console
STR_ABOUT_MENU_SHOW_CHEAT :Cheat
STR_ABOUT_MENU_AI_DEBUG :AI/Game script debug
STR_ABOUT_MENU_SCREENSHOT :Screenshot
STR_ABOUT_MENU_SHOW_FRAMERATE :Show frame rate
Expand Down Expand Up @@ -4640,6 +4641,9 @@ STR_ERROR_CAN_T_PLACE_SIGN_HERE :{WHITE}Can't pl
STR_ERROR_CAN_T_CHANGE_SIGN_NAME :{WHITE}Can't change sign name...
STR_ERROR_CAN_T_DELETE_SIGN :{WHITE}Can't delete sign...

# Misc. errors
STR_ERROR_CAN_T_OPEN_CHEAT :{WHITE}Can't open cheat window in title screen or multiplayer game.

# Translatable comment for OpenTTD's desktop shortcut
STR_DESKTOP_SHORTCUT_COMMENT :A simulation game based on Transport Tycoon Deluxe

Expand Down
21 changes: 11 additions & 10 deletions src/toolbar_gui.cpp
Expand Up @@ -1067,7 +1067,7 @@ static CallBackFunction PlaceLandBlockInfo()

static CallBackFunction ToolbarHelpClick(Window *w)
{
PopupMainToolbMenu(w, _game_mode == GM_EDITOR ? (int)WID_TE_HELP : (int)WID_TN_HELP, STR_ABOUT_MENU_LAND_BLOCK_INFO, _settings_client.gui.newgrf_developer_tools ? 10 : 7);
PopupMainToolbMenu(w, _game_mode == GM_EDITOR ? (int)WID_TE_HELP : (int)WID_TN_HELP, STR_ABOUT_MENU_LAND_BLOCK_INFO, _settings_client.gui.newgrf_developer_tools ? 11 : 8);
return CBF_NONE;
}

Expand Down Expand Up @@ -1157,15 +1157,16 @@ void SetStartingYear(Year year)
static CallBackFunction MenuClickHelp(int index)
{
switch (index) {
case 0: return PlaceLandBlockInfo();
case 2: IConsoleSwitch(); break;
case 3: ShowAIDebugWindow(); break;
case 4: ShowScreenshotWindow(); break;
case 5: ShowFramerateWindow(); break;
case 6: ShowAboutWindow(); break;
case 7: ShowSpriteAlignerWindow(); break;
case 8: ToggleBoundingBoxes(); break;
case 9: ToggleDirtyBlocks(); break;
case 0: return PlaceLandBlockInfo();
case 2: IConsoleSwitch(); break;
case 3: ShowCheatWindow(); break;
case 4: ShowAIDebugWindow(); break;
case 5: ShowScreenshotWindow(); break;
case 6: ShowFramerateWindow(); break;
case 7: ShowAboutWindow(); break;
case 8: ShowSpriteAlignerWindow(); break;
case 9: ToggleBoundingBoxes(); break;
case 10: ToggleDirtyBlocks(); break;
}
return CBF_NONE;
}
Expand Down