Skip to content

Commit

Permalink
Merge pull request #15 from astog/fall-2017-update
Browse files Browse the repository at this point in the history
Fall 2017 update
  • Loading branch information
astog authored Oct 29, 2017
2 parents e78d21d + d75fb91 commit d9b5609
Show file tree
Hide file tree
Showing 7 changed files with 178 additions and 46 deletions.
2 changes: 1 addition & 1 deletion Better Trade Screen.modinfo
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Mod id="8d4fa23a-ef43-440c-8422-2bec11f8f5d7" version="2.1">
<Mod id="8d4fa23a-ef43-440c-8422-2bec11f8f5d7" version="4.0.1">
<Properties>
<Name>LOC_BTS_NAME</Name>
<Stability>LOC_BTS_STABILITY</Stability>
Expand Down
6 changes: 5 additions & 1 deletion UI/Choosers/TradeOriginChooser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ function Refresh()
end

-- Calculate Control Size
Controls.CityScrollPanel:CalculateInternalSize();
Controls.CityStack:CalculateSize();
Controls.CityStack:ReprocessAnchoring();
Controls.CityScrollPanel:CalculateInternalSize();
end

-- ===========================================================================
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions UI/Choosers/TradeOriginChooser.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
</Container>

<!-- Body Container -->
<Container ID="RouteOriginChooserBody" Anchor="C,T" Offset="0,0" Size="parent,0" AutoSize="V">
<Container ID="RouteOriginChooserBody" Anchor="C,T" Offset="0,0" Size="parent,parent">
<ScrollPanel ID="CityScrollPanel" Offset="18,10" Size="parent-22,parent-35" Vertical="1" AutoScrollBar="0">
<ScrollBar Anchor="L,T" Size="11,parent-125" AnchorSide="O,I" Offset="4,0" Style="ScrollVerticalBar" />
<Stack ID="CityStack" StackGrowth="Bottom" StackPadding="2" />
<Stack ID="CityStack" StackGrowth="Bottom" StackPadding="2" />
</ScrollPanel>
</Container>
</Stack>
Expand Down
126 changes: 122 additions & 4 deletions UI/Choosers/TradeRouteChooser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand All @@ -466,6 +519,7 @@ end
-- Route button helpers
-- ---------------------------------------------------------------------------

-- ===========================================================================
function SetRouteInstanceYields(yieldsInstance, yieldIndex, yieldValue)
local iconString, text = FormatYieldText(yieldIndex, yieldValue);

Expand All @@ -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
-- ===========================================================================
Expand Down
53 changes: 33 additions & 20 deletions UI/Choosers/TradeRouteChooser.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<SlideAnim ID="RouteChooserSlideAnim" Anchor="L,T" Begin="-350,0" End="0,0" Cycle="Once" Speed="2" Function="OutQuint">
<Container ID="RouteChooser" Offset="-3,54">
<!-- Body container-->
<Container Size="395,0" AutoSize="V" ConsumeAllMouse="1">
<Container Size="395,parent" ConsumeAllMouse="1">
<Stack StackGrowth="Down">

<!-- Top Panel -->
Expand All @@ -28,25 +28,26 @@
</Grid>

<!-- Resource Information -->
<Grid ID="DestinationResources" Size="313,35" Anchor="C,T" Offset="1,16" Texture="Controls_ItemContainerDestination" SliceCorner="6,2" SliceSize="2,31" SliceTextureSize="24,35" >
<Grid ID="DestinationResources" Size="parent-25,35" Anchor="C,T" Offset="1,16" Texture="Controls_ItemContainerDestination" SliceCorner="6,2" SliceSize="2,31" SliceTextureSize="24,35" >
<!-- Column Background -->
<Box Size="50,parent" Offset="0,0" Color="0,0,0,22"/>
<Box Size="50,parent" Offset="100,0" Color="0,0,0,22"/>
<Box Size="50,parent" Offset="200,0" Color="0,0,0,22"/>
<Box Size="50,parent" Offset="50,0" Color="0,0,0,22"/>
<Box Size="50,parent" Offset="150,0" Color="0,0,0,22"/>
<Box Size="50,parent" Offset="250,0" Color="0,0,0,22"/>
<!-- <Box Size="50,parent" Offset="200,0" Color="0,0,0,22"/> -->

