From 7d96dc9958b14ef3c75107c0085cb8f4450900aa Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sat, 24 Oct 2020 16:16:45 -0300 Subject: [PATCH] Move category names and invention strings to ResearchItem class --- .../windows/EditorInventionsList.cpp | 11 +---- src/openrct2-ui/windows/Research.cpp | 12 +---- src/openrct2/management/Research.cpp | 46 +++++++++++++++++++ src/openrct2/management/Research.h | 2 + 4 files changed, 50 insertions(+), 21 deletions(-) diff --git a/src/openrct2-ui/windows/EditorInventionsList.cpp b/src/openrct2-ui/windows/EditorInventionsList.cpp index 7d79b5a42e..d7dd768af9 100644 --- a/src/openrct2-ui/windows/EditorInventionsList.cpp +++ b/src/openrct2-ui/windows/EditorInventionsList.cpp @@ -113,15 +113,6 @@ static rct_window_event_list window_editor_inventions_list_drag_events([](auto& static ResearchItem _editorInventionsListDraggedItem; -static constexpr const rct_string_id EditorInventionsResearchCategories[] = { - STR_RESEARCH_NEW_TRANSPORT_RIDES, - STR_RESEARCH_NEW_GENTLE_RIDES, - STR_RESEARCH_NEW_ROLLER_COASTERS, - STR_RESEARCH_NEW_THRILL_RIDES, - STR_RESEARCH_NEW_WATER_RIDES, - STR_RESEARCH_NEW_SHOPS_AND_STALLS, - STR_RESEARCH_NEW_SCENERY_AND_THEMING, -}; // clang-format on static void window_editor_inventions_list_drag_open(ResearchItem* researchItem); @@ -576,7 +567,7 @@ static void window_editor_inventions_list_paint(rct_window* w, rct_drawpixelinfo // Item category screenPos.x = w->windowPos.x + w->widgets[WIDX_RESEARCH_ORDER_SCROLL].right + 4; - stringId = EditorInventionsResearchCategories[EnumValue(researchItem->category)]; + stringId = researchItem->GetCategoryInventionString(); gfx_draw_string_left(dpi, STR_INVENTION_RESEARCH_GROUP, &stringId, COLOUR_BLACK, screenPos); } diff --git a/src/openrct2-ui/windows/Research.cpp b/src/openrct2-ui/windows/Research.cpp index 7281101f37..252fed2f00 100644 --- a/src/openrct2-ui/windows/Research.cpp +++ b/src/openrct2-ui/windows/Research.cpp @@ -164,16 +164,6 @@ static uint32_t window_research_page_enabled_widgets[] = { const int32_t window_research_tab_animation_loops[] = { 16, 16 }; -static constexpr const rct_string_id ResearchCategoryNames[] = { - STR_RESEARCH_CATEGORY_TRANSPORT, - STR_RESEARCH_CATEGORY_GENTLE, - STR_RESEARCH_CATEGORY_ROLLERCOASTER, - STR_RESEARCH_CATEGORY_THRILL, - STR_RESEARCH_CATEGORY_WATER, - STR_RESEARCH_CATEGORY_SHOP, - STR_RESEARCH_CATEGORY_SCENERY_GROUP, -}; - static constexpr const rct_string_id ResearchStageNames[] = { STR_RESEARCH_STAGE_INITIAL_RESEARCH, STR_RESEARCH_STAGE_DESIGNING, @@ -329,7 +319,7 @@ void window_research_development_page_paint(rct_window* w, rct_drawpixelinfo* dp rct_string_id label = STR_RESEARCH_TYPE_LABEL; if (gResearchProgressStage != RESEARCH_STAGE_INITIAL_RESEARCH) { - strings[0] = ResearchCategoryNames[EnumValue(gResearchNextItem->category)]; + strings[0] = gResearchNextItem->GetCategoryName(); if (gResearchProgressStage != RESEARCH_STAGE_DESIGNING) { strings[0] = gResearchNextItem->GetName(); diff --git a/src/openrct2/management/Research.cpp b/src/openrct2/management/Research.cpp index be068f506d..9712d4ade6 100644 --- a/src/openrct2/management/Research.cpp +++ b/src/openrct2/management/Research.cpp @@ -890,6 +890,52 @@ bool ResearchItem::Exists() const return false; } +rct_string_id ResearchItem::GetCategoryInventionString() const +{ + switch (category) + { + case ResearchCategory::Transport: + return STR_RESEARCH_NEW_TRANSPORT_RIDES; + case ResearchCategory::Gentle: + return STR_RESEARCH_NEW_GENTLE_RIDES; + case ResearchCategory::Rollercoaster: + return STR_RESEARCH_NEW_ROLLER_COASTERS; + case ResearchCategory::Thrill: + return STR_RESEARCH_NEW_THRILL_RIDES; + case ResearchCategory::Water: + return STR_RESEARCH_NEW_WATER_RIDES; + case ResearchCategory::Shop: + return STR_RESEARCH_NEW_SHOPS_AND_STALLS; + case ResearchCategory::SceneryGroup: + return STR_RESEARCH_NEW_SCENERY_AND_THEMING; + } + log_error("Unsupported category invention string"); + return STR_NONE; +} + +rct_string_id ResearchItem::GetCategoryName() const +{ + switch (category) + { + case ResearchCategory::Transport: + return STR_RESEARCH_CATEGORY_TRANSPORT; + case ResearchCategory::Gentle: + return STR_RESEARCH_CATEGORY_GENTLE; + case ResearchCategory::Rollercoaster: + return STR_RESEARCH_CATEGORY_ROLLERCOASTER; + case ResearchCategory::Thrill: + return STR_RESEARCH_CATEGORY_THRILL; + case ResearchCategory::Water: + return STR_RESEARCH_CATEGORY_WATER; + case ResearchCategory::Shop: + return STR_RESEARCH_CATEGORY_SHOP; + case ResearchCategory::SceneryGroup: + return STR_RESEARCH_CATEGORY_SCENERY_GROUP; + } + log_error("Unsupported category name"); + return STR_NONE; +} + static std::bitset _seenRideType = {}; static void research_update_first_of_type(ResearchItem* researchItem) diff --git a/src/openrct2/management/Research.h b/src/openrct2/management/Research.h index 123abfc25a..b570f98e9d 100644 --- a/src/openrct2/management/Research.h +++ b/src/openrct2/management/Research.h @@ -66,6 +66,8 @@ struct ResearchItem bool Exists() const; bool IsAlwaysResearched() const; rct_string_id GetName() const; + rct_string_id GetCategoryInventionString() const; + rct_string_id GetCategoryName() const; ResearchItem() = default; constexpr ResearchItem(uint32_t _rawValue, ResearchCategory _category, uint8_t _flags)