From 813b111710efe9a5f169a58b0186e4590543d388 Mon Sep 17 00:00:00 2001 From: Basssiiie Date: Mon, 18 Jan 2021 21:25:57 +0100 Subject: [PATCH] Fix #11912: Update active palette on selection --- distribution/changelog.txt | 1 + .../windows/EditorObjectSelection.cpp | 6 ++++ src/openrct2/EditorObjectSelectionSession.cpp | 33 +++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 7dfb201fab..a57df2e6f9 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -19,6 +19,7 @@ - Feature: [#13614] Add terrain surfaces from RollerCoaster Tycoon 1. - Feature: [#13675] [Plugin] Add context.setInterval and context.setTimeout. - Change: [#13346] [Plugin] Renamed FootpathScenery to FootpathAddition, fix typos. +- Fix: [#4605, #11912] Water palettes are not updated properly when selected in Object Selection. - Fix: [#9631, #10716] Banners drawing glitches when there are more than 32 on the screen at once. - Fix: [#12895] Mechanics are called to repair rides that have already been fixed. - Fix: [#13102] Underflow on height chart (Ride measurements). diff --git a/src/openrct2-ui/windows/EditorObjectSelection.cpp b/src/openrct2-ui/windows/EditorObjectSelection.cpp index 814a95d0eb..7ce2c6df7b 100644 --- a/src/openrct2-ui/windows/EditorObjectSelection.cpp +++ b/src/openrct2-ui/windows/EditorObjectSelection.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -1328,6 +1329,11 @@ static void editor_load_selected_objects() } } } + if (_numSelectedObjectsForType[EnumValue(ObjectType::Water)] == 0) + { + // Reloads the default cyan water palette if no palette was selected. + load_palette(); + } } static void window_editor_object_selection_update(rct_window* w) diff --git a/src/openrct2/EditorObjectSelectionSession.cpp b/src/openrct2/EditorObjectSelectionSession.cpp index beb0c068f3..f73f9bd42f 100644 --- a/src/openrct2/EditorObjectSelectionSession.cpp +++ b/src/openrct2/EditorObjectSelectionSession.cpp @@ -13,6 +13,7 @@ #include "Editor.h" #include "Game.h" #include "OpenRCT2.h" +#include "drawing/Drawing.h" #include "localisation/Localisation.h" #include "management/Research.h" #include "object/DefaultObjects.h" @@ -38,6 +39,7 @@ static void setup_track_designer_objects(); static void setup_track_manager_objects(); static void window_editor_object_selection_select_default_objects(); static void SelectDesignerObjects(); +static void ReplaceSelectedWaterPalette(const ObjectRepositoryItem* item); /** * @@ -370,6 +372,32 @@ static void SelectDesignerObjects() } } +/** + * Replaces the previously selected water palette with the palette in the specified item immediately. + */ +static void ReplaceSelectedWaterPalette(const ObjectRepositoryItem* item) +{ + auto& objectManager = OpenRCT2::GetContext()->GetObjectManager(); + Object* oldPalette = objectManager.GetLoadedObject(ObjectType::Water, 0); + + if (oldPalette != nullptr) + { + const std::vector oldEntries = { *(oldPalette->GetObjectEntry()) }; + objectManager.UnloadObjects(oldEntries); + } + + const rct_object_entry* newPaletteEntry = &item->ObjectEntry; + + if (objectManager.GetLoadedObject(newPaletteEntry) != nullptr || objectManager.LoadObject(newPaletteEntry) != nullptr) + { + load_palette(); + } + else + { + log_error("Failed to load selected palette %.8s", newPaletteEntry->name); + } +} + /** * * rct2: 0x006AA770 @@ -513,6 +541,11 @@ bool window_editor_object_selection_select_object(uint8_t isMasterObject, int32_ } } } + else if (objectType == ObjectType::Water) + { + // Replace old palette with newly selected palette immediately. + ReplaceSelectedWaterPalette(item); + } if (isMasterObject != 0 && !(flags & INPUT_FLAG_EDITOR_OBJECT_1)) {