Changeset - r5464:3087751bfbbc
[Not reviewed]
master
0 1 0
rubidium - 17 years ago 2007-01-01 22:46:10
rubidium@openttd.org
(svn r7733) -Fix (r5946): do not use WP(w, querystr_d) and WP(w, def_d) for the same window.
1 file changed with 18 insertions and 15 deletions:
0 comments (0 inline, 0 general)
genworld_gui.c
Show inline comments
 
@@ -40,13 +40,12 @@ typedef enum glwp_modes {
 
	GLWP_GENERATE,
 
	GLWP_HEIGHTMAP,
 
	GLWP_SCENARIO,
 
	GLWP_END
 
} glwp_modes;
 

	
 
static char _edit_str_buf[LEN_RND_SEED];
 
static uint _heightmap_x = 0;
 
static uint _heightmap_y = 0;
 
static StringID _heightmap_str = STR_NULL;
 
static bool _goto_editor = false;
 

	
 
extern void SwitchMode(int new_mode);
 
@@ -190,17 +189,28 @@ void GenerateLandscapeWndProc(Window *w,
 
	static const StringID tree_placer[] = {STR_CONFIG_PATCHES_TREE_PLACER_NONE, STR_CONFIG_PATCHES_TREE_PLACER_ORIGINAL, STR_CONFIG_PATCHES_TREE_PLACER_IMPROVED, INVALID_STRING_ID};
 
	static const StringID rotation[]    = {STR_CONFIG_PATCHES_HEIGHTMAP_ROTATION_COUNTER_CLOCKWISE, STR_CONFIG_PATCHES_HEIGHTMAP_ROTATION_CLOCKWISE, INVALID_STRING_ID};
 
	static const StringID landscape[]   = {STR_CONFIG_PATCHES_LAND_GENERATOR_ORIGINAL, STR_CONFIG_PATCHES_LAND_GENERATOR_TERRA_GENESIS, INVALID_STRING_ID};
 
	static const StringID num_towns[]   = {STR_6816_LOW, STR_6817_NORMAL, STR_6818_HIGH, INVALID_STRING_ID};
 
	static const StringID num_inds[]    = {STR_26816_NONE, STR_6816_LOW, STR_6817_NORMAL, STR_6818_HIGH, INVALID_STRING_ID};
 

	
 
	/* Data used for the generate seed edit box */
 
	static querystr_d _genseed_query;
 
	static char _genseed_buffer[LEN_RND_SEED];
 

	
 
	uint mode = w->window_number;
 
	uint y;
 

	
 
	switch (e->event) {
 
	case WE_CREATE: LowerWindowWidget(w, _opt_newgame.landscape + 3); break;
 
	case WE_CREATE:
 
		LowerWindowWidget(w, _opt_newgame.landscape + 3);
 

	
 
		snprintf(_genseed_buffer, sizeof(_genseed_buffer), "%u", _patches_newgame.generation_seed);
 
		InitializeTextBuffer(&_genseed_query.text, _genseed_buffer, lengthof(_genseed_buffer), 120);
 
		_genseed_query.caption = STR_NULL;
 
		_genseed_query.afilter = CS_NUMERAL;
 
		break;
 

	
 
	case WE_PAINT:
 
		/* You can't select smoothness if not terragenesis */
 
		if (mode == GLWP_GENERATE) {
 
			SetWindowWidgetDisabledState(w, 32, _patches_newgame.land_generator == 0);
 
			SetWindowWidgetDisabledState(w, 33, _patches_newgame.land_generator == 0);
 
@@ -241,13 +251,13 @@ void GenerateLandscapeWndProc(Window *w,
 
		} else {
 
			DrawString(118, 113 + y, num_towns[_opt_newgame.diff.number_towns], 0x10);
 
			DrawString(118, 131 + y, num_inds[_opt_newgame.diff.number_industries], 0x10);
 
		}
 

	
 
		DrawString( 12, 153 + y, STR_RANDOM_SEED, 0);
 
		DrawEditBox(w, &WP(w, querystr_d), SEED_EDIT);
 
		DrawEditBox(w, &_genseed_query, SEED_EDIT);
 

	
 
		DrawString(182, 113 + y, STR_DATE, 0);
 
		SetDParam(0, ConvertYMDToDate(_patches_newgame.starting_year, 0, 1));
 
		DrawStringCentered(271, 113 + y, STR_GENERATE_DATE, 0);
 

	
 
		DrawString(182, 131 + y, STR_SNOW_LINE_HEIGHT, 0);
 
@@ -312,14 +322,14 @@ void GenerateLandscapeWndProc(Window *w,
 
			break;
 
		case 13: case 14: // Number of industries
 
			ShowDropDownMenu(w, num_inds, _opt_newgame.diff.number_industries, 14, 0, 0);
 
			break;
 
		case 16: // Random seed
 
			_patches_newgame.generation_seed = InteractiveRandom();
 
			snprintf(_edit_str_buf, lengthof(_edit_str_buf), "%u", _patches_newgame.generation_seed);
 
			UpdateTextBufferSize(&WP(w, querystr_d).text);
 
			snprintf(_genseed_buffer, lengthof(_genseed_buffer), "%u", _patches_newgame.generation_seed);
 
			UpdateTextBufferSize(&_genseed_query.text);
 
			SetWindowDirty(w);
 
			break;
 
		case 17: // Generate
 
			if (mode == GLWP_HEIGHTMAP && (
 
					_heightmap_x * 2 < (1U << _patches_newgame.map_x) || _heightmap_x / 2 > (1U << _patches_newgame.map_x) ||
 
					_heightmap_y * 2 < (1U << _patches_newgame.map_y) || _heightmap_y / 2 > (1U << _patches_newgame.map_y))) {
 
@@ -382,23 +392,23 @@ void GenerateLandscapeWndProc(Window *w,
 
			ShowDropDownMenu(w, smoothness, _patches_newgame.tgen_smoothness, 33, 0, 0);
 
			break;
 
		}
 
		break;
 

	
 
	case WE_MOUSELOOP:
 
		HandleEditBox(w, &WP(w, querystr_d), SEED_EDIT);
 
		HandleEditBox(w, &_genseed_query, SEED_EDIT);
 
		break;
 

	
 
	case WE_KEYPRESS:
 
		HandleEditBoxKey(w, &WP(w, querystr_d), SEED_EDIT, e);
 
		HandleEditBoxKey(w, &_genseed_query, SEED_EDIT, e);
 
		/* the seed is unsigned, therefore atoi cannot be used.
 
		 * As 2^32 - 1 (MAX_UVALUE(uint32)) is a 'magic' value
 
		 * (use random seed) it should not be possible to be
 
		 * entered into the input field; the generate seed
 
		 * button can be used instead. */
 
		_patches_newgame.generation_seed = minu(strtoul(_edit_str_buf, NULL, 10), MAX_UVALUE(uint32) - 1);
 
		_patches_newgame.generation_seed = minu(strtoul(_genseed_buffer, NULL, sizeof(_genseed_buffer) - 1), MAX_UVALUE(uint32) - 1);
 
		break;
 

	
 
	case WE_DROPDOWN_SELECT:
 
		switch (e->we.dropdown.button) {
 
			case 8:  _patches_newgame.map_x = e->we.dropdown.index + 6; break;
 
			case 10: _patches_newgame.map_y = e->we.dropdown.index + 6; break;
 
@@ -500,19 +510,12 @@ static void _ShowGenerateLandscape(glwp_
 
			return;
 
	}
 

	
 
	w = AllocateWindowDescFront((mode == GLWP_HEIGHTMAP) ? &_heightmap_load_desc : &_generate_landscape_desc, mode);
 

	
 
	if (w != NULL) {
 
		querystr_d *querystr = &WP(w, querystr_d);
 

	
 
		snprintf(_edit_str_buf, lengthof(_edit_str_buf), "%u", _patches_newgame.generation_seed);
 

	
 
		InitializeTextBuffer(&querystr->text, _edit_str_buf, lengthof(_edit_str_buf), 120);
 
		querystr->caption = STR_NULL;
 
		querystr->afilter = CS_NUMERAL;
 

	
 
		InvalidateWindow(WC_GENERATE_LANDSCAPE, mode);
 
	}
 
}
 

	
 
void ShowGenerateLandscape(void)
0 comments (0 inline, 0 general)