This repository was archived by the owner on Nov 28, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFasterLootPlus-UI-RuleSet.lua
More file actions
159 lines (135 loc) · 5.79 KB
/
FasterLootPlus-UI-RuleSet.lua
File metadata and controls
159 lines (135 loc) · 5.79 KB
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
------------------------------------------------------------------------------------------------
-- FasterLootPlus ver. @project-version@
-- Authored by Chimpy Evans, Chrono Syz -- Entity-US / Wildstar
-- Based on FasterLoot by Chimpy Evans -- Entity-US / Wildstar
-- Build @project-hash@
-- Copyright (c) Chronosis. All rights reserved
--
-- https://github.com/chronosis/FasterLootPlus
------------------------------------------------------------------------------------------------
-- FasterLoot-UI-RuleSet.lua
------------------------------------------------------------------------------------------------
require "Window"
require "Item"
require "GameLib"
local FasterLootPlus = Apollo.GetAddon("FasterLootPlus")
local Info = Apollo.GetAddonInfo("FasterLootPlus")
---------------------------------------------------------------------------------------------------
-- FasterLootPlus RuleSet UI Functions
---------------------------------------------------------------------------------------------------
function FasterLootPlus:OnAddRuleSet( wndHandler, wndControl, eMouseButton, nLastRelativeMouseX, nLastRelativeMouseY, bDoubleClick, bStopPropagation )
-- Add a new loot rule
self:CreateEditRuleSetWindow(nil)
end
function FasterLootPlus:CreateEditRuleSetWindow( wndHandler )
if self.state.windows.editRuleSets == nil then
self.state.windows.editRuleSets = Apollo.LoadForm(self.xmlDoc, "EditRuleSetWindow", nil, self)
self.state.windows.editRuleSets:Show(true)
if wndHandler ~= nil then
-- Get Parent List item and associated item data.
local idx = wndHandler:GetData()
local item = self.settings.ruleSets[idx]
-- Populate the Edit window
self.state.windows.editRuleSets:SetData(idx)
self.state.windows.editRuleSets:FindChild("RuleSetName"):FindChild("Text"):SetText(item.label)
self:RebuildRuleSetItems()
self.state.windows.ruleSetList:ArrangeChildrenVert()
end
end
end
---------------------------------------------------------------------------------------------------
-- FasterLootPlus RuleSetListItem UI Functions
---------------------------------------------------------------------------------------------------
function FasterLootPlus:OnLoadRuleSet( wndHandler, wndControl, eMouseButton )
local par = wndHandler:GetParent()
local idx = par:GetData()
-- Change Selected Rule
self.settings.user.currentRuleSet = idx
self:RebuildRuleSetItems()
self:RebuildLootRuleItems()
end
function FasterLootPlus:OnDeleteRuleSet( wndHandler, wndControl, eMouseButton )
-- Add a new loot rule
local par = wndHandler:GetParent()
local idx = par:GetData()
-- Cant Delete the first rule, there always needs to be at least one set
if idx ~= 0 then
self.state.windows.confirmDeleteSet = Apollo.LoadForm(self.xmlDoc, "ConfirmDeleteSetWindow", nil, self)
self.state.windows.confirmDeleteSet:SetData(idx)
end
end
function FasterLootPlus:OnEditRuleSet( wndHandler, wndControl, eMouseButton )
-- Add a new loot rule
local par = wndHandler:GetParent()
local idx = par:GetData()
self:CreateEditRuleSetWindow( par )
end
function FasterLootPlus:OnRuleSetSelected( wndHandler, wndControl, eMouseButton, nLastRelativeMouseX, nLastRelativeMouseY, bDoubleClick, bStopPropagation )
if wndHandler ~= wndControl then
return
end
if eMouseButton == 0 and bDoubleClick then -- Double Left Click
-- Open the Loot Rule Window for this loot rule.
self:CreateEditRuleSetWindow( wndHandler )
end
end
---------------------------------------------------------------------------------------------------
-- FasterLootPlus EditRuleSetWindow UI Functions
---------------------------------------------------------------------------------------------------
function FasterLootPlus:OnEditRuleSetSave( wndHandler, wndControl, eMouseButton )
local label = self.state.windows.editRuleSets:FindChild("RuleSetName"):FindChild("Text"):GetText()
local idx = self.state.windows.editRuleSets:GetData()
if idx then
-- Update Existing Item
self.settings.ruleSets[idx].label = label
else
-- Add New Item
local item = deepcopy(self:GetBaseRuleSet())
item.label = label
table.insert(self.settings.ruleSets, item)
end
self:RebuildRuleSetItems()
self:CloseEditRuleSet()
end
function FasterLootPlus:OnEditRuleSetCancel( wndHandler, wndControl, eMouseButton )
self:CloseEditRuleSet()
end
function FasterLootPlus:OnEditRuleSetClosed( wndHandler, wndControl )
self:CloseEditRuleSet()
end
function FasterLootPlus:CloseEditRuleSet()
self.state.windows.editRuleSets:Show(false)
self.state.windows.editRuleSets:Destroy()
self.state.windows.editRuleSets = nil
end
---------------------------------------------------------------------------------------------------
-- FasterLootPlus UI RuleSet Maintenance Functions
---------------------------------------------------------------------------------------------------
function FasterLootPlus:ClearRuleSetItems()
self:DestroyWindowList(self.state.listItems.ruleSets)
end
function FasterLootPlus:AddRuleSetItem(index, item)
local wnd = Apollo.LoadForm(self.xmlDoc, "RuleSetListItem", self.state.windows.ruleSetList, self)
wnd:SetData(index)
wnd:FindChild("Label"):SetText(item.label)
if index == self.settings.user.currentRuleSet then
wnd:FindChild("Selected"):Show(true)
else
wnd:FindChild("Selected"):Show(false)
end
-- Disable Delete for Root Set
if index == 0 then
wnd:FindChild("DeleteButton"):Enable(false)
end
table.insert(self.state.listItems.ruleSets, wnd)
end
function FasterLootPlus:RebuildRuleSetItems()
local vScrollPos = self.state.windows.ruleSetList:GetVScrollPos()
self:SaveLocation()
self:ClearRuleSetItems()
for key,item in pairs(self.settings.ruleSets) do
self:AddRuleSetItem(key, item)
end
self.state.windows.ruleSetList:SetVScrollPos(vScrollPos)
self:RefreshUI()
end