From 482071a5ba4ee2fcfd4bbc241b1846288702b502 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Fri, 2 Aug 2024 14:37:10 +0200 Subject: [PATCH] LandRights: deduplicate OnToolDown, OnToolDrag --- src/openrct2-ui/windows/LandRights.cpp | 50 ++++++-------------------- 1 file changed, 10 insertions(+), 40 deletions(-) diff --git a/src/openrct2-ui/windows/LandRights.cpp b/src/openrct2-ui/windows/LandRights.cpp index fba09f3d00..e522fef226 100644 --- a/src/openrct2-ui/windows/LandRights.cpp +++ b/src/openrct2-ui/windows/LandRights.cpp @@ -336,50 +336,20 @@ static Widget window_land_rights_widgets[] = { void OnToolDown(WidgetIndex widgetIndex, const ScreenCoordsXY& screenCoords) override { - if (_landRightsMode == LAND_RIGHTS_MODE_BUY_LAND) - { - if (screenCoords.x != kLocationNull) - { - auto landBuyRightsAction = LandBuyRightsAction( - { gMapSelectPositionA.x, gMapSelectPositionA.y, gMapSelectPositionB.x, gMapSelectPositionB.y }, - LandBuyRightSetting::BuyLand); - GameActions::Execute(&landBuyRightsAction); - } - } - else - { - if (screenCoords.x != kLocationNull) - { - auto landBuyRightsAction = LandBuyRightsAction( - { gMapSelectPositionA.x, gMapSelectPositionA.y, gMapSelectPositionB.x, gMapSelectPositionB.y }, - LandBuyRightSetting::BuyConstructionRights); - GameActions::Execute(&landBuyRightsAction); - } - } + if (screenCoords.x == kLocationNull) + return; + + auto modeSetting = _landRightsMode == LAND_RIGHTS_MODE_BUY_LAND ? LandBuyRightSetting::BuyLand + : LandBuyRightSetting::BuyConstructionRights; + + auto landBuyRightsAction = LandBuyRightsAction( + { gMapSelectPositionA.x, gMapSelectPositionA.y, gMapSelectPositionB.x, gMapSelectPositionB.y }, modeSetting); + GameActions::Execute(&landBuyRightsAction); } void OnToolDrag(WidgetIndex widgetIndex, const ScreenCoordsXY& screenCoords) override { - if (_landRightsMode == LAND_RIGHTS_MODE_BUY_LAND) - { - if (screenCoords.x != kLocationNull) - { - auto landBuyRightsAction = LandBuyRightsAction( - { gMapSelectPositionA.x, gMapSelectPositionA.y, gMapSelectPositionB.x, gMapSelectPositionB.y }, - LandBuyRightSetting::BuyLand); - GameActions::Execute(&landBuyRightsAction); - } - } - else - { - if (screenCoords.x != kLocationNull) - { - auto landBuyRightsAction = LandBuyRightsAction( - { gMapSelectPositionA.x, gMapSelectPositionA.y, gMapSelectPositionB.x, gMapSelectPositionB.y }, - LandBuyRightSetting::BuyConstructionRights); - GameActions::Execute(&landBuyRightsAction); - } - } + OnToolDown(widgetIndex, screenCoords); } void OnResize() override