From 8ab08bdb3860bfbfa748af29f4e8a662a00b06a4 Mon Sep 17 00:00:00 2001 From: astog Date: Tue, 8 Aug 2023 11:16:26 -0500 Subject: [PATCH] Add feature to select city with mouse click Was a Vanilla CIV6 feature that was not ported over --- UI/Choosers/TradeRouteChooser.lua | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/UI/Choosers/TradeRouteChooser.lua b/UI/Choosers/TradeRouteChooser.lua index 79999dd..fdb814a 100644 --- a/UI/Choosers/TradeRouteChooser.lua +++ b/UI/Choosers/TradeRouteChooser.lua @@ -59,6 +59,15 @@ m_SortBySettings[1] = { local opt_print = false +-- =========================================================================== +function FindDestinationEntry(cityOwner:number, cityID:number) + for index, entry in ipairs(m_AvailableTradeRoutes) do + if entry.DestinationCityID == cityID and entry.DestinationCityPlayer == cityOwner then + return entry; + end + end +end + -- =========================================================================== -- Refresh functions -- =========================================================================== @@ -847,10 +856,11 @@ function TradeRouteSelected( cityOwner:number, cityID:number ) local player:table = Players[cityOwner]; if player then local pCity:table = player:GetCities():FindID(cityID); - if pCity ~= nil then + if pCity and FindDestinationEntry(cityOwner, cityID) then m_destinationCity = pCity; else - error("Unable to find city '".. tostring(cityID).."' for creating a trade route."); + print("Unable to find city '".. tostring(cityID).."' for creating a trade route."); + m_destinationCity = nil; end end @@ -1292,6 +1302,19 @@ function OnSelectRouteFromOverview( destinationOwnerID:number, destinationCityID CheckNeedsToOpen() end +-- =========================================================================== +-- Create a trade route from the world input. +-- =========================================================================== +function OnWorldInputMakeTradeRoute( plotId:number ) + + local plotX,plotY = Map.GetPlotLocation( plotId ); + local pCity :table = Cities.GetCityInPlot( plotX, plotY ); + if pCity then + UI.PlaySound("Play_UI_Click"); + TradeRouteSelected( pCity:GetOwner(), pCity:GetID() ); + end +end + -- =========================================================================== -- Setup -- =========================================================================== @@ -1321,6 +1344,7 @@ function Initialize() LuaEvents.TradeRouteChooser_SkipOpen.Add( OnSkipNextOpen ) LuaEvents.TradeOverview_SelectRouteFromOverview.Add( OnSelectRouteFromOverview ); LuaEvents.TradeRouteChooser_Close.Add( OnClose ) + LuaEvents.WorldInput_MakeTradeRouteDestination.Add( OnWorldInputMakeTradeRoute ); -- Game Engine Events Events.InterfaceModeChanged.Add( OnInterfaceModeChanged );