1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-16 12:32:29 +01:00

Merge pull request #24248 from Gymnasiast/fix/window-bugs

Fix window bugs
This commit is contained in:
Michael Steenbeek
2025-04-19 18:18:36 +02:00
committed by GitHub
10 changed files with 25 additions and 30 deletions

View File

@@ -9,6 +9,7 @@
- Change: [#24069] [Plugin] Plugins are now available in the scenario editor and track designer. - Change: [#24069] [Plugin] Plugins are now available in the scenario editor and track designer.
- Change: [#24135] Compress Emscripten js/wasm files. - Change: [#24135] Compress Emscripten js/wasm files.
- Change: [#24235] Small changes to RCT1 theme. - Change: [#24235] Small changes to RCT1 theme.
- Fix: [#21207] Track List window gets positioned incorrectly.
- Fix: [#21919] Non-recolourable cars still show colour picker. - Fix: [#21919] Non-recolourable cars still show colour picker.
- Fix: [#22182] [Plugin] Crash when using map.getAllEntities("car"). - Fix: [#22182] [Plugin] Crash when using map.getAllEntities("car").
- Fix: [#22634] Asset packs with sound effect overrides are not loaded correctly at startup. - Fix: [#22634] Asset packs with sound effect overrides are not loaded correctly at startup.

View File

@@ -838,7 +838,7 @@ public:
WindowBase* Create( WindowBase* Create(
std::unique_ptr<WindowBase>&& wp, WindowClass cls, ScreenCoordsXY pos, int32_t width, int32_t height, std::unique_ptr<WindowBase>&& wp, WindowClass cls, ScreenCoordsXY pos, int32_t width, int32_t height,
uint32_t flags) override WindowFlags flags) override
{ {
height += wp->getTitleBarDiffTarget(); height += wp->getTitleBarDiffTarget();
@@ -1070,7 +1070,7 @@ public:
/** /**
* Closes all windows, save for those having any of the passed flags. * Closes all windows, save for those having any of the passed flags.
*/ */
void CloseAllExceptFlags(uint16_t flags) override void CloseAllExceptFlags(WindowFlags flags) override
{ {
CloseByCondition([flags](WindowBase* w) -> bool { return !(w->flags & flags); }); CloseByCondition([flags](WindowBase* w) -> bool { return !(w->flags & flags); });
} }
@@ -1347,7 +1347,7 @@ public:
return &w; return &w;
} }
WindowBase* BringToFrontByClassWithFlags(WindowClass cls, uint16_t flags) override WindowBase* BringToFrontByClassWithFlags(WindowClass cls, WindowFlags flags) override
{ {
WindowBase* w = FindByClass(cls); WindowBase* w = FindByClass(cls);
if (w != nullptr) if (w != nullptr)

View File

@@ -275,7 +275,7 @@ namespace OpenRCT2::Scripting
{ {
viewport->viewPos.x = left; viewport->viewPos.x = left;
viewport->viewPos.y = top; viewport->viewPos.y = top;
viewport->flags &= ~WF_SCROLLING_TO_LOCATION; w->flags &= ~WF_SCROLLING_TO_LOCATION;
w->savedViewPos.x = viewport->viewPos.x; w->savedViewPos.x = viewport->viewPos.x;
w->savedViewPos.y = viewport->viewPos.y; w->savedViewPos.y = viewport->viewPos.y;
viewport->Invalidate(); viewport->Invalidate();

View File

@@ -423,11 +423,8 @@ namespace OpenRCT2::Ui::Windows
gTrackDesignSceneryToggle = false; gTrackDesignSceneryToggle = false;
_currentTrackPieceDirection = 2; _currentTrackPieceDirection = 2;
int32_t screenWidth = ContextGetWidth(); auto* window = windowMgr->FocusOrCreate<InstallTrackWindow>(
int32_t screenHeight = ContextGetHeight(); WindowClass::InstallTrack, WW, WH, WF_AUTO_POSITION | WF_CENTRE_SCREEN);
auto screenPos = ScreenCoordsXY{ screenWidth / 2 - 201, std::max(kTopToolbarHeight + 1, screenHeight / 2 - 200) };
auto* window = windowMgr->FocusOrCreate<InstallTrackWindow>(WindowClass::InstallTrack, screenPos, WW, WH, 0);
window->SetupTrack(path, std::move(trackDesign)); window->SetupTrack(path, std::move(trackDesign));
return window; return window;

View File

@@ -189,15 +189,11 @@ namespace OpenRCT2::Ui::Windows
auto* windowMgr = Ui::GetWindowManager(); auto* windowMgr = Ui::GetWindowManager();
windowMgr->CloseByClass(WindowClass::TrackDeletePrompt); windowMgr->CloseByClass(WindowClass::TrackDeletePrompt);
int32_t screenWidth = ContextGetWidth();
int32_t screenHeight = ContextGetHeight();
auto trackDeletePromptWindow = std::make_unique<TrackDeletePromptWindow>(tdFileRef); auto trackDeletePromptWindow = std::make_unique<TrackDeletePromptWindow>(tdFileRef);
windowMgr->Create( windowMgr->Create(
std::move(trackDeletePromptWindow), WindowClass::TrackDeletePrompt, std::move(trackDeletePromptWindow), WindowClass::TrackDeletePrompt, {}, WW_DELETE_PROMPT, WH_DELETE_PROMPT,
ScreenCoordsXY( WF_STICK_TO_FRONT | WF_TRANSPARENT | WF_AUTO_POSITION | WF_CENTRE_SCREEN);
std::max(kTopToolbarHeight + 1, (screenWidth - WW_DELETE_PROMPT) / 2), (screenHeight - WH_DELETE_PROMPT) / 2),
WW_DELETE_PROMPT, WH_DELETE_PROMPT, WF_STICK_TO_FRONT | WF_TRANSPARENT);
} }
void TrackDeletePromptWindow::OnOpen() void TrackDeletePromptWindow::OnOpen()

View File

@@ -756,19 +756,18 @@ namespace OpenRCT2::Ui::Windows
auto* windowMgr = Ui::GetWindowManager(); auto* windowMgr = Ui::GetWindowManager();
windowMgr->CloseConstructionWindows(); windowMgr->CloseConstructionWindows();
WindowFlags flags = 0;
ScreenCoordsXY screenPos{}; ScreenCoordsXY screenPos{};
if (gLegacyScene == LegacyScene::trackDesignsManager) if (gLegacyScene == LegacyScene::trackDesignsManager)
{ {
int32_t screenWidth = ContextGetWidth(); flags = WF_AUTO_POSITION | WF_CENTRE_SCREEN;
int32_t screenHeight = ContextGetHeight();
screenPos = { screenWidth / 2 - 300, std::max(kTopToolbarHeight + 1, screenHeight / 2 - 200) };
} }
else else
{ {
screenPos = { 0, kTopToolbarHeight + 2 }; screenPos = { 0, kTopToolbarHeight + 2 };
} }
return windowMgr->Create<TrackListWindow>(WindowClass::TrackDesignList, WW, WH, 0, item); return windowMgr->Create<TrackListWindow>(WindowClass::TrackDesignList, screenPos, WW, WH, flags, item);
} }
void WindowTrackDesignListReloadTracks() void WindowTrackDesignListReloadTracks()

View File

@@ -96,6 +96,7 @@ namespace OpenRCT2
WF_AUTO_POSITION = (1 << 16), WF_AUTO_POSITION = (1 << 16),
WF_CENTRE_SCREEN = (1 << 17), WF_CENTRE_SCREEN = (1 << 17),
}; };
using WindowFlags = uint32_t;
enum enum
{ {

View File

@@ -88,7 +88,7 @@ namespace OpenRCT2
rct_windownumber number{}; rct_windownumber number{};
RideId rideId; RideId rideId;
}; };
uint16_t flags{}; WindowFlags flags{};
OpenRCT2::ScrollArea scrolls[3]; OpenRCT2::ScrollArea scrolls[3];
uint16_t no_list_items{}; // 0 for no items uint16_t no_list_items{}; // 0 for no items
int16_t selected_list_item{}; // -1 for none selected int16_t selected_list_item{}; // -1 for none selected

View File

@@ -73,7 +73,7 @@ namespace OpenRCT2::Ui
WindowBase* Create( WindowBase* Create(
std::unique_ptr<WindowBase>&& w, WindowClass cls, ScreenCoordsXY pos, int32_t width, int32_t height, std::unique_ptr<WindowBase>&& w, WindowClass cls, ScreenCoordsXY pos, int32_t width, int32_t height,
uint32_t flags) override WindowFlags flags) override
{ {
return nullptr; return nullptr;
} }
@@ -86,7 +86,7 @@ namespace OpenRCT2::Ui
void CloseTop() override {}; void CloseTop() override {};
void CloseAll() override {}; void CloseAll() override {};
void CloseAllExceptClass(WindowClass cls) override {}; void CloseAllExceptClass(WindowClass cls) override {};
void CloseAllExceptFlags(uint16_t flags) override {}; void CloseAllExceptFlags(WindowFlags flags) override {};
void CloseAllExceptNumberAndClass(rct_windownumber number, WindowClass cls) override {}; void CloseAllExceptNumberAndClass(rct_windownumber number, WindowClass cls) override {};
void CloseConstructionWindows() override {}; void CloseConstructionWindows() override {};
@@ -127,7 +127,7 @@ namespace OpenRCT2::Ui
{ {
return nullptr; return nullptr;
} }
WindowBase* BringToFrontByClassWithFlags(WindowClass cls, uint16_t flags) override WindowBase* BringToFrontByClassWithFlags(WindowClass cls, WindowFlags flags) override
{ {
return nullptr; return nullptr;
} }

View File

@@ -44,26 +44,27 @@ namespace OpenRCT2::Ui
virtual WindowBase* GetOwner(const Viewport* viewport) = 0; virtual WindowBase* GetOwner(const Viewport* viewport) = 0;
virtual WindowBase* Create( virtual WindowBase* Create(
std::unique_ptr<WindowBase>&& w, WindowClass cls, ScreenCoordsXY pos, int32_t width, int32_t height, uint32_t flags) std::unique_ptr<WindowBase>&& w, WindowClass cls, ScreenCoordsXY pos, int32_t width, int32_t height,
WindowFlags flags)
= 0; = 0;
template<typename T, typename... TArgs, typename std::enable_if<std::is_base_of<WindowBase, T>::value>::type* = nullptr> template<typename T, typename... TArgs, typename std::enable_if<std::is_base_of<WindowBase, T>::value>::type* = nullptr>
T* Create( T* Create(
WindowClass cls, const ScreenCoordsXY& pos = {}, int32_t width = 0, int32_t height = 0, uint32_t flags = 0, WindowClass cls, const ScreenCoordsXY& pos = {}, int32_t width = 0, int32_t height = 0, WindowFlags flags = 0,
TArgs&&... args) TArgs&&... args)
{ {
return static_cast<T*>(Create(std::make_unique<T>(std::forward<TArgs>(args)...), cls, pos, width, height, flags)); return static_cast<T*>(Create(std::make_unique<T>(std::forward<TArgs>(args)...), cls, pos, width, height, flags));
} }
template<typename T, typename... TArgs, typename std::enable_if<std::is_base_of<WindowBase, T>::value>::type* = nullptr> template<typename T, typename... TArgs, typename std::enable_if<std::is_base_of<WindowBase, T>::value>::type* = nullptr>
T* Create(WindowClass cls, int32_t width, int32_t height, uint32_t flags, TArgs&&... args) T* Create(WindowClass cls, int32_t width, int32_t height, WindowFlags flags, TArgs&&... args)
{ {
return static_cast<T*>( return static_cast<T*>(
Create(std::make_unique<T>(std::forward<TArgs>(args)...), cls, {}, width, height, flags | WF_AUTO_POSITION)); Create(std::make_unique<T>(std::forward<TArgs>(args)...), cls, {}, width, height, flags | WF_AUTO_POSITION));
} }
template<typename T, typename std::enable_if<std::is_base_of<WindowBase, T>::value>::type* = nullptr> template<typename T, typename std::enable_if<std::is_base_of<WindowBase, T>::value>::type* = nullptr>
T* FocusOrCreate(WindowClass cls, const ScreenCoordsXY& pos, int32_t width, int32_t height, uint32_t flags = 0) T* FocusOrCreate(WindowClass cls, const ScreenCoordsXY& pos, int32_t width, int32_t height, WindowFlags flags = 0)
{ {
auto* w = BringToFrontByClass(cls); auto* w = BringToFrontByClass(cls);
if (w == nullptr) if (w == nullptr)
@@ -74,7 +75,7 @@ namespace OpenRCT2::Ui
} }
template<typename T, typename std::enable_if<std::is_base_of<WindowBase, T>::value>::type* = nullptr> template<typename T, typename std::enable_if<std::is_base_of<WindowBase, T>::value>::type* = nullptr>
T* FocusOrCreate(WindowClass cls, int32_t width, int32_t height, uint32_t flags = 0) T* FocusOrCreate(WindowClass cls, int32_t width, int32_t height, WindowFlags flags = 0)
{ {
auto* w = BringToFrontByClass(cls); auto* w = BringToFrontByClass(cls);
if (w == nullptr) if (w == nullptr)
@@ -92,7 +93,7 @@ namespace OpenRCT2::Ui
virtual void CloseTop() = 0; virtual void CloseTop() = 0;
virtual void CloseAll() = 0; virtual void CloseAll() = 0;
virtual void CloseAllExceptClass(WindowClass cls) = 0; virtual void CloseAllExceptClass(WindowClass cls) = 0;
virtual void CloseAllExceptFlags(uint16_t flags) = 0; virtual void CloseAllExceptFlags(WindowFlags flags) = 0;
virtual void CloseAllExceptNumberAndClass(rct_windownumber number, WindowClass cls) = 0; virtual void CloseAllExceptNumberAndClass(rct_windownumber number, WindowClass cls) = 0;
virtual void CloseConstructionWindows() = 0; virtual void CloseConstructionWindows() = 0;
@@ -112,7 +113,7 @@ namespace OpenRCT2::Ui
virtual WindowBase* BringToFront(WindowBase& w) = 0; virtual WindowBase* BringToFront(WindowBase& w) = 0;
virtual WindowBase* BringToFrontByClass(WindowClass cls) = 0; virtual WindowBase* BringToFrontByClass(WindowClass cls) = 0;
virtual WindowBase* BringToFrontByClassWithFlags(WindowClass cls, uint16_t flags) = 0; virtual WindowBase* BringToFrontByClassWithFlags(WindowClass cls, WindowFlags flags) = 0;
virtual WindowBase* BringToFrontByNumber(WindowClass cls, rct_windownumber number) = 0; virtual WindowBase* BringToFrontByNumber(WindowClass cls, rct_windownumber number) = 0;
}; };