src/misc_gui.cpp
branchcpp_gui
changeset 6258 a2f86b8fd99b
parent 6251 cd413fa2e252
child 6263 19dab6a68886
equal deleted inserted replaced
6257:2ffe947969ca 6258:a2f86b8fd99b
    47 	LAND_INFO_LINE_BUFF_SIZE = 512,
    47 	LAND_INFO_LINE_BUFF_SIZE = 512,
    48 };
    48 };
    49 
    49 
    50 static char _landinfo_data[LAND_INFO_LINES][LAND_INFO_LINE_BUFF_SIZE];
    50 static char _landinfo_data[LAND_INFO_LINES][LAND_INFO_LINE_BUFF_SIZE];
    51 
    51 
    52 static void LandInfoWndProc(Window *w, WindowEvent *e)
    52 static void LandInfoWndProc(BaseWindow *w, WindowEvent *e)
    53 {
    53 {
    54 	if (e->event == WE_PAINT) {
    54 	if (e->event == WE_PAINT) {
    55 		w->DrawWidgets();
    55 		w->DrawWidgets();
    56 
    56 
    57 		DoDrawStringCentered(140, 16, _landinfo_data[0], 13);
    57 		DoDrawStringCentered(140, 16, _landinfo_data[0], 13);
    62 		if (_landinfo_data[5][0] != '\0') DrawStringMultiCenter(140, 76, BindCString(_landinfo_data[5]), 276);
    62 		if (_landinfo_data[5][0] != '\0') DrawStringMultiCenter(140, 76, BindCString(_landinfo_data[5]), 276);
    63 		if (_landinfo_data[6][0] != '\0') DoDrawStringCentered(140, 71, _landinfo_data[6], 0);
    63 		if (_landinfo_data[6][0] != '\0') DoDrawStringCentered(140, 71, _landinfo_data[6], 0);
    64 	}
    64 	}
    65 }
    65 }
    66 
    66 
    67 static const Widget _land_info_widgets[] = {
    67 static const OldWidget _land_info_widgets[] = {
    68 {   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,                       STR_018B_CLOSE_WINDOW},
    68 {   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,                       STR_018B_CLOSE_WINDOW},
    69 {    WWT_CAPTION,   RESIZE_NONE,    14,    11,   279,     0,    13, STR_01A3_LAND_AREA_INFORMATION, STR_018C_WINDOW_TITLE_DRAG_THIS},
    69 {    WWT_CAPTION,   RESIZE_NONE,    14,    11,   279,     0,    13, STR_01A3_LAND_AREA_INFORMATION, STR_018C_WINDOW_TITLE_DRAG_THIS},
    70 {      WWT_PANEL,   RESIZE_NONE,    14,     0,   279,    14,    92, 0x0,                            STR_NULL},
    70 {      WWT_PANEL,   RESIZE_NONE,    14,     0,   279,    14,    92, 0x0,                            STR_NULL},
    71 {    WIDGETS_END},
    71 {    WIDGETS_END},
    72 };
    72 };
    80 };
    80 };
    81 
    81 
    82 static void Place_LandInfo(TileIndex tile)
    82 static void Place_LandInfo(TileIndex tile)
    83 {
    83 {
    84 	Player *p;
    84 	Player *p;
    85 	Window *w;
    85 	BaseWindow *w;
    86 	Town *t;
    86 	Town *t;
    87 	int64 old_money;
    87 	int64 old_money;
    88 	int64 costclear;
    88 	int64 costclear;
    89 	AcceptedCargo ac;
    89 	AcceptedCargo ac;
    90 	TileDesc td;
    90 	TileDesc td;
    91 	StringID str;
    91 	StringID str;
    92 
    92 
    93 	DeleteWindowById(WC_LAND_INFO, 0);
    93 	DeleteWindowById(WC_LAND_INFO, 0);
    94 
    94 
    95 	w = AllocateWindowDesc(&_land_info_desc);
    95 	w = BaseWindow::Allocate(&_land_info_desc);
    96 	WP(w, void_d).data = &_landinfo_data;
    96 	WP(w, void_d).data = &_landinfo_data;
    97 
    97 
    98 	p = GetPlayer(IsValidPlayer(_local_player) ? _local_player : PLAYER_FIRST);
    98 	p = GetPlayer(IsValidPlayer(_local_player) ? _local_player : PLAYER_FIRST);
    99 	t = ClosestTownFromTile(tile, _patches.dist_local_authority);
    99 	t = ClosestTownFromTile(tile, _patches.dist_local_authority);
   100 
   100 
   242 	"",
   242 	"",
   243 	"And last but not least:",
   243 	"And last but not least:",
   244 	"  Chris Sawyer - For an amazing game!"
   244 	"  Chris Sawyer - For an amazing game!"
   245 };
   245 };
   246 
   246 
   247 static void AboutWindowProc(Window *w, WindowEvent *e)
   247 static void AboutWindowProc(BaseWindow *w, WindowEvent *e)
   248 {
   248 {
   249 	switch (e->event) {
   249 	switch (e->event) {
   250 	case WE_CREATE: /* Set up window counter and start position of scroller */
   250 	case WE_CREATE: /* Set up window counter and start position of scroller */
   251 		WP(w, scroller_d).counter = 0;
   251 		WP(w, scroller_d).counter = 0;
   252 		WP(w, scroller_d).height = w->height - 40;
   252 		WP(w, scroller_d).height = w->height - 40;
   281 		}
   281 		}
   282 		break;
   282 		break;
   283 	}
   283 	}
   284 }
   284 }
   285 
   285 
   286 static const Widget _about_widgets[] = {
   286 static const OldWidget _about_widgets[] = {
   287 {   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,         STR_018B_CLOSE_WINDOW},
   287 {   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,         STR_018B_CLOSE_WINDOW},
   288 {    WWT_CAPTION,   RESIZE_NONE,    14,    11,   419,     0,    13, STR_015B_OPENTTD, STR_NULL},
   288 {    WWT_CAPTION,   RESIZE_NONE,    14,    11,   419,     0,    13, STR_015B_OPENTTD, STR_NULL},
   289 {      WWT_PANEL,   RESIZE_NONE,    14,     0,   419,    14,   271, 0x0,              STR_NULL},
   289 {      WWT_PANEL,   RESIZE_NONE,    14,     0,   419,    14,   271, 0x0,              STR_NULL},
   290 {      WWT_FRAME,   RESIZE_NONE,    14,     5,   414,    40,   245, STR_NULL,         STR_NULL},
   290 {      WWT_FRAME,   RESIZE_NONE,    14,     5,   414,    40,   245, STR_NULL,         STR_NULL},
   291 {    WIDGETS_END},
   291 {    WIDGETS_END},
   301 
   301 
   302 
   302 
   303 void ShowAboutWindow(void)
   303 void ShowAboutWindow(void)
   304 {
   304 {
   305 	DeleteWindowById(WC_GAME_OPTIONS, 0);
   305 	DeleteWindowById(WC_GAME_OPTIONS, 0);
   306 	AllocateWindowDesc(&_about_desc);
   306 	BaseWindow::Allocate(&_about_desc);
   307 }
   307 }
   308 
   308 
   309 static int _tree_to_plant;
   309 static int _tree_to_plant;
   310 
   310 
   311 static const PalSpriteID _tree_sprites[] = {
   311 static const PalSpriteID _tree_sprites[] = {
   319 	{ 0x75F, PAL_NONE }, { 0x774, PAL_NONE }, { 0x720, PAL_NONE }, { 0x797, PAL_NONE },
   319 	{ 0x75F, PAL_NONE }, { 0x774, PAL_NONE }, { 0x720, PAL_NONE }, { 0x797, PAL_NONE },
   320 	{ 0x79E, PAL_NONE }, { 0x7A5, PALETTE_TO_GREEN }, { 0x7AC, PALETTE_TO_RED }, { 0x7B3, PAL_NONE },
   320 	{ 0x79E, PAL_NONE }, { 0x7A5, PALETTE_TO_GREEN }, { 0x7AC, PALETTE_TO_RED }, { 0x7B3, PAL_NONE },
   321 	{ 0x7BA, PAL_NONE }, { 0x7C1, PALETTE_TO_RED, }, { 0x7C8, PALETTE_TO_PALE_GREEN }, { 0x7CF, PALETTE_TO_YELLOW }, { 0x7D6, PALETTE_TO_RED }
   321 	{ 0x7BA, PAL_NONE }, { 0x7C1, PALETTE_TO_RED, }, { 0x7C8, PALETTE_TO_PALE_GREEN }, { 0x7CF, PALETTE_TO_YELLOW }, { 0x7D6, PALETTE_TO_RED }
   322 };
   322 };
   323 
   323 
   324 static void BuildTreesWndProc(Window *w, WindowEvent *e)
   324 static void BuildTreesWndProc(BaseWindow *w, WindowEvent *e)
   325 {
   325 {
   326 	switch (e->event) {
   326 	switch (e->event) {
   327 	case WE_PAINT: {
   327 	case WE_PAINT: {
   328 		int x,y;
   328 		int x,y;
   329 		int i, count;
   329 		int i, count;
   401 		w->RaiseButtons();
   401 		w->RaiseButtons();
   402 		break;
   402 		break;
   403 	}
   403 	}
   404 }
   404 }
   405 
   405 
   406 static const Widget _build_trees_widgets[] = {
   406 static const OldWidget _build_trees_widgets[] = {
   407 {   WWT_CLOSEBOX,   RESIZE_NONE,     7,     0,    10,     0,    13, STR_00C5,              STR_018B_CLOSE_WINDOW},
   407 {   WWT_CLOSEBOX,   RESIZE_NONE,     7,     0,    10,     0,    13, STR_00C5,              STR_018B_CLOSE_WINDOW},
   408 {    WWT_CAPTION,   RESIZE_NONE,     7,    11,   142,     0,    13, STR_2802_TREES,        STR_018C_WINDOW_TITLE_DRAG_THIS},
   408 {    WWT_CAPTION,   RESIZE_NONE,     7,    11,   142,     0,    13, STR_2802_TREES,        STR_018C_WINDOW_TITLE_DRAG_THIS},
   409 {      WWT_PANEL,   RESIZE_NONE,     7,     0,   142,    14,   170, 0x0,                   STR_NULL},
   409 {      WWT_PANEL,   RESIZE_NONE,     7,     0,   142,    14,   170, 0x0,                   STR_NULL},
   410 {      WWT_PANEL,   RESIZE_NONE,    14,     2,    35,    16,    61, 0x0,                   STR_280D_SELECT_TREE_TYPE_TO_PLANT},
   410 {      WWT_PANEL,   RESIZE_NONE,    14,     2,    35,    16,    61, 0x0,                   STR_280D_SELECT_TREE_TYPE_TO_PLANT},
   411 {      WWT_PANEL,   RESIZE_NONE,    14,    37,    70,    16,    61, 0x0,                   STR_280D_SELECT_TREE_TYPE_TO_PLANT},
   411 {      WWT_PANEL,   RESIZE_NONE,    14,    37,    70,    16,    61, 0x0,                   STR_280D_SELECT_TREE_TYPE_TO_PLANT},
   429 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
   429 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
   430 	_build_trees_widgets,
   430 	_build_trees_widgets,
   431 	BuildTreesWndProc
   431 	BuildTreesWndProc
   432 };
   432 };
   433 
   433 
   434 static const Widget _build_trees_scen_widgets[] = {
   434 static const OldWidget _build_trees_scen_widgets[] = {
   435 {   WWT_CLOSEBOX,   RESIZE_NONE,     7,     0,    10,     0,    13, STR_00C5,              STR_018B_CLOSE_WINDOW},
   435 {   WWT_CLOSEBOX,   RESIZE_NONE,     7,     0,    10,     0,    13, STR_00C5,              STR_018B_CLOSE_WINDOW},
   436 {    WWT_CAPTION,   RESIZE_NONE,     7,    11,   142,     0,    13, STR_2802_TREES,        STR_018C_WINDOW_TITLE_DRAG_THIS},
   436 {    WWT_CAPTION,   RESIZE_NONE,     7,    11,   142,     0,    13, STR_2802_TREES,        STR_018C_WINDOW_TITLE_DRAG_THIS},
   437 {      WWT_PANEL,   RESIZE_NONE,     7,     0,   142,    14,   183, 0x0,                   STR_NULL},
   437 {      WWT_PANEL,   RESIZE_NONE,     7,     0,   142,    14,   183, 0x0,                   STR_NULL},
   438 {      WWT_PANEL,   RESIZE_NONE,    14,     2,    35,    16,    61, 0x0,                   STR_280D_SELECT_TREE_TYPE_TO_PLANT},
   438 {      WWT_PANEL,   RESIZE_NONE,    14,     2,    35,    16,    61, 0x0,                   STR_280D_SELECT_TREE_TYPE_TO_PLANT},
   439 {      WWT_PANEL,   RESIZE_NONE,    14,    37,    70,    16,    61, 0x0,                   STR_280D_SELECT_TREE_TYPE_TO_PLANT},
   439 {      WWT_PANEL,   RESIZE_NONE,    14,    37,    70,    16,    61, 0x0,                   STR_280D_SELECT_TREE_TYPE_TO_PLANT},
   462 
   462 
   463 
   463 
   464 void ShowBuildTreesToolbar(void)
   464 void ShowBuildTreesToolbar(void)
   465 {
   465 {
   466 	if (!IsValidPlayer(_current_player)) return;
   466 	if (!IsValidPlayer(_current_player)) return;
   467 	AllocateWindowDescFront(&_build_trees_desc, 0);
   467 	BaseWindow::AllocateFront(&_build_trees_desc, 0);
   468 }
   468 }
   469 
   469 
   470 void ShowBuildTreesScenToolbar(void)
   470 void ShowBuildTreesScenToolbar(void)
   471 {
   471 {
   472 	AllocateWindowDescFront(&_build_trees_scen_desc, 0);
   472 	BaseWindow::AllocateFront(&_build_trees_scen_desc, 0);
   473 }
   473 }
   474 
   474 
   475 static uint32 _errmsg_decode_params[20];
   475 static uint32 _errmsg_decode_params[20];
   476 static StringID _errmsg_message_1, _errmsg_message_2;
   476 static StringID _errmsg_message_1, _errmsg_message_2;
   477 static uint _errmsg_duration;
   477 static uint _errmsg_duration;
   478 
   478 
   479 
   479 
   480 static const Widget _errmsg_widgets[] = {
   480 static const OldWidget _errmsg_widgets[] = {
   481 {   WWT_CLOSEBOX,   RESIZE_NONE,     4,     0,    10,     0,    13, STR_00C5,         STR_018B_CLOSE_WINDOW},
   481 {   WWT_CLOSEBOX,   RESIZE_NONE,     4,     0,    10,     0,    13, STR_00C5,         STR_018B_CLOSE_WINDOW},
   482 {    WWT_CAPTION,   RESIZE_NONE,     4,    11,   239,     0,    13, STR_00B2_MESSAGE, STR_NULL},
   482 {    WWT_CAPTION,   RESIZE_NONE,     4,    11,   239,     0,    13, STR_00B2_MESSAGE, STR_NULL},
   483 {      WWT_PANEL,   RESIZE_NONE,     4,     0,   239,    14,    45, 0x0,              STR_NULL},
   483 {      WWT_PANEL,   RESIZE_NONE,     4,     0,   239,    14,    45, 0x0,              STR_NULL},
   484 {    WIDGETS_END},
   484 {    WIDGETS_END},
   485 };
   485 };
   486 
   486 
   487 static const Widget _errmsg_face_widgets[] = {
   487 static const OldWidget _errmsg_face_widgets[] = {
   488 {   WWT_CLOSEBOX,   RESIZE_NONE,     4,     0,    10,     0,    13, STR_00C5,              STR_018B_CLOSE_WINDOW},
   488 {   WWT_CLOSEBOX,   RESIZE_NONE,     4,     0,    10,     0,    13, STR_00C5,              STR_018B_CLOSE_WINDOW},
   489 {    WWT_CAPTION,   RESIZE_NONE,     4,    11,   333,     0,    13, STR_00B3_MESSAGE_FROM, STR_NULL},
   489 {    WWT_CAPTION,   RESIZE_NONE,     4,    11,   333,     0,    13, STR_00B3_MESSAGE_FROM, STR_NULL},
   490 {      WWT_PANEL,   RESIZE_NONE,     4,     0,   333,    14,   136, 0x0,                   STR_NULL},
   490 {      WWT_PANEL,   RESIZE_NONE,     4,     0,   333,    14,   136, 0x0,                   STR_NULL},
   491 {   WIDGETS_END},
   491 {   WIDGETS_END},
   492 };
   492 };
   493 
   493 
   494 static void ErrmsgWndProc(Window *w, WindowEvent *e)
   494 static void ErrmsgWndProc(BaseWindow *w, WindowEvent *e)
   495 {
   495 {
   496 	switch (e->event) {
   496 	switch (e->event) {
   497 	case WE_PAINT:
   497 	case WE_PAINT:
   498 		COPY_IN_DPARAM(0, _errmsg_decode_params, lengthof(_errmsg_decode_params));
   498 		COPY_IN_DPARAM(0, _errmsg_decode_params, lengthof(_errmsg_decode_params));
   499 		w->DrawWidgets();
   499 		w->DrawWidgets();
   551 	}
   551 	}
   552 }
   552 }
   553 
   553 
   554 void ShowErrorMessage(StringID msg_1, StringID msg_2, int x, int y)
   554 void ShowErrorMessage(StringID msg_1, StringID msg_2, int x, int y)
   555 {
   555 {
   556 	Window *w;
   556 	BaseWindow *w;
   557 	const ViewPort *vp;
   557 	const ViewPort *vp;
   558 	Point pt;
   558 	Point pt;
   559 
   559 
   560 	DeleteWindowById(WC_ERRMSG, 0);
   560 	DeleteWindowById(WC_ERRMSG, 0);
   561 
   561 
   570 
   570 
   571 	if (_errmsg_message_1 != STR_013B_OWNED_BY || GetDParamX(_errmsg_decode_params,2) >= 8) {
   571 	if (_errmsg_message_1 != STR_013B_OWNED_BY || GetDParamX(_errmsg_decode_params,2) >= 8) {
   572 
   572 
   573 		if ( (x|y) != 0) {
   573 		if ( (x|y) != 0) {
   574 			pt = RemapCoords2(x, y);
   574 			pt = RemapCoords2(x, y);
   575 			vp = Window::FindById(WC_MAIN_WINDOW, 0)->viewport;
   575 			vp = BaseWindow::FindById(WC_MAIN_WINDOW, 0)->viewport;
   576 
   576 
   577 			// move x pos to opposite corner
   577 			// move x pos to opposite corner
   578 			pt.x = ((pt.x - vp->virtual_left) >> vp->zoom) + vp->left;
   578 			pt.x = ((pt.x - vp->virtual_left) >> vp->zoom) + vp->left;
   579 			pt.x = (pt.x < (_screen.width >> 1)) ? _screen.width - 260 : 20;
   579 			pt.x = (pt.x < (_screen.width >> 1)) ? _screen.width - 260 : 20;
   580 
   580 
   584 
   584 
   585 		} else {
   585 		} else {
   586 			pt.x = (_screen.width - 240) >> 1;
   586 			pt.x = (_screen.width - 240) >> 1;
   587 			pt.y = (_screen.height - 46) >> 1;
   587 			pt.y = (_screen.height - 46) >> 1;
   588 		}
   588 		}
   589 		w = Window::Allocate(pt.x, pt.y, 240, 46, ErrmsgWndProc, WC_ERRMSG, _errmsg_widgets);
   589 		w = BaseWindow::Allocate(pt.x, pt.y, 240, 46, ErrmsgWndProc, WC_ERRMSG, _errmsg_widgets);
   590 	} else {
   590 	} else {
   591 		if ( (x|y) != 0) {
   591 		if ( (x|y) != 0) {
   592 			pt = RemapCoords2(x, y);
   592 			pt = RemapCoords2(x, y);
   593 			vp = Window::FindById(WC_MAIN_WINDOW, 0)->viewport;
   593 			vp = BaseWindow::FindById(WC_MAIN_WINDOW, 0)->viewport;
   594 			pt.x = clamp(((pt.x - vp->virtual_left) >> vp->zoom) + vp->left - (334/2), 0, _screen.width - 334);
   594 			pt.x = clamp(((pt.x - vp->virtual_left) >> vp->zoom) + vp->left - (334/2), 0, _screen.width - 334);
   595 			pt.y = clamp(((pt.y - vp->virtual_top) >> vp->zoom) + vp->top - (137/2), 22, _screen.height - 137);
   595 			pt.y = clamp(((pt.y - vp->virtual_top) >> vp->zoom) + vp->top - (137/2), 22, _screen.height - 137);
   596 		} else {
   596 		} else {
   597 			pt.x = (_screen.width - 334) >> 1;
   597 			pt.x = (_screen.width - 334) >> 1;
   598 			pt.y = (_screen.height - 137) >> 1;
   598 			pt.y = (_screen.height - 137) >> 1;
   599 		}
   599 		}
   600 		w = Window::Allocate(pt.x, pt.y, 334, 137, ErrmsgWndProc, WC_ERRMSG, _errmsg_face_widgets);
   600 		w = BaseWindow::Allocate(pt.x, pt.y, 334, 137, ErrmsgWndProc, WC_ERRMSG, _errmsg_face_widgets);
   601 	}
   601 	}
   602 
   602 
   603 	w->desc_flags = WDF_STD_BTN | WDF_DEF_WIDGET;
   603 	w->desc_flags = WDF_STD_BTN | WDF_DEF_WIDGET;
   604 }
   604 }
   605 
   605 
   636 
   636 
   637 	SetDParam(0, cost);
   637 	SetDParam(0, cost);
   638 	AddTextEffect(STR_FEEDER, pt.x, pt.y, 0x250);
   638 	AddTextEffect(STR_FEEDER, pt.x, pt.y, 0x250);
   639 }
   639 }
   640 
   640 
   641 static const Widget _tooltips_widgets[] = {
   641 static const OldWidget _tooltips_widgets[] = {
   642 {      WWT_PANEL,   RESIZE_NONE,    14,     0,   199,     0,    31, 0x0, STR_NULL},
   642 {      WWT_PANEL,   RESIZE_NONE,    14,     0,   199,     0,    31, 0x0, STR_NULL},
   643 {   WIDGETS_END},
   643 {   WIDGETS_END},
   644 };
   644 };
   645 
   645 
   646 
   646 
   647 static void TooltipsWndProc(Window *w, WindowEvent *e)
   647 static void TooltipsWndProc(BaseWindow *w, WindowEvent *e)
   648 {
   648 {
   649 	switch (e->event) {
   649 	switch (e->event) {
   650 		case WE_PAINT: {
   650 		case WE_PAINT: {
   651 			uint arg;
   651 			uint arg;
   652 			GfxFillRect(0, 0, w->width - 1, w->height - 1, 0);
   652 			GfxFillRect(0, 0, w->width - 1, w->height - 1, 0);
   678 * added to a tooltip; currently only supports parameters of {NUM} (integer) */
   678 * added to a tooltip; currently only supports parameters of {NUM} (integer) */
   679 void GuiShowTooltipsWithArgs(StringID str, uint paramcount, const uint32 params[])
   679 void GuiShowTooltipsWithArgs(StringID str, uint paramcount, const uint32 params[])
   680 {
   680 {
   681 	char buffer[512];
   681 	char buffer[512];
   682 	BoundingRect br;
   682 	BoundingRect br;
   683 	Window *w;
   683 	BaseWindow *w;
   684 	uint i;
   684 	uint i;
   685 	int x, y;
   685 	int x, y;
   686 
   686 
   687 	DeleteWindowById(WC_TOOLTIPS, 0);
   687 	DeleteWindowById(WC_TOOLTIPS, 0);
   688 
   688 
   706 	 * go below window, flip it so it is shown above the cursor */
   706 	 * go below window, flip it so it is shown above the cursor */
   707 	y = clamp(_cursor.pos.y + _cursor.size.y + _cursor.offs.y + 5, 22, _screen.height - 12);
   707 	y = clamp(_cursor.pos.y + _cursor.size.y + _cursor.offs.y + 5, 22, _screen.height - 12);
   708 	if (y + br.height > _screen.height - 12) y = _cursor.pos.y + _cursor.offs.y - br.height - 5;
   708 	if (y + br.height > _screen.height - 12) y = _cursor.pos.y + _cursor.offs.y - br.height - 5;
   709 	x = clamp(_cursor.pos.x - (br.width >> 1), 0, _screen.width - br.width);
   709 	x = clamp(_cursor.pos.x - (br.width >> 1), 0, _screen.width - br.width);
   710 
   710 
   711 	w = Window::Allocate(x, y, br.width, br.height, TooltipsWndProc, WC_TOOLTIPS, _tooltips_widgets);
   711 	w = BaseWindow::Allocate(x, y, br.width, br.height, TooltipsWndProc, WC_TOOLTIPS, _tooltips_widgets);
   712 
   712 
   713 	WP(w, tooltips_d).string_id = str;
   713 	WP(w, tooltips_d).string_id = str;
   714 	assert(sizeof(WP(w, tooltips_d).params[0]) == sizeof(params[0]));
   714 	assert(sizeof(WP(w, tooltips_d).params[0]) == sizeof(params[0]));
   715 	memcpy(WP(w, tooltips_d).params, params, sizeof(WP(w, tooltips_d).params[0]) * paramcount);
   715 	memcpy(WP(w, tooltips_d).params, params, sizeof(WP(w, tooltips_d).params[0]) * paramcount);
   716 	WP(w, tooltips_d).paramcount = paramcount;
   716 	WP(w, tooltips_d).paramcount = paramcount;
   758 		GetAcceptanceAroundTiles(accepts, tile, _thd.size.x / TILE_SIZE, _thd.size.y / TILE_SIZE , rad);
   758 		GetAcceptanceAroundTiles(accepts, tile, _thd.size.x / TILE_SIZE, _thd.size.y / TILE_SIZE , rad);
   759 		DrawStationCoverageText(accepts, sx, sy, mask);
   759 		DrawStationCoverageText(accepts, sx, sy, mask);
   760 	}
   760 	}
   761 }
   761 }
   762 
   762 
   763 void CheckRedrawStationCoverage(const Window *w)
   763 void CheckRedrawStationCoverage(const BaseWindow *w)
   764 {
   764 {
   765 	if (_thd.dirty & 1) {
   765 	if (_thd.dirty & 1) {
   766 		_thd.dirty &= ~1;
   766 		_thd.dirty &= ~1;
   767 		w->SetDirty();
   767 		w->SetDirty();
   768 	}
   768 	}
   769 }
   769 }
   770 
   770 
   771 void SetVScrollCount(Window *w, int num)
   771 void SetVScrollCount(BaseWindow *w, int num)
   772 {
   772 {
   773 	w->vscroll.count = num;
   773 	w->vscroll.count = num;
   774 	num -= w->vscroll.cap;
   774 	num -= w->vscroll.cap;
   775 	if (num < 0) num = 0;
   775 	if (num < 0) num = 0;
   776 	if (num < w->vscroll.pos) w->vscroll.pos = num;
   776 	if (num < w->vscroll.pos) w->vscroll.pos = num;
   777 }
   777 }
   778 
   778 
   779 void SetVScroll2Count(Window *w, int num)
   779 void SetVScroll2Count(BaseWindow *w, int num)
   780 {
   780 {
   781 	w->vscroll2.count = num;
   781 	w->vscroll2.count = num;
   782 	num -= w->vscroll2.cap;
   782 	num -= w->vscroll2.cap;
   783 	if (num < 0) num = 0;
   783 	if (num < 0) num = 0;
   784 	if (num < w->vscroll2.pos) w->vscroll2.pos = num;
   784 	if (num < w->vscroll2.pos) w->vscroll2.pos = num;
   785 }
   785 }
   786 
   786 
   787 void SetHScrollCount(Window *w, int num)
   787 void SetHScrollCount(BaseWindow *w, int num)
   788 {
   788 {
   789 	w->hscroll.count = num;
   789 	w->hscroll.count = num;
   790 	num -= w->hscroll.cap;
   790 	num -= w->hscroll.cap;
   791 	if (num < 0) num = 0;
   791 	if (num < 0) num = 0;
   792 	if (num < w->hscroll.pos) w->hscroll.pos = num;
   792 	if (num < w->hscroll.pos) w->hscroll.pos = num;
   960 
   960 
   961 	tb->caretpos = tb->length;
   961 	tb->caretpos = tb->length;
   962 	tb->caretxoffs = tb->width;
   962 	tb->caretxoffs = tb->width;
   963 }
   963 }
   964 
   964 
   965 int HandleEditBoxKey(Window *w, querystr_d *string, int wid, WindowEvent *e)
   965 int HandleEditBoxKey(BaseWindow *w, querystr_d *string, int wid, WindowEvent *e)
   966 {
   966 {
   967 	e->we.keypress.cont = false;
   967 	e->we.keypress.cont = false;
   968 
   968 
   969 	switch (e->we.keypress.keycode) {
   969 	switch (e->we.keypress.keycode) {
   970 	case WKC_ESC: return 2;
   970 	case WKC_ESC: return 2;
  1008 		return true;
  1008 		return true;
  1009 	}
  1009 	}
  1010 	return false;
  1010 	return false;
  1011 }
  1011 }
  1012 
  1012 
  1013 void HandleEditBox(Window *w, querystr_d *string, int wid)
  1013 void HandleEditBox(BaseWindow *w, querystr_d *string, int wid)
  1014 {
  1014 {
  1015 	if (HandleCaret(&string->text)) w->InvalidateWidget(wid);
  1015 	if (HandleCaret(&string->text)) w->InvalidateWidget(wid);
  1016 }
  1016 }
  1017 
  1017 
  1018 void DrawEditBox(Window *w, querystr_d *string, int wid)
  1018 void DrawEditBox(BaseWindow *w, querystr_d *string, int wid)
  1019 {
  1019 {
  1020 	DrawPixelInfo dpi, *old_dpi;
  1020 	DrawPixelInfo dpi, *old_dpi;
  1021 	int delta;
  1021 	int delta;
  1022 	const Widget *wi = &w->widget[wid];
  1022 	const OldWidget *wi = &w->widget[wid];
  1023 	const Textbuf *tb = &string->text;
  1023 	const Textbuf *tb = &string->text;
  1024 
  1024 
  1025 	GfxFillRect(wi->left + 1, wi->top + 1, wi->right - 1, wi->bottom - 1, 215);
  1025 	GfxFillRect(wi->left + 1, wi->top + 1, wi->right - 1, wi->bottom - 1, 215);
  1026 
  1026 
  1027 	/* Limit the drawing of the string inside the widget boundaries */
  1027 	/* Limit the drawing of the string inside the widget boundaries */
  1053 	QUERY_STR_WIDGET_CANCEL,
  1053 	QUERY_STR_WIDGET_CANCEL,
  1054 	QUERY_STR_WIDGET_OK
  1054 	QUERY_STR_WIDGET_OK
  1055 };
  1055 };
  1056 
  1056 
  1057 
  1057 
  1058 static void QueryStringWndProc(Window *w, WindowEvent *e)
  1058 static void QueryStringWndProc(BaseWindow *w, WindowEvent *e)
  1059 {
  1059 {
  1060 	querystr_d *qs = &WP(w, querystr_d);
  1060 	querystr_d *qs = &WP(w, querystr_d);
  1061 
  1061 
  1062 	switch (e->event) {
  1062 	switch (e->event) {
  1063 		case WE_CREATE:
  1063 		case WE_CREATE:
  1074 		case WE_CLICK:
  1074 		case WE_CLICK:
  1075 			switch (e->we.click.widget) {
  1075 			switch (e->we.click.widget) {
  1076 				case QUERY_STR_WIDGET_OK:
  1076 				case QUERY_STR_WIDGET_OK:
  1077 		press_ok:;
  1077 		press_ok:;
  1078 					if (qs->orig == NULL || strcmp(qs->text.buf, qs->orig) != 0) {
  1078 					if (qs->orig == NULL || strcmp(qs->text.buf, qs->orig) != 0) {
  1079 						Window *parent = w->parent;
  1079 						BaseWindow *parent = w->parent;
  1080 						qs->handled = true;
  1080 						qs->handled = true;
  1081 
  1081 
  1082 						/* If the parent is NULL, the editbox is handled by general function
  1082 						/* If the parent is NULL, the editbox is handled by general function
  1083 						 * HandleOnEditText */
  1083 						 * HandleOnEditText */
  1084 						if (parent != NULL) {
  1084 						if (parent != NULL) {
  1109 			break;
  1109 			break;
  1110 
  1110 
  1111 		case WE_DESTROY: /* Call cancellation of query, if we have not handled it before */
  1111 		case WE_DESTROY: /* Call cancellation of query, if we have not handled it before */
  1112 			if (!qs->handled && w->parent != NULL) {
  1112 			if (!qs->handled && w->parent != NULL) {
  1113 				WindowEvent e;
  1113 				WindowEvent e;
  1114 				Window *parent = w->parent;
  1114 				BaseWindow *parent = w->parent;
  1115 
  1115 
  1116 				qs->handled = true;
  1116 				qs->handled = true;
  1117 				e.event = WE_ON_EDIT_TEXT_CANCEL;
  1117 				e.event = WE_ON_EDIT_TEXT_CANCEL;
  1118 				parent->wndproc(parent, &e);
  1118 				parent->wndproc(parent, &e);
  1119 			}
  1119 			}
  1120 			CLRBIT(_no_scroll, SCROLL_EDIT);
  1120 			CLRBIT(_no_scroll, SCROLL_EDIT);
  1121 			break;
  1121 			break;
  1122 		}
  1122 		}
  1123 }
  1123 }
  1124 
  1124 
  1125 static const Widget _query_string_widgets[] = {
  1125 static const OldWidget _query_string_widgets[] = {
  1126 {   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,        STR_018B_CLOSE_WINDOW},
  1126 {   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,        STR_018B_CLOSE_WINDOW},
  1127 {    WWT_CAPTION,   RESIZE_NONE,    14,    11,   259,     0,    13, STR_012D,        STR_NULL},
  1127 {    WWT_CAPTION,   RESIZE_NONE,    14,    11,   259,     0,    13, STR_012D,        STR_NULL},
  1128 {      WWT_PANEL,   RESIZE_NONE,    14,     0,   259,    14,    29, 0x0,             STR_NULL},
  1128 {      WWT_PANEL,   RESIZE_NONE,    14,     0,   259,    14,    29, 0x0,             STR_NULL},
  1129 {      WWT_PANEL,   RESIZE_NONE,    14,     2,   257,    16,    27, 0x0,             STR_NULL},
  1129 {      WWT_PANEL,   RESIZE_NONE,    14,     2,   257,    16,    27, 0x0,             STR_NULL},
  1130 {    WWT_TEXTBTN,   RESIZE_NONE,    14,     0,   129,    30,    41, STR_012E_CANCEL, STR_NULL},
  1130 {    WWT_TEXTBTN,   RESIZE_NONE,    14,     0,   129,    30,    41, STR_012E_CANCEL, STR_NULL},
  1146  * @param str StringID for the text shown in the textbox
  1146  * @param str StringID for the text shown in the textbox
  1147  * @param caption StringID of text shown in caption of querywindow
  1147  * @param caption StringID of text shown in caption of querywindow
  1148  * @param maxlen maximum length in characters allowed. If bit 12 is set we
  1148  * @param maxlen maximum length in characters allowed. If bit 12 is set we
  1149  * will not check the resulting string against to original string to return success
  1149  * will not check the resulting string against to original string to return success
  1150  * @param maxwidth maximum width in pixels allowed
  1150  * @param maxwidth maximum width in pixels allowed
  1151  * @param parent pointer to a Window that will handle the events (ok/cancel) of this
  1151  * @param parent pointer to a BaseWindow that will handle the events (ok/cancel) of this
  1152  * window. If NULL, results are handled by global function HandleOnEditText
  1152  * window. If NULL, results are handled by global function HandleOnEditText
  1153  * @param afilter filters out unwanted character input */
  1153  * @param afilter filters out unwanted character input */
  1154 void ShowQueryString(StringID str, StringID caption, uint maxlen, uint maxwidth, Window *parent, CharSetFilter afilter)
  1154 void ShowQueryString(StringID str, StringID caption, uint maxlen, uint maxwidth, BaseWindow *parent, CharSetFilter afilter)
  1155 {
  1155 {
  1156 	static char orig_str_buf[lengthof(_edit_str_buf)];
  1156 	static char orig_str_buf[lengthof(_edit_str_buf)];
  1157 	Window *w;
  1157 	BaseWindow *w;
  1158 	uint realmaxlen = maxlen & ~0x1000;
  1158 	uint realmaxlen = maxlen & ~0x1000;
  1159 
  1159 
  1160 	assert(realmaxlen < lengthof(_edit_str_buf));
  1160 	assert(realmaxlen < lengthof(_edit_str_buf));
  1161 
  1161 
  1162 	DeleteWindowById(WC_QUERY_STRING, 0);
  1162 	DeleteWindowById(WC_QUERY_STRING, 0);
  1163 	DeleteWindowById(WC_SAVELOAD, 0);
  1163 	DeleteWindowById(WC_SAVELOAD, 0);
  1164 
  1164 
  1165 	w = AllocateWindowDesc(&_query_string_desc);
  1165 	w = BaseWindow::Allocate(&_query_string_desc);
  1166 	w->parent = parent;
  1166 	w->parent = parent;
  1167 
  1167 
  1168 	GetString(_edit_str_buf, str, lastof(_edit_str_buf));
  1168 	GetString(_edit_str_buf, str, lastof(_edit_str_buf));
  1169 	_edit_str_buf[realmaxlen - 1] = '\0';
  1169 	_edit_str_buf[realmaxlen - 1] = '\0';
  1170 
  1170 
  1188 	QUERY_WIDGET_YES
  1188 	QUERY_WIDGET_YES
  1189 };
  1189 };
  1190 
  1190 
  1191 
  1191 
  1192 typedef struct query_d {
  1192 typedef struct query_d {
  1193 	void (*proc)(Window*, bool); ///< callback function executed on closing of popup. Window* points to parent, bool is true if 'yes' clicked, false otherwise
  1193 	void (*proc)(BaseWindow*, bool); ///< callback function executed on closing of popup. BaseWindow* points to parent, bool is true if 'yes' clicked, false otherwise
  1194 	StringID message;            ///< message shown for query window
  1194 	StringID message;            ///< message shown for query window
  1195 	uint32 params[20];           ///< local copy of _decode_parameters
  1195 	uint32 params[20];           ///< local copy of _decode_parameters
  1196 	bool calledback;             ///< has callback been executed already (internal usage for WE_DESTROY event)
  1196 	bool calledback;             ///< has callback been executed already (internal usage for WE_DESTROY event)
  1197 } query_d;
  1197 } query_d;
  1198 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(query_d));
  1198 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(query_d));
  1199 
  1199 
  1200 
  1200 
  1201 static void QueryWndProc(Window *w, WindowEvent *e)
  1201 static void QueryWndProc(BaseWindow *w, WindowEvent *e)
  1202 {
  1202 {
  1203 	query_d *q = &WP(w, query_d);
  1203 	query_d *q = &WP(w, query_d);
  1204 
  1204 
  1205 	switch (e->event) {
  1205 	switch (e->event) {
  1206 		case WE_PAINT:
  1206 		case WE_PAINT:
  1245 			break;
  1245 			break;
  1246 	}
  1246 	}
  1247 }
  1247 }
  1248 
  1248 
  1249 
  1249 
  1250 static const Widget _query_widgets[] = {
  1250 static const OldWidget _query_widgets[] = {
  1251 {  WWT_CLOSEBOX, RESIZE_NONE,  4,   0,  10,   0,  13, STR_00C5,        STR_018B_CLOSE_WINDOW},
  1251 {  WWT_CLOSEBOX, RESIZE_NONE,  4,   0,  10,   0,  13, STR_00C5,        STR_018B_CLOSE_WINDOW},
  1252 {   WWT_CAPTION, RESIZE_NONE,  4,  11, 209,   0,  13, STR_NULL,        STR_NULL},
  1252 {   WWT_CAPTION, RESIZE_NONE,  4,  11, 209,   0,  13, STR_NULL,        STR_NULL},
  1253 {     WWT_PANEL, RESIZE_NONE,  4,   0, 209,  14,  81, 0x0, /*OVERRIDE*/STR_NULL},
  1253 {     WWT_PANEL, RESIZE_NONE,  4,   0, 209,  14,  81, 0x0, /*OVERRIDE*/STR_NULL},
  1254 {WWT_PUSHTXTBTN, RESIZE_NONE,  3,  20,  90,  62,  73, STR_00C9_NO,     STR_NULL},
  1254 {WWT_PUSHTXTBTN, RESIZE_NONE,  3,  20,  90,  62,  73, STR_00C9_NO,     STR_NULL},
  1255 {WWT_PUSHTXTBTN, RESIZE_NONE,  3, 120, 190,  62,  73, STR_00C8_YES,    STR_NULL},
  1255 {WWT_PUSHTXTBTN, RESIZE_NONE,  3, 120, 190,  62,  73, STR_00C8_YES,    STR_NULL},
  1271  * @param message string that will be shown for the window
  1271  * @param message string that will be shown for the window
  1272  * @param parent pointer to parent window, if this pointer is NULL the parent becomes
  1272  * @param parent pointer to parent window, if this pointer is NULL the parent becomes
  1273  * the main window WC_MAIN_WINDOW
  1273  * the main window WC_MAIN_WINDOW
  1274  * @param x,y coordinates to show the window at
  1274  * @param x,y coordinates to show the window at
  1275  * @param yes_no_callback callback function called when window is closed through any button */
  1275  * @param yes_no_callback callback function called when window is closed through any button */
  1276 void ShowQuery(StringID caption, StringID message, Window *parent, void (*callback)(Window*, bool))
  1276 void ShowQuery(StringID caption, StringID message, BaseWindow *parent, void (*callback)(BaseWindow*, bool))
  1277 {
  1277 {
  1278 	Window *w = AllocateWindowDesc(&_query_desc);
  1278 	BaseWindow *w = BaseWindow::Allocate(&_query_desc);
  1279 	if (w == NULL) return;
  1279 	if (w == NULL) return;
  1280 
  1280 
  1281 	if (parent == NULL) parent = Window::FindById(WC_MAIN_WINDOW, 0);
  1281 	if (parent == NULL) parent = BaseWindow::FindById(WC_MAIN_WINDOW, 0);
  1282 	w->parent = parent;
  1282 	w->parent = parent;
  1283 	w->left = parent->left + (parent->width / 2) - (w->width / 2);
  1283 	w->left = parent->left + (parent->width / 2) - (w->width / 2);
  1284 	w->top = parent->top + (parent->height / 2) - (w->height / 2);
  1284 	w->top = parent->top + (parent->height / 2) - (w->height / 2);
  1285 
  1285 
  1286 	/* Create a backup of the variadic arguments to strings because it will be
  1286 	/* Create a backup of the variadic arguments to strings because it will be
  1291 	WP(w, query_d).proc       = callback;
  1291 	WP(w, query_d).proc       = callback;
  1292 	WP(w, query_d).calledback = false;
  1292 	WP(w, query_d).calledback = false;
  1293 }
  1293 }
  1294 
  1294 
  1295 
  1295 
  1296 static const Widget _load_dialog_widgets[] = {
  1296 static const OldWidget _load_dialog_widgets[] = {
  1297 {   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,         STR_018B_CLOSE_WINDOW},
  1297 {   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,         STR_018B_CLOSE_WINDOW},
  1298 {    WWT_CAPTION,  RESIZE_RIGHT,    14,    11,   256,     0,    13, STR_NULL,         STR_018C_WINDOW_TITLE_DRAG_THIS},
  1298 {    WWT_CAPTION,  RESIZE_RIGHT,    14,    11,   256,     0,    13, STR_NULL,         STR_018C_WINDOW_TITLE_DRAG_THIS},
  1299 { WWT_PUSHTXTBTN,   RESIZE_NONE,    14,     0,   127,    14,    25, STR_SORT_BY_NAME, STR_SORT_ORDER_TIP},
  1299 { WWT_PUSHTXTBTN,   RESIZE_NONE,    14,     0,   127,    14,    25, STR_SORT_BY_NAME, STR_SORT_ORDER_TIP},
  1300 { WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   128,   256,    14,    25, STR_SORT_BY_DATE, STR_SORT_ORDER_TIP},
  1300 { WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   128,   256,    14,    25, STR_SORT_BY_DATE, STR_SORT_ORDER_TIP},
  1301 {      WWT_PANEL,  RESIZE_RIGHT,    14,     0,   256,    26,    47, 0x0,              STR_NULL},
  1301 {      WWT_PANEL,  RESIZE_RIGHT,    14,     0,   256,    26,    47, 0x0,              STR_NULL},
  1305 {  WWT_SCROLLBAR,    RESIZE_LRB,    14,   245,   256,    60,   281, 0x0,              STR_0190_SCROLL_BAR_SCROLLS_LIST},
  1305 {  WWT_SCROLLBAR,    RESIZE_LRB,    14,   245,   256,    60,   281, 0x0,              STR_0190_SCROLL_BAR_SCROLLS_LIST},
  1306 {  WWT_RESIZEBOX,   RESIZE_LRTB,    14,   245,   256,   282,   293, 0x0,              STR_RESIZE_BUTTON},
  1306 {  WWT_RESIZEBOX,   RESIZE_LRTB,    14,   245,   256,   282,   293, 0x0,              STR_RESIZE_BUTTON},
  1307 {   WIDGETS_END},
  1307 {   WIDGETS_END},
  1308 };
  1308 };
  1309 
  1309 
  1310 static const Widget _save_dialog_widgets[] = {
  1310 static const OldWidget _save_dialog_widgets[] = {
  1311 {   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,         STR_018B_CLOSE_WINDOW},
  1311 {   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,         STR_018B_CLOSE_WINDOW},
  1312 {    WWT_CAPTION,  RESIZE_RIGHT,    14,    11,   256,     0,    13, STR_NULL,         STR_018C_WINDOW_TITLE_DRAG_THIS},
  1312 {    WWT_CAPTION,  RESIZE_RIGHT,    14,    11,   256,     0,    13, STR_NULL,         STR_018C_WINDOW_TITLE_DRAG_THIS},
  1313 { WWT_PUSHTXTBTN,   RESIZE_NONE,    14,     0,   127,    14,    25, STR_SORT_BY_NAME, STR_SORT_ORDER_TIP},
  1313 { WWT_PUSHTXTBTN,   RESIZE_NONE,    14,     0,   127,    14,    25, STR_SORT_BY_NAME, STR_SORT_ORDER_TIP},
  1314 { WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   128,   256,    14,    25, STR_SORT_BY_DATE, STR_SORT_ORDER_TIP},
  1314 { WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   128,   256,    14,    25, STR_SORT_BY_DATE, STR_SORT_ORDER_TIP},
  1315 {      WWT_PANEL,  RESIZE_RIGHT,    14,     0,   256,    26,    47, 0x0,              STR_NULL},
  1315 {      WWT_PANEL,  RESIZE_RIGHT,    14,     0,   256,    26,    47, 0x0,              STR_NULL},
  1397 	GetString(_edit_str_buf, STR_4004, lastof(_edit_str_buf));
  1397 	GetString(_edit_str_buf, STR_4004, lastof(_edit_str_buf));
  1398 }
  1398 }
  1399 
  1399 
  1400 extern void StartupEngines(void);
  1400 extern void StartupEngines(void);
  1401 
  1401 
  1402 static void SaveLoadDlgWndProc(Window *w, WindowEvent *e)
  1402 static void SaveLoadDlgWndProc(BaseWindow *w, WindowEvent *e)
  1403 {
  1403 {
  1404 	static FiosItem o_dir;
  1404 	static FiosItem o_dir;
  1405 
  1405 
  1406 	switch (e->event) {
  1406 	switch (e->event) {
  1407 	case WE_CREATE: { /* Set up OPENTTD button */
  1407 	case WE_CREATE: { /* Set up OPENTTD button */
  1575 		}
  1575 		}
  1576 		FiosFreeSavegameList();
  1576 		FiosFreeSavegameList();
  1577 		CLRBIT(_no_scroll, SCROLL_SAVE);
  1577 		CLRBIT(_no_scroll, SCROLL_SAVE);
  1578 		break;
  1578 		break;
  1579 	case WE_RESIZE: {
  1579 	case WE_RESIZE: {
  1580 		/* Widget 2 and 3 have to go with halve speed, make it so obiwan */
  1580 		/* OldWidget 2 and 3 have to go with halve speed, make it so obiwan */
  1581 		uint diff = e->we.sizing.diff.x / 2;
  1581 		uint diff = e->we.sizing.diff.x / 2;
  1582 		w->widget[2].right += diff;
  1582 		w->widget[2].right += diff;
  1583 		w->widget[3].left  += diff;
  1583 		w->widget[3].left  += diff;
  1584 		w->widget[3].right += e->we.sizing.diff.x;
  1584 		w->widget[3].right += e->we.sizing.diff.x;
  1585 
  1585 
  1619 		STR_4000_SAVE_GAME,
  1619 		STR_4000_SAVE_GAME,
  1620 		STR_0299_SAVE_SCENARIO,
  1620 		STR_0299_SAVE_SCENARIO,
  1621 		STR_4011_LOAD_HEIGHTMAP,
  1621 		STR_4011_LOAD_HEIGHTMAP,
  1622 	};
  1622 	};
  1623 
  1623 
  1624 	Window *w;
  1624 	BaseWindow *w;
  1625 	const WindowDesc *sld = &_save_dialog_desc;
  1625 	const WindowDesc *sld = &_save_dialog_desc;
  1626 
  1626 
  1627 
  1627 
  1628 	SetObjectToPlace(SPR_CURSOR_ZZZ, PAL_NONE, 0, WC_MAIN_WINDOW, 0);
  1628 	SetObjectToPlace(SPR_CURSOR_ZZZ, PAL_NONE, 0, WC_MAIN_WINDOW, 0);
  1629 	DeleteWindowById(WC_QUERY_STRING, 0);
  1629 	DeleteWindowById(WC_QUERY_STRING, 0);
  1637 		case SLD_SAVE_SCENARIO: strcpy(_edit_str_buf, "UNNAMED"); break;
  1637 		case SLD_SAVE_SCENARIO: strcpy(_edit_str_buf, "UNNAMED"); break;
  1638 		default:                sld = &_load_dialog_desc; break;
  1638 		default:                sld = &_load_dialog_desc; break;
  1639 	}
  1639 	}
  1640 
  1640 
  1641 	assert((uint)mode < lengthof(saveload_captions));
  1641 	assert((uint)mode < lengthof(saveload_captions));
  1642 	w = AllocateWindowDesc(sld);
  1642 	w = BaseWindow::Allocate(sld);
  1643 	w->widget[1].data = saveload_captions[mode];
  1643 	w->widget[1].data = saveload_captions[mode];
  1644 	w->vscroll.cap = 24;
  1644 	w->vscroll.cap = 24;
  1645 	w->resize.step_width = 2;
  1645 	w->resize.step_width = 2;
  1646 	w->resize.step_height = 10;
  1646 	w->resize.step_height = 10;
  1647 	w->resize.height = w->height - 14 * 10; // Minimum of 10 items
  1647 	w->resize.height = w->height - 14 * 10; // Minimum of 10 items
  1661 	ResetObjectToPlace();
  1661 	ResetObjectToPlace();
  1662 }
  1662 }
  1663 
  1663 
  1664 void RedrawAutosave(void)
  1664 void RedrawAutosave(void)
  1665 {
  1665 {
  1666 	Window::SetDirtyById(WC_STATUS_BAR, 0);
  1666 	BaseWindow::SetDirtyById(WC_STATUS_BAR, 0);
  1667 }
  1667 }
  1668 
  1668 
  1669 void SetFiosType(const byte fiostype)
  1669 void SetFiosType(const byte fiostype)
  1670 {
  1670 {
  1671 	switch (fiostype) {
  1671 	switch (fiostype) {
  1737 
  1737 
  1738 	if ((ymd.year == MIN_YEAR && p2 == -1) || (ymd.year == MAX_YEAR && p2 == 1)) return _cur_year;
  1738 	if ((ymd.year == MIN_YEAR && p2 == -1) || (ymd.year == MAX_YEAR && p2 == 1)) return _cur_year;
  1739 
  1739 
  1740 	SetDate(ConvertYMDToDate(_cur_year + p2, ymd.month, ymd.day));
  1740 	SetDate(ConvertYMDToDate(_cur_year + p2, ymd.month, ymd.day));
  1741 	EnginesMonthlyLoop();
  1741 	EnginesMonthlyLoop();
  1742 	Window::SetDirtyById(WC_STATUS_BAR, 0);
  1742 	BaseWindow::SetDirtyById(WC_STATUS_BAR, 0);
  1743 	return _cur_year;
  1743 	return _cur_year;
  1744 }
  1744 }
  1745 
  1745 
  1746 typedef int32 CheckButtonClick(int32, int32);
  1746 typedef int32 CheckButtonClick(int32, int32);
  1747 
  1747 
  1778 	{SLE_UINT8, {CE_NONE}, STR_CHEAT_SWITCH_CLIMATE, &_opt.landscape,                &_cheats.switch_climate.been_used,  &ClickChangeClimateCheat,-1,  4},
  1778 	{SLE_UINT8, {CE_NONE}, STR_CHEAT_SWITCH_CLIMATE, &_opt.landscape,                &_cheats.switch_climate.been_used,  &ClickChangeClimateCheat,-1,  4},
  1779 	{SLE_INT32, {CE_NONE}, STR_CHEAT_CHANGE_DATE,    &_cur_year,                     &_cheats.change_date.been_used,     &ClickChangeDateCheat,   -1,  1},
  1779 	{SLE_INT32, {CE_NONE}, STR_CHEAT_CHANGE_DATE,    &_cur_year,                     &_cheats.change_date.been_used,     &ClickChangeDateCheat,   -1,  1},
  1780 };
  1780 };
  1781 
  1781 
  1782 
  1782 
  1783 static const Widget _cheat_widgets[] = {
  1783 static const OldWidget _cheat_widgets[] = {
  1784 {   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,   STR_018B_CLOSE_WINDOW},
  1784 {   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,   STR_018B_CLOSE_WINDOW},
  1785 {    WWT_CAPTION,   RESIZE_NONE,    14,    11,   399,     0,    13, STR_CHEATS, STR_018C_WINDOW_TITLE_DRAG_THIS},
  1785 {    WWT_CAPTION,   RESIZE_NONE,    14,    11,   399,     0,    13, STR_CHEATS, STR_018C_WINDOW_TITLE_DRAG_THIS},
  1786 {      WWT_PANEL,   RESIZE_NONE,    14,     0,   399,    14,   169, 0x0,        STR_NULL},
  1786 {      WWT_PANEL,   RESIZE_NONE,    14,     0,   399,    14,   169, 0x0,        STR_NULL},
  1787 {      WWT_PANEL,   RESIZE_NONE,    14,     0,   399,    14,   169, 0x0,        STR_CHEATS_TIP},
  1787 {      WWT_PANEL,   RESIZE_NONE,    14,     0,   399,    14,   169, 0x0,        STR_CHEATS_TIP},
  1788 {   WIDGETS_END},
  1788 {   WIDGETS_END},
  1789 };
  1789 };
  1790 
  1790 
  1791 static void CheatsWndProc(Window *w, WindowEvent *e)
  1791 static void CheatsWndProc(BaseWindow *w, WindowEvent *e)
  1792 {
  1792 {
  1793 	switch (e->event) {
  1793 	switch (e->event) {
  1794 	case WE_PAINT: {
  1794 	case WE_PAINT: {
  1795 		int clk = WP(w,def_d).data_1;
  1795 		int clk = WP(w,def_d).data_1;
  1796 		int x, y;
  1796 		int x, y;
  1921 
  1921 
  1922 
  1922 
  1923 void ShowCheatWindow(void)
  1923 void ShowCheatWindow(void)
  1924 {
  1924 {
  1925 	DeleteWindowById(WC_CHEATS, 0);
  1925 	DeleteWindowById(WC_CHEATS, 0);
  1926 	AllocateWindowDesc(&_cheats_desc);
  1926 	BaseWindow::Allocate(&_cheats_desc);
  1927 }
  1927 }