1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-22 15:23:01 +01:00

Move all construction related logic into OnOpen (#20632)

This commit is contained in:
Duncan
2023-09-07 07:20:28 +01:00
committed by GitHub
parent 37caebdde9
commit 77dd3cf8e2
6 changed files with 56 additions and 40 deletions

View File

@@ -390,28 +390,32 @@ namespace OpenRCT2::Ui::Windows
public:
CustomWindow(std::shared_ptr<Plugin> owner, const CustomWindowDesc& desc)
: _info(owner, desc)
{
}
void OnOpen() override
{
number = GetNewWindowNumber();
// Set window tab
page = desc.TabIndex.value_or(0);
page = _info.Desc.TabIndex.value_or(0);
// Set window colours
colours[0] = COLOUR_GREY;
colours[1] = COLOUR_GREY;
colours[2] = COLOUR_GREY;
auto numColours = std::min(std::size(colours), std::size(desc.Colours));
auto numColours = std::min(std::size(colours), std::size(_info.Desc.Colours));
for (size_t i = 0; i < numColours; i++)
{
colours[i] = desc.Colours[i];
colours[i] = _info.Desc.Colours[i];
}
if (desc.IsResizable())
if (_info.Desc.IsResizable())
{
min_width = desc.MinWidth.value_or(0);
min_height = desc.MinHeight.value_or(0);
max_width = desc.MaxWidth.value_or(std::numeric_limits<uint16_t>::max());
max_height = desc.MaxHeight.value_or(std::numeric_limits<uint16_t>::max());
min_width = _info.Desc.MinWidth.value_or(0);
min_height = _info.Desc.MinHeight.value_or(0);
max_width = _info.Desc.MaxWidth.value_or(std::numeric_limits<uint16_t>::max());
max_height = _info.Desc.MaxHeight.value_or(std::numeric_limits<uint16_t>::max());
}
RefreshWidgets();
}

View File

@@ -492,33 +492,15 @@ static u8string OpenSystemFileBrowser(bool isSave)
class LoadSaveWindow final : public Window
{
public:
LoadSaveWindow(int32_t type)
LoadSaveWindow(int32_t loadSaveType)
: type(loadSaveType)
{
widgets = window_loadsave_widgets;
const auto uiContext = OpenRCT2::GetContext()->GetUiContext();
if (!uiContext->HasFilePicker())
{
disabled_widgets |= (1uLL << WIDX_BROWSE);
window_loadsave_widgets[WIDX_BROWSE].type = WindowWidgetType::Empty;
}
// TODO: Split LOADSAVETYPE_* into two proper enum classes (one for load/save, the other for the type)
const bool isSave = (type & 0x01) == LOADSAVETYPE_SAVE;
const auto path = GetDir(type);
const char* pattern = GetFilterPatternByType(type, isSave);
PopulateList(isSave, path, pattern);
no_list_items = static_cast<uint16_t>(_listItems.size());
selected_list_item = -1;
InitScrollWidgets();
ComputeMaxDateWidth();
}
private:
int32_t maxDateWidth{ 0 };
int32_t maxTimeWidth{ 0 };
int32_t type;
public:
void PopulateList(int32_t includeNewItem, const u8string& directory, std::string_view extensionPattern)
@@ -692,6 +674,26 @@ public:
public:
void OnOpen() override
{
widgets = window_loadsave_widgets;
const auto uiContext = OpenRCT2::GetContext()->GetUiContext();
if (!uiContext->HasFilePicker())
{
disabled_widgets |= (1uLL << WIDX_BROWSE);
window_loadsave_widgets[WIDX_BROWSE].type = WindowWidgetType::Empty;
}
// TODO: Split LOADSAVETYPE_* into two proper enum classes (one for load/save, the other for the type)
const bool isSave = (type & 0x01) == LOADSAVETYPE_SAVE;
const auto path = GetDir(type);
const char* pattern = GetFilterPatternByType(type, isSave);
PopulateList(isSave, path, pattern);
no_list_items = static_cast<uint16_t>(_listItems.size());
selected_list_item = -1;
InitScrollWidgets();
ComputeMaxDateWidth();
min_width = WW;
min_height = WH / 2;
max_width = WW * 2;
@@ -1120,6 +1122,10 @@ public:
OverwritePromptWindow(const std::string_view name, const std::string_view path)
: _name(name)
, _path(path)
{
}
void OnOpen() override
{
widgets = window_overwrite_prompt_widgets;
colours[0] = TRANSLUCENT(COLOUR_BORDEAUX_RED);

View File

@@ -36,7 +36,7 @@ static Formatter _mapTooltipArgs;
class MapTooltip final : public Window
{
public:
MapTooltip()
void OnOpen() override
{
widgets = window_map_tooltip_widgets;
}

View File

@@ -161,7 +161,7 @@ private:
ScreenCoordsXY InformationGetSize();
public:
MultiplayerWindow();
void OnOpen() override;
void SetPage(int32_t page_number);
@@ -193,7 +193,7 @@ WindowBase* WindowMultiplayerOpen()
return window;
}
MultiplayerWindow::MultiplayerWindow()
void MultiplayerWindow::OnOpen()
{
SetPage(WINDOW_MULTIPLAYER_PAGE_INFORMATION);
}

View File

@@ -116,11 +116,12 @@ static constexpr StringId ResearchStageNames[] = {
class ResearchWindow final : public Window
{
public:
ResearchWindow()
void OnOpen() override
{
widgets = window_research_page_widgets[WINDOW_RESEARCH_PAGE_DEVELOPMENT];
width = WW_DEVELOPMENT;
height = WH_DEVELOPMENT;
ResearchUpdateUncompletedTypes();
}
void SetPage(int32_t newPageIndex)
@@ -152,11 +153,6 @@ public:
}
private:
void OnOpen() override
{
ResearchUpdateUncompletedTypes();
}
void OnUpdate() override
{
// Tab animation

View File

@@ -635,6 +635,10 @@ public:
RideWindow(const Ride& ride)
{
rideId = ride.id;
}
virtual void OnOpen() override
{
widgets = PageWidgets[WINDOW_RIDE_PAGE_MAIN];
hold_down_widgets = PageHoldDownWidgets[WINDOW_RIDE_PAGE_MAIN];
@@ -648,9 +652,15 @@ public:
max_width = 500;
max_height = 450;
UpdateOverallView(ride);
auto ride = GetRide(rideId);
if (ride == nullptr)
{
Close();
return;
}
UpdateOverallView(*ride);
PopulateVehicleTypeDropdown(ride, true);
PopulateVehicleTypeDropdown(*ride, true);
}
virtual void OnClose() override