Skip to content

Commit

Permalink
Move frame definitions into XML
Browse files Browse the repository at this point in the history
  • Loading branch information
funkjedi committed Oct 29, 2022
1 parent a995c78 commit 2663627
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 96 deletions.
23 changes: 13 additions & 10 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@

root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.xml]
indent_size = 2
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"[xml]": {
"editor.formatOnSave": false,
},
"editor.formatOnSave": true,
"Lua.diagnostics.disable": [
//"undefined-global"
],
Expand Down
6 changes: 3 additions & 3 deletions SheepMonitor.toc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
## Interface: 90205
## Interface: 100000
## Title: Sheep Monitor
## Notes: Provides various methods of notification to help you keep track of your flock.
## Author: funkjedi
## Version: 1.25
## Version: 1.26
## SavedVariables: SheepMonitorDatabase
## OptionalDeps: Ace3, LibAuras, LibAuraInfo-1.0
## X-Curse-Project-ID: 28218
Expand All @@ -17,6 +17,6 @@ localization\localization.ruRU.lua
localization\localization.zhTW.lua
main.lua
auras.lua
timers.lua
timers.xml
integrations.lua
options.lua
2 changes: 1 addition & 1 deletion auras.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ SheepMonitor.trackableAuras = {
[61025] = 'Interface\\Icons\\Spell_Nature_GuardianWard', -- Polymorph (Serpent)
[61780] = 'Interface\\Icons\\Achievement_WorldEvent_Thanksgiving', -- Polymorph (Turkey)
[28271] = 'Interface\\Icons\\Ability_Hunter_Pet_Turtle', -- Polymorph (Turtle)
[383121] = 'Interface\\Icons\\Spell_Nature_DoublePolymorph1', -- Mass Polymorph
-- [219393] = 'Interface\\Icons\\Spell_Nature_Polymorph', -- [Crittermorph] Polymorph
-- [219407] = 'Interface\\Icons\\Achievement_Halloween_Cat_01', -- [Crittermorph] Polymorph (Black Cat)
-- [277793] = 'Interface\\Icons\\Inv_Bee_Default', -- [Crittermorph] Polymorph (Bumblebee)
Expand All @@ -31,7 +32,6 @@ SheepMonitor.trackableAuras = {
-- [219403] = 'Interface\\Icons\\Spell_Magic_PolymorphPig', -- [Crittermorph] Polymorph (Pig)
-- [219401] = 'Interface\\Icons\\Inv_Pet_Porcupine', -- [Crittermorph] Polymorph (Porcupine)
-- [219398] = 'Interface\\Icons\\Ability_Hunter_Pet_Turtle', -- [Crittermorph] Polymorph (Turtle)

[51514] = 'Interface\\Icons\\Spell_Shaman_Hex', -- Hex
[76780] = 'Interface\\Icons\\Spell_Shaman_BindElemental', -- Bind Elemental
[9484] = 'Interface\\Icons\\Spell_Nature_Slow', -- Shackle Undead
Expand Down
5 changes: 5 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
1.26
- updated for patch 10.0
- moved frame definition into XML
- added support for Mass Polymorph

1.25
- updated for patch 9.2
- fixed bug where names wouldn't always show
Expand Down
1 change: 1 addition & 0 deletions main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ LibAuraInfo.auraInfo[161353] = '60;1' -- updating polymorph value for BFA
LibAuraInfo.auraInfo[161354] = '60;1' -- updating polymorph value for BFA
LibAuraInfo.auraInfo[161355] = '60;1' -- updating polymorph value for BFA
LibAuraInfo.auraInfo[161372] = '60;1' -- updating polymorph value for BFA
LibAuraInfo.auraInfo[383121] = '60;1' -- adding mass polymorph
LibAuraInfo.auraInfo[3355] = '60;1' -- fixing incorrect value
LibAuraInfo.auraInfo[115078] = '40;1' -- adding ability_monk_paralysis
-- LuaFormatter on
Expand Down
115 changes: 33 additions & 82 deletions timers.lua
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
local addonName, SheepMonitor = ...

local TimerMixin = {}

local notifierFrame
local timerInstances = {}

local fontFamily = [[Interface\AddOns\SheepMonitor\fonts\DroidSans.ttf]]
SheepMonitorTimerMixin = {}

BACKDROP_SHEEPMONITOR_TIMER_32_1 = {
bgFile = 'Interface\\DialogFrame\\UI-DialogBox-Background',
edgeFile = 'Interface\\DialogFrame\\UI-DialogBox-Background',
tile = true,
tileSize = 32,
edgeSize = 1,
insets = { left = 0, right = 0, top = 0, bottom = 0 },
}

SHEEPMONITOR_TEXT_FONT = [[Interface\AddOns\SheepMonitor\fonts\DroidSans.ttf]]

-- use default game font for non-English locales
if not string.match(GetLocale(), '^en') then
fontFamily = [[Fonts\FRIZQT__.ttf]]
SHEEPMONITOR_TEXT_FONT = STANDARD_TEXT_FONT
end

local function createNotifierFrame()
Expand Down Expand Up @@ -45,81 +53,24 @@ local function createAuraTimer()
end

local frameName = 'SheepMonitorTimer' .. (#timerInstances + 1)
local timer = CreateFrame('Frame', frameName, createNotifierFrame(), 'BackdropTemplate')

Mixin(timer, TimerMixin)

timer:Hide()
timer:SetWidth(140)
timer:SetHeight(28)
timer:SetPoint('CENTER')
timer:EnableMouse(true)

---@diagnostic disable
timer:SetScript('OnHide', timer.StopDragging)
timer:SetScript('OnMouseDown', timer.StartDragging)
timer:SetScript('OnMouseUp', timer.StopDragging)
---@diagnostic enable

timer:SetBackdrop({
bgFile = 'Interface\\DialogFrame\\UI-DialogBox-Background',
edgeFile = 'Interface\\DialogFrame\\UI-DialogBox-Background',
tile = true,
tileSize = 32,
edgeSize = 1,
insets = { left = 0, right = 0, top = 0, bottom = 0 },
})

-- create our icon texture; default to the polymorph spell
local texture = timer:CreateTexture(frameName .. 'Icon', 'ARTWORK')
texture:SetTexture('Interface\\Icons\\Spell_nature_polymorph')
texture:SetSize(23, 23)
texture:SetPoint('LEFT', 3, 0)
texture:SetTexCoord(0.08, 0.92, 0.08, 0.92)

-- create our status bar
local statusBar = CreateFrame('StatusBar', frameName .. 'StatusBar', timer, 'TextStatusBar')
statusBar:SetWidth(110)
statusBar:SetHeight(26)
statusBar:SetPoint('BOTTOMLEFT', timer, 27, 1)
statusBar:SetStatusBarTexture('Interface\\TargetingFrame\\UI-StatusBar')
statusBar:SetStatusBarColor(1, 0, 0)

-- create our unit name label
local label = statusBar:CreateFontString(frameName .. 'StatusBarLabel', 'ARTWORK', 'GameFontHighlightSmall')
label:SetPoint('TOP')
label:SetPoint('BOTTOM')
label:SetPoint('LEFT', 4, 0)
label:SetPoint('RIGHT', -26, 0)
label:SetJustifyH('LEFT')
label:SetWordWrap(true) ---@diagnostic disable-line
label:SetFont(fontFamily, 11)

-- create our timer text
local countdown = statusBar:CreateFontString(frameName .. 'StatusBarCountdown', 'ARTWORK', 'GameFontNormal')
countdown:SetPoint('TOP')
countdown:SetPoint('BOTTOM')
countdown:SetPoint('RIGHT', -4, 0)
countdown:SetFont(fontFamily, 13)

timer.countdown = countdown
timer.label = label
timer.statusBar = statusBar
timer.texture = texture
local timer = CreateFrame('Frame', frameName, createNotifierFrame(), 'SheepMonitorTimerTemplate')

timer.StatusBar.Label:SetFont([[Interface\AddOns\SheepMonitor\fonts\DroidSans.ttf]], 11)
timer.StatusBar.Countdown:SetFont([[Interface\AddOns\SheepMonitor\fonts\DroidSans.ttf]], 13)

table.insert(timerInstances, timer)

return timer, #timerInstances
end

function TimerMixin:StartDragging(button)
function SheepMonitorTimerMixin:StartDragging(button)
if button == 'RightButton' and not self.isMoving then
self.isMoving = true
notifierFrame:StartMoving()
end
end

function TimerMixin:StopDragging(button)
function SheepMonitorTimerMixin:StopDragging(button)
if self.isMoving then
self.isMoving = false
notifierFrame:StopMovingOrSizing()
Expand All @@ -131,19 +82,19 @@ function TimerMixin:StopDragging(button)
end
end

function TimerMixin:Start(aura)
function SheepMonitorTimerMixin:Start(aura)
if self.aura then
self:Stop()
end

self.aura = aura

if SheepMonitor.db.char.enableNotifier then
self.label:SetText(aura.destName)
self.texture:SetTexture(aura.texture)
self.statusBar:SetMinMaxValues(0, aura.duration)
self.statusBar:SetValue(aura.duration)
self.countdown:SetText(aura.duration)
self.Icon:SetTexture(aura.texture)
self.StatusBar:SetMinMaxValues(0, aura.duration)
self.StatusBar:SetValue(aura.duration)
self.StatusBar.Countdown:SetText(aura.duration)
self.StatusBar.Label:SetText(aura.destName)
SheepMonitor:UpdateAuraTimers()
end

Expand All @@ -152,19 +103,19 @@ function TimerMixin:Start(aura)
return self
end

function TimerMixin:Stop()
function SheepMonitorTimerMixin:Stop()
self:CancelRepeatingTimers()
self:Hide()
self.aura = nil
SheepMonitor:UpdateAuraTimers()
end

function TimerMixin:GetRemaining(raw)
function SheepMonitorTimerMixin:GetRemaining(raw)
local remaining = self.aura.duration - (GetTime() - self.aura.timestamp)
return raw and remaining or floor(remaining)
end

function TimerMixin:ScheduleRepeatingTimers()
function SheepMonitorTimerMixin:ScheduleRepeatingTimers()
local onFinished = function(timer)
local remaining = timer:GetRemaining()

Expand All @@ -191,21 +142,21 @@ function TimerMixin:ScheduleRepeatingTimers()
end
end

function TimerMixin:CancelRepeatingTimers()
function SheepMonitorTimerMixin:CancelRepeatingTimers()
SheepMonitor:CancelTimer(self.onFinishedTimer, true)
SheepMonitor:CancelTimer(self.onUpdateTimer, true)
end

function TimerMixin:OnFinished(remaining)
function SheepMonitorTimerMixin:OnFinished(remaining)
SheepMonitor:POLYMORPH_UPDATE(self.aura, remaining)

if self:IsVisible() then
self.countdown:SetText(remaining)
self.StatusBar.Countdown:SetText(remaining)
end
end

function TimerMixin:OnUpdate(remaining)
self.statusBar:SetValue(remaining)
function SheepMonitorTimerMixin:OnUpdate(remaining)
self.StatusBar:SetValue(remaining)
end

function SheepMonitor:StartAuraTimer(aura)
Expand Down
65 changes: 65 additions & 0 deletions timers.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
..\FrameXML\UI.xsd">

<Script file="timers.lua"/>

<Frame name="SheepMonitorTimerTemplate" inherits="BackdropTemplate" mixin="SheepMonitorTimerMixin" virtual="true" enableMouse="true" hidden="true">
<Size x="140" y="28"/>
<Anchors>
<Anchor point="CENTER" x="0" y="0"/>
</Anchors>
<KeyValues>
<KeyValue key="backdropInfo" value="BACKDROP_SHEEPMONITOR_TIMER_32_1" type="global"/>
</KeyValues>
<Scripts>
<OnHide method="StopDragging"/>
<OnMouseDown method="StartDragging"/>
<OnMouseUp method="StopDragging"/>
</Scripts>
<Layers>
<Layer level="ARTWORK">
<Texture parentKey="Icon" file="Interface\Icons\Spell_nature_polymorph">
<Size x="23" y="23"/>
<TexCoords left="0.08" right="0.92" top="0.08" bottom="0.92"/>
<Anchors>
<Anchor point="LEFT" x="3" y="0"/>
</Anchors>
</Texture>
</Layer>
</Layers>
<Frames>
<StatusBar parentKey="StatusBar" inherits="TextStatusBar">
<Size x="110" y="26"/>
<Anchors>
<Anchor point="BOTTOMLEFT" relativeKey="$parent" x="27" y="1"/>
</Anchors>
<Layers>
<Layer level="ARTWORK">
<FontString parentKey="Label" inherits="GameFontHighlightSmall" justifyH="LEFT" wordwrap="true">
<Anchors>
<Anchor point="TOP"/>
<Anchor point="BOTTOM"/>
<Anchor point="LEFT" x="4" y="0"/>
<Anchor point="RIGHT" x="-26" y="0"/>
</Anchors>
<Color r="1.0" g="1.0" b="1.0"/>
<FontHeight val="11"/>
</FontString>
<FontString parentKey="Countdown" inherits="GameFontNormal">
<Anchors>
<Anchor point="TOP"/>
<Anchor point="BOTTOM"/>
<Anchor point="RIGHT" x="-4" y="0"/>
</Anchors>
<Color r="1.0" g="0.82" b="0"/>
<FontHeight val="13"/>
</FontString>
</Layer>
</Layers>
<BarTexture file="Interface\TargetingFrame\UI-StatusBar"/>
<BarColor r="1.0" g="0" b="0"/>
</StatusBar>
</Frames>
</Frame>

</Ui>

0 comments on commit 2663627

Please sign in to comment.