src/town_gui.cpp
branchNewGRF_ports
changeset 10184 fcf5fb2548eb
parent 6878 7d1ff2f621c7
child 10210 a2131f7a315d
equal deleted inserted replaced
10179:eec5a7dcbf61 10184:fcf5fb2548eb
    16 #include "player_base.h"
    16 #include "player_base.h"
    17 #include "player_gui.h"
    17 #include "player_gui.h"
    18 #include "network/network.h"
    18 #include "network/network.h"
    19 #include "variables.h"
    19 #include "variables.h"
    20 #include "strings_func.h"
    20 #include "strings_func.h"
       
    21 #include "sound_func.h"
    21 #include "economy_func.h"
    22 #include "economy_func.h"
    22 #include "core/alloc_func.hpp"
    23 #include "core/alloc_func.hpp"
    23 #include "settings_type.h"
    24 #include "settings_type.h"
    24 
    25 
    25 #include "table/sprites.h"
    26 #include "table/sprites.h"
    26 #include "table/strings.h"
    27 #include "table/strings.h"
       
    28 
       
    29 extern bool GenerateTowns();
       
    30 static int _scengen_town_size = 1; // depress medium-sized towns per default
    27 
    31 
    28 enum TownAuthorityWidget {
    32 enum TownAuthorityWidget {
    29 	TWA_CLOSEBOX = 0,
    33 	TWA_CLOSEBOX = 0,
    30 	TWA_CAPTION,
    34 	TWA_CAPTION,
    31 	TWA_RATING_INFO,
    35 	TWA_RATING_INFO,
   273 static void TownViewWndProc(Window *w, WindowEvent *e)
   277 static void TownViewWndProc(Window *w, WindowEvent *e)
   274 {
   278 {
   275 	Town *t = GetTown(w->window_number);
   279 	Town *t = GetTown(w->window_number);
   276 
   280 
   277 	switch (e->event) {
   281 	switch (e->event) {
       
   282 	case WE_CREATE:
       
   283 		if (t->larger_town) w->widget[1].data = STR_CITY;
       
   284 		break;
       
   285 
   278 	case WE_PAINT:
   286 	case WE_PAINT:
   279 		/* disable renaming town in network games if you are not the server */
   287 		/* disable renaming town in network games if you are not the server */
   280 		w->SetWidgetDisabledState(8, _networking && !_network_server);
   288 		w->SetWidgetDisabledState(8, _networking && !_network_server);
   281 
   289 
   282 		SetDParam(0, t->index);
   290 		SetDParam(0, t->index);
   565 		w->vscroll.cap = 16;
   573 		w->vscroll.cap = 16;
   566 		w->resize.step_height = 10;
   574 		w->resize.step_height = 10;
   567 		w->resize.height = w->height - 10 * 6; // minimum of 10 items in the list, each item 10 high
   575 		w->resize.height = w->height - 10 * 6; // minimum of 10 items in the list, each item 10 high
   568 	}
   576 	}
   569 }
   577 }
       
   578 
       
   579 void CcBuildTown(bool success, TileIndex tile, uint32 p1, uint32 p2)
       
   580 {
       
   581 	if (success) {
       
   582 		SndPlayTileFx(SND_1F_SPLAT, tile);
       
   583 		ResetObjectToPlace();
       
   584 	}
       
   585 }
       
   586 
       
   587 static void PlaceProc_Town(TileIndex tile)
       
   588 {
       
   589 	uint32 size = min(_scengen_town_size, (int)TSM_CITY);
       
   590 	uint32 mode = _scengen_town_size > TSM_CITY ? TSM_CITY : TSM_FIXED;
       
   591 	DoCommandP(tile, size, mode, CcBuildTown, CMD_BUILD_TOWN | CMD_MSG(STR_0236_CAN_T_BUILD_TOWN_HERE));
       
   592 }
       
   593 
       
   594 static const Widget _scen_edit_town_gen_widgets[] = {
       
   595 {   WWT_CLOSEBOX,   RESIZE_NONE,     7,     0,    10,     0,    13, STR_00C5,                 STR_018B_CLOSE_WINDOW},
       
   596 {    WWT_CAPTION,   RESIZE_NONE,     7,    11,   147,     0,    13, STR_0233_TOWN_GENERATION, STR_018C_WINDOW_TITLE_DRAG_THIS},
       
   597 {  WWT_STICKYBOX,   RESIZE_NONE,     7,   148,   159,     0,    13, 0x0,                      STR_STICKY_BUTTON},
       
   598 {      WWT_PANEL,   RESIZE_NONE,     7,     0,   159,    14,    94, 0x0,                      STR_NULL},
       
   599 {    WWT_TEXTBTN,   RESIZE_NONE,    14,     2,   157,    16,    27, STR_0234_NEW_TOWN,        STR_0235_CONSTRUCT_NEW_TOWN},
       
   600 {    WWT_TEXTBTN,   RESIZE_NONE,    14,     2,   157,    29,    40, STR_023D_RANDOM_TOWN,     STR_023E_BUILD_TOWN_IN_RANDOM_LOCATION},
       
   601 {    WWT_TEXTBTN,   RESIZE_NONE,    14,     2,   157,    42,    53, STR_MANY_RANDOM_TOWNS,    STR_RANDOM_TOWNS_TIP},
       
   602 {    WWT_TEXTBTN,   RESIZE_NONE,    14,     2,    53,    68,    79, STR_02A1_SMALL,           STR_02A4_SELECT_TOWN_SIZE},
       
   603 {    WWT_TEXTBTN,   RESIZE_NONE,    14,    54,   105,    68,    79, STR_02A2_MEDIUM,          STR_02A4_SELECT_TOWN_SIZE},
       
   604 {    WWT_TEXTBTN,   RESIZE_NONE,    14,   106,   157,    68,    79, STR_02A3_LARGE,           STR_02A4_SELECT_TOWN_SIZE},
       
   605 {    WWT_TEXTBTN,   RESIZE_NONE,    14,     2,   157,    81,    92, STR_SCENARIO_EDITOR_CITY, STR_02A4_SELECT_TOWN_SIZE},
       
   606 {      WWT_LABEL,   RESIZE_NONE,     7,     0,   147,    54,    67, STR_02A5_TOWN_SIZE,       STR_NULL},
       
   607 {   WIDGETS_END},
       
   608 };
       
   609 
       
   610 static void ScenEditTownGenWndProc(Window *w, WindowEvent *e)
       
   611 {
       
   612 	switch (e->event) {
       
   613 	case WE_PAINT:
       
   614 		DrawWindowWidgets(w);
       
   615 		break;
       
   616 
       
   617 	case WE_CREATE:
       
   618 		w->LowerWidget(_scengen_town_size + 7);
       
   619 		break;
       
   620 
       
   621 	case WE_CLICK:
       
   622 		switch (e->we.click.widget) {
       
   623 		case 4: // new town
       
   624 			HandlePlacePushButton(w, 4, SPR_CURSOR_TOWN, VHM_RECT, PlaceProc_Town);
       
   625 			break;
       
   626 		case 5: {// random town
       
   627 			Town *t;
       
   628 			uint size = min(_scengen_town_size, (int)TSM_CITY);
       
   629 			TownSizeMode mode = _scengen_town_size > TSM_CITY ? TSM_CITY : TSM_FIXED;
       
   630 
       
   631 			w->HandleButtonClick(5);
       
   632 			_generating_world = true;
       
   633 			t = CreateRandomTown(20, mode, size);
       
   634 			_generating_world = false;
       
   635 
       
   636 			if (t == NULL) {
       
   637 				ShowErrorMessage(STR_NO_SPACE_FOR_TOWN, STR_CANNOT_GENERATE_TOWN, 0, 0);
       
   638 			} else {
       
   639 				ScrollMainWindowToTile(t->xy);
       
   640 			}
       
   641 
       
   642 			break;
       
   643 		}
       
   644 		case 6: {// many random towns
       
   645 			w->HandleButtonClick(6);
       
   646 
       
   647 			_generating_world = true;
       
   648 			if (!GenerateTowns()) ShowErrorMessage(STR_NO_SPACE_FOR_TOWN, STR_CANNOT_GENERATE_TOWN, 0, 0);
       
   649 			_generating_world = false;
       
   650 			break;
       
   651 		}
       
   652 
       
   653 		case 7: case 8: case 9: case 10:
       
   654 			w->RaiseWidget(_scengen_town_size + 7);
       
   655 			_scengen_town_size = e->we.click.widget - 7;
       
   656 			w->LowerWidget(_scengen_town_size + 7);
       
   657 			SetWindowDirty(w);
       
   658 			break;
       
   659 		}
       
   660 		break;
       
   661 
       
   662 	case WE_TIMEOUT:
       
   663 		w->RaiseWidget(5);
       
   664 		w->RaiseWidget(6);
       
   665 		SetWindowDirty(w);
       
   666 		break;
       
   667 	case WE_PLACE_OBJ:
       
   668 		_place_proc(e->we.place.tile);
       
   669 		break;
       
   670 	case WE_ABORT_PLACE_OBJ:
       
   671 		w->RaiseButtons();
       
   672 		w->LowerWidget(_scengen_town_size + 7);
       
   673 		SetWindowDirty(w);
       
   674 		break;
       
   675 	}
       
   676 }
       
   677 
       
   678 static const WindowDesc _scen_edit_town_gen_desc = {
       
   679 	WDP_AUTO, WDP_AUTO, 160, 95, 160, 95,
       
   680 	WC_SCEN_TOWN_GEN, WC_NONE,
       
   681 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
       
   682 	_scen_edit_town_gen_widgets,
       
   683 	ScenEditTownGenWndProc,
       
   684 };
       
   685 
       
   686 void ShowBuildTownWindow()
       
   687 {
       
   688 	if (_game_mode != GM_EDITOR && !IsValidPlayer(_current_player)) return;
       
   689 	AllocateWindowDescFront(&_scen_edit_town_gen_desc, 0);
       
   690 }
       
   691