Skip to content

Commit

Permalink
adding new options and fixing current options
Browse files Browse the repository at this point in the history
  • Loading branch information
rbgdevx committed Jan 1, 2024
1 parent da97b7b commit 38f9942
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 35 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Dynamic Movement Speed

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

- adding default font
- addressing an issue where you cant set the label correctly
- adding a new option to round the percent value

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

- Refactor to fully use Ace 3.0 libs since the db and options kept resetting and couldn't figure it out
Expand Down
19 changes: 9 additions & 10 deletions DynamicMovementSpeed.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,19 @@ do
playerMovingFrame.moving = moving
end

local speed = NS.GetSpeedInfo()
if playerMovingFrame and playerMovingFrame.speed ~= speed then
playerMovingFrame.speed = speed
end
local currentSpeed, runSpeed = NS.GetSpeedInfo()
if playerMovingFrame and playerMovingFrame.speed ~= currentSpeed then
playerMovingFrame.speed = currentSpeed

if playerMovingFrame then
local currentSpeed, runSpeed = NS.GetSpeedInfo()
local speedPercent = ""
local speedPercent = playerMovingFrame.speed

if playerMovingFrame.moving or currentSpeed > 0 then
speedPercent = NS.formatSpeed(currentSpeed)
speedPercent = currentSpeed
else
speedPercent = NS.formatSpeed(runSpeed)
speedPercent = runSpeed
end

Interface.speed = speedPercent
NS.UpdateText(Interface.text, speedPercent)
end
end
Expand All @@ -50,7 +48,8 @@ do
--- @cast playerMovingFrame PlayerMovingFrame
playerMovingFrame.speed = currentSpeed

local runSpeedPercent = NS.formatSpeed(runSpeed)
local runSpeedPercent = runSpeed
Interface.speed = runSpeedPercent
NS.UpdateText(Interface.text, runSpeedPercent)
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: 100200
## Title: DynamicMovementSpeed
## Version: 1.1.2
## Version: 1.1.3
## Author: Ajax
## Notes: Provides real time movement speed
## X-Flavor: Mainline
Expand Down
2 changes: 2 additions & 0 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ NS.DefaultDatabase = {
["labeltext"] = "Speed:",
["showlabel"] = true,
["fontsize"] = 15,
["font"] = "Friz Quadrata TT",
["round"] = true,
["color"] = {
["r"] = 1,
["g"] = 1,
Expand Down
22 changes: 19 additions & 3 deletions helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,27 @@ local sformat = string.format

local LSM = LibStub("LibSharedMedia-3.0")

NS.round = function(x)
local decimal = x - math.floor(x)
if decimal < 0.5 then
return math.floor(x)
else
return math.ceil(x)
end
end

NS.getPercent = function(speed)
return speed / 7 * 100
end

NS.formatSpeed = function(speed)
return sformat("%.2f%%", NS.getPercent(speed))
NS.formatSpeed = function(speed, round)
if round then
local percent = NS.getPercent(speed)
local rounded = NS.round(percent)
return sformat("%d%%", rounded)
else
return sformat("%.1f%%", NS.getPercent(speed))
end
end

NS.GetSpeedInfo = function()
Expand All @@ -29,7 +44,8 @@ NS.GetSpeedInfo = function()
return GetUnitSpeed("player")
end

NS.UpdateText = function(frame, txt)
NS.UpdateText = function(frame, speed)
local txt = NS.formatSpeed(speed, DMS.db.global.round)
if DMS.db.global.showlabel then
if DMS.db.global.labeltext then
local speedWithLabel = sformat("%s %s", DMS.db.global.labeltext, txt)
Expand Down
1 change: 1 addition & 0 deletions interface.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ function Interface:CreateInterface()
NS.UpdateFont(Text)
NS.UpdateText(Text, runSpeed)

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

Expand Down
56 changes: 35 additions & 21 deletions options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,27 @@ NS.AceConfig = {
name = AddonName,
type = "group",
args = {
round = {
name = "Round the percentage value",
type = "toggle",
width = "double",
order = 1,
set = function(_, val)
DMS.db.global.round = val
NS.UpdateText(NS.Interface.text, NS.Interface.speed)
end,
get = function(_)
return DMS.db.global.round
end,
},
showlabel = {
name = "Toggle label on/off",
type = "toggle",
width = "double",
order = 1,
order = 2,
set = function(_, val)
DMS.db.global.showlabel = val
NS.UpdateText(NS.Interface.text, NS.Interface.speed)
end,
get = function(_)
return DMS.db.global.showlabel
Expand All @@ -24,10 +38,10 @@ NS.AceConfig = {
type = "input",
name = "Label Text",
width = "double",
order = 2,
order = 3,
set = function(_, val)
DMS.db.global.labeltext = val
NS.UpdateText(NS.Interface.text, val)
NS.UpdateText(NS.Interface.text, NS.Interface.speed)
NS.Interface.textFrame:SetWidth(NS.Interface.text:GetStringWidth())
NS.Interface.textFrame:SetHeight(NS.Interface.text:GetStringHeight())
end,
Expand All @@ -39,7 +53,7 @@ NS.AceConfig = {
type = "range",
name = "Font Size",
width = "double",
order = 3,
order = 4,
min = 1,
max = 500,
step = 1,
Expand All @@ -53,23 +67,6 @@ NS.AceConfig = {
return DMS.db.global.fontsize
end,
},
color = {
type = "color",
name = "Color",
width = "double",
order = 4,
hasAlpha = true,
set = function(_, val1, val2, val3, val4)
DMS.db.global.color.r = val1
DMS.db.global.color.g = val2
DMS.db.global.color.b = val3
DMS.db.global.color.a = val4
NS.Interface.text:SetTextColor(val1, val2, val3, val4)
end,
get = function(_)
return DMS.db.global.color.r, DMS.db.global.color.g, DMS.db.global.color.b, DMS.db.global.color.a
end,
},
font = {
type = "select",
name = "Font",
Expand All @@ -87,6 +84,23 @@ NS.AceConfig = {
return DMS.db.global.font
end,
},
color = {
type = "color",
name = "Color",
width = "double",
order = 6,
hasAlpha = true,
set = function(_, val1, val2, val3, val4)
DMS.db.global.color.r = val1
DMS.db.global.color.g = val2
DMS.db.global.color.b = val3
DMS.db.global.color.a = val4
NS.Interface.text:SetTextColor(val1, val2, val3, val4)
end,
get = function(_)
return DMS.db.global.color.r, DMS.db.global.color.g, DMS.db.global.color.b, DMS.db.global.color.a
end,
},
},
}

Expand Down

0 comments on commit 38f9942

Please sign in to comment.