Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- -- Created by Keaton VanAuken, Nov 13 2017
- -- Copyright (c) Firaxis Games
- --]]
- -- ===========================================================================
- -- Base File
- -- ===========================================================================
- include("CityStates");
- -- ===========================================================================
- -- Variables
- -- ===========================================================================
- local m_CityStateGovernors:table = {}
- local CITYSTATEBASE_DEFAULT_SIZEY :number = 48;
- local CQUI_InlineCityStateQuestFontSize = 10;
- local ICON_NAMES = {"%[ICON_TechBoosted%] ", "%[ICON_CivicBoosted%] ", "%[ICON_TradeRoute%] ", "%[ICON_Barbarian%] "};
- -- ===========================================================================
- -- CACHE BASE FUNCTIONS
- -- ===========================================================================
- BASE_GetData = GetData;
- BASE_AddCityStateRow = AddCityStateRow;
- BASE_AddInfluenceRow = AddInfluenceRow;
- -- ===========================================================================
- if Modding.IsModActive("1B28771A-C749-434B-9053-D1380C553DE9") or Modding.IsModActive("4873eb62-8ccc-4574-b784-dda455e74e68") then
- function GetData()
- BASE_GetData();
- m_CityStateGovernors = {};
- -- Check if any civilizations have assigned an ambassador to any city-state
- for i, pCityState in ipairs(PlayerManager.GetAliveMinors()) do
- local governorData:table = {
- Ambassadors = {},
- HasAnyAmbassador = false,
- };
- for j, PlayerID in ipairs(PlayerManager.GetAliveMajorIDs()) do
- local pPlayerGovernors:table = Players[PlayerID]:GetGovernors();
- for i,pCityStateCity in pCityState:GetCities():Members() do
- local pAssignedGovernor:table = pPlayerGovernors ~= nil and pPlayerGovernors:GetAssignedGovernor(pCityStateCity) or nil;
- if pAssignedGovernor ~= nil then
- governorData.Ambassadors[PlayerID] = true;
- governorData.HasAnyAmbassador = true;
- end
- end
- end
- m_CityStateGovernors[pCityState:GetID()] = governorData;
- end
- end
- -- ===========================================================================
- function AddCityStateRow( kCityState:table )
- local kInst:table = BASE_AddCityStateRow( kCityState );
- local ambassadorData:table = m_CityStateGovernors[kCityState.iPlayer];
- if ambassadorData.HasAnyAmbassador then
- kInst.AmbassadorButton:RegisterCallback( Mouse.eLClick, function() OpenSingleViewCityState( kCityState.iPlayer ); OnInfluencedByClick(); end );
- local tooltip = Locale.Lookup("LOC_CITY_STATE_PANEL_HAS_AMBASSADOR_TOOLTIP");
- local localPlayerID:number = Game.GetLocalPlayer();
- local pLocalPlayerDiplomacy = Players[localPlayerID]:GetDiplomacy();
- for playerID, playerHasAmbassador in pairs(ambassadorData.Ambassadors) do
- local playerConfig = PlayerConfigurations[playerID];
- if (playerID == localPlayerID or pLocalPlayerDiplomacy:HasMet(playerID)) then
- tooltip = tooltip .. Locale.Lookup("LOC_CITY_STATE_PANEL_HAS_AMBASSADOR_TOOLTIP_ENTRY", Locale.Lookup(playerConfig:GetCivilizationDescription()), Locale.Lookup(playerConfig:GetPlayerName()));
- else
- tooltip = tooltip .. Locale.Lookup("LOC_CITY_STATE_PANEL_HAS_AMBASSADOR_TOOLTIP_ENTRY_UNMET", Locale.Lookup("LOC_LOYALTY_PANEL_UNMET_CIV"));
- end
- end
- kInst.AmbassadorButton:SetToolTipString(tooltip);
- kInst.AmbassadorButton:SetHide(false);
- else
- kInst.AmbassadorButton:SetHide(true);
- end
- -- ==== BEGIN CQUI Modification ==== ----
- -- CQUI Inline City State Quests
- anyQuests = false;
- for _,kQuest in pairs( kCityState.Quests ) do
- anyQuests = true;
- questString = kQuest.Name;
- end
- if (anyQuests) then
- kInst.QuestIcon:SetHide(true);
- -- Adjust the size of the container based on the font size of the Inline City State Quest
- kInst.CityStateBase:SetSizeY(CITYSTATEBASE_DEFAULT_SIZEY + CQUI_InlineCityStateQuestFontSize - 2);
- kInst.QuestRow:SetHide(false);
- kInst.CityStateQuest:SetFontSize(CQUI_InlineCityStateQuestFontSize);
- kInst.CityStateQuest:SetString(CQUI_RemoveQuestIconsFromString(questString));
- kInst.CityStateQuest:SetColor(kCityState.ColorSecondary);
- else
- kInst.CityStateBase:SetSizeY(CITYSTATEBASE_DEFAULT_SIZEY);
- kInst.QuestRow:SetHide(true);
- end
- -- Determine the 2nd place (or first-place tie), produce text for Tooltip on the EnvoyCount label
- local envoyTable:table = {};
- -- Iterate through all players that have influenced this city state
- local localPlayerID = Game.GetLocalPlayer();
- for iOtherPlayer,influence in pairs(kCityState.Influence) do
- local pLocalPlayer :table = Players[localPlayerID];
- local civName :string = "LOCAL_CITY_STATES_UNKNOWN";
- local isLocalPlayer:boolean = false;
- if (pLocalPlayer ~= nil) then
- local pPlayerConfig :table = PlayerConfigurations[iOtherPlayer];
- if (localPlayerID == iOtherPlayer) then
- civName = Locale.Lookup("LOC_CITY_STATES_YOU") .. " (" .. Locale.Lookup(pPlayerConfig:GetPlayerName()) .. ")";
- isLocalPlayer = true;
- else
- if (pLocalPlayer:GetDiplomacy():HasMet(iOtherPlayer)) then
- civName = Locale.Lookup(pPlayerConfig:GetPlayerName());
- else
- civName = Locale.Lookup("LOCAL_CITY_STATES_UNKNOWN")
- end
- end
- table.insert(envoyTable, {Name = civName, EnvoyCount = influence, IsLocalPlayer = isLocalPlayer});
- end
- end
- if (#envoyTable > 0) then
- -- Sort the table by value descending, alphabetically where tied, favoring local player
- table.sort(envoyTable,
- function(a,b)
- if (a.EnvoyCount == b.EnvoyCount) then
- if (a.IsLocalPlayer) then
- return true;
- elseif (b.IsLocalPlayer) then
- return false;
- else
- return a.Name < b.Name;
- end
- else
- return a.EnvoyCount > b.EnvoyCount
- end
- end);
- local envoysToolTip = Locale.Lookup("LOC_CITY_STATES_ENVOYS_SENT")..":";
- for i=1, #envoyTable do
- envoysToolTip = envoysToolTip .. "[NEWLINE] - " .. envoyTable.Name .. ": " .. envoyTable.EnvoyCount;
- end
- kInst.EnvoyCount:SetToolTipString(envoysToolTip);
- if (#envoyTable > 1 and kInst.SecondHighestName ~= nil) then
- -- Show 2nd place if there is one (recall Lua tables/arrays start at index 1)
- -- The check on kInst.SecondHighestName is for cases where another mod replaces the XML, but not the citystates lua file
- local secondPlaceIdx = 2;
- -- is there a tie for first?
- if (envoyTable[1].EnvoyCount == envoyTable[2].EnvoyCount) then
- -- Already sorted above, so this is either local player or the leader appearing first alphabetically
- secondPlaceIdx = 1;
- end
- local secondHighestIsPlayer = envoyTable[secondPlaceIdx].IsLocalPlayer;
- local secondHighestName = envoyTable[secondPlaceIdx].Name;
- local secondHighestEnvoys = envoyTable[secondPlaceIdx].EnvoyCount;
- if (secondHighestIsPlayer) then
- secondHighestName = Locale.Lookup("LOC_CITY_STATES_YOU");
- end
- -- Add changes to the actual UI object placeholders, which are created in the CityStates.xml file
- kInst.SecondHighestName:SetColor(secondHighestIsPlayer and kCityState.ColorSecondary or COLOR_ICON_BONUS_OFF);
- kInst.SecondHighestName:SetText(secondHighestName);
- kInst.SecondHighestEnvoys:SetColor(secondHighestIsPlayer and kCityState.ColorSecondary or COLOR_ICON_BONUS_OFF);
- kInst.SecondHighestEnvoys:SetText(secondHighestEnvoys);
- end
- end
- -- ============ END CQUI Modification ===================[/code]
- return kInst;
- end
- -- ===========================================================================
- function AddInfluenceRow(cityStateID:number, playerID:number, influence:number, largestInfluence:number)
- local kItem:table = BASE_AddInfluenceRow(cityStateID, playerID, influence, largestInfluence);
- local playerConfig:table = PlayerConfigurations[playerID];
- local localPlayerID:number = Game.GetLocalPlayer();
- local playerHasAmbassador:boolean = m_CityStateGovernors[cityStateID] and m_CityStateGovernors[cityStateID].Ambassadors[playerID] or false;
- kItem.AmbassadorIcon:SetHide(not playerHasAmbassador);
- local pLocalPlayerDiplomacy = Players[localPlayerID]:GetDiplomacy();
- local playerName:string = Locale.Lookup("LOC_LOYALTY_PANEL_UNMET_CIV");
- if (playerID == localPlayerID or pLocalPlayerDiplomacy:HasMet(playerID)) then
- playerName = playerConfig:GetPlayerName();
- end
- kItem.AmbassadorIcon:SetToolTipString(Locale.Lookup("LOC_CITY_STATE_PANEL_CIV_AMBASSADOR_TOOLTIP", playerName));
- return kItem;
- end
- end
- function CQUI_RemoveQuestIconsFromString( inStr:string )
- local lookupStr :string = inStr;
- local outStr :string = lookupStr;
- for _,iconName in ipairs(ICON_NAMES) do
- if (string.find(lookupStr, iconName)) then
- outStr = string.gsub(lookupStr, iconName, "");
- end
- end
- return outStr;
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement