forked from Azurency/Civ6-UIFiles
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ModalScreen_PlayerYieldsHelper.lua
112 lines (90 loc) · 3.98 KB
/
ModalScreen_PlayerYieldsHelper.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
include( "ToolTipHelper_PlayerYields" );
-- ===========================================================================
-- GLOBALS
-- ===========================================================================
TOP_PANEL_OFFSET = 29;
MIN_SPEC_HEIGHT = 768;
-- ===========================================================================
-- Refresh the yeilds
-- RETURNS: true if screen is taller than minspec height.
-- ===========================================================================
function RefreshYields()
-- This panel should only show at minispec
local screenX, screenY:number = UIManager:GetScreenSizeVal();
if (screenY > MIN_SPEC_HEIGHT ) then
Controls.YieldsContainer:SetHide(true);
return false;
end
local ePlayer :number = Game.GetLocalPlayer();
local localPlayer :table= nil;
if ePlayer ~= -1 then
localPlayer = Players[ePlayer];
if localPlayer == nil then
return false;
end
else
return false;
end
local YIELD_PADDING_Y:number = 12;
---- SCIENCE ----
local playerTechnology :table = localPlayer:GetTechs();
local currentScienceYield :number = playerTechnology:GetScienceYield();
Controls.SciencePerTurn:SetText( FormatValuePerTurn(currentScienceYield) );
Controls.ScienceBacking:SetToolTipString( GetScienceTooltip() );
Controls.ScienceStack:CalculateSize();
Controls.ScienceBacking:SetSizeX(Controls.ScienceStack:GetSizeX() + YIELD_PADDING_Y);
---- GOLD ----
local playerTreasury:table = localPlayer:GetTreasury();
local goldYield :number = playerTreasury:GetGoldYield() - playerTreasury:GetTotalMaintenance();
local goldBalance :number = math.floor(playerTreasury:GetGoldBalance());
Controls.GoldBalance:SetText( Locale.ToNumber(goldBalance, "#,###.#") );
Controls.GoldPerTurn:SetText( FormatValuePerTurn(goldYield) );
Controls.GoldBacking:SetToolTipString( GetGoldTooltip() );
Controls.GoldStack:CalculateSize();
Controls.GoldBacking:SetSizeX(Controls.GoldStack:GetSizeX() + YIELD_PADDING_Y);
-- Size yields in first column to match largest
if Controls.GoldBacking:GetSizeX() > Controls.ScienceBacking:GetSizeX() then
-- Gold is wider so size Science to match
Controls.ScienceBacking:SetSizeX(Controls.GoldBacking:GetSizeX());
else
-- Science is wider so size Gold to match
Controls.GoldBacking:SetSizeX(Controls.ScienceBacking:GetSizeX());
end
---- CULTURE----
local playerCulture :table = localPlayer:GetCulture();
local currentCultureYield :number = playerCulture:GetCultureYield();
Controls.CulturePerTurn:SetText( FormatValuePerTurn(currentCultureYield) );
Controls.CultureBacking:SetToolTipString( GetCultureTooltip() );
Controls.CultureStack:CalculateSize();
Controls.CultureBacking:SetSizeX(Controls.CultureStack:GetSizeX() + YIELD_PADDING_Y);
---- FAITH ----
local playerReligion :table = localPlayer:GetReligion();
local faithYield :number = playerReligion:GetFaithYield();
local faithBalance :number = playerReligion:GetFaithBalance();
Controls.FaithBalance:SetText( Locale.ToNumber(faithBalance, "#,###.#") );
Controls.FaithPerTurn:SetText( FormatValuePerTurn(faithYield) );
Controls.FaithBacking:SetToolTipString( GetFaithTooltip() );
Controls.FaithStack:CalculateSize();
Controls.FaithBacking:SetSizeX(Controls.FaithStack:GetSizeX() + YIELD_PADDING_Y);
-- Size yields in second column to match largest
if Controls.FaithBacking:GetSizeX() > Controls.CultureBacking:GetSizeX() then
-- Faith is wider so size Culture to match
Controls.CultureBacking:SetSizeX(Controls.FaithBacking:GetSizeX());
else
-- Culture is wider so size Faith to match
Controls.FaithBacking:SetSizeX(Controls.CultureBacking:GetSizeX());
end
Controls.YieldsContainer:SetHide(false);
if Controls.ModalScreenClose ~= nil then
Controls.ModalScreenClose:Reparent();
end
return true;
end
-- ===========================================================================
function FormatValuePerTurn( value:number )
if(value == 0) then
return Locale.ToNumber(value);
else
return Locale.Lookup("{1: number +#,###.#;-#,###.#}", value);
end
end