forked from civfanatics/Civ6-UIFiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PortraitSupport.lua
106 lines (89 loc) · 3.59 KB
/
PortraitSupport.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
-- Copyright 2019, Firaxis Games
-- Support for (unit) portraits.
-- ===========================================================================
function GetUnitPortraitPrefix( playerID:number )
local iconPrefix:string = "ICON_";
-- Add civilization ethnicity
local playerConfig:table = PlayerConfigurations[playerID];
local civ:table = GameInfo.Civilizations[playerConfig:GetCivilizationTypeID()];
if civ then
-- Barbarians don't have an ethnicity field so make sure it exists
if civ.Ethnicity and civ.Ethnicity ~= "ETHNICITY_EURO" then
iconPrefix = iconPrefix .. civ.Ethnicity .. "_";
end
end
return iconPrefix;
end
-- ===========================================================================
function GetUnitPortraitEraSuffix( playerID:number )
-- Era system changed between BASE and XP1
-- XP1+...
if Game.GetEras ~= nil then
local pGameEras :table = Game.GetEras();
local eraName :string = GameInfo.Eras[ pGameEras:GetCurrentEra() ].EraType;
return "_PORTRAIT_" .. eraName;
end
-- BASE
local pPlayer = Players[playerID];
if pPlayer ~= nil then
local eraIndex = pPlayer:GetEra() + 1;
for row:table in GameInfo.Eras() do
if row.ChronologyIndex == eraIndex then
return "_" .. row.EraType;
end
end
else
UI.DataError("PortraitSupport could not find a suffix for Player ID '"..tostring(playerID));
end
return "";
end
-- ===========================================================================
function GetGreatPersonGenderSuffix( pUnit:table )
local pGreatPerson :table = pUnit:GetGreatPerson();
if pGreatPerson and pGreatPerson:IsGreatPerson() then
local greatPersonDetails = GameInfo.GreatPersonIndividuals[pGreatPerson:GetIndividual()];
if greatPersonDetails.Gender == "F" then -- female?
return "_F";
end
end
return "";
end
-- ===========================================================================
-- Obtain potential names for a unit portrait.
-- RETURNS:
--
--
--
-- ===========================================================================
function GetUnitPortraitIconNames( pUnit:table )
if pUnit == nil then
UI.DataError("Unable to GetUnitPortrait() for a NIL unit.");
return;
end
local playerID :number = pUnit:GetOwner();
local pUnitDef :table = GameInfo.Units[pUnit:GetUnitType()];
local prefix :string = GetUnitPortraitPrefix( playerID )..pUnitDef.UnitType;
local suffix :string = GetUnitPortraitEraSuffix( playerID )
local genderSuffix :string = GetGreatPersonGenderSuffix( pUnit );
local iconName :string = prefix ..suffix;
local prefixOnlyIconName :string = prefix .."_PORTRAIT";
local eraOnlyIconName :string = "ICON_"..pUnitDef.UnitType..suffix..genderSuffix;
local fallbackIconName :string = "ICON_"..pUnitDef.UnitType.."_PORTRAIT"..genderSuffix;
return iconName, prefixOnlyIconName, eraOnlyIconName, fallbackIconName;
end
-- ===========================================================================
-- Obtain potential names for a unit portrait based on a definition and player.
-- RETURNS:
--
--
--
-- ===========================================================================
function GetUnitPortraitIconNamesFromDefinition( playerID:number, pUnitDef:table )
local prefix :string = GetUnitPortraitPrefix( playerID )..pUnitDef.UnitType;
local suffix :string = GetUnitPortraitEraSuffix( playerID )
local iconName :string = prefix ..suffix;
local prefixOnlyIconName :string = prefix .."_PORTRAIT";
local eraOnlyIconName :string = "ICON_"..pUnitDef.UnitType..suffix;
local fallbackIconName :string = "ICON_"..pUnitDef.UnitType.."_PORTRAIT";
return iconName, prefixOnlyIconName, eraOnlyIconName, fallbackIconName;
end