2015-05-15 17:28:27 +02:00
/*****************************************************************************
2020-07-21 15:04:34 +02:00
* Copyright ( c ) 2014 - 2020 OpenRCT2 developers
2015-05-15 17:28:27 +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
2015-05-15 17:28:27 +02:00
*
2018-06-15 14:07:34 +02:00
* OpenRCT2 is licensed under the GNU General Public License version 3.
2015-05-15 17:28:27 +02:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2018-08-12 13:50:40 +02:00
# include <algorithm>
2018-06-22 23:21:44 +02:00
# include <openrct2-ui/interface/LandTool.h>
# include <openrct2-ui/interface/Viewport.h>
# include <openrct2-ui/interface/Widget.h>
2017-08-06 21:20:05 +02:00
# include <openrct2-ui/windows/Window.h>
2018-06-22 23:21:44 +02:00
# include <openrct2/Context.h>
2017-11-30 18:17:06 +01:00
# include <openrct2/Game.h>
2017-12-12 14:52:57 +01:00
# include <openrct2/Input.h>
2019-03-17 09:25:51 +01:00
# include <openrct2/actions/LandBuyRightsAction.hpp>
2018-03-19 23:28:40 +01:00
# include <openrct2/drawing/Drawing.h>
2018-06-22 23:21:44 +02:00
# include <openrct2/localisation/Localisation.h>
2018-03-19 23:28:40 +01:00
# include <openrct2/world/Park.h>
2015-05-15 17:28:27 +02:00
2020-05-05 22:26:14 +02:00
static constexpr const rct_string_id WINDOW_TITLE = STR_LAND_RIGHTS ;
static constexpr const int32_t WH = 94 ;
static constexpr const int32_t WW = 98 ;
2019-10-19 04:02:31 +02:00
2018-05-16 20:41:29 +02:00
// clang-format off
2015-05-15 17:28:27 +02:00
enum WINDOW_WATER_WIDGET_IDX {
2017-06-06 23:24:18 +02:00
WIDX_BACKGROUND ,
WIDX_TITLE ,
WIDX_CLOSE ,
WIDX_PREVIEW ,
WIDX_DECREMENT ,
WIDX_INCREMENT ,
WIDX_BUY_LAND_RIGHTS ,
WIDX_BUY_CONSTRUCTION_RIGHTS
2015-05-15 17:28:27 +02:00
} ;
2017-05-02 02:01:29 +02:00
2015-05-15 17:28:27 +02:00
static rct_widget window_land_rights_widgets [ ] = {
2020-05-09 16:44:21 +02:00
WINDOW_SHIM ( WINDOW_TITLE , WW , WH ) ,
2020-11-27 04:14:20 +01:00
MakeWidget ( { 27 , 17 } , { 44 , 32 } , WindowWidgetType : : ImgBtn , WindowColour : : Primary , SPR_LAND_TOOL_SIZE_0 ) , // preview box
MakeRemapWidget ( { 28 , 18 } , { 16 , 16 } , WindowWidgetType : : TrnBtn , WindowColour : : Tertiary , SPR_LAND_TOOL_DECREASE , STR_ADJUST_SMALLER_LAND_RIGHTS_TIP ) , // decrement size
MakeRemapWidget ( { 54 , 32 } , { 16 , 16 } , WindowWidgetType : : TrnBtn , WindowColour : : Tertiary , SPR_LAND_TOOL_INCREASE , STR_ADJUST_LARGER_LAND_RIGHTS_TIP ) , // increment size
MakeRemapWidget ( { 22 , 53 } , { 24 , 24 } , WindowWidgetType : : FlatBtn , WindowColour : : Tertiary , SPR_BUY_LAND_RIGHTS , STR_BUY_LAND_RIGHTS_TIP ) , // land rights
MakeRemapWidget ( { 52 , 53 } , { 24 , 24 } , WindowWidgetType : : FlatBtn , WindowColour : : Tertiary , SPR_BUY_CONSTRUCTION_RIGHTS , STR_BUY_CONSTRUCTION_RIGHTS_TIP ) , // construction rights
2017-06-06 23:24:18 +02:00
{ WIDGETS_END } ,
2015-05-15 17:28:27 +02:00
} ;
2015-07-10 02:39:16 +02:00
static void window_land_rights_close ( rct_window * w ) ;
2017-05-01 15:41:45 +02:00
static void window_land_rights_mouseup ( rct_window * w , rct_widgetindex widgetIndex ) ;
2017-07-14 19:20:42 +02:00
static void window_land_rights_mousedown ( rct_window * w , rct_widgetindex widgetIndex , rct_widget * widget ) ;
2015-07-10 02:39:16 +02:00
static void window_land_rights_update ( rct_window * w ) ;
static void window_land_rights_invalidate ( rct_window * w ) ;
static void window_land_rights_paint ( rct_window * w , rct_drawpixelinfo * dpi ) ;
2017-05-01 15:41:45 +02:00
static void window_land_rights_textinput ( rct_window * w , rct_widgetindex widgetIndex , char * text ) ;
2015-05-15 17:28:27 +02:00
static void window_land_rights_inputsize ( rct_window * w ) ;
2020-02-29 03:43:29 +01:00
static void window_land_rights_toolupdate ( rct_window * w , rct_widgetindex widgetIndex , const ScreenCoordsXY & screenCoords ) ;
static void window_land_rights_tooldown ( rct_window * w , rct_widgetindex widgetIndex , const ScreenCoordsXY & screenCoords ) ;
static void window_land_rights_tooldrag ( rct_window * w , rct_widgetindex widgetIndex , const ScreenCoordsXY & screenCoords ) ;
2017-06-26 20:01:35 +02:00
static void window_land_rights_toolabort ( rct_window * w , rct_widgetindex widgetIndex ) ;
static bool land_rights_tool_is_active ( ) ;
2015-05-15 17:28:27 +02:00
2020-09-28 20:36:15 +02:00
static rct_window_event_list window_land_rights_events ( [ ] ( auto & events )
{
events . close = & window_land_rights_close ;
events . mouse_up = & window_land_rights_mouseup ;
events . mouse_down = & window_land_rights_mousedown ;
events . update = & window_land_rights_update ;
events . tool_update = & window_land_rights_toolupdate ;
events . tool_down = & window_land_rights_tooldown ;
events . tool_drag = & window_land_rights_tooldrag ;
events . tool_abort = & window_land_rights_toolabort ;
events . text_input = & window_land_rights_textinput ;
events . invalidate = & window_land_rights_invalidate ;
events . paint = & window_land_rights_paint ;
} ) ;
2018-05-16 20:41:29 +02:00
// clang-format on
2015-05-15 17:28:27 +02:00
2019-10-24 05:38:13 +02:00
constexpr uint8_t LAND_RIGHTS_MODE_BUY_CONSTRUCTION_RIGHTS = 0 ;
constexpr uint8_t LAND_RIGHTS_MODE_BUY_LAND = 1 ;
2017-06-26 20:01:35 +02:00
2018-06-20 17:28:51 +02:00
static uint8_t _landRightsMode ;
2017-06-26 20:01:35 +02:00
static money32 _landRightsCost ;
2018-06-22 23:21:44 +02:00
rct_window * window_land_rights_open ( )
2015-05-15 17:28:27 +02:00
{
2017-06-06 23:24:18 +02:00
rct_window * window ;
// Check if window is already open
2017-08-06 05:22:00 +02:00
window = window_find_by_class ( WC_LAND_RIGHTS ) ;
2017-08-15 10:07:44 +02:00
if ( window ! = nullptr )
2017-08-06 05:22:00 +02:00
return window ;
2017-06-26 20:59:52 +02:00
2020-11-04 05:52:23 +01:00
window = WindowCreate ( ScreenCoordsXY ( context_get_width ( ) - 98 , 29 ) , 98 , 94 , & window_land_rights_events , WC_LAND_RIGHTS , 0 ) ;
2017-06-06 23:24:18 +02:00
window - > widgets = window_land_rights_widgets ;
2018-06-22 23:21:44 +02:00
window - > enabled_widgets = ( 1 < < WIDX_CLOSE ) | ( 1 < < WIDX_DECREMENT ) | ( 1 < < WIDX_INCREMENT ) | ( 1 < < WIDX_PREVIEW )
| ( 1 < < WIDX_BUY_LAND_RIGHTS ) | ( 1 < < WIDX_BUY_CONSTRUCTION_RIGHTS ) ;
2017-07-04 01:49:37 +02:00
window - > hold_down_widgets = ( 1 < < WIDX_INCREMENT ) | ( 1 < < WIDX_DECREMENT ) ;
2020-11-04 05:52:23 +01:00
WindowInitScrollWidgets ( window ) ;
2017-06-06 23:24:18 +02:00
window_push_others_below ( window ) ;
2017-06-26 20:01:35 +02:00
_landRightsMode = LAND_RIGHTS_MODE_BUY_LAND ;
2017-06-06 23:24:18 +02:00
window - > pressed_widgets = ( 1 < < WIDX_BUY_LAND_RIGHTS ) ;
2017-06-22 20:49:13 +02:00
gLandToolSize = 1 ;
2017-06-06 23:24:18 +02:00
2017-06-26 20:01:35 +02:00
show_gridlines ( ) ;
tool_set ( window , WIDX_BUY_LAND_RIGHTS , TOOL_UP_ARROW ) ;
input_set_flag ( INPUT_FLAG_6 , true ) ;
2017-06-26 20:59:52 +02:00
2017-06-06 23:24:18 +02:00
show_land_rights ( ) ;
2018-06-22 23:21:44 +02:00
if ( gLandRemainingConstructionSales = = 0 )
{
2017-06-06 23:24:18 +02:00
show_construction_rights ( ) ;
}
2017-08-06 05:22:00 +02:00
return window ;
2015-05-15 17:28:27 +02:00
}
2018-06-22 23:21:44 +02:00
static void window_land_rights_close ( rct_window * w )
2015-05-15 17:28:27 +02:00
{
2018-06-22 23:21:44 +02:00
if ( gLandRemainingConstructionSales = = 0 )
{
2017-06-06 23:24:18 +02:00
hide_construction_rights ( ) ;
}
// If the tool wasn't changed, turn tool off
if ( land_rights_tool_is_active ( ) )
tool_cancel ( ) ;
2015-05-15 17:28:27 +02:00
}
2018-06-22 23:21:44 +02:00
static void window_land_rights_mouseup ( rct_window * w , rct_widgetindex widgetIndex )
2015-05-15 17:28:27 +02:00
{
2018-06-22 23:21:44 +02:00
switch ( widgetIndex )
{
case WIDX_CLOSE :
window_close ( w ) ;
break ;
case WIDX_PREVIEW :
window_land_rights_inputsize ( w ) ;
break ;
case WIDX_BUY_LAND_RIGHTS :
if ( _landRightsMode ! = LAND_RIGHTS_MODE_BUY_LAND )
{
tool_set ( w , WIDX_BUY_LAND_RIGHTS , TOOL_UP_ARROW ) ;
_landRightsMode = LAND_RIGHTS_MODE_BUY_LAND ;
show_land_rights ( ) ;
2019-06-15 17:20:16 +02:00
w - > Invalidate ( ) ;
2018-06-22 23:21:44 +02:00
}
break ;
case WIDX_BUY_CONSTRUCTION_RIGHTS :
if ( _landRightsMode ! = LAND_RIGHTS_MODE_BUY_CONSTRUCTION_RIGHTS )
{
tool_set ( w , WIDX_BUY_CONSTRUCTION_RIGHTS , TOOL_UP_ARROW ) ;
_landRightsMode = LAND_RIGHTS_MODE_BUY_CONSTRUCTION_RIGHTS ;
show_construction_rights ( ) ;
2019-06-15 17:20:16 +02:00
w - > Invalidate ( ) ;
2018-06-22 23:21:44 +02:00
}
break ;
2017-06-06 23:24:18 +02:00
}
2015-05-15 17:28:27 +02:00
}
2018-06-22 23:21:44 +02:00
static void window_land_rights_mousedown ( rct_window * w , rct_widgetindex widgetIndex , 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 rights tool size
gLandToolSize = std : : max ( MINIMUM_TOOL_SIZE , gLandToolSize - 1 ) ;
2017-07-04 01:49:37 +02:00
2018-06-22 23:21:44 +02:00
// Invalidate the window
2019-06-15 17:20:16 +02:00
w - > Invalidate ( ) ;
2018-06-22 23:21:44 +02:00
break ;
case WIDX_INCREMENT :
// Decrement land rights tool size
gLandToolSize = std : : min ( MAXIMUM_TOOL_SIZE , gLandToolSize + 1 ) ;
2017-07-04 01:49:37 +02:00
2018-06-22 23:21:44 +02:00
// Invalidate the window
2019-06-15 17:20:16 +02:00
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_land_rights_textinput ( rct_window * w , rct_widgetindex widgetIndex , char * text )
2015-05-15 17:28:27 +02:00
{
2018-06-20 17:28:51 +02:00
int32_t size ;
2017-06-06 23:24:18 +02:00
char * end ;
2017-08-15 10:07:44 +02:00
if ( widgetIndex ! = WIDX_PREVIEW | | text = = nullptr )
2017-06-06 23:24:18 +02:00
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 ) ;
2017-06-06 23:24:18 +02:00
gLandToolSize = size ;
2019-06-15 17:20:16 +02:00
w - > Invalidate ( ) ;
2017-06-06 23:24:18 +02:00
}
2015-05-15 17:28:27 +02:00
}
2018-06-22 23:21:44 +02:00
static void window_land_rights_inputsize ( rct_window * w )
2015-05-15 17:28:27 +02:00
{
2017-06-06 23:24:18 +02:00
TextInputDescriptionArgs [ 0 ] = MINIMUM_TOOL_SIZE ;
TextInputDescriptionArgs [ 1 ] = MAXIMUM_TOOL_SIZE ;
window_text_input_open ( w , WIDX_PREVIEW , STR_SELECTION_SIZE , STR_ENTER_SELECTION_SIZE , STR_NONE , STR_NONE , 3 ) ;
2015-05-15 17:28:27 +02:00
}
2018-06-22 23:21:44 +02:00
static void window_land_rights_update ( rct_window * w )
2015-05-15 17:28:27 +02:00
{
2017-07-04 01:49:37 +02:00
w - > frame_no + + ;
2017-06-06 23:24:18 +02:00
// Close window if another tool is open
if ( ! land_rights_tool_is_active ( ) )
window_close ( w ) ;
2015-05-15 17:28:27 +02:00
}
2018-06-22 23:21:44 +02:00
static void window_land_rights_invalidate ( rct_window * w )
2015-05-15 17:28:27 +02:00
{
2017-06-06 23:24:18 +02:00
// Set the preview image button to be pressed down
2018-06-22 23:21:44 +02:00
w - > pressed_widgets | = ( 1 < < WIDX_PREVIEW )
| ( 1 < < ( ( _landRightsMode = = LAND_RIGHTS_MODE_BUY_LAND ) ? WIDX_BUY_LAND_RIGHTS : WIDX_BUY_CONSTRUCTION_RIGHTS ) ) ;
w - > pressed_widgets & = ~ (
1
< < ( ( _landRightsMode = = LAND_RIGHTS_MODE_BUY_CONSTRUCTION_RIGHTS ) ? WIDX_BUY_LAND_RIGHTS
: WIDX_BUY_CONSTRUCTION_RIGHTS ) ) ;
2017-06-06 23:24:18 +02:00
// Update the preview image
2020-11-03 11:59:00 +01:00
window_land_rights_widgets [ WIDX_PREVIEW ] . image = LandTool : : SizeToSpriteIndex ( gLandToolSize ) ;
2017-06-06 23:24:18 +02:00
// Disable ownership and/or construction buying functions if there are no tiles left for sale
2018-06-22 23:21:44 +02:00
if ( gLandRemainingOwnershipSales = = 0 )
{
2017-06-06 23:24:18 +02:00
w - > disabled_widgets | = ( 1 < < WIDX_BUY_LAND_RIGHTS ) ;
window_land_rights_widgets [ WIDX_BUY_LAND_RIGHTS ] . tooltip = STR_NO_LAND_RIGHTS_FOR_SALE_TIP ;
2018-06-22 23:21:44 +02:00
}
else
{
2017-06-06 23:24:18 +02:00
w - > disabled_widgets & = ~ ( 1 < < WIDX_BUY_LAND_RIGHTS ) ;
window_land_rights_widgets [ WIDX_BUY_LAND_RIGHTS ] . tooltip = STR_BUY_LAND_RIGHTS_TIP ;
}
2018-06-22 23:21:44 +02:00
if ( gLandRemainingConstructionSales = = 0 )
{
2017-06-06 23:24:18 +02:00
w - > disabled_widgets | = ( 1 < < WIDX_BUY_CONSTRUCTION_RIGHTS ) ;
window_land_rights_widgets [ WIDX_BUY_CONSTRUCTION_RIGHTS ] . tooltip = STR_NO_CONSTRUCTION_RIGHTS_FOR_SALE_TIP ;
2018-06-22 23:21:44 +02:00
}
else
{
2017-06-06 23:24:18 +02:00
w - > disabled_widgets & = ~ ( 1 < < WIDX_BUY_CONSTRUCTION_RIGHTS ) ;
window_land_rights_widgets [ WIDX_BUY_CONSTRUCTION_RIGHTS ] . tooltip = STR_BUY_CONSTRUCTION_RIGHTS_TIP ;
}
2015-05-15 17:28:27 +02:00
}
2018-06-22 23:21:44 +02:00
static void window_land_rights_paint ( rct_window * w , rct_drawpixelinfo * dpi )
2015-05-15 17:28:27 +02:00
{
2020-06-25 10:31:15 +02:00
auto screenCoords = ScreenCoordsXY { w - > windowPos . x + window_land_rights_widgets [ WIDX_PREVIEW ] . midX ( ) ,
w - > windowPos . y + window_land_rights_widgets [ WIDX_PREVIEW ] . midY ( ) } ;
2017-06-06 23:24:18 +02:00
2020-11-04 05:52:23 +01:00
WindowDrawWidgets ( w , dpi ) ;
2017-06-06 23:24:18 +02:00
// Draw number for tool sizes bigger than 7
2018-06-22 23:21:44 +02:00
if ( gLandToolSize > MAX_TOOL_SIZE_WITH_SPRITE )
{
2020-05-17 20:29:56 +02:00
gfx_draw_string_centred (
dpi , STR_LAND_TOOL_SIZE_VALUE , screenCoords - ScreenCoordsXY { 0 , 2 } , COLOUR_BLACK , & gLandToolSize ) ;
2017-06-06 23:24:18 +02:00
}
// Draw cost amount
2019-04-20 18:10:15 +02:00
if ( _landRightsCost ! = MONEY32_UNDEFINED & & _landRightsCost ! = 0 & & ! ( gParkFlags & PARK_FLAGS_NO_MONEY ) )
2018-06-22 23:21:44 +02:00
{
2020-06-25 10:31:15 +02:00
screenCoords = { window_land_rights_widgets [ WIDX_PREVIEW ] . midX ( ) + w - > windowPos . x ,
2020-05-17 20:29:56 +02:00
window_land_rights_widgets [ WIDX_PREVIEW ] . bottom + w - > windowPos . y + 32 } ;
gfx_draw_string_centred ( dpi , STR_COST_AMOUNT , screenCoords , COLOUR_BLACK , & _landRightsCost ) ;
2017-06-26 20:01:35 +02:00
}
}
2020-02-29 03:43:29 +01:00
static void window_land_rights_tool_update_land_rights ( const ScreenCoordsXY & screenCoords )
2017-06-26 20:01:35 +02:00
{
map_invalidate_selection_rect ( ) ;
gMapSelectFlags & = ~ MAP_SELECT_FLAG_ENABLE ;
2017-06-26 20:59:52 +02:00
2019-11-29 17:17:01 +01:00
auto mapTile = screen_get_map_xy ( screenCoords , nullptr ) ;
2017-06-26 20:59:52 +02:00
2019-11-29 17:17:01 +01:00
if ( ! mapTile )
2018-06-22 23:21:44 +02:00
{
if ( _landRightsCost ! = MONEY32_UNDEFINED )
{
2017-06-26 20:01:35 +02:00
_landRightsCost = MONEY32_UNDEFINED ;
window_invalidate_by_class ( WC_CLEAR_SCENERY ) ;
}
return ;
}
2017-06-26 20:59:52 +02:00
2018-06-20 17:28:51 +02:00
uint8_t state_changed = 0 ;
2017-06-26 20:59:52 +02:00
2018-06-22 23:21:44 +02:00
if ( ! ( gMapSelectFlags & MAP_SELECT_FLAG_ENABLE ) )
{
2017-06-26 20:01:35 +02:00
gMapSelectFlags | = MAP_SELECT_FLAG_ENABLE ;
state_changed + + ;
}
2017-06-26 20:59:52 +02:00
2018-06-22 23:21:44 +02:00
if ( gMapSelectType ! = MAP_SELECT_TYPE_FULL )
{
2017-06-26 20:01:35 +02:00
gMapSelectType = MAP_SELECT_TYPE_FULL ;
state_changed + + ;
}
2017-06-26 20:59:52 +02:00
2018-06-20 17:28:51 +02:00
int16_t tool_size = gLandToolSize ;
2017-06-26 20:01:35 +02:00
if ( tool_size = = 0 )
tool_size = 1 ;
2017-06-26 20:59:52 +02:00
2018-06-20 17:28:51 +02:00
int16_t tool_length = ( tool_size - 1 ) * 32 ;
2017-06-26 20:59:52 +02:00
2017-06-26 20:01:35 +02:00
// Move to tool bottom left
2019-11-29 17:17:01 +01:00
mapTile - > x - = ( tool_size - 1 ) * 16 ;
mapTile - > y - = ( tool_size - 1 ) * 16 ;
2019-11-30 16:47:23 +01:00
mapTile = mapTile - > ToTileStart ( ) ;
2017-06-26 20:59:52 +02:00
2019-11-29 17:17:01 +01:00
if ( gMapSelectPositionA . x ! = mapTile - > x )
2018-06-22 23:21:44 +02:00
{
2019-11-29 17:17:01 +01:00
gMapSelectPositionA . x = mapTile - > x ;
2017-06-26 20:01:35 +02:00
state_changed + + ;
}
2017-06-26 20:59:52 +02:00
2019-11-29 17:17:01 +01:00
if ( gMapSelectPositionA . y ! = mapTile - > y )
2018-06-22 23:21:44 +02:00
{
2019-11-29 17:17:01 +01:00
gMapSelectPositionA . y = mapTile - > y ;
2017-06-26 20:01:35 +02:00
state_changed + + ;
}
2017-06-26 20:59:52 +02:00
2019-11-29 17:17:01 +01:00
mapTile - > x + = tool_length ;
mapTile - > y + = tool_length ;
2017-06-26 20:59:52 +02:00
2019-11-29 17:17:01 +01:00
if ( gMapSelectPositionB . x ! = mapTile - > x )
2018-06-22 23:21:44 +02:00
{
2019-11-29 17:17:01 +01:00
gMapSelectPositionB . x = mapTile - > x ;
2017-06-26 20:01:35 +02:00
state_changed + + ;
}
2017-06-26 20:59:52 +02:00
2019-11-29 17:17:01 +01:00
if ( gMapSelectPositionB . y ! = mapTile - > y )
2018-06-22 23:21:44 +02:00
{
2019-11-29 17:17:01 +01:00
gMapSelectPositionB . y = mapTile - > y ;
2017-06-26 20:01:35 +02:00
state_changed + + ;
}
2017-06-26 20:59:52 +02:00
2017-06-26 20:01:35 +02:00
map_invalidate_selection_rect ( ) ;
if ( ! state_changed )
return ;
2017-06-26 20:59:52 +02:00
2019-03-17 09:25:51 +01:00
auto landBuyRightsAction = LandBuyRightsAction (
{ gMapSelectPositionA . x , gMapSelectPositionA . y , gMapSelectPositionB . x , gMapSelectPositionB . y } ,
( _landRightsMode = = LAND_RIGHTS_MODE_BUY_LAND ) ? LandBuyRightSetting : : BuyLand
: LandBuyRightSetting : : BuyConstructionRights ) ;
auto res = GameActions : : Query ( & landBuyRightsAction ) ;
2020-10-15 03:04:39 +02:00
_landRightsCost = res - > Error = = GameActions : : Status : : Ok ? res - > Cost : MONEY32_UNDEFINED ;
2017-06-26 20:01:35 +02:00
}
/**
*
* rct2 : 0x0066822A
*/
2018-06-22 23:21:44 +02:00
static void window_land_rights_toolabort ( rct_window * w , rct_widgetindex widgetIndex )
2017-06-26 20:01:35 +02:00
{
hide_gridlines ( ) ;
if ( _landRightsMode = = LAND_RIGHTS_MODE_BUY_LAND )
{
hide_land_rights ( ) ;
2017-06-06 23:24:18 +02:00
}
2017-06-26 20:01:35 +02:00
else
{
hide_construction_rights ( ) ;
}
}
/**
*
* rct2 : 0x006681D1
*/
2020-02-29 03:43:29 +01:00
static void window_land_rights_toolupdate ( rct_window * w , rct_widgetindex widgetIndex , const ScreenCoordsXY & screenCoords )
2017-06-26 20:01:35 +02:00
{
2019-11-14 11:58:54 +01:00
window_land_rights_tool_update_land_rights ( screenCoords ) ;
2017-06-26 20:01:35 +02:00
}
/**
*
* rct2 : 0x006681E6
*/
2020-02-29 03:43:29 +01:00
static void window_land_rights_tooldown ( rct_window * w , rct_widgetindex widgetIndex , const ScreenCoordsXY & screenCoords )
2017-06-26 20:01:35 +02:00
{
if ( _landRightsMode = = LAND_RIGHTS_MODE_BUY_LAND )
{
2019-10-21 14:13:08 +02:00
if ( screenCoords . x ! = LOCATION_NULL )
2017-06-26 20:01:35 +02:00
{
2019-03-17 09:25:51 +01:00
auto landBuyRightsAction = LandBuyRightsAction (
{ gMapSelectPositionA . x , gMapSelectPositionA . y , gMapSelectPositionB . x , gMapSelectPositionB . y } ,
LandBuyRightSetting : : BuyLand ) ;
GameActions : : Execute ( & landBuyRightsAction ) ;
2017-06-26 20:01:35 +02:00
}
}
else
{
2019-10-21 14:13:08 +02:00
if ( screenCoords . x ! = LOCATION_NULL )
2017-06-26 20:01:35 +02:00
{
2019-03-17 09:25:51 +01:00
auto landBuyRightsAction = LandBuyRightsAction (
{ gMapSelectPositionA . x , gMapSelectPositionA . y , gMapSelectPositionB . x , gMapSelectPositionB . y } ,
LandBuyRightSetting : : BuyConstructionRights ) ;
GameActions : : Execute ( & landBuyRightsAction ) ;
2017-06-26 20:01:35 +02:00
}
}
}
/**
*
* rct2 : 0x006681FB
*/
2020-02-29 03:43:29 +01:00
static void window_land_rights_tooldrag ( rct_window * w , rct_widgetindex widgetIndex , const ScreenCoordsXY & screenCoords )
2017-06-26 20:01:35 +02:00
{
2018-06-22 23:21:44 +02:00
if ( _landRightsMode = = LAND_RIGHTS_MODE_BUY_LAND )
{
2019-10-21 14:13:08 +02:00
if ( screenCoords . x ! = LOCATION_NULL )
2017-06-26 20:01:35 +02:00
{
2019-03-17 09:25:51 +01:00
auto landBuyRightsAction = LandBuyRightsAction (
{ gMapSelectPositionA . x , gMapSelectPositionA . y , gMapSelectPositionB . x , gMapSelectPositionB . y } ,
LandBuyRightSetting : : BuyLand ) ;
GameActions : : Execute ( & landBuyRightsAction ) ;
2017-06-26 20:01:35 +02:00
}
}
else
{
2019-10-21 14:13:08 +02:00
if ( screenCoords . x ! = LOCATION_NULL )
2017-06-26 20:01:35 +02:00
{
2019-03-17 09:25:51 +01:00
auto landBuyRightsAction = LandBuyRightsAction (
{ gMapSelectPositionA . x , gMapSelectPositionA . y , gMapSelectPositionB . x , gMapSelectPositionB . y } ,
LandBuyRightSetting : : BuyConstructionRights ) ;
GameActions : : Execute ( & landBuyRightsAction ) ;
2017-06-26 20:01:35 +02:00
}
}
}
static bool land_rights_tool_is_active ( )
{
if ( ! ( input_test_flag ( INPUT_FLAG_TOOL_ACTIVE ) ) )
return false ;
if ( gCurrentToolWidget . window_classification ! = WC_LAND_RIGHTS )
return false ;
return true ;
2015-05-15 17:28:27 +02:00
}