Back to Home

ESO Lua File v100021

ingame/guild/keyboard/guildhome_keyboard.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
ZO_GUILD_RESOURCE_ICONS =
{
    [RESOURCETYPE_WOOD] = "EsoUI/Art/Guild/ownership_icon_lumberMill.dds",
    [RESOURCETYPE_ORE] = "EsoUI/Art/Guild/ownership_icon_mine.dds",
    [RESOURCETYPE_FOOD] = "EsoUI/Art/Guild/ownership_icon_farm.dds",
}
local GuildHomeManager = ZO_Object:Subclass()
function GuildHomeManager:New(control)
    local manager = ZO_Object.New(self)
    manager.control = control
    manager.scroll = GetControl(control, "PaneScroll")
    manager.scrollChild = GetControl(manager.scroll, "Child")
    manager.infoContainer = CreateControlFromVirtual("ZO_GuildHomeInfo", manager.scrollChild, "ZO_GuildHomeInfo")
    manager.keepIcon = GetControl(control, "KeepIcon")
    manager.keepName = GetControl(control, "KeepName")
    manager.campaignName = GetControl(control, "KeepCampaignName")
    manager.traderIcon = GetControl(control, "TraderIcon")
    manager.traderName = GetControl(control, "TraderName")
    manager.savingEditBoxGroup = ZO_SavingEditBoxGroup:New()
    manager.motd = ZO_SavingEditBox:New(GetControl(manager.infoContainer, "MotD"))
    manager.motd:SetDefaultText(GetString(SI_GUILD_MOTD_DEFAULT_TEXT))
    manager.motd:SetEmptyText(GetString(SI_GUILD_MOTD_EMPTY_TEXT))
    manager.savingEditBoxGroup:Add(manager.motd)
    local motdEditControl = manager.motd:GetEditControl()
    motdEditControl:SetMultiLine(true)
    motdEditControl:SetMaxInputChars(MAX_GUILD_MOTD_LENGTH)
    manager.motd:RegisterCallback("Save", function(text) SetGuildMotD(manager.guildId, text) end)
    manager.description = ZO_SavingEditBox:New(GetControl(manager.infoContainer, "Description"))
    manager.description:SetDefaultText(GetString(SI_GUILD_DESCRIPTION_DEFAULT_TEXT))
    manager.description:SetEmptyText(GetString(SI_GUILD_DESCRIPTION_EMPTY_TEXT))
    manager.savingEditBoxGroup:Add(manager.description)
    local descriptionEditControl = manager.description:GetEditControl()
    descriptionEditControl:SetMultiLine(true)
    descriptionEditControl:SetMaxInputChars(MAX_GUILD_DESCRIPTION_LENGTH)
    manager.description:RegisterCallback("Save", function(text) SetGuildDescription(manager.guildId, text) end)
    manager:InitializeKeybindDescriptors()
    control:RegisterForEvent(EVENT_GUILD_MOTD_CHANGED, function(_, guildId) if(manager.guildId == guildId) then manager:OnGuildMotDChanged() end end)
    control:RegisterForEvent(EVENT_GUILD_DESCRIPTION_CHANGED, function(_, guildId) if(manager.guildId == guildId) then manager:OnGuildDescriptionChanged() end end)
    control:RegisterForEvent(EVENT_GUILD_RANK_CHANGED, function(_, guildId) if(manager.guildId == guildId) then manager:OnGuildRankChanged() end end)
    control:RegisterForEvent(EVENT_GUILD_RANKS_CHANGED, function(_, guildId) if(manager.guildId == guildId) then manager:OnGuildRanksChanged() end end)
    control:RegisterForEvent(EVENT_GUILD_MEMBER_RANK_CHANGED, function(_, guildId, displayName) if(manager.guildId == guildId) then manager:OnGuildMemberRankChanged(displayName) end end)
    control:RegisterForEvent(EVENT_GUILD_KEEP_CLAIM_UPDATED, function(_, guildId) if(manager.guildId == guildId) then manager:OnGuildKeepClaimUpdated() end end)
    control:RegisterForEvent(EVENT_GUILD_TRADER_HIRED_UPDATED, function(_, guildId) if(manager.guildId == guildId) then manager:OnGuildTraderHiredUpdated() end end)
    CALLBACK_MANAGER:RegisterCallback("ProfanityFilter_Off", function() manager:OnProfanityFilterChanged() end)
    CALLBACK_MANAGER:RegisterCallback("ProfanityFilter_On", function() manager:OnProfanityFilterChanged() end)
    GUILD_HOME_SCENE = ZO_Scene:New("guildHome", SCENE_MANAGER)
    GUILD_HOME_SCENE:RegisterCallback("StateChange",     function(oldState, state)
                                                                if(state == SCENE_SHOWING) then
                                                                    KEYBIND_STRIP:AddKeybindButtonGroup(manager.keybindStripDescriptor)
                                                                elseif(state == SCENE_HIDDEN) then
                                                                    KEYBIND_STRIP:RemoveKeybindButtonGroup(manager.keybindStripDescriptor)
                                                                end
                                                            end)
    return manager