<Label ID="DestinationResourceHeader" Size="300,20" Anchor="L,T" Offset="2,-15" Style="FontNormal14" Color="0,0,0,150" String="$Destination$ receives:"/>
<Label ID="DestinationResourceHeader" Size="300,20" Anchor="L,T" Offset="2,-15" Style="FontNormal14" Color="0,0,0,150" TruncateWidth="279"/>
<Stack ID="DestinationResourceList" Anchor="L,T" Offset="3,8" StackGrowth="Bottom"/>
<Label ID="DestinationReceivesNoBenefitsLabel" Anchor="C,C" Offset="-4,0" Style="FontNormal16" FontStyle="Shadow" EffectColor="Black" String="LOC_ROUTECHOOSER_NO_BENEFITS_FROM_ROUTE" Hidden="1"/>
</Grid>

<Grid ID="OriginResources" Size="313,35" Anchor="C,T" Offset="-10,24" Texture="Controls_ItemContainerOrigin" SliceCorner="14,2" SliceSize="3,31" SliceTextureSize="24,35" >
<Grid ID="OriginResources" Size="parent-25,35" Anchor="R,T" Offset="2,24" Texture="Controls_ItemContainerOrigin" SliceCorner="14,2" SliceSize="3,31" SliceTextureSize="24,35" >
<!-- Column Background -->
<Box Size="50,parent" Offset="62,0" Color="0,0,0,22"/>
<Box Size="50,parent" Offset="162,0" Color="0,0,0,22"/>
<Box Size="50,parent" Offset="262,0" Color="0,0,0,22"/>
<Box Size="50,parent" Offset="53,0" Color="0,0,0,22"/>
<Box Size="50,parent" Offset="153,0" Color="0,0,0,22"/>
<Box Size="50,parent" Offset="253,0" Color="0,0,0,22"/>

<Label ID="OriginResourceHeader" Size="250,20" Anchor="L,T" Offset="13,-15" Style="FontNormal14" Color="0,0,0,150" String="$Origin$ receives:"/>
<Stack ID="OriginResourceList" Anchor="C,C" Offset="6,-1" StackGrowth="Bottom"/>
<Label ID="OriginResourceHeader" Size="250,20" Anchor="L,T" Offset="13,-15" Style="FontNormal14" Color="0,0,0,150" TruncateWidth="279"/>
<Stack ID="OriginResourceList" Anchor="L,C" Offset="6,-1" StackGrowth="Bottom"/>
<Label ID="OriginReceivesNoBenefitsLabel" Anchor="C,C" Style="FontNormal16" FontStyle="Shadow" EffectColor="Black" String="LOC_ROUTECHOOSER_NO_BENEFITS_FROM_ROUTE" Hidden="1"/>
</Grid>

Expand Down Expand Up @@ -102,7 +103,7 @@

<!-- Sort Yield Stack -->
<Stack Anchor="L,T" ID="SortBarStack" StackGrowth="Right" Offset="0,34" StackPadding="2">
<GridButton ID="FoodSortButton" ToolTip="LOC_TRADE_SORT_BY_FOOD_TOOLTIP" Offset="25,0" Size="48,18" Color="255,255,255,255" Style="PanelButtonLightweight">
<GridButton ID="FoodSortButton" ToolTip="LOC_TRADE_SORT_BY_FOOD_TOOLTIP" Offset="17,0" Size="48,18" Color="255,255,255,255" Style="PanelButtonLightweight">
<Label ID="FoodSortLabel" Anchor="R,C" Offset="-2,1" Style="FontNormal12" String="[Icon_Food]"/>
<Label ID="FoodSortOrder" Hidden="1" Anchor="C,C" Offset="0,0" String="9" Style="FontNormal12"/>
<Image ID="FoodDescArrow" Texture="Controls_ButtonExtendSmall2" TextureOffset="0,0" Size="20,16" Anchor="L,C" Offset="2,0"/>
Expand Down Expand Up @@ -153,13 +154,13 @@
</Stack>

