OpenRCT2/src/openrct2-ui/windows/ClearScenery.cpp

241 lines
8.4 KiB
C++
Raw Normal View History

2014-04-18 20:51:18 +02:00
/*****************************************************************************
2020-07-21 15:04:34 +02:00
* Copyright (c) 2014-2020 OpenRCT2 developers
2014-04-18 20:51:18 +02:00
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
2014-04-18 20:51:18 +02:00
*
* OpenRCT2 is licensed under the GNU General Public License version 3.
2014-04-18 20:51:18 +02:00
*****************************************************************************/
#include <algorithm>
2018-06-22 23:21:44 +02:00
#include <openrct2-ui/interface/LandTool.h>
#include <openrct2-ui/interface/Widget.h>
2017-08-12 23:06:12 +02:00
#include <openrct2-ui/windows/Window.h>
2018-06-22 23:21:44 +02:00
#include <openrct2/Context.h>
2018-01-06 18:32:25 +01:00
#include <openrct2/localisation/Localisation.h>
#include <openrct2/world/Park.h>
2018-01-11 10:59:26 +01:00
#include <openrct2/world/Scenery.h>
2014-04-18 20:51:18 +02:00
// clang-format off
enum WINDOW_CLEAR_SCENERY_WIDGET_IDX {
WIDX_BACKGROUND,
WIDX_TITLE,
WIDX_CLOSE,
WIDX_PREVIEW,
WIDX_DECREMENT,
WIDX_INCREMENT,
WIDX_SMALL_SCENERY,
WIDX_LARGE_SCENERY,
WIDX_FOOTPATH
2014-04-18 20:51:18 +02:00
};
2020-05-05 22:26:14 +02:00
static constexpr const rct_string_id WINDOW_TITLE = STR_CLEAR_SCENERY;
2020-05-09 18:02:16 +02:00
static constexpr const int32_t WW = 98;
static constexpr const int32_t WH = 94;
static rct_widget window_clear_scenery_widgets[] = {
2020-05-09 16:44:21 +02:00
WINDOW_SHIM(WINDOW_TITLE, WW, WH),
MakeWidget ({27, 17}, {44, 32}, WindowWidgetType::ImgBtn, WindowColour::Primary , SPR_LAND_TOOL_SIZE_0, STR_NONE), // preview box
MakeRemapWidget({28, 18}, {16, 16}, WindowWidgetType::TrnBtn, WindowColour::Secondary, SPR_LAND_TOOL_DECREASE, STR_ADJUST_SMALLER_LAND_TIP), // decrement size
MakeRemapWidget({54, 32}, {16, 16}, WindowWidgetType::TrnBtn, WindowColour::Secondary, SPR_LAND_TOOL_INCREASE, STR_ADJUST_LARGER_LAND_TIP), // increment size
MakeRemapWidget({ 7, 53}, {24, 24}, WindowWidgetType::FlatBtn, WindowColour::Secondary, SPR_G2_BUTTON_TREES, STR_CLEAR_SCENERY_REMOVE_SMALL_SCENERY_TIP), // small scenery
MakeRemapWidget({37, 53}, {24, 24}, WindowWidgetType::FlatBtn, WindowColour::Secondary, SPR_G2_BUTTON_LARGE_SCENERY, STR_CLEAR_SCENERY_REMOVE_LARGE_SCENERY_TIP), // large scenery
MakeRemapWidget({67, 53}, {24, 24}, WindowWidgetType::FlatBtn, WindowColour::Secondary, SPR_G2_BUTTON_FOOTPATH, STR_CLEAR_SCENERY_REMOVE_FOOTPATHS_TIP), // footpaths
{ WIDGETS_END },
2014-04-18 20:51:18 +02:00
};
static void window_clear_scenery_close(rct_window *w);
2017-05-01 15:41:45 +02:00
static void window_clear_scenery_mouseup(rct_window *w, rct_widgetindex widgetIndex);
2017-07-14 19:20:42 +02:00
static void window_clear_scenery_mousedown(rct_window *w, rct_widgetindex widgetIndex, rct_widget *widget);
static void window_clear_scenery_update(rct_window *w);
static void window_clear_scenery_invalidate(rct_window *w);
static void window_clear_scenery_paint(rct_window *w, rct_drawpixelinfo *dpi);
2017-05-01 15:41:45 +02:00
static void window_clear_scenery_textinput(rct_window *w, rct_widgetindex widgetIndex, char *text);
static void window_clear_scenery_inputsize(rct_window *w);
2014-04-18 20:51:18 +02:00
static rct_window_event_list window_clear_scenery_events([](auto& events)
{
events.close = &window_clear_scenery_close;
events.mouse_up = &window_clear_scenery_mouseup;
events.mouse_down = &window_clear_scenery_mousedown;
events.update = &window_clear_scenery_update;
events.text_input = &window_clear_scenery_textinput;
events.invalidate = &window_clear_scenery_invalidate;
events.paint = &window_clear_scenery_paint;
});
// clang-format on
2014-04-18 20:51:18 +02:00
/**
2015-10-20 20:16:30 +02:00
*
2014-04-18 20:51:18 +02:00
* rct2: 0x0068E0A7
*/
2018-06-22 23:21:44 +02:00
rct_window* window_clear_scenery_open()
2014-04-18 20:51:18 +02:00
{
rct_window* window;
2014-04-18 20:51:18 +02:00
// Check if window is already open
2017-08-12 23:06:12 +02:00
window = window_find_by_class(WC_CLEAR_SCENERY);
2017-08-15 10:07:44 +02:00
if (window != nullptr)
2017-08-12 23:06:12 +02:00
return window;
2014-04-18 20:51:18 +02:00
window = WindowCreate(
2020-05-09 18:02:16 +02:00
ScreenCoordsXY(context_get_width() - WW, 29), WW, WH, &window_clear_scenery_events, WC_CLEAR_SCENERY, 0);
window->widgets = window_clear_scenery_widgets;
window->enabled_widgets = (1ULL << WIDX_CLOSE) | (1ULL << WIDX_INCREMENT) | (1ULL << WIDX_DECREMENT)
| (1ULL << WIDX_PREVIEW) | (1ULL << WIDX_SMALL_SCENERY) | (1ULL << WIDX_LARGE_SCENERY) | (1ULL << WIDX_FOOTPATH);
window->hold_down_widgets = (1ULL << WIDX_INCREMENT) | (1ULL << WIDX_DECREMENT);
WindowInitScrollWidgets(window);
window_push_others_below(window);
2014-04-18 20:51:18 +02:00
2017-06-22 20:49:13 +02:00
gLandToolSize = 2;
2021-07-27 17:59:49 +02:00
gClearSceneryCost = MONEY64_UNDEFINED;
gClearSmallScenery = true;
gClearLargeScenery = false;
gClearFootpath = false;
2017-08-12 23:06:12 +02:00
return window;
2014-04-18 20:51:18 +02:00
}
/**
*
* rct2: 0x006E6B65
*/
2018-06-22 23:21:44 +02:00
static void window_clear_scenery_close([[maybe_unused]] rct_window* w)
2014-04-18 20:51:18 +02:00
{
// If the tool wasn't changed, turn tool off
if (clear_scenery_tool_is_active())
tool_cancel();
2014-04-18 20:51:18 +02:00
}
/**
*
* rct2: 0x0068E185
*/
2018-06-22 23:21:44 +02:00
static void window_clear_scenery_mouseup(rct_window* w, rct_widgetindex widgetIndex)
2014-04-18 20:51:18 +02:00
{
2018-06-22 23:21:44 +02:00
switch (widgetIndex)
{
case WIDX_CLOSE:
window_close(w);
break;
case WIDX_PREVIEW:
window_clear_scenery_inputsize(w);
break;
case WIDX_SMALL_SCENERY:
gClearSmallScenery ^= 1;
w->Invalidate();
2018-06-22 23:21:44 +02:00
break;
case WIDX_LARGE_SCENERY:
gClearLargeScenery ^= 1;
w->Invalidate();
2018-06-22 23:21:44 +02:00
break;
case WIDX_FOOTPATH:
gClearFootpath ^= 1;
w->Invalidate();
2018-06-22 23:21:44 +02:00
break;
}
}
2018-06-22 23:21:44 +02:00
static void window_clear_scenery_mousedown(rct_window* w, rct_widgetindex widgetIndex, [[maybe_unused]] rct_widget* widget)
2017-07-04 01:49:37 +02:00
{
2018-06-22 23:21:44 +02:00
switch (widgetIndex)
{
case WIDX_DECREMENT:
// Decrement land tool size, if it stays within the limit
gLandToolSize = std::max(MINIMUM_TOOL_SIZE, gLandToolSize - 1);
// Invalidate the window
w->Invalidate();
2018-06-22 23:21:44 +02:00
break;
case WIDX_INCREMENT:
// Increment land tool size, if it stays within the limit
gLandToolSize = std::min(MAXIMUM_TOOL_SIZE, gLandToolSize + 1);
// Invalidate the window
w->Invalidate();
2018-06-22 23:21:44 +02:00
break;
2017-07-04 01:49:37 +02:00
}
}
2018-06-22 23:21:44 +02:00
static void window_clear_scenery_textinput(rct_window* w, rct_widgetindex widgetIndex, char* text)
{
int32_t size;
char* end;
2017-08-15 10:07:44 +02:00
if (widgetIndex != WIDX_PREVIEW || text == nullptr)
return;
size = strtol(text, &end, 10);
2018-06-22 23:21:44 +02:00
if (*end == '\0')
{
size = std::max(MINIMUM_TOOL_SIZE, size);
size = std::min(MAXIMUM_TOOL_SIZE, size);
gLandToolSize = size;
w->Invalidate();
}
2014-04-18 20:51:18 +02:00
}
2018-06-22 23:21:44 +02:00
static void window_clear_scenery_inputsize(rct_window* w)
{
Formatter ft;
ft.Add<int16_t>(MINIMUM_TOOL_SIZE);
ft.Add<int16_t>(MAXIMUM_TOOL_SIZE);
window_text_input_open(w, WIDX_PREVIEW, STR_SELECTION_SIZE, STR_ENTER_SELECTION_SIZE, ft, STR_NONE, STR_NONE, 3);
}
2014-04-18 20:51:18 +02:00
/**
*
* rct2: 0x0068E205
*/
2018-06-22 23:21:44 +02:00
static void window_clear_scenery_update(rct_window* w)
2014-04-18 20:51:18 +02:00
{
2017-07-04 01:49:37 +02:00
w->frame_no++;
// Close window if another tool is open
if (!clear_scenery_tool_is_active())
window_close(w);
2014-04-18 20:51:18 +02:00
}
/**
*
* rct2: 0x0068E115
*/
2018-06-22 23:21:44 +02:00
static void window_clear_scenery_invalidate(rct_window* w)
2014-04-18 20:51:18 +02:00
{
// Set the preview image button to be pressed down
w->pressed_widgets = (1ULL << WIDX_PREVIEW) | (gClearSmallScenery ? (1ULL << WIDX_SMALL_SCENERY) : 0)
| (gClearLargeScenery ? (1ULL << WIDX_LARGE_SCENERY) : 0) | (gClearFootpath ? (1ULL << WIDX_FOOTPATH) : 0);
// Update the preview image (for tool sizes up to 7)
window_clear_scenery_widgets[WIDX_PREVIEW].image = LandTool::SizeToSpriteIndex(gLandToolSize);
2014-04-18 20:51:18 +02:00
}
/**
*
* rct2: 0x0068E130
*/
2018-06-22 23:21:44 +02:00
static void window_clear_scenery_paint(rct_window* w, rct_drawpixelinfo* dpi)
2014-04-18 20:51:18 +02:00
{
WindowDrawWidgets(w, dpi);
// Draw number for tool sizes bigger than 7
ScreenCoordsXY screenCoords = { w->windowPos.x + window_clear_scenery_widgets[WIDX_PREVIEW].midX(),
w->windowPos.y + window_clear_scenery_widgets[WIDX_PREVIEW].midY() };
2018-06-22 23:21:44 +02:00
if (gLandToolSize > MAX_TOOL_SIZE_WITH_SPRITE)
{
auto ft = Formatter();
ft.Add<uint16_t>(gLandToolSize);
DrawTextBasic(dpi, screenCoords - ScreenCoordsXY{ 0, 2 }, STR_LAND_TOOL_SIZE_VALUE, ft, { TextAlignment::CENTRE });
}
// Draw cost amount
2021-07-27 17:59:49 +02:00
if (gClearSceneryCost != MONEY64_UNDEFINED && gClearSceneryCost != 0 && !(gParkFlags & PARK_FLAGS_NO_MONEY))
2018-06-22 23:21:44 +02:00
{
2021-07-27 17:59:49 +02:00
auto ft = Formatter();
ft.Add<money64>(gClearSceneryCost);
screenCoords.x = window_clear_scenery_widgets[WIDX_PREVIEW].midX() + w->windowPos.x;
screenCoords.y = window_clear_scenery_widgets[WIDX_PREVIEW].bottom + w->windowPos.y + 5 + 27;
2021-07-27 17:59:49 +02:00
DrawTextBasic(dpi, screenCoords, STR_COST_AMOUNT, ft, { TextAlignment::CENTRE });
}
2014-04-18 20:51:18 +02:00
}