src/misc_gui.cpp
branchNewGRF_ports
changeset 6872 1c4a4a609f85
parent 6871 5a9dc001e1ad
child 6877 889301acc299
equal deleted inserted replaced
6871:5a9dc001e1ad 6872:1c4a4a609f85
     4 
     4 
     5 #include "stdafx.h"
     5 #include "stdafx.h"
     6 #include "openttd.h"
     6 #include "openttd.h"
     7 #include "heightmap.h"
     7 #include "heightmap.h"
     8 #include "debug.h"
     8 #include "debug.h"
     9 #include "functions.h"
       
    10 #include "landscape.h"
     9 #include "landscape.h"
    11 #include "newgrf.h"
    10 #include "newgrf.h"
    12 #include "newgrf_text.h"
    11 #include "newgrf_text.h"
    13 #include "saveload.h"
    12 #include "saveload.h"
    14 #include "strings.h"
    13 #include "tile_map.h"
       
    14 #include "gui.h"
       
    15 #include "window_gui.h"
       
    16 #include "station_gui.h"
       
    17 #include "textbuf_gui.h"
       
    18 #include "viewport_func.h"
       
    19 #include "gfx_func.h"
       
    20 #include "station.h"
       
    21 #include "command_func.h"
       
    22 #include "player_func.h"
       
    23 #include "player_base.h"
       
    24 #include "town.h"
       
    25 #include "network/network.h"
       
    26 #include "variables.h"
       
    27 #include "train.h"
       
    28 #include "tgp.h"
       
    29 #include "cargotype.h"
       
    30 #include "player_face.h"
       
    31 #include "strings_func.h"
       
    32 #include "fileio.h"
       
    33 #include "fios.h"
       
    34 #include "tile_cmd.h"
       
    35 #include "zoom_func.h"
       
    36 #include "functions.h"
       
    37 #include "window_func.h"
       
    38 #include "date_func.h"
       
    39 #include "sound_func.h"
       
    40 #include "string_func.h"
       
    41 #include "player_gui.h"
       
    42 #include "settings_type.h"
       
    43 
    15 #include "table/sprites.h"
    44 #include "table/sprites.h"
    16 #include "table/strings.h"
    45 #include "table/strings.h"
    17 #include "strings.h"
       
    18 #include "table/tree_land.h"
    46 #include "table/tree_land.h"
    19 #include "map.h"
    47 
    20 #include "window.h"
       
    21 #include "gui.h"
       
    22 #include "viewport.h"
       
    23 #include "gfx.h"
       
    24 #include "station.h"
       
    25 #include "command.h"
       
    26 #include "player.h"
       
    27 #include "town.h"
       
    28 #include "sound.h"
       
    29 #include "network/network.h"
       
    30 #include "string.h"
       
    31 #include "variables.h"
       
    32 #include "vehicle.h"
       
    33 #include "train.h"
       
    34 #include "tgp.h"
       
    35 #include "settings.h"
       
    36 #include "date.h"
       
    37 #include "cargotype.h"
       
    38 #include "player_face.h"
       
    39 #include "fileio.h"
       
    40 
       
    41 #include "fileio.h"
       
    42 #include "fios.h"
       
    43 /* Variables to display file lists */
    48 /* Variables to display file lists */
    44 FiosItem *_fios_list;
    49 FiosItem *_fios_list;
    45 int _saveload_mode;
    50 SaveLoadDialogMode _saveload_mode;
    46 
    51 
    47 
    52 
    48 static bool _fios_path_changed;
    53 static bool _fios_path_changed;
    49 static bool _savegame_sort_dirty;
    54 static bool _savegame_sort_dirty;
    50 
    55 
   208 	 *                      maximum length of string which fits in window   -^*/
   213 	 *                      maximum length of string which fits in window   -^*/
   209 	"Original design by Chris Sawyer",
   214 	"Original design by Chris Sawyer",
   210 	"Original graphics by Simon Foster",
   215 	"Original graphics by Simon Foster",
   211 	"",
   216 	"",
   212 	"The OpenTTD team (in alphabetical order):",
   217 	"The OpenTTD team (in alphabetical order):",
   213 	"  Jean-Francois Claeys (Belugas) - In training, not yet specialized",
   218 	"  Jean-Francois Claeys (Belugas) - GUI, newindustries and more",
   214 	"  Bjarni Corfitzen (Bjarni) - MacOSX port, coder",
   219 	"  Bjarni Corfitzen (Bjarni) - MacOSX port, coder and vehicles",
   215 	"  Matthijs Kooijman (blathijs) - Pathfinder-guru",
   220 	"  Matthijs Kooijman (blathijs) - Pathfinder-guru, pool rework",
   216 	"  Victor Fischer (Celestar) - Programming everywhere you need him to",
   221 	"  Loïc Guilloux (glx) - General coding",
   217 	"  Tamás Faragó (Darkvater) - Lead coder",
       
   218 	"  Loïc Guilloux (glx) - In training, not yet specialized",
       
   219 	"  Jaroslav Mazanec (KUDr) - YAPG (Yet Another Pathfinder God) ;)",
   222 	"  Jaroslav Mazanec (KUDr) - YAPG (Yet Another Pathfinder God) ;)",
   220 	"  Jonathan Coome (Maedhros) - High priest of the newGRF Temple",
   223 	"  Jonathan Coome (Maedhros) - High priest of the newGRF Temple",
   221 	"  Attila Bán (MiHaMiX) - WebTranslator, Nightlies, Wiki and bugtracker host",
   224 	"  Attila Bán (MiHaMiX) - WebTranslator, Nightlies, Wiki and bugtracker host",
   222 	"  Owen Rudge (orudge) - Forum host, OS/2 port",
   225 	"  Owen Rudge (orudge) - Forum host, OS/2 port",
   223 	"  Peter Nelson (peter1138) - Spiritual descendant from newgrf gods",
   226 	"  Peter Nelson (peter1138) - Spiritual descendant from newGRF gods",
   224 	"  Remko Bijker (Rubidium) - THE desync hunter",
   227 	"  Remko Bijker (Rubidium) - Lead coder and way more",
       
   228 	"  Benedikt Brüggemeier (skidd13) - Bug fixer and code reworker",
       
   229 	"  Zdenek Sojka (SmatZ) - Bug finder and fixer",
       
   230 	"",
       
   231 	"Inactive Developers:",
       
   232 	"  Victor Fischer (Celestar) - Programming everywhere you need him to",
       
   233 	"  Tamás Faragó (Darkvater) - Ex-Lead coder",
   225 	"  Christoph Mallon (Tron) - Programmer, code correctness police",
   234 	"  Christoph Mallon (Tron) - Programmer, code correctness police",
   226 	"",
   235 	"",
   227 	"Retired Developers:",
   236 	"Retired Developers:",
   228 	"  Ludvig Strigeus (ludde) - OpenTTD author, main coder (0.1 - 0.3.3)",
   237 	"  Ludvig Strigeus (ludde) - OpenTTD author, main coder (0.1 - 0.3.3)",
   229 	"  Serge Paquet (vurlix) - Assistant project manager, coder (0.1 - 0.3.3)",
   238 	"  Serge Paquet (vurlix) - Assistant project manager, coder (0.1 - 0.3.3)",
   231 	"  Patric Stout (TrueLight) - Programmer, webhoster (0.3 - pre0.6)",
   240 	"  Patric Stout (TrueLight) - Programmer, webhoster (0.3 - pre0.6)",
   232 	"",
   241 	"",
   233 	"Special thanks go out to:",
   242 	"Special thanks go out to:",
   234 	"  Josef Drexler - For his great work on TTDPatch",
   243 	"  Josef Drexler - For his great work on TTDPatch",
   235 	"  Marcin Grzegorczyk - For his documentation of TTD internals",
   244 	"  Marcin Grzegorczyk - For his documentation of TTD internals",
   236 	"  Petr Baudis (pasky) - Many patches, newgrf support",
   245 	"  Petr Baudis (pasky) - Many patches, newGRF support",
   237 	"  Stefan Meißner (sign_de) - For his work on the console",
   246 	"  Stefan Meißner (sign_de) - For his work on the console",
   238 	"  Simon Sasburg (HackyKid) - Many bugfixes he has blessed us with (and PBS)",
   247 	"  Simon Sasburg (HackyKid) - Many bugfixes he has blessed us with",
   239 	"  Cian Duffy (MYOB) - BeOS port / manual writing",
   248 	"  Cian Duffy (MYOB) - BeOS port / manual writing",
   240 	"  Christian Rosentreter (tokai) - MorphOS / AmigaOS port",
   249 	"  Christian Rosentreter (tokai) - MorphOS / AmigaOS port",
   241 	"  Richard Kempton (richK) - additional airports, initial TGP implementation",
   250 	"  Richard Kempton (richK) - additional airports, initial TGP implementation",
   242 	"",
   251 	"",
   243 	"  Michael Blunck - Pre-Signals and Semaphores © 2003",
   252 	"  Michael Blunck - Pre-Signals and Semaphores © 2003",
   254 
   263 
   255 static void AboutWindowProc(Window *w, WindowEvent *e)
   264 static void AboutWindowProc(Window *w, WindowEvent *e)
   256 {
   265 {
   257 	switch (e->event) {
   266 	switch (e->event) {
   258 	case WE_CREATE: // Set up window counter and start position of scroller
   267 	case WE_CREATE: // Set up window counter and start position of scroller
   259 		WP(w, scroller_d).counter = 0;
   268 		WP(w, scroller_d).counter = 5;
   260 		WP(w, scroller_d).height = w->height - 40;
   269 		WP(w, scroller_d).height = w->height - 40;
   261 		break;
   270 		break;
   262 	case WE_PAINT: {
   271 	case WE_PAINT: {
   263 		uint i;
   272 		uint i;
   264 		int y = WP(w, scroller_d).height;
   273 		int y = WP(w, scroller_d).height;
   280 		if (y < 50) WP(w, scroller_d).height = w->height - 40;
   289 		if (y < 50) WP(w, scroller_d).height = w->height - 40;
   281 
   290 
   282 		DoDrawStringCentered(210, w->height - 25, "Website: http://www.openttd.org", TC_BLACK);
   291 		DoDrawStringCentered(210, w->height - 25, "Website: http://www.openttd.org", TC_BLACK);
   283 		DrawStringCentered(210, w->height - 15, STR_00BA_COPYRIGHT_OPENTTD, TC_FROMSTRING);
   292 		DrawStringCentered(210, w->height - 15, STR_00BA_COPYRIGHT_OPENTTD, TC_FROMSTRING);
   284 	} break;
   293 	} break;
   285 	case WE_MOUSELOOP: // Timer to scroll the text and adjust the new top
   294 	case WE_TICK: // Timer to scroll the text and adjust the new top
   286 		if (WP(w, scroller_d).counter++ % 3 == 0) {
   295 		if (--WP(w, scroller_d).counter == 0) {
       
   296 			WP(w, scroller_d).counter = 5;
   287 			WP(w, scroller_d).height--;
   297 			WP(w, scroller_d).height--;
   288 			SetWindowDirty(w);
   298 			SetWindowDirty(w);
   289 		}
   299 		}
   290 		break;
   300 		break;
   291 	}
   301 	}
   336 		int x,y;
   346 		int x,y;
   337 		int i, count;
   347 		int i, count;
   338 
   348 
   339 		DrawWindowWidgets(w);
   349 		DrawWindowWidgets(w);
   340 
   350 
   341 		WP(w,tree_d).base = i = _tree_base_by_landscape[_opt.landscape];
   351 		WP(w, tree_d).base = i = _tree_base_by_landscape[_opt.landscape];
   342 		WP(w,tree_d).count = count = _tree_count_by_landscape[_opt.landscape];
   352 		WP(w, tree_d).count = count = _tree_count_by_landscape[_opt.landscape];
   343 
   353 
   344 		x = 18;
   354 		x = 18;
   345 		y = 54;
   355 		y = 54;
   346 		do {
   356 		do {
   347 			DrawSprite(_tree_sprites[i].sprite, _tree_sprites[i].pal, x, y);
   357 			DrawSprite(_tree_sprites[i].sprite, _tree_sprites[i].pal, x, y);
   362 			break;
   372 			break;
   363 
   373 
   364 		case 3: case 4: case 5: case 6:
   374 		case 3: case 4: case 5: case 6:
   365 		case 7: case 8: case 9: case 10:
   375 		case 7: case 8: case 9: case 10:
   366 		case 11:case 12: case 13: case 14:
   376 		case 11:case 12: case 13: case 14:
   367 			if (wid - 3 >= WP(w,tree_d).count) break;
   377 			if (wid - 3 >= WP(w, tree_d).count) break;
   368 
   378 
   369 			if (HandlePlacePushButton(w, wid, SPR_CURSOR_TREE, VHM_RECT, NULL))
   379 			if (HandlePlacePushButton(w, wid, SPR_CURSOR_TREE, VHM_RECT, NULL))
   370 				_tree_to_plant = WP(w,tree_d).base + wid - 3;
   380 				_tree_to_plant = WP(w, tree_d).base + wid - 3;
   371 			break;
   381 			break;
   372 
   382 
   373 		case 15: // tree of random type.
   383 		case 15: // tree of random type.
   374 			if (HandlePlacePushButton(w, 15, SPR_CURSOR_TREE, VHM_RECT, NULL))
   384 			if (HandlePlacePushButton(w, 15, SPR_CURSOR_TREE, VHM_RECT, NULL))
   375 				_tree_to_plant = -1;
   385 				_tree_to_plant = -1;
   404 	case WE_TIMEOUT:
   414 	case WE_TIMEOUT:
   405 		w->RaiseWidget(16);
   415 		w->RaiseWidget(16);
   406 		break;
   416 		break;
   407 
   417 
   408 	case WE_ABORT_PLACE_OBJ:
   418 	case WE_ABORT_PLACE_OBJ:
   409 		RaiseWindowButtons(w);
   419 		w->RaiseButtons();
   410 		break;
   420 		break;
   411 	}
   421 	}
   412 }
   422 }
   413 
   423 
   414 static const Widget _build_trees_widgets[] = {
   424 static const Widget _build_trees_widgets[] = {
   719  * @param params (optional) up to 5 pieces of additional information that may be
   729  * @param params (optional) up to 5 pieces of additional information that may be
   720  * added to a tooltip; currently only supports parameters of {NUM} (integer) */
   730  * added to a tooltip; currently only supports parameters of {NUM} (integer) */
   721 void GuiShowTooltipsWithArgs(StringID str, uint paramcount, const uint64 params[])
   731 void GuiShowTooltipsWithArgs(StringID str, uint paramcount, const uint64 params[])
   722 {
   732 {
   723 	char buffer[512];
   733 	char buffer[512];
   724 	BoundingRect br;
   734 	Dimension br;
   725 	Window *w;
   735 	Window *w;
   726 	uint i;
   736 	uint i;
   727 	int x, y;
   737 	int x, y;
   728 
   738 
   729 	DeleteWindowById(WC_TOOLTIPS, 0);
   739 	DeleteWindowById(WC_TOOLTIPS, 0);
   770 	bool first = true;
   780 	bool first = true;
   771 
   781 
   772 	b = InlineString(b, STR_000D_ACCEPTS);
   782 	b = InlineString(b, STR_000D_ACCEPTS);
   773 
   783 
   774 	for (CargoID i = 0; i < NUM_CARGO; i++) {
   784 	for (CargoID i = 0; i < NUM_CARGO; i++) {
   775 		if (b >= lastof(_userstring) - 5) break;
   785 		if (b >= lastof(_userstring) - (1 + 2 * 4)) break; // ',' or ' ' and two calls to Utf8Encode()
   776 		switch (sct) {
   786 		switch (sct) {
   777 			case SCT_PASSENGERS_ONLY: if (!IsCargoInClass(i, CC_PASSENGERS)) continue; break;
   787 			case SCT_PASSENGERS_ONLY: if (!IsCargoInClass(i, CC_PASSENGERS)) continue; break;
   778 			case SCT_NON_PASSENGERS_ONLY: if (IsCargoInClass(i, CC_PASSENGERS)) continue; break;
   788 			case SCT_NON_PASSENGERS_ONLY: if (IsCargoInClass(i, CC_PASSENGERS)) continue; break;
   779 			case SCT_ALL: break;
   789 			case SCT_ALL: break;
   780 			default: NOT_REACHED();
   790 			default: NOT_REACHED();
   793 
   803 
   794 	/* If first is still true then no cargo is accepted */
   804 	/* If first is still true then no cargo is accepted */
   795 	if (first) b = InlineString(b, STR_00D0_NOTHING);
   805 	if (first) b = InlineString(b, STR_00D0_NOTHING);
   796 
   806 
   797 	*b = '\0';
   807 	*b = '\0';
       
   808 
       
   809 	/* Make sure we detect any buffer overflow */
       
   810 	assert(b < endof(_userstring));
       
   811 
   798 	DrawStringMultiLine(str_x, str_y, STR_SPEC_USERSTRING, 144);
   812 	DrawStringMultiLine(str_x, str_y, STR_SPEC_USERSTRING, 144);
   799 }
   813 }
   800 
   814 
   801 void DrawStationCoverageAreaText(int sx, int sy, StationCoverageType sct, int rad)
   815 void DrawStationCoverageAreaText(int sx, int sy, StationCoverageType sct, int rad)
   802 {
   816 {
  1014 	switch (e->we.keypress.keycode) {
  1028 	switch (e->we.keypress.keycode) {
  1015 	case WKC_ESC: return 2;
  1029 	case WKC_ESC: return 2;
  1016 	case WKC_RETURN: case WKC_NUM_ENTER: return 1;
  1030 	case WKC_RETURN: case WKC_NUM_ENTER: return 1;
  1017 	case (WKC_CTRL | 'V'):
  1031 	case (WKC_CTRL | 'V'):
  1018 		if (InsertTextBufferClipboard(&string->text))
  1032 		if (InsertTextBufferClipboard(&string->text))
  1019 			InvalidateWidget(w, wid);
  1033 			w->InvalidateWidget(wid);
  1020 		break;
  1034 		break;
  1021 	case (WKC_CTRL | 'U'):
  1035 	case (WKC_CTRL | 'U'):
  1022 		DeleteTextBufferAll(&string->text);
  1036 		DeleteTextBufferAll(&string->text);
  1023 		InvalidateWidget(w, wid);
  1037 		w->InvalidateWidget(wid);
  1024 		break;
  1038 		break;
  1025 	case WKC_BACKSPACE: case WKC_DELETE:
  1039 	case WKC_BACKSPACE: case WKC_DELETE:
  1026 		if (DeleteTextBufferChar(&string->text, e->we.keypress.keycode))
  1040 		if (DeleteTextBufferChar(&string->text, e->we.keypress.keycode))
  1027 			InvalidateWidget(w, wid);
  1041 			w->InvalidateWidget(wid);
  1028 		break;
  1042 		break;
  1029 	case WKC_LEFT: case WKC_RIGHT: case WKC_END: case WKC_HOME:
  1043 	case WKC_LEFT: case WKC_RIGHT: case WKC_END: case WKC_HOME:
  1030 		if (MoveTextBufferPos(&string->text, e->we.keypress.keycode))
  1044 		if (MoveTextBufferPos(&string->text, e->we.keypress.keycode))
  1031 			InvalidateWidget(w, wid);
  1045 			w->InvalidateWidget(wid);
  1032 		break;
  1046 		break;
  1033 	default:
  1047 	default:
  1034 		if (IsValidChar(e->we.keypress.key, string->afilter)) {
  1048 		if (IsValidChar(e->we.keypress.key, string->afilter)) {
  1035 			if (InsertTextBufferChar(&string->text, e->we.keypress.key)) {
  1049 			if (InsertTextBufferChar(&string->text, e->we.keypress.key)) {
  1036 				InvalidateWidget(w, wid);
  1050 				w->InvalidateWidget(wid);
  1037 			}
  1051 			}
  1038 		} else { // key wasn't caught. Continue only if standard entry specified
  1052 		} else { // key wasn't caught. Continue only if standard entry specified
  1039 			e->we.keypress.cont = (string->afilter == CS_ALPHANUMERAL);
  1053 			e->we.keypress.cont = (string->afilter == CS_ALPHANUMERAL);
  1040 		}
  1054 		}
  1041 	}
  1055 	}
  1055 	return false;
  1069 	return false;
  1056 }
  1070 }
  1057 
  1071 
  1058 void HandleEditBox(Window *w, querystr_d *string, int wid)
  1072 void HandleEditBox(Window *w, querystr_d *string, int wid)
  1059 {
  1073 {
  1060 	if (HandleCaret(&string->text)) InvalidateWidget(w, wid);
  1074 	if (HandleCaret(&string->text)) w->InvalidateWidget(wid);
  1061 }
  1075 }
  1062 
  1076 
  1063 void DrawEditBox(Window *w, querystr_d *string, int wid)
  1077 void DrawEditBox(Window *w, querystr_d *string, int wid)
  1064 {
  1078 {
  1065 	DrawPixelInfo dpi, *old_dpi;
  1079 	DrawPixelInfo dpi, *old_dpi;
  1489 			_savegame_sort_dirty = false;
  1503 			_savegame_sort_dirty = false;
  1490 			MakeSortedSaveGameList();
  1504 			MakeSortedSaveGameList();
  1491 		}
  1505 		}
  1492 
  1506 
  1493 		GfxFillRect(w->widget[7].left + 1, w->widget[7].top + 1, w->widget[7].right, w->widget[7].bottom, 0xD7);
  1507 		GfxFillRect(w->widget[7].left + 1, w->widget[7].top + 1, w->widget[7].right, w->widget[7].bottom, 0xD7);
  1494 		DoDrawString(
  1508 		DrawSortButtonState(w, _savegame_sort_order & SORT_BY_NAME ? 2 : 3, _savegame_sort_order & SORT_DESCENDING ? SBS_DOWN : SBS_UP);
  1495 			_savegame_sort_order & SORT_DESCENDING ? DOWNARROW : UPARROW,
       
  1496 			_savegame_sort_order & SORT_BY_NAME ? w->widget[2].right - 9 : w->widget[3].right - 9,
       
  1497 			15, TC_BLACK
       
  1498 		);
       
  1499 
  1509 
  1500 		y = w->widget[7].top + 1;
  1510 		y = w->widget[7].top + 1;
  1501 		for (pos = w->vscroll.pos; pos < _fios_num; pos++) {
  1511 		for (pos = w->vscroll.pos; pos < _fios_num; pos++) {
  1502 			const FiosItem *item = _fios_list + pos;
  1512 			const FiosItem *item = _fios_list + pos;
  1503 
  1513 
  1562 					ShowHeightmapLoad();
  1572 					ShowHeightmapLoad();
  1563 				} else {
  1573 				} else {
  1564 					/* SLD_SAVE_GAME, SLD_SAVE_SCENARIO copy clicked name to editbox */
  1574 					/* SLD_SAVE_GAME, SLD_SAVE_SCENARIO copy clicked name to editbox */
  1565 					ttd_strlcpy(WP(w, querystr_d).text.buf, file->title, WP(w, querystr_d).text.maxlength);
  1575 					ttd_strlcpy(WP(w, querystr_d).text.buf, file->title, WP(w, querystr_d).text.maxlength);
  1566 					UpdateTextBufferSize(&WP(w, querystr_d).text);
  1576 					UpdateTextBufferSize(&WP(w, querystr_d).text);
  1567 					InvalidateWidget(w, 10);
  1577 					w->InvalidateWidget(10);
  1568 				}
  1578 				}
  1569 			} else {
  1579 			} else {
  1570 				/* Changed directory, need repaint. */
  1580 				/* Changed directory, need repaint. */
  1571 				SetWindowDirty(w);
  1581 				SetWindowDirty(w);
  1572 				BuildFileList();
  1582 				BuildFileList();
  1589 			return;
  1599 			return;
  1590 		}
  1600 		}
  1591 
  1601 
  1592 		if (_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO) {
  1602 		if (_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO) {
  1593 			if (HandleEditBoxKey(w, &WP(w, querystr_d), 10, e) == 1) // Press Enter
  1603 			if (HandleEditBoxKey(w, &WP(w, querystr_d), 10, e) == 1) // Press Enter
  1594 					HandleButtonClick(w, 12);
  1604 					w->HandleButtonClick(12);
  1595 		}
  1605 		}
  1596 		break;
  1606 		break;
  1597 	case WE_TIMEOUT:
  1607 	case WE_TIMEOUT:
  1598 		/* This test protects against using widgets 11 and 12 which are only available
  1608 		/* This test protects against using widgets 11 and 12 which are only available
  1599 		 * in those two saveload mode  */
  1609 		 * in those two saveload mode  */
  1659 	WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_STD_BTN | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
  1669 	WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_STD_BTN | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
  1660 	_save_dialog_widgets,
  1670 	_save_dialog_widgets,
  1661 	SaveLoadDlgWndProc,
  1671 	SaveLoadDlgWndProc,
  1662 };
  1672 };
  1663 
  1673 
  1664 void ShowSaveLoadDialog(int mode)
  1674 /** These values are used to convert the file/operations mode into a corresponding file type.
       
  1675  * So each entry, as expressed by the related comment, is based on the enum   */
       
  1676 static const FileType _file_modetotype[] = {
       
  1677 	FT_SAVEGAME,  ///< used for SLD_LOAD_GAME
       
  1678 	FT_SCENARIO,  ///< used for SLD_LOAD_SCENARIO
       
  1679 	FT_SAVEGAME,  ///< used for SLD_SAVE_GAME
       
  1680 	FT_SCENARIO,  ///< used for SLD_SAVE_SCENARIO
       
  1681 	FT_HEIGHTMAP, ///< used for SLD_LOAD_HEIGHTMAP
       
  1682 	FT_SAVEGAME,  ///< SLD_NEW_GAME
       
  1683 };
       
  1684 
       
  1685 void ShowSaveLoadDialog(SaveLoadDialogMode mode)
  1665 {
  1686 {
  1666 	static const StringID saveload_captions[] = {
  1687 	static const StringID saveload_captions[] = {
  1667 		STR_4001_LOAD_GAME,
  1688 		STR_4001_LOAD_GAME,
  1668 		STR_0298_LOAD_SCENARIO,
  1689 		STR_0298_LOAD_SCENARIO,
  1669 		STR_4000_SAVE_GAME,
  1690 		STR_4000_SAVE_GAME,
  1680 	DeleteWindowById(WC_SAVELOAD, 0);
  1701 	DeleteWindowById(WC_SAVELOAD, 0);
  1681 
  1702 
  1682 	_saveload_mode = mode;
  1703 	_saveload_mode = mode;
  1683 	SetBit(_no_scroll, SCROLL_SAVE);
  1704 	SetBit(_no_scroll, SCROLL_SAVE);
  1684 
  1705 
       
  1706 	/* Use an array to define what will be the current file type being handled
       
  1707 	 * by current file mode */
       
  1708 	_file_to_saveload.filetype = _file_modetotype[mode];
  1685 	switch (mode) {
  1709 	switch (mode) {
  1686 		case SLD_SAVE_GAME:     GenerateFileName(); break;
  1710 		case SLD_SAVE_GAME:     GenerateFileName(); break;
  1687 		case SLD_SAVE_SCENARIO: strcpy(_edit_str_buf, "UNNAMED"); break;
  1711 		case SLD_SAVE_SCENARIO: strcpy(_edit_str_buf, "UNNAMED"); break;
  1688 		default:                sld = &_load_dialog_desc; break;
  1712 		default:                sld = &_load_dialog_desc; break;
  1689 	}
  1713 	}
  1845 
  1869 
  1846 static void CheatsWndProc(Window *w, WindowEvent *e)
  1870 static void CheatsWndProc(Window *w, WindowEvent *e)
  1847 {
  1871 {
  1848 	switch (e->event) {
  1872 	switch (e->event) {
  1849 	case WE_PAINT: {
  1873 	case WE_PAINT: {
  1850 		int clk = WP(w,def_d).data_1;
  1874 		int clk = WP(w, def_d).data_1;
  1851 		int x, y;
  1875 		int x, y;
  1852 		int i;
  1876 		int i;
  1853 
  1877 
  1854 		DrawWindowWidgets(w);
  1878 		DrawWindowWidgets(w);
  1855 
  1879 
  1924 
  1948 
  1925 			*ce->been_used = true;
  1949 			*ce->been_used = true;
  1926 
  1950 
  1927 			switch (ce->type) {
  1951 			switch (ce->type) {
  1928 			case SLE_BOOL:
  1952 			case SLE_BOOL:
  1929 				if (ce->flags & CE_CLICK) WP(w,def_d).data_1 = btn * 2 + 1;
  1953 				if (ce->flags & CE_CLICK) WP(w, def_d).data_1 = btn * 2 + 1;
  1930 				value ^= 1;
  1954 				value ^= 1;
  1931 				if (ce->proc != NULL) ce->proc(value, 0);
  1955 				if (ce->proc != NULL) ce->proc(value, 0);
  1932 				break;
  1956 				break;
  1933 			default: {
  1957 			default: {
  1934 				/* Add a dynamic step-size to the scroller. In a maximum of
  1958 				/* Add a dynamic step-size to the scroller. In a maximum of
  1942 
  1966 
  1943 				/* take whatever the function returns */
  1967 				/* take whatever the function returns */
  1944 				value = ce->proc(value, (x >= 30) ? 1 : -1);
  1968 				value = ce->proc(value, (x >= 30) ? 1 : -1);
  1945 
  1969 
  1946 				if (value != oldvalue) {
  1970 				if (value != oldvalue) {
  1947 					WP(w,def_d).data_1 = btn * 2 + 1 + ((x >= 30) ? 1 : 0);
  1971 					WP(w, def_d).data_1 = btn * 2 + 1 + ((x >= 30) ? 1 : 0);
  1948 				}
  1972 				}
  1949 			} break;
  1973 			} break;
  1950 			}
  1974 			}
  1951 
  1975 
  1952 			if (value != oldvalue) {
  1976 			if (value != oldvalue) {
  1958 
  1982 
  1959 			SetWindowDirty(w);
  1983 			SetWindowDirty(w);
  1960 		}
  1984 		}
  1961 		break;
  1985 		break;
  1962 	case WE_TIMEOUT:
  1986 	case WE_TIMEOUT:
  1963 		WP(w,def_d).data_1 = 0;
  1987 		WP(w, def_d).data_1 = 0;
  1964 		SetWindowDirty(w);
  1988 		SetWindowDirty(w);
  1965 		break;
  1989 		break;
  1966 	}
  1990 	}
  1967 }
  1991 }
  1968 
  1992