Init
This commit is contained in:
commit
b77f539ae1
60
Core/Config.lua
Normal file
60
Core/Config.lua
Normal file
@ -0,0 +1,60 @@
|
||||
local addon, ns = ...
|
||||
local L = ns.L
|
||||
local T = ns.T
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- # CORE > CONFIG
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
-- ## RESET
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
StaticPopupDialogs.KLAZSTATS_RESET = {
|
||||
text = L.CONFIG_POPUP_RESET,
|
||||
button1 = ACCEPT,
|
||||
button2 = CANCEL,
|
||||
OnAccept = function()
|
||||
KlazStatsDB.Position = {'TOP', 'TOP', 0, 0}
|
||||
T.Anchor:ClearAllPoints()
|
||||
T.Anchor:SetPoint(KlazStatsDB.Position[1], UIParent, KlazStatsDB.Position[2], KlazStatsDB.Position[3], KlazStatsDB.Position[4])
|
||||
KlazStatsDB.UserPlaced = true
|
||||
print('Klaz|cff1994ffStats|r — |cnYELLOW_FONT_COLOR:'..L.CONFIG_POPUP_RESET_OK..'!|r')
|
||||
end,
|
||||
OnCancel = function() end,
|
||||
showAlert = true,
|
||||
timeout = 0,
|
||||
whileDead = 1,
|
||||
hideOnEscape = true,
|
||||
preferredIndex = 5,
|
||||
}
|
||||
|
||||
-- ## SLASH COMMAND
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
SlashCmdList['KLAZSTATS'] = function(msg, editbox)
|
||||
if string.lower(msg) == 'reset' then
|
||||
StaticPopup_Show('KLAZSTATS_RESET')
|
||||
elseif string.lower(msg) == 'unlock' then
|
||||
if not T.Anchor:IsShown() then
|
||||
T.Anchor:Show()
|
||||
KlazStatsDB.UserPlaced = false
|
||||
print('Klaz|cff1994ffStats|r — |cnGREEN_FONT_COLOR:'..L.COMMAND_UNLOCK..'|r')
|
||||
end
|
||||
elseif string.lower(msg) == 'lock' then
|
||||
if not KlazStatsDB.UserPlaced then
|
||||
T.Anchor:Hide()
|
||||
KlazStatsDB.UserPlaced = true
|
||||
print('Klaz|cff1994ffStats|r — |cnRED_FONT_COLOR:'..L.COMMAND_LOCK..'|r')
|
||||
end
|
||||
else
|
||||
print('------------------------------------------')
|
||||
print('Klaz|cff1994ffStats|r')
|
||||
print('------------------------------------------')
|
||||
print('|cff1994ff/kstats|r — '..L.COMMAND_HELP_SHORT..'.')
|
||||
print('|cnGREEN_FONT_COLOR:/kstats unlock|r — '..L.COMMAND_HELP_UNLOCK..'.')
|
||||
print('|cnRED_FONT_COLOR:/kstats lock|r — '..L.COMMAND_HELP_LOCK..'.')
|
||||
print('|cnYELLOW_FONT_COLOR:/kstats reset|r — '..L.COMMAND_HELP_RESET..'.')
|
||||
end
|
||||
end
|
||||
SLASH_KLAZSTATS1 = '/klazstats'
|
||||
SLASH_KLAZSTATS2 = '/kstats'
|
92
Core/Functions.lua
Normal file
92
Core/Functions.lua
Normal file
@ -0,0 +1,92 @@
|
||||
local addon, ns = ...
|
||||
local T = {}
|
||||
ns.T = T
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- # CORE > FUNCTIONS
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
-- ## FORMAT
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
T.Backdrop = {
|
||||
bgFile = 'Interface\\Buttons\\WHITE8x8',
|
||||
edgeFile = 'Interface\\Buttons\\WHITE8x8',
|
||||
tileEdge = false,
|
||||
edgeSize = 1,
|
||||
insets = { left = 1, right = 1, top = 1, bottom = 1 },
|
||||
}
|
||||
|
||||
T.ClassColor = RAID_CLASS_COLORS[select(2, UnitClass('player'))]
|
||||
|
||||
local function colorDurabilityPercent(perc)
|
||||
perc = perc > 1 and 1 or perc < 0 and 0 or perc
|
||||
local seg, relperc = math.modf(perc*2)
|
||||
local r1, g1, b1, r2, g2, b2 = select(seg*3+1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0)
|
||||
local r, g, b = r1+(r2-r1)*relperc, g1+(g2-g1)*relperc, b1+(b2-b1)*relperc
|
||||
return format('|cff%02x%02x%02x', r*255, g*255, b*255), r, g, b
|
||||
end
|
||||
|
||||
-- ## MODULES
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
T.GetLootSpec = function()
|
||||
local currentSpec = GetSpecialization()
|
||||
local currentSpecName = select(2, GetSpecializationInfo(currentSpec))
|
||||
local lootSpecID = GetLootSpecialization()
|
||||
local lootSpec = select(2, GetSpecializationInfoByID(lootSpecID))
|
||||
|
||||
-- if loot spec was manually set
|
||||
if lootSpec then
|
||||
return '|cnWHITE_FONT_COLOR:Loot:|r '..lootSpec..' '
|
||||
-- otherwise use current loot spec
|
||||
elseif currentSpec then
|
||||
return '|cnWHITE_FONT_COLOR:Loot:|r '..currentSpecName..' '
|
||||
else
|
||||
return ''
|
||||
end
|
||||
end
|
||||
|
||||
T.GetLatency = function()
|
||||
return '|cnWHITE_FONT_COLOR:'..select(3, GetNetStats())..' / '..select(4, GetNetStats())..'|r ms '
|
||||
end
|
||||
|
||||
T.GetFPS = function()
|
||||
return '|cnWHITE_FONT_COLOR:'..floor(GetFramerate())..'|r fps '
|
||||
end
|
||||
|
||||
local SLOTS = {}
|
||||
for _, slot in pairs({
|
||||
'Head',
|
||||
'Shoulder',
|
||||
'Chest',
|
||||
'Waist',
|
||||
'Legs',
|
||||
'Feet',
|
||||
'Wrist',
|
||||
'Hands',
|
||||
'MainHand',
|
||||
'SecondaryHand'
|
||||
}) do
|
||||
SLOTS[slot] = GetInventorySlotInfo(slot..'Slot')
|
||||
end
|
||||
|
||||
T.GetDurability = function()
|
||||
local l = 1
|
||||
for slot, id in pairs(SLOTS) do
|
||||
local d, md = GetInventoryItemDurability(id)
|
||||
if d and md and md ~= 0 then
|
||||
l = math.min(d/md, l)
|
||||
end
|
||||
end
|
||||
return format('%s%d|r dur ', colorDurabilityPercent(l), l*100)
|
||||
end
|
||||
|
||||
T.GetTime = function()
|
||||
-- return 24-hour notation
|
||||
-- local time = date('%H:%M')
|
||||
-- return '|cnWHITE_FONT_COLOR:'..time..'|r '
|
||||
-- return 12-hour notation with AM/PM
|
||||
local time = date('|cnWHITE_FONT_COLOR:%I:%M|r %p')
|
||||
return time
|
||||
end
|
44
Core/Launch.lua
Normal file
44
Core/Launch.lua
Normal file
@ -0,0 +1,44 @@
|
||||
local addon, ns = ...
|
||||
local C = {}
|
||||
ns.C = C
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- # CORE > LAUNCH
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
C.Settings = {
|
||||
Position = {'TOP', 'TOP', 0, 0},
|
||||
UserPlaced = true,
|
||||
Font = {
|
||||
Family = STANDARD_TEXT_FONT,
|
||||
Size = 12,
|
||||
Style = 'OUTLINE',
|
||||
Align = 'CENTER',
|
||||
},
|
||||
}
|
||||
|
||||
local loader = CreateFrame('Frame')
|
||||
loader:RegisterEvent('ADDON_LOADED')
|
||||
loader:SetScript('OnEvent', function(self, addon)
|
||||
if addon ~= KlazStats then
|
||||
local function initDB(db, defaults)
|
||||
if type(db) ~= 'table' then db = {} end
|
||||
if type(defaults) ~= 'table' then return db end
|
||||
|
||||
for k, v in pairs(defaults) do
|
||||
if type(v) == 'table' then
|
||||
db[k] = initDB(db[k], v)
|
||||
elseif type(v) ~= type(db[k]) then
|
||||
db[k] = v
|
||||
end
|
||||
end
|
||||
|
||||
return db
|
||||
end
|
||||
|
||||
KlazStatsDB = initDB(KlazStatsDB, C.Settings)
|
||||
C.Settings = KlazStatsDB
|
||||
|
||||
self:UnregisterEvent('ADDON_LOADED')
|
||||
end
|
||||
end)
|
38
Core/Localization.lua
Normal file
38
Core/Localization.lua
Normal file
@ -0,0 +1,38 @@
|
||||
local addon, ns = ...
|
||||
local L = {}
|
||||
ns.L = L
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- # CORE > LOCALIZATION
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
-- ## ENGLISH
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
L['COMMAND_HELP_SHORT'] = 'Short command'
|
||||
L['COMMAND_HELP_UNLOCK'] = 'Unlocks frame'
|
||||
L['COMMAND_HELP_LOCK'] = 'Locks frame in current position'
|
||||
L['COMMAND_HELP_RESET'] = 'Resets frame position to default position (top center of screen)'
|
||||
|
||||
L['COMMAND_UNLOCK'] = 'Unlocked'
|
||||
L['COMMAND_LOCK'] = 'Locked'
|
||||
|
||||
L['CONFIG_POPUP_RESET'] = 'Klaz|cff1994ffStats|r\n|cnNORMAL_FONT_COLOR:Reset to default position?|r'
|
||||
L['CONFIG_POPUP_RESET_OK'] = 'Reset completed'
|
||||
|
||||
local locale = GetLocale()
|
||||
if locale == 'en_GB' or locale == 'enUS' then return end -- ENGLISH
|
||||
|
||||
-- ## OTHER
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
-- if locale == 'esMX' then return end -- SPANISH (MEXICO)
|
||||
-- if locale == 'pt_BR' then return end -- PORTUGEUSE
|
||||
-- if locale == 'de_DE' then return end -- GERMAN
|
||||
-- if locale == 'es_ES' then return end -- SPANISH (SPAIN)
|
||||
-- if locale == 'fr_FR' then return end -- FRENCH
|
||||
-- if locale == 'it_IT' then return end -- ITALIAN
|
||||
-- if locale == 'ru_RU' then return end -- RUSSIAN
|
||||
-- if locale == 'ko_KR' then return end -- KOREAN
|
||||
-- if locale == 'zh_TW' then return end -- CHINESE (TRADITIONAL)
|
||||
-- if locale == 'zh_CN' then return end -- CHINESE (SIMPLIFIED)
|
39
Core/Mover.lua
Normal file
39
Core/Mover.lua
Normal file
@ -0,0 +1,39 @@
|
||||
local addon, ns = ...
|
||||
local T = ns.T
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- # CORE > MOVER
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
T.Anchor = CreateFrame('Frame', 'KlazStatsAnchor', UIParent)
|
||||
T.Anchor:SetSize(400, 25)
|
||||
if not T.Anchor.SetBackdrop then Mixin(T.Anchor, BackdropTemplateMixin) end
|
||||
T.Anchor:SetBackdrop(T.Backdrop)
|
||||
T.Anchor:SetBackdropColor(0.02, 0.02, 0.02, 0.8)
|
||||
T.Anchor:SetBackdropBorderColor(T.ClassColor.r, T.ClassColor.g, T.ClassColor.b, 1)
|
||||
T.Anchor:SetFrameStrata('HIGH')
|
||||
T.Anchor:EnableMouse(true)
|
||||
T.Anchor:SetMovable(true)
|
||||
T.Anchor:SetUserPlaced(true)
|
||||
T.Anchor:SetClampedToScreen(true)
|
||||
T.Anchor:RegisterForDrag('LeftButton')
|
||||
T.Anchor:RegisterEvent('PLAYER_LOGIN')
|
||||
T.Anchor:SetScript('OnEvent', function(self, event)
|
||||
self:ClearAllPoints()
|
||||
self:SetPoint(KlazStatsDB.Position[1], UIParent, KlazStatsDB.Position[2], KlazStatsDB.Position[3], KlazStatsDB.Position[4])
|
||||
|
||||
if KlazStatsDB.UserPlaced then self:Hide() end
|
||||
end)
|
||||
T.Anchor:SetScript('OnDragStart', function(self) self:StartMoving() end)
|
||||
T.Anchor:SetScript('OnDragStop', function(self)
|
||||
self:StopMovingOrSizing()
|
||||
local point, _, relativePoint, xOffset, yOffset = self:GetPoint()
|
||||
KlazStatsDB.Position[1] = point
|
||||
KlazStatsDB.Position[2] = relativePoint
|
||||
KlazStatsDB.Position[3] = xOffset
|
||||
KlazStatsDB.Position[4] = yOffset
|
||||
end)
|
||||
|
||||
T.Anchor.text = T.Anchor:CreateFontString(nil, 'OVERLAY', 'GameFontHighlight')
|
||||
T.Anchor.text:SetAllPoints(T.Anchor)
|
||||
T.Anchor.text:SetText('Klaz|cff1994ffStats|r — |cnRED_FONT_COLOR:/kstats lock|r')
|
14
KlazStats.toc
Normal file
14
KlazStats.toc
Normal file
@ -0,0 +1,14 @@
|
||||
## Interface: 100205
|
||||
## Title: Klaz|cff1994ffStats|r
|
||||
## Author: Klaz
|
||||
## Notes: Displays loot specialization, fps, latency, durability, and clock on screen. (/klazstats)
|
||||
## IconTexture: Interface\AddOns\KlazStats\Media\KlazAddOnIcon.blp
|
||||
## SavedVariables: KlazStatsDB
|
||||
|
||||
Core\Launch.lua
|
||||
Core\Localization.lua
|
||||
Core\Functions.lua
|
||||
Core\Config.lua
|
||||
Core\Mover.lua
|
||||
|
||||
Modules\Stats.lua
|
BIN
Media/KlazAddOnIcon.blp
Normal file
BIN
Media/KlazAddOnIcon.blp
Normal file
Binary file not shown.
43
Modules/Stats.lua
Normal file
43
Modules/Stats.lua
Normal file
@ -0,0 +1,43 @@
|
||||
local addon, ns = ...
|
||||
local L = ns.L
|
||||
local T = ns.T
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- # MODULES > STATS
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
local fontFamily = STANDARD_TEXT_FONT
|
||||
local fontSize = 12
|
||||
local fontOutline = 'OUTLINE'
|
||||
local fontAlign = 'CENTER'
|
||||
|
||||
local stats = CreateFrame('Frame', 'KlazStats', UIParent)
|
||||
stats:SetAllPoints(T.Anchor)
|
||||
|
||||
stats.text = stats:CreateFontString(nil, 'BACKGROUND')
|
||||
stats.text:SetPoint(fontAlign, stats)
|
||||
stats.text:SetJustifyH(fontAlign)
|
||||
stats.text:SetFont(fontFamily, fontSize, fontOutline)
|
||||
stats.text:SetTextColor(T.ClassColor.r, T.ClassColor.g, T.ClassColor.b)
|
||||
|
||||
-- ## UPDATE
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
local lastUpdate = 0
|
||||
local function UpdateStats(self, elapsed)
|
||||
lastUpdate = lastUpdate + elapsed
|
||||
|
||||
if lastUpdate > 1 then
|
||||
lastUpdate = 0
|
||||
stats.text:SetText(T.GetLootSpec()..T.GetFPS()..T.GetLatency()..T.GetDurability()..T.GetTime())
|
||||
end
|
||||
end
|
||||
|
||||
stats:RegisterEvent('PLAYER_LOGIN')
|
||||
stats:RegisterEvent('PLAYER_ENTERING_WORLD')
|
||||
stats:RegisterEvent('UPDATE_INVENTORY_DURABILITY')
|
||||
stats:RegisterEvent('PLAYER_LOOT_SPEC_UPDATED')
|
||||
stats:RegisterEvent('PLAYER_SPECIALIZATION_CHANGED')
|
||||
stats:SetScript('OnEvent', function(self, event)
|
||||
self:SetScript('OnUpdate', UpdateStats)
|
||||
end)
|
Loading…
Reference in New Issue
Block a user