<!-- Destination List -->
<ScrollPanel ID="RouteChoiceScrollPanel" Offset="0,54" Size="parent,parent-54" Vertical="1" AutoScrollBar="1" AutoSizeScrollBar="1">
<ScrollPanel ID="RouteChoiceScrollPanel" Anchor="L,T" Offset="1,54" Size="parent,parent-54" Vertical="1" AutoScrollBar="1" AutoSizeScrollBar="1">
<ScrollBar Style="ScrollVerticalBacking" Anchor="L,T" AnchorSide="O,I" Color="28,60,90,255" Offset="-7,2">
<Thumb Style="ScrollThumbAlt" Color="28,60,90,255" />
</ScrollBar>

<!-- Destination Stack -->
<Stack ID="RouteChoiceStack" Offset="10,0" StackGrowth="Down"/>
<Stack ID="RouteChoiceStack" Anchor="L,T" Offset="0,0" StackGrowth="Down"/>
</ScrollPanel>

<!-- Bottom Divider -->
Expand Down Expand Up @@ -202,9 +203,11 @@
</Container>
</SlideAnim>

<!-- Instances -->
<!-- ======================= -->
<!-- Instances -->
<!-- ======================= -->
<Instance Name="RouteChoiceInstance">
<Container ID="Top" Size="364,95" Offset="0,2">
<Container ID="Top" Size="380,110" Offset="0,2">
<GridButton ID="Button" Size="parent,parent" Anchor="C,T">
<GridData Texture="DestinationChooser_Button" StateOffsetIncrement="0,76" SliceCorner="14,14" SliceSize="19,44" SliceTextureSize="48,76"/>

Expand All @@ -228,21 +231,22 @@
</Grid>

<!-- Resource Info -->
<Grid Size="350,50" Anchor="C,B" Offset="-1,7" Texture="Controls_ItemContainer" SliceCorner="8,8" SliceTextureSize="16,16" >
<Grid Size="parent-13,parent-45" Anchor="C,B" Offset="-1,7" Texture="Controls_ItemContainer" SliceCorner="8,8" SliceTextureSize="16,16" >
<!-- Column Background -->
<Box Size="50,parent" Offset="50,0" Color="0,0,0,22"/>
<Box Size="50,parent" Offset="150,0" Color="0,0,0,22"/>
<Box Size="50,parent" Offset="250,0" Color="0,0,0,22"/>
<!-- <Box Size="50,parent" Offset="350,0" Color="0,0,0,22"/> -->

<Stack ID="ResourceList" Anchor="C,C" Offset="-23,0" StackGrowth="Bottom" StackPadding="4"/>
<Stack ID="ResourceList" Anchor="L,C" Offset="4,0" StackGrowth="Bottom" StackPadding="10"/>
</Grid>
</GridButton>
</Container>
</Instance>

<!-- Route Yields Instance -->
<Instance Name="RouteYieldInstance">
<Stack StackGrowth="Right" StackPadding="2">
<Stack ID="YieldStack" StackGrowth="Right" StackPadding="2">
<Container Size="48,20">
<Label ID="YieldFoodLabel" Color="Food" Anchor="C,C" Offset="0,0" Style="FontNormal12" FontStyle="Shadow" String="+15[Icon_Food]"/>
</Container>
Expand All @@ -266,6 +270,15 @@
<Container Size="48,20">
<Label ID="YieldFaithLabel" Color="Faith" Anchor="C,C" Offset="0,0" Style="FontNormal12" FontStyle="Shadow" String="+15[Icon_Faith]"/>
</Container>

<Container ID="RouteReligionContainer" Size="56,20" Hidden="1">
<Container Anchor="C,C" Offset="1,0" >
<Image ID="ReligionIconBacking" Anchor="R,C" Texture="Religion_FollowersSlot" Size="30,30">
<Image ID="ReligionIcon" Anchor="C,C" Size="22,22" IconSize="22"/>
</Image>
<Label ID="ResourceEntryText" Anchor="L,C" Size="50,10" Offset="2,0" String="+0.5" Style="FontNormal12"/>
</Container>
</Container>
</Stack>
</Instance>
</Context>
Loading

0 comments on commit d9b5609

Please sign in to comment.