Rework EditorBottomToolbar into EditorStepController (#26961)

* Rename EditorBottomToolbar to EditorStepController

* Split off EditorStatusLine to its own window

* Simplify step/jump functions by making them static

* Split EditorStepController into two instances

* Resize new editor panels when game window is resized

* Move kEditorStepNames defs into EditorController to share between windows
This commit is contained in:
Aaron van Geffen authored and GitHub committed 2026-08-29 20:23:20 +00:00
1 parent 550fe4be85
commit 21e37e12f9
15 files changed
+546 -484

No files matched your search

-9
View File
@@ -491,15 +491,6 @@ namespace OpenRCT2
// Window: EditorBottomToolbar
STR_BACK_TO_PREVIOUS_STEP = 3209,
STR_CANT_ADVANCE_TO_NEXT_EDITOR_STAGE = 3328,
STR_EDITOR_STEP_INVENTIONS_LIST_SET_UP = 3203,
STR_EDITOR_STEP_LANDSCAPE_EDITOR = 3202,
STR_EDITOR_STEP_OBJECTIVE_SELECTION = 3205,
STR_EDITOR_STEP_OBJECT_SELECTION = 3201,
STR_EDITOR_STEP_OPTIONS_SELECTION = 3204,
STR_EDITOR_STEP_ROLLERCOASTER_DESIGNER = 3207,
STR_EDITOR_STEP_SAVE_SCENARIO = 3206,
STR_EDITOR_STEP_SCENARIO_DETAILS = 6761,
STR_EDITOR_STEP_TRACK_DESIGNS_MANAGER = 3208,
STR_FORWARD_TO_NEXT_STEP = 3210,
STR_UNABLE_TO_SAVE_SCENARIO_FILE = 3320,
+4 -2
View File
@@ -162,6 +162,10 @@ public:
return AssetPacksOpen();
case WindowClass::editorParkEntrance:
return EditorParkEntranceOpen();
case WindowClass::editorStepController:
return editorStepControllerOpen();
case WindowClass::editorStatusLine:
return editorStatusLineOpen();
default:
Console::Error::WriteLine("Unhandled window class (%d)", wc);
return nullptr;
@@ -192,8 +196,6 @@ public:
return MazeConstructionOpen();
case WindowView::networkPassword:
return NetworkStatusOpenPassword();
case WindowView::editorBottomToolbar:
return EditorBottomToolbarOpen();
case WindowView::changelog:
return ChangelogOpen(WindowView::changelog);
case WindowView::newVersionInfo:
+3 -1
View File
@@ -184,7 +184,9 @@ static void ShortcutRemoveTopBottomToolbarToggle()
else
{
ContextOpenWindow(WindowClass::topToolbar);
ContextOpenWindowView(WindowView::editorBottomToolbar);
ContextOpenWindow(WindowClass::editorStepController); // previous step
ContextOpenWindow(WindowClass::editorStatusLine);
ContextOpenWindow(WindowClass::editorStepController); // next step
}
}
GfxInvalidateScreen();
+2 -1
View File
@@ -178,11 +178,12 @@
<ClCompile Include="windows\DebugPaint.cpp" />
<ClCompile Include="windows\DemolishRidePrompt.cpp" />
<ClCompile Include="windows\Dropdown.cpp" />
<ClCompile Include="windows\EditorBottomToolbar.cpp" />
<ClCompile Include="windows\EditorInventionsList.cpp" />
<ClCompile Include="windows\EditorObjectSelection.cpp" />
<ClCompile Include="windows\EditorParkEntrance.cpp" />
<ClCompile Include="windows\EditorScenarioOptions.cpp" />
<ClCompile Include="windows\EditorStatusLine.cpp" />
<ClCompile Include="windows\EditorStepController.cpp" />
<ClCompile Include="windows\Error.cpp" />
<ClCompile Include="windows\Finances.cpp" />
<ClCompile Include="windows\Footpath.cpp" />
@@ -1,466 +0,0 @@
/*****************************************************************************
* Copyright (c) 2014-2026 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include "../interface/Theme.h"
#include <openrct2-ui/interface/Widget.h>
#include <openrct2-ui/interface/Window.h>
#include <openrct2-ui/windows/Windows.h>
#include <openrct2/Context.h>
#include <openrct2/Game.h>
#include <openrct2/GameState.h>
#include <openrct2/Input.h>
#include <openrct2/OpenRCT2.h>
#include <openrct2/SpriteIds.h>
#include <openrct2/actions/ResultWithMessage.h>
#include <openrct2/drawing/Drawing.h>
#include <openrct2/drawing/Rectangle.h>
#include <openrct2/drawing/Text.h>
#include <openrct2/management/Research.h>
#include <openrct2/scenario/Scenario.h>
#include <openrct2/scenes/editor/EditorController.h>
#include <openrct2/scripting/ScriptEngine.h>
#include <openrct2/ui/WindowManager.h>
#include <openrct2/windows/Intent.h>
#include <string>
using namespace OpenRCT2::Drawing;
namespace OpenRCT2::Ui::Windows
{
static constexpr int32_t kToolbarHeight = 32;
enum WindowEditorBottomToolbarWidgetIdx : WidgetIndex
{
WIDX_PREVIOUS_IMAGE, // 1
WIDX_PREVIOUS_STEP_BUTTON, // 2
WIDX_NEXT_IMAGE, // 4
WIDX_NEXT_STEP_BUTTON, // 8
};
// clang-format off
static constexpr Widget kEditorBottomToolbarWidgets[] = {
makeWidget({ 0, 0}, {200, 34}, WidgetType::imgBtn, WindowColour::primary),
makeWidget({ 2, 2}, {196, 30}, WidgetType::flatBtn, WindowColour::primary),
makeWidget({440, 0}, {200, 34}, WidgetType::imgBtn, WindowColour::primary),
makeWidget({442, 2}, {196, 30}, WidgetType::flatBtn, WindowColour::primary),
};
// clang-format on
class EditorBottomToolbarWindow final : public Window
{
private:
using FuncPtr = void (EditorBottomToolbarWindow::*)() const;
static constexpr StringId kEditorStepNames[] = {
STR_EDITOR_STEP_OBJECT_SELECTION, // Editor::Step::objectSelection
STR_EDITOR_STEP_LANDSCAPE_EDITOR, // Editor::Step::landscapeEditor
STR_EDITOR_STEP_INVENTIONS_LIST_SET_UP, // Editor::Step::inventionsListSetUp
STR_EDITOR_STEP_OPTIONS_SELECTION, // Editor::Step::optionsSelection
STR_EDITOR_STEP_OBJECTIVE_SELECTION, // Editor::Step::objectiveSelection
STR_EDITOR_STEP_SCENARIO_DETAILS, // Editor::Step::scenarioDetails
STR_EDITOR_STEP_SAVE_SCENARIO, // Editor::Step::saveScenario
STR_EDITOR_STEP_ROLLERCOASTER_DESIGNER, // Editor::Step::rollerCoasterDesigner
STR_EDITOR_STEP_TRACK_DESIGNS_MANAGER, // Editor::Step::designsManager
};
public:
void onOpen() override
{
setWidgets(kEditorBottomToolbarWidgets);
initScrollWidgets();
SetAllSceneryItemsInvented();
}
bool GameHasEntities() const
{
auto& gameState = getGameState();
return gameState.entities.GetNumFreeEntities() != kMaxEntities
|| gameState.park.flags.has(ParkFlag::spritesInitialised);
}
void onPrepareDraw() override
{
ColourSchemeUpdateByClass(
this,
gLegacyScene == LegacyScene::scenarioEditor ? WindowClass::editorScenarioBottomToolbar
: WindowClass::editorTrackBottomToolbar);
uint16_t screenWidth = ContextGetWidth();
widgets[WIDX_NEXT_IMAGE].left = screenWidth - 200;
widgets[WIDX_NEXT_IMAGE].right = screenWidth - 1;
widgets[WIDX_NEXT_STEP_BUTTON].left = screenWidth - 198;
widgets[WIDX_NEXT_STEP_BUTTON].right = screenWidth - 3;
widgets[WIDX_PREVIOUS_STEP_BUTTON].setHidden(false);
widgets[WIDX_NEXT_STEP_BUTTON].setHidden(false);
widgets[WIDX_PREVIOUS_IMAGE].setHidden(false);
widgets[WIDX_NEXT_IMAGE].setHidden(false);
auto& gameState = getGameState();
if (gLegacyScene == LegacyScene::trackDesignsManager || gameState.editorStep == Editor::Step::saveScenario)
{
HidePreviousStepButton();
HideNextStepButton();
}
else
{
if (gameState.editorStep == Editor::Step::objectSelection
|| (GameHasEntities() && gameState.editorStep == Editor::Step::optionsSelection))
{
HidePreviousStepButton();
}
else if (gameState.editorStep == Editor::Step::rollerCoasterDesigner)
{
HideNextStepButton();
}
}
}
void onDraw(RenderTarget& rt) override
{
auto drawPreviousButton = widgets[WIDX_PREVIOUS_STEP_BUTTON].isVisible();
auto drawNextButton = widgets[WIDX_NEXT_STEP_BUTTON].isVisible();
if (drawPreviousButton)
DrawLeftButtonBack(rt);
if (drawNextButton)
DrawRightButtonBack(rt);
drawWidgets(rt);
if (drawPreviousButton)
DrawLeftButton(rt);
if (drawNextButton)
DrawRightButton(rt);
DrawStepText(rt);
}
void onMouseUp(WidgetIndex widgetIndex) override
{
auto& gameState = getGameState();
if (widgetIndex == WIDX_PREVIOUS_STEP_BUTTON)
{
((this)->*(kPreviousButtonMouseUp[EnumValue(gameState.editorStep)]))();
}
else if (widgetIndex == WIDX_NEXT_STEP_BUTTON)
{
((this)->*(kNextButtonMouseUp[EnumValue(gameState.editorStep)]))();
}
}
private:
void JumpBackToObjectSelection() const
{
auto* windowMgr = GetWindowManager();
windowMgr->CloseAll();
getGameState().editorStep = Editor::Step::objectSelection;
GfxInvalidateScreen();
}
void JumpBackToLandscapeEditor() const
{
auto* windowMgr = GetWindowManager();
windowMgr->CloseAll();
SetAllSceneryItemsInvented();
WindowScenerySetDefaultPlacementConfiguration();
getGameState().editorStep = Editor::Step::landscapeEditor;
ContextOpenWindow(WindowClass::map);
GfxInvalidateScreen();
}
void JumpBackToInventionListSetUp() const
{
auto* windowMgr = GetWindowManager();
windowMgr->CloseAll();
ContextOpenWindow(WindowClass::editorInventionList);
getGameState().editorStep = Editor::Step::inventionsListSetUp;
GfxInvalidateScreen();
}
void JumpBackToObjectiveSelection() const
{
auto* windowMgr = GetWindowManager();
windowMgr->CloseAll();
ContextOpenWindow(WindowClass::editorScenarioOptions);
getGameState().editorStep = Editor::Step::objectiveSelection;
GfxInvalidateScreen();
}
void JumpBackToOptionsSelection() const
{
auto* windowMgr = GetWindowManager();
windowMgr->CloseAll();
ContextOpenWindow(WindowClass::editorScenarioOptions);
getGameState().editorStep = Editor::Step::optionsSelection;
GfxInvalidateScreen();
}
void JumpForwardFromObjectSelection() const
{
if (!EditorObjectSelectionWindowCheck())
return;
auto* windowMgr = GetWindowManager();
windowMgr->CloseByClass(WindowClass::editorObjectSelection);
Editor::FinishObjectSelection();
if (gLegacyScene == LegacyScene::trackDesigner)
{
ContextOpenWindow(WindowClass::constructRide);
}
else
{
ContextOpenWindow(WindowClass::map);
ContextOpenWindow(WindowClass::mapgen);
}
}
void JumpForwardToInventionListSetUp() const
{
auto [checksPassed, errorString] = Editor::CheckPark();
if (checksPassed)
{
auto* windowMgr = GetWindowManager();
windowMgr->CloseAll();
ContextOpenWindow(WindowClass::editorInventionList);
getGameState().editorStep = Editor::Step::inventionsListSetUp;
}
else
{
ContextShowError(STR_CANT_ADVANCE_TO_NEXT_EDITOR_STAGE, errorString, {});
}
GfxInvalidateScreen();
}
void JumpForwardToObjectiveSelection() const
{
auto* windowMgr = GetWindowManager();
windowMgr->CloseAll();
ContextOpenWindow(WindowClass::editorScenarioOptions);
getGameState().editorStep = Editor::Step::objectiveSelection;
GfxInvalidateScreen();
}
void JumpForwardToOptionsSelection() const
{
auto* windowMgr = GetWindowManager();
windowMgr->CloseAll();
ContextOpenWindow(WindowClass::editorScenarioOptions);
getGameState().editorStep = Editor::Step::optionsSelection;
GfxInvalidateScreen();
}
void JumpForwardToScenarioDetails() const
{
auto* windowMgr = GetWindowManager();
windowMgr->CloseAll();
ContextOpenWindow(WindowClass::editorScenarioOptions);
getGameState().editorStep = Editor::Step::scenarioDetails;
GfxInvalidateScreen();
}
static void SaveScenarioCallback(ModalResult result, const utf8* path)
{
if (result == ModalResult::ok)
{
GameUnloadScripts();
}
else
{
getGameState().editorStep = Editor::Step::scenarioDetails;
}
}
void JumpForwardToSaveScenario() const
{
auto& gameState = getGameState();
gameState.editorStep = Editor::Step::saveScenario;
GfxInvalidateScreen();
const auto savePrepareResult = ScenarioPrepareForSave(gameState);
if (!savePrepareResult.Successful)
{
ContextShowError(STR_UNABLE_TO_SAVE_SCENARIO_FILE, savePrepareResult.Message, {});
return;
}
#ifdef ENABLE_SCRIPTING
// Clear the plugin storage before saving
auto& scriptEngine = GetContext()->GetScriptEngine();
scriptEngine.ClearParkStorage();
#endif
auto* windowMgr = GetWindowManager();
windowMgr->CloseAll();
auto intent = Intent(WindowClass::loadsave);
intent.PutEnumExtra<LoadSaveAction>(INTENT_EXTRA_LOADSAVE_ACTION, LoadSaveAction::save);
intent.PutEnumExtra<LoadSaveType>(INTENT_EXTRA_LOADSAVE_TYPE, LoadSaveType::scenario);
intent.PutExtra(INTENT_EXTRA_PATH, gameState.scenarioOptions.name);
intent.PutExtra(INTENT_EXTRA_CALLBACK, reinterpret_cast<CloseCallback>(SaveScenarioCallback));
ContextOpenIntent(&intent);
}
void HidePreviousStepButton()
{
widgets[WIDX_PREVIOUS_STEP_BUTTON].setHidden(true);
widgets[WIDX_PREVIOUS_IMAGE].setHidden(true);
}
void HideNextStepButton()
{
widgets[WIDX_NEXT_STEP_BUTTON].setHidden(true);
widgets[WIDX_NEXT_IMAGE].setHidden(true);
}
void DrawLeftButtonBack(RenderTarget& rt)
{
const auto& previousWidget = widgets[WIDX_PREVIOUS_IMAGE];
auto leftTop = windowPos + ScreenCoordsXY{ previousWidget.left, previousWidget.top };
auto rightBottom = windowPos + ScreenCoordsXY{ previousWidget.right, previousWidget.bottom };
Rectangle::filter(rt, { leftTop, rightBottom }, FilterPaletteID::palette51);
}
void DrawLeftButton(RenderTarget& rt)
{
const auto topLeft = windowPos
+ ScreenCoordsXY{ widgets[WIDX_PREVIOUS_IMAGE].left + 1, widgets[WIDX_PREVIOUS_IMAGE].top + 1 };
const auto bottomRight = windowPos
+ ScreenCoordsXY{ widgets[WIDX_PREVIOUS_IMAGE].right - 1, widgets[WIDX_PREVIOUS_IMAGE].bottom - 1 };
Rectangle::fillInset(
rt, { topLeft, bottomRight }, colours[1], Rectangle::BorderStyle::inset, Rectangle::FillBrightness::light,
Rectangle::FillMode::none);
GfxDrawSprite(
rt, ImageId(SPR_PREVIOUS),
windowPos + ScreenCoordsXY{ widgets[WIDX_PREVIOUS_IMAGE].left + 6, widgets[WIDX_PREVIOUS_IMAGE].top + 6 });
Drawing::Colour textColour = colours[1].colour;
if (gHoverWidget.windowClassification == WindowClass::bottomToolbar
&& gHoverWidget.widgetIndex == WIDX_PREVIOUS_STEP_BUTTON)
{
textColour = Drawing::Colour::white;
}
int16_t textX = (widgets[WIDX_PREVIOUS_IMAGE].left + 30 + widgets[WIDX_PREVIOUS_IMAGE].right) / 2 + windowPos.x;
int16_t textY = widgets[WIDX_PREVIOUS_IMAGE].top + 6 + windowPos.y;
StringId stringId = kEditorStepNames[EnumValue(getGameState().editorStep) - 1];
if (gLegacyScene == LegacyScene::trackDesigner)
stringId = STR_EDITOR_STEP_OBJECT_SELECTION;
drawText(rt, { textX, textY }, STR_BACK_TO_PREVIOUS_STEP, { textColour, TextAlignment::centre });
drawText(rt, { textX, textY + 10 }, stringId, { textColour, TextAlignment::centre });
}
void DrawRightButtonBack(RenderTarget& rt)
{
auto nextWidget = widgets[WIDX_NEXT_IMAGE];
auto leftTop = windowPos + ScreenCoordsXY{ nextWidget.left, nextWidget.top };
auto rightBottom = windowPos + ScreenCoordsXY{ nextWidget.right, nextWidget.bottom };
Rectangle::filter(rt, { leftTop, rightBottom }, FilterPaletteID::palette51);
}
void DrawRightButton(RenderTarget& rt)
{
const auto topLeft = windowPos
+ ScreenCoordsXY{ widgets[WIDX_NEXT_IMAGE].left + 1, widgets[WIDX_NEXT_IMAGE].top + 1 };
const auto bottomRight = windowPos
+ ScreenCoordsXY{ widgets[WIDX_NEXT_IMAGE].right - 1, widgets[WIDX_NEXT_IMAGE].bottom - 1 };
Rectangle::fillInset(
rt, { topLeft, bottomRight }, colours[1], Rectangle::BorderStyle::inset, Rectangle::FillBrightness::light,
Rectangle::FillMode::none);
GfxDrawSprite(
rt, ImageId(SPR_NEXT),
windowPos + ScreenCoordsXY{ widgets[WIDX_NEXT_IMAGE].right - 29, widgets[WIDX_NEXT_IMAGE].top + 6 });
Drawing::Colour textColour = colours[1].colour;
if (gHoverWidget.windowClassification == WindowClass::bottomToolbar
&& gHoverWidget.widgetIndex == WIDX_NEXT_STEP_BUTTON)
{
textColour = Drawing::Colour::white;
}
int16_t textX = (widgets[WIDX_NEXT_IMAGE].left + widgets[WIDX_NEXT_IMAGE].right - 30) / 2 + windowPos.x;
int16_t textY = widgets[WIDX_NEXT_IMAGE].top + 6 + windowPos.y;
StringId stringId = kEditorStepNames[EnumValue(getGameState().editorStep) + 1];
if (gLegacyScene == LegacyScene::trackDesigner)
stringId = STR_EDITOR_STEP_ROLLERCOASTER_DESIGNER;
drawText(rt, { textX, textY }, STR_FORWARD_TO_NEXT_STEP, { textColour, TextAlignment::centre });
drawText(rt, { textX, textY + 10 }, stringId, { textColour, TextAlignment::centre });
}
void DrawStepText(RenderTarget& rt)
{
int16_t stateX = (widgets[WIDX_PREVIOUS_IMAGE].right + widgets[WIDX_NEXT_IMAGE].left) / 2 + windowPos.x;
int16_t stateY = height - 0x0C + windowPos.y;
auto colour = colours[2].withFlag(ColourFlag::translucent, false).withFlag(ColourFlag::withOutline, true);
drawText(
rt, { stateX, stateY }, kEditorStepNames[EnumValue(getGameState().editorStep)],
{ colour, TextAlignment::centre });
}
static constexpr FuncPtr kPreviousButtonMouseUp[] = {
/* ObjectSelection */ nullptr,
/* LandscapeEditor */ &EditorBottomToolbarWindow::JumpBackToObjectSelection,
/* InventionsListSetUp */ &EditorBottomToolbarWindow::JumpBackToLandscapeEditor,
/* OptionsSelection */ &EditorBottomToolbarWindow::JumpBackToInventionListSetUp,
/* ObjectiveSelection */ &EditorBottomToolbarWindow::JumpBackToOptionsSelection,
/* ScenarioDetails */ &EditorBottomToolbarWindow::JumpBackToObjectiveSelection,
/* SaveScenario */ nullptr,
/* RollercoasterDesigner */ &EditorBottomToolbarWindow::JumpBackToObjectSelection,
/* DesignsManager */ nullptr,
};
static constexpr FuncPtr kNextButtonMouseUp[] = {
/* ObjectSelection */ &EditorBottomToolbarWindow::JumpForwardFromObjectSelection,
/* LandscapeEditor */ &EditorBottomToolbarWindow::JumpForwardToInventionListSetUp,
/* InventionsListSetUp */ &EditorBottomToolbarWindow::JumpForwardToOptionsSelection,
/* OptionsSelection */ &EditorBottomToolbarWindow::JumpForwardToObjectiveSelection,
/* ObjectiveSelection */ &EditorBottomToolbarWindow::JumpForwardToScenarioDetails,
/* ScenarioDetails */ &EditorBottomToolbarWindow::JumpForwardToSaveScenario,
/* SaveScenario */ nullptr,
/* RollercoasterDesigner */ nullptr,
/* DesignsManager */ nullptr,
};
};
/**
* Creates the main editor top toolbar window.
* rct2: 0x0066F052 (part of 0x0066EF38)
*/
WindowBase* EditorBottomToolbarOpen()
{
auto* windowMgr = GetWindowManager();
auto* window = windowMgr->Create<EditorBottomToolbarWindow>(
WindowClass::bottomToolbar, ScreenCoordsXY(0, ContextGetHeight() - kToolbarHeight),
{ ContextGetWidth(), kToolbarHeight },
{ WindowFlag::stickToFront, WindowFlag::transparent, WindowFlag::noBackground, WindowFlag::noTitleBar });
return window;
}
} // namespace OpenRCT2::Ui::Windows
@@ -0,0 +1,65 @@
/*****************************************************************************
* Copyright (c) 2014-2026 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include <openrct2-ui/interface/Theme.h>
#include <openrct2-ui/interface/Widget.h>
#include <openrct2-ui/interface/Window.h>
#include <openrct2-ui/windows/Windows.h>
#include <openrct2/Context.h>
#include <openrct2/GameState.h>
#include <openrct2/OpenRCT2.h>
#include <openrct2/drawing/Text.h>
#include <openrct2/scenes/editor/EditorController.h>
#include <openrct2/ui/WindowManager.h>
using namespace OpenRCT2::Drawing;
namespace OpenRCT2::Ui::Windows
{
static constexpr ScreenSize kWindowSize = { 300, 16 };
static constexpr Widget kEditorBottomToolbarWidgets[] = {
makeWidget({ 0, 0 }, { 0, 0 }, WidgetType::placeholder, WindowColour::primary),
};
class EditorStatusLine final : public Window
{
public:
void onOpen() override
{
setWidgets(kEditorBottomToolbarWidgets);
}
void onPrepareDraw() override
{
ColourSchemeUpdateByClass(
this,
gLegacyScene == LegacyScene::scenarioEditor ? WindowClass::editorScenarioBottomToolbar
: WindowClass::editorTrackBottomToolbar);
}
void onDraw(RenderTarget& rt) override
{
auto colour = colours[2].withFlag(ColourFlag::translucent, false).withFlag(ColourFlag::withOutline, true);
auto stringId = Editor::getStepStringId(getGameState().editorStep);
drawText(rt, windowPos + ScreenCoordsXY{ width / 2, height - 12 }, stringId, { colour, TextAlignment::centre });
}
};
WindowBase* editorStatusLineOpen()
{
auto* windowMgr = GetWindowManager();
auto* window = windowMgr->Create<EditorStatusLine>(
WindowClass::editorStatusLine,
{ (ContextGetWidth() - kWindowSize.width) / 2, ContextGetHeight() - kWindowSize.height }, kWindowSize,
{ WindowFlag::stickToFront, WindowFlag::transparent, WindowFlag::noBackground, WindowFlag::noTitleBar });
return window;
}
} // namespace OpenRCT2::Ui::Windows
@@ -0,0 +1,395 @@
/*****************************************************************************
* Copyright (c) 2014-2026 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include <openrct2-ui/interface/Theme.h>
#include <openrct2-ui/interface/Widget.h>
#include <openrct2-ui/interface/Window.h>
#include <openrct2-ui/windows/Windows.h>
#include <openrct2/Context.h>
#include <openrct2/Game.h>
#include <openrct2/GameState.h>
#include <openrct2/Input.h>
#include <openrct2/OpenRCT2.h>
#include <openrct2/SpriteIds.h>
#include <openrct2/actions/ResultWithMessage.h>
#include <openrct2/drawing/Drawing.h>
#include <openrct2/drawing/Rectangle.h>
#include <openrct2/drawing/Text.h>
#include <openrct2/management/Research.h>
#include <openrct2/scenario/Scenario.h>
#include <openrct2/scenes/editor/EditorController.h>
#include <openrct2/scripting/ScriptEngine.h>
#include <openrct2/ui/WindowManager.h>
#include <openrct2/windows/Intent.h>
#include <string>
using namespace OpenRCT2::Drawing;
namespace OpenRCT2::Ui::Windows
{
static constexpr ScreenSize kWindowSize = { 200, 32 };
enum EditorStepControllerWidgetIdx : WidgetIndex
{
WIDX_IMAGE,
WIDX_STEP_BUTTON,
};
// clang-format off
static constexpr Widget kEditorStepControllerWidgets[] = {
makeWidget({ 0, 0}, {200, 34}, WidgetType::imgBtn, WindowColour::primary),
makeWidget({ 2, 2}, {196, 30}, WidgetType::flatBtn, WindowColour::primary),
};
// clang-format on
enum class StepDirection : uint8_t
{
previous,
next,
};
class EditorStepController final : public Window
{
private:
using FuncPtr = void (*)();
public:
StepDirection direction;
void onOpen() override
{
setWidgets(kEditorStepControllerWidgets);
initScrollWidgets();
SetAllSceneryItemsInvented();
}
bool GameHasEntities() const
{
auto& gameState = getGameState();
return gameState.entities.GetNumFreeEntities() != kMaxEntities
|| gameState.park.flags.has(ParkFlag::spritesInitialised);
}
void onPrepareDraw() override
{
ColourSchemeUpdateByClass(
this,
gLegacyScene == LegacyScene::scenarioEditor ? WindowClass::editorScenarioBottomToolbar
: WindowClass::editorTrackBottomToolbar);
auto& gameState = getGameState();
bool stepVisible = gLegacyScene != LegacyScene::trackDesignsManager
&& gameState.editorStep != Editor::Step::saveScenario;
if (stepVisible)
{
if (gameState.editorStep == Editor::Step::objectSelection
|| (GameHasEntities() && gameState.editorStep == Editor::Step::optionsSelection))
{
stepVisible = direction == StepDirection::next;
}
else if (gameState.editorStep == Editor::Step::rollerCoasterDesigner)
{
stepVisible = direction == StepDirection::previous;
}
}
widgets[WIDX_STEP_BUTTON].setVisible(stepVisible);
widgets[WIDX_IMAGE].setVisible(stepVisible);
}
void onDraw(RenderTarget& rt) override
{
if (!widgets[WIDX_STEP_BUTTON].isVisible())
return;
drawButtonBackground(rt);
drawWidgets(rt);
drawButtonCaption(rt);
}
void onMouseUp(WidgetIndex widgetIndex) override
{
auto& gameState = getGameState();
if (direction == StepDirection::previous)
{
kPreviousButtonMouseUp[EnumValue(gameState.editorStep)]();
}
else if (direction == StepDirection::next)
{
kNextButtonMouseUp[EnumValue(gameState.editorStep)]();
}
}
private:
static void jumpBackToObjectSelection()
{
auto* windowMgr = GetWindowManager();
windowMgr->CloseAll();
getGameState().editorStep = Editor::Step::objectSelection;
GfxInvalidateScreen();
}
static void jumpBackToLandscapeEditor()
{
auto* windowMgr = GetWindowManager();
windowMgr->CloseAll();
SetAllSceneryItemsInvented();
WindowScenerySetDefaultPlacementConfiguration();
getGameState().editorStep = Editor::Step::landscapeEditor;
ContextOpenWindow(WindowClass::map);
GfxInvalidateScreen();
}
static void jumpBackToInventionListSetUp()
{
auto* windowMgr = GetWindowManager();
windowMgr->CloseAll();
ContextOpenWindow(WindowClass::editorInventionList);
getGameState().editorStep = Editor::Step::inventionsListSetUp;
GfxInvalidateScreen();
}
static void jumpBackToObjectiveSelection()
{
auto* windowMgr = GetWindowManager();
windowMgr->CloseAll();
ContextOpenWindow(WindowClass::editorScenarioOptions);
getGameState().editorStep = Editor::Step::objectiveSelection;
GfxInvalidateScreen();
}
static void jumpBackToOptionsSelection()
{
auto* windowMgr = GetWindowManager();
windowMgr->CloseAll();
ContextOpenWindow(WindowClass::editorScenarioOptions);
getGameState().editorStep = Editor::Step::optionsSelection;
GfxInvalidateScreen();
}
static void jumpForwardFromObjectSelection()
{
if (!EditorObjectSelectionWindowCheck())
return;
auto* windowMgr = GetWindowManager();
windowMgr->CloseByClass(WindowClass::editorObjectSelection);
Editor::FinishObjectSelection();
if (gLegacyScene == LegacyScene::trackDesigner)
{
ContextOpenWindow(WindowClass::constructRide);
}
else
{
ContextOpenWindow(WindowClass::map);
ContextOpenWindow(WindowClass::mapgen);
}
}
static void jumpForwardToInventionListSetUp()
{
auto [checksPassed, errorString] = Editor::CheckPark();
if (checksPassed)
{
auto* windowMgr = GetWindowManager();
windowMgr->CloseAll();
ContextOpenWindow(WindowClass::editorInventionList);
getGameState().editorStep = Editor::Step::inventionsListSetUp;
}
else
{
ContextShowError(STR_CANT_ADVANCE_TO_NEXT_EDITOR_STAGE, errorString, {});
}
GfxInvalidateScreen();
}
static void jumpForwardToObjectiveSelection()
{
auto* windowMgr = GetWindowManager();
windowMgr->CloseAll();
ContextOpenWindow(WindowClass::editorScenarioOptions);
getGameState().editorStep = Editor::Step::objectiveSelection;
GfxInvalidateScreen();
}
static void jumpForwardToOptionsSelection()
{
auto* windowMgr = GetWindowManager();
windowMgr->CloseAll();
ContextOpenWindow(WindowClass::editorScenarioOptions);
getGameState().editorStep = Editor::Step::optionsSelection;
GfxInvalidateScreen();
}
static void jumpForwardToScenarioDetails()
{
auto* windowMgr = GetWindowManager();
windowMgr->CloseAll();
ContextOpenWindow(WindowClass::editorScenarioOptions);
getGameState().editorStep = Editor::Step::scenarioDetails;
GfxInvalidateScreen();
}
static void saveScenarioCallback(ModalResult result, const utf8* path)
{
if (result == ModalResult::ok)
{
GameUnloadScripts();
}
else
{
getGameState().editorStep = Editor::Step::scenarioDetails;
}
}
static void jumpForwardToSaveScenario()
{
auto& gameState = getGameState();
gameState.editorStep = Editor::Step::saveScenario;
GfxInvalidateScreen();
const auto savePrepareResult = ScenarioPrepareForSave(gameState);
if (!savePrepareResult.Successful)
{
ContextShowError(STR_UNABLE_TO_SAVE_SCENARIO_FILE, savePrepareResult.Message, {});
return;
}
#ifdef ENABLE_SCRIPTING
// Clear the plugin storage before saving
auto& scriptEngine = GetContext()->GetScriptEngine();
scriptEngine.ClearParkStorage();
#endif
auto* windowMgr = GetWindowManager();
windowMgr->CloseAll();
auto intent = Intent(WindowClass::loadsave);
intent.PutEnumExtra<LoadSaveAction>(INTENT_EXTRA_LOADSAVE_ACTION, LoadSaveAction::save);
intent.PutEnumExtra<LoadSaveType>(INTENT_EXTRA_LOADSAVE_TYPE, LoadSaveType::scenario);
intent.PutExtra(INTENT_EXTRA_PATH, gameState.scenarioOptions.name);
intent.PutExtra(INTENT_EXTRA_CALLBACK, reinterpret_cast<CloseCallback>(saveScenarioCallback));
ContextOpenIntent(&intent);
}
void drawButtonBackground(RenderTarget& rt)
{
const auto& widget = widgets[WIDX_IMAGE];
auto leftTop = windowPos + ScreenCoordsXY{ widget.left, widget.top };
auto rightBottom = windowPos + ScreenCoordsXY{ widget.right, widget.bottom };
Rectangle::filter(rt, { leftTop, rightBottom }, FilterPaletteID::palette51);
}
struct StepFrame
{
StringId label;
uint32_t image;
ScreenCoordsXY labelOffset;
ScreenCoordsXY imageOffset;
};
static constexpr std::array kStepFrames = std::to_array<StepFrame>({
{ STR_BACK_TO_PREVIOUS_STEP, SPR_PREVIOUS, { (kWindowSize.width + 30) / 2, 6 }, { 6, 6 } },
{ STR_FORWARD_TO_NEXT_STEP, SPR_NEXT, { (kWindowSize.width - 31) / 2, 6 }, { kWindowSize.width - 29, 6 } },
});
void drawButtonCaption(RenderTarget& rt)
{
const auto topLeft = windowPos + ScreenCoordsXY{ widgets[WIDX_IMAGE].left + 1, widgets[WIDX_IMAGE].top + 1 };
const auto bottomRight = windowPos
+ ScreenCoordsXY{ widgets[WIDX_IMAGE].right - 1, widgets[WIDX_IMAGE].bottom - 1 };
Rectangle::fillInset(
rt, { topLeft, bottomRight }, colours[1], Rectangle::BorderStyle::inset, Rectangle::FillBrightness::light,
Rectangle::FillMode::none);
const bool isPrevious = direction == StepDirection::previous;
const auto& layout = isPrevious ? kStepFrames[0] : kStepFrames[1];
GfxDrawSprite(rt, ImageId(layout.image), windowPos + layout.imageOffset);
Drawing::Colour textColour = colours[1].colour;
if (widgetIsHighlighted(*this, WIDX_STEP_BUTTON))
{
textColour = Drawing::Colour::white;
}
drawText(rt, windowPos + layout.labelOffset, layout.label, { textColour, TextAlignment::centre });
auto step = Editor::Step(EnumValue(getGameState().editorStep) + (isPrevious ? -1 : 1));
auto stringId = Editor::getStepStringId(step);
if (isPrevious && gLegacyScene == LegacyScene::trackDesigner)
stringId = STR_EDITOR_STEP_OBJECT_SELECTION;
else if (!isPrevious && gLegacyScene == LegacyScene::trackDesigner)
stringId = STR_EDITOR_STEP_ROLLERCOASTER_DESIGNER;
drawText(
rt, windowPos + layout.labelOffset + ScreenCoordsXY{ 0, 10 }, stringId, { textColour, TextAlignment::centre });
}
static constexpr FuncPtr kPreviousButtonMouseUp[] = {
/* ObjectSelection */ nullptr,
/* LandscapeEditor */ &EditorStepController::jumpBackToObjectSelection,
/* InventionsListSetUp */ &EditorStepController::jumpBackToLandscapeEditor,
/* OptionsSelection */ &EditorStepController::jumpBackToInventionListSetUp,
/* ObjectiveSelection */ &EditorStepController::jumpBackToOptionsSelection,
/* ScenarioDetails */ &EditorStepController::jumpBackToObjectiveSelection,
/* SaveScenario */ nullptr,
/* RollercoasterDesigner */ &EditorStepController::jumpBackToObjectSelection,
/* DesignsManager */ nullptr,
};
static constexpr FuncPtr kNextButtonMouseUp[] = {
/* ObjectSelection */ &EditorStepController::jumpForwardFromObjectSelection,
/* LandscapeEditor */ &EditorStepController::jumpForwardToInventionListSetUp,
/* InventionsListSetUp */ &EditorStepController::jumpForwardToOptionsSelection,
/* OptionsSelection */ &EditorStepController::jumpForwardToObjectiveSelection,
/* ObjectiveSelection */ &EditorStepController::jumpForwardToScenarioDetails,
/* ScenarioDetails */ &EditorStepController::jumpForwardToSaveScenario,
/* SaveScenario */ nullptr,
/* RollercoasterDesigner */ nullptr,
/* DesignsManager */ nullptr,
};
};
/**
* Creates the main editor bottom toolbar window.
* rct2: 0x0066F052 (part of 0x0066EF38)
*/
WindowBase* editorStepControllerOpen()
{
auto direction = StepDirection::previous;
auto* windowMgr = GetWindowManager();
if (windowMgr->FindByNumber(WindowClass::editorStepController, 0) != nullptr)
{
direction = StepDirection::next;
}
auto xPos = direction == StepDirection::previous ? 0 : ContextGetWidth() - kWindowSize.width;
auto* window = windowMgr->Create<EditorStepController>(
WindowClass::editorStepController, ScreenCoordsXY(xPos, ContextGetHeight() - kWindowSize.height), kWindowSize,
{ WindowFlag::stickToFront, WindowFlag::transparent, WindowFlag::noBackground, WindowFlag::noTitleBar });
window->direction = direction;
window->number = EnumValue(direction);
return window;
}
} // namespace OpenRCT2::Ui::Windows
+6 -3
View File
@@ -93,9 +93,6 @@ namespace OpenRCT2::Ui::Windows
// EditorInventionsList
WindowBase* EditorInventionsListOpen();
// EditorBottomToolbar
WindowBase* EditorBottomToolbarOpen();
// EditorObjectSelection
WindowBase* EditorObjectSelectionOpen();
bool EditorObjectSelectionWindowCheck();
@@ -107,6 +104,12 @@ namespace OpenRCT2::Ui::Windows
// EditorScenarioOptions
WindowBase* EditorScenarioOptionsOpen();
// EditorStatusLine
WindowBase* editorStatusLineOpen();
// EditorStepController
WindowBase* editorStepControllerOpen();
// Error
WindowBase* ErrorOpen(StringId title, StringId message, const class Formatter& formatter, bool autoClose = false);
WindowBase* ErrorOpen(std::string_view title, std::string_view message, bool autoClose = false);
+32
View File
@@ -12,6 +12,7 @@
#include "../Context.h"
#include "../Game.h"
#include "../Input.h"
#include "../OpenRCT2.h"
#include "../audio/Audio.h"
#include "../config/Config.h"
#include "../drawing/Drawing.String.h"
@@ -826,6 +827,32 @@ static constexpr float kWindowScrollLocations[][2] = {
}
}
static void WindowResizeEditorController(const int32_t width, const int32_t height)
{
auto* windowMgr = Ui::GetWindowManager();
auto* prevStep = windowMgr->FindByNumber(WindowClass::editorStepController, 0);
if (prevStep != nullptr)
{
prevStep->windowPos.x = 0;
prevStep->windowPos.y = height - prevStep->height;
}
auto* statusLine = windowMgr->FindByClass(WindowClass::editorStatusLine);
if (statusLine != nullptr)
{
statusLine->windowPos.x = (width - statusLine->width) / 2;
statusLine->windowPos.y = height - statusLine->height;
}
auto* nextStep = windowMgr->FindByNumber(WindowClass::editorStepController, 1);
if (nextStep != nullptr)
{
nextStep->windowPos.x = width - nextStep->width;
nextStep->windowPos.y = height - nextStep->height;
}
}
void WindowResizeGui(const int32_t width, const int32_t height)
{
WindowResizeGuiMainToolbars(width, height);
@@ -836,6 +863,11 @@ static constexpr float kWindowScrollLocations[][2] = {
return WindowResizeGuiTitleScreen(width, height);
}
if (isInEditorMode() || isInTrackDesignerOrManager())
{
WindowResizeEditorController(width, height);
}
WindowResizeGuiCentredWindows(width, height);
GfxInvalidateScreen();
+2
View File
@@ -94,6 +94,8 @@ namespace OpenRCT2
progressWindow = 137,
titleVersion = 138,
editorParkEntrance = 139,
editorStepController = 140,
editorStatusLine = 141,
// Only used for colour schemes
staff = 220,
-1
View File
@@ -35,7 +35,6 @@ namespace OpenRCT2
rideResearch,
mazeConstruction,
networkPassword,
editorBottomToolbar,
changelog,
newVersionInfo,
financeMarketing,
+11
View File
@@ -1228,6 +1228,15 @@ enum : StringId
STR_OBJECT_SELECTION_PARK_ENTRANCE = 3192,
STR_OBJECT_SELECTION_WATER = 3193,
STR_EDITOR_STEP_OBJECT_SELECTION = 3201,
STR_EDITOR_STEP_LANDSCAPE_EDITOR = 3202,
STR_EDITOR_STEP_INVENTIONS_LIST_SET_UP = 3203,
STR_EDITOR_STEP_OPTIONS_SELECTION = 3204,
STR_EDITOR_STEP_OBJECTIVE_SELECTION = 3205,
STR_EDITOR_STEP_SAVE_SCENARIO = 3206,
STR_EDITOR_STEP_ROLLERCOASTER_DESIGNER = 3207,
STR_EDITOR_STEP_TRACK_DESIGNS_MANAGER = 3208,
STR_CANT_DECREASE_MAP_SIZE_ANY_FURTHER = 3213,
STR_CANT_INCREASE_MAP_SIZE_ANY_FURTHER = 3214,
STR_TOO_CLOSE_TO_EDGE_OF_MAP = 3215,
@@ -1745,6 +1754,8 @@ enum : StringId
STR_OBJECT_SELECTION_CLIMATE = 6743,
STR_CLIMATE_WEATHER_PERCENT = 6744,
STR_EDITOR_STEP_SCENARIO_DETAILS = 6761,
// Gamepad settings
STR_GAMEPAD_GROUP = 6785,
STR_GAMEPAD_DEADZONE_LABEL = 6786,
@@ -22,6 +22,7 @@
#include "../../entity/Staff.h"
#include "../../localisation/Formatting.h"
#include "../../localisation/LocalisationService.h"
#include "../../localisation/StringIds.h"
#include "../../management/Research.h"
#include "../../object/DefaultObjects.h"
#include "../../object/FootpathEntry.h"
@@ -970,4 +971,22 @@ namespace OpenRCT2::Editor
return numUnselectedObjects;
}
static constexpr StringId kEditorStepNames[] = {
STR_EDITOR_STEP_OBJECT_SELECTION, // Editor::Step::objectSelection
STR_EDITOR_STEP_LANDSCAPE_EDITOR, // Editor::Step::landscapeEditor
STR_EDITOR_STEP_INVENTIONS_LIST_SET_UP, // Editor::Step::inventionsListSetUp
STR_EDITOR_STEP_OPTIONS_SELECTION, // Editor::Step::optionsSelection
STR_EDITOR_STEP_OBJECTIVE_SELECTION, // Editor::Step::objectiveSelection
STR_EDITOR_STEP_SCENARIO_DETAILS, // Editor::Step::scenarioDetails
STR_EDITOR_STEP_SAVE_SCENARIO, // Editor::Step::saveScenario
STR_EDITOR_STEP_ROLLERCOASTER_DESIGNER, // Editor::Step::rollerCoasterDesigner
STR_EDITOR_STEP_TRACK_DESIGNS_MANAGER, // Editor::Step::designsManager
};
StringId getStepStringId(Step step)
{
return kEditorStepNames[EnumValue(step)];
}
} // namespace OpenRCT2::Editor
@@ -39,6 +39,8 @@ namespace OpenRCT2::Editor
};
using InputFlags = FlagHolder<uint8_t, InputFlag>;
enum class Step : uint8_t;
extern u8string gSceneryGroupPartialSelectError;
extern std::vector<ObjectSelectionFlags> _objectSelectionFlags;
extern uint32_t _numSelectedObjectsForType[EnumValue(ObjectType::count)];
@@ -70,4 +72,6 @@ namespace OpenRCT2::Editor
* @return The number of removed objects.
*/
int32_t RemoveUnusedObjects();
StringId getStepStringId(Step step);
} // namespace OpenRCT2::Editor
+3 -1
View File
@@ -234,7 +234,9 @@ void EditorScene::OpenEditorWindows()
{
ContextOpenWindow(WindowClass::mainWindow);
ContextOpenWindow(WindowClass::topToolbar);
ContextOpenWindowView(WindowView::editorBottomToolbar);
ContextOpenWindow(WindowClass::editorStepController); // previous step
ContextOpenWindow(WindowClass::editorStatusLine);
ContextOpenWindow(WindowClass::editorStepController); // next step
}
/**