This repository has been archived by the owner on Jun 23, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.lua
154 lines (118 loc) · 3.19 KB
/
main.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
--[[
the main controller of dominos progress
--]]
local AddonName, Addon = ...
local Dominos = LibStub('AceAddon-3.0'):GetAddon('Dominos')
local ProgressBarModule = Dominos:NewModule('ProgressBars', 'AceEvent-3.0')
local L = LibStub('AceLocale-3.0'):GetLocale('Dominos-Progress')
local ConfigVersion = 1
function ProgressBarModule:OnInitialize()
Addon.Config:Init()
end
function ProgressBarModule:Load()
if Addon.Config:OneBarMode() then
self.bars = {
Addon.ExperienceBar:New('exp', { 'xp', 'reputation', 'honor', 'artifact' }),
}
else
self.bars = {
Addon.ExperienceBar:New('exp', { 'xp', 'reputation', 'honor' }),
Addon.ArtifactBar:New('artifact', { 'artifact' })
}
end
-- common events
self:RegisterEvent('PLAYER_ENTERING_WORLD')
self:RegisterEvent('UPDATE_EXHAUSTION')
self:RegisterEvent('PLAYER_UPDATE_RESTING')
-- xp bar events
self:RegisterEvent('PLAYER_XP_UPDATE')
-- reputation events
self:RegisterEvent('UPDATE_FACTION')
-- honor events
self:RegisterEvent('HONOR_XP_UPDATE')
self:RegisterEvent('HONOR_LEVEL_UPDATE')
-- artifact events
self:RegisterEvent('ARTIFACT_XP_UPDATE')
self:RegisterEvent('UNIT_INVENTORY_CHANGED')
self:RegisterEvent('ADDON_LOADED')
end
function ProgressBarModule:UpdateAllBars()
for _, bar in pairs(self.bars) do
bar:UpdateMode()
bar:Update()
end
end
function ProgressBarModule:Unload()
for i, bar in pairs(self.bars) do
bar:Free()
end
self.bars = {}
end
--[[ events ]]--
function ProgressBarModule:PLAYER_ENTERING_WORLD()
self:UpdateAllBars()
end
function ProgressBarModule:UPDATE_EXHAUSTION()
self:UpdateAllBars()
end
function ProgressBarModule:PLAYER_UPDATE_RESTING()
self:UpdateAllBars()
end
function ProgressBarModule:PLAYER_XP_UPDATE()
self:UpdateAllBars()
end
function ProgressBarModule:UPDATE_FACTION(event)
self:UpdateAllBars()
end
function ProgressBarModule:ARTIFACT_XP_UPDATE()
self:UpdateAllBars()
end
function ProgressBarModule:UNIT_INVENTORY_CHANGED(event, unit)
if unit ~= 'player' then return end
self:UpdateAllBars()
end
function ProgressBarModule:HONOR_XP_UPDATE()
self:UpdateAllBars()
end
function ProgressBarModule:HONOR_LEVEL_UPDATE()
self:UpdateAllBars()
end
function ProgressBarModule:ADDON_LOADED(event, addonName)
if addonName == 'Dominos_Config' then
self:AddOptionsPanel()
self:UnregisterEvent('ADDON_LOADED')
end
end
function ProgressBarModule:AddOptionsPanel()
local panel = Dominos.Options.AddonOptions:NewPanel(L.Progress)
local prev = nil
local oneBarModeToggle = panel:Add('CheckButton', {
name = L.OneBarMode,
get = function()
return Addon.Config:OneBarMode()
end,
set = function(_, enable)
Addon.Config:SetOneBarMode(enable)
self:Unload()
self:Load()
end
})
oneBarModeToggle:SetPoint('TOPLEFT', 0, -2)
for i, key in ipairs{'xp', 'xp_bonus', 'honor', 'honor_bonus', 'artifact'} do
local picker = panel:Add('ColorPicker', {
name = L['Color_' .. key],
hasOpacity = true,
get = function()
return Addon.Config:GetColor(key)
end,
set = function(...)
Addon.Config:SetColor(key, ...)
for i, bar in pairs(self.bars) do
bar:Init()
end
end
})
picker:SetPoint('TOP', prev or oneBarModeToggle, 'BOTTOM', 0, -6)
prev = picker
end
end