Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions addons/giltracker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@ This addon displays the current gil, similar to the FFXIV Gil HUD widget.

![Imgur](https://i.imgur.com/vZ8NkDr.png)

## Settings

- `thousandsSeparator`: Separator used when displaying gil. Defaults to `,`.
Named values are `comma`, `period`, `space`, and `none`. Literal and custom
separators such as `.`, `,`, or `○` are also supported. Custom values must
be valid XML text.
- `refreshInterval`: Seconds between periodic gil updates. Defaults to `5`.
Values below `1` are treated as `1`.

Custom separators must be valid XML text. XML-reserved characters must be
escaped, such as `&amp;` for `&` and `&lt;` for `<`.

## How to edit the settings
1. Login to your character in FFXI
2. Edit the addon settings file: **_Windower4\addons\giltracker\data\settings.xml_**
Expand Down
50 changes: 45 additions & 5 deletions addons/giltracker/giltracker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

_addon.name = 'giltracker'
_addon.author = 'sylandro'
_addon.version = '1.0.0'
_addon.version = '1.1.0'
_addon.language = 'English'

config = require('config')
Expand All @@ -45,12 +45,22 @@ local LOGIN_ZONE_PACKET = 0x0A
local ITEM_UPDATE_PACKET = 0x20
local ITEM_MODIFY_PACKET = 0x1F

local separator_map = {
none = '',
space = ' ',
period = '.',
comma = ',',
[''] = ',',
}

local hideKey = SCROLL_LOCK_KEY
local is_hidden_by_cutscene = false
local is_hidden_by_key = false

defaults = {}
defaults.hideKey = SCROLL_LOCK_KEY
defaults.thousandsSeparator = ','
defaults.refreshInterval = 5
defaults.gilText = {}
defaults.gilText.bg = {}
defaults.gilText.bg.alpha = 100
Expand Down Expand Up @@ -92,6 +102,16 @@ defaults.gilImage.visible = true
local settings = config.load(defaults)
config.save(settings)

function get_separator()
local separator = separator_map[settings.thousandsSeparator] or settings.thousandsSeparator

if type(separator) ~= 'string' then
return defaults.thousandsSeparator
end

return separator
end

settings.gilImage.texture = {}
settings.gilImage.texture.path = windower.addon_path..'gil.png'
settings.gilImage.texture.fit = true
Expand All @@ -108,6 +128,15 @@ local gil_text = texts.new(settings.gilText)
local inventory_loaded = false
local ready = false

local function refresh_gil_loop()
while true do
coroutine.sleep(math.max(tonumber(settings.refreshInterval) or defaults.refreshInterval, 1))
Comment thread
FFNeko marked this conversation as resolved.
if inventory_loaded then
update_gil()
end
end
end

config.register(settings, function(settings)
hideKey = settings.hideKey
local windower_settings = windower.get_windower_settings()
Expand All @@ -121,6 +150,7 @@ windower.register_event('load',function()
if windower.ffxi.get_info().logged_in then
initialize()
end
coroutine.schedule(refresh_gil_loop, 0)
end)

windower.register_event('login',function()
Expand Down Expand Up @@ -192,7 +222,7 @@ end

function update_gil()
local gil = windower.ffxi.get_items('gil')
gil_text:text(comma_value(gil))
gil_text:text(format_value(gil))
end

function show()
Expand All @@ -205,12 +235,22 @@ function hide()
gil_image:hide()
end

function comma_value(amount)
function format_value(amount)
local formatted = tostring(amount)
local separator = get_separator()
local k

if separator == '' then
return formatted
end

local replacement = '%1'..separator:gsub('%%', '%%%%')..'%2'

while true do
formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
if (k==0) then break end
formatted, k = string.gsub(formatted, '^(%d+)(%d%d%d)', replacement)
if k == 0 then break end
end

return formatted
end

Expand Down