added quest list to the players hud
This commit is contained in:
parent
e4c25cb294
commit
9988f3f181
@ -121,44 +121,6 @@ function crafting_guide.get_item_formspec(page)
|
||||
y = y +1
|
||||
end
|
||||
end
|
||||
elseif page == -3 then
|
||||
local x = 0
|
||||
local y = 0
|
||||
str = str .. "label[0,0;Treasure Chest Loot :]"
|
||||
for i,name in ipairs(default.treasure_chest_items) do
|
||||
str = str .. "item_image_button[".. x ..",".. y+0.5 ..";1,1;"..name..";"..name..";]"
|
||||
x = x + 1
|
||||
if x > 7 then
|
||||
x = 0
|
||||
y = y +1
|
||||
end
|
||||
end
|
||||
|
||||
str = str .. "label[0,1.5;Abilities :]"
|
||||
x = 0
|
||||
y = 2
|
||||
for _,name in ipairs(skills.abilities.all) do
|
||||
str = str .. "item_image_button[".. x ..",".. y ..";1,1;"..name..";"..name..";]"
|
||||
x = x + 1
|
||||
if x > 7 then
|
||||
x = 0
|
||||
y = y +1
|
||||
end
|
||||
end
|
||||
|
||||
str = str .. "label[0,3;Blueprints :]"
|
||||
x = 0
|
||||
y = 3
|
||||
for _,name in ipairs(blueprint.all) do
|
||||
str = str .. "item_image_button[".. x ..",".. y+0.5 ..";1,1;"..name..";"..name..";]"
|
||||
x = x + 1
|
||||
if x > 7 then
|
||||
x = 0
|
||||
y = y +1
|
||||
end
|
||||
end
|
||||
elseif page == -4 then
|
||||
|
||||
end
|
||||
|
||||
return str
|
||||
|
@ -4,6 +4,7 @@ quests = {}
|
||||
quests.player_quests = {}
|
||||
quests.file = minetest.get_worldpath() .. "/quests"
|
||||
quests.callback = nil
|
||||
quests.hud = {}
|
||||
|
||||
function quests.load()
|
||||
local input = io.open(quests.file, "r")
|
||||
@ -48,6 +49,8 @@ function quests.add_quest(player, quest)
|
||||
print("[quests] add quest")
|
||||
table.insert(quests.player_quests[player], quest)
|
||||
quests.save()
|
||||
|
||||
quests.update_hud(minetest.get_player_by_name(player),player)
|
||||
|
||||
if #quest.goals > 0 then
|
||||
quests.show_text(quest.text .. "\n" .. quest.goals[1].description, player)
|
||||
@ -189,6 +192,7 @@ function quests.process_node_count_goals(player, type, node, count)
|
||||
quests.finish_goal(player, quest, goal)
|
||||
goal.done = true
|
||||
end
|
||||
quests.update_hud(minetest.get_player_by_name(player),player)
|
||||
quests.save()
|
||||
end
|
||||
end
|
||||
@ -211,6 +215,31 @@ function quests.format_goal(player, quest, goal)
|
||||
end
|
||||
end
|
||||
|
||||
function quests.update_hud(player,name)
|
||||
if quests.hud[name] == nil then return end
|
||||
|
||||
local player_quests = quests.player_quests[name]
|
||||
if not player_quests or #player_quests == 0 then
|
||||
player:hud_change(quests.hud[name], "text", "")
|
||||
return
|
||||
end
|
||||
|
||||
local txt = ""
|
||||
for _, quest in pairs(player_quests) do
|
||||
if not(quest.done) then
|
||||
txt = txt .. " -> " .. (quest.title or "[NO TITLE]") .. "\n"
|
||||
for _, goal in pairs(quest.goals) do
|
||||
if (not goal.requires or goal.requires.done) and not(goal.done) then
|
||||
txt = txt .. " [ ] " .. (goal.title or "[NO TITLE]") .. " (" .. tostring(goal.progress) ..
|
||||
"/" .. tostring(goal.max) .. ")\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
player:hud_change(quests.hud[name], "text", txt)
|
||||
end
|
||||
|
||||
function quests.get_formspec(name)
|
||||
local player_quests = quests.player_quests[name]
|
||||
if not player_quests or #player_quests == 0 then
|
||||
@ -274,6 +303,27 @@ minetest.register_on_craft(function(itemstack, player, old_craft_grid, craft_inv
|
||||
quests.process_node_count_goals(player:get_player_name(), "craft", itemstack:get_name(),itemstack:get_count())
|
||||
end)
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
if not player then
|
||||
return
|
||||
end
|
||||
local name = player:get_player_name()
|
||||
|
||||
quests.hud[name] = player:hud_add({
|
||||
hud_elem_type = "text",
|
||||
name = "quests",
|
||||
text = "",
|
||||
position = {x = 1, y = 0},
|
||||
alignment = {x = -1, y = 1},
|
||||
offset = {x=-10,y=10},
|
||||
number = "0xFFFFFF",
|
||||
})
|
||||
|
||||
minetest.after(1, function(player,name)
|
||||
quests.update_hud(player,name)
|
||||
end, player, name)
|
||||
end)
|
||||
|
||||
minetest.register_on_newplayer(function(player)
|
||||
if not player then
|
||||
return
|
||||
|
Loading…
x
Reference in New Issue
Block a user