forked from mtcontrib/awards
Add progress bar
This commit is contained in:
parent
f5cf49af2e
commit
b689dc8eaf
33
api.lua
33
api.lua
@ -98,6 +98,23 @@ function awards.increment_item_counter(data, field, itemname, count)
|
|||||||
end
|
end
|
||||||
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)
|
function awards.register_on_unlock(func)
|
||||||
table.insert(awards.on_unlock, func)
|
table.insert(awards.on_unlock, func)
|
||||||
end
|
end
|
||||||
@ -284,6 +301,7 @@ awards.give_achievement = awards.unlock
|
|||||||
function awards.getFormspec(name, to, sid)
|
function awards.getFormspec(name, to, sid)
|
||||||
local formspec = "size[11,5]"
|
local formspec = "size[11,5]"
|
||||||
local listofawards = awards._order_awards(name)
|
local listofawards = awards._order_awards(name)
|
||||||
|
local playerdata = awards.players[name]
|
||||||
|
|
||||||
-- Sidebar
|
-- Sidebar
|
||||||
if sid then
|
if sid then
|
||||||
@ -308,6 +326,21 @@ function awards.getFormspec(name, to, sid)
|
|||||||
if def and def.icon then
|
if def and def.icon then
|
||||||
formspec = formspec .. "image[1,0;3,3;" .. def.icon .. "]"
|
formspec = formspec .. "image[1,0;3,3;" .. def.icon .. "]"
|
||||||
end
|
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
|
if def and def.description then
|
||||||
formspec = formspec .. "label[0,3.25;"..def.description.."]"
|
formspec = formspec .. "label[0,3.25;"..def.description.."]"
|
||||||
end
|
end
|
||||||
|
BIN
textures/awards_progress_gray.png
Normal file
BIN
textures/awards_progress_gray.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 146 B |
BIN
textures/awards_progress_green.png
Normal file
BIN
textures/awards_progress_green.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 177 B |
43
triggers.lua
43
triggers.lua
@ -21,6 +21,13 @@ awards.register_trigger("dig", function(def)
|
|||||||
target = def.trigger.target
|
target = def.trigger.target
|
||||||
}
|
}
|
||||||
table.insert(awards.on.dig, tmp)
|
table.insert(awards.on.dig, tmp)
|
||||||
|
def.getProgress = function(self, data)
|
||||||
|
local itemcount = awards.get_item_count(data, "count", tmp.node) or 0
|
||||||
|
return {
|
||||||
|
perc = itemcount / tmp.target,
|
||||||
|
label = itemcount .. " / " .. tmp.target .. " dug" -- TODO: translation
|
||||||
|
}
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
awards.register_trigger("place", function(def)
|
awards.register_trigger("place", function(def)
|
||||||
@ -30,6 +37,13 @@ awards.register_trigger("place", function(def)
|
|||||||
target = def.trigger.target
|
target = def.trigger.target
|
||||||
}
|
}
|
||||||
table.insert(awards.on.place, tmp)
|
table.insert(awards.on.place, tmp)
|
||||||
|
def.getProgress = function(self, data)
|
||||||
|
local itemcount = awards.get_item_count(data, "place", tmp.node) or 0
|
||||||
|
return {
|
||||||
|
perc = itemcount / tmp.target,
|
||||||
|
label = itemcount .. " / " .. tmp.target .. " placed" -- TODO: translation
|
||||||
|
}
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
awards.register_trigger("death", function(def)
|
awards.register_trigger("death", function(def)
|
||||||
@ -38,6 +52,13 @@ awards.register_trigger("death", function(def)
|
|||||||
target = def.trigger.target
|
target = def.trigger.target
|
||||||
}
|
}
|
||||||
table.insert(awards.on.death, tmp)
|
table.insert(awards.on.death, tmp)
|
||||||
|
def.getProgress = function(self, data)
|
||||||
|
local itemcount = data.deaths or 0
|
||||||
|
return {
|
||||||
|
perc = itemcount / tmp.target,
|
||||||
|
label = itemcount .. " deaths, need " .. tmp.target -- TODO: translation
|
||||||
|
}
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
awards.register_trigger("chat", function(def)
|
awards.register_trigger("chat", function(def)
|
||||||
@ -46,6 +67,13 @@ awards.register_trigger("chat", function(def)
|
|||||||
target = def.trigger.target
|
target = def.trigger.target
|
||||||
}
|
}
|
||||||
table.insert(awards.on.chat, tmp)
|
table.insert(awards.on.chat, tmp)
|
||||||
|
def.getProgress = function(self, data)
|
||||||
|
local itemcount = data.chats or 0
|
||||||
|
return {
|
||||||
|
perc = itemcount / tmp.target,
|
||||||
|
label = itemcount .. " / " .. tmp.target .. " line of chat" -- TODO: translation
|
||||||
|
}
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
awards.register_trigger("join", function(def)
|
awards.register_trigger("join", function(def)
|
||||||
@ -54,6 +82,14 @@ awards.register_trigger("join", function(def)
|
|||||||
target = def.trigger.target
|
target = def.trigger.target
|
||||||
}
|
}
|
||||||
table.insert(awards.on.join, tmp)
|
table.insert(awards.on.join, tmp)
|
||||||
|
|
||||||
|
def.getProgress = function(self, data)
|
||||||
|
local itemcount = data.joins or 0
|
||||||
|
return {
|
||||||
|
perc = itemcount / tmp.target,
|
||||||
|
label = itemcount .. " game joins, need " .. tmp.target -- TODO: translation
|
||||||
|
}
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
awards.register_trigger("craft", function(def)
|
awards.register_trigger("craft", function(def)
|
||||||
@ -63,6 +99,13 @@ awards.register_trigger("craft", function(def)
|
|||||||
target = def.trigger.target
|
target = def.trigger.target
|
||||||
}
|
}
|
||||||
table.insert(awards.on.craft, tmp)
|
table.insert(awards.on.craft, tmp)
|
||||||
|
def.getProgress = function(self, data)
|
||||||
|
local itemcount = awards.get_item_count(data, "craft", tmp.item) or 0
|
||||||
|
return {
|
||||||
|
perc = itemcount / tmp.target,
|
||||||
|
label = itemcount .. " / " .. tmp.target .. " crafted" -- TODO: translation
|
||||||
|
}
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Backwards compatibility
|
-- Backwards compatibility
|
||||||
|
Loading…
Reference in New Issue
Block a user