Use intents to control scenery window (#16562)

* Use intents to control scenery window
This commit is contained in:
Duncan 2022-02-03 21:10:21 +00:00 committed by GitHub
parent c00cc90b1f
commit cdd3c28b2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 43 additions and 20 deletions

View File

@ -297,6 +297,28 @@ public:
return w;
}
case INTENT_ACTION_NEW_SCENERY:
{
// Check if window is already open
auto* window = window_bring_to_front_by_class(WC_SCENERY);
if (window == nullptr)
{
auto* tlbrWindow = window_find_by_class(WC_TOP_TOOLBAR);
if (tlbrWindow != nullptr)
{
tlbrWindow->Invalidate();
if (!tool_set(tlbrWindow, WC_TOP_TOOLBAR__WIDX_SCENERY, Tool::Arrow))
{
input_set_flag(INPUT_FLAG_6, true);
window = WindowSceneryOpen();
}
}
}
// Switch to new scenery tab
WindowScenerySetSelectedTab(intent->GetUIntExtra(INTENT_EXTRA_SCENERY_GROUP_ENTRY_INDEX));
return window;
}
default:
Console::Error::WriteLine("Unhandled window class for intent (%d)", intent->GetWindowClass());
return nullptr;

View File

@ -1405,6 +1405,21 @@ bool WindowScenerySetSelectedItem(const ScenerySelection& scenery)
return result;
}
void WindowScenerySetSelectedTab(const ObjectEntryIndex sceneryGroupIndex)
{
const auto* tabInfo = GetSceneryTabInfoForGroup(sceneryGroupIndex);
if (tabInfo == nullptr)
{
tabInfo = &_tabEntries.back();
}
const auto tabId = std::distance(&*_tabEntries.cbegin(), tabInfo);
auto* window = window_find_by_class(WC_SCENERY);
if (window != nullptr)
{
window_event_mouse_down_call(window, WIDX_SCENERY_TAB_1 + tabId);
}
}
// Used after removing objects, in order to avoid crashes.
void WindowSceneryResetSelectedSceneryItems()
{

View File

@ -176,6 +176,7 @@ bool WaterToolIsActive();
rct_window* WindowSceneryOpen();
bool WindowScenerySetSelectedItem(const ScenerySelection& scenery);
void WindowScenerySetSelectedTab(const ObjectEntryIndex sceneryGroupIndex);
void WindowScenerySetDefaultPlacementConfiguration();
void WindowSceneryInit();
void WindowSceneryResetSelectedSceneryItems();

View File

@ -391,26 +391,9 @@ void News::OpenSubject(News::ItemType type, int32_t subject)
break;
}
// Check if window is already open
auto window = window_bring_to_front_by_class(WC_SCENERY);
if (window == nullptr)
{
window = window_find_by_class(WC_TOP_TOOLBAR);
if (window != nullptr)
{
window->Invalidate();
if (!tool_set(window, WC_TOP_TOOLBAR__WIDX_SCENERY, Tool::Arrow))
{
input_set_flag(INPUT_FLAG_6, true);
context_open_window(WC_SCENERY);
}
}
}
// Switch to new scenery tab
window = window_find_by_class(WC_SCENERY);
if (window != nullptr)
window_event_mouse_down_call(window, WC_SCENERY__WIDX_SCENERY_TAB_1 + subject);
auto intent = Intent(INTENT_ACTION_NEW_SCENERY);
intent.putExtra(INTENT_EXTRA_SCENERY_GROUP_ENTRY_INDEX, item.entryIndex);
context_open_intent(&intent);
break;
}
case News::ItemType::Peeps:

View File

@ -82,6 +82,7 @@ enum
INTENT_EXTRA_PAGE,
INTENT_EXTRA_BANNER_INDEX,
INTENT_EXTRA_FORMATTER,
INTENT_EXTRA_SCENERY_GROUP_ENTRY_INDEX,
};
enum
@ -114,4 +115,5 @@ enum
INTENT_ACTION_TRACK_DESIGN_REMOVE_PROVISIONAL,
INTENT_ACTION_TRACK_DESIGN_RESTORE_PROVISIONAL,
INTENT_ACTION_SET_MAP_TOOLTIP,
INTENT_ACTION_NEW_SCENERY,
};