-
Notifications
You must be signed in to change notification settings - Fork 0
/
GroupDisplayOptions.lua
349 lines (292 loc) · 14.2 KB
/
GroupDisplayOptions.lua
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
-----------------------------------------------------------------------------------------------
-- Client Lua Script for GroupDisplayOptions
-- Copyright (c) NCsoft. All rights reserved
-----------------------------------------------------------------------------------------------
require "Window"
require "GroupLib"
local GroupDisplayOptions = {}
local ktSubMenus =
{
"ThresholdDistribution",
"LootThreshold",
"Mentoring",
"JoinRequest",
"Referral"
}
function GroupDisplayOptions:new(o)
o = o or {}
setmetatable(o, self)
self.__index = self
return o
end
function GroupDisplayOptions:Init()
Apollo.RegisterAddon(self)
end
function GroupDisplayOptions:OnLoad()
self.xmlDoc = XmlDoc.CreateFromFile("GroupDisplayOptions.xml")
self.xmlDoc:RegisterCallback("OnDocumentReady", self)
end
function GroupDisplayOptions:OnDocumentReady()
if self.xmlDoc == nil then
return
end
Apollo.RegisterEventHandler("Group_Updated", "RedrawAll", self)
Apollo.RegisterEventHandler("GenericEvent_UpdateGroupLeaderOptions", "RedrawAll", self)
Apollo.RegisterEventHandler("GenericEvent_InitializeGroupLeaderOptions", "Initialize", self)
end
function GroupDisplayOptions:Initialize(wndParent)
self.wndMain = Apollo.LoadForm(self.xmlDoc, "GroupLeaderOptions", wndParent, self)
wndParent:AttachWindow(self.wndMain)
for idx, strMenu in ipairs(ktSubMenus) do
if strMenu and self.wndMain:FindChild(strMenu) then
self.wndMain:FindChild(strMenu):AttachWindow(self.wndMain:FindChild(strMenu .. "Area"))
end
end
local tLootThreshold =
{
[Item.CodeEnumItemQuality.Inferior] = Apollo.GetString("CRB_Inferior"),
[Item.CodeEnumItemQuality.Average] = Apollo.GetString("CRB_Average"),
[Item.CodeEnumItemQuality.Good] = Apollo.GetString("CRB_Good"),
[Item.CodeEnumItemQuality.Excellent] = Apollo.GetString("CRB_Excellent"),
[Item.CodeEnumItemQuality.Superb] = Apollo.GetString("CRB_Superb"),
[Item.CodeEnumItemQuality.Legendary] = Apollo.GetString("CRB_Legendary"),
[Item.CodeEnumItemQuality.Artifact] = Apollo.GetString("CRB_Artifact")
}
self:HelperInitializeWindows(tLootThreshold, "LootThreshold", self.wndMain:FindChild("LootThresholdArea"):FindChild("ItemsContainer"))
local tThresholdDistribution =
{
[GroupLib.LootRule.Master] = Apollo.GetString("Group_MasterLoot"),
[GroupLib.LootRule.NeedBeforeGreed] = Apollo.GetString("Group_NeedVsGreed"),
[GroupLib.LootRule.RoundRobin] = Apollo.GetString("Group_RoundRobin"),
[GroupLib.LootRule.FreeForAll] = Apollo.GetString("Group_FFA"),
}
self:HelperInitializeWindows(tThresholdDistribution, "ThresholdDistribution", self.wndMain:FindChild("ThresholdDistributionArea"):FindChild("ItemsContainer"))
local tInvitationMethod =
{
[GroupLib.InvitationMethod.Open] = Apollo.GetString("CRB_Open"),
[GroupLib.InvitationMethod.Neutral] = Apollo.GetString("CRB_Neutral"),
[GroupLib.InvitationMethod.Closed] = Apollo.GetString("CRB_Closed")
}
self:HelperInitializeWindows(tInvitationMethod, "JoinRequest", self.wndMain:FindChild("JoinRequestArea"):FindChild("ItemsContainer"))
self:HelperInitializeWindows(tInvitationMethod, "Referral", self.wndMain:FindChild("ReferralArea"):FindChild("ItemsContainer"))
self:RedrawAll()
end
---------------------------------------------------------------------------------------------------
-- Group Options Menu
---------------------------------------------------------------------------------------------------
function GroupDisplayOptions:OnSubOptionSet(wndHandler, wndControl)
local strSubOptionName = wndHandler:GetName()
local tCurrRules = GroupLib.GetLootRules()
if strSubOptionName == "LootThreshold" then
GroupLib.SetLootRules(tCurrRules.eNormalRule, tCurrRules.eThresholdRule, wndHandler:GetData(), tCurrRules.eHarvestRule)
elseif strSubOptionName == "ThresholdDistribution" then
GroupLib.SetLootRules(tCurrRules.eNormalRule, wndHandler:GetData(), tCurrRules.eThresholdQuality, tCurrRules.eHarvestRule)
elseif strSubOptionName == "JoinRequest" then
GroupLib.SetJoinRequestMethod(wndHandler:GetData())
elseif strSubOptionName == "Referral" then
GroupLib.SetReferralMethod(wndHandler:GetData())
end
end
function GroupDisplayOptions:RedrawAll() -- The button check and various UI calls route here
if not self.wndMain or not self.wndMain:IsValid() then -- Will rely on the initialize to RedrawAll
return
end
local nGroupCount = GroupLib.GetMemberCount()
if nGroupCount == 0 then
return
end
local tLootRules = GroupLib.GetLootRules()
self:HelperRedrawSpecific("LootThreshold", tLootRules.eThresholdQuality)
self:HelperRedrawSpecific("ThresholdDistribution", tLootRules.eThresholdRule)
self:HelperRedrawSpecific("JoinRequest", GroupLib.GetJoinRequestMethod())
self:HelperRedrawSpecific("Referral", GroupLib.GetReferralMethod())
-- Mentoring has a custom redraw
self:HelperRedrawMentoring()
end
function GroupDisplayOptions:HelperRedrawSpecific(strMenuName, tProvidedValue)
if not self.wndMain or not self.wndMain:IsValid() or not strMenuName or strMenuName == "" then
return
end
local wndItems = self.wndMain:FindChild(strMenuName .. "Area"):FindChild("ItemsContainer")
if not wndItems then
return
end
local bIsLeader = GroupLib.AmILeader()
local bIsInstance = GroupLib.InInstance()
for idx, wndOption in ipairs(wndItems:GetChildren()) do
local bIsChecked = wndOption:GetData() == tProvidedValue
wndOption:Enable(bIsLeader and not bIsInstance)
wndOption:SetCheck(bIsChecked)
wndOption:FindChild("CheckIcon"):Show(bIsChecked)
if not bIsLeader or bIsInstance then -- Priority: Red for disabled, Light Blue for checked, else Dark Blue
wndOption:FindChild("SubOptionsBtnText"):SetTextColor(ApolloColor.new("UI_BtnTextHoloListDisabled"))
elseif bIsChecked then
wndOption:FindChild("SubOptionsBtnText"):SetTextColor(ApolloColor.new("UI_BtnTextHoloListPressed"))
else
wndOption:FindChild("SubOptionsBtnText"):SetTextColor(ApolloColor.new("UI_BtnTextHoloListNormal"))
end
end
self.wndMain:FindChild("DisbandGroup"):Enable(bIsLeader and not bIsInstance)
if bIsLeader and not bIsInstance then
self.wndMain:FindChild("DisbandGroup"):FindChild("OptionsBtnText"):SetTextColor(ApolloColor.new("UI_BtnTextHoloListNormal"))
else
self.wndMain:FindChild("DisbandGroup"):FindChild("OptionsBtnText"):SetTextColor(ApolloColor.new("UI_BtnTextHoloListDisabled"))
end
self.wndMain:FindChild("ResetInstances"):Enable(bIsLeader and not bIsInstance)
if bIsLeader and not bIsInstance then
self.wndMain:FindChild("ResetInstances"):FindChild("OptionsBtnText"):SetTextColor(ApolloColor.new("UI_BtnTextHoloListNormal"))
else
self.wndMain:FindChild("ResetInstances"):FindChild("OptionsBtnText"):SetTextColor(ApolloColor.new("UI_BtnTextHoloListDisabled"))
end
self.wndMain:FindChild("LeaveGroup"):Enable(true)
self.wndMain:FindChild("LeaveGroup"):FindChild("OptionsBtnText"):SetTextColor(ApolloColor.new("UI_BtnTextHoloListNormal"))
local bIsInRaid = GroupLib.InRaid()
self.wndMain:FindChild("ConvertToRaid"):Enable(bIsLeader and not bIsInRaid and not bIsInstance)
if bIsLeader and not bIsInRaid and not bIsInstance then
self.wndMain:FindChild("ConvertToRaid"):FindChild("OptionsBtnText"):SetTextColor(ApolloColor.new("UI_BtnTextHoloListNormal"))
else
self.wndMain:FindChild("ConvertToRaid"):FindChild("OptionsBtnText"):SetTextColor(ApolloColor.new("UI_BtnTextHoloListDisabled"))
end
end
---------------------------------------------------------------------------------------------------
-- Mentoring
---------------------------------------------------------------------------------------------------
function GroupDisplayOptions:HelperRedrawMentoring() -- Also from XML's Mentoring Btn
if not self.wndMain or not self.wndMain:IsValid() then
return
end
local tMyGroupData = GroupLib.GetGroupMember(1)
local wndParent = self.wndMain:FindChild("MentoringArea"):FindChild("ItemsContainer")
wndParent:FindChild("MentoringStopBtn"):SetCheck(false) -- Consider swapping to a button
if not tMyGroupData then
return
end
local nMemberCount = GroupLib.GetMemberCount()
local bCanStopMentoring = tMyGroupData.bIsMentoring or tMyGroupData.bIsMentored
local strMentoringStopBtnColor = ApolloColor.new(bCanStopMentoring and "UI_BtnTextHoloListNormal" or "UI_BtnTextHoloListDisabled")
wndParent:FindChild("MentoringStopBtn"):Enable(bCanStopMentoring)
wndParent:FindChild("MentoringStopBtn"):FindChild("SubOptionsBtnText"):SetTextColor(strMentoringStopBtnColor)
for idx = 1, 4 do
local tTargetGroupData = GroupLib.GetGroupMember(idx + 1) -- GOTCHA: Off by one "Group Member One" text really means idx2
local bActivelyMentoringThisPersonAlready = (idx + 1) == tMyGroupData.nMenteeIdx
local bCanRallyToThisPerson = tTargetGroupData and tTargetGroupData.nLevel < tMyGroupData.nLevel and idx < nMemberCount and not bCanStopMentoring
local wndCurrBtn = wndParent:FindChild("MentoringSpecificBtn"..idx)
wndCurrBtn:SetCheck(bActivelyMentoringThisPersonAlready)
wndCurrBtn:FindChild("CheckIcon"):Show(bActivelyMentoringThisPersonAlready)
wndCurrBtn:FindChild("SubOptionsBtnText"):SetTextColor(ApolloColor.new(bCanRallyToThisPerson and "UI_BtnTextHoloListNormal" or "UI_BtnTextHoloListDisabled"))
wndCurrBtn:Enable(bCanRallyToThisPerson)
-- Button Text
if tTargetGroupData and bActivelyMentoringThisPersonAlready then
wndCurrBtn:FindChild("SubOptionsBtnText"):SetText(String_GetWeaselString(Apollo.GetString("Group_MentoringPerson"), tTargetGroupData.strCharacterName))
elseif tTargetGroupData and tTargetGroupData.strCharacterName then
wndCurrBtn:FindChild("SubOptionsBtnText"):SetText(String_GetWeaselString(Apollo.GetString("Group_MentorPerson"), tTargetGroupData.strCharacterName))
else
wndCurrBtn:FindChild("SubOptionsBtnText"):SetText(Apollo.GetString("Group_RallyMember"..idx))
end
end
end
function GroupDisplayOptions:OnMentorSpecificPerson(wndHandler, wndControl)
local karRallySpecificBtnToIdx =
{
["MentoringSpecificBtn1"] = 2,
["MentoringSpecificBtn2"] = 3,
["MentoringSpecificBtn3"] = 4,
["MentoringSpecificBtn4"] = 5,
}
local unitTarget = GroupLib.GetUnitForGroupMember(karRallySpecificBtnToIdx[wndHandler:GetName()] or 0)
if unitTarget then
GroupLib.AcceptMentoring(unitTarget)
end
self:HelperRedrawMentoring()
self:OnGroupFormatClose()
end
function GroupDisplayOptions:OnStopMentoringBtn(wndHandler, wndControl)
GroupLib.CancelMentoring()
self:HelperRedrawMentoring()
self:OnGroupFormatClose()
end
---------------------------------------------------------------------------------------------------
-- Simple UI buttons
---------------------------------------------------------------------------------------------------
function GroupDisplayOptions:OnLeaveGroup()
self.wndMain:Show(false)
self:OnGroupFormatClose()
Event_FireGenericEvent("GenericEvent_ShowConfirmLeaveDisband", 1)
end
function GroupDisplayOptions:OnDisbandGroup()
self.wndMain:Show(false)
self:OnGroupFormatClose()
Event_FireGenericEvent("GenericEvent_ShowConfirmLeaveDisband", 0)
end
function GroupDisplayOptions:OnResetInstances()
self.wndMain:Show(false)
self:OnGroupFormatClose()
Apollo.ParseInput("/resetinstances") -- TODO: Replace with a library call
end
function GroupDisplayOptions:OnConvertToRaid()
if self.wndRaidConfirm and self.wndRaidConfirm:IsValid() then
self.wndRaidConfirm:Destroy()
self.wndRaidConfirm = nil
end
self.wndMain:Show(false)
self.wndRaidConfirm = Apollo.LoadForm(self.xmlDoc, "RaidConvertConfirmForm", nil, self)
self.wndRaidConfirm:Show(true)
self.wndRaidConfirm:ToFront()
end
function GroupDisplayOptions:OnGroupFormatClose() -- clean up on close
for idx, strMenu in ipairs(ktSubMenus) do
if strMenu and self.wndMain:FindChild(strMenu) then
self.wndMain:FindChild(strMenu):SetCheck(false)
self.wndMain:FindChild(strMenu .. "Area"):Show(false)
self.wndMain:FindChild(strMenu):FindChild("OptionsBtnText"):SetTextColor(ApolloColor.new("UI_BtnTextHoloListNormal"))
end
end
end
function GroupDisplayOptions:ResetMouseEnterHighlights(wndHandler, wndControl)
for idx, strMenu in ipairs(ktSubMenus) do
if strMenu and self.wndMain:FindChild(strMenu) and self.wndMain:FindChild(strMenu):FindChild("OptionsBtnText") then
self.wndMain:FindChild(strMenu):FindChild("OptionsBtnText"):SetTextColor(ApolloColor.new("UI_BtnTextHoloListNormal"))
end
end
wndHandler:FindChild("OptionsBtnText"):SetTextColor(ApolloColor.new("UI_BtnTextHoloListPressed"))
end
function GroupDisplayOptions:OnOptionsWindowBtnMouseEnter(wndHandler, wndControl)
wndHandler:SetTextColor(ApolloColor.new("UI_BtnTextHoloListPressedFlyby"))
end
function GroupDisplayOptions:OnOptionsWindowBtnMouseExit(wndHandler, wndControl)
if not wndHandler:GetParent():IsChecked() then -- TODO: refactor
wndHandler:SetTextColor(ApolloColor.new("UI_BtnTextHoloListNormal"))
end
end
---------------------------------------------------------------------------------------------------
-- RaidConvertConfirmForm Functions
---------------------------------------------------------------------------------------------------
function GroupDisplayOptions:OnRaidConfirmNo(wndHandler, wndControl, eMouseButton)
if self.wndRaidConfirm and self.wndRaidConfirm:IsValid() then
self.wndRaidConfirm:Destroy()
self.wndRaidConfirm = nil
end
end
function GroupDisplayOptions:OnRaidConfirmYes(wndHandler, wndControl, eMouseButton)
if self.wndRaidConfirm and self.wndRaidConfirm:IsValid() then
self.wndRaidConfirm:Destroy()
self.wndRaidConfirm = nil
end
self.wndMain:Show(false)
GroupLib.ConvertToRaid()
end
---------------------------------------------------------------------------------------------------
-- Helpers
---------------------------------------------------------------------------------------------------
function GroupDisplayOptions:HelperInitializeWindows(tLootThreshold, strLuaNameId, wndParent)
for key, strCurrData in pairs(tLootThreshold) do
local wndCurr = Apollo.LoadForm(self.xmlDoc, "GroupLeaderSubOption", wndParent, self)
wndCurr:SetData(key)
wndCurr:SetName(strLuaNameId)
wndCurr:FindChild("SubOptionsBtnText"):SetText(strCurrData)
end
wndParent:ArrangeChildrenVert(0, function(a,b) return a:GetData() < b:GetData() end)
wndParent:SetTooltip(GroupLib.AmILeader() and "" or "<P Font=\"CRB_InterfaceMedium\" TextColor=\"ff9d9d9d\">" .. Apollo.GetString("Group_PermissionsDisabledTooltip") .. "</P>")
end
local GroupDisplayOptionsInst = GroupDisplayOptions:new()
GroupDisplayOptionsInst:Init()