end
function GuildHomeManager:InitializeKeybindDescriptors()
    self.keybindStripDescriptor =
    {
          alignment = KEYBIND_STRIP_ALIGN_CENTER,
          -- Leave Guild
          {
               name = GetString(SI_GUILD_LEAVE),
               keybind = "UI_SHORTCUT_NEGATIVE",
               callback = function()
                    ZO_ShowLeaveGuildDialog(self.guildId)
               end,
               visible = function()
                    return true;
               end
          },
        -- Release Keep
        {
            name = GetString(SI_GUILD_RELEASE_KEEP),
            keybind = "UI_SHORTCUT_SECONDARY",
            visible = function()
                return DoesGuildHaveClaimedKeep(self.guildId) and DoesPlayerHaveGuildPermission(self.guildId, GUILD_PERMISSION_RELEASE_AVA_RESOURCE)
            end,
            callback = function()
                local keepId, campaignId = GetGuildClaimedKeep(self.guildId)
                ZO_Dialogs_ShowDialog("CONFIRM_RELEASE_KEEP_OWNERSHIP", { release = function() ReleaseKeepForGuild(self.guildId) end, keepId = keepId })
            end,
        },
    }
end
function GuildHomeManager:SetGuildId(guildId)
    self.guildId = guildId
    self:RefreshAll()
end
function GuildHomeManager:RefreshGuildMaster()
    local guildMasterLabel = GetControl(self.control, "GuildMaster")
    local _, _, guildLeader = GetGuildInfo(self.guildId)
    guildMasterLabel:SetText(guildLeader)
end
function GuildHomeManager:RefreshMotD()
    self.motd:SetText(GetGuildMotD(self.guildId))
end
function GuildHomeManager:RefreshDescription()
end
function GuildHomeManager:RefreshPermissions()
    if(DoesPlayerHaveGuildPermission(self.guildId, GUILD_PERMISSION_SET_MOTD)) then
        self.motd:SetHidden(false)
    else
        self.motd:SetHidden(true)
    end
    if(DoesPlayerHaveGuildPermission(self.guildId, GUILD_PERMISSION_DESCRIPTION_EDIT)) then
        self.description:SetHidden(false)
    else
        self.description:SetHidden(true)
    end
end
function GuildHomeManager:RefreshFoundedDate()
    GetControl(self.control, "Founded"):SetText(GetGuildFoundedDate(self.guildId))
end
function GuildHomeManager:RefreshKeepOwnership()
    if(DoesGuildHaveClaimedKeep(self.guildId)) then    
        local keepId, campaignId = GetGuildClaimedKeep(self.guildId)
        local keepType = GetKeepType(keepId)
        local icon = "EsoUI/Art/Guild/ownership_icon_keep.dds"
        if(keepType == KEEPTYPE_RESOURCE) then
            local resourceType = GetKeepResourceType(keepId)
            icon = ZO_GUILD_RESOURCE_ICONS[resourceType]
        end
        self.keepIcon:SetTexture(icon)
        self.keepIcon:SetAlpha(1)
        self.keepName:SetText(zo_strformat(SI_TOOLTIP_KEEP_NAME, GetKeepName(keepId)))
        self.campaignName:SetHidden(false)
        self.campaignName:SetText(GetCampaignName(campaignId))
    else
        self.keepIcon:SetTexture("EsoUI/Art/Guild/ownership_icon_keep.dds")
        self.keepIcon:SetAlpha(0.2)
        self.keepName:SetText(GetString(SI_GUILD_NO_CLAIMED_KEEP))
        self.campaignName:SetHidden(true)
    end
end
function GuildHomeManager:RefreshTraderOwnership()
    local traderName = GetGuildOwnedKioskInfo(self.guildId)
    if(traderName) then
        self.traderIcon:SetAlpha(1)
        self.traderName:SetText(zo_strformat(SI_GUILD_HIRED_TRADER, traderName))
    else
        self.traderIcon:SetAlpha(0.2)
        self.traderName:SetText(GetString(SI_GUILD_NO_HIRED_TRADER))
    end
end
function GuildHomeManager:RefreshReleaseKeep()
    KEYBIND_STRIP:UpdateKeybindButtonGroup(self.keybindStripDescriptor)
end
function GuildHomeManager:RefreshAll()
    self.motd:SetEditing(false)
    self.description:SetEditing(false)
    self:RefreshMotD()
end
--Events
function GuildHomeManager:OnGuildMotDChanged()
    self:RefreshMotD()
end
function GuildHomeManager:OnGuildDescriptionChanged()
end
function GuildHomeManager:OnProfanityFilterChanged()
    self:RefreshMotD()
end
function GuildHomeManager:OnGuildRanksChanged()
end
function GuildHomeManager:OnGuildMemberRankChanged()
end
function GuildHomeManager:OnGuildRankChanged()
end
function GuildHomeManager:OnGuildKeepClaimUpdated()
end
function GuildHomeManager:OnGuildTraderHiredUpdated()
end
--Global XML
    GUILD_HOME = GuildHomeManager:New(self)
end