Back to Home

ESO Lua File v100032

ingame/battleground/battlegroundscoreboardendofgame.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
--------------------------------------------
--Battleground Scoreboard End Of Game Scene
--------------------------------------------
local LEAVE_BATTLEGROUND_KEYBIND_COOLDOWN_MS = 2000
local KEYBIND_BUTTON_SPACING_X = 10
ZO_Battleground_Scoreboard_End_Of_Game = ZO_Object:Subclass()
function ZO_Battleground_Scoreboard_End_Of_Game:New(...)
    local scoreboard = ZO_Object.New(self)
    scoreboard:Initialize(...)
    return scoreboard
end
function ZO_Battleground_Scoreboard_End_Of_Game:Initialize(control)
    self.control = control
    self.closingTimerLabel = control:GetNamedChild("ClosingTimer")
    BATTLEGROUND_SCOREBOARD_END_OF_GAME_OPTIONS = ZO_HUDFadeSceneFragment:New(control)
    
    BATTLEGROUND_SCOREBOARD_END_OF_GAME_SCENE = ZO_Scene:New("battleground_scoreboard_end_of_game", SCENE_MANAGER)
    BATTLEGROUND_SCOREBOARD_END_OF_GAME_SCENE:RegisterCallback("StateChange", function(oldState, newState)
        if newState == SCENE_SHOWING then
            self:OnShowing()
        elseif newState == SCENE_HIDING then
            self:OnHiding()
        end
    end)
    -- the loot history fragments may not exist depending on the platform
    if GAMEPAD_LOOT_HISTORY_FRAGMENT then
        BATTLEGROUND_SCOREBOARD_END_OF_GAME_SCENE:AddFragment(GAMEPAD_LOOT_HISTORY_FRAGMENT)
    end
    if KEYBOARD_LOOT_HISTORY_FRAGMENT then
        BATTLEGROUND_SCOREBOARD_END_OF_GAME_SCENE:AddFragment(KEYBOARD_LOOT_HISTORY_FRAGMENT)
    end
    local function OnGamepadModeChanged()
        self:RefreshMatchInfoFragments()
        -- End game doesn't close the UI when gamepad mode switches, but it shares the same fragment is in game,
        -- so only in end game do we want to make sure that the match info gets refreshed on switching fragments
        BATTLEGROUND_SCOREBOARD_FRAGMENT:RefreshMatchInfoDisplay()
    end
    local function OnBattlegroundStateChanged(eventId, previousState, currentState)
        -- prevent people from accidentally leaving the BG because they are fighting to the bitter end
        if currentState == BATTLEGROUND_STATE_POSTGAME and IsInGamepadPreferredMode() then
            self.leaveBattlegroundKeybind:SetCooldown(LEAVE_BATTLEGROUND_KEYBIND_COOLDOWN_MS)
        end
    end
    EVENT_MANAGER:RegisterForEvent("BattlegroundScoreboardEndOfGame", EVENT_GAMEPAD_PREFERRED_MODE_CHANGED, OnGamepadModeChanged)
    EVENT_MANAGER:RegisterForEvent("BattlegroundScoreboardEndOfGame", EVENT_BATTLEGROUND_STATE_CHANGED, OnBattlegroundStateChanged)
    SYSTEMS:RegisterKeyboardRootScene("battleground_scoreboard_end_of_game", BATTLEGROUND_SCOREBOARD_END_OF_GAME_SCENE)
    SYSTEMS:RegisterGamepadRootScene("battleground_scoreboard_end_of_game", BATTLEGROUND_SCOREBOARD_END_OF_GAME_SCENE)
    self.scene = BATTLEGROUND_SCOREBOARD_END_OF_GAME_SCENE
    SCENE_MANAGER:SetSceneRestoresBaseSceneOnGameMenuToggle("battleground_scoreboard_end_of_game", true)
    self:UpdateAll()
end
function ZO_Battleground_Scoreboard_End_Of_Game:InitializeKeybinds()
    local keybindContainer = self.control:GetNamedChild("KeybindContainer")
    self.keybindNameTextMap = {}
    self.keybindActionMap = {}
    local keybindButtonIndex = 1
    local previousKeybindControl
    local function CreateKeybindButton(keybind, callbackFunction, text)
        -- Make and anchor the button
        local keybindControl = CreateControlFromVirtual("$(parent)KeybindButton" .. keybindButtonIndex, keybindContainer, "ZO_KeybindButton")
        ZO_KeybindButtonTemplate_Setup(keybindControl, keybind, callbackFunction, text)
        if previousKeybindControl then
            keybindControl:SetAnchor(LEFT, previousKeybindControl, RIGHT, KEYBIND_BUTTON_SPACING_X, 0)
        else
            keybindControl:SetAnchor(TOPLEFT)
        end
        -- Keep track of the control for gamepad switching
        keybindControl.nameLabel = keybindControl:GetNamedChild("NameLabel")
        self.keybindNameTextMap[keybindControl] = text
        -- Keep track of the keybind mapping to handle the key being pressed
        self.keybindActionMap[keybind] = keybindControl
        keybindButtonIndex = keybindButtonIndex + 1
        previousKeybindControl = keybindControl
        return keybindControl
    end
    self.playerOptionsButton = CreateKeybindButton("BATTLEGROUND_SCOREBOARD_PLAYER_OPTIONS", function() BATTLEGROUND_SCOREBOARD_FRAGMENT:ShowGamepadPlayerMenu() end, GetString(SI_BATTLEGROUND_SCOREBOARD_PLAYER_OPTIONS_KEYBIND))
    self.leaveBattlegroundKeybind = CreateKeybindButton("LEAVE_BATTLEGROUND", function() self:OnLeaveBattlegroundPressed() end, GetString(SI_BATTLEGROUND_SCOREBOARD_END_OF_GAME_LEAVE_KEYBIND))
    self.previousPlayerButton = CreateKeybindButton("BATTLEGROUND_SCOREBOARD_PREVIOUS", function() BATTLEGROUND_SCOREBOARD_FRAGMENT:SelectPreviousPlayerData() end, GetString(SI_BATTLEGROUND_SCOREBOARD_PREVIOUS_PLAYER_KEYBIND))
    self.nextPlayerButton = CreateKeybindButton("BATTLEGROUND_SCOREBOARD_NEXT", function() BATTLEGROUND_SCOREBOARD_FRAGMENT:SelectNextPlayerData() end, GetString(SI_BATTLEGROUND_SCOREBOARD_NEXT_PLAYER_KEYBIND))
