/
EditorBottomToolbar.cpp
404 lines (346 loc) 路 14.3 KB
/
EditorBottomToolbar.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
/*****************************************************************************
* Copyright (c) 2014-2024 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/windows/Window.h>
#include <openrct2/Context.h>
#include <openrct2/Editor.h>
#include <openrct2/EditorObjectSelectionSession.h>
#include <openrct2/Game.h>
#include <openrct2/GameState.h>
#include <openrct2/Input.h>
#include <openrct2/OpenRCT2.h>
#include <openrct2/audio/audio.h>
#include <openrct2/localisation/Localisation.h>
#include <openrct2/management/Research.h>
#include <openrct2/scenario/Scenario.h>
#include <openrct2/sprites.h>
#include <openrct2/windows/Intent.h>
#include <openrct2/world/Park.h>
#include <openrct2/world/Scenery.h>
#include <string>
using namespace OpenRCT2;
// clang-format off
enum {
WIDX_PREVIOUS_IMAGE, // 1
WIDX_PREVIOUS_STEP_BUTTON, // 2
WIDX_NEXT_IMAGE, // 4
WIDX_NEXT_STEP_BUTTON, // 8
};
static Widget _editorBottomToolbarWidgets[] = {
MakeWidget({ 0, 0}, {200, 34}, WindowWidgetType::ImgBtn, WindowColour::Primary),
MakeWidget({ 2, 2}, {196, 30}, WindowWidgetType::FlatBtn, WindowColour::Primary),
MakeWidget({440, 0}, {200, 34}, WindowWidgetType::ImgBtn, WindowColour::Primary),
MakeWidget({442, 2}, {196, 30}, WindowWidgetType::FlatBtn, WindowColour::Primary),
WIDGETS_END,
};
// clang-format on
class EditorBottomToolbarWindow final : public Window
{
private:
using FuncPtr = void (EditorBottomToolbarWindow::*)() const;
static constexpr StringId _editorStepNames[] = {
STR_EDITOR_STEP_OBJECT_SELECTION, STR_EDITOR_STEP_LANDSCAPE_EDITOR, STR_EDITOR_STEP_INVENTIONS_LIST_SET_UP,
STR_EDITOR_STEP_OPTIONS_SELECTION, STR_EDITOR_STEP_OBJECTIVE_SELECTION, STR_EDITOR_STEP_SAVE_SCENARIO,
STR_EDITOR_STEP_ROLLERCOASTER_DESIGNER, STR_EDITOR_STEP_TRACK_DESIGNS_MANAGER,
};
public:
void OnOpen() override
{
widgets = _editorBottomToolbarWidgets;
InitScrollWidgets();
SetAllSceneryItemsInvented();
}
void OnPrepareDraw() override
{
ColourSchemeUpdateByClass(
this,
(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) ? 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].type = WindowWidgetType::FlatBtn;
widgets[WIDX_NEXT_STEP_BUTTON].type = WindowWidgetType::FlatBtn;
widgets[WIDX_PREVIOUS_IMAGE].type = WindowWidgetType::ImgBtn;
widgets[WIDX_NEXT_IMAGE].type = WindowWidgetType::ImgBtn;
if (gScreenFlags & SCREEN_FLAGS_TRACK_MANAGER)
{
HidePreviousStepButton();
HideNextStepButton();
}
else
{
if (gEditorStep == EditorStep::ObjectSelection)
{
HidePreviousStepButton();
}
else if (gEditorStep == EditorStep::RollercoasterDesigner)
{
HideNextStepButton();
}
else if (!(gScreenFlags & SCREEN_FLAGS_TRACK_DESIGNER))
{
if (GetNumFreeEntities() != MAX_ENTITIES || GetGameState().ParkFlags & PARK_FLAGS_SPRITES_INITIALISED)
{
HidePreviousStepButton();
}
}
}
}
void OnDraw(DrawPixelInfo& dpi) override
{
auto drawPreviousButton = widgets[WIDX_PREVIOUS_STEP_BUTTON].type != WindowWidgetType::Empty;
auto drawNextButton = widgets[WIDX_NEXT_STEP_BUTTON].type != WindowWidgetType::Empty;
if (drawPreviousButton)
DrawLeftButtonBack(dpi);
if (drawNextButton)
DrawRightButtonBack(dpi);
DrawWidgets(dpi);
if (drawPreviousButton)
DrawLeftButton(dpi);
if (drawNextButton)
DrawRightButton(dpi);
DrawStepText(dpi);
}
void OnMouseUp(WidgetIndex widgetIndex) override
{
if (widgetIndex == WIDX_PREVIOUS_STEP_BUTTON)
{
if ((gScreenFlags & SCREEN_FLAGS_TRACK_DESIGNER)
|| (GetNumFreeEntities() == MAX_ENTITIES && !(GetGameState().ParkFlags & PARK_FLAGS_SPRITES_INITIALISED)))
{
((this)->*(_previousButtonMouseUp[EnumValue(gEditorStep)]))();
}
}
else if (widgetIndex == WIDX_NEXT_STEP_BUTTON)
{
((this)->*(_nextButtonMouseUp[EnumValue(gEditorStep)]))();
}
}
private:
void JumpBackToObjectSelection() const
{
WindowCloseAll();
gEditorStep = EditorStep::ObjectSelection;
GfxInvalidateScreen();
}
void JumpBackToLandscapeEditor() const
{
WindowCloseAll();
SetAllSceneryItemsInvented();
ScenerySetDefaultPlacementConfiguration();
gEditorStep = EditorStep::LandscapeEditor;
ContextOpenWindow(WindowClass::Map);
GfxInvalidateScreen();
}
void JumpBackToInventionListSetUp() const
{
WindowCloseAll();
ContextOpenWindow(WindowClass::EditorInventionList);
gEditorStep = EditorStep::InventionsListSetUp;
GfxInvalidateScreen();
}
void JumpBackToOptionsSelection() const
{
WindowCloseAll();
ContextOpenWindow(WindowClass::EditorScenarioOptions);
gEditorStep = EditorStep::OptionsSelection;
GfxInvalidateScreen();
}
bool CheckObjectSelection() const
{
WindowBase* w;
auto [missingObjectType, errorString] = Editor::CheckObjectSelection();
if (missingObjectType == ObjectType::None)
{
WindowCloseByClass(WindowClass::EditorObjectSelection);
return true;
}
ContextShowError(STR_INVALID_SELECTION_OF_OBJECTS, errorString, {});
w = WindowFindByClass(WindowClass::EditorObjectSelection);
if (w != nullptr)
{
// Click tab with missing object
WindowEventMouseUpCall(w, WC_EDITOR_OBJECT_SELECTION__WIDX_TAB_1 + EnumValue(missingObjectType));
}
return false;
}
void JumpForwardFromObjectSelection() const
{
if (!CheckObjectSelection())
return;
FinishObjectSelection();
if (gScreenFlags & SCREEN_FLAGS_TRACK_DESIGNER)
{
ContextOpenWindow(WindowClass::ConstructRide);
}
else
{
ContextOpenWindow(WindowClass::Map);
}
}
void JumpForwardToInventionListSetUp() const
{
auto [checksPassed, errorString] = Editor::CheckPark();
if (checksPassed)
{
WindowCloseAll();
ContextOpenWindow(WindowClass::EditorInventionList);
gEditorStep = EditorStep::InventionsListSetUp;
}
else
{
ContextShowError(STR_CANT_ADVANCE_TO_NEXT_EDITOR_STAGE, errorString, {});
}
GfxInvalidateScreen();
}
void JumpForwardToOptionsSelection() const
{
WindowCloseAll();
ContextOpenWindow(WindowClass::EditorScenarioOptions);
gEditorStep = EditorStep::OptionsSelection;
GfxInvalidateScreen();
}
void JumpForwardToObjectiveSelection() const
{
WindowCloseAll();
ContextOpenWindow(WindowClass::EditorObjectiveOptions);
gEditorStep = EditorStep::ObjectiveSelection;
GfxInvalidateScreen();
}
void JumpForwardToSaveScenario() const
{
auto& gameState = GetGameState();
const auto savePrepareResult = ScenarioPrepareForSave(gameState);
if (!savePrepareResult.Successful)
{
ContextShowError(STR_UNABLE_TO_SAVE_SCENARIO_FILE, savePrepareResult.Message, {});
GfxInvalidateScreen();
return;
}
WindowCloseAll();
auto intent = Intent(WindowClass::Loadsave);
intent.PutExtra(INTENT_EXTRA_LOADSAVE_TYPE, LOADSAVETYPE_SAVE | LOADSAVETYPE_SCENARIO);
intent.PutExtra(INTENT_EXTRA_PATH, gameState.ScenarioName);
ContextOpenIntent(&intent);
}
void HidePreviousStepButton()
{
widgets[WIDX_PREVIOUS_STEP_BUTTON].type = WindowWidgetType::Empty;
widgets[WIDX_PREVIOUS_IMAGE].type = WindowWidgetType::Empty;
}
void HideNextStepButton()
{
widgets[WIDX_NEXT_STEP_BUTTON].type = WindowWidgetType::Empty;
widgets[WIDX_NEXT_IMAGE].type = WindowWidgetType::Empty;
}
void DrawLeftButtonBack(DrawPixelInfo& dpi)
{
auto previousWidget = widgets[WIDX_PREVIOUS_IMAGE];
auto leftTop = windowPos + ScreenCoordsXY{ previousWidget.left, previousWidget.top };
auto rightBottom = windowPos + ScreenCoordsXY{ previousWidget.right, previousWidget.bottom };
GfxFilterRect(dpi, { leftTop, rightBottom }, FilterPaletteID::Palette51);
}
void DrawLeftButton(DrawPixelInfo& dpi)
{
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 };
GfxFillRectInset(dpi, { topLeft, bottomRight }, colours[1], INSET_RECT_F_30);
GfxDrawSprite(
dpi, ImageId(SPR_PREVIOUS),
windowPos + ScreenCoordsXY{ widgets[WIDX_PREVIOUS_IMAGE].left + 6, widgets[WIDX_PREVIOUS_IMAGE].top + 6 });
colour_t textColour = NOT_TRANSLUCENT(colours[1]);
if (gHoverWidget.window_classification == WindowClass::BottomToolbar
&& gHoverWidget.widget_index == WIDX_PREVIOUS_STEP_BUTTON)
{
textColour = 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 = _editorStepNames[EnumValue(gEditorStep) - 1];
if (gScreenFlags & SCREEN_FLAGS_TRACK_DESIGNER)
stringId = STR_EDITOR_STEP_OBJECT_SELECTION;
DrawTextBasic(dpi, { textX, textY }, STR_BACK_TO_PREVIOUS_STEP, {}, { textColour, TextAlignment::CENTRE });
DrawTextBasic(dpi, { textX, textY + 10 }, stringId, {}, { textColour, TextAlignment::CENTRE });
}
void DrawRightButtonBack(DrawPixelInfo& dpi)
{
auto nextWidget = widgets[WIDX_NEXT_IMAGE];
auto leftTop = windowPos + ScreenCoordsXY{ nextWidget.left, nextWidget.top };
auto rightBottom = windowPos + ScreenCoordsXY{ nextWidget.right, nextWidget.bottom };
GfxFilterRect(dpi, { leftTop, rightBottom }, FilterPaletteID::Palette51);
}
void DrawRightButton(DrawPixelInfo& dpi)
{
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 };
GfxFillRectInset(dpi, { topLeft, bottomRight }, colours[1], INSET_RECT_F_30);
GfxDrawSprite(
dpi, ImageId(SPR_NEXT),
windowPos + ScreenCoordsXY{ widgets[WIDX_NEXT_IMAGE].right - 29, widgets[WIDX_NEXT_IMAGE].top + 6 });
colour_t textColour = NOT_TRANSLUCENT(colours[1]);
if (gHoverWidget.window_classification == WindowClass::BottomToolbar
&& gHoverWidget.widget_index == WIDX_NEXT_STEP_BUTTON)
{
textColour = 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 = _editorStepNames[EnumValue(gEditorStep) + 1];
if (gScreenFlags & SCREEN_FLAGS_TRACK_DESIGNER)
stringId = STR_EDITOR_STEP_ROLLERCOASTER_DESIGNER;
DrawTextBasic(dpi, { textX, textY }, STR_FORWARD_TO_NEXT_STEP, {}, { textColour, TextAlignment::CENTRE });
DrawTextBasic(dpi, { textX, textY + 10 }, stringId, {}, { textColour, TextAlignment::CENTRE });
}
void DrawStepText(DrawPixelInfo& dpi)
{
int16_t stateX = (widgets[WIDX_PREVIOUS_IMAGE].right + widgets[WIDX_NEXT_IMAGE].left) / 2 + windowPos.x;
int16_t stateY = height - 0x0C + windowPos.y;
DrawTextBasic(
dpi, { stateX, stateY }, _editorStepNames[EnumValue(gEditorStep)], {},
{ static_cast<colour_t>(NOT_TRANSLUCENT(colours[2]) | COLOUR_FLAG_OUTLINE), TextAlignment::CENTRE });
}
static constexpr FuncPtr _previousButtonMouseUp[] = {
nullptr,
&EditorBottomToolbarWindow::JumpBackToObjectSelection,
&EditorBottomToolbarWindow::JumpBackToLandscapeEditor,
&EditorBottomToolbarWindow::JumpBackToInventionListSetUp,
&EditorBottomToolbarWindow::JumpBackToOptionsSelection,
nullptr,
&EditorBottomToolbarWindow::JumpBackToObjectSelection,
nullptr,
};
static constexpr FuncPtr _nextButtonMouseUp[] = {
&EditorBottomToolbarWindow::JumpForwardFromObjectSelection,
&EditorBottomToolbarWindow::JumpForwardToInventionListSetUp,
&EditorBottomToolbarWindow::JumpForwardToOptionsSelection,
&EditorBottomToolbarWindow::JumpForwardToObjectiveSelection,
&EditorBottomToolbarWindow::JumpForwardToSaveScenario,
nullptr,
nullptr,
nullptr,
};
};
/**
* Creates the main editor top toolbar window.
* rct2: 0x0066F052 (part of 0x0066EF38)
*/
WindowBase* WindowEditorBottomToolbarOpen()
{
auto* window = WindowCreate<EditorBottomToolbarWindow>(
WindowClass::BottomToolbar, ScreenCoordsXY(0, ContextGetHeight() - 32), ContextGetWidth(), 32,
WF_STICK_TO_FRONT | WF_TRANSPARENT | WF_NO_BACKGROUND);
return window;
}