src/genworld_gui.cpp
branchnoai
changeset 10455 22c441f5adf9
parent 9826 9707ad4c9b60
child 10513 33cb70ff2f5d
equal deleted inserted replaced
10412:ef44f62cb8b9 10455:22c441f5adf9
     1 /* $Id$ */
     1 /* $Id$ */
     2 
     2 
     3 /** @file genworld_gui.cpp */
     3 /** @file genworld_gui.cpp GUI to configure and show progress during map generation. */
     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 "gui.h"
     8 #include "gui.h"
    26 #include "gfx_func.h"
    26 #include "gfx_func.h"
    27 #include "settings_type.h"
    27 #include "settings_type.h"
    28 #include "widgets/dropdown_type.h"
    28 #include "widgets/dropdown_type.h"
    29 #include "widgets/dropdown_func.h"
    29 #include "widgets/dropdown_func.h"
    30 #include "core/random_func.hpp"
    30 #include "core/random_func.hpp"
       
    31 #include "landscape_type.h"
    31 
    32 
    32 #include "table/strings.h"
    33 #include "table/strings.h"
    33 #include "table/sprites.h"
    34 #include "table/sprites.h"
    34 
    35 
    35 /**
    36 /**
   340 			}
   341 			}
   341 			break;
   342 			break;
   342 
   343 
   343 		case WE_CLICK:
   344 		case WE_CLICK:
   344 			switch (e->we.click.widget) {
   345 			switch (e->we.click.widget) {
   345 				case 0: DeleteWindow(w); break;
   346 				case 0: delete w; break;
   346 
   347 
   347 				case GLAND_TEMPERATE:
   348 				case GLAND_TEMPERATE:
   348 				case GLAND_ARCTIC:
   349 				case GLAND_ARCTIC:
   349 				case GLAND_TROPICAL:
   350 				case GLAND_TROPICAL:
   350 				case GLAND_TOYLAND:
   351 				case GLAND_TOYLAND:
   370 
   371 
   371 				case GLAND_RANDOM_BUTTON: // Random seed
   372 				case GLAND_RANDOM_BUTTON: // Random seed
   372 					_patches_newgame.generation_seed = InteractiveRandom();
   373 					_patches_newgame.generation_seed = InteractiveRandom();
   373 					snprintf(_genseed_buffer, lengthof(_genseed_buffer), "%u", _patches_newgame.generation_seed);
   374 					snprintf(_genseed_buffer, lengthof(_genseed_buffer), "%u", _patches_newgame.generation_seed);
   374 					UpdateTextBufferSize(&_genseed_query.text);
   375 					UpdateTextBufferSize(&_genseed_query.text);
   375 					SetWindowDirty(w);
   376 					w->SetDirty();
   376 					break;
   377 					break;
   377 
   378 
   378 				case GLAND_RANDOM_EDITBOX: // edit box for random seed
   379 				case GLAND_RANDOM_EDITBOX: // edit box for random seed
   379 					ShowOnScreenKeyboard(w, & _genseed_query, GLAND_RANDOM_EDITBOX, 0, 0);
   380 					ShowOnScreenKeyboard(w, & _genseed_query, GLAND_RANDOM_EDITBOX, 0, 0);
   380 					break;
   381 					break;
   406 				case GLAND_START_DATE_DOWN:
   407 				case GLAND_START_DATE_DOWN:
   407 				case GLAND_START_DATE_UP: // Year buttons
   408 				case GLAND_START_DATE_UP: // Year buttons
   408 					/* Don't allow too fast scrolling */
   409 					/* Don't allow too fast scrolling */
   409 					if ((w->flags4 & WF_TIMEOUT_MASK) <= 2 << WF_TIMEOUT_SHL) {
   410 					if ((w->flags4 & WF_TIMEOUT_MASK) <= 2 << WF_TIMEOUT_SHL) {
   410 						w->HandleButtonClick(e->we.click.widget);
   411 						w->HandleButtonClick(e->we.click.widget);
   411 						SetWindowDirty(w);
   412 						w->SetDirty();
   412 
   413 
   413 						_patches_newgame.starting_year = Clamp(_patches_newgame.starting_year + e->we.click.widget - GLAND_START_DATE_TEXT, MIN_YEAR, MAX_YEAR);
   414 						_patches_newgame.starting_year = Clamp(_patches_newgame.starting_year + e->we.click.widget - GLAND_START_DATE_TEXT, MIN_YEAR, MAX_YEAR);
   414 					}
   415 					}
   415 					_left_button_clicked = false;
   416 					_left_button_clicked = false;
   416 					break;
   417 					break;
   424 				case GLAND_SNOW_LEVEL_DOWN:
   425 				case GLAND_SNOW_LEVEL_DOWN:
   425 				case GLAND_SNOW_LEVEL_UP: // Snow line buttons
   426 				case GLAND_SNOW_LEVEL_UP: // Snow line buttons
   426 					/* Don't allow too fast scrolling */
   427 					/* Don't allow too fast scrolling */
   427 					if ((w->flags4 & WF_TIMEOUT_MASK) <= 2 << WF_TIMEOUT_SHL) {
   428 					if ((w->flags4 & WF_TIMEOUT_MASK) <= 2 << WF_TIMEOUT_SHL) {
   428 						w->HandleButtonClick(e->we.click.widget);
   429 						w->HandleButtonClick(e->we.click.widget);
   429 						SetWindowDirty(w);
   430 						w->SetDirty();
   430 
   431 
   431 						_patches_newgame.snow_line_height = Clamp(_patches_newgame.snow_line_height + e->we.click.widget - GLAND_SNOW_LEVEL_TEXT, 2, MAX_SNOWLINE_HEIGHT);
   432 						_patches_newgame.snow_line_height = Clamp(_patches_newgame.snow_line_height + e->we.click.widget - GLAND_SNOW_LEVEL_TEXT, 2, MAX_SNOWLINE_HEIGHT);
   432 					}
   433 					}
   433 					_left_button_clicked = false;
   434 					_left_button_clicked = false;
   434 					break;
   435 					break;
   518 					_opt_newgame.diff.quantity_sea_lakes = e->we.dropdown.index;
   519 					_opt_newgame.diff.quantity_sea_lakes = e->we.dropdown.index;
   519 					if (_opt_newgame.diff_level != 3) ShowErrorMessage(INVALID_STRING_ID, STR_DIFFICULTY_TO_CUSTOM, 0, 0);
   520 					if (_opt_newgame.diff_level != 3) ShowErrorMessage(INVALID_STRING_ID, STR_DIFFICULTY_TO_CUSTOM, 0, 0);
   520 					DoCommandP(0, 13, _opt_newgame.diff.quantity_sea_lakes, NULL, CMD_CHANGE_DIFFICULTY_LEVEL);
   521 					DoCommandP(0, 13, _opt_newgame.diff.quantity_sea_lakes, NULL, CMD_CHANGE_DIFFICULTY_LEVEL);
   521 					break;
   522 					break;
   522 			}
   523 			}
   523 			SetWindowDirty(w);
   524 			w->SetDirty();
   524 			break;
   525 			break;
   525 
   526 
   526 		case WE_ON_EDIT_TEXT:
   527 		case WE_ON_EDIT_TEXT:
   527 			if (e->we.edittext.str != NULL) {
   528 			if (e->we.edittext.str != NULL) {
   528 				int32 value = atoi(e->we.edittext.str);
   529 				int32 value = atoi(e->we.edittext.str);
   537 						w->InvalidateWidget(GLAND_SNOW_LEVEL_TEXT);
   538 						w->InvalidateWidget(GLAND_SNOW_LEVEL_TEXT);
   538 						_patches_newgame.snow_line_height = Clamp(value, 2, MAX_SNOWLINE_HEIGHT);
   539 						_patches_newgame.snow_line_height = Clamp(value, 2, MAX_SNOWLINE_HEIGHT);
   539 						break;
   540 						break;
   540 				}
   541 				}
   541 
   542 
   542 				SetWindowDirty(w);
   543 				w->SetDirty();
   543 			}
   544 			}
   544 			break;
   545 			break;
   545 	}
   546 	}
   546 }
   547 }
   547 
   548 
   695 				case CSCEN_START_DATE_DOWN:
   696 				case CSCEN_START_DATE_DOWN:
   696 				case CSCEN_START_DATE_UP: // Year buttons
   697 				case CSCEN_START_DATE_UP: // Year buttons
   697 					/* Don't allow too fast scrolling */
   698 					/* Don't allow too fast scrolling */
   698 					if ((w->flags4 & WF_TIMEOUT_MASK) <= 2 << WF_TIMEOUT_SHL) {
   699 					if ((w->flags4 & WF_TIMEOUT_MASK) <= 2 << WF_TIMEOUT_SHL) {
   699 						w->HandleButtonClick(e->we.click.widget);
   700 						w->HandleButtonClick(e->we.click.widget);
   700 						SetWindowDirty(w);
   701 						w->SetDirty();
   701 
   702 
   702 						_patches_newgame.starting_year = Clamp(_patches_newgame.starting_year + e->we.click.widget - CSCEN_START_DATE_TEXT, MIN_YEAR, MAX_YEAR);
   703 						_patches_newgame.starting_year = Clamp(_patches_newgame.starting_year + e->we.click.widget - CSCEN_START_DATE_TEXT, MIN_YEAR, MAX_YEAR);
   703 					}
   704 					}
   704 					_left_button_clicked = false;
   705 					_left_button_clicked = false;
   705 					break;
   706 					break;
   713 				case CSCEN_FLAT_LAND_HEIGHT_DOWN:
   714 				case CSCEN_FLAT_LAND_HEIGHT_DOWN:
   714 				case CSCEN_FLAT_LAND_HEIGHT_UP: // Height level buttons
   715 				case CSCEN_FLAT_LAND_HEIGHT_UP: // Height level buttons
   715 					/* Don't allow too fast scrolling */
   716 					/* Don't allow too fast scrolling */
   716 					if ((w->flags4 & WF_TIMEOUT_MASK) <= 2 << WF_TIMEOUT_SHL) {
   717 					if ((w->flags4 & WF_TIMEOUT_MASK) <= 2 << WF_TIMEOUT_SHL) {
   717 						w->HandleButtonClick(e->we.click.widget);
   718 						w->HandleButtonClick(e->we.click.widget);
   718 						SetWindowDirty(w);
   719 						w->SetDirty();
   719 
   720 
   720 						_patches_newgame.se_flat_world_height = Clamp(_patches_newgame.se_flat_world_height + e->we.click.widget - CSCEN_FLAT_LAND_HEIGHT_TEXT, 0, MAX_TILE_HEIGHT);
   721 						_patches_newgame.se_flat_world_height = Clamp(_patches_newgame.se_flat_world_height + e->we.click.widget - CSCEN_FLAT_LAND_HEIGHT_TEXT, 0, MAX_TILE_HEIGHT);
   721 					}
   722 					}
   722 					_left_button_clicked = false;
   723 					_left_button_clicked = false;
   723 					break;
   724 					break;
   733 		case WE_DROPDOWN_SELECT:
   734 		case WE_DROPDOWN_SELECT:
   734 			switch (e->we.dropdown.button) {
   735 			switch (e->we.dropdown.button) {
   735 				case CSCEN_MAPSIZE_X_PULLDOWN: _patches_newgame.map_x = e->we.dropdown.index; break;
   736 				case CSCEN_MAPSIZE_X_PULLDOWN: _patches_newgame.map_x = e->we.dropdown.index; break;
   736 				case CSCEN_MAPSIZE_Y_PULLDOWN: _patches_newgame.map_y = e->we.dropdown.index; break;
   737 				case CSCEN_MAPSIZE_Y_PULLDOWN: _patches_newgame.map_y = e->we.dropdown.index; break;
   737 			}
   738 			}
   738 			SetWindowDirty(w);
   739 			w->SetDirty();
   739 			break;
   740 			break;
   740 
   741 
   741 		case WE_ON_EDIT_TEXT:
   742 		case WE_ON_EDIT_TEXT:
   742 			if (e->we.edittext.str != NULL) {
   743 			if (e->we.edittext.str != NULL) {
   743 				int32 value = atoi(e->we.edittext.str);
   744 				int32 value = atoi(e->we.edittext.str);
   752 						w->InvalidateWidget(CSCEN_FLAT_LAND_HEIGHT_TEXT);
   753 						w->InvalidateWidget(CSCEN_FLAT_LAND_HEIGHT_TEXT);
   753 						_patches_newgame.se_flat_world_height = Clamp(value, 0, MAX_TILE_HEIGHT);
   754 						_patches_newgame.se_flat_world_height = Clamp(value, 0, MAX_TILE_HEIGHT);
   754 						break;
   755 						break;
   755 				}
   756 				}
   756 
   757 
   757 				SetWindowDirty(w);
   758 				w->SetDirty();
   758 			}
   759 			}
   759 			break;
   760 			break;
   760 	}
   761 	}
   761 }
   762 }
   762 
   763 
   863 			/* And say where we are in that class */
   864 			/* And say where we are in that class */
   864 			SetDParam(0, _tp.current);
   865 			SetDParam(0, _tp.current);
   865 			SetDParam(1, _tp.total);
   866 			SetDParam(1, _tp.total);
   866 			DrawStringCentered(90, 58, STR_GENERATION_PROGRESS, TC_FROMSTRING);
   867 			DrawStringCentered(90, 58, STR_GENERATION_PROGRESS, TC_FROMSTRING);
   867 
   868 
   868 			SetWindowDirty(w);
   869 			w->SetDirty();
   869 			break;
   870 			break;
   870 	}
   871 	}
   871 }
   872 }
   872 
   873 
   873 static const WindowDesc _show_terrain_progress_desc = {
   874 static const WindowDesc _show_terrain_progress_desc = {