Back to Home

ESO Lua File v100036

ingame/battleground/battlegroundhud.lua

[◄ back to folders ]
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
local COUNTDOWN_TIMER_START_MS = 5000
local COUNTDOWN_TIMER_END_BATTLEGROUND_MS = ZO_ONE_MINUTE_IN_MILLISECONDS
--------------------
--Battleground HUD Fragment
--------------------
local BattlegroundHUDFragment = ZO_HUDFadeSceneFragment:Subclass()
function BattlegroundHUDFragment:New(...)
    return ZO_HUDFadeSceneFragment.New(self, ...)
end
function BattlegroundHUDFragment:Initialize(control)
    ZO_HUDFadeSceneFragment.Initialize(self, control)
    self.currentBattlegroundTimeMS = 0
    self.keybindButton = control:GetNamedChild("KeybindButton")
    self.keybindButton:SetKeybind("SHOW_BATTLEGROUND_SCOREBOARD")
    
    self.headerLabel = control:GetNamedChild("Header")
    self.stateLabel = control:GetNamedChild("State")
    
    self.battlegroundScoreHudControl = control:GetNamedChild("BattlegroundScoreHud")
    control:RegisterForEvent(EVENT_PLAYER_ACTIVATED, function() self:OnPlayerActivated() end)
    control:RegisterForEvent(EVENT_BATTLEGROUND_RULESET_CHANGED, function() self:OnBattlegroundRulesetChanged() end)
end
do
    local KEYBOARD_STYLE = 
    {
        hudTemplate = "ZO_BattlegroundHudTopLevel_Keyboard",
        keybindButtonTemplate = "ZO_KeybindButton_Keyboard_Template",
    }
    local GAMEPAD_STYLE = 
    {
        hudTemplate = "ZO_BattlegroundHudTopLevel_Gamepad",
        keybindButtonTemplate = "ZO_KeybindButton_Gamepad_Template",
    }
    function BattlegroundHUDFragment:InitializePlatformStyle()
        self.platformStyle = ZO_PlatformStyle:New(function(style) self:ApplyPlatformStyle(style) end, KEYBOARD_STYLE, GAMEPAD_STYLE)
    end
end
function BattlegroundHUDFragment:ApplyPlatformStyle(style)
    ApplyTemplateToControl(self.control, style.hudTemplate)
    ApplyTemplateToControl(self.keybindButton, style.keybindButtonTemplate)
    self.headerLabel:SetText(GetString(SI_BATTLEGROUND_HUD_HEADER))
end
function BattlegroundHUDFragment:OnPlayerActivated()
end
function BattlegroundHUDFragment:OnBattlegroundRulesetChanged()
end
function BattlegroundHUDFragment:CheckForBattleground()
    local currentBattlegroundId = GetCurrentBattlegroundId()
    if currentBattlegroundId ~= 0 then
        EVENT_MANAGER:RegisterForUpdate(self.control:GetName(), 10, function() self:OnUpdate() end)
    else
        EVENT_MANAGER:UnregisterForUpdate(self.control:GetName())
    end
end
function BattlegroundHUDFragment:GetFormattedTimer()
    return ZO_FormatTime(zo_ceil(self.currentBattlegroundTimeMS / 1000), TIME_FORMAT_STYLE_COLONS, TIME_FORMAT_PRECISION_SECONDS, TIME_FORMAT_DIRECTION_DESCENDING)
