UIElement.SetUpdate (Civ5 API)

From Civilization Modding Wiki
Revision as of 14:21, 20 September 2012 by DonQuich (talk | contribs) (Bot update)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

This page is a part of the Lua and UI Reference (Civ5).


Function.png This method is declared by Context.

This is an instance method, invoke it with a colon.


Usage

void UIElement:SetUpdate((void func(float fTimeDelta)) UpdateHandler)


Parameters

UpdateHandler: No description available.


Source code samples

Too many occurences. Only 50 out of 25 are listed.

CivsAlive.lua - DLC_01 DLC

DLC/DLC_01/Scenarios/Mongol Scenario/CivsAlive.lua
0031
ContextPtr:SetUpdate(function()
0032
if (Game.GetGameState() == GameplayGameStateTypes.GAMESTATE_ON) then
0033
-- Display victory information
0034
local iRemainingToDestroy, iTurnsRemaining = GetVictoryValues();
0035
Controls.CivsAliveLabel:LocalizeAndSetText("TXT_KEY_MONGOL_SCENARIO_CIVSALIVE", iRemainingToDestroy, iTurnsRemaining);
0036
Controls.Grid:DoAutoSize();
0037
else
0038
-- Game over, hide the UI
0039
ContextPtr:ClearUpdate();
0040
ContextPtr:SetHide( true );
0041
end
0042
end);


CustomMod.lua

UI/FrontEnd/Modding/CustomMod.lua
0058
ContextPtr:SetUpdate( function()
0059
if(g_ModList == nil) then
0060
SetupFileButtonList();
0061
end
0062
end);


DebugMenu.lua

UI/InGame/DebugMenu.lua
0293
ContextPtr:SetUpdate( UpdateHandler );


EndGameMenu.lua

UI/InGame/Popups/EndGameMenu.lua
0108
ContextPtr:SetUpdate( OnUpdate );


InstalledPanel.lua

UI/FrontEnd/Modding/InstalledPanel.lua
0489
ContextPtr:SetUpdate(OnUpdate);


NetworkDebug.lua

UI/InGame/NetworkDebug.lua
0050
ContextPtr:SetUpdate(UpdateNetworkDisplay);


TurnsRemaining.lua - DLC_02 DLC

DLC/DLC_02/Scenarios/NewWorldScenario/TurnsRemaining.lua
0004
ContextPtr:SetUpdate(function()
0006
local iTurnsRemaining = 100 - Game.GetGameTurn();
0007
if (iTurnsRemaining < 1) then
0008
Game.SetGameState(GameplayGameStateTypes.GAMESTATE_OVER);
0009
ContextPtr:ClearUpdate();
0010
ContextPtr:SetHide( true );
0011
end
0012
-- Loop through all the Majors
0013
for iPlayerLoop = 0, GameDefines.MAX_MAJOR_CIVS-1, 1 do
0015
   local player = Players[iPlayerLoop];
0016
   if (player:IsAlive()) then
0018
   if (player:GetScore() >= 1000) then
0019
   print(string.format("Player %i has won w/ a score of %i", iPlayerLoop, player:GetScore()));
0020
   Game.SetWinner(player:GetTeam(), GameInfo.Victories["VICTORY_DOMINATION"].ID);
0021
   ContextPtr:ClearUpdate();
0022
   ContextPtr:SetHide( true );
0023
   end
0024
   end
0025
   end
0027
   Controls.TurnsRemainingLabel:LocalizeAndSetText("TXT_KEY_NEWWORLD_SCENARIO_TURNSREMAINING", iTurnsRemaining);
0028
   Controls.Grid:DoAutoSize();
0029
   end);


TurnsRemaining.lua - DLC_04 DLC

