From 7feb3802fb9f4b100ebf4fdf9ada078f4a5945a3 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Wed, 26 May 2021 17:44:38 +0200 Subject: [PATCH] Show what a stall sells in Object Selection --- data/language/en-GB.txt | 1 + .../windows/EditorObjectSelection.cpp | 199 ++++++++++-------- src/openrct2/localisation/StringIds.h | 2 + 3 files changed, 119 insertions(+), 83 deletions(-) diff --git a/data/language/en-GB.txt b/data/language/en-GB.txt index f47810eece..28782944a9 100644 --- a/data/language/en-GB.txt +++ b/data/language/en-GB.txt @@ -3691,6 +3691,7 @@ STR_6448 :Unsupported object format STR_6449 :{WINDOW_COLOUR_2}Tracks: STR_6450 :{BLACK}“{STRING}” STR_6451 :{BLACK}“{STRING}” - {STRING} +STR_6452 :{WINDOW_COLOUR_2}Sells: {BLACK}{STRING} ############# # Scenarios # diff --git a/src/openrct2-ui/windows/EditorObjectSelection.cpp b/src/openrct2-ui/windows/EditorObjectSelection.cpp index db6ea3dca5..3500bfd8fa 100644 --- a/src/openrct2-ui/windows/EditorObjectSelection.cpp +++ b/src/openrct2-ui/windows/EditorObjectSelection.cpp @@ -937,6 +937,120 @@ static void window_editor_object_selection_invalidate(rct_window* w) } } +static void window_editor_object_selection_paint_descriptions(rct_window* w, rct_drawpixelinfo* dpi) +{ + auto widget = &w->widgets[WIDX_PREVIEW]; + auto screenPos = w->windowPos + ScreenCoordsXY{ w->widgets[WIDX_LIST].right + 4, widget->bottom + 23 }; + auto width = w->windowPos.x + w->width - screenPos.x - 4; + + auto description = object_get_description(_loadedObject.get()); + if (!description.empty()) + { + auto ft = Formatter(); + ft.Add(STR_STRING); + ft.Add(description.c_str()); + + screenPos.y += DrawTextWrapped(dpi, screenPos, width, STR_WINDOW_COLOUR_2_STRINGID, ft) + LIST_ROW_HEIGHT; + } + if (get_selected_object_type(w) == ObjectType::Ride) + { + auto* rideObject = reinterpret_cast(_loadedObject.get()); + const auto* rideEntry = reinterpret_cast(rideObject->GetLegacyData()); + if (rideEntry->shop_item[0] != ShopItem::None) + { + std::string sells = ""; + for (size_t i = 0; i < std::size(rideEntry->shop_item); i++) + { + if (rideEntry->shop_item[i] == ShopItem::None) + continue; + + if (!sells.empty()) + sells += ", "; + + sells += language_get_string(GetShopItemDescriptor(rideEntry->shop_item[i]).Naming.Plural); + } + auto ft = Formatter(); + ft.Add(sells.c_str()); + screenPos.y += DrawTextWrapped(dpi, screenPos, width, STR_RIDE_OBJECT_SHOP_SELLS, ft) + 2; + } + } + else if (get_selected_object_type(w) == ObjectType::SceneryGroup) + { + const auto* sceneryGroupObject = reinterpret_cast(_loadedObject.get()); + auto ft = Formatter(); + ft.Add(sceneryGroupObject->GetNumIncludedObjects()); + screenPos.y += DrawTextWrapped(dpi, screenPos, width, STR_INCLUDES_X_OBJECTS, ft) + 2; + } + else if (get_selected_object_type(w) == ObjectType::Music) + { + screenPos.y += DrawTextWrapped(dpi, screenPos, width, STR_MUSIC_OBJECT_TRACK_HEADER) + 2; + const auto* musicObject = reinterpret_cast(_loadedObject.get()); + for (size_t i = 0; i < musicObject->GetTrackCount(); i++) + { + const auto* track = musicObject->GetTrack(i); + if (track->Name.empty()) + continue; + + auto stringId = track->Composer.empty() ? STR_MUSIC_OBJECT_TRACK_LIST_ITEM + : STR_MUSIC_OBJECT_TRACK_LIST_ITEM_WITH_COMPOSER; + auto ft = Formatter(); + ft.Add(track->Name.c_str()); + ft.Add(track->Composer.c_str()); + screenPos.y += DrawTextWrapped(dpi, screenPos + ScreenCoordsXY{ 10, 0 }, width, stringId, ft); + } + } +} + +static void window_editor_object_selection_paint_debug_data(rct_window* w, rct_drawpixelinfo* dpi) +{ + list_item* listItem = &_listItems[w->selected_list_item]; + auto screenPos = w->windowPos + ScreenCoordsXY{ w->width - 5, w->height - (LIST_ROW_HEIGHT * 5) }; + // Draw ride type. + if (get_selected_object_type(w) == ObjectType::Ride) + { + auto stringId = get_ride_type_string_id(listItem->repositoryItem); + DrawTextBasic(dpi, screenPos, stringId, {}, { COLOUR_WHITE, TextAlignment::RIGHT }); + } + + screenPos.y += LIST_ROW_HEIGHT; + + // Draw object source + auto stringId = object_manager_get_source_game_string(listItem->repositoryItem->GetFirstSourceGame()); + DrawTextBasic(dpi, screenPos, stringId, {}, { COLOUR_WHITE, TextAlignment::RIGHT }); + screenPos.y += LIST_ROW_HEIGHT; + + // Draw object dat name + { + const char* path = path_get_filename(listItem->repositoryItem->Path.c_str()); + auto ft = Formatter(); + ft.Add(STR_STRING); + ft.Add(path); + DrawTextBasic( + dpi, { w->windowPos.x + w->width - 5, screenPos.y }, STR_WINDOW_COLOUR_2_STRINGID, ft, + { COLOUR_BLACK, TextAlignment::RIGHT }); + screenPos.y += LIST_ROW_HEIGHT; + } + + // Draw object author (will be blank space if no author in file or a non JSON object) + { + auto ft = Formatter(); + std::string authorsString; + for (size_t i = 0; i < listItem->repositoryItem->Authors.size(); i++) + { + if (i > 0) + { + authorsString.append(", "); + } + authorsString.append(listItem->repositoryItem->Authors[i]); + } + ft.Add(STR_STRING); + ft.Add(authorsString.c_str()); + DrawTextEllipsised( + dpi, { w->windowPos.x + w->width - 5, screenPos.y }, w->width - w->widgets[WIDX_LIST].right - 4, + STR_WINDOW_COLOUR_2_STRINGID, ft, { TextAlignment::RIGHT }); + } +} + /** * * rct2: 0x006AAB56 @@ -1060,89 +1174,8 @@ static void window_editor_object_selection_paint(rct_window* w, rct_drawpixelinf DrawTextEllipsised(dpi, screenPos, width, STR_WINDOW_COLOUR_2_STRINGID, ft, { TextAlignment::CENTRE }); } - auto screenPos = w->windowPos + ScreenCoordsXY{ w->widgets[WIDX_LIST].right + 4, widget->bottom + 23 }; - width = w->windowPos.x + w->width - screenPos.x - 4; - - auto description = object_get_description(_loadedObject.get()); - if (!description.empty()) - { - auto ft = Formatter(); - ft.Add(STR_STRING); - ft.Add(description.c_str()); - - screenPos.y += DrawTextWrapped(dpi, screenPos, width, STR_WINDOW_COLOUR_2_STRINGID, ft); - } - if (get_selected_object_type(w) == ObjectType::SceneryGroup) - { - const auto* sceneryGroupObject = reinterpret_cast(_loadedObject.get()); - auto ft = Formatter(); - ft.Add(sceneryGroupObject->GetNumIncludedObjects()); - screenPos.y += DrawTextWrapped(dpi, screenPos, width, STR_INCLUDES_X_OBJECTS, ft) + 2; - } - else if (get_selected_object_type(w) == ObjectType::Music) - { - screenPos.y += DrawTextWrapped(dpi, screenPos, width, STR_MUSIC_OBJECT_TRACK_HEADER) + 2; - const auto* musicObject = reinterpret_cast(_loadedObject.get()); - for (size_t i = 0; i < musicObject->GetTrackCount(); i++) - { - const auto* track = musicObject->GetTrack(i); - if (track->Name.empty()) - continue; - - auto stringId = track->Composer.empty() ? STR_MUSIC_OBJECT_TRACK_LIST_ITEM - : STR_MUSIC_OBJECT_TRACK_LIST_ITEM_WITH_COMPOSER; - auto ft = Formatter(); - ft.Add(track->Name.c_str()); - ft.Add(track->Composer.c_str()); - screenPos.y += DrawTextWrapped(dpi, screenPos + ScreenCoordsXY{ 10, 0 }, width, stringId, ft); - } - } - - screenPos = w->windowPos + ScreenCoordsXY{ w->width - 5, w->height - (LIST_ROW_HEIGHT * 5) }; - // Draw ride type. - if (get_selected_object_type(w) == ObjectType::Ride) - { - auto stringId = get_ride_type_string_id(listItem->repositoryItem); - DrawTextBasic(dpi, screenPos, stringId, {}, { COLOUR_WHITE, TextAlignment::RIGHT }); - } - - screenPos.y += LIST_ROW_HEIGHT; - - // Draw object source - auto stringId = object_manager_get_source_game_string(listItem->repositoryItem->GetFirstSourceGame()); - DrawTextBasic(dpi, screenPos, stringId, {}, { COLOUR_WHITE, TextAlignment::RIGHT }); - screenPos.y += LIST_ROW_HEIGHT; - - // Draw object dat name - { - const char* path = path_get_filename(listItem->repositoryItem->Path.c_str()); - auto ft = Formatter(); - ft.Add(STR_STRING); - ft.Add(path); - DrawTextBasic( - dpi, { w->windowPos.x + w->width - 5, screenPos.y }, STR_WINDOW_COLOUR_2_STRINGID, ft, - { COLOUR_BLACK, TextAlignment::RIGHT }); - screenPos.y += LIST_ROW_HEIGHT; - } - - // Draw object author (will be blank space if no author in file or a non JSON object) - { - auto ft = Formatter(); - std::string authorsString; - for (size_t i = 0; i < listItem->repositoryItem->Authors.size(); i++) - { - if (i > 0) - { - authorsString.append(", "); - } - authorsString.append(listItem->repositoryItem->Authors[i]); - } - ft.Add(STR_STRING); - ft.Add(authorsString.c_str()); - DrawTextEllipsised( - dpi, { w->windowPos.x + w->width - 5, screenPos.y }, w->width - w->widgets[WIDX_LIST].right - 4, - STR_WINDOW_COLOUR_2_STRINGID, ft, { TextAlignment::RIGHT }); - } + window_editor_object_selection_paint_descriptions(w, dpi); + window_editor_object_selection_paint_debug_data(w, dpi); } /** * diff --git a/src/openrct2/localisation/StringIds.h b/src/openrct2/localisation/StringIds.h index e8bb3ea546..10553f6eee 100644 --- a/src/openrct2/localisation/StringIds.h +++ b/src/openrct2/localisation/StringIds.h @@ -3954,6 +3954,8 @@ enum STR_MUSIC_OBJECT_TRACK_LIST_ITEM = 6450, STR_MUSIC_OBJECT_TRACK_LIST_ITEM_WITH_COMPOSER = 6451, + STR_RIDE_OBJECT_SHOP_SELLS = 6452, + // Have to include resource strings (from scenarios and objects) for the time being now that language is partially working /* MAX_STR_COUNT = 32768 */ // MAX_STR_COUNT - upper limit for number of strings, not the current count strings };