summaryrefslogtreecommitdiff
path: root/api.lua
diff options
context:
space:
mode:
authorrubenwardy <rubenwardy@gmail.com>2016-08-01 20:27:12 +0100
committerrubenwardy <rubenwardy@gmail.com>2016-08-01 20:27:12 +0100
commitb689dc8eaf799fe8f45724ace8bfa943436bc412 (patch)
tree90c606b5514e8915456a9bd9d2125ee629b692c4 /api.lua
parentf5cf49af2ee073b470b7b28e72d95cffd8c4defd (diff)
Add progress bar
Diffstat (limited to 'api.lua')
-rw-r--r--api.lua33
1 files changed, 33 insertions, 0 deletions
diff --git a/api.lua b/api.lua
index 7a4de0a..1fd8a29 100644
--- a/api.lua
+++ b/api.lua
@@ -98,6 +98,23 @@ function awards.increment_item_counter(data, field, itemname, count)
end
end
+function awards.get_item_count(data, field, itemname)
+ local name_split = string.split(itemname, ":")
+ if #name_split ~= 2 then
+ return false
+ end
+ local mod = name_split[1]
+ local item = name_split[2]
+
+ if data and field and mod and item then
+ awards.assertPlayer(data)
+ awards.tbv(data, field)
+ awards.tbv(data[field], mod)
+ awards.tbv(data[field][mod], item, 0)
+ return data[field][mod][item]
+ end
+end
+
function awards.register_on_unlock(func)
table.insert(awards.on_unlock, func)
end
@@ -284,6 +301,7 @@ awards.give_achievement = awards.unlock
function awards.getFormspec(name, to, sid)
local formspec = "size[11,5]"
local listofawards = awards._order_awards(name)
+ local playerdata = awards.players[name]
-- Sidebar
if sid then
@@ -308,6 +326,21 @@ function awards.getFormspec(name, to, sid)
if def and def.icon then
formspec = formspec .. "image[1,0;3,3;" .. def.icon .. "]"
end
+ local barwidth = 4.6
+ local perc = nil
+ local label = nil
+ if def.getProgress and playerdata then
+ local res = def:getProgress(playerdata)
+ perc = res.perc
+ label = res.label
+ end
+ if perc then
+ formspec = formspec .. "background[0,4.80;" .. barwidth ..",0.25;awards_progress_gray.png]"
+ formspec = formspec .. "background[0,4.80;" .. (barwidth * perc) ..",0.25;awards_progress_green.png]"
+ if label then
+ formspec = formspec .. "label[1.75,4.63;" .. label .. "]"
+ end
+ end
if def and def.description then
formspec = formspec .. "label[0,3.25;"..def.description.."]"
end