DLC/DLC_04/Scenarios/1066Scenario/TurnsRemaining.lua
0004
ContextPtr:SetUpdate(function()
0006
local iTurnsRemaining = 70 - Game.GetGameTurn();
0007
local iOtherLeadersAlive = 0;
0008
local iLondonPlayer = -1;
0010
-- Loop through all the Majors checking for victory
0011
for iPlayerLoop = 0, GameDefines.MAX_MAJOR_CIVS-1, 1 do
0013
   local player = Players[iPlayerLoop];
0014
   if (player:IsAlive()) then
0016
   iOtherLeadersAlive = iOtherLeadersAlive + 1;
0018
   -- Controls London?
0019
   local pLondon = Map.GetPlot(43,17):GetPlotCity();
0020
   if (pLondon:GetOwner() == iPlayerLoop) then
0021
   iLondonPlayer = iPlayerLoop;
0022
   if (pLondon:GetNumBuilding(GameInfo.Buildings["BUILDING_NATIONAL_COLLEGE"].ID) > 0) then
0023
   Game.SetWinner(player:GetTeam(), GameInfo.Victories["VICTORY_DOMINATION"].ID);
0024
   ContextPtr:ClearUpdate();
0025
   ContextPtr:SetHide( true );
0026
   end
0027
   end
0028
   end
0029
   end
0032
   if (iTurnsRemaining < 1 or Game.GetGameState() == GameplayGameStateTypes.GAMESTATE_EXTENDED) then
0033
   Game.SetGameState(GameplayGameStateTypes.GAMESTATE_OVER);
0034
   ContextPtr:ClearUpdate();
0035
   ContextPtr:SetHide( true );
0037
   elseif (iOtherLeadersAlive == 0) then
0038
   Game.SetWinner(Players[Game.GetActivePlayer()]:GetTeam(), GameInfo.Victories["VICTORY_DOMINATION"].ID);
0039
   ContextPtr:SetHide( true );
0041
   else
0042
   local londonText;
0043
   local shireCourtText;
0044
   local turnsRemainingText = Locale.ConvertTextKey("TXT_KEY_1066_SCENARIO_TURNSREMAINING", iTurnsRemaining);
0045
   if (iLondonPlayer ~= -1) then
0046
   local londonText = Locale.ConvertTextKey("TXT_KEY_1066_SCENARIO_LONDON_STATUS", Players[iLondonPlayer]:GetCivilizationShortDescriptionKey());
0047
   local shireCourtText = Locale.ConvertTextKey("TXT_KEY_1066_SCENARIO_SHIRE_COURT_STATUS", Players[iLondonPlayer]:CountNumBuildings(GameInfo.Buildings["BUILDING_COURTHOUSE"].ID));
0048
   turnsRemainingText = turnsRemainingText .. "[NEWLINE]" .. londonText .. "[NEWLINE]" .. shireCourtText;
0049
   end
0050
   Controls.TurnsRemainingLabel:LocalizeAndSetText(turnsRemainingText);
0051
   Controls.Grid:DoAutoSize();
0052
   end
0053
   end);


TurnsRemaining.lua (G&K)

DLC/Expansion/Scenarios/MedievalScenario/TurnsRemaining.lua
0074
ContextPtr:SetUpdate(function()
0076
if (g_ScenarioDone) then
0077
ContextPtr:ClearUpdate();
0078
ContextPtr:SetHide( true );
0079
end
0081
local iTurnsRemaining = 200 - Game.GetGameTurn();
0082
local turnsRemainingText = Locale.ConvertTextKey("TXT_KEY_MEDIEVAL_SCENARIO_TURNSREMAINING", iTurnsRemaining);
0083
Controls.TurnsRemainingLabel:LocalizeAndSetText(turnsRemainingText);
0084
Controls.Grid:DoAutoSize();
0086
end);


TurnsRemaining.lua (G&K)

DLC/Expansion/Scenarios/FallOfRomeScenario/TurnsRemaining.lua
0007
ContextPtr:SetUpdate(function()
0009
if (g_ScenarioDone) then
0010
ContextPtr:ClearUpdate();
0011
ContextPtr:SetHide( true );
0012
end
0014
local iTurnsRemaining = g_iGameTurnLength - Game.GetGameTurn();
0015
local turnsRemainingText = Locale.ConvertTextKey("TXT_KEY_FOR_SCENARIO_TURNS_REMAINING", iTurnsRemaining);
0016
Controls.TurnsRemainingLabel:LocalizeAndSetText(turnsRemainingText);
0017
Controls.Grid:DoAutoSize();
0019
end);


TurnsRemaining.lua (G&K)

DLC/Expansion/Scenarios/SteampunkScenario/TurnsRemaining.lua
0082
ContextPtr:SetUpdate(function()
0083
if (gbScenarioDone) then
0084
ContextPtr:ClearUpdate();
0085
end
0087
if (not gbUpdated) then
0088
local iActivePlayer = Game.GetActivePlayer();
0089
local strStatus = Locale.Lookup("TXT_KEY_STEAMPUNK_SCENARIO_TURNS_REMAINING", GetNumTokensOwned(iActivePlayer), GetNumTokensUnlocked(Game.GetGameTurn() - 1)); --antonjs: consider: keep var for last turn updated
0090
if (giPlayerAboutToWin == iActivePlayer) then
0091
strStatus = "[COLOR_POSITIVE_TEXT]" .. strStatus .. "[ENDCOLOR]";
0092
elseif (giPlayerAboutToWin ~= -1) then
0093
strStatus = "[COLOR_WARNING_TEXT]" .. strStatus .. "[ENDCOLOR]";
0094
end
0095
Controls.QuickStatusLabel:SetText(strStatus);
0096
gbUpdated = true;
0097
end
0099
Controls.Grid:DoAutoSize();
0100
end);


VictoryStatus.lua (G&K)

