Skip to content

Commit

Permalink
Add feature to select city with mouse click
Browse files Browse the repository at this point in the history
Was a Vanilla CIV6 feature that was not ported over
  • Loading branch information
astog committed Aug 8, 2023
1 parent c4700f5 commit 8ab08bd
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions UI/Choosers/TradeRouteChooser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
-- ===========================================================================
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
-- ===========================================================================
Expand Down Expand Up @@ -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 );
Expand Down

0 comments on commit 8ab08bd

Please sign in to comment.