Skip to content

Commit

Permalink
release add groupmember distance
Browse files Browse the repository at this point in the history
  • Loading branch information
snwflake committed Jul 16, 2021
1 parent 4cd1d95 commit 41282b3
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.set_env.outputs.version }}
release_name: Release snwDistance-${{ steps.set_env.outputs.version }}
release_name: snwDistance-${{ steps.set_env.outputs.version }}
body: |
${{ steps.set_env.outputs.RELEASEBODY }}
draft: false
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### Version v0.1.2:
- Add raidmember tracking

### Version v0.1.1:
- Remove debug code (recurring theme)

Expand Down
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# snwDistance for 7.3.5 (tauri alpha ptr testing)


Allows setting a position from your char
Allows setting a position with your character and automatically calculate the distance to your current location.
Also allows calculating distances between yourself and a groupmember in open-world.

![](https://i.imgur.com/sz8rzdp.png)
<br />

## Planned:
![](https://i.imgur.com/yQYWVkg.png)

- Add ability to get the distance between yourself and a raid-/groupmember (limitation by blizzard)
<br />

**Tracking raid-/groupmember does not work in instances/battleground/arenas!**
92 changes: 60 additions & 32 deletions core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ local ldb = nil
local initialPos = {}

local next = next
local text = nil
local text, cbRaid = nil

local function getInitialPos()
if cbRaid then return end
initialPos.y, initialPos.x = UnitPosition('Player')
end

Expand All @@ -14,28 +15,46 @@ local function resetPos()
text:SetText('0')
end

local function debugAbort(...)
resetPos()
print('|cffff8359snwDistance' .. ':|r ', ...)
end

local function calcDistance()
local y1, x1 = initialPos.y, initialPos.x
local y1, x1
if cbRaid then
y1, x1 = UnitPosition('target')
if not y1 or not x1 then resetPos();return end
else
y1, x1 = initialPos.y, initialPos.x
end
local y2, x2 = UnitPosition('player')
text:SetText(string.format('%.3f', ((x2 - x1) ^ 2 + (y2 - y1) ^ 2) ^ 0.5))
end

local function isRaidTarget(f)
cbRaid = f:GetChecked()
if not cbRaid then
resetPos()
end
end

local frame = CreateFrame('frame', 'snwDistance', UIParent)

local timeElapsed = 0
frame:HookScript("OnUpdate", function(self, elapsed)
frame:HookScript('OnUpdate', function(self, elapsed)
timeElapsed = timeElapsed + elapsed
if timeElapsed > 0.5 then
timeElapsed = 0
if next(initialPos) ~= nil then
if next(initialPos) ~= nil or cbRaid then
calcDistance()
end
end
end)

frame:SetBackdrop({
bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background-Dark",
edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
bgFile = 'Interface\\DialogFrame\\UI-DialogBox-Background-Dark',
edgeFile = 'Interface\\DialogFrame\\UI-DialogBox-Border',
tile = true, tileSize = 16, edgeSize = 16,
insets = {left = 1, right = 1, top = 1, bottom = 1}
})
Expand All @@ -46,40 +65,49 @@ frame:SetSize(300, 150)
frame:SetPoint('CENTER', UIParent, 'CENTER')
frame:EnableMouse(true)
frame:SetMovable(true)
frame:RegisterForDrag("LeftButton")
frame:SetScript("OnDragStart", function(self) self:StartMoving() end)
frame:SetScript("OnDragStop", function(self) self:StopMovingOrSizing() end)
frame:SetFrameStrata("DIALOG")
frame:RegisterForDrag('LeftButton')
frame:SetScript('OnDragStart', function(self) self:StartMoving() end)
frame:SetScript('OnDragStop', function(self) self:StopMovingOrSizing() end)
frame:SetFrameStrata('DIALOG')

local tex = frame:CreateTexture(nil, 'DIALOG')
tex:SetAllPoints(frame)
tex:SetColorTexture(0, 0, 0, 0.5)

local pos1 = CreateFrame("button", nil, frame, "UIPanelButtonTemplate")
local pos1 = CreateFrame('button', nil, frame, 'UIPanelButtonTemplate')
pos1:SetHeight(24)
pos1:SetWidth(120)
pos1:SetPoint("BOTTOM", frame, "BOTTOMLEFT", 70, 40)
pos1:SetText("Set Pos")
pos1:SetScript("OnClick", getInitialPos)

local clear = CreateFrame("button", nil, frame, "UIPanelButtonTemplate")
pos1:SetPoint('BOTTOM', frame, 'BOTTOMLEFT', 70, 40)
pos1:SetText('Set Pos')
pos1:SetScript('OnClick', getInitialPos)

local cb = CreateFrame('CheckButton', nil, frame, 'UICheckButtonTemplate')
cb:SetHeight(24)
cb:SetWidth(24)
cb:SetPoint('BOTTOM', frame, 'BOTTOMLEFT', 145, 40)
cb.text:SetText(' Target Raidmember')
cb:SetScript('OnClick', isRaidTarget)

local clear = CreateFrame('button', nil, frame, 'UIPanelButtonTemplate')
clear:SetHeight(24)
clear:SetWidth(120)
clear:SetPoint("BOTTOM", frame, "BOTTOMLEFT", 70, 10)
clear:SetText("Clear")
clear:SetScript("OnClick", resetPos)
clear:SetPoint('BOTTOM', frame, 'BOTTOMLEFT', 70, 10)
clear:SetText('Clear')
clear:SetScript('OnClick', resetPos)

local close = CreateFrame("button", nil, frame, "UIPanelButtonTemplate")
local close = CreateFrame('button', nil, frame, 'UIPanelButtonTemplate')
close:SetHeight(24)
close:SetWidth(120)
close:SetPoint("BOTTOM", frame, "BOTTOMRIGHT", -70, 10)
close:SetText("Close")
close:SetScript("OnClick", function(self) self:GetParent():Hide() end)
close:SetPoint('BOTTOM', frame, 'BOTTOMRIGHT', -70, 10)
close:SetText('Close')
close:SetScript('OnClick', function(self) self:GetParent():Hide() end)

text = frame:CreateFontString(frame, "OVERLAY", "GameFontNormalWTF2Outline")
text:SetPoint("TOP", 0, -30)
text = frame:CreateFontString(frame, 'OVERLAY', 'GameFontNormalWTF2Outline')
text:SetPoint('TOP', 0, -30)
text:SetText('0')

frame:Hide()

local function toggleFrame()
if frame:IsShown() then
frame:Hide()
Expand All @@ -90,12 +118,12 @@ end

-- LDB ---------------------------------------------------------------------- --
do
local libLdb = LibStub("LibDataBroker-1.1")
local libLdb = LibStub('LibDataBroker-1.1')
if libLdb then
ldb = libLdb:NewDataObject("snwDistance", {
type = "launcher",
label = "snwDistance",
icon = "Interface\\AddOns\\snwDistance\\media\\icon",
ldb = libLdb:NewDataObject('snwDistance', {
type = 'launcher',
label = 'snwDistance',
icon = 'Interface\\AddOns\\snwDistance\\media\\icon',
})

function ldb.OnClick(self, button)
Expand All @@ -108,9 +136,9 @@ frame:SetScript('OnEvent', function(self, e, ...)
if e == 'ADDON_LOADED' then
local args = ...
if args ~= 'snwDistance' then return end
local icon = LibStub("LibDBIcon-1.0")
local icon = LibStub('LibDBIcon-1.0')
if icon and ldb then
icon:Register("snwDistance", ldb, {})
icon:Register('snwDistance', ldb, {})
end
end
end)
2 changes: 1 addition & 1 deletion snwDistance.toc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Title: snwDistance
## Author: snwflake
## Version: v0.1.1
## Version: v0.1.2

embeds.xml

Expand Down

0 comments on commit 41282b3

Please sign in to comment.