improved formspec regarding your data
This commit is contained in:
parent
fe873ddb64
commit
d8fc8eaa68
@ -177,6 +177,9 @@ reward_inv.get_reward_fs = function(player, reward_id)
|
||||
reward_data = {}
|
||||
end
|
||||
|
||||
-- for showing the player when and how much he/she took
|
||||
local access_data = reward_inv.get_access_data(pname, reward_id) or {0, 0, {}, 0}
|
||||
|
||||
-- create the formspec
|
||||
local formspec = {"size[12,11]"}
|
||||
|
||||
@ -231,37 +234,57 @@ reward_inv.get_reward_fs = function(player, reward_id)
|
||||
table.insert(formspec, "container_end[]")
|
||||
|
||||
-- show some simple access data to all
|
||||
local first_found = "- never -"
|
||||
local last_found = "- never -"
|
||||
local last_taken = "- never -"
|
||||
if(reward_data.first_found and reward_data.first_found > 0) then
|
||||
first_found = os.date("%m/%d/%y %H:%M", reward_data.first_found)
|
||||
end
|
||||
if(reward_data.last_found and reward_data.last_found > 0) then
|
||||
last_found = os.date("%m/%d/%y %H:%M", reward_data.last_found)
|
||||
end
|
||||
if(reward_data.last_found and reward_data.last_found > 0) then
|
||||
last_taken = os.date("%m/%d/%y %H:%M", reward_data.last_taken)
|
||||
end
|
||||
table.insert(formspec, "container[8.3,2]")
|
||||
table.insert(formspec, "box[-0.3,0.3;3.9,3.9;#000000]")
|
||||
table.insert(formspec, "container[8.2,2]")
|
||||
table.insert(formspec, "box[-0.2,0.3;3.9,2.9;#000000]")
|
||||
table.insert(formspec, "label[1,0.5;Statistic:]")
|
||||
table.insert(formspec, "label[0,1.0;Found by:]")
|
||||
table.insert(formspec, "label[2,1.0;")
|
||||
table.insert(formspec, "label[0,2.5;Found by:]")
|
||||
table.insert(formspec, "label[2,2.5;")
|
||||
table.insert(formspec, tostring(reward_data.anz_found or 0))
|
||||
table.insert(formspec, " people]")
|
||||
table.insert(formspec, "label[0,1.5;First found:]")
|
||||
table.insert(formspec, "label[1.5,1.5;")
|
||||
table.insert(formspec, minetest.formspec_escape(first_found))
|
||||
table.insert(formspec, "]")
|
||||
table.insert(formspec, "label[0,2.0;Last found:]")
|
||||
table.insert(formspec, "label[1.5,2.0;")
|
||||
table.insert(formspec, minetest.formspec_escape(last_found))
|
||||
table.insert(formspec, "]")
|
||||
table.insert(formspec, "label[0,2.5;Last taken:]")
|
||||
table.insert(formspec, "label[1.5,2.5;")
|
||||
table.insert(formspec, minetest.formspec_escape(last_taken))
|
||||
table.insert(formspec, "label[0,1.0;First found:]")
|
||||
table.insert(formspec, "label[0,1.5;Last found:]")
|
||||
table.insert(formspec, "label[0,2.0;Last taken:]")
|
||||
-- player-specific information
|
||||
table.insert(formspec, "box[-0.2,4.9;3.9,2.1;#000000]")
|
||||
table.insert(formspec, "label[1,5.0;Your data:]")
|
||||
table.insert(formspec, "label[0,5.5;First found:]")
|
||||
table.insert(formspec, "label[0,6.0;Last taken:]")
|
||||
table.insert(formspec, "label[0,6.5;Items taken:]")
|
||||
local offset = 0.5
|
||||
local dates = {reward_data.first_found or 0,
|
||||
reward_data.last_found or 0,
|
||||
reward_data.last_taken or 0,
|
||||
access_data[1] or 0,
|
||||
access_data[4] or 0}
|
||||
for i, date in ipairs(dates) do
|
||||
local txt = "- never -"
|
||||
if(date and date > 0) then
|
||||
txt = os.date("%m/%d/%y %H:%M", date)
|
||||
end
|
||||
table.insert(formspec, "label[1.6,")
|
||||
table.insert(formspec, tostring(offset + (0.5 * i)))
|
||||
table.insert(formspec, ";")
|
||||
table.insert(formspec, minetest.formspec_escape(txt))
|
||||
table.insert(formspec, "]")
|
||||
-- for the "Your data:" part
|
||||
if(i==3) then
|
||||
offset = 3.5
|
||||
end
|
||||
end
|
||||
local anz_taken = 0
|
||||
for k, v in pairs(access_data[3] or {}) do
|
||||
anz_taken = anz_taken + v
|
||||
end
|
||||
table.insert(formspec, "label[2,6.5;")
|
||||
table.insert(formspec, tostring(anz_taken))
|
||||
table.insert(formspec, "]")
|
||||
|
||||
table.insert(formspec, "button_exit[-0.2,8.2;4.1,1;exit;Close]")
|
||||
if(edit_mode) then
|
||||
table.insert(formspec, "button_exit[-0.2,3.4;4.1,1;save;Save changes]")
|
||||
else
|
||||
table.insert(formspec, "button_exit[-0.2,3.4;4.1,1;start_edit;Edit]")
|
||||
end
|
||||
table.insert(formspec, "container_end[]")
|
||||
|
||||
-- add a short text in the space between the two inventories
|
||||
|
||||
Loading…
Reference in New Issue
Block a user