2014-09-27 01:41:24 +02:00
|
|
|
/*****************************************************************************
|
2024-01-01 12:52:28 +01:00
|
|
|
* Copyright (c) 2014-2024 OpenRCT2 developers
|
2014-09-27 01:41:24 +02:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* For a complete list of all authors, please refer to contributors.md
|
|
|
|
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
2014-09-27 01:41:24 +02:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
2014-09-27 01:41:24 +02:00
|
|
|
*****************************************************************************/
|
|
|
|
|
2018-08-12 13:50:40 +02:00
|
|
|
#include <algorithm>
|
2018-06-22 23:21:44 +02:00
|
|
|
#include <openrct2-ui/interface/Widget.h>
|
2022-08-11 00:00:58 +02:00
|
|
|
#include <openrct2-ui/ride/Construction.h>
|
2018-06-22 23:21:44 +02:00
|
|
|
#include <openrct2-ui/windows/Window.h>
|
2017-10-21 16:37:30 +02:00
|
|
|
#include <openrct2/Context.h>
|
2018-06-22 23:21:44 +02:00
|
|
|
#include <openrct2/Editor.h>
|
|
|
|
#include <openrct2/OpenRCT2.h>
|
|
|
|
#include <openrct2/audio/audio.h>
|
2021-03-27 15:52:46 +01:00
|
|
|
#include <openrct2/config/Config.h>
|
2017-11-23 11:57:49 +01:00
|
|
|
#include <openrct2/core/String.hpp>
|
2017-10-21 16:37:30 +02:00
|
|
|
#include <openrct2/drawing/IDrawingEngine.h>
|
2021-12-12 00:06:06 +01:00
|
|
|
#include <openrct2/localisation/Formatter.h>
|
2018-01-06 18:32:25 +01:00
|
|
|
#include <openrct2/localisation/Localisation.h>
|
2021-12-18 19:50:29 +01:00
|
|
|
#include <openrct2/ride/RideConstruction.h>
|
2020-06-20 02:32:52 +02:00
|
|
|
#include <openrct2/ride/RideData.h>
|
2018-06-22 23:21:44 +02:00
|
|
|
#include <openrct2/ride/TrackDesign.h>
|
2017-10-21 16:37:30 +02:00
|
|
|
#include <openrct2/ride/TrackDesignRepository.h>
|
|
|
|
#include <openrct2/sprites.h>
|
|
|
|
#include <openrct2/windows/Intent.h>
|
2018-06-22 23:21:44 +02:00
|
|
|
#include <vector>
|
2014-09-27 01:41:24 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
namespace OpenRCT2::Ui::Windows
|
|
|
|
{
|
|
|
|
static constexpr StringId WINDOW_TITLE = STR_SELECT_DESIGN;
|
|
|
|
static constexpr int32_t WH = 441;
|
|
|
|
static constexpr int32_t WW = 600;
|
|
|
|
static constexpr int32_t DEBUG_PATH_HEIGHT = 12;
|
|
|
|
static constexpr int32_t ROTATE_AND_SCENERY_BUTTON_SIZE = 24;
|
|
|
|
static constexpr int32_t WINDOW_PADDING = 5;
|
|
|
|
|
|
|
|
// clang-format off
|
2014-09-27 01:41:24 +02:00
|
|
|
enum {
|
2017-06-06 23:24:18 +02:00
|
|
|
WIDX_BACKGROUND,
|
|
|
|
WIDX_TITLE,
|
|
|
|
WIDX_CLOSE,
|
2017-11-23 11:57:49 +01:00
|
|
|
WIDX_BACK,
|
|
|
|
WIDX_FILTER_STRING,
|
2017-11-23 15:39:15 +01:00
|
|
|
WIDX_FILTER_CLEAR,
|
2017-06-06 23:24:18 +02:00
|
|
|
WIDX_TRACK_LIST,
|
|
|
|
WIDX_TRACK_PREVIEW,
|
|
|
|
WIDX_ROTATE,
|
|
|
|
WIDX_TOGGLE_SCENERY,
|
2014-09-27 01:41:24 +02:00
|
|
|
};
|
|
|
|
|
2017-05-02 02:01:29 +02:00
|
|
|
validate_global_widx(WC_TRACK_DESIGN_LIST, WIDX_ROTATE);
|
|
|
|
|
2023-07-05 22:49:09 +02:00
|
|
|
static Widget _trackListWidgets[] = {
|
2020-05-09 16:44:21 +02:00
|
|
|
WINDOW_SHIM(WINDOW_TITLE, WW, WH),
|
2020-11-27 04:14:20 +01:00
|
|
|
MakeWidget({ 4, 18}, {218, 13}, WindowWidgetType::TableHeader, WindowColour::Primary , STR_SELECT_OTHER_RIDE ),
|
|
|
|
MakeWidget({ 4, 32}, {124, 13}, WindowWidgetType::TextBox, WindowColour::Secondary ),
|
|
|
|
MakeWidget({130, 32}, { 92, 13}, WindowWidgetType::Button, WindowColour::Primary , STR_OBJECT_SEARCH_CLEAR ),
|
|
|
|
MakeWidget({ 4, 46}, {218, 381}, WindowWidgetType::Scroll, WindowColour::Primary , SCROLL_VERTICAL, STR_CLICK_ON_DESIGN_TO_BUILD_IT_TIP),
|
|
|
|
MakeWidget({224, 18}, {372, 219}, WindowWidgetType::FlatBtn, WindowColour::Primary ),
|
2022-12-24 17:47:22 +01:00
|
|
|
MakeWidget({572, 405}, { ROTATE_AND_SCENERY_BUTTON_SIZE, ROTATE_AND_SCENERY_BUTTON_SIZE}, WindowWidgetType::FlatBtn, WindowColour::Primary , ImageId(SPR_ROTATE_ARROW), STR_ROTATE_90_TIP ),
|
|
|
|
MakeWidget({572, 381}, { ROTATE_AND_SCENERY_BUTTON_SIZE, ROTATE_AND_SCENERY_BUTTON_SIZE}, WindowWidgetType::FlatBtn, WindowColour::Primary , ImageId(SPR_SCENERY), STR_TOGGLE_SCENERY_TIP ),
|
2024-03-09 15:15:45 +01:00
|
|
|
kWidgetsEnd,
|
2014-09-27 01:41:24 +02:00
|
|
|
};
|
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
// clang-format on
|
2014-09-27 01:41:24 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
constexpr uint16_t TRACK_DESIGN_INDEX_UNLOADED = UINT16_MAX;
|
2016-05-04 20:03:27 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
RideSelection _window_track_list_item;
|
2014-09-27 01:41:24 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
class TrackListWindow final : public Window
|
2018-06-22 23:21:44 +02:00
|
|
|
{
|
2024-03-10 14:52:35 +01:00
|
|
|
private:
|
|
|
|
std::vector<TrackDesignFileRef> _trackDesigns;
|
|
|
|
utf8 _filterString[USER_STRING_MAX_LENGTH]{};
|
|
|
|
std::vector<uint16_t> _filteredTrackIds;
|
|
|
|
uint16_t _loadedTrackDesignIndex;
|
|
|
|
std::unique_ptr<TrackDesign> _loadedTrackDesign;
|
|
|
|
std::vector<uint8_t> _trackDesignPreviewPixels;
|
|
|
|
bool _selectedItemIsBeingUpdated;
|
|
|
|
bool _reloadTrackDesigns;
|
|
|
|
|
|
|
|
void FilterList()
|
|
|
|
{
|
|
|
|
_filteredTrackIds.clear();
|
|
|
|
|
|
|
|
// Nothing to filter, so fill the list with all indices
|
|
|
|
if (String::LengthOf(_filterString) == 0)
|
|
|
|
{
|
|
|
|
for (uint16_t i = 0; i < _trackDesigns.size(); i++)
|
|
|
|
_filteredTrackIds.push_back(i);
|
2017-11-23 11:57:49 +01:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
return;
|
|
|
|
}
|
2017-06-06 23:24:18 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
// Convert filter to uppercase
|
|
|
|
const auto filterStringUpper = String::ToUpper(_filterString);
|
2017-10-21 16:37:30 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
// Fill the set with indices for tracks that match the filter
|
|
|
|
for (uint16_t i = 0; i < _trackDesigns.size(); i++)
|
|
|
|
{
|
|
|
|
const auto trackNameUpper = String::ToUpper(_trackDesigns[i].name);
|
|
|
|
if (trackNameUpper.find(filterStringUpper) != std::string::npos)
|
|
|
|
{
|
|
|
|
_filteredTrackIds.push_back(i);
|
|
|
|
}
|
|
|
|
}
|
2014-09-27 01:41:24 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
// Ensure that the selected item is still in the list.
|
|
|
|
if (static_cast<size_t>(selected_list_item) >= _filteredTrackIds.size())
|
2021-10-14 16:35:40 +02:00
|
|
|
{
|
2024-03-10 14:52:35 +01:00
|
|
|
selected_list_item = 0;
|
2021-10-14 16:35:40 +02:00
|
|
|
}
|
|
|
|
}
|
2023-07-19 13:54:06 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
void SelectFromList(int32_t listIndex)
|
2023-07-19 13:54:06 +02:00
|
|
|
{
|
2024-03-10 14:52:35 +01:00
|
|
|
OpenRCT2::Audio::Play(OpenRCT2::Audio::SoundId::Click1, 0, this->windowPos.x + (this->width / 2));
|
|
|
|
if (!(gScreenFlags & SCREEN_FLAGS_TRACK_MANAGER))
|
|
|
|
{
|
|
|
|
if (listIndex == 0)
|
|
|
|
{
|
|
|
|
Close();
|
|
|
|
RideConstructNew(_window_track_list_item);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
listIndex--;
|
|
|
|
}
|
2017-11-23 15:39:15 +01:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
// Displays a message if the ride can't load, fix #4080
|
|
|
|
if (_loadedTrackDesign == nullptr)
|
2021-10-14 16:35:40 +02:00
|
|
|
{
|
2024-03-10 14:52:35 +01:00
|
|
|
ContextShowError(STR_CANT_BUILD_THIS_HERE, STR_TRACK_LOAD_FAILED_ERROR, {});
|
2021-10-14 16:35:40 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-11-23 15:39:15 +01:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
if (_loadedTrackDesign->track_flags & TRACK_DESIGN_FLAG_SCENERY_UNAVAILABLE)
|
|
|
|
{
|
|
|
|
gTrackDesignSceneryToggle = true;
|
|
|
|
}
|
2017-11-23 15:39:15 +01:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
uint16_t trackDesignIndex = _filteredTrackIds[listIndex];
|
|
|
|
TrackDesignFileRef* tdRef = &_trackDesigns[trackDesignIndex];
|
|
|
|
if (gScreenFlags & SCREEN_FLAGS_TRACK_MANAGER)
|
|
|
|
{
|
|
|
|
auto intent = Intent(WindowClass::ManageTrackDesign);
|
|
|
|
intent.PutExtra(INTENT_EXTRA_TRACK_DESIGN, tdRef);
|
|
|
|
ContextOpenIntent(&intent);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (_loadedTrackDesignIndex != TRACK_DESIGN_INDEX_UNLOADED
|
|
|
|
&& (_loadedTrackDesign->track_flags & TRACK_DESIGN_FLAG_VEHICLE_UNAVAILABLE))
|
|
|
|
{
|
|
|
|
ContextShowError(STR_THIS_DESIGN_WILL_BE_BUILT_WITH_AN_ALTERNATIVE_VEHICLE_TYPE, STR_NONE, {});
|
|
|
|
}
|
2017-06-06 23:24:18 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
auto intent = Intent(WindowClass::TrackDesignPlace);
|
|
|
|
intent.PutExtra(INTENT_EXTRA_TRACK_DESIGN, tdRef);
|
|
|
|
ContextOpenIntent(&intent);
|
|
|
|
}
|
2021-10-14 16:35:40 +02:00
|
|
|
}
|
2024-03-10 14:52:35 +01:00
|
|
|
|
|
|
|
int32_t GetListItemFromPosition(const ScreenCoordsXY& screenCoords)
|
2021-10-14 16:35:40 +02:00
|
|
|
{
|
2024-03-10 14:52:35 +01:00
|
|
|
size_t maxItems = _filteredTrackIds.size();
|
|
|
|
if (!(gScreenFlags & SCREEN_FLAGS_TRACK_MANAGER))
|
2021-10-14 16:35:40 +02:00
|
|
|
{
|
2024-03-10 14:52:35 +01:00
|
|
|
// Extra item: custom design
|
|
|
|
maxItems++;
|
2021-10-14 16:35:40 +02:00
|
|
|
}
|
|
|
|
|
2024-04-14 19:27:32 +02:00
|
|
|
int32_t index = screenCoords.y / SCROLLABLE_ROW_HEIGHT;
|
2024-03-10 14:52:35 +01:00
|
|
|
if (index < 0 || static_cast<uint32_t>(index) >= maxItems)
|
|
|
|
{
|
|
|
|
index = -1;
|
|
|
|
}
|
|
|
|
return index;
|
2021-10-14 16:35:40 +02:00
|
|
|
}
|
2016-04-30 14:27:12 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
void LoadDesignsList(RideSelection item)
|
2018-06-22 23:21:44 +02:00
|
|
|
{
|
2024-03-10 14:52:35 +01:00
|
|
|
auto repo = OpenRCT2::GetContext()->GetTrackDesignRepository();
|
|
|
|
std::string entryName;
|
|
|
|
if (item.Type < 0x80)
|
|
|
|
{
|
|
|
|
if (GetRideTypeDescriptor(item.Type).HasFlag(RIDE_TYPE_FLAG_LIST_VEHICLES_SEPARATELY))
|
|
|
|
{
|
|
|
|
entryName = GetRideEntryName(item.EntryIndex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_trackDesigns = repo->GetItemsForObjectEntry(item.Type, entryName);
|
2017-06-06 23:24:18 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
FilterList();
|
2021-10-14 16:35:40 +02:00
|
|
|
}
|
2020-02-22 19:06:57 +01:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
bool LoadDesignPreview(const u8string& path)
|
2021-10-14 16:35:40 +02:00
|
|
|
{
|
2024-03-10 14:52:35 +01:00
|
|
|
_loadedTrackDesign = TrackDesignImport(path.c_str());
|
|
|
|
if (_loadedTrackDesign != nullptr)
|
2021-10-14 16:35:40 +02:00
|
|
|
{
|
2024-03-10 14:52:35 +01:00
|
|
|
TrackDesignDrawPreview(_loadedTrackDesign.get(), _trackDesignPreviewPixels.data());
|
|
|
|
return true;
|
2021-10-14 16:35:40 +02:00
|
|
|
}
|
2024-03-10 14:52:35 +01:00
|
|
|
return false;
|
2021-10-14 16:35:40 +02:00
|
|
|
}
|
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
public:
|
|
|
|
TrackListWindow(const RideSelection item)
|
2021-10-14 16:35:40 +02:00
|
|
|
{
|
2024-03-10 14:52:35 +01:00
|
|
|
_window_track_list_item = item;
|
2021-10-14 16:35:40 +02:00
|
|
|
}
|
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
void OnOpen() override
|
|
|
|
{
|
|
|
|
LoadDesignsList(_window_track_list_item);
|
2023-07-19 09:02:31 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
String::Set(_filterString, sizeof(_filterString), "");
|
|
|
|
_trackListWidgets[WIDX_FILTER_STRING].string = _filterString;
|
|
|
|
widgets = _trackListWidgets;
|
2023-07-19 09:02:31 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
if (gScreenFlags & SCREEN_FLAGS_TRACK_MANAGER)
|
|
|
|
{
|
|
|
|
widgets[WIDX_BACK].type = WindowWidgetType::Empty;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
widgets[WIDX_BACK].type = WindowWidgetType::TableHeader;
|
|
|
|
}
|
2021-11-01 18:32:28 +01:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
WindowInitScrollWidgets(*this);
|
|
|
|
_selectedItemIsBeingUpdated = false;
|
|
|
|
_reloadTrackDesigns = false;
|
|
|
|
// Start with first track highlighted
|
|
|
|
selected_list_item = 0;
|
|
|
|
if (_trackDesigns.size() != 0 && !(gScreenFlags & SCREEN_FLAGS_TRACK_MANAGER))
|
|
|
|
{
|
|
|
|
selected_list_item = 1;
|
|
|
|
}
|
|
|
|
gTrackDesignSceneryToggle = false;
|
|
|
|
WindowPushOthersRight(*this);
|
|
|
|
_currentTrackPieceDirection = 2;
|
2024-03-24 22:49:50 +01:00
|
|
|
_trackDesignPreviewPixels.resize(4 * kTrackPreviewImageSize);
|
2024-03-10 14:52:35 +01:00
|
|
|
|
|
|
|
_loadedTrackDesign = nullptr;
|
|
|
|
_loadedTrackDesignIndex = TRACK_DESIGN_INDEX_UNLOADED;
|
2021-11-01 18:32:28 +01:00
|
|
|
}
|
2021-10-14 16:35:40 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
void OnClose() override
|
2018-06-22 23:21:44 +02:00
|
|
|
{
|
2024-03-10 14:52:35 +01:00
|
|
|
// Dispose track design and preview
|
|
|
|
_loadedTrackDesign = nullptr;
|
|
|
|
_trackDesignPreviewPixels.clear();
|
|
|
|
_trackDesignPreviewPixels.shrink_to_fit();
|
2017-06-06 23:24:18 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
// Dispose track list
|
|
|
|
_trackDesigns.clear();
|
2014-09-27 21:26:04 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
// If gScreenAge is zero, we're already in the process
|
|
|
|
// of loading the track manager, so we shouldn't try
|
|
|
|
// to do it again. Otherwise, this window will get
|
|
|
|
// another close signal from the track manager load function,
|
|
|
|
// try to load the track manager again, and an infinite loop will result.
|
|
|
|
if ((gScreenFlags & SCREEN_FLAGS_TRACK_MANAGER) && gScreenAge != 0)
|
|
|
|
{
|
|
|
|
WindowCloseByNumber(WindowClass::ManageTrackDesign, number);
|
|
|
|
WindowCloseByNumber(WindowClass::TrackDeletePrompt, number);
|
|
|
|
Editor::LoadTrackManager();
|
|
|
|
}
|
2021-10-14 16:35:40 +02:00
|
|
|
}
|
2014-09-27 21:26:04 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
void OnMouseUp(const WidgetIndex widgetIndex) override
|
2021-10-14 16:35:40 +02:00
|
|
|
{
|
2024-03-10 14:52:35 +01:00
|
|
|
switch (widgetIndex)
|
|
|
|
{
|
|
|
|
case WIDX_CLOSE:
|
|
|
|
Close();
|
|
|
|
break;
|
|
|
|
case WIDX_ROTATE:
|
|
|
|
_currentTrackPieceDirection++;
|
|
|
|
_currentTrackPieceDirection %= 4;
|
|
|
|
Invalidate();
|
|
|
|
break;
|
|
|
|
case WIDX_TOGGLE_SCENERY:
|
|
|
|
gTrackDesignSceneryToggle = !gTrackDesignSceneryToggle;
|
|
|
|
_loadedTrackDesignIndex = TRACK_DESIGN_INDEX_UNLOADED;
|
|
|
|
Invalidate();
|
|
|
|
break;
|
|
|
|
case WIDX_BACK:
|
|
|
|
Close();
|
|
|
|
if (!(gScreenFlags & SCREEN_FLAGS_TRACK_MANAGER))
|
|
|
|
{
|
|
|
|
ContextOpenWindow(WindowClass::ConstructRide);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WIDX_FILTER_STRING:
|
|
|
|
WindowStartTextbox(
|
|
|
|
*this, widgetIndex, STR_STRING, _filterString, sizeof(_filterString)); // TODO check this out
|
|
|
|
break;
|
|
|
|
case WIDX_FILTER_CLEAR:
|
|
|
|
// Keep the highlighted item selected
|
|
|
|
if (gScreenFlags & SCREEN_FLAGS_TRACK_MANAGER)
|
|
|
|
{
|
|
|
|
if (selected_list_item != -1 && _filteredTrackIds.size() > static_cast<size_t>(selected_list_item))
|
|
|
|
selected_list_item = _filteredTrackIds[selected_list_item];
|
|
|
|
else
|
|
|
|
selected_list_item = -1;
|
|
|
|
}
|
2021-10-14 16:35:40 +02:00
|
|
|
else
|
2024-03-10 14:52:35 +01:00
|
|
|
{
|
|
|
|
if (selected_list_item != 0)
|
|
|
|
selected_list_item = _filteredTrackIds[selected_list_item - 1] + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
String::Set(_filterString, sizeof(_filterString), "");
|
|
|
|
FilterList();
|
|
|
|
Invalidate();
|
|
|
|
break;
|
|
|
|
}
|
2021-10-14 16:35:40 +02:00
|
|
|
}
|
2014-09-27 01:41:24 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
ScreenSize OnScrollGetSize(const int32_t scrollIndex) override
|
2021-10-14 16:35:40 +02:00
|
|
|
{
|
2024-03-10 14:52:35 +01:00
|
|
|
size_t numItems = _filteredTrackIds.size();
|
|
|
|
if (!(gScreenFlags & SCREEN_FLAGS_TRACK_MANAGER))
|
|
|
|
{
|
|
|
|
// Extra item: custom design
|
|
|
|
numItems++;
|
|
|
|
}
|
2024-04-14 19:27:32 +02:00
|
|
|
int32_t scrollHeight = static_cast<int32_t>(numItems * SCROLLABLE_ROW_HEIGHT);
|
2014-09-27 01:41:24 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
return { width, scrollHeight };
|
|
|
|
}
|
2014-09-27 01:41:24 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
void OnScrollMouseDown(const int32_t scrollIndex, const ScreenCoordsXY& screenCoords) override
|
2018-06-22 23:21:44 +02:00
|
|
|
{
|
2024-03-10 14:52:35 +01:00
|
|
|
if (!_selectedItemIsBeingUpdated)
|
2021-10-14 16:35:40 +02:00
|
|
|
{
|
2024-03-10 14:52:35 +01:00
|
|
|
int32_t i = GetListItemFromPosition(screenCoords);
|
|
|
|
if (i != -1)
|
|
|
|
{
|
|
|
|
SelectFromList(i);
|
|
|
|
}
|
2021-10-14 16:35:40 +02:00
|
|
|
}
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2014-09-27 01:41:24 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
void OnScrollMouseOver(const int32_t scrollIndex, const ScreenCoordsXY& screenCoords) override
|
2017-11-23 11:57:49 +01:00
|
|
|
{
|
2024-03-10 14:52:35 +01:00
|
|
|
if (!_selectedItemIsBeingUpdated)
|
2021-10-14 16:35:40 +02:00
|
|
|
{
|
2024-03-10 14:52:35 +01:00
|
|
|
int32_t i = GetListItemFromPosition(screenCoords);
|
|
|
|
if (i != -1 && selected_list_item != i)
|
|
|
|
{
|
|
|
|
selected_list_item = i;
|
|
|
|
Invalidate();
|
|
|
|
}
|
2021-10-14 16:35:40 +02:00
|
|
|
}
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2017-11-23 11:57:49 +01:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
void OnTextInput(const WidgetIndex widgetIndex, std::string_view text) override
|
|
|
|
{
|
|
|
|
if (widgetIndex != WIDX_FILTER_STRING)
|
|
|
|
return;
|
2017-11-23 11:57:49 +01:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
if (String::Equals(_filterString, std::string(text).c_str()))
|
|
|
|
return;
|
2017-11-23 11:57:49 +01:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
String::Set(_filterString, sizeof(_filterString), std::string(text).c_str());
|
2017-11-23 11:57:49 +01:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
FilterList();
|
2017-11-23 11:57:49 +01:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
scrolls->v_top = 0;
|
2017-06-06 23:24:18 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
Invalidate();
|
2021-10-14 16:35:40 +02:00
|
|
|
}
|
2017-06-06 23:24:18 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
void OnPrepareDraw() override
|
2018-06-22 23:21:44 +02:00
|
|
|
{
|
2024-03-10 14:52:35 +01:00
|
|
|
StringId stringId = STR_NONE;
|
|
|
|
const auto* entry = GetRideEntryByIndex(_window_track_list_item.EntryIndex);
|
2021-03-27 15:52:46 +01:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
if (entry != nullptr)
|
2021-10-14 16:35:40 +02:00
|
|
|
{
|
2024-03-10 14:52:35 +01:00
|
|
|
RideNaming rideName = GetRideNaming(_window_track_list_item.Type, *entry);
|
|
|
|
stringId = rideName.Name;
|
|
|
|
}
|
|
|
|
|
|
|
|
Formatter::Common().Add<StringId>(stringId);
|
|
|
|
if (gScreenFlags & SCREEN_FLAGS_TRACK_MANAGER)
|
|
|
|
{
|
|
|
|
widgets[WIDX_TITLE].text = STR_TRACK_DESIGNS;
|
|
|
|
widgets[WIDX_TRACK_LIST].tooltip = STR_CLICK_ON_DESIGN_TO_RENAME_OR_DELETE_IT;
|
2021-10-14 16:35:40 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-03-10 14:52:35 +01:00
|
|
|
widgets[WIDX_TITLE].text = STR_SELECT_DESIGN;
|
|
|
|
widgets[WIDX_TRACK_LIST].tooltip = STR_CLICK_ON_DESIGN_TO_BUILD_IT_TIP;
|
2021-10-14 16:35:40 +02:00
|
|
|
}
|
2017-06-06 23:24:18 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
if ((gScreenFlags & SCREEN_FLAGS_TRACK_MANAGER) || selected_list_item != 0)
|
|
|
|
{
|
|
|
|
pressed_widgets |= 1uLL << WIDX_TRACK_PREVIEW;
|
|
|
|
disabled_widgets &= ~(1uLL << WIDX_TRACK_PREVIEW);
|
|
|
|
widgets[WIDX_ROTATE].type = WindowWidgetType::FlatBtn;
|
|
|
|
widgets[WIDX_TOGGLE_SCENERY].type = WindowWidgetType::FlatBtn;
|
|
|
|
if (gTrackDesignSceneryToggle)
|
|
|
|
{
|
|
|
|
pressed_widgets &= ~(1uLL << WIDX_TOGGLE_SCENERY);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pressed_widgets |= (1uLL << WIDX_TOGGLE_SCENERY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pressed_widgets &= ~(1uLL << WIDX_TRACK_PREVIEW);
|
|
|
|
disabled_widgets |= (1uLL << WIDX_TRACK_PREVIEW);
|
|
|
|
widgets[WIDX_ROTATE].type = WindowWidgetType::Empty;
|
|
|
|
widgets[WIDX_TOGGLE_SCENERY].type = WindowWidgetType::Empty;
|
|
|
|
}
|
2021-10-14 16:35:40 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
// When debugging tools are on, shift everything up a bit to make room for displaying the path.
|
|
|
|
const int32_t bottomMargin = gConfigGeneral.DebuggingTools ? (WINDOW_PADDING + DEBUG_PATH_HEIGHT) : WINDOW_PADDING;
|
|
|
|
widgets[WIDX_TRACK_LIST].bottom = height - bottomMargin;
|
|
|
|
widgets[WIDX_ROTATE].bottom = height - bottomMargin;
|
|
|
|
widgets[WIDX_ROTATE].top = widgets[WIDX_ROTATE].bottom - ROTATE_AND_SCENERY_BUTTON_SIZE;
|
|
|
|
widgets[WIDX_TOGGLE_SCENERY].bottom = widgets[WIDX_ROTATE].top;
|
|
|
|
widgets[WIDX_TOGGLE_SCENERY].top = widgets[WIDX_TOGGLE_SCENERY].bottom - ROTATE_AND_SCENERY_BUTTON_SIZE;
|
2021-10-14 16:35:40 +02:00
|
|
|
}
|
2017-11-23 11:57:49 +01:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
void OnUpdate() override
|
2021-10-14 16:35:40 +02:00
|
|
|
{
|
2024-03-10 14:52:35 +01:00
|
|
|
if (gCurrentTextBox.window.classification == classification && gCurrentTextBox.window.number == number)
|
|
|
|
{
|
|
|
|
WindowUpdateTextboxCaret();
|
|
|
|
WidgetInvalidate(*this, WIDX_FILTER_STRING); // TODO Check this
|
|
|
|
}
|
2017-06-06 23:24:18 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
if (_reloadTrackDesigns)
|
|
|
|
{
|
|
|
|
LoadDesignsList(_window_track_list_item);
|
|
|
|
selected_list_item = 0;
|
|
|
|
Invalidate();
|
|
|
|
_reloadTrackDesigns = false;
|
|
|
|
}
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
void OnDraw(DrawPixelInfo& dpi) override
|
|
|
|
{
|
|
|
|
DrawWidgets(dpi);
|
2023-07-19 21:32:15 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
int32_t listItemIndex = selected_list_item;
|
|
|
|
if ((gScreenFlags & SCREEN_FLAGS_TRACK_MANAGER) == 0)
|
|
|
|
{
|
|
|
|
// Because the first item in the list is "Build a custom design", lower the index by one
|
|
|
|
listItemIndex--;
|
|
|
|
}
|
2017-06-06 23:24:18 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
if (_filteredTrackIds.empty() || listItemIndex == -1)
|
|
|
|
return;
|
2018-03-16 13:24:59 +01:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
int32_t trackIndex = _filteredTrackIds[listItemIndex];
|
2018-03-16 13:24:59 +01:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
// Track preview
|
|
|
|
auto& tdWidget = widgets[WIDX_TRACK_PREVIEW];
|
|
|
|
int32_t colour = ColourMapA[colours[0]].darkest;
|
|
|
|
u8string path = _trackDesigns[trackIndex].path;
|
2017-06-06 23:24:18 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
// Show track file path (in debug mode)
|
|
|
|
if (gConfigGeneral.DebuggingTools)
|
2021-10-14 16:35:40 +02:00
|
|
|
{
|
2024-03-10 14:52:35 +01:00
|
|
|
const auto shortPath = ShortenPath(path, width, FontStyle::Medium);
|
|
|
|
auto ft = Formatter();
|
|
|
|
ft.Add<utf8*>(shortPath.c_str());
|
|
|
|
DrawTextBasic(
|
|
|
|
dpi, windowPos + ScreenCoordsXY{ 0, height - DEBUG_PATH_HEIGHT - 3 }, STR_STRING, ft,
|
|
|
|
{ colours[1] }); // TODO Check dpi
|
2021-10-14 16:35:40 +02:00
|
|
|
}
|
2024-03-10 14:52:35 +01:00
|
|
|
|
|
|
|
auto screenPos = windowPos + ScreenCoordsXY{ tdWidget.left + 1, tdWidget.top + 1 };
|
|
|
|
GfxFillRect(dpi, { screenPos, screenPos + ScreenCoordsXY{ 369, 216 } }, colour); // TODO Check dpi
|
|
|
|
|
|
|
|
if (_loadedTrackDesignIndex != trackIndex)
|
2021-10-14 16:35:40 +02:00
|
|
|
{
|
2024-03-10 14:52:35 +01:00
|
|
|
if (LoadDesignPreview(path))
|
|
|
|
{
|
|
|
|
_loadedTrackDesignIndex = trackIndex;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_loadedTrackDesignIndex = TRACK_DESIGN_INDEX_UNLOADED;
|
|
|
|
}
|
2021-10-14 16:35:40 +02:00
|
|
|
}
|
2017-06-06 23:24:18 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
if (!_loadedTrackDesign)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2021-10-14 16:35:40 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
auto trackPreview = screenPos;
|
|
|
|
screenPos = windowPos + ScreenCoordsXY{ tdWidget.midX(), tdWidget.midY() };
|
2021-10-14 16:35:40 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
G1Element g1temp = {};
|
2024-03-24 22:49:50 +01:00
|
|
|
g1temp.offset = _trackDesignPreviewPixels.data() + (_currentTrackPieceDirection * kTrackPreviewImageSize);
|
2024-03-10 14:52:35 +01:00
|
|
|
g1temp.width = 370;
|
|
|
|
g1temp.height = 217;
|
|
|
|
g1temp.flags = G1_FLAG_HAS_TRANSPARENCY;
|
|
|
|
GfxSetG1Element(SPR_TEMP, &g1temp);
|
|
|
|
DrawingEngineInvalidateImage(SPR_TEMP);
|
|
|
|
GfxDrawSprite(dpi, ImageId(SPR_TEMP), trackPreview);
|
2021-10-14 16:35:40 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
screenPos.y = windowPos.y + tdWidget.bottom - 12;
|
2021-10-14 16:35:40 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
// Warnings
|
|
|
|
if ((_loadedTrackDesign->track_flags & TRACK_DESIGN_FLAG_VEHICLE_UNAVAILABLE)
|
|
|
|
&& !(gScreenFlags & SCREEN_FLAGS_TRACK_MANAGER))
|
2021-10-14 16:35:40 +02:00
|
|
|
{
|
2024-03-10 14:52:35 +01:00
|
|
|
// Vehicle design not available
|
|
|
|
DrawTextEllipsised(dpi, screenPos, 368, STR_VEHICLE_DESIGN_UNAVAILABLE, {}, { TextAlignment::CENTRE });
|
2024-04-14 19:27:32 +02:00
|
|
|
screenPos.y -= SCROLLABLE_ROW_HEIGHT;
|
2021-10-14 16:35:40 +02:00
|
|
|
}
|
2017-06-06 23:24:18 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
if (_loadedTrackDesign->track_flags & TRACK_DESIGN_FLAG_SCENERY_UNAVAILABLE)
|
|
|
|
{
|
|
|
|
if (!gTrackDesignSceneryToggle)
|
|
|
|
{
|
|
|
|
// Scenery not available
|
|
|
|
DrawTextEllipsised(
|
|
|
|
dpi, screenPos, 368, STR_DESIGN_INCLUDES_SCENERY_WHICH_IS_UNAVAILABLE, {}, { TextAlignment::CENTRE });
|
2024-04-14 19:27:32 +02:00
|
|
|
screenPos.y -= SCROLLABLE_ROW_HEIGHT;
|
2024-03-10 14:52:35 +01:00
|
|
|
}
|
|
|
|
}
|
2017-06-06 23:24:18 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
// Track design name
|
|
|
|
auto ft = Formatter();
|
|
|
|
ft.Add<const utf8*>(_trackDesigns[trackIndex].name.c_str());
|
|
|
|
DrawTextEllipsised(dpi, screenPos, 368, STR_TRACK_PREVIEW_NAME_FORMAT, ft, { TextAlignment::CENTRE });
|
2017-06-06 23:24:18 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
// Information
|
|
|
|
screenPos = windowPos + ScreenCoordsXY{ tdWidget.left + 1, tdWidget.bottom + 2 };
|
2017-06-06 23:24:18 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
// Stats
|
|
|
|
ft = Formatter();
|
|
|
|
ft.Add<fixed32_2dp>(_loadedTrackDesign->excitement * 10);
|
|
|
|
DrawTextBasic(dpi, screenPos, STR_TRACK_LIST_EXCITEMENT_RATING, ft);
|
2024-04-14 18:37:01 +02:00
|
|
|
screenPos.y += kListRowHeight;
|
2017-06-06 23:24:18 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
ft = Formatter();
|
|
|
|
ft.Add<fixed32_2dp>(_loadedTrackDesign->intensity * 10);
|
|
|
|
DrawTextBasic(dpi, screenPos, STR_TRACK_LIST_INTENSITY_RATING, ft);
|
2024-04-14 18:37:01 +02:00
|
|
|
screenPos.y += kListRowHeight;
|
2021-10-14 16:35:40 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
ft = Formatter();
|
|
|
|
ft.Add<fixed32_2dp>(_loadedTrackDesign->nausea * 10);
|
|
|
|
DrawTextBasic(dpi, screenPos, STR_TRACK_LIST_NAUSEA_RATING, ft);
|
2024-04-14 18:37:01 +02:00
|
|
|
screenPos.y += kListRowHeight + 4;
|
2024-03-10 14:52:35 +01:00
|
|
|
|
|
|
|
// Information for tracked rides.
|
|
|
|
if (GetRideTypeDescriptor(_loadedTrackDesign->type).HasFlag(RIDE_TYPE_FLAG_HAS_TRACK))
|
2018-05-25 23:01:27 +02:00
|
|
|
{
|
2024-03-10 14:52:35 +01:00
|
|
|
const auto& rtd = GetRideTypeDescriptor(_loadedTrackDesign->type);
|
|
|
|
if (!rtd.HasFlag(RIDE_TYPE_FLAG_IS_MAZE))
|
2021-10-14 16:35:40 +02:00
|
|
|
{
|
2024-03-10 14:52:35 +01:00
|
|
|
if (_loadedTrackDesign->type == RIDE_TYPE_MINI_GOLF)
|
|
|
|
{
|
|
|
|
// Holes
|
|
|
|
ft = Formatter();
|
|
|
|
ft.Add<uint16_t>(_loadedTrackDesign->holes & 0x1F);
|
|
|
|
DrawTextBasic(dpi, screenPos, STR_HOLES, ft);
|
2024-04-14 18:37:01 +02:00
|
|
|
screenPos.y += kListRowHeight;
|
2024-03-10 14:52:35 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Maximum speed
|
|
|
|
ft = Formatter();
|
|
|
|
ft.Add<uint16_t>(((_loadedTrackDesign->max_speed << 16) * 9) >> 18);
|
|
|
|
DrawTextBasic(dpi, screenPos, STR_MAX_SPEED, ft);
|
2024-04-14 18:37:01 +02:00
|
|
|
screenPos.y += kListRowHeight;
|
2024-03-10 14:52:35 +01:00
|
|
|
|
|
|
|
// Average speed
|
|
|
|
ft = Formatter();
|
|
|
|
ft.Add<uint16_t>(((_loadedTrackDesign->average_speed << 16) * 9) >> 18);
|
|
|
|
DrawTextBasic(dpi, screenPos, STR_AVERAGE_SPEED, ft);
|
2024-04-14 18:37:01 +02:00
|
|
|
screenPos.y += kListRowHeight;
|
2024-03-10 14:52:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Ride length
|
2021-10-14 16:35:40 +02:00
|
|
|
ft = Formatter();
|
2024-03-10 14:52:35 +01:00
|
|
|
ft.Add<StringId>(STR_RIDE_LENGTH_ENTRY);
|
|
|
|
ft.Add<uint16_t>(_loadedTrackDesign->ride_length);
|
|
|
|
DrawTextEllipsised(dpi, screenPos, 214, STR_TRACK_LIST_RIDE_LENGTH, ft);
|
2024-04-14 18:37:01 +02:00
|
|
|
screenPos.y += kListRowHeight;
|
2021-10-14 16:35:40 +02:00
|
|
|
}
|
2024-03-10 14:52:35 +01:00
|
|
|
|
|
|
|
if (GetRideTypeDescriptor(_loadedTrackDesign->type).HasFlag(RIDE_TYPE_FLAG_HAS_G_FORCES))
|
2021-10-14 16:35:40 +02:00
|
|
|
{
|
2024-03-10 14:52:35 +01:00
|
|
|
// Maximum positive vertical Gs
|
2021-10-14 16:35:40 +02:00
|
|
|
ft = Formatter();
|
2024-03-10 14:52:35 +01:00
|
|
|
ft.Add<int32_t>(_loadedTrackDesign->max_positive_vertical_g * 32);
|
|
|
|
DrawTextBasic(dpi, screenPos, STR_MAX_POSITIVE_VERTICAL_G, ft);
|
2024-04-14 18:37:01 +02:00
|
|
|
screenPos.y += kListRowHeight;
|
2021-10-14 16:35:40 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
// Maximum negative vertical Gs
|
2021-10-14 16:35:40 +02:00
|
|
|
ft = Formatter();
|
2024-03-10 14:52:35 +01:00
|
|
|
ft.Add<int32_t>(_loadedTrackDesign->max_negative_vertical_g * 32);
|
|
|
|
DrawTextBasic(dpi, screenPos, STR_MAX_NEGATIVE_VERTICAL_G, ft);
|
2024-04-14 18:37:01 +02:00
|
|
|
screenPos.y += kListRowHeight;
|
2018-05-25 23:01:27 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
// Maximum lateral Gs
|
|
|
|
ft = Formatter();
|
|
|
|
ft.Add<int32_t>(_loadedTrackDesign->max_lateral_g * 32);
|
|
|
|
DrawTextBasic(dpi, screenPos, STR_MAX_LATERAL_G, ft);
|
2024-04-14 18:37:01 +02:00
|
|
|
screenPos.y += kListRowHeight;
|
2017-06-06 23:24:18 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
if (_loadedTrackDesign->total_air_time != 0)
|
|
|
|
{
|
|
|
|
// Total air time
|
|
|
|
ft = Formatter();
|
|
|
|
ft.Add<int32_t>(_loadedTrackDesign->total_air_time * 25);
|
|
|
|
DrawTextBasic(dpi, screenPos, STR_TOTAL_AIR_TIME, ft);
|
2024-04-14 18:37:01 +02:00
|
|
|
screenPos.y += kListRowHeight;
|
2024-03-10 14:52:35 +01:00
|
|
|
}
|
|
|
|
}
|
2017-06-06 23:24:18 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
if (GetRideTypeDescriptor(_loadedTrackDesign->type).HasFlag(RIDE_TYPE_FLAG_HAS_DROPS))
|
2021-10-14 16:35:40 +02:00
|
|
|
{
|
2024-03-10 14:52:35 +01:00
|
|
|
// Drops
|
2021-10-14 16:35:40 +02:00
|
|
|
ft = Formatter();
|
2024-03-10 14:52:35 +01:00
|
|
|
ft.Add<uint16_t>(_loadedTrackDesign->drops & 0x3F);
|
|
|
|
DrawTextBasic(dpi, screenPos, STR_DROPS, ft);
|
2024-04-14 18:37:01 +02:00
|
|
|
screenPos.y += kListRowHeight;
|
2024-03-10 14:52:35 +01:00
|
|
|
|
|
|
|
// Drop height is multiplied by 0.75
|
|
|
|
ft = Formatter();
|
|
|
|
ft.Add<uint16_t>((_loadedTrackDesign->highest_drop_height * 3) / 4);
|
|
|
|
DrawTextBasic(dpi, screenPos, STR_HIGHEST_DROP_HEIGHT, ft);
|
2024-04-14 18:37:01 +02:00
|
|
|
screenPos.y += kListRowHeight;
|
2021-10-14 16:35:40 +02:00
|
|
|
}
|
2024-03-10 14:52:35 +01:00
|
|
|
|
|
|
|
if (_loadedTrackDesign->type != RIDE_TYPE_MINI_GOLF)
|
|
|
|
{
|
|
|
|
uint16_t inversions = _loadedTrackDesign->inversions & 0x1F;
|
|
|
|
if (inversions != 0)
|
|
|
|
{
|
|
|
|
ft = Formatter();
|
|
|
|
ft.Add<uint16_t>(inversions);
|
|
|
|
// Inversions
|
|
|
|
DrawTextBasic(dpi, screenPos, STR_INVERSIONS, ft);
|
2024-04-14 18:37:01 +02:00
|
|
|
screenPos.y += kListRowHeight;
|
2024-03-10 14:52:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
screenPos.y += 4;
|
2021-10-14 16:35:40 +02:00
|
|
|
}
|
2017-06-06 23:24:18 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
if (_loadedTrackDesign->space_required_x != 0xFF)
|
2018-05-25 23:01:27 +02:00
|
|
|
{
|
2024-03-10 14:52:35 +01:00
|
|
|
// Space required
|
2021-10-14 16:35:40 +02:00
|
|
|
ft = Formatter();
|
2024-03-10 14:52:35 +01:00
|
|
|
ft.Add<uint16_t>(_loadedTrackDesign->space_required_x);
|
|
|
|
ft.Add<uint16_t>(_loadedTrackDesign->space_required_y);
|
|
|
|
DrawTextBasic(dpi, screenPos, STR_TRACK_LIST_SPACE_REQUIRED, ft);
|
2024-04-14 18:37:01 +02:00
|
|
|
screenPos.y += kListRowHeight;
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2021-10-14 16:35:40 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
if (_loadedTrackDesign->cost != 0)
|
2021-10-14 16:35:40 +02:00
|
|
|
{
|
2024-03-10 14:52:35 +01:00
|
|
|
ft = Formatter();
|
|
|
|
ft.Add<uint32_t>(_loadedTrackDesign->cost);
|
|
|
|
DrawTextBasic(dpi, screenPos, STR_TRACK_LIST_COST_AROUND, ft);
|
2021-10-14 16:35:40 +02:00
|
|
|
}
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
void OnScrollDraw(const int32_t scrollIndex, DrawPixelInfo& dpi) override
|
2018-05-25 23:01:27 +02:00
|
|
|
{
|
2024-03-10 14:52:35 +01:00
|
|
|
uint8_t paletteIndex = ColourMapA[colours[0]].mid_light;
|
2024-03-10 16:00:08 +01:00
|
|
|
GfxClear(dpi, paletteIndex);
|
2018-05-25 23:01:27 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
auto screenCoords = ScreenCoordsXY{ 0, 0 };
|
|
|
|
size_t listIndex = 0;
|
|
|
|
if (gScreenFlags & SCREEN_FLAGS_TRACK_MANAGER)
|
2017-11-23 11:57:49 +01:00
|
|
|
{
|
2024-03-10 14:52:35 +01:00
|
|
|
if (_trackDesigns.empty())
|
|
|
|
{
|
|
|
|
// No track designs
|
|
|
|
DrawTextBasic(dpi, screenCoords - ScreenCoordsXY{ 0, 1 }, STR_NO_TRACK_DESIGNS_OF_THIS_TYPE);
|
|
|
|
return;
|
|
|
|
}
|
2017-11-23 11:57:49 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-03-10 14:52:35 +01:00
|
|
|
// Build custom track item
|
2022-07-31 14:22:58 +02:00
|
|
|
StringId stringId;
|
2021-10-14 16:35:40 +02:00
|
|
|
if (listIndex == static_cast<size_t>(selected_list_item))
|
|
|
|
{
|
|
|
|
// Highlight
|
2023-01-16 14:50:43 +01:00
|
|
|
GfxFilterRect(
|
2024-04-14 19:27:32 +02:00
|
|
|
dpi, { screenCoords, { width, screenCoords.y + SCROLLABLE_ROW_HEIGHT - 1 } },
|
2021-10-14 16:35:40 +02:00
|
|
|
FilterPaletteID::PaletteDarken1);
|
|
|
|
stringId = STR_WINDOW_COLOUR_2_STRINGID;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
stringId = STR_BLACK_STRING;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto ft = Formatter();
|
2024-03-10 14:52:35 +01:00
|
|
|
ft.Add<StringId>(STR_BUILD_CUSTOM_DESIGN);
|
2023-02-24 22:05:07 +01:00
|
|
|
DrawTextBasic(dpi, screenCoords - ScreenCoordsXY{ 0, 1 }, stringId, ft);
|
2024-04-14 19:27:32 +02:00
|
|
|
screenCoords.y += SCROLLABLE_ROW_HEIGHT;
|
2024-03-10 14:52:35 +01:00
|
|
|
listIndex++;
|
2021-10-14 16:35:40 +02:00
|
|
|
}
|
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
for (auto i : _filteredTrackIds)
|
|
|
|
{
|
2024-04-14 19:27:32 +02:00
|
|
|
if (screenCoords.y + SCROLLABLE_ROW_HEIGHT >= dpi.y && screenCoords.y < dpi.y + dpi.height)
|
2024-03-10 14:52:35 +01:00
|
|
|
{
|
|
|
|
StringId stringId;
|
|
|
|
if (listIndex == static_cast<size_t>(selected_list_item))
|
|
|
|
{
|
|
|
|
// Highlight
|
|
|
|
GfxFilterRect(
|
2024-04-14 19:27:32 +02:00
|
|
|
dpi, { screenCoords, { width, screenCoords.y + SCROLLABLE_ROW_HEIGHT - 1 } },
|
2024-03-10 14:52:35 +01:00
|
|
|
FilterPaletteID::PaletteDarken1);
|
|
|
|
stringId = STR_WINDOW_COLOUR_2_STRINGID;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
stringId = STR_BLACK_STRING;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw track name
|
|
|
|
auto ft = Formatter();
|
|
|
|
ft.Add<StringId>(STR_TRACK_LIST_NAME_FORMAT);
|
|
|
|
ft.Add<const utf8*>(_trackDesigns[i].name.c_str());
|
|
|
|
DrawTextBasic(dpi, screenCoords - ScreenCoordsXY{ 0, 1 }, stringId, ft);
|
|
|
|
}
|
|
|
|
|
2024-04-14 19:27:32 +02:00
|
|
|
screenCoords.y += SCROLLABLE_ROW_HEIGHT;
|
2024-03-10 14:52:35 +01:00
|
|
|
listIndex++;
|
|
|
|
}
|
2019-08-03 19:55:24 +02:00
|
|
|
}
|
2017-11-23 11:57:49 +01:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
void OnResize() override
|
|
|
|
{
|
|
|
|
ResizeFrame();
|
|
|
|
}
|
2023-05-19 10:17:38 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
void SetIsBeingUpdated(const bool beingUpdated)
|
|
|
|
{
|
|
|
|
_selectedItemIsBeingUpdated = beingUpdated;
|
|
|
|
}
|
2023-07-19 09:02:31 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
void ReloadTrackDesigns()
|
|
|
|
{
|
|
|
|
_reloadTrackDesigns = true;
|
|
|
|
}
|
|
|
|
};
|
2016-04-30 14:27:12 +02:00
|
|
|
|
2024-03-17 07:37:46 +01:00
|
|
|
WindowBase* TrackListOpen(const RideSelection item)
|
2018-06-22 23:21:44 +02:00
|
|
|
{
|
2024-03-10 14:52:35 +01:00
|
|
|
WindowCloseConstructionWindows();
|
|
|
|
ScreenCoordsXY screenPos{};
|
|
|
|
if (gScreenFlags & SCREEN_FLAGS_TRACK_MANAGER)
|
|
|
|
{
|
|
|
|
int32_t screenWidth = ContextGetWidth();
|
|
|
|
int32_t screenHeight = ContextGetHeight();
|
2024-04-14 19:41:28 +02:00
|
|
|
screenPos = { screenWidth / 2 - 300, std::max(kTopToolbarHeight + 1, screenHeight / 2 - 200) };
|
2024-03-10 14:52:35 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-04-14 19:41:28 +02:00
|
|
|
screenPos = { 0, kTopToolbarHeight + 2 };
|
2024-03-10 14:52:35 +01:00
|
|
|
}
|
|
|
|
return WindowCreate<TrackListWindow>(WindowClass::TrackDesignList, WW, WH, 0, item);
|
2021-10-14 16:35:40 +02:00
|
|
|
}
|
2023-07-19 09:02:31 +02:00
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
void WindowTrackDesignListReloadTracks()
|
2023-07-19 09:02:31 +02:00
|
|
|
{
|
2024-03-10 14:52:35 +01:00
|
|
|
auto* trackListWindow = static_cast<TrackListWindow*>(WindowFindByClass(WindowClass::TrackDesignList));
|
|
|
|
if (trackListWindow != nullptr)
|
|
|
|
{
|
|
|
|
trackListWindow->ReloadTrackDesigns();
|
|
|
|
}
|
2023-07-19 09:02:31 +02:00
|
|
|
}
|
|
|
|
|
2024-03-10 14:52:35 +01:00
|
|
|
void WindowTrackDesignListSetBeingUpdated(const bool beingUpdated)
|
2023-07-19 09:02:31 +02:00
|
|
|
{
|
2024-03-10 14:52:35 +01:00
|
|
|
auto* trackListWindow = static_cast<TrackListWindow*>(WindowFindByClass(WindowClass::TrackDesignList));
|
|
|
|
if (trackListWindow != nullptr)
|
|
|
|
{
|
|
|
|
trackListWindow->SetIsBeingUpdated(beingUpdated);
|
|
|
|
}
|
2023-07-19 09:02:31 +02:00
|
|
|
}
|
2024-03-10 14:52:35 +01:00
|
|
|
} // namespace OpenRCT2::Ui::Windows
|