forked from Azurency/Civ6-UIFiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlayerSupport.lua
57 lines (51 loc) · 2.27 KB
/
PlayerSupport.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
-- Copyright (c) 2018 Firaxis Games
function GetMetPlayersAndUniqueLeaders()
local metPlayers:table = {};
local isUniqueLeader:table = {};
local aPlayers:table = PlayerManager.GetAliveMajors();
local pDiplomacy:table = Players[Game.GetLocalPlayer()]:GetDiplomacy();
for _, pPlayer in ipairs(aPlayers) do
local playerID:number = pPlayer:GetID();
if playerID ~= localPlayerID then
local playerMet:boolean = pDiplomacy:HasMet(playerID);
if playerMet then
local leaderName:string = PlayerConfigurations[playerID]:GetLeaderTypeName();
if (isUniqueLeader[playerID] == nil) then
isUniqueLeader[playerID] = true;
else
isUniqueLeader[playerID] = false;
end
end
metPlayers[playerID] = playerMet;
end
end
return metPlayers, isUniqueLeader;
end
-- metPlayers parameter is optional, cache the return value from GetMetPlayersAndUniqueLeaders and pass it in as a parameter within loops
function GetPlayerName(playerID:number, metPlayers:table)
if not metPlayers then metPlayers = GetMetPlayersAndUniqueLeaders(); end
local localPlayerID:number = Game.GetLocalPlayer();
local playerMet:boolean = playerID == localPlayerID or metPlayers[playerID];
local pPlayerConfig:table = PlayerConfigurations[playerID];
local isHuman:boolean = pPlayerConfig:IsHuman();
if playerMet or (GameConfiguration.IsAnyMultiplayer() and isHuman) then
local civName:string = pPlayerConfig:GetCivilizationTypeName();
local leaderName:string = pPlayerConfig:GetLeaderTypeName();
local leaderDesc:string = pPlayerConfig:GetLeaderName();
if GameConfiguration.IsAnyMultiplayer() and isHuman then
if(playerID ~= localPlayerID and not playerMet) then
return Locale.Lookup("LOC_DIPLOPANEL_UNMET_PLAYER") .. " (" .. pPlayerConfig:GetPlayerName() .. ")", "ICON_LEADER_DEFAULT", "ICON_CIVILIZATION_UNKNOWN";
else
return Locale.Lookup(leaderDesc) .. " (" .. pPlayerConfig:GetPlayerName() .. ")", "ICON_"..leaderName, "ICON_" .. civName;
end
else
if(playerID ~= localPlayerID and not playerMet) then
return "LOC_DIPLOPANEL_UNMET_PLAYER", "ICON_LEADER_DEFAULT", "ICON_CIVILIZATION_UNKNOWN";
else
return leaderDesc, "ICON_"..leaderName, "ICON_" .. civName;
end
end
else
return "LOC_DIPLOPANEL_UNMET_PLAYER", "ICON_LEADER_DEFAULT", "ICON_CIVILIZATION_UNKNOWN";
end
end