-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOptionsPanel.lua
More file actions
121 lines (103 loc) · 4.83 KB
/
OptionsPanel.lua
File metadata and controls
121 lines (103 loc) · 4.83 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
local _, HealthAlert = ...
HealthAlert.HealthAlertOptions = {
global = {
HealthPercent = 35,
AlertSound = "Interface\\AddOns\\HealthAlert\\Sounds\\Alerts\\BeepBeep.ogg",
SoundChannel = "Master",
SoundIntervalSeconds = 1,
LastAlertUnixTime = time(),
MuteAlertSound = false,
DisableRaidWarning = false,
RaidWarningText = "LOW HEALTH - HEAL UP!",
PlayerName = GetUnitName('player'),
PlayerHealth = UnitHealth('player'),
DisplayVersion = GetAddOnMetadata('HealthAlert', 'Version')
}
}
function HealthAlert:ResetSettings()
self.db:ResetDB()
end
function SetupOptionsPanel()
--[[ Main Panel ]]--
local configFrame = CreateFrame('Frame', 'HealthAlertConfigFrame', InterfaceOptionsFramePanelContainer)
configFrame:Hide()
configFrame.name = 'HealthAlert'
InterfaceOptions_AddCategory(configFrame)
--[[ Title ]]--
local titleLabel = configFrame:CreateFontString(nil, 'ARTWORK', 'GameFontNormalLarge')
titleLabel:SetPoint('TOPLEFT', configFrame, 'TOPLEFT', 16, -16)
titleLabel:SetText('HealthAlert')
-- [[ Version ]] --
local versionLabel = configFrame:CreateFontString(nil, 'ARTWORK', 'GameFontNormalSmall')
versionLabel:SetPoint('TOP', configFrame, 'TOP', 0, -16)
versionLabel:SetText('v' .. GetAddOnMetadata('HealthAlert', 'Version'))
--[[ Subtitle ]]--
local displayLabel = configFrame:CreateFontString(nil, 'ARTWORK', 'GameFontHighlightSmall')
displayLabel:SetPoint('TOPLEFT', titleLabel, 'BOTTOMLEFT', 0, -16)
displayLabel:SetText("Alert options")
--[[ Health Slider Title ]]--
local healthSliderTitle = configFrame:CreateFontString(nil, 'ARTWORK', 'GameFontNormalSmall')
healthSliderTitle:SetPoint('TOPLEFT', displayLabel, 'TOPLEFT', 0, -24)
healthSliderTitle:SetText("Health alert percentage")
--[[ Health Slider ]]--
local healthSlider = CreateFrame('Slider', 'HealthAlertConfigFrameHealthSlider', configFrame, 'OptionsSliderTemplate')
healthSlider:SetPoint('RIGHT', healthSliderTitle, 'RIGHT', 182, 0)
healthSlider:SetThumbTexture("Interface\\Buttons\\UI-SliderBar-Button-Horizontal")
healthSlider:SetMinMaxValues(5, 85)
healthSlider:SetValueStep(1)
healthSlider:SetValue(HealthAlert.db.global.HealthPercent)
healthSlider:SetOrientation('HORIZONTAL')
getglobal(healthSlider:GetName() .. 'Low'):SetText('5')
getglobal(healthSlider:GetName() .. 'High'):SetText('85')
getglobal(healthSlider:GetName() .. 'Text'):SetText(healthSlider:GetValue())
healthSlider:SetScript("OnValueChanged", function(self, newvalue)
UpdateHealthSlider(self, newvalue)
end)
--[[ Mute Alert Checkbox ]]--
local muteAlert = CreateFrame('CheckButton', 'HealthAlertConfigMuteAlertCheckButton', configFrame, 'InterfaceOptionsCheckButtonTemplate')
muteAlert:SetPoint('TOPLEFT', healthSliderTitle, 'LEFT', -4, -16)
muteAlert:SetChecked(HealthAlert.db.global.MuteAlertSound)
muteAlert:SetScript("OnClick", function(self)
UpdateMuteAlertSound(self:GetChecked())
end)
--[[ Mute Alert Title ]]--
local muteAlertTitle = configFrame:CreateFontString(nil, 'ARTWORK', 'GameFontNormal')
muteAlertTitle:SetPoint('RIGHT', muteAlert, 'RIGHT', 106, 0)
muteAlertTitle:SetText("Mute sound alert")
--[[ Disable Raidwarning Checkbox ]]--
local muteRaidwarning = CreateFrame('CheckButton', 'HealthAlertConfigDisableRaidwarningCheckButton', configFrame, 'InterfaceOptionsCheckButtonTemplate')
muteRaidwarning:SetPoint('TOPLEFT', muteAlert, 'LEFT', 0, -10)
muteRaidwarning:SetChecked(HealthAlert.db.global.DisableRaidWarning)
muteRaidwarning:SetScript("OnClick", function(self)
UpdateDisableRaidwarning(self:GetChecked())
end)
--[[ Disable Raidwarning Title ]]--
local muteRaidwarningTitle = configFrame:CreateFontString(nil, 'ARTWORK', 'GameFontNormal')
muteRaidwarningTitle:SetPoint('TOPLEFT', muteAlertTitle, 'LEFT', 0, -16)
muteRaidwarningTitle:SetText("Disable raidwarning")
--[[ Disable Raidwarning Checkbox ]]--
--[[ Reset Settings Button ]]--
local resetSettings = CreateFrame('Button', 'HealthAlertConfigFrameResetSettingsButton', configFrame, 'UIPanelButtonTemplate')
resetSettings:SetPoint('BOTTOMRIGHT', InterfaceOptionsFramePanelContainer, 'BOTTOMRIGHT', -16, 16)
resetSettings:SetWidth(128)
resetSettings:SetHeight(24)
resetSettings:SetText("Reset Settings")
resetSettings:SetScript("OnClick", function()
HealthAlert:ResetSettings()
UpdateHealthSlider(healthSlider, HealthAlert.db.global.HealthPercent)
healthSlider:SetValue(HealthAlert.db.global.HealthPercent)
muteAlert:SetChecked(HealthAlert.db.global.MuteAlertSound)
muteRaidwarning:SetChecked(HealthAlert.db.global.DisableRaidWarning)
end)
end
function UpdateMuteAlertSound(value)
HealthAlertOptions.global.MuteAlertSound = value
end
function UpdateDisableRaidwarning(value)
HealthAlertOptions.global.DisableRaidWarning = value
end
function UpdateHealthSlider(self, newvalue)
local v = math.floor(newvalue)
HealthAlertOptions.global.HealthPercent = v
getglobal(self:GetName() .. 'Text'):SetText(v)
end