diff --git a/Better Trade Screen.modinfo b/Better Trade Screen.modinfo index 5bf009e..1cbf12b 100644 --- a/Better Trade Screen.modinfo +++ b/Better Trade Screen.modinfo @@ -1,5 +1,5 @@ - + LOC_BTS_NAME LOC_BTS_STABILITY diff --git a/UI/Choosers/TradeOriginChooser.lua b/UI/Choosers/TradeOriginChooser.lua index 42389e3..3a91ab8 100644 --- a/UI/Choosers/TradeOriginChooser.lua +++ b/UI/Choosers/TradeOriginChooser.lua @@ -68,9 +68,9 @@ function Refresh() end -- Calculate Control Size - Controls.CityScrollPanel:CalculateInternalSize(); Controls.CityStack:CalculateSize(); Controls.CityStack:ReprocessAnchoring(); + Controls.CityScrollPanel:CalculateInternalSize(); end -- =========================================================================== @@ -113,7 +113,9 @@ end -- =========================================================================== function AddCity(cityID:number) local city = Players[Game.GetLocalPlayer()]:GetCities():FindID(cityID) + print("Adding city " .. Locale.Lookup(city:GetName())) local cityInstance:table = m_cityIM:GetInstance(); + cityInstance.CityButton:SetHide(false); cityInstance.CityButton:SetText(Locale.ToUpper(city:GetName())); if m_newOriginCity ~= nil and m_newOriginCity:GetID() == cityID then @@ -171,6 +173,8 @@ function TeleportToCity(city:table) local pSelectedUnit = UI.GetHeadSelectedUnit(); if (UnitManager.CanStartOperation( pSelectedUnit, eOperation, nil, tParameters)) then UnitManager.RequestOperation( pSelectedUnit, eOperation, tParameters); + UI.SetInterfaceMode(InterfaceModeTypes.SELECTION); + UI.PlaySound("Unit_Relocate"); OnClose(); end end diff --git a/UI/Choosers/TradeOriginChooser.xml b/UI/Choosers/TradeOriginChooser.xml index e919637..47b59b2 100644 --- a/UI/Choosers/TradeOriginChooser.xml +++ b/UI/Choosers/TradeOriginChooser.xml @@ -31,10 +31,10 @@ - + - + diff --git a/UI/Choosers/TradeRouteChooser.lua b/UI/Choosers/TradeRouteChooser.lua index 79a2fde..80924af 100644 --- a/UI/Choosers/TradeRouteChooser.lua +++ b/UI/Choosers/TradeRouteChooser.lua @@ -190,12 +190,39 @@ function RefreshTopPanel() end end - Controls.OriginResources:SetToolTipString(""); - Controls.DestinationResources:SetToolTipString(""); - Controls.OriginResourceHeader:SetText(L_Lookup("LOC_ROUTECHOOSER_RECEIVES_RESOURCE", L_Lookup(m_originCity:GetName()))); Controls.DestinationResourceHeader:SetText(L_Lookup("LOC_ROUTECHOOSER_RECEIVES_RESOURCE", L_Lookup(m_destinationCity:GetName()))); - + local originTooltipText = "" + local destinationTooltipText:string = ""; + + -- Handle Religion pressure icons + local destinationMajorityReligion = m_destinationCity:GetReligion():GetMajorityReligion(); + if (destinationMajorityReligion > 0) then + local pressureValue, sourceText = GetReligiousPressureForCity(destinationMajorityReligion, m_destinationCity, true); + if (pressureValue ~= 0) then + if (originTooltipText ~= "") then + originTooltipText = originTooltipText .. "[NEWLINE]"; + end + originTooltipText = originTooltipText .. sourceText; + AddReligiousPressureResourceEntry(GameInfo.Religions[destinationMajorityReligion], pressureValue, true, sourceText, originYieldInstance); + originReceivedResources = true; + end + end + Controls.OriginResources:SetToolTipString(originTooltipText); + + local originMajorityReligion = m_originCity:GetReligion():GetMajorityReligion(); + if (originMajorityReligion > 0) then + local pressureValue, sourceText = GetReligiousPressureForCity(originMajorityReligion, m_originCity, false); + if (pressureValue ~= 0) then + if (destinationTooltipText ~= "") then + destinationTooltipText = destinationTooltipText .. "[NEWLINE]"; + end + destinationTooltipText = destinationTooltipText .. sourceText; + AddReligiousPressureResourceEntry(GameInfo.Religions[originMajorityReligion], pressureValue, false, sourceText, destinationYieldInstance); + destinationReceivedResources = true; + end + end + Controls.DestinationResources:SetToolTipString(destinationTooltipText); if originReceivedResources then Controls.OriginReceivesNoBenefitsLabel:SetHide(true); @@ -372,6 +399,8 @@ function AddRouteToDestinationStack(routeInfo:table) local destinationPlayer:table = Players[routeInfo.DestinationCityPlayer]; local destinationCity:table = destinationPlayer:GetCities():FindID(routeInfo.DestinationCityID); + local originPlayer:table = Players[routeInfo.OriginCityPlayer]; + local originCity:table = originPlayer:GetCities():FindID(routeInfo.OriginCityID); -- Update Selector Brace if m_destinationCity ~= nil and destinationCity:GetName() == m_destinationCity:GetName() then @@ -451,6 +480,30 @@ function AddRouteToDestinationStack(routeInfo:table) SetRouteInstanceYields(destinationYieldInstance, yieldIndex, destinationYieldValue) end + local destinationMajorityReligion = destinationCity:GetReligion():GetMajorityReligion(); + if (destinationMajorityReligion > 0) then + local pressureValue, sourceText = GetReligiousPressureForCity(destinationMajorityReligion, destinationCity, true); + if (pressureValue ~= 0) then + if (tooltipText ~= "") then + tooltipText = tooltipText .. "[NEWLINE]"; + end + tooltipText = tooltipText .. sourceText; + AddReligiousPressureResourceEntry(GameInfo.Religions[destinationMajorityReligion], pressureValue, true, sourceText, originYieldInstance); + end + end + + local originMajorityReligion = originCity:GetReligion():GetMajorityReligion(); + if (originMajorityReligion > 0) then + local pressureValue, sourceText = GetReligiousPressureForCity(originMajorityReligion, destinationCity, false); + if (pressureValue ~= 0) then + if (tooltipText ~= "") then + tooltipText = tooltipText .. "[NEWLINE]"; + end + tooltipText = tooltipText .. sourceText; + AddReligiousPressureResourceEntry(GameInfo.Religions[originMajorityReligion], pressureValue, false, sourceText, destinationYieldInstance); + end + end + -- Cleanup cityEntry.ResourceList:CalculateSize(); cityEntry.ResourceList:ReprocessAnchoring(); @@ -466,6 +519,7 @@ end -- Route button helpers -- --------------------------------------------------------------------------- +-- =========================================================================== function SetRouteInstanceYields(yieldsInstance, yieldIndex, yieldValue) local iconString, text = FormatYieldText(yieldIndex, yieldValue); @@ -484,6 +538,70 @@ function SetRouteInstanceYields(yieldsInstance, yieldIndex, yieldValue) end end +-- =========================================================================== +function GetReligiousPressureForCity(religionIndex:number, destinationCity:table, forOriginCity:boolean) + local pressureValue = 0; + local pressureIconString = ""; + local cityName = ""; + local tradeManager = Game.GetTradeManager(); + + if m_originCity == nil or destinationCity == nil then + return 0, ""; + end + + if (forOriginCity) then + pressureValue = tradeManager:CalculateOriginReligiousPressureFromPotentialRoute(m_originCity:GetOwner(), m_originCity:GetID(), destinationCity:GetOwner(), destinationCity:GetID(), religionIndex); + pressureIconString = "[ICON_PressureLeft]"; + cityName = destinationCity:GetName(); + else + pressureValue = tradeManager:CalculateDestinationReligiousPressureFromPotentialRoute(m_originCity:GetOwner(), m_originCity:GetID(), destinationCity:GetOwner(), destinationCity:GetID(), religionIndex); + pressureIconString = "[ICON_PressureRight]"; + cityName = m_originCity:GetName(); + end + local sourceText = Locale.Lookup("LOC_ROUTECHOOSER_RELIGIOUS_PRESSURE_SOURCE_MAJORITY_RELIGION", pressureValue, pressureIconString, Game.GetReligion():GetName(religionIndex), cityName); + return pressureValue, sourceText; +end + +-- =========================================================================== +function AddReligiousPressureResourceEntry(religionInfo:table, pressureValue:number, forOriginCity:boolean, sourceText:string, instanceControl:table) + -- local entryInstance:table = {}; + -- ContextPtr:BuildInstanceForControl( "ReligionPressureEntryInstance", entryInstance, stackControl ); + instanceControl.RouteReligionContainer:SetHide(false); + + local religionColor = UI.GetColorValue(religionInfo.Color); + local religionName = Game.GetReligion():GetName(religionInfo.Index); + instanceControl.ReligionIcon:SetIcon("ICON_" .. religionInfo.ReligionType); + instanceControl.ReligionIcon:SetColor(religionColor); + instanceControl.ReligionIconBacking:SetColor(religionColor); + instanceControl.ReligionIconBacking:SetToolTipString(religionName); + + local icon:string, text:string = FormatReligiousPressureText(religionInfo, pressureValue, forOriginCity); + instanceControl.ResourceEntryText:SetText(text); + -- instanceControl.RouteReligionContainer:CalculateSize(); + -- instanceControl.RouteReligionContainer:ReprocessAnchoring(); +end + +-- =========================================================================== +function FormatReligiousPressureText(religionInfo, pressureValue, forOriginCity:boolean) + local text:string = ""; + + local iconString = ""; + if (religionInfo ~= nil) then + if (forOriginCity) then + iconString = "[ICON_PressureLeft]"; + else + iconString = "[ICON_PressureRight]"; + end + end + + if (pressureValue >= 0) then + text = text .. "+"; + end + + text = text .. pressureValue; + return iconString, text; +end + -- =========================================================================== -- Filter, Filter Pulldown functions -- =========================================================================== diff --git a/UI/Choosers/TradeRouteChooser.xml b/UI/Choosers/TradeRouteChooser.xml index ff8a259..963c402 100644 --- a/UI/Choosers/TradeRouteChooser.xml +++ b/UI/Choosers/TradeRouteChooser.xml @@ -4,7 +4,7 @@ - + @@ -28,25 +28,26 @@ - + - - - + + + + - - + - - - + + + - @@ -102,7 +103,7 @@ - + - + - + @@ -202,9 +203,11 @@ - + + + - + @@ -228,13 +231,14 @@ - + + - + @@ -242,7 +246,7 @@ - + @@ -266,6 +270,15 @@ + + diff --git a/UI/TradeOverview.lua b/UI/TradeOverview.lua index c47761d..2e5c58e 100644 --- a/UI/TradeOverview.lua +++ b/UI/TradeOverview.lua @@ -378,23 +378,21 @@ function ViewRoutesToCities() local routesSortedByPlayer:table = {}; local players = Game.GetPlayers{ Alive=true }; for _, player in ipairs(players) do - if m_filterList[m_filterSelected].FilterFunction and m_filterList[m_filterSelected].FilterFunction(player) then - for _, city in player:GetCities():Members() do - local outgoingRoutes = city:GetTrade():GetOutgoingRoutes(); - for _, route in ipairs(outgoingRoutes) do - -- Check that the destination city owner is the local palyer - local isDestinationOwnedByLocalPlayer:boolean = false; - if route.DestinationCityPlayer == Game.GetLocalPlayer() then - isDestinationOwnedByLocalPlayer = true; - end + -- Don't show domestic routes + if player:GetID() ~= Game.GetLocalPlayer() then + if m_filterList[m_filterSelected].FilterFunction and m_filterList[m_filterSelected].FilterFunction(player) then + for _, city in player:GetCities():Members() do + local outgoingRoutes = city:GetTrade():GetOutgoingRoutes(); + for _, route in ipairs(outgoingRoutes) do + -- Make sure the destination city is owned by the local player + if route.DestinationCityPlayer == Game.GetLocalPlayer() then + -- Make sure we have a table for each destination player + if routesSortedByPlayer[route.OriginCityPlayer] == nil then + routesSortedByPlayer[route.OriginCityPlayer] = {}; + end - if isDestinationOwnedByLocalPlayer then - -- Make sure we have a table for each destination player - if routesSortedByPlayer[route.OriginCityPlayer] == nil then - routesSortedByPlayer[route.OriginCityPlayer] = {}; + tinsert(routesSortedByPlayer[route.OriginCityPlayer], route); end - - tinsert(routesSortedByPlayer[route.OriginCityPlayer], route); end end end @@ -416,7 +414,6 @@ end -- Show Available Routes Tab -- Note: There is a lot OPT prints and time information calculated --- This is just for logging purposes and don't affect the logic in any way function ViewAvailableRoutes() -- Update Tabs diff --git a/UI/TradeOverview.xml b/UI/TradeOverview.xml index 23c8007..51ec080 100644 --- a/UI/TradeOverview.xml +++ b/UI/TradeOverview.xml @@ -50,7 +50,7 @@ - + @@ -75,7 +75,7 @@ - +