-------------------------------------------------------------------------------------------------
-- Libraries --
-------------------------------------------------------------------------------------------------
local LAM2 = LibStub:GetLibrary("LibAddonMenu-2.0")
Dek01 = {}
Dek01.Default = {
OffsetX = 20,
OffsetY = 75,
Show = true,
StaminaBarColor = {1, 0, 0, 1},
BarWidth = 300,
BarHeight = 50,
}
-------------------------------------------------------------------------------------------------
-- Initialize Variables --
-------------------------------------------------------------------------------------------------
Dek01.name = "Dek01"
Dek01.version = 1
Dek01.varVersion = 2
-------------------------------------------------------------------------------------------------
-- OnAddOnLoaded --
-------------------------------------------------------------------------------------------------
function Dek01.OnAddOnLoaded(event, addonName)
if addonName ~= Dek01.name then return end
Dek01:Initialize()
end
-------------------------------------------------------------------------------------------------
-- Initialize Function --
-------------------------------------------------------------------------------------------------
function Dek01:Initialize()
Dek01.savedVars = ZO_SavedVars:New("Dek01Vars", Dek01.varVersion, nil, Dek01.Default)
Dek01.CreateSettingsWindow()
Dek01StaminaBarWindow:SetHidden(not Dek01.savedVars.Show)
Dek01.SetBarSize(Dek01.savedVars.BarWidth, Dek01.savedVars.BarHeight)
Dek01StaminaBarWindowStatusBar:SetColor(unpack(Dek01.savedVars.StaminaBarColor))
local current, max, effectiveMax = GetUnitPower("player", POWERTYPE_STAMINA)
Dek01StaminaBarWindowStatusBar:SetMinMax(0, max) -- Set max stamina
Dek01StaminaBarWindowStatusBar:SetValue(current) -- Set current stamina
local ourName = GetUnitName("player") --Get player name
Dek01StaminaBarWindowLabel:SetText(ourName) --Set label to player name
Dek01StaminaBarWindow.ClearAnchors()
Dek01StaminaBarWindow:SetAnchor(TOPLEFT, GuiRoot, TOPLEFT, Dek01.savedVars.OffsetX, Dek01.savedVars.OffsetY)
EVENT_MANAGER:UnregisterForEvent(Dek01.name, EVENT_ADD_ON_LOADED) --Unregister event
end
-------------------------------------------------------------------------------------------------
-- Other Functions --
-------------------------------------------------------------------------------------------------
function Dek01.UpdateStamina(eventCode, unitTag, powerIndex, powerType, powerValue, powerMax, powerEffectiveMax)
if powerType == POWERTYPE_STAMINA then
Dek01StaminaBarWindowStatusBar:SetMinMax(0, powerMax) -- Set max stamina
Dek01StaminaBarWindowStatusBar:SetValue(powerValue) -- Set current stamina
end
end
function Dek01.SaveLoc()
Dek01.savedVars.OffsetX = Dek01StaminaBarWindow:GetLeft()
Dek01.savedVars.OffsetY = Dek01StaminaBarWindow:GetTop()
end
-------------------------------------------------------------------------------------------------
-- Restore Functions --
-------------------------------------------------------------------------------------------------
function Dek01.SetBarSize(_width, _height)
Dek01StaminaBarWindowStatusBar:SetDimensions(_width, _height)
Dek01StaminaBarWindowBackdrop:SetDimensions(_width, _height)
Dek01StaminaBarBorder:SetDimensions(_width, _height)
Dek01StaminaBarWindow:SetDimensions(_width, _height)
end
-------------------------------------------------------------------------------------------------
-- Menu Functions --
-------------------------------------------------------------------------------------------------
function Dek01.CreateSettingsWindow()
local panelData = {
type = "panel",
name = "Dek01",
displayName = "DekUI",
author = "Dekthro",
version = Dek01.version,
slashCommand = "/dekui",
registerForRefresh = true,
registerForDefaults = true,
}
local cntrlOptionsPanel = LAM2:RegisterAddonPanel("Dek_01", panelData)
local optionsData = {
[1] = {
type = "header",
name = "Stamina Bar Settings",
},
[2] = {
type = "description",
text = "Here you can adjust how the stamina bar works.",
},
[3] = {
type = "checkbox",
name = "Show Stamina Bar",
tooltip = "When ON the stamina bar will be visible. When OFF the stamina bar will be hidden.",
default = true,
getFunc = function() return Dek01.savedVars.Show end,
setFunc = function(newValue)
Dek01.savedVars.Show = newValue
Dek01StaminaBarWindow:SetHidden(not newValue) end,
},
[4] = {
type = "slider",
name = "Select Width",
tooltip = "Adjusts the width of the stamina bar.",
min = 100,
max = 1000,
step = 1,
default = 300,
getFunc = function() return Dek01.savedVars.BarWidth end,
setFunc = function(newValue)
Dek01.savedVars.BarWidth = newValue
Dek01.SetBarSize(newValue, Dek01.savedVars.BarHeight)
end,
},
[5] = {
type = "slider",
name = "Select Height",
tooltip = "Adjusts the height of the stamina bar.",
min = 25,
max = 100,
step = 1,
default = 50,
getFunc = function() return Dek01.savedVars.BarHeight end,
setFunc = function(newValue)
Dek01.savedVars.BarHeight = newValue
Dek01.SetBarSize(Dek01.savedVars.BarWidth, newValue)
end,
},
[6] = {
type = "submenu",
name = "Colors",
tooltip = "Allows you to change colors.",
controls = {
[1] = {
type = "colorpicker",
name = "Bar Color",
tooltip = "Changes the color of the stamina bar background.",
getFunc = function() return unpack(Dek01.savedVars.StaminaBarColor ) end,
setFunc = function(r,g,b,a)
local alpha = Dek01StaminaBarWindowStatusBar:GetAlpha()
Dek01.savedVars.StaminaBarColor = { r, g, b, a}
Dek01StaminaBarWindowStatusBar:SetColor( r, g, b, a)
end,
},
}
},
}
LAM2:RegisterOptionControls("Dek_01", optionsData)
end
-------------------------------------------------------------------------------------------------
-- Register Events --
-------------------------------------------------------------------------------------------------
EVENT_MANAGER:RegisterForEvent(Dek01.name, EVENT_ADD_ON_LOADED, Dek01.OnAddOnLoaded)
EVENT_MANAGER:RegisterForEvent(Dek01.name, EVENT_POWER_UPDATE, Dek01.UpdateStamina)