src/terraform_gui.cpp
changeset 8360 3021c928de6c
parent 8270 e7c342f6b14c
child 8381 9f861b4e8f48
equal deleted inserted replaced
8359:6efdb08cedb8 8360:3021c928de6c
   130 			GenerateDesertArea(end_tile, start_tile);
   130 			GenerateDesertArea(end_tile, start_tile);
   131 			break;
   131 			break;
   132 		case DDSP_CREATE_WATER:
   132 		case DDSP_CREATE_WATER:
   133 			DoCommandP(end_tile, start_tile, _ctrl_pressed, CcBuildCanal, CMD_BUILD_CANAL | CMD_MSG(STR_CANT_BUILD_CANALS));
   133 			DoCommandP(end_tile, start_tile, _ctrl_pressed, CcBuildCanal, CMD_BUILD_CANAL | CMD_MSG(STR_CANT_BUILD_CANALS));
   134 			break;
   134 			break;
       
   135 		case DDSP_CREATE_RIVER:
       
   136 			DoCommandP(end_tile, start_tile, 2, CcBuildCanal, CMD_BUILD_CANAL | CMD_MSG(STR_CANT_BUILD_CANALS));
       
   137 			break;
   135 		default:
   138 		default:
   136 			return false;
   139 			return false;
   137 	}
   140 	}
   138 
   141 
   139 	return true;
   142 	return true;
   410 static void PlaceProc_WaterArea(TileIndex tile)
   413 static void PlaceProc_WaterArea(TileIndex tile)
   411 {
   414 {
   412 	VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_CREATE_WATER);
   415 	VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_CREATE_WATER);
   413 }
   416 }
   414 
   417 
       
   418 static void PlaceProc_RiverArea(TileIndex tile)
       
   419 {
       
   420 	VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_CREATE_RIVER);
       
   421 }
       
   422 
   415 static const Widget _scen_edit_land_gen_widgets[] = {
   423 static const Widget _scen_edit_land_gen_widgets[] = {
   416 {  WWT_CLOSEBOX,   RESIZE_NONE,     7,     0,    10,     0,    13, STR_00C5,                  STR_018B_CLOSE_WINDOW},
   424 {  WWT_CLOSEBOX,   RESIZE_NONE,     7,     0,    10,     0,    13, STR_00C5,                  STR_018B_CLOSE_WINDOW},
   417 {   WWT_CAPTION,   RESIZE_NONE,     7,    11,   169,     0,    13, STR_0223_LAND_GENERATION,  STR_018C_WINDOW_TITLE_DRAG_THIS},
   425 {   WWT_CAPTION,   RESIZE_NONE,     7,    11,   191,     0,    13, STR_0223_LAND_GENERATION,  STR_018C_WINDOW_TITLE_DRAG_THIS},
   418 { WWT_STICKYBOX,   RESIZE_NONE,     7,   170,   181,     0,    13, STR_NULL,                  STR_STICKY_BUTTON},
   426 { WWT_STICKYBOX,   RESIZE_NONE,     7,   192,   203,     0,    13, STR_NULL,                  STR_STICKY_BUTTON},
   419 {     WWT_PANEL,   RESIZE_NONE,     7,     0,   181,    14,   102, 0x0,                       STR_NULL},
   427 {     WWT_PANEL,   RESIZE_NONE,     7,     0,   203,    14,   102, 0x0,                       STR_NULL},
   420 {    WWT_IMGBTN,   RESIZE_NONE,    14,     2,    23,    16,    37, SPR_IMG_DYNAMITE,          STR_018D_DEMOLISH_BUILDINGS_ETC},
   428 {    WWT_IMGBTN,   RESIZE_NONE,    14,     2,    23,    16,    37, SPR_IMG_DYNAMITE,          STR_018D_DEMOLISH_BUILDINGS_ETC},
   421 {    WWT_IMGBTN,   RESIZE_NONE,    14,    24,    45,    16,    37, SPR_IMG_TERRAFORM_DOWN,    STR_018E_LOWER_A_CORNER_OF_LAND},
   429 {    WWT_IMGBTN,   RESIZE_NONE,    14,    24,    45,    16,    37, SPR_IMG_TERRAFORM_DOWN,    STR_018E_LOWER_A_CORNER_OF_LAND},
   422 {    WWT_IMGBTN,   RESIZE_NONE,    14,    46,    67,    16,    37, SPR_IMG_TERRAFORM_UP,      STR_018F_RAISE_A_CORNER_OF_LAND},
   430 {    WWT_IMGBTN,   RESIZE_NONE,    14,    46,    67,    16,    37, SPR_IMG_TERRAFORM_UP,      STR_018F_RAISE_A_CORNER_OF_LAND},
   423 {    WWT_IMGBTN,   RESIZE_NONE,    14,    68,    89,    16,    37, SPR_IMG_LEVEL_LAND,        STR_LEVEL_LAND_TOOLTIP},
   431 {    WWT_IMGBTN,   RESIZE_NONE,    14,    68,    89,    16,    37, SPR_IMG_LEVEL_LAND,        STR_LEVEL_LAND_TOOLTIP},
   424 {    WWT_IMGBTN,   RESIZE_NONE,    14,    90,   111,    16,    37, SPR_IMG_BUILD_CANAL,       STR_CREATE_LAKE},
   432 {    WWT_IMGBTN,   RESIZE_NONE,    14,    90,   111,    16,    37, SPR_IMG_BUILD_CANAL,       STR_CREATE_LAKE},
   425 {    WWT_IMGBTN,   RESIZE_NONE,    14,   112,   134,    16,    37, SPR_IMG_ROCKS,             STR_028C_PLACE_ROCKY_AREAS_ON_LANDSCAPE},
   433 {    WWT_IMGBTN,   RESIZE_NONE,    14,   112,   133,    16,    37, SPR_IMG_BUILD_CANAL,       STR_CREATE_RIVER},
   426 {    WWT_IMGBTN,   RESIZE_NONE,    14,   135,   157,    16,    37, SPR_IMG_LIGHTHOUSE_DESERT, STR_NULL}, // XXX - dynamic
   434 {    WWT_IMGBTN,   RESIZE_NONE,    14,   134,   156,    16,    37, SPR_IMG_ROCKS,             STR_028C_PLACE_ROCKY_AREAS_ON_LANDSCAPE},
   427 {    WWT_IMGBTN,   RESIZE_NONE,    14,   158,   179,    16,    37, SPR_IMG_TRANSMITTER,       STR_028E_PLACE_TRANSMITTER},
   435 {    WWT_IMGBTN,   RESIZE_NONE,    14,   157,   179,    16,    37, SPR_IMG_LIGHTHOUSE_DESERT, STR_NULL}, // XXX - dynamic
   428 {    WWT_IMGBTN,   RESIZE_NONE,    14,   139,   150,    45,    56, SPR_ARROW_UP,              STR_0228_INCREASE_SIZE_OF_LAND_AREA},
   436 {    WWT_IMGBTN,   RESIZE_NONE,    14,   180,   201,    16,    37, SPR_IMG_TRANSMITTER,       STR_028E_PLACE_TRANSMITTER},
   429 {    WWT_IMGBTN,   RESIZE_NONE,    14,   139,   150,    58,    69, SPR_ARROW_DOWN,            STR_0229_DECREASE_SIZE_OF_LAND_AREA},
   437 {    WWT_IMGBTN,   RESIZE_NONE,    14,   150,   161,    45,    56, SPR_ARROW_UP,              STR_0228_INCREASE_SIZE_OF_LAND_AREA},
   430 {   WWT_TEXTBTN,   RESIZE_NONE,    14,    24,   157,    76,    87, STR_SE_NEW_WORLD,          STR_022A_GENERATE_RANDOM_LAND},
   438 {    WWT_IMGBTN,   RESIZE_NONE,    14,   150,   161,    58,    69, SPR_ARROW_DOWN,            STR_0229_DECREASE_SIZE_OF_LAND_AREA},
   431 {   WWT_TEXTBTN,   RESIZE_NONE,    14,    24,   157,    89,   100, STR_022B_RESET_LANDSCAPE,  STR_RESET_LANDSCAPE_TOOLTIP},
   439 {   WWT_TEXTBTN,   RESIZE_NONE,    14,    24,   179,    76,    87, STR_SE_NEW_WORLD,          STR_022A_GENERATE_RANDOM_LAND},
       
   440 {   WWT_TEXTBTN,   RESIZE_NONE,    14,    24,   179,    89,   100, STR_022B_RESET_LANDSCAPE,  STR_RESET_LANDSCAPE_TOOLTIP},
   432 {   WIDGETS_END},
   441 {   WIDGETS_END},
   433 };
   442 };
   434 
   443 
   435 static const int8 _multi_terraform_coords[][2] = {
   444 static const int8 _multi_terraform_coords[][2] = {
   436 	{  0, -2},
   445 	{  0, -2},
   470 static void EditorTerraformClick_WaterArea(Window *w)
   479 static void EditorTerraformClick_WaterArea(Window *w)
   471 {
   480 {
   472 	HandlePlacePushButton(w, 8, SPR_CURSOR_CANAL, VHM_RECT, PlaceProc_WaterArea);
   481 	HandlePlacePushButton(w, 8, SPR_CURSOR_CANAL, VHM_RECT, PlaceProc_WaterArea);
   473 }
   482 }
   474 
   483 
       
   484 static void EditorTerraformClick_RiverArea(Window *w)
       
   485 {
       
   486 	HandlePlacePushButton(w, 9, SPR_CURSOR_CANAL, VHM_RECT, PlaceProc_RiverArea);
       
   487 }
       
   488 
   475 static void EditorTerraformClick_RockyArea(Window *w)
   489 static void EditorTerraformClick_RockyArea(Window *w)
   476 {
   490 {
   477 	HandlePlacePushButton(w, 9, SPR_CURSOR_ROCKY_AREA, VHM_RECT, PlaceProc_RockyArea);
   491 	HandlePlacePushButton(w, 10, SPR_CURSOR_ROCKY_AREA, VHM_RECT, PlaceProc_RockyArea);
   478 }
   492 }
   479 
   493 
   480 static void EditorTerraformClick_DesertLightHouse(Window *w)
   494 static void EditorTerraformClick_DesertLightHouse(Window *w)
   481 {
   495 {
   482 	HandlePlacePushButton(w, 10, SPR_CURSOR_LIGHTHOUSE, VHM_RECT, (_opt.landscape == LT_TROPIC) ? PlaceProc_DesertArea : PlaceProc_LightHouse);
   496 	HandlePlacePushButton(w, 11, SPR_CURSOR_LIGHTHOUSE, VHM_RECT, (_opt.landscape == LT_TROPIC) ? PlaceProc_DesertArea : PlaceProc_LightHouse);
   483 }
   497 }
   484 
   498 
   485 static void EditorTerraformClick_Transmitter(Window *w)
   499 static void EditorTerraformClick_Transmitter(Window *w)
   486 {
   500 {
   487 	HandlePlacePushButton(w, 11, SPR_CURSOR_TRANSMITTER, VHM_RECT, PlaceProc_Transmitter);
   501 	HandlePlacePushButton(w, 12, SPR_CURSOR_TRANSMITTER, VHM_RECT, PlaceProc_Transmitter);
   488 }
   502 }
   489 
   503 
   490 static const uint16 _editor_terraform_keycodes[] = {
   504 static const uint16 _editor_terraform_keycodes[] = {
   491 	'D',
   505 	'D',
   492 	'Q',
   506 	'Q',
   493 	'W',
   507 	'W',
   494 	'E',
   508 	'E',
   495 	'R',
   509 	'R',
   496 	'T',
   510 	'T',
   497 	'Y',
   511 	'Y',
   498 	'U'
   512 	'U',
       
   513 	'I'
   499 };
   514 };
   500 
   515 
   501 typedef void OnButtonClick(Window *w);
   516 typedef void OnButtonClick(Window *w);
   502 static OnButtonClick * const _editor_terraform_button_proc[] = {
   517 static OnButtonClick * const _editor_terraform_button_proc[] = {
   503 	EditorTerraformClick_Dynamite,
   518 	EditorTerraformClick_Dynamite,
   504 	EditorTerraformClick_LowerBigLand,
   519 	EditorTerraformClick_LowerBigLand,
   505 	EditorTerraformClick_RaiseBigLand,
   520 	EditorTerraformClick_RaiseBigLand,
   506 	EditorTerraformClick_LevelLand,
   521 	EditorTerraformClick_LevelLand,
   507 	EditorTerraformClick_WaterArea,
   522 	EditorTerraformClick_WaterArea,
       
   523 	EditorTerraformClick_RiverArea,
   508 	EditorTerraformClick_RockyArea,
   524 	EditorTerraformClick_RockyArea,
   509 	EditorTerraformClick_DesertLightHouse,
   525 	EditorTerraformClick_DesertLightHouse,
   510 	EditorTerraformClick_Transmitter
   526 	EditorTerraformClick_Transmitter
   511 };
   527 };
   512 
   528 
   541 
   557 
   542 static void ScenEditLandGenWndProc(Window *w, WindowEvent *e)
   558 static void ScenEditLandGenWndProc(Window *w, WindowEvent *e)
   543 {
   559 {
   544 	switch (e->event) {
   560 	switch (e->event) {
   545 		case WE_CREATE:
   561 		case WE_CREATE:
   546 			/* XXX - lighthouse button is widget 10!! Don't forget when changing */
   562 			/* XXX - lighthouse button is widget 11!! Don't forget when changing */
   547 			w->widget[10].tooltips = (_opt.landscape == LT_TROPIC) ? STR_028F_DEFINE_DESERT_AREA : STR_028D_PLACE_LIGHTHOUSE;
   563 			w->widget[11].tooltips = (_opt.landscape == LT_TROPIC) ? STR_028F_DEFINE_DESERT_AREA : STR_028D_PLACE_LIGHTHOUSE;
   548 			break;
   564 			break;
   549 
   565 
   550 		case WE_PAINT: {
   566 		case WE_PAINT: {
   551 			DrawWindowWidgets(w);
   567 			DrawWindowWidgets(w);
   552 
   568 
   553 			int n = _terraform_size * _terraform_size;
   569 			int n = _terraform_size * _terraform_size;
   554 			const int8 *coords = &_multi_terraform_coords[0][0];
   570 			const int8 *coords = &_multi_terraform_coords[0][0];
   555 
   571 
   556 			assert(n != 0);
   572 			assert(n != 0);
   557 			do {
   573 			do {
   558 				DrawSprite(SPR_WHITE_POINT, PAL_NONE, 77 + coords[0], 55 + coords[1]);
   574 				DrawSprite(SPR_WHITE_POINT, PAL_NONE, 88 + coords[0], 55 + coords[1]);
   559 				coords += 2;
   575 				coords += 2;
   560 			} while (--n);
   576 			} while (--n);
   561 
   577 
   562 			if (w->IsWidgetLowered(5) || w->IsWidgetLowered(6)) // change area-size if raise/lower corner is selected
   578 			if (w->IsWidgetLowered(5) || w->IsWidgetLowered(6)) // change area-size if raise/lower corner is selected
   563 				SetTileSelectSize(_terraform_size, _terraform_size);
   579 				SetTileSelectSize(_terraform_size, _terraform_size);
   574 			}
   590 			}
   575 			break;
   591 			break;
   576 
   592 
   577 		case WE_CLICK:
   593 		case WE_CLICK:
   578 			switch (e->we.click.widget) {
   594 			switch (e->we.click.widget) {
   579 				case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11:
   595 				case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: case 12:
   580 					_editor_terraform_button_proc[e->we.click.widget - 4](w);
   596 					_editor_terraform_button_proc[e->we.click.widget - 4](w);
   581 					break;
   597 					break;
   582 				case 12: case 13: { // Increase/Decrease terraform size
   598 				case 13: case 14: { // Increase/Decrease terraform size
   583 					int size = (e->we.click.widget == 12) ? 1 : -1;
   599 					int size = (e->we.click.widget == 13) ? 1 : -1;
   584 					w->HandleButtonClick(e->we.click.widget);
   600 					w->HandleButtonClick(e->we.click.widget);
   585 					size += _terraform_size;
   601 					size += _terraform_size;
   586 
   602 
   587 					if (!IsInsideMM(size, 1, 8 + 1)) return;
   603 					if (!IsInsideMM(size, 1, 8 + 1)) return;
   588 					_terraform_size = size;
   604 					_terraform_size = size;
   589 
   605 
   590 					SndPlayFx(SND_15_BEEP);
   606 					SndPlayFx(SND_15_BEEP);
   591 					SetWindowDirty(w);
   607 					SetWindowDirty(w);
   592 				} break;
   608 				} break;
   593 				case 14: // gen random land
   609 				case 15: // gen random land
   594 					w->HandleButtonClick(14);
   610 					w->HandleButtonClick(15);
   595 					ShowCreateScenario();
   611 					ShowCreateScenario();
   596 					break;
   612 					break;
   597 				case 15: // Reset landscape
   613 				case 16: // Reset landscape
   598 					ShowQuery(
   614 					ShowQuery(
   599 						STR_022C_RESET_LANDSCAPE,
   615 						STR_022C_RESET_LANDSCAPE,
   600 						STR_RESET_LANDSCAPE_CONFIRMATION_TEXT,
   616 						STR_RESET_LANDSCAPE_CONFIRMATION_TEXT,
   601 						NULL,
   617 						NULL,
   602 						ResetLandscapeConfirmationCallback);
   618 						ResetLandscapeConfirmationCallback);
   608 			for (uint i = 0; i < w->widget_count; i++) {
   624 			for (uint i = 0; i < w->widget_count; i++) {
   609 				if (w->IsWidgetLowered(i)) {
   625 				if (w->IsWidgetLowered(i)) {
   610 					w->RaiseWidget(i);
   626 					w->RaiseWidget(i);
   611 					w->InvalidateWidget(i);
   627 					w->InvalidateWidget(i);
   612 				}
   628 				}
   613 				if (i == 3) i = 11;
   629 				if (i == 3) i = 12;
   614 			}
   630 			}
   615 			break;
   631 			break;
   616 
   632 
   617 		case WE_PLACE_OBJ:
   633 		case WE_PLACE_OBJ:
   618 			_place_proc(e->we.place.tile);
   634 			_place_proc(e->we.place.tile);
   626 			if (e->we.place.pt.x != -1) {
   642 			if (e->we.place.pt.x != -1) {
   627 				switch (e->we.place.select_proc) {
   643 				switch (e->we.place.select_proc) {
   628 					case DDSP_CREATE_ROCKS:
   644 					case DDSP_CREATE_ROCKS:
   629 					case DDSP_CREATE_DESERT:
   645 					case DDSP_CREATE_DESERT:
   630 					case DDSP_CREATE_WATER:
   646 					case DDSP_CREATE_WATER:
       
   647 					case DDSP_CREATE_RIVER:
   631 					case DDSP_RAISE_AND_LEVEL_AREA:
   648 					case DDSP_RAISE_AND_LEVEL_AREA:
   632 					case DDSP_LOWER_AND_LEVEL_AREA:
   649 					case DDSP_LOWER_AND_LEVEL_AREA:
   633 					case DDSP_LEVEL_AREA:
   650 					case DDSP_LEVEL_AREA:
   634 					case DDSP_DEMOLISH_AREA:
   651 					case DDSP_DEMOLISH_AREA:
   635 						GUIPlaceProcDragXY(e);
   652 						GUIPlaceProcDragXY(e);
   644 			break;
   661 			break;
   645 	}
   662 	}
   646 }
   663 }
   647 
   664 
   648 static const WindowDesc _scen_edit_land_gen_desc = {
   665 static const WindowDesc _scen_edit_land_gen_desc = {
   649 	WDP_AUTO, WDP_AUTO, 182, 103, 182, 103,
   666 	WDP_AUTO, WDP_AUTO, 204, 103, 204, 103,
   650 	WC_SCEN_LAND_GEN, WC_NONE,
   667 	WC_SCEN_LAND_GEN, WC_NONE,
   651 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
   668 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
   652 	_scen_edit_land_gen_widgets,
   669 	_scen_edit_land_gen_widgets,
   653 	ScenEditLandGenWndProc,
   670 	ScenEditLandGenWndProc,
   654 };
   671 };