mirror of
https://github.com/TeTpaAka/quests.git
synced 2024-12-22 16:50:39 +01:00
Added progress bars for quests
This commit is contained in:
parent
f2ec86c86c
commit
63fb8d6404
98
init.lua
98
init.lua
@ -17,6 +17,10 @@ quests.hud = quests.hud or {}
|
|||||||
|
|
||||||
quests.formspec_lists = {}
|
quests.formspec_lists = {}
|
||||||
|
|
||||||
|
local hud_config = { position = {x = 1, y = 0.2},
|
||||||
|
offset = { x = -200, y = 0},
|
||||||
|
number = 0xAAAA00 }
|
||||||
|
|
||||||
-- call this function to enable the HUD for the player that shows his quests
|
-- call this function to enable the HUD for the player that shows his quests
|
||||||
-- the HUD can only show up to show_max quests
|
-- the HUD can only show up to show_max quests
|
||||||
function quests.show_hud(playername)
|
function quests.show_hud(playername)
|
||||||
@ -26,9 +30,9 @@ function quests.show_hud(playername)
|
|||||||
local hud = {
|
local hud = {
|
||||||
hud_elem_type = "text",
|
hud_elem_type = "text",
|
||||||
alignment = {x=1, y=1},
|
alignment = {x=1, y=1},
|
||||||
position = {x = 1, y = 0.3},
|
position = {x = hud_config.position.x, y = hud_config.position.y},
|
||||||
offset = {x = -150, y = 0},
|
offset = {x = hud_config.offset.x, y = hud_config.offset.y},
|
||||||
number = 0xCACA00,
|
number = hud_config.number,
|
||||||
text = "Open Quests:" }
|
text = "Open Quests:" }
|
||||||
|
|
||||||
|
|
||||||
@ -50,6 +54,12 @@ function quests.hide_hud(playername)
|
|||||||
end
|
end
|
||||||
for _,quest in pairs(quests.hud[playername]) do
|
for _,quest in pairs(quests.hud[playername]) do
|
||||||
player:hud_remove(quest.id)
|
player:hud_remove(quest.id)
|
||||||
|
if (quest.id_background ~= nil) then
|
||||||
|
player:hud_remove(quest.id_background)
|
||||||
|
end
|
||||||
|
if (quest.id_bar ~= nil) then
|
||||||
|
player:hud_remove(quest.id_bar)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
quests.hud[playername] = nil
|
quests.hud[playername] = nil
|
||||||
end
|
end
|
||||||
@ -62,7 +72,7 @@ end
|
|||||||
local function get_quest_hud_string(questname, quest)
|
local function get_quest_hud_string(questname, quest)
|
||||||
local quest_string = quests.registered_quests[questname].title
|
local quest_string = quests.registered_quests[questname].title
|
||||||
if (quests.registered_quests[questname].max ~= 1) then
|
if (quests.registered_quests[questname].max ~= 1) then
|
||||||
quest_string = quest_string .. "\n ("..round(quest.value, 2).."/"..quests.registered_quests[questname].max..")"
|
quest_string = quest_string .. "\n ("..round(quest.value, 2).."/"..quests.registered_quests[questname].max..")"
|
||||||
end
|
end
|
||||||
return quest_string
|
return quest_string
|
||||||
end
|
end
|
||||||
@ -92,15 +102,31 @@ function quests.update_hud(playername)
|
|||||||
player:hud_change(hud_element.id, "number", 0x00BB00)
|
player:hud_change(hud_element.id, "number", 0x00BB00)
|
||||||
end
|
end
|
||||||
player:hud_change(hud_element.id, "text", get_quest_hud_string(hud_element.name, quests.active_quests[playername][hud_element.name]))
|
player:hud_change(hud_element.id, "text", get_quest_hud_string(hud_element.name, quests.active_quests[playername][hud_element.name]))
|
||||||
|
if (hud_element.id_bar ~= nil) then
|
||||||
|
player:hud_change(hud_element.id_bar, "number", math.floor(40 * hud_element.value / quests.registered_quests[hud_element.name].max))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
if (i ~= j) then
|
if (i ~= j) then
|
||||||
print(i .. "="..j)
|
print(i .. "="..j)
|
||||||
player:hud_change(hud_element.id, "offset", { x= -150, y=(i-1) *40})
|
player:hud_change(hud_element.id, "offset", { x= hud_config.offset.x, y=hud_config.offset.y + (i-1) *40})
|
||||||
|
if (hud_element.id_background ~= nil) then
|
||||||
|
player:hud_change(hud_element.id_background, "offset", { x= hud_config.offset.x, y=hud_config.offset.y + (i-1) *40 + 22})
|
||||||
|
end
|
||||||
|
if (hud_element.id_bar ~= nil) then
|
||||||
|
player:hud_change(hud_element.id_bar, "offset", { x= hud_config.offset.x, y=hud_config.offset.y + (i-1) *40 + 24})
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
visible[hud_element.name] = true
|
visible[hud_element.name] = true
|
||||||
i = i + 1
|
i = i + 1
|
||||||
else
|
else
|
||||||
player:hud_remove(hud_element.id)
|
player:hud_remove(hud_element.id)
|
||||||
|
if (hud_element.id_background ~= nil) then
|
||||||
|
player:hud_remove(hud_element.id_background)
|
||||||
|
end
|
||||||
|
if (hud_element.id_bar ~= nil) then
|
||||||
|
player:hud_remove(hud_element.id_bar)
|
||||||
|
end
|
||||||
table.insert(remove, j)
|
table.insert(remove, j)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -122,13 +148,33 @@ function quests.update_hud(playername)
|
|||||||
if (not visible[questname]) then
|
if (not visible[questname]) then
|
||||||
local id = player:hud_add({ hud_elem_type = "text",
|
local id = player:hud_add({ hud_elem_type = "text",
|
||||||
alignment = { x=1, y= 1 },
|
alignment = { x=1, y= 1 },
|
||||||
position = {x = 1, y = 0.3},
|
position = {x = hud_config.position.x, y = hud_config.position.y},
|
||||||
offset = {x = -150, y = counter * 40},
|
offset = {x = hud_config.offset.x, y = hud_config.offset.y + counter * 40},
|
||||||
number = 0xCACA00,
|
number = hud_config.number,
|
||||||
text = get_quest_hud_string(questname, questspecs) })
|
text = get_quest_hud_string(questname, questspecs) })
|
||||||
table.insert(quests.hud[playername], { name = questname,
|
local id_background
|
||||||
id = id,
|
local id_bar
|
||||||
value = questspecs.value })
|
if (quests.registered_quests[questname].max ~= 1) then
|
||||||
|
id_background = player:hud_add({ hud_elem_type = "image",
|
||||||
|
scale = { x = 1, y = 1 },
|
||||||
|
alignment = { x = 1, y = 1 },
|
||||||
|
position = { x = hud_config.position.x, y = hud_config.position.y },
|
||||||
|
offset = { x = hud_config.offset.x, y = hud_config.offset.y + counter * 40 + 22 },
|
||||||
|
text = "quests_questbar_background.png" })
|
||||||
|
id_bar = player:hud_add({hud_elem_type = "statbar",
|
||||||
|
scale = { x = 1, y = 1 },
|
||||||
|
alignment = { x = 1, y = 1 },
|
||||||
|
position = { x = hud_config.position.x, y = hud_config.position.y },
|
||||||
|
offset = { x = hud_config.offset.x + 2, y = hud_config.offset.y + counter * 40 + 24 },
|
||||||
|
number = math.floor(40 * questspecs.value / quests.registered_quests[questname].max),
|
||||||
|
text = "quests_questbar.png" })
|
||||||
|
end
|
||||||
|
|
||||||
|
table.insert(quests.hud[playername], { name = questname,
|
||||||
|
id = id,
|
||||||
|
id_background = id_background,
|
||||||
|
id_bar = id_bar,
|
||||||
|
value = questspecs.value })
|
||||||
counter = counter + 1
|
counter = counter + 1
|
||||||
if (counter >= show_max + 1) then
|
if (counter >= show_max + 1) then
|
||||||
break
|
break
|
||||||
@ -284,8 +330,18 @@ function quests.abort_quest(playername, questname)
|
|||||||
quests.failed_quests[playername][questname] = { count = 1 }
|
quests.failed_quests[playername][questname] = { count = 1 }
|
||||||
end
|
end
|
||||||
|
|
||||||
quests.active_quests[playername][questname] = nil
|
quests.active_quests[playername][questname].finished = true
|
||||||
quests.update_hud(playername)
|
for _,quest in ipairs(quests.hud[playername]) do
|
||||||
|
print(dump(quest))
|
||||||
|
if (quest.name == questname) then
|
||||||
|
local player = minetest.get_player_by_name(playername)
|
||||||
|
player:hud_change(quest.id, "number", 0xAD0000)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
minetest.after(3, function(playername, questname)
|
||||||
|
quests.active_quests[playername][questname] = nil
|
||||||
|
minetest.after(1,quests.update_hud,playername)
|
||||||
|
end, playername, questname)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- construct the questlog
|
-- construct the questlog
|
||||||
@ -306,14 +362,16 @@ function quests.create_formspec(playername, tab)
|
|||||||
quests.formspec_lists[playername].tab = tab
|
quests.formspec_lists[playername].tab = tab
|
||||||
|
|
||||||
for questname,questspecs in pairs(questlist) do
|
for questname,questspecs in pairs(questlist) do
|
||||||
local queststring = quests.registered_quests[questname]["title"]
|
if (questspecs.finished == nil) then
|
||||||
if (questspecs["count"] and questspecs["count"] > 1) then
|
local queststring = quests.registered_quests[questname]["title"]
|
||||||
queststring = queststring .. " - " .. questspecs["count"]
|
if (questspecs["count"] and questspecs["count"] > 1) then
|
||||||
elseif(not questspecs["count"] and quests.registered_quests[questname]["max"] ~= 1) then
|
queststring = queststring .. " - " .. questspecs["count"]
|
||||||
queststring = queststring .. " - (" .. round(questspecs["value"], 2) .. "/" .. quests.registered_quests[questname]["max"] .. ")"
|
elseif(not questspecs["count"] and quests.registered_quests[questname]["max"] ~= 1) then
|
||||||
|
queststring = queststring .. " - (" .. round(questspecs["value"], 2) .. "/" .. quests.registered_quests[questname]["max"] .. ")"
|
||||||
|
end
|
||||||
|
table.insert(queststringlist, queststring)
|
||||||
|
table.insert(quests.formspec_lists[playername].list, questname)
|
||||||
end
|
end
|
||||||
table.insert(queststringlist, queststring)
|
|
||||||
table.insert(quests.formspec_lists[playername].list, questname)
|
|
||||||
end
|
end
|
||||||
local formspec = "size[7,10]"..
|
local formspec = "size[7,10]"..
|
||||||
"tabheader[0,0;header;Open quests,Finished quests,Failed quests;" .. tab .. "]"..
|
"tabheader[0,0;header;Open quests,Finished quests,Failed quests;" .. tab .. "]"..
|
||||||
|
BIN
textures/quests_questbar.png
Normal file
BIN
textures/quests_questbar.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 155 B |
BIN
textures/quests_questbar_background.png
Normal file
BIN
textures/quests_questbar_background.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 337 B |
Loading…
Reference in New Issue
Block a user