Skip to content

Commit

Permalink
adding new option + watching for only player events
Browse files Browse the repository at this point in the history
  • Loading branch information
rbgdevx committed Oct 11, 2024
1 parent c962fb1 commit 1030689
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 44 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"SlashCmdList",
"hash_SlashCmdList",
"FrameUtil",
"ButtonFrameTemplate_HidePortrait"
"ButtonFrameTemplate_HidePortrait",
"BASE_MOVEMENT_SPEED"
],
"Lua.runtime.version": "Lua 5.1",
"Lua.runtime.builtin": {
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Dynamic Movement Speed

## [v1.2.1](https://github.com/rbgdevx/dynamic-movement-speed/releases/tag/v1.2.1) (2024-10-10)

- Adding new option to show 0 instead of run speed while not moving
- making sure to only care about events related to you the player

## [v1.2.0](https://github.com/rbgdevx/dynamic-movement-speed/releases/tag/v1.2.0) (2024-09-08)

- Adding Dynamic Riding support
Expand Down
96 changes: 64 additions & 32 deletions DynamicMovementSpeed.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ local CreateFrame = CreateFrame
local IsPlayerMoving = IsPlayerMoving
local GetTime = GetTime
local IsFlying = IsFlying
local UnitIsUnit = UnitIsUnit

local mmin = math.min
local mmax = math.max
Expand All @@ -19,6 +20,7 @@ local GetPlayerAuraBySpellID = C_UnitAuras.GetPlayerAuraBySpellID
local DMS = NS.DMS
local DMSFrame = NS.DMS.frame

local isFlying = false
local isDragonRiding = false
local ascentSpell = 372610
local lastUpdatedSpeed = 0
Expand Down Expand Up @@ -62,6 +64,7 @@ do

function DMS:GetDynamicSpeed()
local time = GetTime()
isFlying = IsFlying()

-- Delta time
local dt = time - lastT
Expand Down Expand Up @@ -92,28 +95,21 @@ do
-- Don't track negative acceleration when boosting
smoothAccel = mmax(0, smoothAccel)
end
if not IsFlying() then
if not isFlying then
smoothAccel = 0 -- Don't track acceleration on ground
end
-- lastAccel = smoothAccel
if NS.db.global.debug then
print("smoothAccel", smoothAccel)
end
NS.Debug("smoothAccel", smoothAccel)

-- Update display variables
isBoosting = boosting
isThrill = not not thrill
if NS.db.global.debug then
print("isBoosting", isBoosting)
print("isThrill", isThrill)
end
NS.Debug("isBoosting", isBoosting)
NS.Debug("isThrill", isThrill)

dynamicSpeed = smoothSpeed * speedTextFactor
speedtext = smoothSpeed < 1 and "" or sformat(speedTextFormat, dynamicSpeed)
if NS.db.global.debug then
print("dynamicSpeed", dynamicSpeed)
print("speedtext", speedtext)
end
NS.Debug("speedtext", speedtext)
end
end

Expand All @@ -128,16 +124,17 @@ do

local function PlayerMoveUpdate()
local moving = IsPlayerMoving()
isDragonRiding = NS.IsDragonriding()
isFlying = IsFlying()

if playerMovingFrame and (playerMovingFrame.moving ~= moving or playerMovingFrame.moving == nil) then
playerMovingFrame.moving = moving
end

local currentSpeed, runSpeed = NS.GetSpeedInfo()

local correctSpeed = currentSpeed

if moving and IsFlying() and isDragonRiding then
if moving and isFlying and isDragonRiding then
DMS:GetDynamicSpeed()
correctSpeed = dynamicSpeed
end
Expand All @@ -147,38 +144,40 @@ do

local speedPercent = playerMovingFrame.speed

if NS.db.global.debug then
print("moving", moving, "flying", IsFlying(), "isDragonRiding", isDragonRiding)
end

if playerMovingFrame.moving or correctSpeed > 0 then
local showSpeed = correctSpeed
if not IsFlying() then
if not isFlying then
showSpeed = currentSpeed == 0 and runSpeed or currentSpeed
end

speedPercent = showSpeed
else
speedPercent = runSpeed
local showSpeed = NS.db.global.showzero and 0 or runSpeed
speedPercent = showSpeed
end

Interface.speed = speedPercent
NS.UpdateText(Interface.text, speedPercent, isDragonRiding and IsFlying())
NS.Interface.speed = speedPercent
NS.UpdateText(Interface.text, speedPercent, isDragonRiding and isFlying)
end
end

function DMS:WatchForPlayerMoving()
isDragonRiding = NS.IsDragonriding()
isFlying = IsFlying()

local currentSpeed, runSpeed = NS.GetSpeedInfo()
NS.UpdateText(Interface.text, runSpeed)
local showSpeed = currentSpeed == 0 and (NS.db.global.showzero and 0 or runSpeed) or currentSpeed
NS.UpdateText(Interface.text, showSpeed, isDragonRiding and isFlying)

if not playerMovingFrame then
playerMovingFrame = CreateFrame("Frame")
--- @cast playerMovingFrame PlayerMovingFrame
playerMovingFrame.speed = currentSpeed

local runSpeedPercent = runSpeed
Interface.speed = runSpeedPercent
NS.UpdateText(Interface.text, runSpeedPercent)
showSpeed = currentSpeed == 0 and (NS.db.global.showzero and 0 or runSpeedPercent) or currentSpeed
NS.Interface.speed = showSpeed
NS.UpdateText(Interface.text, showSpeed, isDragonRiding and isFlying)
end

playerMovingFrame:SetScript("OnUpdate", PlayerMoveUpdate)
Expand All @@ -187,7 +186,33 @@ end

function DMS:PLAYER_ENTERING_WORLD()
isDragonRiding = NS.IsDragonriding()
isFlying = IsFlying()

self:WatchForPlayerMoving()

if NS.db and NS.db.global.debug then
local f = CreateFrame("Frame", nil, UIParent, "BackdropTemplate")
f:SetPoint("CENTER", 0, 50)
f:SetSize(132, 50)
f:SetBackdrop({
bgFile = "Interface/Tooltips/UI-Tooltip-Background",
edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
edgeSize = 16,
insets = { left = 4, right = 4, top = 4, bottom = 4 },
})
f:SetBackdropColor(0, 0, 0, 0.5)
f.glide = f:CreateFontString(nil, nil, "GameTooltipText")
f.glide:SetPoint("TOPLEFT", 10, -12)
f.movespeed = f:CreateFontString(nil, nil, "GameTooltipText")
f.movespeed:SetPoint("TOPLEFT", f.glide, "BOTTOMLEFT")
C_Timer.NewTicker(0.1, function()
local isGliding, canGlide, forwardSpeed = C_PlayerInfo.GetGlidingInfo()
local base = isGliding and forwardSpeed or GetUnitSpeed("player")
local movespeed = Round(base / BASE_MOVEMENT_SPEED * 100)
f.glide:SetText(format("Gliding speed: |cff71d5ff%d%%|r", forwardSpeed))
f.movespeed:SetText(format("Move speed: |cffffff00%d%%|r", movespeed))
end)
end
end

local function checkSpeed()
Expand All @@ -196,6 +221,7 @@ local function checkSpeed()
After(0.1, checkSpeed)
else
isDragonRiding = NS.IsDragonriding()
isFlying = IsFlying()
DMS:WatchForPlayerMoving()
end
end
Expand All @@ -206,18 +232,24 @@ function DMS:PLAYER_MOUNT_DISPLAY_CHANGED()
After(0, checkSpeed)
end

function DMS:UNIT_POWER_BAR_SHOW()
isDragonRiding = NS.IsDragonriding()
self:WatchForPlayerMoving()
function DMS:UNIT_POWER_BAR_SHOW(unitTarget)
if UnitIsUnit(unitTarget, "player") then
isDragonRiding = NS.IsDragonriding()
isFlying = IsFlying()
self:WatchForPlayerMoving()
end
end

function DMS:UNIT_POWER_BAR_HIDE()
isDragonRiding = NS.IsDragonriding()
self:WatchForPlayerMoving()
function DMS:UNIT_POWER_BAR_HIDE(unitTarget)
if UnitIsUnit(unitTarget, "player") then
isDragonRiding = NS.IsDragonriding()
isFlying = IsFlying()
self:WatchForPlayerMoving()
end
end

function DMS:UNIT_SPELLCAST_SUCCEEDED(unitTarget, _, spellID)
if unitTarget == "player" and spellID == ascentSpell then
if UnitIsUnit(unitTarget, "player") and spellID == ascentSpell then
ascentStart = GetTime()
end
end
Expand Down
2 changes: 1 addition & 1 deletion DynamicMovementSpeed.toc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Interface: 110002
## Title: DynamicMovementSpeed
## Version: 1.2.0
## Version: 1.2.1
## Author: RBGDEV
## Notes: Provides real time movement speed
## OptionalDeps: Ace3, LibStub, LibSharedMedia-3.0, AceGUI-3.0-SharedMediaWidgets
Expand Down
2 changes: 2 additions & 0 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ local CreateFrame = CreateFrame
---@field lock boolean
---@field labeltext string
---@field showlabel boolean
---@field showzero boolean
---@field font string
---@field round boolean
---@field color ColorArray
Expand Down Expand Up @@ -59,6 +60,7 @@ NS.DefaultDatabase = {
lock = false,
labeltext = "Speed:",
showlabel = true,
showzero = false,
fontsize = 15,
font = "Friz Quadrata TT",
round = true,
Expand Down
6 changes: 6 additions & 0 deletions helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ local sformat = string.format

local LSM = LibStub("LibSharedMedia-3.0")

NS.Debug = function(...)
if NS.db and NS.db.global.debug then
print(...)
end
end

NS.round = function(x)
local decimal = x - math.floor(x)
if decimal < 0.5 then
Expand Down
8 changes: 5 additions & 3 deletions interface.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local AddonName, NS = ...

local CreateFrame = CreateFrame
local LibStub = LibStub
local IsFlying = IsFlying

local Interface = {}
NS.Interface = Interface
Expand Down Expand Up @@ -75,11 +76,12 @@ function Interface:CreateInterface()
Text:SetJustifyV("MIDDLE")
Text:SetPoint("CENTER", TextFrame, "CENTER", 0, 0)

local _, runSpeed = NS.GetSpeedInfo()
local currentSpeed, runSpeed = NS.GetSpeedInfo()
NS.UpdateFont(Text)
NS.UpdateText(Text, runSpeed)
local showSpeed = currentSpeed == 0 and (NS.db.global.showzero and 0 or runSpeed) or currentSpeed
NS.UpdateText(Text, showSpeed, NS.IsDragonriding() and IsFlying())

Interface.speed = runSpeed
Interface.speed = showSpeed
Interface.text = Text
Interface.textFrame = TextFrame

Expand Down
31 changes: 24 additions & 7 deletions options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local AddonName, NS = ...
local LibStub = LibStub
local CopyTable = CopyTable
local next = next
local IsFlying = IsFlying

---@type DMS
local DMS = NS.DMS
Expand Down Expand Up @@ -39,7 +40,7 @@ NS.AceConfig = {
order = 2,
set = function(_, val)
NS.db.global.round = val
NS.UpdateText(NS.Interface.text, NS.Interface.speed)
NS.UpdateText(NS.Interface.text, NS.Interface.speed, NS.IsDragonriding() and IsFlying())
end,
get = function(_)
return NS.db.global.round
Expand All @@ -52,20 +53,36 @@ NS.AceConfig = {
order = 3,
set = function(_, val)
NS.db.global.showlabel = val
NS.UpdateText(NS.Interface.text, NS.Interface.speed)
NS.UpdateText(NS.Interface.text, NS.Interface.speed, NS.IsDragonriding() and IsFlying())
end,
get = function(_)
return NS.db.global.showlabel
end,
},
showzero = {
name = "Show 0% when NOT moving, instead of run speed",
type = "toggle",
width = "double",
order = 4,
set = function(_, val)
NS.db.global.showzero = val
local currentSpeed, runSpeed = NS.GetSpeedInfo()
local staticSpeed = NS.db.global.showzero and 0 or runSpeed
local showSpeed = (currentSpeed == 0 or NS.Interface.speed == 0) and staticSpeed or NS.Interface.speed
NS.UpdateText(NS.Interface.text, showSpeed, NS.IsDragonriding() and IsFlying())
end,
get = function(_)
return NS.db.global.showzero
end,
},
labeltext = {
type = "input",
name = "Label Text",
width = "double",
order = 4,
order = 5,
set = function(_, val)
NS.db.global.labeltext = val
NS.UpdateText(NS.Interface.text, NS.Interface.speed)
NS.UpdateText(NS.Interface.text, NS.Interface.speed, NS.IsDragonriding() and IsFlying())
NS.Interface.textFrame:SetWidth(NS.Interface.text:GetStringWidth())
NS.Interface.textFrame:SetHeight(NS.Interface.text:GetStringHeight())
end,
Expand All @@ -77,7 +94,7 @@ NS.AceConfig = {
type = "range",
name = "Font Size",
width = "double",
order = 5,
order = 6,
min = 1,
max = 500,
step = 1,
Expand All @@ -97,7 +114,7 @@ NS.AceConfig = {
width = "double",
dialogControl = "LSM30_Font",
values = AceGUIWidgetLSMlists.font,
order = 6,
order = 7,
set = function(_, val)
NS.db.global.font = val
NS.UpdateFont(NS.Interface.text)
Expand All @@ -112,7 +129,7 @@ NS.AceConfig = {
type = "color",
name = "Color",
width = "double",
order = 7,
order = 8,
hasAlpha = true,
set = function(_, val1, val2, val3, val4)
NS.db.global.color.r = val1
Expand Down

0 comments on commit 1030689

Please sign in to comment.