Index: main_gui.c =================================================================== --- main_gui.c (revision 6179) +++ main_gui.c (working copy) @@ -892,16 +892,21 @@ break; } + /* This assertion is not always true now that WC_MAIN_TOOLBAR can be disabled, such as by the GUI hide console command assert(wt); + */ - // update the toolbar button too - CLRBIT(wt->disabled_state, button); - CLRBIT(wt->disabled_state, button + 1); - switch (vp->zoom) { - case 0: SETBIT(wt->disabled_state, button); break; - case 2: SETBIT(wt->disabled_state, button + 1); break; + + if (wt) { + // update the toolbar button too + CLRBIT(wt->disabled_state, button); + CLRBIT(wt->disabled_state, button + 1); + switch (vp->zoom) { + case 0: SETBIT(wt->disabled_state, button); break; + case 2: SETBIT(wt->disabled_state, button + 1); break; + } + SetWindowDirty(wt); } - SetWindowDirty(wt); } return true; @@ -2214,39 +2219,47 @@ static void MainWindowWndProc(Window *w, WindowEvent *e) { - int off_x; + // offset of 'openttd' banner + int off_x, off_y; switch (e->event) { case WE_PAINT: DrawWindowViewport(w); if (_game_mode == GM_MENU) { off_x = _screen.width / 2; + if(FindWindowById(WC_SELECT_GAME, 0)) { + // display above main menu window + off_y = 50; + } else { + // display in the centre of the screen + off_y = _screen.height / 2; + } - DrawSprite(SPR_OTTD_O, off_x - 120, 50); - DrawSprite(SPR_OTTD_P, off_x - 86, 50); - DrawSprite(SPR_OTTD_E, off_x - 53, 50); - DrawSprite(SPR_OTTD_N, off_x - 22, 50); + DrawSprite(SPR_OTTD_O, off_x - 120, off_y); + DrawSprite(SPR_OTTD_P, off_x - 86, off_y); + DrawSprite(SPR_OTTD_E, off_x - 53, off_y); + DrawSprite(SPR_OTTD_N, off_x - 22, off_y); - DrawSprite(SPR_OTTD_T, off_x + 34, 50); - DrawSprite(SPR_OTTD_T, off_x + 65, 50); - DrawSprite(SPR_OTTD_D, off_x + 96, 50); + DrawSprite(SPR_OTTD_T, off_x + 34, off_y); + DrawSprite(SPR_OTTD_T, off_x + 65, off_y); + DrawSprite(SPR_OTTD_D, off_x + 96, off_y); /* - DrawSprite(SPR_OTTD_R, off_x + 119, 50); - DrawSprite(SPR_OTTD_A, off_x + 148, 50); - DrawSprite(SPR_OTTD_N, off_x + 181, 50); - DrawSprite(SPR_OTTD_S, off_x + 215, 50); - DrawSprite(SPR_OTTD_P, off_x + 246, 50); - DrawSprite(SPR_OTTD_O, off_x + 275, 50); - DrawSprite(SPR_OTTD_R, off_x + 307, 50); - DrawSprite(SPR_OTTD_T, off_x + 337, 50); + DrawSprite(SPR_OTTD_R, off_x + 119, off_y); + DrawSprite(SPR_OTTD_A, off_x + 148, off_y); + DrawSprite(SPR_OTTD_N, off_x + 181, off_y); + DrawSprite(SPR_OTTD_S, off_x + 215, off_y); + DrawSprite(SPR_OTTD_P, off_x + 246, off_y); + DrawSprite(SPR_OTTD_O, off_x + 275, off_y); + DrawSprite(SPR_OTTD_R, off_x + 307, off_y); + DrawSprite(SPR_OTTD_T, off_x + 337, off_y); - DrawSprite(SPR_OTTD_T, off_x + 390, 50); - DrawSprite(SPR_OTTD_Y, off_x + 417, 50); - DrawSprite(SPR_OTTD_C, off_x + 447, 50); - DrawSprite(SPR_OTTD_O, off_x + 478, 50); - DrawSprite(SPR_OTTD_O, off_x + 509, 50); - DrawSprite(SPR_OTTD_N, off_x + 541, 50); + DrawSprite(SPR_OTTD_T, off_x + 390, off_y); + DrawSprite(SPR_OTTD_Y, off_x + 417, off_y); + DrawSprite(SPR_OTTD_C, off_x + 447, off_y); + DrawSprite(SPR_OTTD_O, off_x + 478, off_y); + DrawSprite(SPR_OTTD_O, off_x + 509, off_y); + DrawSprite(SPR_OTTD_N, off_x + 541, off_y); */ } break; @@ -2388,37 +2401,45 @@ { Window *w; - if (_game_mode != GM_EDITOR) { - w = AllocateWindowDesc(&_toolb_normal_desc); - /* Disable zoom-in for normal things, and zoom-out if we come - * from world-generating. */ - w->disabled_state = IsGeneratingWorld() ? (1 << 18) : (1 << 17); - } else { - w = AllocateWindowDesc(&_toolb_scen_desc); - /* Disable zoom-in for normal things, and zoom-out if we come - * from world-generating. */ - w->disabled_state = IsGeneratingWorld() ? (1 << 10) : (1 << 9); - } - CLRBITS(w->flags4, WF_WHITE_BORDER_MASK); + // XXX: this function will try to spawn certain windows regardless of whether they already exist + if ((_game_mode != GM_MENU) && (_gui_spawn == true)){ + // console variable gui_spawn is on + if (_game_mode != GM_EDITOR) { + w = AllocateWindowDesc(&_toolb_normal_desc); + /* Disable zoom-in for normal things, and zoom-out if we come + * from world-generating. */ + w->disabled_state = IsGeneratingWorld() ? (1 << 18) : (1 << 17); + } else { + w = AllocateWindowDesc(&_toolb_scen_desc); + /* Disable zoom-in for normal things, and zoom-out if we come + * from world-generating. */ + w->disabled_state = IsGeneratingWorld() ? (1 << 10) : (1 << 9); + } + CLRBITS(w->flags4, WF_WHITE_BORDER_MASK); - if (_networking) { - /* If networking, disable fast-forward button */ - SETBIT(w->disabled_state, 1); - /* If not server, disable pause button */ - if (!_network_server) SETBIT(w->disabled_state, 0); - } + if (_networking) { + /* If networking, disable fast-forward button */ + SETBIT(w->disabled_state, 1); + /* If not server, disable pause button */ + if (!_network_server) SETBIT(w->disabled_state, 0); + } - /* 'w' is for sure a WC_MAIN_TOOLBAR */ - PositionMainToolbar(w); + /* 'w' is for sure a WC_MAIN_TOOLBAR */ + PositionMainToolbar(w); - /* Status bad only for normal games */ - if (_game_mode == GM_EDITOR) return; + /* Status bad only for normal games */ + if (_game_mode == GM_EDITOR) return; - _main_status_desc.top = _screen.height - 12; - w = AllocateWindowDesc(&_main_status_desc); - CLRBITS(w->flags4, WF_WHITE_BORDER_MASK); + _main_status_desc.top = _screen.height - 12; + w = AllocateWindowDesc(&_main_status_desc); + CLRBITS(w->flags4, WF_WHITE_BORDER_MASK); - WP(w,def_d).data_1 = -1280; + WP(w,def_d).data_1 = -1280; + } else if (_game_mode == GM_MENU) { + // try to show main menu + ShowSelectGameWindow(); + } + } void GameSizeChanged(void) Index: console_cmds.c =================================================================== --- console_cmds.c (revision 6179) +++ console_cmds.c (working copy) @@ -22,6 +22,8 @@ #include "screenshot.h" #include "genworld.h" #include "date.h" +#include "window.h" +#include "gfx.h" #ifdef ENABLE_NETWORK #include "table/strings.h" @@ -172,6 +174,46 @@ return false; } +DEF_CONSOLE_CMD(ConHideGUI) +{ + // hide the GUI + if (argc == 0) { + IConsoleHelp("HideVitalWindows() then UndrawMouseCursor(). Usage: 'gui_hide'"); + return true; + } + + if (argc == 1) { + UndrawMouseCursor(); + HideVitalWindows(); + return true; + } + + return false; +} + +DEF_CONSOLE_CMD(ConShowGUI) +{ + // show the GUI + if (argc == 0) { + IConsoleHelp("HideVitalWindows(), ShowVitalWindows() then DrawMouseCursor(). Sets gui_spawn on. Usage: 'gui_show'"); + return true; + } + + if (argc == 1) { + // allow GUI to spawn + _gui_spawn = true; + IConsolePrintF(_icolour_warn, "gui_spawn changed to: on"); + + // hide before show, as ShowVitalWindows() is not designed for the case where the GUI is already shown + HideVitalWindows(); + ShowVitalWindows(); + DrawMouseCursor(); + return true; + } + + return false; +} + extern bool SafeSaveOrLoad(const char *filename, int mode, int newgm); extern void BuildFileList(void); extern void SetFiosType(const byte fiostype); @@ -1447,6 +1489,8 @@ IConsoleCmdRegister("screenshot", ConScreenShot); IConsoleCmdRegister("script", ConScript); IConsoleCmdRegister("scrollto", ConScrollToTile); + IConsoleCmdRegister("gui_hide", ConHideGUI); + IConsoleCmdRegister("gui_show", ConShowGUI); IConsoleCmdRegister("alias", ConAlias); IConsoleCmdRegister("load", ConLoad); IConsoleCmdRegister("rm", ConRemove); @@ -1465,6 +1509,8 @@ IConsoleVarRegister("developer", &_stdlib_developer, ICONSOLE_VAR_BYTE, "Redirect debugging output from the console/command line to the ingame console (value 2). Default value: 1"); + IConsoleVarRegister("gui_spawn", &_gui_spawn, ICONSOLE_VAR_BOOLEAN, "Control whether GUI elements should spawn as usual."); + /* networking variables and functions */ #ifdef ENABLE_NETWORK /* Network hooks; only active in network */ Index: intro_gui.c =================================================================== --- intro_gui.c (revision 6179) +++ intro_gui.c (working copy) @@ -97,7 +97,10 @@ void ShowSelectGameWindow(void) { - AllocateWindowDesc(&_select_game_desc); + if (_gui_spawn == true) { + // GUI is allowed to spawn + AllocateWindowDesc(&_select_game_desc); + } } static const Widget _ask_abandon_game_widgets[] = { Index: variables.h =================================================================== --- variables.h (revision 6179) +++ variables.h (working copy) @@ -339,6 +339,8 @@ VARDEF char _savegame_format[8]; VARDEF char *_config_file; +// script passed by -z commandline option to be run instead of autoexec.scr +VARDEF char *_script_filename; VARDEF char *_highscore_file; VARDEF char *_log_file; @@ -417,4 +419,7 @@ /* Forking stuff */ VARDEF bool _dedicated_forks; +// control whether GUI elements are spawned +VARDEF bool _gui_spawn; + #endif /* VARIABLES_H */ Index: openttd.c =================================================================== --- openttd.c (revision 6179) +++ openttd.c (working copy) @@ -156,6 +156,7 @@ " -i = Force to use the DOS palette\n" " (use this if you see a lot of pink)\n" " -c config_file = Use 'config_file' instead of 'openttd.cfg'\n" + " -z script_file = Use 'script_file' instead of 'autoexec.scr'\n" "\n" ); @@ -339,7 +340,7 @@ // a letter means: it accepts that param (e.g.: -h) // a ':' behind it means: it need a param (e.g.: -m) // a '::' behind it means: it can optional have a param (e.g.: -d) - optformat = "bm:s:v:hDn::eit:d::r:g::G:c:" + optformat = "bm:s:v:hDn::eit:d::r:g::G:c:z:" #if !defined(__MORPHOS__) && !defined(__AMIGA__) && !defined(WIN32) "f" #endif @@ -383,6 +384,7 @@ break; case 'G': generation_seed = atoi(mgo.opt); break; case 'c': _config_file = strdup(mgo.opt); break; + case 'z': _script_filename = strdup(mgo.opt); break; case -2: case 'h': showhelp(); @@ -470,12 +472,29 @@ UpdatePatches(); } + // GUI should normally spawn + _gui_spawn = true; // initialize the ingame console IConsoleInit(); _cursor.in_window = true; InitializeGUI(); - IConsoleCmdExec("exec scripts/autoexec.scr 0"); + if (!_script_filename) { + // default to scripts/autoexec.scr + IConsoleCmdExec("exec scripts/autoexec.scr 0"); + } else { + // create console command to exec _script_filename + char *exec_script_file = (char *) malloc(strlen("exec ") + strlen(_script_filename) + strlen(" 0")); + strcpy(exec_script_file, "exec "); + strcat(exec_script_file, _script_filename); + strcat(exec_script_file, " 0"); + + // execute the desired script + IConsoleCmdExec(exec_script_file); + + free(exec_script_file); + } + GenerateWorld(GW_EMPTY, 64, 64); // Make the viewport initialization happy WaitTillGeneratedWorld(); Index: news_gui.c =================================================================== --- news_gui.c (revision 6179) +++ news_gui.c (working copy) @@ -233,7 +233,8 @@ NewsItem *ni; Window *w; - if (_game_mode == GM_MENU) return; + // prevent news items in main menu or when gui_spawn == false + if (_game_mode == GM_MENU || _gui_spawn == false) return; // check the rare case that the oldest (to be overwritten) news item is open if (_total_news==MAX_NEWS && (_oldest_news == _current_news || _oldest_news == _forced_news)) Index: window.c =================================================================== --- window.c (revision 6179) +++ window.c (working copy) @@ -1580,6 +1580,7 @@ { DeleteWindowById(WC_MAIN_TOOLBAR, 0); DeleteWindowById(WC_STATUS_BAR, 0); + DeleteWindowById(WC_SELECT_GAME,0); } int PositionMainToolbar(Window *w)