end
do
    local PRE_SHUTDOWN_WARNING_TIME_MS = 10000
    local PRE_SHUTDOWN_WARNING_TIME_S = zo_round(PRE_SHUTDOWN_WARNING_TIME_MS / 1000)
    function BattlegroundHUDFragment:OnUpdate()
        local battlegroundState = GetCurrentBattlegroundState()
        local previousBattlegroundTimeMS = self.currentBattlegroundTimeMS
        self.currentBattlegroundTimeMS = GetCurrentBattlegroundStateTimeRemaining()
        local previousShutdownTimerMS = self.shutdownTimerMS
        self.shutdownTimerMS = GetCurrentBattlegroundShutdownTimer()
    
        local text
        if battlegroundState == BATTLEGROUND_STATE_PREGAME then
            text = zo_strformat(SI_BATTLEGROUND_STATE_PREGAME, self:GetFormattedTimer())
            if self.currentBattlegroundTimeMS <= PRE_SHUTDOWN_WARNING_TIME_MS and previousBattlegroundTimeMS > PRE_SHUTDOWN_WARNING_TIME_MS then
                local shutdownImminentMessage = zo_strformat(SI_BATTLEGROUND_SHUTDOWN_IMMINENT, PRE_SHUTDOWN_WARNING_TIME_S)
                CHAT_ROUTER:AddSystemMessage(shutdownImminentMessage)
                ZO_Alert(UI_ALERT_CATEGORY_ALERT, nil, shutdownImminentMessage)
            end 
        elseif battlegroundState == BATTLEGROUND_STATE_STARTING then
            if IsCurrentBattlegroundStateTimed() then
                if self.currentBattlegroundTimeMS <= COUNTDOWN_TIMER_START_MS then
                    text = GetString(SI_BATTLEGROUND_STATE_STARTING_COUNTDOWN)
                    if previousBattlegroundTimeMS > COUNTDOWN_TIMER_START_MS then
                        local messageParams = CENTER_SCREEN_ANNOUNCE:CreateMessageParams(CSA_CATEGORY_COUNTDOWN_TEXT, SOUNDS.BATTLEGROUND_COUNTDOWN_FINISH )
                        messageParams:SetLifespanMS(COUNTDOWN_TIMER_START_MS)
                        messageParams:SetIconData(GetCountdownBattlegroundAllianceSymbolIcon(GetUnitBattlegroundAlliance("player")))
                        messageParams:SetCSAType(CENTER_SCREEN_ANNOUNCE_TYPE_COUNTDOWN)
                        CENTER_SCREEN_ANNOUNCE:AddMessageWithParams(messageParams)
                    end
                else
                    local gameTypeString = GetString("SI_BATTLEGROUNDGAMETYPE", GetBattlegroundGameType(GetCurrentBattlegroundId()))
                    text = zo_strformat(SI_BATTLEGROUND_STATE_STARTING, gameTypeString, self:GetFormattedTimer())
                end
            end
        elseif battlegroundState == BATTLEGROUND_STATE_RUNNING then
            if IsCurrentBattlegroundStateTimed() then
                local gameTypeString = GetString("SI_BATTLEGROUNDGAMETYPE", GetBattlegroundGameType(GetCurrentBattlegroundId()))
                gameTypeString = ZO_NORMAL_TEXT:Colorize(gameTypeString)
                text = zo_strformat(SI_BATTLEGROUND_STATE_RUNNING, gameTypeString, self:GetFormattedTimer())
                if self.currentBattlegroundTimeMS <= COUNTDOWN_TIMER_END_BATTLEGROUND_MS and previousBattlegroundTimeMS > COUNTDOWN_TIMER_END_BATTLEGROUND_MS then
                    local messageParams = CENTER_SCREEN_ANNOUNCE:CreateMessageParams(CSA_CATEGORY_MAJOR_TEXT, SOUNDS.BATTLEGROUND_ONE_MINUTE_WARNING)
                    messageParams:SetText(GetString(SI_BATTLEGROUND_WARNING_ONE_MINUTE_REMAINING))
                    messageParams:SetCSAType(CENTER_SCREEN_ANNOUNCE_TYPE_BATTLEGROUND_MINUTE_WARNING)
                    CENTER_SCREEN_ANNOUNCE:AddMessageWithParams(messageParams)
                end
            end
            if previousShutdownTimerMS and self.shutdownTimerMS then
                if previousShutdownTimerMS >= PRE_SHUTDOWN_WARNING_TIME_MS and self.shutdownTimerMS < PRE_SHUTDOWN_WARNING_TIME_MS then
                    local shutdownImminentMessage = zo_strformat(SI_BATTLEGROUND_SHUTDOWN_IMMINENT, PRE_SHUTDOWN_WARNING_TIME_S)
                    CHAT_ROUTER:AddSystemMessage(shutdownImminentMessage)
                    ZO_Alert(UI_ALERT_CATEGORY_ALERT, nil, shutdownImminentMessage)
                end
            end
        elseif battlegroundState == BATTLEGROUND_STATE_FINISHED then
            if IsCurrentBattlegroundStateTimed() then
                text = zo_strformat(SI_BATTLEGROUND_STATE_FINISHED, self:GetFormattedTimer())
            end
        end
        if text then
            self.stateLabel:SetHidden(false)
            self.stateLabel:SetText(text)
        else
            self.stateLabel:SetHidden(true)
        end
    end
end
function BattlegroundHUDFragment:GetStateText()
    return self.stateLabel:GetText()
end
--[[ xml functions ]]--
    BATTLEGROUND_HUD_FRAGMENT = BattlegroundHUDFragment:New(control)
end