-
Notifications
You must be signed in to change notification settings - Fork 6
/
CivilizationIcon.lua
175 lines (152 loc) · 6.74 KB
/
CivilizationIcon.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
--[[
-- Created by Samuel Batista on Friday Apr 19 2017
-- Copyright (c) Firaxis Games
--]]
include("LuaClass");
include("SupportFunctions");
------------------------------------------------------------------
-- Class Table
------------------------------------------------------------------
CivilizationIcon = LuaClass:Extend()
------------------------------------------------------------------
-- Class Constants
------------------------------------------------------------------
CivilizationIcon.m_CivTooltip = {};
TTManager:GetTypeControlTable("CivTooltip", CivilizationIcon.m_CivTooltip);
CivilizationIcon.UNKNOWN_COLOR = RGBAValuesToABGRHex(1, 1, 1, 1);
CivilizationIcon.ICON_UNKNOWN_CIV = "ICON_CIVILIZATION_UNKNOWN";
CivilizationIcon.DATA_FIELD_CLASS = "CIVILIZATION_ICON_CLASS";
------------------------------------------------------------------
-- Class Members
------------------------------------------------------------------
--This is needed for how we deal with tooltip callbacks. The stack
--seizure could end up changing because of reuse of tables in other
--files
CivilizationIcon.playerID = -1;
CivilizationIcon.detailString = "";
------------------------------------------------------------------
-- Static-style initialization functions
------------------------------------------------------------------
function CivilizationIcon:GetInstance(instanceManager:table, newParent:table)
local instance = instanceManager:GetInstance(newParent);
return CivilizationIcon:AttachInstance(instance);
end
function CivilizationIcon:AttachInstance(instance:table)
self = instance[CivilizationIcon.DATA_FIELD_CLASS];
if not self then
self = CivilizationIcon:new(instance);
instance[CivilizationIcon.DATA_FIELD_CLASS] = self;
end
self:Reset();
return self, instance;
end
------------------------------------------------------------------
------------------------------------------------------------------
-- Constructor
------------------------------------------------------------------
function CivilizationIcon:new(instance:table)
self = LuaClass.new(CivilizationIcon)
self.Controls = instance or Controls;
return self;
end
------------------------------------------------------------------
function CivilizationIcon:UpdateIconFromPlayerID(playerID:number)
local playerConfig:table = PlayerConfigurations[playerID];
local localPlayerID:number = Game.GetLocalPlayer();
local localPlayer:table = Players[localPlayerID];
local hasMetLocalPlayer:boolean = localPlayer and localPlayer:GetDiplomacy():HasMet(playerID);
local showCivIcon:boolean = (playerID == localPlayerID) or hasMetLocalPlayer;
local civIcon = showCivIcon and "ICON_" .. playerConfig:GetCivilizationTypeName() or self.ICON_UNKNOWN_CIV;
local textureOffsetX:number, textureOffsetY:number, textureSheet:string = IconManager:FindIconAtlas(civIcon, self.Controls.CivIcon:GetSizeX());
if(textureSheet == nil or textureSheet == "") then
UI.DataError("Could not find icon in CivilizationIcon.UpdateIcon: icon=\""..civIcon.."\", iconSize="..tostring(self.Controls.CivIcon:GetSizeX()));
else
self.Controls.CivIcon:SetTexture(textureOffsetX, textureOffsetY, textureSheet);
end
if self.Controls.LocalPlayer then
self.Controls.LocalPlayer:SetHide(playerID ~= localPlayerID);
end
self:ColorCivIcon(playerID, showCivIcon);
end
function CivilizationIcon:ColorCivIcon(playerID:number, showCivIcon:boolean)
if showCivIcon then
local backColor, frontColor = UI.GetPlayerColors(playerID);
self.Controls.CivIcon:SetColor(frontColor);
if self.Controls.CivIconBacking then
self.Controls.CivIconBacking:SetColor(backColor);
else
self.Controls.CivBacking_Base:SetColor(backColor);
self.Controls.CivBacking_Lighter:SetColor(DarkenLightenColor(backColor, 80, 255));
self.Controls.CivBacking_Darker:SetColor(DarkenLightenColor(backColor, -55, 230));
end
else
self.Controls.CivIcon:SetColor(self.UNKNOWN_COLOR);
if self.Controls.CivIconBacking then
self.Controls.CivIconBacking:SetColor(self.UNKNOWN_COLOR);
else
self.Controls.CivBacking_Base:SetColor(self.UNKNOWN_COLOR);
self.Controls.CivBacking_Lighter:SetColor(self.UNKNOWN_COLOR);
self.Controls.CivBacking_Darker:SetColor(self.UNKNOWN_COLOR);
end
end
end
function CivilizationIcon:SetLeaderTooltip(playerID:number, details:string)
local pPlayer:table = Players[playerID];
local playerConfig:table = PlayerConfigurations[playerID];
local localPlayerID:number = Game.GetLocalPlayer();
local localPlayer:table = Players[localPlayerID];
--Cache our string
self.playerID = playerID;
self.detailString = details;
if(playerID ~= localPlayerID and localPlayer ~= nil and not localPlayer:GetDiplomacy():HasMet(playerID)) then
self.Controls.CivIcon:SetToolTipType();
self.Controls.CivIcon:ClearToolTipCallback();
if GameConfiguration.IsAnyMultiplayer() and pPlayer:IsHuman() then
self.Controls.CivIcon:SetToolTipString(Locale.Lookup("LOC_DIPLOPANEL_UNMET_PLAYER") .. " (" .. playerConfig:GetPlayerName() .. ")");
else
self.Controls.CivIcon:SetToolTipString(Locale.Lookup("LOC_DIPLOPANEL_UNMET_PLAYER"));
end
else
self.Controls.CivIcon:SetToolTipType("CivTooltip");
self.Controls.CivIcon:SetToolTipCallback(function() self:UpdateLeaderTooltip(self.playerID, self.detailString); end);
end
end
function CivilizationIcon:SetTooltipString(tooltip:string)
self.Controls.CivIcon:SetToolTipType();
self.Controls.CivIcon:ClearToolTipCallback();
self.Controls.CivIcon:SetToolTipString(tooltip);
end
function CivilizationIcon:UpdateLeaderTooltip(playerID:number, details:string)
local pPlayer:table = Players[playerID];
local playerConfig:table = PlayerConfigurations[playerID];
local localPlayerID:number = Game.GetLocalPlayer();
if(pPlayer ~= nil and playerConfig ~= nil) then
self.m_CivTooltip.YouIndicator:SetHide(playerID ~= localPlayerID);
local leaderTypeName:string = playerConfig:GetLeaderTypeName();
if(leaderTypeName ~= nil) then
self.m_CivTooltip.LeaderIcon:SetIcon("ICON_"..leaderTypeName);
local desc:string;
local leaderDesc:string = playerConfig:GetLeaderName();
local civDesc:string = playerConfig:GetCivilizationDescription();
if GameConfiguration.IsAnyMultiplayer() and pPlayer:IsHuman() then
local name = Locale.Lookup(playerConfig:GetPlayerName());
desc = Locale.Lookup("LOC_DIPLOMACY_DEAL_PLAYER_PANEL_TITLE", leaderDesc, civDesc) .. " (" .. name .. ")";
else
desc = Locale.Lookup("LOC_DIPLOMACY_DEAL_PLAYER_PANEL_TITLE", leaderDesc, civDesc);
end
if (details ~= nil and details ~= "") then
desc = desc .. "[NEWLINE]" .. details;
end
self.m_CivTooltip.LeaderName:SetText(desc);
self.m_CivTooltip.BG:DoAutoSize();
end
end
end
function CivilizationIcon:Reset()
if self.Controls.LocalPlayer then
self.Controls.LocalPlayer:SetHide(true);
end
if self.detailString ~= "" then
self.detailString = "";
end
end