main_gui.c
changeset 4300 c7e43c47a2b9
parent 4299 91f5d2bedcff
child 4335 02934874f33d
equal deleted inserted replaced
4299:91f5d2bedcff 4300:c7e43c47a2b9
     1 /* $Id$ */
     1 /* $Id$ */
     2 
     2 
     3 #include "stdafx.h"
     3 #include "stdafx.h"
     4 #include "openttd.h"
     4 #include "openttd.h"
       
     5 #include "heightmap.h"
     5 #include "currency.h"
     6 #include "currency.h"
     6 #include "functions.h"
     7 #include "functions.h"
     7 #include "spritecache.h"
     8 #include "spritecache.h"
     8 #include "station.h"
     9 #include "station.h"
     9 #include "strings.h"
    10 #include "strings.h"
    27 #include "waypoint.h"
    28 #include "waypoint.h"
    28 #include "variables.h"
    29 #include "variables.h"
    29 #include "train.h"
    30 #include "train.h"
    30 #include "unmovable_map.h"
    31 #include "unmovable_map.h"
    31 #include "screenshot.h"
    32 #include "screenshot.h"
       
    33 #include "genworld.h"
       
    34 #include "settings.h"
    32 #include "date.h"
    35 #include "date.h"
    33 
    36 
    34 #include "network_data.h"
    37 #include "network_data.h"
    35 #include "network_client.h"
    38 #include "network_client.h"
    36 #include "network_server.h"
    39 #include "network_server.h"
    37 
    40 
    38 /* Min/Max date for scenario editor */
       
    39 static const Date MinDate = 0;     // 1920-01-01 (MAX_YEAR_BEGIN_REAL)
       
    40 static const Date MaxDate = 29220; // 2000-01-01
       
    41 
       
    42 static int _rename_id;
    41 static int _rename_id;
    43 static int _rename_what;
    42 static int _rename_what;
    44 
    43 
    45 static byte _terraform_size = 1;
    44 static byte _terraform_size = 1;
    46 static RailType _last_built_railtype;
    45 static RailType _last_built_railtype;
    47 extern void GenerateWorld(int mode, uint size_x, uint size_y);
       
    48 
    46 
    49 extern void GenerateIndustries(void);
    47 extern void GenerateIndustries(void);
    50 extern bool GenerateTowns(void);
    48 extern bool GenerateTowns(void);
    51 
    49 
    52 void HandleOnEditTextCancel(void)
    50 void HandleOnEditTextCancel(void)
  1000 static void ToolbarScenDateBackward(Window *w)
   998 static void ToolbarScenDateBackward(Window *w)
  1001 {
   999 {
  1002 	// don't allow too fast scrolling
  1000 	// don't allow too fast scrolling
  1003 	if ((w->flags4 & WF_TIMEOUT_MASK) <= 2 << WF_TIMEOUT_SHL) {
  1001 	if ((w->flags4 & WF_TIMEOUT_MASK) <= 2 << WF_TIMEOUT_SHL) {
  1004 		HandleButtonClick(w, 6);
  1002 		HandleButtonClick(w, 6);
  1005 		InvalidateWidget(w, 5);
  1003 		SetWindowDirty(w);
  1006 
  1004 
  1007 		if (_date > MinDate) SetDate(ConvertYMDToDate(_cur_year - 1, 0, 1));
  1005 		_patches_newgame.starting_year = clamp(_patches_newgame.starting_year - 1, MIN_YEAR, MAX_YEAR);
       
  1006 		SetDate(ConvertYMDToDate(_patches_newgame.starting_year, 0, 1));
  1008 	}
  1007 	}
  1009 	_left_button_clicked = false;
  1008 	_left_button_clicked = false;
  1010 }
  1009 }
  1011 
  1010 
  1012 static void ToolbarScenDateForward(Window *w)
  1011 static void ToolbarScenDateForward(Window *w)
  1013 {
  1012 {
  1014 	// don't allow too fast scrolling
  1013 	// don't allow too fast scrolling
  1015 	if ((w->flags4 & WF_TIMEOUT_MASK) <= 2 << WF_TIMEOUT_SHL) {
  1014 	if ((w->flags4 & WF_TIMEOUT_MASK) <= 2 << WF_TIMEOUT_SHL) {
  1016 		HandleButtonClick(w, 7);
  1015 		HandleButtonClick(w, 7);
  1017 		InvalidateWidget(w, 5);
  1016 		SetWindowDirty(w);
  1018 
  1017 
  1019 		if (_date < MaxDate) SetDate(ConvertYMDToDate(_cur_year + 1, 0, 1));
  1018 		_patches_newgame.starting_year = clamp(_patches_newgame.starting_year + 1, MIN_YEAR, MAX_YEAR);
       
  1019 		SetDate(ConvertYMDToDate(_patches_newgame.starting_year, 0, 1));
  1020 	}
  1020 	}
  1021 	_left_button_clicked = false;
  1021 	_left_button_clicked = false;
  1022 }
  1022 }
  1023 
  1023 
  1024 static void ToolbarScenMapTownDir(Window *w)
  1024 static void ToolbarScenMapTownDir(Window *w)
  1049 
  1049 
  1050 	assert(w != 0);
  1050 	assert(w != 0);
  1051 
  1051 
  1052 	vp = w->viewport;
  1052 	vp = w->viewport;
  1053 
  1053 
  1054 	if (_game_mode != GM_MENU) {
  1054 	if (_game_mode != GM_MENU && !IsGeneratingWorld()) {
  1055 		if ((in && vp->zoom == 0) || (!in && vp->zoom == 2))
  1055 		if ((in && vp->zoom == 0) || (!in && vp->zoom == 2))
  1056 			return;
  1056 			return;
  1057 
  1057 
  1058 		pt = GetTileZoomCenterWindow(in,w);
  1058 		pt = GetTileZoomCenterWindow(in,w);
  1059 		if (pt.x != -1) {
  1059 		if (pt.x != -1) {
  1060 			ScrollWindowTo(pt.x, pt.y, w);
  1060 			ScrollWindowTo(pt.x, pt.y, w);
  1061 
  1061 
  1062 			DoZoomInOutWindow(in ? ZOOM_IN : ZOOM_OUT, w);
  1062 			DoZoomInOutWindow(in ? ZOOM_IN : ZOOM_OUT, w);
  1063 		}
  1063 		}
  1064 	}
  1064 	}
  1065 }
       
  1066 
       
  1067 static void ResetLandscape(void)
       
  1068 {
       
  1069 	_random_seeds[0][0] = InteractiveRandom();
       
  1070 	_random_seeds[0][1] = InteractiveRandom();
       
  1071 
       
  1072 	GenerateWorld(GW_EMPTY, 1 << _patches.map_x, 1 << _patches.map_y);
       
  1073 	MarkWholeScreenDirty();
       
  1074 }
       
  1075 
       
  1076 static const Widget _ask_reset_landscape_widgets[] = {
       
  1077 {   WWT_CLOSEBOX,   RESIZE_NONE,     4,     0,    10,     0,    13, STR_00C5,									STR_018B_CLOSE_WINDOW},
       
  1078 {    WWT_CAPTION,   RESIZE_NONE,     4,    11,   179,     0,    13, STR_022C_RESET_LANDSCAPE,	STR_NULL},
       
  1079 {     WWT_IMGBTN,   RESIZE_NONE,     4,     0,   179,    14,    91, 0x0,												STR_NULL},
       
  1080 {    WWT_TEXTBTN,   RESIZE_NONE,    12,    25,    84,    72,    83, STR_00C9_NO,								STR_NULL},
       
  1081 {    WWT_TEXTBTN,   RESIZE_NONE,    12,    95,   154,    72,    83, STR_00C8_YES,							STR_NULL},
       
  1082 {   WIDGETS_END},
       
  1083 };
       
  1084 
       
  1085 // Ask first to reset landscape or to make a random landscape
       
  1086 static void AskResetLandscapeWndProc(Window *w, WindowEvent *e)
       
  1087 {
       
  1088 	uint mode = w->window_number;
       
  1089 
       
  1090 	switch (e->event) {
       
  1091 	case WE_PAINT:
       
  1092 		DrawWindowWidgets(w);
       
  1093 		DrawStringMultiCenter(
       
  1094 			90, 38,
       
  1095 			mode ? STR_022D_ARE_YOU_SURE_YOU_WANT_TO : STR_GENERATE_RANDOM_LANDSCAPE,
       
  1096 			168
       
  1097 		);
       
  1098 		break;
       
  1099 	case WE_CLICK:
       
  1100 		switch (e->click.widget) {
       
  1101 		case 3:
       
  1102 			DeleteWindow(w);
       
  1103 			break;
       
  1104 		case 4:
       
  1105 			DeleteWindow(w);
       
  1106 			DeleteWindowByClass(WC_INDUSTRY_VIEW);
       
  1107 			DeleteWindowByClass(WC_TOWN_VIEW);
       
  1108 			DeleteWindowByClass(WC_LAND_INFO);
       
  1109 
       
  1110 			if (mode) { // reset landscape
       
  1111 				ResetLandscape();
       
  1112 			} else { // make random landscape
       
  1113 				SndPlayFx(SND_15_BEEP);
       
  1114 				_switch_mode = SM_GENRANDLAND;
       
  1115 			}
       
  1116 			break;
       
  1117 		}
       
  1118 		break;
       
  1119 	}
       
  1120 }
       
  1121 
       
  1122 static const WindowDesc _ask_reset_landscape_desc = {
       
  1123 	230,205, 180, 92,
       
  1124 	WC_ASK_RESET_LANDSCAPE,0,
       
  1125 	WDF_STD_BTN | WDF_DEF_WIDGET,
       
  1126 	_ask_reset_landscape_widgets,
       
  1127 	AskResetLandscapeWndProc,
       
  1128 };
       
  1129 
       
  1130 static void AskResetLandscape(uint mode)
       
  1131 {
       
  1132 	AllocateWindowDescFront(&_ask_reset_landscape_desc, mode);
       
  1133 }
  1065 }
  1134 
  1066 
  1135 // TODO - Incorporate into game itself to allow for ingame raising/lowering of
  1067 // TODO - Incorporate into game itself to allow for ingame raising/lowering of
  1136 // larger chunks at the same time OR remove altogether, as we have 'level land' ?
  1068 // larger chunks at the same time OR remove altogether, as we have 'level land' ?
  1137 /**
  1069 /**
  1236 
  1168 
  1237 static const Widget _scen_edit_land_gen_widgets[] = {
  1169 static const Widget _scen_edit_land_gen_widgets[] = {
  1238 {  WWT_CLOSEBOX,   RESIZE_NONE,     7,     0,    10,     0,    13, STR_00C5,                  STR_018B_CLOSE_WINDOW},
  1170 {  WWT_CLOSEBOX,   RESIZE_NONE,     7,     0,    10,     0,    13, STR_00C5,                  STR_018B_CLOSE_WINDOW},
  1239 {   WWT_CAPTION,   RESIZE_NONE,     7,    11,   169,     0,    13, STR_0223_LAND_GENERATION,  STR_018C_WINDOW_TITLE_DRAG_THIS},
  1171 {   WWT_CAPTION,   RESIZE_NONE,     7,    11,   169,     0,    13, STR_0223_LAND_GENERATION,  STR_018C_WINDOW_TITLE_DRAG_THIS},
  1240 { WWT_STICKYBOX,   RESIZE_NONE,     7,   170,   181,     0,    13, STR_NULL,                  STR_STICKY_BUTTON},
  1172 { WWT_STICKYBOX,   RESIZE_NONE,     7,   170,   181,     0,    13, STR_NULL,                  STR_STICKY_BUTTON},
  1241 {    WWT_IMGBTN,   RESIZE_NONE,     7,     0,   181,    14,   101, STR_NULL,                  STR_NULL},
  1173 {    WWT_IMGBTN,   RESIZE_NONE,     7,     0,   181,    14,    95, STR_NULL,                  STR_NULL},
  1242 
       
  1243 {    WWT_IMGBTN,   RESIZE_NONE,    14,     2,    23,    14,    35, SPR_IMG_DYNAMITE,          STR_018D_DEMOLISH_BUILDINGS_ETC},
  1174 {    WWT_IMGBTN,   RESIZE_NONE,    14,     2,    23,    14,    35, SPR_IMG_DYNAMITE,          STR_018D_DEMOLISH_BUILDINGS_ETC},
  1244 {    WWT_IMGBTN,   RESIZE_NONE,    14,    24,    45,    14,    35, SPR_IMG_TERRAFORM_DOWN,    STR_018E_LOWER_A_CORNER_OF_LAND},
  1175 {    WWT_IMGBTN,   RESIZE_NONE,    14,    24,    45,    14,    35, SPR_IMG_TERRAFORM_DOWN,    STR_018E_LOWER_A_CORNER_OF_LAND},
  1245 {    WWT_IMGBTN,   RESIZE_NONE,    14,    46,    67,    14,    35, SPR_IMG_TERRAFORM_UP,      STR_018F_RAISE_A_CORNER_OF_LAND},
  1176 {    WWT_IMGBTN,   RESIZE_NONE,    14,    46,    67,    14,    35, SPR_IMG_TERRAFORM_UP,      STR_018F_RAISE_A_CORNER_OF_LAND},
  1246 {    WWT_IMGBTN,   RESIZE_NONE,    14,    68,    89,    14,    35, SPR_IMG_LEVEL_LAND,        STR_LEVEL_LAND_TOOLTIP},
  1177 {    WWT_IMGBTN,   RESIZE_NONE,    14,    68,    89,    14,    35, SPR_IMG_LEVEL_LAND,        STR_LEVEL_LAND_TOOLTIP},
  1247 {    WWT_IMGBTN,   RESIZE_NONE,    14,    90,   111,    14,    35, SPR_IMG_BUILD_CANAL,       STR_CREATE_LAKE},
  1178 {    WWT_IMGBTN,   RESIZE_NONE,    14,    90,   111,    14,    35, SPR_IMG_BUILD_CANAL,       STR_CREATE_LAKE},
  1248 {    WWT_IMGBTN,   RESIZE_NONE,    14,   112,   134,    14,    35, SPR_IMG_ROCKS,             STR_028C_PLACE_ROCKY_AREAS_ON_LANDSCAPE},
  1179 {    WWT_IMGBTN,   RESIZE_NONE,    14,   112,   134,    14,    35, SPR_IMG_ROCKS,             STR_028C_PLACE_ROCKY_AREAS_ON_LANDSCAPE},
  1249 {    WWT_IMGBTN,   RESIZE_NONE,    14,   135,   157,    14,    35, SPR_IMG_LIGHTHOUSE_DESERT, STR_NULL}, // XXX - dynamic
  1180 {    WWT_IMGBTN,   RESIZE_NONE,    14,   135,   157,    14,    35, SPR_IMG_LIGHTHOUSE_DESERT, STR_NULL}, // XXX - dynamic
  1250 {    WWT_IMGBTN,   RESIZE_NONE,    14,   158,   179,    14,    35, SPR_IMG_TRANSMITTER,       STR_028E_PLACE_TRANSMITTER},
  1181 {    WWT_IMGBTN,   RESIZE_NONE,    14,   158,   179,    14,    35, SPR_IMG_TRANSMITTER,       STR_028E_PLACE_TRANSMITTER},
  1251 {   WWT_TEXTBTN,   RESIZE_NONE,    14,   139,   149,    43,    54, STR_0224,                  STR_0228_INCREASE_SIZE_OF_LAND_AREA},
  1182 {   WWT_TEXTBTN,   RESIZE_NONE,    14,   139,   149,    43,    54, STR_0224,                  STR_0228_INCREASE_SIZE_OF_LAND_AREA},
  1252 {   WWT_TEXTBTN,   RESIZE_NONE,    14,   139,   149,    56,    67, STR_0225,                  STR_0229_DECREASE_SIZE_OF_LAND_AREA},
  1183 {   WWT_TEXTBTN,   RESIZE_NONE,    14,   139,   149,    56,    67, STR_0225,                  STR_0229_DECREASE_SIZE_OF_LAND_AREA},
  1253 {   WWT_TEXTBTN,   RESIZE_NONE,    14,    34,   149,    75,    86, STR_0226_RANDOM_LAND,      STR_022A_GENERATE_RANDOM_LAND},
  1184 {   WWT_TEXTBTN,   RESIZE_NONE,    14,    34,   149,    75,    86, STR_SE_NEW_WORLD,          STR_022A_GENERATE_RANDOM_LAND},
  1254 {   WWT_TEXTBTN,   RESIZE_NONE,    14,    34,   149,    88,    99, STR_0227_RESET_LAND,       STR_022B_RESET_LANDSCAPE},
       
  1255 {   WIDGETS_END},
  1185 {   WIDGETS_END},
  1256 };
  1186 };
  1257 
  1187 
  1258 static const int8 _multi_terraform_coords[][2] = {
  1188 static const int8 _multi_terraform_coords[][2] = {
  1259 	{  0, -2},
  1189 	{  0, -2},
  1386 			SndPlayFx(SND_15_BEEP);
  1316 			SndPlayFx(SND_15_BEEP);
  1387 			SetWindowDirty(w);
  1317 			SetWindowDirty(w);
  1388 		} break;
  1318 		} break;
  1389 		case 14: /* gen random land */
  1319 		case 14: /* gen random land */
  1390 			HandleButtonClick(w, 14);
  1320 			HandleButtonClick(w, 14);
  1391 			AskResetLandscape(0);
  1321 			ShowCreateScenario();
  1392 			break;
       
  1393 		case 15: /* reset landscape */
       
  1394 			HandleButtonClick(w,15);
       
  1395 			AskResetLandscape(1);
       
  1396 			break;
  1322 			break;
  1397 		}
  1323 		}
  1398 		break;
  1324 		break;
  1399 
  1325 
  1400 	case WE_TIMEOUT:
  1326 	case WE_TIMEOUT:
  1420 		break;
  1346 		break;
  1421 	}
  1347 	}
  1422 }
  1348 }
  1423 
  1349 
  1424 static const WindowDesc _scen_edit_land_gen_desc = {
  1350 static const WindowDesc _scen_edit_land_gen_desc = {
  1425 	-1,-1, 182, 102,
  1351 	-1,-1, 182, 96,
  1426 	WC_SCEN_LAND_GEN,0,
  1352 	WC_SCEN_LAND_GEN,0,
  1427 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
  1353 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
  1428 	_scen_edit_land_gen_widgets,
  1354 	_scen_edit_land_gen_widgets,
  1429 	ScenEditLandGenWndProc,
  1355 	ScenEditLandGenWndProc,
  1430 };
  1356 };
  1876 			_toolbar_button_procs[e->click.widget](w);
  1802 			_toolbar_button_procs[e->click.widget](w);
  1877 	} break;
  1803 	} break;
  1878 
  1804 
  1879 	case WE_KEYPRESS: {
  1805 	case WE_KEYPRESS: {
  1880 		PlayerID local = (_local_player != OWNER_SPECTATOR) ? _local_player : 0;
  1806 		PlayerID local = (_local_player != OWNER_SPECTATOR) ? _local_player : 0;
       
  1807 
       
  1808 		if (IsGeneratingWorld()) break;
  1881 
  1809 
  1882 		switch (e->keypress.keycode) {
  1810 		switch (e->keypress.keycode) {
  1883 		case WKC_F1: case WKC_PAUSE:
  1811 		case WKC_F1: case WKC_PAUSE:
  1884 			ToolbarPauseClick(w);
  1812 			ToolbarPauseClick(w);
  1885 			break;
  1813 			break;
  2060 
  1988 
  2061 static void ScenEditToolbarWndProc(Window *w, WindowEvent *e)
  1989 static void ScenEditToolbarWndProc(Window *w, WindowEvent *e)
  2062 {
  1990 {
  2063 	switch (e->event) {
  1991 	switch (e->event) {
  2064 	case WE_PAINT:
  1992 	case WE_PAINT:
  2065 		/* XXX look for better place for these */
  1993 		if (_patches_newgame.starting_year <= MIN_YEAR) {
  2066 		if (_date <= MinDate) {
       
  2067 			SETBIT(w->disabled_state, 6);
  1994 			SETBIT(w->disabled_state, 6);
  2068 		} else {
  1995 		} else {
  2069 			CLRBIT(w->disabled_state, 6);
  1996 			CLRBIT(w->disabled_state, 6);
  2070 		}
  1997 		}
  2071 		if (_date >= MaxDate) {
  1998 		if (_patches_newgame.starting_year >= MAX_YEAR) {
  2072 			SETBIT(w->disabled_state, 7);
  1999 			SETBIT(w->disabled_state, 7);
  2073 		} else {
  2000 		} else {
  2074 			CLRBIT(w->disabled_state, 7);
  2001 			CLRBIT(w->disabled_state, 7);
  2075 		}
  2002 		}
  2076 
  2003 
  2078 		GfxFillRect(0, 0, w->width-1, w->height-1, 0xB2);
  2005 		GfxFillRect(0, 0, w->width-1, w->height-1, 0xB2);
  2079 		GfxFillRect(0, 0, w->width-1, w->height-1, 0xB4 | PALETTE_MODIFIER_GREYOUT);
  2006 		GfxFillRect(0, 0, w->width-1, w->height-1, 0xB4 | PALETTE_MODIFIER_GREYOUT);
  2080 
  2007 
  2081 		DrawWindowWidgets(w);
  2008 		DrawWindowWidgets(w);
  2082 
  2009 
  2083 		SetDParam(0, _date);
  2010 		SetDParam(0, ConvertYMDToDate(_patches_newgame.starting_year, 0, 1));
  2084 		DrawStringCentered(298, 6, STR_00AF, 0);
  2011 		DrawStringCentered(298, 6, STR_00AF, 0);
  2085 
  2012 
  2086 		SetDParam(0, _date);
  2013 		SetDParam(0, ConvertYMDToDate(_patches_newgame.starting_year, 0, 1));
  2087 		DrawStringCentered(161, 1, STR_0221_OPENTTD, 0);
  2014 		DrawStringCentered(161, 1, STR_0221_OPENTTD, 0);
  2088 		DrawStringCentered(161, 11,STR_0222_SCENARIO_EDITOR, 0);
  2015 		DrawStringCentered(161, 11,STR_0222_SCENARIO_EDITOR, 0);
  2089 
  2016 
  2090 		break;
  2017 		break;
  2091 
  2018 
  2205 		SetDParam(0, _date);
  2132 		SetDParam(0, _date);
  2206 		DrawStringCentered(
  2133 		DrawStringCentered(
  2207 			70, 1, (_pause || _patches.status_long_date) ? STR_00AF : STR_00AE, 0
  2134 			70, 1, (_pause || _patches.status_long_date) ? STR_00AF : STR_00AE, 0
  2208 		);
  2135 		);
  2209 
  2136 
  2210 		if (p != NULL) {
  2137 		if (p != NULL && !IsGeneratingWorld()) {
  2211 			// Draw player money
  2138 			// Draw player money
  2212 			SetDParam64(0, p->money64);
  2139 			SetDParam64(0, p->money64);
  2213 			DrawStringCentered(570, 1, p->player_money >= 0 ? STR_0004 : STR_0005, 0);
  2140 			DrawStringCentered(570, 1, p->player_money >= 0 ? STR_0004 : STR_0005, 0);
  2214 		}
  2141 		}
  2215 
  2142 
  2223 		} else if (WP(w,def_d).data_1 > -1280 && FindWindowById(WC_NEWS_WINDOW,0) == NULL && _statusbar_news_item.string_id != 0) {
  2150 		} else if (WP(w,def_d).data_1 > -1280 && FindWindowById(WC_NEWS_WINDOW,0) == NULL && _statusbar_news_item.string_id != 0) {
  2224 			// Draw the scrolling news text
  2151 			// Draw the scrolling news text
  2225 			if (!DrawScrollingStatusText(&_statusbar_news_item, WP(w,def_d).data_1))
  2152 			if (!DrawScrollingStatusText(&_statusbar_news_item, WP(w,def_d).data_1))
  2226 				WP(w,def_d).data_1 = -1280;
  2153 				WP(w,def_d).data_1 = -1280;
  2227 		} else {
  2154 		} else {
  2228 			if (p != NULL) {
  2155 			if (p != NULL && !IsGeneratingWorld()) {
  2229 				// This is the default text
  2156 				// This is the default text
  2230 				SetDParam(0, p->name_1);
  2157 				SetDParam(0, p->name_1);
  2231 				SetDParam(1, p->name_2);
  2158 				SetDParam(1, p->name_2);
  2232 				DrawStringCentered(320, 1, STR_02BA, 0);
  2159 				DrawStringCentered(320, 1, STR_02BA, 0);
  2233 			}
  2160 			}
  2325 		}
  2252 		}
  2326 		break;
  2253 		break;
  2327 
  2254 
  2328 	case WE_KEYPRESS:
  2255 	case WE_KEYPRESS:
  2329 		if (e->keypress.keycode == WKC_BACKQUOTE) {
  2256 		if (e->keypress.keycode == WKC_BACKQUOTE) {
  2330 			IConsoleSwitch();
  2257 			if (!IsGeneratingWorld()) IConsoleSwitch();
  2331 			e->keypress.cont = false;
  2258 			e->keypress.cont = false;
  2332 			break;
  2259 			break;
  2333 		}
  2260 		}
  2334 
  2261 
  2335 		switch (e->keypress.keycode) {
  2262 		switch (e->keypress.keycode) {
  2337 			case 'Q' | WKC_META:
  2264 			case 'Q' | WKC_META:
  2338 				AskExitGame();
  2265 				AskExitGame();
  2339 				break;
  2266 				break;
  2340 		}
  2267 		}
  2341 
  2268 
  2342 		if (_game_mode == GM_MENU) break;
  2269 		if (_game_mode == GM_MENU || IsGeneratingWorld()) break;
  2343 
  2270 
  2344 		switch (e->keypress.keycode) {
  2271 		switch (e->keypress.keycode) {
  2345 			case 'C':
  2272 			case 'C':
  2346 			case 'Z': {
  2273 			case 'Z': {
  2347 				Point pt = GetTileBelowCursor();
  2274 				Point pt = GetTileBelowCursor();
  2433 		break;
  2360 		break;
  2434 	case GM_EDITOR:
  2361 	case GM_EDITOR:
  2435 		w = AllocateWindow(0, 0, width, height, MainWindowWndProc, WC_MAIN_WINDOW, NULL);
  2362 		w = AllocateWindow(0, 0, width, height, MainWindowWndProc, WC_MAIN_WINDOW, NULL);
  2436 		AssignWindowViewport(w, 0, 0, width, height, 0, 0);
  2363 		AssignWindowViewport(w, 0, 0, width, height, 0, 0);
  2437 
  2364 
  2438 		w = AllocateWindowDesc(&_toolb_scen_desc);
  2365 		ShowVitalWindows();
  2439 		w->disabled_state = 1 << 9;
       
  2440 		CLRBITS(w->flags4, WF_WHITE_BORDER_MASK);
       
  2441 
       
  2442 		PositionMainToolbar(w); // already WC_MAIN_TOOLBAR passed (&_toolb_scen_desc)
       
  2443 		break;
  2366 		break;
  2444 	default:
  2367 	default:
  2445 		NOT_REACHED();
  2368 		NOT_REACHED();
  2446 	}
  2369 	}
  2447 }
  2370 }
  2448 
  2371 
  2449 void ShowVitalWindows(void)
  2372 void ShowVitalWindows(void)
  2450 {
  2373 {
  2451 	Window *w;
  2374 	Window *w;
  2452 
  2375 
  2453 	w = AllocateWindowDesc(&_toolb_normal_desc);
  2376 	if (_game_mode != GM_EDITOR) {
  2454 	w->disabled_state = 1 << 17; // disable zoom-in button (by default game is zoomed in)
  2377 		w = AllocateWindowDesc(&_toolb_normal_desc);
       
  2378 		/* Disable zoom-in for normal things, and zoom-out if we come
       
  2379 		 *  from world-generating. */
       
  2380 		w->disabled_state = IsGeneratingWorld() ? (1 << 18) : (1 << 17);
       
  2381 	} else {
       
  2382 		w = AllocateWindowDesc(&_toolb_scen_desc);
       
  2383 		/* Disable zoom-in for normal things, and zoom-out if we come
       
  2384 		 *  from world-generating. */
       
  2385 		w->disabled_state = IsGeneratingWorld() ? (1 << 10) : (1 << 9);
       
  2386 	}
  2455 	CLRBITS(w->flags4, WF_WHITE_BORDER_MASK);
  2387 	CLRBITS(w->flags4, WF_WHITE_BORDER_MASK);
  2456 
  2388 
  2457 	if (_networking) { // if networking, disable fast-forward button
  2389 	if (_networking) {
       
  2390 		/* If networking, disable fast-forward button */
  2458 		SETBIT(w->disabled_state, 1);
  2391 		SETBIT(w->disabled_state, 1);
  2459 		if (!_network_server) // if not server, disable pause button
  2392 		/* If not server, disable pause button */
  2460 			SETBIT(w->disabled_state, 0);
  2393 		if (!_network_server) SETBIT(w->disabled_state, 0);
  2461 	}
  2394 	}
  2462 
  2395 
  2463 	PositionMainToolbar(w); // already WC_MAIN_TOOLBAR passed (&_toolb_normal_desc)
  2396 	/* 'w' is for sure a WC_MAIN_TOOLBAR */
       
  2397 	PositionMainToolbar(w);
       
  2398 
       
  2399 	/* Status bad only for normal games */
       
  2400 	if (_game_mode == GM_EDITOR) return;
  2464 
  2401 
  2465 	_main_status_desc.top = _screen.height - 12;
  2402 	_main_status_desc.top = _screen.height - 12;
  2466 	w = AllocateWindowDesc(&_main_status_desc);
  2403 	w = AllocateWindowDesc(&_main_status_desc);
  2467 	CLRBITS(w->flags4, WF_WHITE_BORDER_MASK);
  2404 	CLRBITS(w->flags4, WF_WHITE_BORDER_MASK);
  2468 
  2405