src/town_gui.cpp
changeset 8933 c1f075679c2e
parent 8932 c1650d1cdc31
child 8945 7fa9c9bf5522
equal deleted inserted replaced
8932:c1650d1cdc31 8933:c1f075679c2e
   273 		w->vscroll.cap = 5;
   273 		w->vscroll.cap = 5;
   274 		WP(w, def_d).data_1 = -1;
   274 		WP(w, def_d).data_1 = -1;
   275 	}
   275 	}
   276 }
   276 }
   277 
   277 
       
   278 
       
   279 enum TownViewWidget {
       
   280 	TVW_CAPTION = 1,
       
   281 	TVW_CENTERVIEW = 6,
       
   282 	TVW_SHOWAUTORITY,
       
   283 	TVW_CHANGENAME,
       
   284 	TVW_EXPAND,
       
   285 	TVW_DELETE,
       
   286 };
       
   287 
   278 static void TownViewWndProc(Window *w, WindowEvent *e)
   288 static void TownViewWndProc(Window *w, WindowEvent *e)
   279 {
   289 {
   280 	Town *t = GetTown(w->window_number);
   290 	Town *t = GetTown(w->window_number);
   281 
   291 
   282 	switch (e->event) {
   292 	switch (e->event) {
   283 		case WE_CREATE:
   293 		case WE_CREATE:
   284 			if (t->larger_town) w->widget[1].data = STR_CITY;
   294 			if (t->larger_town) w->widget[TVW_CAPTION].data = STR_CITY;
   285 			break;
   295 			break;
   286 
   296 
   287 		case WE_PAINT:
   297 		case WE_PAINT:
   288 			/* disable renaming town in network games if you are not the server */
   298 			/* disable renaming town in network games if you are not the server */
   289 			w->SetWidgetDisabledState(8, _networking && !_network_server);
   299 			w->SetWidgetDisabledState(TVW_CHANGENAME, _networking && !_network_server);
   290 
   300 
   291 			SetDParam(0, t->index);
   301 			SetDParam(0, t->index);
   292 			DrawWindowWidgets(w);
   302 			DrawWindowWidgets(w);
   293 
   303 
   294 			SetDParam(0, t->population);
   304 			SetDParam(0, t->population);
   306 			DrawWindowViewport(w);
   316 			DrawWindowViewport(w);
   307 			break;
   317 			break;
   308 
   318 
   309 		case WE_CLICK:
   319 		case WE_CLICK:
   310 			switch (e->we.click.widget) {
   320 			switch (e->we.click.widget) {
   311 				case 6: /* scroll to location */
   321 				case TVW_CENTERVIEW: /* scroll to location */
   312 					ScrollMainWindowToTile(t->xy);
   322 					ScrollMainWindowToTile(t->xy);
   313 					break;
   323 					break;
   314 
   324 
   315 				case 7: /* town authority */
   325 				case TVW_SHOWAUTORITY: /* town authority */
   316 					ShowTownAuthorityWindow(w->window_number);
   326 					ShowTownAuthorityWindow(w->window_number);
   317 					break;
   327 					break;
   318 
   328 
   319 				case 8: /* rename */
   329 				case TVW_CHANGENAME: /* rename */
   320 					SetDParam(0, w->window_number);
   330 					SetDParam(0, w->window_number);
   321 					ShowQueryString(STR_TOWN, STR_2007_RENAME_TOWN, 31, 130, w, CS_ALPHANUMERAL);
   331 					ShowQueryString(STR_TOWN, STR_2007_RENAME_TOWN, 31, 130, w, CS_ALPHANUMERAL);
   322 					break;
   332 					break;
   323 
   333 
   324 				case 9: /* expand town */
   334 				case TVW_EXPAND: /* expand town - only available on Scenario editor */
   325 					ExpandTown(t);
   335 					ExpandTown(t);
   326 					break;
   336 					break;
   327 
   337 
   328 				case 10: /* delete town */
   338 				case TVW_DELETE: /* delete town - only available on Scenario editor */
   329 					delete t;
   339 					delete t;
   330 					break;
   340 					break;
   331 			} break;
   341 			} break;
   332 
   342 
   333 		case WE_ON_EDIT_TEXT:
   343 		case WE_ON_EDIT_TEXT:
   589 {
   599 {
   590 	uint32 size = min(_scengen_town_size, (int)TSM_CITY);
   600 	uint32 size = min(_scengen_town_size, (int)TSM_CITY);
   591 	uint32 mode = _scengen_town_size > TSM_CITY ? TSM_CITY : TSM_FIXED;
   601 	uint32 mode = _scengen_town_size > TSM_CITY ? TSM_CITY : TSM_FIXED;
   592 	DoCommandP(tile, size, mode, CcBuildTown, CMD_BUILD_TOWN | CMD_MSG(STR_0236_CAN_T_BUILD_TOWN_HERE));
   602 	DoCommandP(tile, size, mode, CcBuildTown, CMD_BUILD_TOWN | CMD_MSG(STR_0236_CAN_T_BUILD_TOWN_HERE));
   593 }
   603 }
       
   604 
       
   605 enum TownScenarioEditorWidget {
       
   606 	TSEW_NEWTOWN = 4,
       
   607 	TSEW_RANDOMTOWN,
       
   608 	TSEW_MANYRANDOMTOWNS,
       
   609 	TSEW_SMALLTOWN,
       
   610 	TSEW_MEDIUMTOWN,
       
   611 	TSEW_LARGETOWN,
       
   612 	TSEW_CITY,
       
   613 };
   594 
   614 
   595 static const Widget _scen_edit_town_gen_widgets[] = {
   615 static const Widget _scen_edit_town_gen_widgets[] = {
   596 {   WWT_CLOSEBOX,   RESIZE_NONE,     7,     0,    10,     0,    13, STR_00C5,                 STR_018B_CLOSE_WINDOW},
   616 {   WWT_CLOSEBOX,   RESIZE_NONE,     7,     0,    10,     0,    13, STR_00C5,                 STR_018B_CLOSE_WINDOW},
   597 {    WWT_CAPTION,   RESIZE_NONE,     7,    11,   147,     0,    13, STR_0233_TOWN_GENERATION, STR_018C_WINDOW_TITLE_DRAG_THIS},
   617 {    WWT_CAPTION,   RESIZE_NONE,     7,    11,   147,     0,    13, STR_0233_TOWN_GENERATION, STR_018C_WINDOW_TITLE_DRAG_THIS},
   598 {  WWT_STICKYBOX,   RESIZE_NONE,     7,   148,   159,     0,    13, 0x0,                      STR_STICKY_BUTTON},
   618 {  WWT_STICKYBOX,   RESIZE_NONE,     7,   148,   159,     0,    13, 0x0,                      STR_STICKY_BUTTON},
   614 		case WE_PAINT:
   634 		case WE_PAINT:
   615 			DrawWindowWidgets(w);
   635 			DrawWindowWidgets(w);
   616 			break;
   636 			break;
   617 
   637 
   618 		case WE_CREATE:
   638 		case WE_CREATE:
   619 			w->LowerWidget(_scengen_town_size + 7);
   639 			w->LowerWidget(_scengen_town_size + TSEW_SMALLTOWN);
   620 			break;
   640 			break;
   621 
   641 
   622 		case WE_CLICK:
   642 		case WE_CLICK:
   623 			switch (e->we.click.widget) {
   643 			switch (e->we.click.widget) {
   624 				case 4: // new town
   644 				case TSEW_NEWTOWN:
   625 					HandlePlacePushButton(w, 4, SPR_CURSOR_TOWN, VHM_RECT, PlaceProc_Town);
   645 					HandlePlacePushButton(w, TSEW_NEWTOWN, SPR_CURSOR_TOWN, VHM_RECT, PlaceProc_Town);
   626 					break;
   646 					break;
   627 
   647 
   628 				case 5: {// random town
   648 				case TSEW_RANDOMTOWN: {
   629 					Town *t;
   649 					Town *t;
   630 					uint size = min(_scengen_town_size, (int)TSM_CITY);
   650 					uint size = min(_scengen_town_size, (int)TSM_CITY);
   631 					TownSizeMode mode = _scengen_town_size > TSM_CITY ? TSM_CITY : TSM_FIXED;
   651 					TownSizeMode mode = _scengen_town_size > TSM_CITY ? TSM_CITY : TSM_FIXED;
   632 
   652 
   633 					w->HandleButtonClick(5);
   653 					w->HandleButtonClick(TSEW_RANDOMTOWN);
   634 					_generating_world = true;
   654 					_generating_world = true;
   635 					t = CreateRandomTown(20, mode, size);
   655 					t = CreateRandomTown(20, mode, size);
   636 					_generating_world = false;
   656 					_generating_world = false;
   637 
   657 
   638 					if (t == NULL) {
   658 					if (t == NULL) {
   640 					} else {
   660 					} else {
   641 						ScrollMainWindowToTile(t->xy);
   661 						ScrollMainWindowToTile(t->xy);
   642 					}
   662 					}
   643 				} break;
   663 				} break;
   644 
   664 
   645 				case 6: // many random towns
   665 				case TSEW_MANYRANDOMTOWNS:
   646 					w->HandleButtonClick(6);
   666 					w->HandleButtonClick(TSEW_MANYRANDOMTOWNS);
   647 
   667 
   648 					_generating_world = true;
   668 					_generating_world = true;
   649 					if (!GenerateTowns()) ShowErrorMessage(STR_NO_SPACE_FOR_TOWN, STR_CANNOT_GENERATE_TOWN, 0, 0);
   669 					if (!GenerateTowns()) ShowErrorMessage(STR_NO_SPACE_FOR_TOWN, STR_CANNOT_GENERATE_TOWN, 0, 0);
   650 					_generating_world = false;
   670 					_generating_world = false;
   651 					break;
   671 					break;
   652 
   672 
   653 				case 7: case 8: case 9: case 10:
   673 				case TSEW_SMALLTOWN: case TSEW_MEDIUMTOWN: case TSEW_LARGETOWN: case TSEW_CITY:
   654 					w->RaiseWidget(_scengen_town_size + 7);
   674 					w->RaiseWidget(_scengen_town_size + TSEW_SMALLTOWN);
   655 					_scengen_town_size = e->we.click.widget - 7;
   675 					_scengen_town_size = e->we.click.widget - TSEW_SMALLTOWN;
   656 					w->LowerWidget(_scengen_town_size + 7);
   676 					w->LowerWidget(_scengen_town_size + TSEW_SMALLTOWN);
   657 					SetWindowDirty(w);
   677 					SetWindowDirty(w);
   658 					break;
   678 					break;
   659 			} break;
   679 			} break;
   660 
   680 
   661 		case WE_TIMEOUT:
   681 		case WE_TIMEOUT:
   662 			w->RaiseWidget(5);
   682 			w->RaiseWidget(TSEW_RANDOMTOWN);
   663 			w->RaiseWidget(6);
   683 			w->RaiseWidget(TSEW_MANYRANDOMTOWNS);
   664 			SetWindowDirty(w);
   684 			SetWindowDirty(w);
   665 			break;
   685 			break;
   666 
   686 
   667 		case WE_PLACE_OBJ:
   687 		case WE_PLACE_OBJ:
   668 			_place_proc(e->we.place.tile);
   688 			_place_proc(e->we.place.tile);
   669 			break;
   689 			break;
   670 
   690 
   671 		case WE_ABORT_PLACE_OBJ:
   691 		case WE_ABORT_PLACE_OBJ:
   672 			w->RaiseButtons();
   692 			w->RaiseButtons();
   673 			w->LowerWidget(_scengen_town_size + 7);
   693 			w->LowerWidget(_scengen_town_size + TSEW_SMALLTOWN);
   674 			SetWindowDirty(w);
   694 			SetWindowDirty(w);
   675 			break;
   695 			break;
   676 	}
   696 	}
   677 }
   697 }
   678 
   698