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 0
Expand file tree
/
Copy path1Version-UI.lua
More file actions
230 lines (199 loc) · 8.25 KB
/
1Version-UI.lua
File metadata and controls
230 lines (199 loc) · 8.25 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
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
------------------------------------------------------------------------------------------------
-- 1Version ver. @project-version@
-- Authored by Chrono Syz -- Entity-US / Wildstar
-- Build @project-hash@
-- Copyright (c) Chronosis. All rights reserved
--
-- https://github.com/chronosis/1Version
------------------------------------------------------------------------------------------------
-- 1Version-UI.lua
------------------------------------------------------------------------------------------------
require "Window"
require "Item"
require "GameLib"
local OneVersion = Apollo.GetAddon("1Version")
local Info = Apollo.GetAddonInfo("1Version")
local Utils = Apollo.GetPackage("SimpleUtils-1.0").tPackage
---------------------------------------------------------------------------------------------------
-- OneVersion General UI Functions
---------------------------------------------------------------------------------------------------
function OneVersion:OnToggleOneVersion()
if self.state.isOpen == true then
self.state.isOpen = false
self:SaveLocation()
self:CloseMain()
else
self.state.isOpen = true
self.state.windows.main:Invoke() -- show the window
if self.state.isAlerted == true then
self:CloseAlert()
self.state.isAlerted = false
end
end
end
function OneVersion:SaveLocation()
self.settings.positions.main = self.state.windows.main:GetLocation():ToTable()
self.settings.positions.alert = self.state.windows.alert:GetLocation():ToTable()
end
function OneVersion:CloseMain()
self.state.windows.main:Close()
end
---------------------------------------------------------------------------------------------------
-- OneVersion OneVersionWindow UI Functions
---------------------------------------------------------------------------------------------------
function OneVersion:OnOneVersionClose( wndHandler, wndControl, eMouseButton )
self.state.isOpen = false
self:SaveLocation()
self:CloseMain()
end
function OneVersion:OnOneVersionClosed( wndHandler, wndControl )
self.state.isOpen = false
end
-----------------------------------------------------------------------------------------------
-- OneVersion OnConfigure
-----------------------------------------------------------------------------------------------
function OneVersion:OnConfigure()
if self.state.windows.options == nil then
self.state.windows.options = Apollo.LoadForm(self.xmlDoc, "OneVersionOptionsWindow", nil, self)
-- Load Options
--self.state.windows.options:FindChild("AutoMLButton"):SetCheck(self.settings.options.autoSetMasterLootWhenLeading)
self.state.windows.options:Show(true)
end
self.state.windows.options:ToFront()
end
-----------------------------------------------------------------------------------------------
-- OneVersion Configuration UI Functions
-----------------------------------------------------------------------------------------------
function OneVersion:OnOptionsSave( wndHandler, wndControl, eMouseButton )
--self.settings.options.autoSetMasterLootWhenLeading = self.state.windows.options:FindChild("AutoMLButton"):IsChecked()
self:CloseOptions()
-- Update addon state based on new settings
self:ProcessOptions()
end
function OneVersion:OnOptionsCancel( wndHandler, wndControl, eMouseButton )
self:CloseOptions()
end
function OneVersion:OnOptionsClosed( wndHandler, wndControl )
self:CloseOptions()
end
function OneVersion:CloseOptions()
self.state.windows.options:Show(false)
self.state.windows.options:Destroy()
self.state.windows.options = nil
end
---------------------------------------------------------------------------------------------------
-- OneVersion UI Location
---------------------------------------------------------------------------------------------------
function OneVersion:RestoreLocations()
-- Main Location Restore
if self.settings.positions.main ~= nil and self.settings.positions.main ~= {} then
locSavedLoc = WindowLocation.new(self.settings.positions.main)
self.state.windows.main:MoveToLocation(locSavedLoc)
end
-- Alert Location Restore
if self.settings.positions.alert ~= nil and self.settings.positions.alert ~= {} then
local locSavedLoc = WindowLocation.new(self.settings.positions.alert)
self.state.windows.alert:MoveToLocation(locSavedLoc)
end
end
---------------------------------------------------------------------------------------------------
-- OneVersion UI Refresh
---------------------------------------------------------------------------------------------------
function OneVersion:RefreshUI()
self:RestoreLocations()
-- Set Enabled Flag
self.state.windows.main:FindChild("EnabledButton"):SetCheck(self.settings.user.enabled)
-- Sort List Items
self.state.windows.addonList:ArrangeChildrenVert()
self:RecalculateOutdatedCount()
if self.state.updateCount > 0 then
Event_FireGenericEvent("InterfaceMenuList_AlertAddOn", "OneVersion", {true, nil, self.state.updateCount})
else
Event_FireGenericEvent("InterfaceMenuList_AlertAddOn", "OneVersion", {false, nil, nil})
end
end
function OneVersion:ShowAlert()
self.state.windows.alert:Invoke()
-- Location Restore
if self.settings.positions.alert ~= nil and self.settings.positions.alert ~= {} then
local locSavedLoc = WindowLocation.new(self.settings.positions.alert)
self.state.windows.alert:MoveToLocation(locSavedLoc)
end
end
function OneVersion:CloseAlert()
self.state.windows.alert:Close()
end
function OneVersion:ProcessLock()
if self.settings.user.unlocked == true then
self:ShowAlert()
self.state.windows.alert:AddStyle("Moveable")
self.state.windows.alert:FindChild("Button"):Enable(false)
self.state.windows.alert:AddStyle("Moveable")
self.state.windows.alert:SetTooltip("-Drag to Move-")
else
self.state.windows.alert:RemoveStyle("Moveable")
self.state.windows.alert:FindChild("Button"):Enable(true)
self.state.windows.alert:SetTooltip("-OneVersion Alert-")
if self.state.isAlerted == false then
self:CloseAlert()
end
end
self.state.windows.moveWindow:Show(self.settings.user.unlocked)
end
function OneVersion:OnUnlockCheck( wndHandler, wndControl, eMouseButton )
local checked = wndControl:IsChecked()
self.settings.user.unlocked = checked
self:ProcessLock()
end
function OneVersion:OnAlertMove( wndHandler, wndControl, nOldLeft, nOldTop, nOldRight, nOldBottom )
self:SaveLocation()
end
function OneVersion:OnOpenAlerts()
if self.state.isOpen ~= true then
self.state.windows.main:Show(true)
end
self.state.isAlerted = false
self:CloseAlert()
end
---------------------------------------------------------------------------------------------------
-- OneVersion Addon List UI Maintenance Functions
---------------------------------------------------------------------------------------------------
function OneVersion:ClearAddonListItem()
self:DestroyWindowList(self.state.listItems.addons)
end
function OneVersion:AddAddonListItem(index, item)
local wnd = Apollo.LoadForm(self.xmlDoc, "AddonListItem", self.state.windows.addonList, self)
local mine = {
major = (item.mine.major or 0),
minor = (item.mine.minor or 0),
patch = (item.mine.patch or 0),
suffix = (item.mine.suffix or 0)
}
local reported = {
major = (item.reported.major or 0),
minor = (item.reported.minor or 0),
patch = (item.reported.patch or 0),
suffix = (item.reported.suffix or 0)
}
wnd:SetData(index)
-- Populate List Items fields from the item data
wnd:FindChild("Type"):SetText(item.type)
wnd:FindChild("Label"):SetText(item.label)
wnd:FindChild("Mine"):SetText(self:BuildVersionString(mine.major, mine.minor, mine.patch, mine.suffix))
wnd:FindChild("Reported"):SetText(self:BuildVersionString(reported.major, reported.minor, reported.patch, reported.suffix))
wnd:FindChild("Upgrade"):Show(item.upgrade)
table.insert(self.state.listItems.addons, wnd)
end
function OneVersion:RebuildAddonListItems()
local vScrollPos = self.state.windows.addonList:GetVScrollPos()
local tAddons = {}
self:SaveLocation()
self:ClearAddonListItem()
tAddons = self:BuildSortableTable(self.state.trackedAddons)
table.sort(tAddons, OneVersion.AddonSort)
for idx,item in ipairs(tAddons) do
self:AddAddonListItem(item.label, item)
end
self.state.windows.addonList:SetVScrollPos(vScrollPos)
self:RefreshUI()
end