From 810103b90f11ecbb7e8e4215c8a802e2f60dc9bc Mon Sep 17 00:00:00 2001 From: Broxzier Date: Tue, 7 Mar 2017 16:59:50 +0100 Subject: [PATCH] Use loadsave window for selecting the heightmap --- src/openrct2/interface/window.h | 1 + src/openrct2/windows/loadsave.c | 13 +++++++++ src/openrct2/windows/mapgen.c | 50 ++++++++++++++++++++++----------- src/openrct2/world/mapgen.c | 4 ++- src/openrct2/world/mapgen.h | 2 ++ 5 files changed, 53 insertions(+), 17 deletions(-) diff --git a/src/openrct2/interface/window.h b/src/openrct2/interface/window.h index 3832933240..2e0873640c 100644 --- a/src/openrct2/interface/window.h +++ b/src/openrct2/interface/window.h @@ -506,6 +506,7 @@ enum { LOADSAVETYPE_LANDSCAPE = 1 << 1, LOADSAVETYPE_SCENARIO = 2 << 1, LOADSAVETYPE_TRACK = 3 << 1, + LOADSAVETYPE_IMAGE = 4 << 1, }; enum { diff --git a/src/openrct2/windows/loadsave.c b/src/openrct2/windows/loadsave.c index 7b36028c49..3d5301f299 100644 --- a/src/openrct2/windows/loadsave.c +++ b/src/openrct2/windows/loadsave.c @@ -16,6 +16,7 @@ #include #include "../config/Config.h" +#include "../core/Guard.hpp" #include "../editor.h" #include "../game.h" #include "../interface/themes.h" @@ -215,6 +216,14 @@ rct_window *window_loadsave_open(sint32 type, char *defaultName) success = true; } break; + case LOADSAVETYPE_IMAGE: + openrct2_assert(isSave == false, "Cannot save images through loadsave window"); + w->widgets[WIDX_TITLE].text = STR_FILE_DIALOG_TITLE_LOAD_HEIGHTMAP; + if (window_loadsave_get_dir(gConfigGeneral.last_save_track_directory, path, "", sizeof(path))) { + window_loadsave_populate_list(w, false, path, ".bmp"); + success = true; + } + break; default: log_error("Unsupported load/save type: %d", type & 0x0F); } @@ -812,6 +821,10 @@ static void window_loadsave_select(rct_window *w, const char *path) window_loadsave_invoke_callback(MODAL_RESULT_FAIL, path); } } + case (LOADSAVETYPE_LOAD | LOADSAVETYPE_IMAGE): + window_close_by_class(WC_LOADSAVE); + window_loadsave_invoke_callback(MODAL_RESULT_OK, path); + break; } } diff --git a/src/openrct2/windows/mapgen.c b/src/openrct2/windows/mapgen.c index a055a630e6..f3e7e5146d 100644 --- a/src/openrct2/windows/mapgen.c +++ b/src/openrct2/windows/mapgen.c @@ -190,7 +190,7 @@ static rct_widget SimplexWidgets[] = { static rct_widget HeightmapWidgets[] = { SHARED_WIDGETS, - { WWT_DROPDOWN_BUTTON, 1, WW - 95, WW - 6, WH - 17, WH - 6, STR_MAPGEN_ACTION_GENERATE, STR_NONE }, // WIDX_HEIGHTMAP_SELECT + { WWT_DROPDOWN_BUTTON, 1, WW - 155, WW - 6, WH - 17, WH - 6, STR_MAPGEN_SELECT_HEIGHTMAP, STR_NONE }, // WIDX_HEIGHTMAP_SELECT { WWT_CHECKBOX, 1, 4, 103, 52, 63, STR_MAPGEN_SMOOTH_HEIGHTMAP,STR_NONE }, // WIDX_HEIGHTMAP_SMOOTH_HEIGHTMAP { WWT_SPINNER, 1, 104, 198, 70, 81, STR_NONE, STR_NONE }, // WIDX_HEIGHTMAP_STRENGTH @@ -564,6 +564,7 @@ static sint32 _simplex_octaves = 4; static bool _heightmapSmoothMap = false; static sint32 _heightmapSmoothStrength = 1; static bool _heightmapNormalize = false; +static bool _heightmapSmoothTiles = true; static sint32 _heightmapLow = 6; static sint32 _heightmapHigh = 40; @@ -1177,6 +1178,31 @@ static void window_mapgen_heightmap_mousedown(sint32 widgetIndex, rct_window *w, } } +static void window_mapgen_heightmap_generate_map(rct_window *w) +{ + mapgen_settings mapgenSettings; + mapgenSettings.water_level = _waterLevel; + mapgenSettings.smooth = _heightmapSmoothTiles; + mapgenSettings.smooth_height_map = _heightmapSmoothMap; + mapgenSettings.smooth_strength = _heightmapSmoothStrength; + mapgenSettings.normalize_height = _heightmapNormalize; + mapgenSettings.simplex_low = _heightmapLow; + mapgenSettings.simplex_high = _heightmapHigh; + mapgen_generate_from_heightmap(&mapgenSettings); + gfx_invalidate_screen(); +} + +static void window_mapgen_heightmap_loadsave_callback(sint32 result, const utf8 *path) +{ + if (result == MODAL_RESULT_OK) + { + strcpy(heightmap_path, path); + + rct_window *const w = window_find_by_class(WC_MAPGEN); + window_mapgen_heightmap_generate_map(w); + } +} + static void window_mapgen_heightmap_mouseup(rct_window *w, sint32 widgetIndex) { window_mapgen_shared_mouseup(w, widgetIndex); @@ -1188,12 +1214,13 @@ static void window_mapgen_heightmap_mouseup(rct_window *w, sint32 widgetIndex) case WIDX_TAB_2: case WIDX_TAB_3: case WIDX_TAB_4: - return; // Don't generate map + return; // Only widgets that change a setting need to regenerate the map // Page widgets case WIDX_HEIGHTMAP_SELECT: - // TODO: Open image select window - break; + window_loadsave_open(LOADSAVETYPE_LOAD | LOADSAVETYPE_IMAGE, NULL); + window_loadsave_set_loadsave_callback(window_mapgen_heightmap_loadsave_callback); + return; case WIDX_HEIGHTMAP_SMOOTH_HEIGHTMAP: _heightmapSmoothMap = !_heightmapSmoothMap; widget_set_checkbox_value(w, WIDX_HEIGHTMAP_SMOOTH_HEIGHTMAP, _heightmapSmoothMap); @@ -1209,23 +1236,14 @@ static void window_mapgen_heightmap_mouseup(rct_window *w, sint32 widgetIndex) widget_invalidate(w, WIDX_HEIGHTMAP_NORMALIZE); break; case WIDX_HEIGHTMAP_SMOOTH_TILES: - widget_set_checkbox_value(w, WIDX_HEIGHTMAP_SMOOTH_TILES, !widget_is_pressed(w, WIDX_HEIGHTMAP_SMOOTH_TILES)); + _heightmapSmoothTiles = !_heightmapSmoothTiles; + widget_set_checkbox_value(w, _heightmapSmoothTiles, _heightmapSmoothTiles); widget_invalidate(w, WIDX_HEIGHTMAP_SMOOTH_TILES); break; } // Always regenerate the map after one of the page widgets has been changed - mapgen_settings mapgenSettings; - mapgenSettings.water_level = _waterLevel; - mapgenSettings.smooth = widget_is_pressed(w, WIDX_HEIGHTMAP_SMOOTH_TILES); - mapgenSettings.smooth_height_map = _heightmapSmoothMap; - mapgenSettings.smooth_strength = _heightmapSmoothStrength; - mapgenSettings.normalize_height = _heightmapNormalize; - mapgenSettings.simplex_low = _heightmapLow; - mapgenSettings.simplex_high = _heightmapHigh; - mapgen_generate_from_heightmap(&mapgenSettings); - gfx_invalidate_screen(); - + window_mapgen_heightmap_generate_map(w); } static void window_mapgen_heightmap_invalidate(rct_window *w) diff --git a/src/openrct2/world/mapgen.c b/src/openrct2/world/mapgen.c index be63b132a1..6aa6230f8a 100644 --- a/src/openrct2/world/mapgen.c +++ b/src/openrct2/world/mapgen.c @@ -25,6 +25,8 @@ #pragma region Random objects +char heightmap_path[260] = ""; + const char *GrassTrees[] = { // Dark "TCF ", // Caucasian Fir Tree @@ -830,7 +832,7 @@ void mapgen_generate_from_heightmap(mapgen_settings *settings) { openrct2_assert(settings->simplex_high != settings->simplex_low, "Low and high setting cannot be the same"); - SDL_Surface *bitmap = SDL_LoadBMP("test_blurry.bmp"); + SDL_Surface *bitmap = SDL_LoadBMP(heightmap_path); if (bitmap == NULL) { printf("Failed to load bitmap: %s\n", SDL_GetError()); diff --git a/src/openrct2/world/mapgen.h b/src/openrct2/world/mapgen.h index 9755b2f4ca..a3148bd60b 100644 --- a/src/openrct2/world/mapgen.h +++ b/src/openrct2/world/mapgen.h @@ -41,6 +41,8 @@ typedef struct mapgen_settings { bool normalize_height; } mapgen_settings; +extern char heightmap_path[260]; + void mapgen_generate_blank(mapgen_settings *settings); void mapgen_generate(mapgen_settings *settings); void mapgen_generate_custom_simplex(mapgen_settings *settings);