-
Notifications
You must be signed in to change notification settings - Fork 0
/
se_resource_bars.lua
129 lines (109 loc) · 3.86 KB
/
se_resource_bars.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
local SE_ResourceBars = SimpleExtension.Create("SE_RESOURCE_BARS", 1)
local wm = GetWindowManager()
local hp = ZO_PlayerAttributeHealth
local mp = ZO_PlayerAttributeMagicka
local sp = ZO_PlayerAttributeStamina
function SE_ResourceBars:New()
local obj = ZO_Object.New(self)
obj:Initialize({
always_show = true,
show_centered = true,
size_locked = true,
})
obj:controls("Resource Bars", {
{
type = "checkbox",
name = "Always show",
tooltip = "Always show.",
getFunc = function() return obj.settings.always_show end,
setFunc = function(value) obj:toggleAlwaysShow(value) end,
},
{
type = "checkbox",
name = "Show centered",
tooltip = "Show centered.",
getFunc = function() return obj.settings.show_centered end,
setFunc = function(value) obj:toggleShowCentered(value) end,
},
{
type = "checkbox",
name = "Size locked",
tooltip = "Size locked.",
getFunc = function() return obj.settings.size_locked end,
setFunc = function(value) obj:toggleSizeLock(value) end,
},
})
obj.default_anchors = {}
obj.default_sizes = {}
return obj
end
function SE_ResourceBars:Run()
EVENT_MANAGER:RegisterForEvent(self.SE_NAME, EVENT_PLAYER_ACTIVATED, function()
EVENT_MANAGER:UnregisterForEvent(self.SE_NAME, EVENT_PLAYER_ACTIVATED)
self:saveDefaultAnchors()
self:toggleAlwaysShow()
self:toggleShowCentered()
self:toggleSizeLock()
end)
end
function SE_ResourceBars:restoreDefaultAnchors()
for bar, data in pairs(self.default_anchors) do
bar:ClearAnchors()
bar:SetAnchor(unpack(data))
end
end
function SE_ResourceBars:saveDefaultAnchors()
for _, bar in ipairs({hp, sp, mp}) do
local isValid, point, relTo, relPoint, offsX, offsY = bar:GetAnchor()
self.default_anchors[bar] = {point, relTo, relPoint, offsX, offsY}
end
end
function SE_ResourceBars:toggleAlwaysShow(value)
self.settings.always_show = (value == nil) or value
if self.settings.always_show then
SetSetting(SETTING_TYPE_UI, UI_SETTING_FADE_PLAYER_BARS, "0")
else
SetSetting(SETTING_TYPE_UI, UI_SETTING_FADE_PLAYER_BARS, "1")
end
end
function SE_ResourceBars:toggleShowCentered(value)
self.settings.show_centered = (value == nil) or value
if self.settings.show_centered then
local rb = hp:GetParent()
local anchors = {
[hp] = {CENTER, rb, CENTER, 0, 0},
[sp] = {LEFT , hp, RIGHT , 12, 0},
[mp] = {RIGHT , hp, LEFT , -12, 0},
}
for bar, data in pairs(anchors) do
local w, h = bar:GetDimensions()
bar:ClearAnchors()
bar:SetAnchor(unpack(data))
end
else
self:restoreDefaultAnchors()
end
end
function SE_ResourceBars:toggleSizeLock(value)
self.settings.size_locked = (value == nil) or value
for k, v in pairs(PLAYER_ATTRIBUTE_BARS.attributeVisualizer.visualModules) do
if (v.expandedWidth) then
if (not self.default_sizes.expandedWidth or not self.default_sizes.shrunkWidth) then
self.default_sizes.expandedWidth = v.expandedWidth
self.default_sizes.shrunkWidth = v.shrunkWidth
end
if (self.settings.size_locked) then
v.expandedWidth, v.shrunkWidth = v.normalWidth, v.normalWidth
for stat, _ in pairs(v.barControls) do
v.barInfo[stat].state = ATTRIBUTE_BAR_STATE_NORMAL
end
else
v.expandedWidth = self.default_sizes.expandedWidth
v.shrunkWidth = self.default_sizes.shrunkWidth
v.barInfo = {}
v:OnUnitChanged()
end
v:OnUnitChanged()
end
end
end