ESO Lua File v100011

ingame/inventory/gamepad/guildbankswitch_gamepad.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
local GUILD_ENTRY_TEMPLATE = "ZO_GamepadSubMenuEntryTemplate"
-----------------------
-- Switch Active Guild
-----------------------
local GAMEPAD_GUILD_SWITCH_ACTIVE_GUILD_SCENE_NAME = "gamepad_guild_switch"
local GuildBankSwitch_Gamepad = ZO_Gamepad_ParametricList_Screen:Subclass()
function GuildBankSwitch_Gamepad:New(...)
    return ZO_Gamepad_ParametricList_Screen.New(self, ...)
end
function GuildBankSwitch_Gamepad:Initialize(control)
    GAMEPAD_GUILD_SWITCH_ACTIVE_GUILD_SCENE = ZO_InteractScene:New(GAMEPAD_GUILD_SWITCH_ACTIVE_GUILD_SCENE_NAME, SCENE_MANAGER, GUILD_BANKING_INTERACTION)
    local ACTIVATE_LIST_ON_SHOW = true
    ZO_Gamepad_ParametricList_Screen.Initialize(self, control, ZO_GAMEPAD_HEADER_TABBAR_DONT_CREATE, ACTIVATE_LIST_ON_SHOW, GAMEPAD_GUILD_SWITCH_ACTIVE_GUILD_SCENE)
end
local SORT_KEYS = 
{
    guildName = { tiebreaker = "guildId" },
    guildId = { isNumeric = true },
}
local function SortGuildList(guild1, guild2)
    return ZO_TableOrderingFunction(guild1, guild2, "guildName", SORT_KEYS, ZO_SORT_ORDER_UP)
end 
function GuildBankSwitch_Gamepad:PerformDeferredInitialization()
    if self.isInitialized then return end
    self.lastSuccessfulGuildBankId = GetSelectedGuildBankId()
    self.guildSwitchList = self:GetMainList()
    self.isInitialized = true
end
function GuildBankSwitch_Gamepad:RegisterForEvents()
    local function OnOpenGuildBank()
        if IsInGamepadPreferredMode() then
            ZO_SharedInventory_SelectAccessibleGuildBank(self.lastSuccessfulGuildBankId)
        end
    end
    local function OnUpdateGuildList()
        if IsInGamepadPreferredMode() and not self.control:IsControlHidden() then
            self:UpdateGuildList()
        else
            self.dirty = true
        end
    end
    self.control:RegisterForEvent(EVENT_OPEN_GUILD_BANK, OnOpenGuildBank)
    self.control:RegisterForEvent(EVENT_GUILD_SELF_JOINED_GUILD, OnUpdateGuildList)
    self.control:RegisterForEvent(EVENT_GUILD_SELF_LEFT_GUILD, OnUpdateGuildList)
    self.control:RegisterForEvent(EVENT_GUILD_RANKS_CHANGED, OnUpdateGuildList)
    self.control:RegisterForEvent(EVENT_GUILD_RANK_CHANGED, OnUpdateGuildList)
    self.control:RegisterForEvent(EVENT_GUILD_MEMBER_RANK_CHANGED, OnUpdateGuildList)
end
function GuildBankSwitch_Gamepad:InitializeKeybindStripDescriptors()
    self.keybindStripDescriptor =
    {
        alignment = KEYBIND_STRIP_ALIGN_LEFT,
        {
            keybind = "UI_SHORTCUT_PRIMARY",
            name = GetString(SI_GAMEPAD_SELECT_OPTION),
            callback = function() self:ChangeGuild() end,
        },
    }
    ZO_Gamepad_AddBackNavigationKeybindDescriptors(self.keybindStripDescriptor, GAME_NAVIGATION_TYPE_BUTTON)
end
function GuildBankSwitch_Gamepad:InitializeHeader()
    self.headerData = {
        titleText = GetString(SI_GAMEPAD_GUILD_BANK_GUILD_SELECTION),
    }
end
function GuildBankSwitch_Gamepad:SetupList(list)
end
function GuildBankSwitch_Gamepad:UpdateGuildList() 
    self.guildSwitchList:Clear()
    for i = 1, GetNumGuilds() do
        local guildId = GetGuildId(i)
        local guildName = GetGuildName(guildId)
        local allianceId = GetGuildAlliance(guildId)
        local icon = GetLargeAllianceSymbolIcon(allianceId)
        local entry = ZO_GamepadEntryData:New(guildName, icon)
        entry.guildId = guildId
        entry.guildName = guildName
        entry.fontScaleOnSelection = false
        self.guildSwitchList:AddEntry(GUILD_ENTRY_TEMPLATE, entry)
    end
    self.guildSwitchList:Commit()
    self.dirty = false
end
function GuildBankSwitch_Gamepad:PerformUpdate()
end
function GuildBankSwitch_Gamepad:ChangeGuild()
    local selectedGuild = self.guildSwitchList:GetSelectedData()
    if selectedGuild then
        SelectGuildBank(selectedGuild.guildId)
        self.lastSuccessfulGuildBankId = selectedGuild.guildId
    end
    
    SCENE_MANAGER:HideCurrentScene()
end
function GuildBankSwitch_Gamepad:Show()
    SCENE_MANAGER:Push(GAMEPAD_GUILD_SWITCH_ACTIVE_GUILD_SCENE_NAME)
end
    GAMEPAD_GUILD_SWITCH_ACTIVE_GUILD = GuildBankSwitch_Gamepad:New(control)
end