end
do
    local KEYBOARD_PLATFORM_STYLE = 
    {
        timerFont = "ZoFontWinH2",
        keybindButtonTemplate = "ZO_KeybindButton_Keyboard_Template",
        hasPlayerOptionsButton = false,
    }
    local GAMEPAD_PLATFORM_STYLE = 
    {
        timerFont = "ZoFontGamepad42",
        keybindButtonTemplate = "ZO_KeybindButton_Gamepad_Template",
        hasPlayerOptionsButton = true,
    }
    function ZO_Battleground_Scoreboard_End_Of_Game:InitializePlatformStyle()
        self.platformStyle = ZO_PlatformStyle:New(function(style) self:ApplyPlatformStyle(style) end, KEYBOARD_PLATFORM_STYLE, GAMEPAD_PLATFORM_STYLE)
    end
end
function ZO_Battleground_Scoreboard_End_Of_Game:ApplyPlatformStyle(style)
    self.closingTimerLabel:SetFont(style.timerFont)
    for keybindButton, nameText in pairs(self.keybindNameTextMap) do
        ApplyTemplateToControl(keybindButton, style.keybindButtonTemplate)
        -- We need this because of modifyTextType
        keybindButton.nameLabel:SetText(nameText)
    end
    self.playerOptionsButton:SetHidden(not style.hasPlayerOptionsButton)
    if style.hasPlayerOptionsButton then
        self.leaveBattlegroundKeybind:SetAnchor(LEFT, self.playerOptionsButton, RIGHT, KEYBIND_BUTTON_SPACING_X, 0)
    else
        self.leaveBattlegroundKeybind:SetAnchor(TOPLEFT)
    end
end
function ZO_Battleground_Scoreboard_End_Of_Game:OnShowing()
    self.control:SetHandler("OnUpdate", function() self:UpdateAll() end)
end
function ZO_Battleground_Scoreboard_End_Of_Game:OnHiding()
    self.control:SetHandler("OnUpdate", nil)
end
function ZO_Battleground_Scoreboard_End_Of_Game:UpdateAll()
    self.closingTimerLabel:SetText(zo_strformat(SI_BATTLEGROUND_SCOREBOARD_END_OF_GAME_CLOSING_TIME, timeLeft))
end
function ZO_Battleground_Scoreboard_End_Of_Game:RefreshMatchInfoFragments()
    local groupToAdd, groupToRemove
    if IsInGamepadPreferredMode() then
        groupToAdd = FRAGMENT_GROUP.BATTLEGROUND_MATCH_INFO_GAMEPAD_GROUP
        groupToRemove = FRAGMENT_GROUP.BATTLEGROUND_MATCH_INFO_KEYBOARD_GROUP
    else
        groupToAdd = FRAGMENT_GROUP.BATTLEGROUND_MATCH_INFO_KEYBOARD_GROUP
        groupToRemove = FRAGMENT_GROUP.BATTLEGROUND_MATCH_INFO_GAMEPAD_GROUP
    end
    BATTLEGROUND_SCOREBOARD_END_OF_GAME_SCENE:RemoveFragmentGroup(groupToRemove)
    BATTLEGROUND_SCOREBOARD_END_OF_GAME_SCENE:AddFragmentGroup(groupToAdd)
end
function ZO_Battleground_Scoreboard_End_Of_Game:OnLeaveBattlegroundPressed()
    if self.scene:IsShowing() then
        LeaveBattleground()
    end
end
function ZO_Battleground_Scoreboard_End_Of_Game:OnKeybindDown(keybind)
    if self.scene:IsShowing() then
        local keybindButton = self.keybindActionMap[keybind]
        if keybindButton and keybindButton:IsEnabled() then
            keybindButton:OnClicked()
            return true
        end
    end
    return false
end
--[[ xml functions ]]--
    BATTLEGROUND_SCOREBOARD_END_OF_GAME = ZO_Battleground_Scoreboard_End_Of_Game:New(control)
end