From e27a20f800b12f6dd593ddf73d85ee03228d095b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Severin=20Paul=20H=C3=B6fer?= <84280965+zzril@users.noreply.github.com> Date: Sat, 20 Jan 2024 23:38:49 +0100 Subject: [PATCH 1/7] Sort entries in entrance style dropdown --- src/openrct2-ui/windows/Ride.cpp | 106 +++++++++++++++++++------------ 1 file changed, 64 insertions(+), 42 deletions(-) diff --git a/src/openrct2-ui/windows/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp index d7099ad689..c80bbb577c 100644 --- a/src/openrct2-ui/windows/Ride.cpp +++ b/src/openrct2-ui/windows/Ride.cpp @@ -49,6 +49,7 @@ #include #include #include +#include #include #include #include @@ -619,6 +620,14 @@ struct VehicleTypeLabel const char* label_string; }; +// Used for sorting the entrance type dropdown. +struct EntranceTypeLabel +{ + ObjectEntryIndex ObjIndex; + StringId Name; + uint8_t StationStyle; +}; + class RideWindow final : public Window { int16_t _viewIndex; @@ -630,6 +639,7 @@ class RideWindow final : public Window std::vector _vehicleDropdownData; int16_t _vehicleIndex = 0; uint16_t _rideColour = 0; + std::vector _entranceStyleDropdownData; bool _autoScrollGraph = true; public: @@ -1989,6 +1999,48 @@ private: Dropdown::SetChecked(pos, true); } + void PopulateEntranceStyleDropdown() + { + _entranceStyleDropdownData.clear(); + + auto& objManager = GetContext()->GetObjectManager(); + + for (ObjectEntryIndex i = 0; i < MAX_STATION_OBJECTS; i++) + { + auto stationObj = static_cast(objManager.GetLoadedObject(ObjectType::Station, i)); + if (stationObj != nullptr) + { + _entranceStyleDropdownData.push_back( + { i, stationObj->NameStringId, GetStationStyleFromIdentifier(stationObj->GetIdentifier()) }); + } + } + + std::stable_sort( + _entranceStyleDropdownData.begin(), _entranceStyleDropdownData.end(), + [](const EntranceTypeLabel& a, const EntranceTypeLabel& b) { return a.StationStyle < b.StationStyle; }); + } + + void ShowEntranceStyleDropdown() + { + auto dropdownWidget = &widgets[WIDX_ENTRANCE_STYLE_DROPDOWN] - 1; + auto ride = GetRide(rideId); + + PopulateEntranceStyleDropdown(); + + for (size_t i = 0; i < _entranceStyleDropdownData.size(); i++) + { + gDropdownItems[i].Args = _entranceStyleDropdownData[i].Name; + gDropdownItems[i].Format = _entranceStyleDropdownData[i].ObjIndex == ride->entrance_style + ? STR_DROPDOWN_MENU_LABEL_SELECTED + : STR_DROPDOWN_MENU_LABEL; + } + + WindowDropdownShowTextCustomWidth( + { windowPos.x + dropdownWidget->left, windowPos.y + dropdownWidget->top }, dropdownWidget->height() + 1, colours[1], + 0, Dropdown::Flag::StayOpen, _entranceStyleDropdownData.size(), + widgets[WIDX_ENTRANCE_STYLE_DROPDOWN].right - dropdownWidget->left); + } + void MainOnMouseDown(WidgetIndex widgetIndex) { switch (widgetIndex) @@ -4152,29 +4204,8 @@ private: Dropdown::SetChecked(ride->track_colour[colourSchemeIndex].supports, true); break; case WIDX_ENTRANCE_STYLE_DROPDOWN: - { - auto ddIndex = 0; - auto& objManager = GetContext()->GetObjectManager(); - for (i = 0; i < MAX_STATION_OBJECTS; i++) - { - auto stationObj = static_cast(objManager.GetLoadedObject(ObjectType::Station, i)); - if (stationObj != nullptr) - { - gDropdownItems[ddIndex].Format = STR_DROPDOWN_MENU_LABEL; - gDropdownItems[ddIndex].Args = stationObj->NameStringId; - if (ride->entrance_style == i) - { - gDropdownItems[ddIndex].Format = STR_DROPDOWN_MENU_LABEL_SELECTED; - } - ddIndex++; - } - } - - WindowDropdownShowTextCustomWidth( - { windowPos.x + dropdownWidget->left, windowPos.y + dropdownWidget->top }, dropdownWidget->height() + 1, - colours[1], 0, Dropdown::Flag::StayOpen, ddIndex, widgets[widgetIndex].right - dropdownWidget->left); + ShowEntranceStyleDropdown(); break; - } case WIDX_VEHICLE_COLOUR_SCHEME_DROPDOWN: for (i = 0; i < 3; i++) { @@ -4271,28 +4302,19 @@ private: break; case WIDX_ENTRANCE_STYLE_DROPDOWN: { - auto ddIndex = 0; - auto& objManager = GetContext()->GetObjectManager(); - for (auto i = 0; i < MAX_STATION_OBJECTS; i++) + if (static_cast(dropdownIndex) >= _entranceStyleDropdownData.size()) { - auto stationObj = static_cast(objManager.GetLoadedObject(ObjectType::Station, i)); - if (stationObj != nullptr) - { - if (ddIndex == dropdownIndex) - { - auto rideSetAppearanceAction = RideSetAppearanceAction( - rideId, RideSetAppearanceType::EntranceStyle, ddIndex, 0); - rideSetAppearanceAction.SetCallback([ddIndex](const GameAction*, const GameActions::Result* res) { - if (res->Error != GameActions::Status::Ok) - return; - gLastEntranceStyle = ddIndex; - }); - GameActions::Execute(&rideSetAppearanceAction); - break; - } - ddIndex++; - } + break; } + auto objIndex = _entranceStyleDropdownData[dropdownIndex].ObjIndex; + auto rideSetAppearanceAction = RideSetAppearanceAction( + rideId, RideSetAppearanceType::EntranceStyle, objIndex, 0); + rideSetAppearanceAction.SetCallback([objIndex](const GameAction*, const GameActions::Result* res) { + if (res->Error != GameActions::Status::Ok) + return; + gLastEntranceStyle = objIndex; + }); + GameActions::Execute(&rideSetAppearanceAction); break; } case WIDX_VEHICLE_COLOUR_SCHEME_DROPDOWN: From e8b05c4afd8a536c300d1f9f0d52eaa2242abf42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Severin=20Paul=20H=C3=B6fer?= <84280965+zzril@users.noreply.github.com> Date: Mon, 22 Jan 2024 21:47:08 +0100 Subject: [PATCH 2/7] Sort entrance styles alphabetically --- src/openrct2-ui/windows/Ride.cpp | 40 ++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/src/openrct2-ui/windows/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp index c80bbb577c..236a7cb689 100644 --- a/src/openrct2-ui/windows/Ride.cpp +++ b/src/openrct2-ui/windows/Ride.cpp @@ -49,7 +49,6 @@ #include #include #include -#include #include #include #include @@ -623,9 +622,9 @@ struct VehicleTypeLabel // Used for sorting the entrance type dropdown. struct EntranceTypeLabel { - ObjectEntryIndex ObjIndex; - StringId Name; - uint8_t StationStyle; + ObjectEntryIndex EntranceTypeId; + StringId LabelId; + const char* label_string; }; class RideWindow final : public Window @@ -634,12 +633,13 @@ class RideWindow final : public Window std::vector _rideDropdownData; int32_t _rideDropdownDataLanguage = LANGUAGE_UNDEFINED; int32_t _vehicleDropdownDataLanguage = LANGUAGE_UNDEFINED; + int32_t _entranceDropdownDataLanguage = LANGUAGE_UNDEFINED; const RideObjectEntry* _vehicleDropdownRideType = nullptr; bool _vehicleDropdownExpanded = false; std::vector _vehicleDropdownData; int16_t _vehicleIndex = 0; uint16_t _rideColour = 0; - std::vector _entranceStyleDropdownData; + std::vector _entranceDropdownData; bool _autoScrollGraph = true; public: @@ -2001,7 +2001,11 @@ private: void PopulateEntranceStyleDropdown() { - _entranceStyleDropdownData.clear(); + auto& ls = OpenRCT2::GetContext()->GetLocalisationService(); + if (_entranceDropdownDataLanguage == ls.GetCurrentLanguage()) + return; + + _entranceDropdownData.clear(); auto& objManager = GetContext()->GetObjectManager(); @@ -2010,14 +2014,16 @@ private: auto stationObj = static_cast(objManager.GetLoadedObject(ObjectType::Station, i)); if (stationObj != nullptr) { - _entranceStyleDropdownData.push_back( - { i, stationObj->NameStringId, GetStationStyleFromIdentifier(stationObj->GetIdentifier()) }); + auto name = stationObj->NameStringId; + _entranceDropdownData.push_back({ i, name, ls.GetString(name) }); } } - std::stable_sort( - _entranceStyleDropdownData.begin(), _entranceStyleDropdownData.end(), - [](const EntranceTypeLabel& a, const EntranceTypeLabel& b) { return a.StationStyle < b.StationStyle; }); + std::sort(_entranceDropdownData.begin(), _entranceDropdownData.end(), [](auto& a, auto& b) { + return String::Compare(a.label_string, b.label_string, true) < 0; + }); + + _entranceDropdownDataLanguage = ls.GetCurrentLanguage(); } void ShowEntranceStyleDropdown() @@ -2027,17 +2033,17 @@ private: PopulateEntranceStyleDropdown(); - for (size_t i = 0; i < _entranceStyleDropdownData.size(); i++) + for (size_t i = 0; i < _entranceDropdownData.size(); i++) { - gDropdownItems[i].Args = _entranceStyleDropdownData[i].Name; - gDropdownItems[i].Format = _entranceStyleDropdownData[i].ObjIndex == ride->entrance_style + gDropdownItems[i].Args = _entranceDropdownData[i].LabelId; + gDropdownItems[i].Format = _entranceDropdownData[i].EntranceTypeId == ride->entrance_style ? STR_DROPDOWN_MENU_LABEL_SELECTED : STR_DROPDOWN_MENU_LABEL; } WindowDropdownShowTextCustomWidth( { windowPos.x + dropdownWidget->left, windowPos.y + dropdownWidget->top }, dropdownWidget->height() + 1, colours[1], - 0, Dropdown::Flag::StayOpen, _entranceStyleDropdownData.size(), + 0, Dropdown::Flag::StayOpen, _entranceDropdownData.size(), widgets[WIDX_ENTRANCE_STYLE_DROPDOWN].right - dropdownWidget->left); } @@ -4302,11 +4308,11 @@ private: break; case WIDX_ENTRANCE_STYLE_DROPDOWN: { - if (static_cast(dropdownIndex) >= _entranceStyleDropdownData.size()) + if (static_cast(dropdownIndex) >= _entranceDropdownData.size()) { break; } - auto objIndex = _entranceStyleDropdownData[dropdownIndex].ObjIndex; + auto objIndex = _entranceDropdownData[dropdownIndex].EntranceTypeId; auto rideSetAppearanceAction = RideSetAppearanceAction( rideId, RideSetAppearanceType::EntranceStyle, objIndex, 0); rideSetAppearanceAction.SetCallback([objIndex](const GameAction*, const GameActions::Result* res) { From 794ee9be78d67b45b4b1ff67f05aba6c34662a30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Severin=20Paul=20H=C3=B6fer?= <84280965+zzril@users.noreply.github.com> Date: Sun, 21 Jan 2024 14:52:23 +0100 Subject: [PATCH 3/7] Update changelog.txt --- distribution/changelog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 6e96bdfee2..9b74afa327 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -3,6 +3,7 @@ - Feature: [#21062] [Plugin] Add API for managing a guest's items. - Improved: [#18632] Land ownership and construction rights are now shown on top of the water. - Improved: [#20951] Activate OpenRCT2 window after using native file dialog on macOS. +- Improved: [#21227] Entrance style dropdown is now sorted alphabetically everywhere. - Change: [#21225] Raise maximum allowed misc entities to 1600. - Fix: [#20196] New scenarios start with an incorrect temperature. - Fix: [#20255] Images from the last hovered-over coaster in the object selection are not freed. From 2136706129e50380146e65b2ea01c3fc28fe146d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Severin=20Paul=20H=C3=B6fer?= <84280965+zzril@users.noreply.github.com> Date: Tue, 23 Jan 2024 21:46:31 +0100 Subject: [PATCH 4/7] Use TitleCase for members of EntranceTypeLabel --- src/openrct2-ui/windows/Ride.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/openrct2-ui/windows/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp index 236a7cb689..26408fe2b4 100644 --- a/src/openrct2-ui/windows/Ride.cpp +++ b/src/openrct2-ui/windows/Ride.cpp @@ -624,7 +624,7 @@ struct EntranceTypeLabel { ObjectEntryIndex EntranceTypeId; StringId LabelId; - const char* label_string; + const char* LabelString; }; class RideWindow final : public Window @@ -2020,7 +2020,7 @@ private: } std::sort(_entranceDropdownData.begin(), _entranceDropdownData.end(), [](auto& a, auto& b) { - return String::Compare(a.label_string, b.label_string, true) < 0; + return String::Compare(a.LabelString, b.LabelString, true) < 0; }); _entranceDropdownDataLanguage = ls.GetCurrentLanguage(); From fb41a5764c9eb1c7043c0d91f5644114dc52618c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Severin=20Paul=20H=C3=B6fer?= <84280965+zzril@users.noreply.github.com> Date: Tue, 23 Jan 2024 21:49:43 +0100 Subject: [PATCH 5/7] Refactor existing structs to use TitleCase --- src/openrct2-ui/windows/Ride.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/openrct2-ui/windows/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp index 26408fe2b4..29ff08a580 100644 --- a/src/openrct2-ui/windows/Ride.cpp +++ b/src/openrct2-ui/windows/Ride.cpp @@ -608,7 +608,7 @@ struct RideTypeLabel { ride_type_t RideTypeId; StringId LabelId; - const char* label_string; + const char* LabelString; }; // Used for sorting the vehicle type dropdown. @@ -616,7 +616,7 @@ struct VehicleTypeLabel { ObjectEntryIndex SubTypeId; StringId LabelId; - const char* label_string; + const char* LabelString; }; // Used for sorting the entrance type dropdown. @@ -1810,7 +1810,7 @@ private: } std::sort(_rideDropdownData.begin(), _rideDropdownData.end(), [](auto& a, auto& b) { - return String::Compare(a.label_string, b.label_string, true) < 0; + return String::Compare(a.LabelString, b.LabelString, true) < 0; }); _rideDropdownDataLanguage = ls.GetCurrentLanguage(); @@ -1953,7 +1953,7 @@ private: } std::sort(_vehicleDropdownData.begin(), _vehicleDropdownData.end(), [](auto& a, auto& b) { - return String::Compare(a.label_string, b.label_string, true) < 0; + return String::Compare(a.LabelString, b.LabelString, true) < 0; }); _vehicleDropdownExpanded = selectionShouldBeExpanded; From 576caaa09442f19258c0c21887f2e3d2ce73895d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Severin=20Paul=20H=C3=B6fer?= <84280965+zzril@users.noreply.github.com> Date: Tue, 23 Jan 2024 22:43:45 +0100 Subject: [PATCH 6/7] Use u8string_view for LabelString --- src/openrct2-ui/windows/Ride.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/openrct2-ui/windows/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp index 29ff08a580..65e07a4481 100644 --- a/src/openrct2-ui/windows/Ride.cpp +++ b/src/openrct2-ui/windows/Ride.cpp @@ -64,6 +64,7 @@ #include #include #include +#include #include using namespace OpenRCT2; @@ -624,7 +625,7 @@ struct EntranceTypeLabel { ObjectEntryIndex EntranceTypeId; StringId LabelId; - const char* LabelString; + u8string_view LabelString; }; class RideWindow final : public Window @@ -2015,12 +2016,12 @@ private: if (stationObj != nullptr) { auto name = stationObj->NameStringId; - _entranceDropdownData.push_back({ i, name, ls.GetString(name) }); + _entranceDropdownData.push_back({ i, name, u8string_view{ ls.GetString(name) } }); } } std::sort(_entranceDropdownData.begin(), _entranceDropdownData.end(), [](auto& a, auto& b) { - return String::Compare(a.LabelString, b.LabelString, true) < 0; + return a.LabelString.compare(b.LabelString) < 0; }); _entranceDropdownDataLanguage = ls.GetCurrentLanguage(); From d0aae46a755b9d857fef6727291fc6eb8c84c774 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Severin=20Paul=20H=C3=B6fer?= <84280965+zzril@users.noreply.github.com> Date: Tue, 23 Jan 2024 22:54:06 +0100 Subject: [PATCH 7/7] Refactor existing structs to use u8string_view --- src/openrct2-ui/windows/Ride.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/openrct2-ui/windows/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp index 65e07a4481..04d247da90 100644 --- a/src/openrct2-ui/windows/Ride.cpp +++ b/src/openrct2-ui/windows/Ride.cpp @@ -609,7 +609,7 @@ struct RideTypeLabel { ride_type_t RideTypeId; StringId LabelId; - const char* LabelString; + u8string_view LabelString; }; // Used for sorting the vehicle type dropdown. @@ -617,7 +617,7 @@ struct VehicleTypeLabel { ObjectEntryIndex SubTypeId; StringId LabelId; - const char* LabelString; + u8string_view LabelString; }; // Used for sorting the entrance type dropdown. @@ -1807,11 +1807,11 @@ private: for (uint8_t i = 0; i < RIDE_TYPE_COUNT; i++) { auto name = GetRideTypeNameForDropdown(i); - _rideDropdownData.push_back({ i, name, ls.GetString(name) }); + _rideDropdownData.push_back({ i, name, u8string_view{ ls.GetString(name) } }); } std::sort(_rideDropdownData.begin(), _rideDropdownData.end(), [](auto& a, auto& b) { - return String::Compare(a.LabelString, b.LabelString, true) < 0; + return a.LabelString.compare(b.LabelString) < 0; }); _rideDropdownDataLanguage = ls.GetCurrentLanguage(); @@ -1948,13 +1948,13 @@ private: if (!RideEntryIsInvented(rideEntryIndex) && !gCheatsIgnoreResearchStatus) continue; - _vehicleDropdownData.push_back( - { rideEntryIndex, currentRideEntry->naming.Name, ls.GetString(currentRideEntry->naming.Name) }); + auto name = currentRideEntry->naming.Name; + _vehicleDropdownData.push_back({ rideEntryIndex, name, u8string_view{ ls.GetString(name) } }); } } std::sort(_vehicleDropdownData.begin(), _vehicleDropdownData.end(), [](auto& a, auto& b) { - return String::Compare(a.LabelString, b.LabelString, true) < 0; + return a.LabelString.compare(b.LabelString) < 0; }); _vehicleDropdownExpanded = selectionShouldBeExpanded;