DLC/Expansion/Scenarios/SteampunkScenario/VictoryStatus.lua
0072
ContextPtr:SetUpdate(function()
0073
if (not gbUpdated) then
0074
local iActivePlayer = Game:GetActivePlayer();
0076
local iTokensNeededForVictory = GetTokensNeededForVictory();
0077
local sHelpText = Locale.Lookup("TXT_KEY_STEAMPUNK_SCENARIO_VICTORY_HELP", iTokensNeededForVictory, GetTurnsMustHoldForVictory());
0078
sHelpText = sHelpText .. "[NEWLINE][NEWLINE]";
0079
if (not IsVictoryPossible(giYearUpdated)) then
0080
sHelpText = sHelpText .. Locale.Lookup("TXT_KEY_STEAMPUNK_SCENARIO_VICTORY_LOCKED") .. "  ";
0081
elseif (giPlayerAboutToWin ~= -1) then
0082
local iTurnsUntilWin = GetTurnsMustHoldForVictory() - giTurnsControlHeld;
0083
if (iTurnsUntilWin < 0) then
0084
iTurnsUntilWin = 0;
0085
end
0086
local sCivAboutToWinKey = Players[giPlayerAboutToWin]:GetCivilizationShortDescriptionKey();
0087
local sCountdownText = Locale.Lookup("TXT_KEY_STEAMPUNK_SCENARIO_VICTORY_COUNTDOWN", iTurnsUntilWin, sCivAboutToWinKey) .. "  ";
0088
if (giPlayerAboutToWin == iActivePlayer) then
0089
sCountdownText = "[COLOR_POSITIVE_TEXT]" .. sCountdownText .. "[ENDCOLOR]";
0090
else
0091
sCountdownText = "[COLOR_WARNING_TEXT]" .. sCountdownText .. "[ENDCOLOR]";
0092
end
0093
sHelpText = sHelpText .. sCountdownText;
0094
end
0095
sHelpText = sHelpText .. Locale.Lookup("TXT_KEY_STEAMPUNK_SCENARIO_VICTORY_POSSIBLE", giYearUpdated); --antonjs: todo: separate line, general UI stuff
0096
Controls.HelpLabel:SetText(sHelpText);
0098
for s,t in pairs(ktTokens) do
0099
   local bUnlocked = IsTokenUnlocked(s, giTurnUpdated);
0101
   gtTokenUI[s].TitleLabel:SetText(t.Title .. "  ");
0102
   gtTokenUI[s].PortraitFrame:SetHide(true);
0104
   local sLabelText = "[ICON_LOCKED]  ";
0105
   if (bUnlocked) then
0106
   sLabelText = "[ICON_BULLET]  ";
0107
   end
0108
   sLabelText = sLabelText .. t.Help .. "[NEWLINE]      ";
0109
   local iNumInList = 0;
0110
   for iPlayer = 0, GameDefines.MAX_MAJOR_CIVS - 1, 1 do
0111
   if (Players[iPlayer]:IsAlive()) then
0112
   if (iNumInList ~= 0) then
0113
   sLabelText = sLabelText .. ", ";
0114
   end
0115
   iNumInList = iNumInList + 1;
0117
   local sCivDesc = Locale.Lookup(Players[iPlayer]:GetCivilizationShortDescriptionKey());
0118
   if (iPlayer == iActivePlayer) then
0119
   sCivDesc = Locale.Lookup("TXT_KEY_YOU");
0120
   end
0121
   sCivDesc = sCivDesc .. ": " .. gtPlayerStatus[iPlayer][s].Value;
0122
   if (gtPlayerStatus[iPlayer][s].Owned) then
0123
   sCivDesc = "[COLOR_POSITIVE_TEXT]" .. sCivDesc .. "[ENDCOLOR]";
0124
   local pPlayer = Players[iPlayer];
0125
   if (pPlayer ~= nil) then
0126
   local tLeader = GameInfo.Leaders[pPlayer:GetLeaderType()];
0127
   IconHookup( tLeader.PortraitIndex, 64, tLeader.IconAtlas, gtTokenUI[s].Portrait );
0128
   gtTokenUI[s].PortraitFrame:SetHide(false);
0129
   else
0130
   print("SCRIPTING ERROR: Got nil when looking for player that owns a Title");
0131
   end
0133
   end
0134
   sLabelText = sLabelText .. sCivDesc;
0135
   end
0136
   end
0137
   local sLabelTT = GetTokenTooltip(s, iActivePlayer);
0138
   gtTokenUI[s].TokenLabel:SetText(sLabelText);
0139
   gtTokenUI[s].TokenLabel:SetToolTipString(sLabelTT);
0140
   end
0142
   gbUpdated = true;
0143
   end
0144
   end);



The initial version of this page was created by the Civ5 API Bot, see the Civ5 API Reference FAQ. Some of the texts come from the 2kgames' wiki and most of code samples are copyrighted to Firaxis.
Functions' signatures were either copied from the 2kgames' wiki, or infered from the Lua source files and the binaries. Errors are possible.
Contributors may find help in the Contributors guide to the Civ5 API.