mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-15 11:03:00 +01:00
Use loadsave window for selecting the heightmap
This commit is contained in:
committed by
Michał Janiszewski
parent
3095106b0e
commit
810103b90f
@@ -506,6 +506,7 @@ enum {
|
||||
LOADSAVETYPE_LANDSCAPE = 1 << 1,
|
||||
LOADSAVETYPE_SCENARIO = 2 << 1,
|
||||
LOADSAVETYPE_TRACK = 3 << 1,
|
||||
LOADSAVETYPE_IMAGE = 4 << 1,
|
||||
};
|
||||
|
||||
enum {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
#include <time.h>
|
||||
#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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user