1
0
mirror of https://github.com/TeTpaAka/quests.git synced 2024-12-22 16:50:39 +01:00

Add pages to unified_inventory

This commit is contained in:
TeTpaAka 2015-03-04 20:56:00 +01:00
parent d9658b8b49
commit 0d6868cff6
2 changed files with 137 additions and 62 deletions

View File

@ -9,7 +9,8 @@ end
-- construct the questlog
function quests.create_formspec(playername, tab)
function quests.create_formspec(playername, tab, integrated)
print(tab)
local queststringlist = {}
local questlist = {}
quests.formspec_lists[playername] = quests.formspec_lists[playername] or {}
@ -39,52 +40,61 @@ function quests.create_formspec(playername, tab)
no_quests = false
end
end
local formspec = "size[7,10]"..
"tabheader[0,0;header;" .. S("Open quests") .. "," .. S("Finished quests") .. "," .. S("Failed quests") .. ";" .. tab .. "]"
local formspec = ""
if (not integrated) then
formspec = formspec .. "size[7,9]"
end
formspec = formspec .. "tabheader[0,0;quests_header;" .. S("Open quests") .. "," .. S("Finished quests") .. "," .. S("Failed quests") .. ";" .. tab .. "]"
if (no_quests) then
formspec = formspec .. "label[0.25,0.25;" .. S("There are no quests in this category.") .. "]"
else
formspec = formspec .. "textlist[0.25,0.25;6.5,7.5;questlist;"..table.concat(queststringlist, ",") .. ";1;false]"
formspec = formspec .. "textlist[0.25,0.25;6.5,6.5;quests_questlist;"..table.concat(queststringlist, ",") .. ";1;false]"
end
if (quests.formspec_lists[playername].tab == "1") then
formspec = formspec .."button[0.25,8;3,.7;abort;" .. S("Abort quest") .. "]"
formspec = formspec .."button[0.25,7;3,.7;quests_abort;" .. S("Abort quest") .. "]"
end
formspec = formspec .. "button[3.75,8;3,.7;config;" .. S("Configure") .. "]"..
"button[.25,9;3,.7;info;" .. S("Info") .. "]"..
"button_exit[3.75,9;3,.7;exit;" .. S("Exit") .. "]"
formspec = formspec .. "button[3.75,7;3,.7;quests_config;" .. S("Configure") .. "]"..
"button[.25,8;3,.7;quests_info;" .. S("Info") .. "]"..
"button_exit[3.75,8;3,.7;quests_exit;" .. S("Exit") .. "]"
return formspec
end
-- construct the configuration
function quests.create_config(playername)
local formspec = "size[7,3]" ..
"checkbox[.25,.25;enable;" .. S("Enable HUD") .. ";"
function quests.create_config(playername, integrated)
local formspec = ""
if (not integrated) then
formspec = formspec .. "size[7,3]"
end
formspec = formspec .. "checkbox[.25,.25;quests_config_enable;" .. S("Enable HUD") .. ";"
if(quests.hud[playername] ~= nil) then
formspec = formspec .. "true"
else
formspec = formspec .. "false"
end
formspec = formspec .. "]"..
"button[.25,1.25;3,.7;return;" .. S("Return") .. "]"
"button[.25,1.25;3,.7;quests_config_return;" .. S("Return") .. "]"
return formspec
end
-- construct the info formspec
function quests.create_info(playername, questname)
local formspec = "size[7,6.5]" ..
"label[0.5,0.5;"
function quests.create_info(playername, questname, integrated)
local formspec = ""
if (not integrated) then
formspec = formspec .. "size[7,6.5]"
end
formspec = formspec .. "label[0.5,0.5;"
if (questname) then
formspec = formspec .. quests.registered_quests[questname].title .. "]" ..
"textarea[.5,1.5;6,4.5;description;;" .. quests.registered_quests[questname].description .. "]"
"textarea[.5,1.5;6,4.5;quests_info_description;;" .. quests.registered_quests[questname].description .. "]"
if (quests.formspec_lists[playername].tab == "1") then
formspec = formspec .. "button[.5,6;3,.7;abort;" .. S("Abort quest") .. "]"
formspec = formspec .. "button[.5,6;3,.7;quests_info_abort;" .. S("Abort quest") .. "]"
end
else
formspec = formspec .. S("No quest specified.") .. "]"
end
formspec = formspec .. "button[3.25,6;3,.7;return;" .. S("Return") .. "]"
formspec = formspec .. "button[3.25,6;3,.7;quests_info_return;" .. S("Return") .. "]"
return formspec
end
@ -112,55 +122,89 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if (playername == "") then
return
end
if (formname == "quests:questlog") then
if (fields["header"]) then
minetest.show_formspec(playername, "quests:questlog", quests.create_formspec(playername, fields["header"]))
-- questlog
if (fields["quests_header"]) then
if (formname == "quests:questlog") then
minetest.show_formspec(playername, "quests:questlog", quests.create_formspec(playername, fields["quests_header"]))
else
if (fields["quests_header"] == "1") then
unified_inventory.set_inventory_formspec(player, "quests")
elseif (fields["quests_header"] == "2") then
unified_inventory.set_inventory_formspec(player, "quests_successfull")
return
else
unified_inventory.set_inventory_formspec(player, "quests_failed")
return
end
end
return
end
if (fields["quests_questlist"]) then
local event = minetest.explode_textlist_event(fields["quests_questlist"])
if (event.type == "CHG") then
quests.formspec_lists[playername].id = event.index
end
end
if (fields["quests_abort"]) then
if (quests.formspec_lists[playername].id == nil) then
return
end
if (fields["questlist"]) then
local event = minetest.explode_textlist_event(fields["questlist"])
if (event.type == "CHG") then
quests.formspec_lists[playername].id = event.index
end
end
if (fields["abort"]) then
if (quests.formspec_lists[playername].id == nil) then
return
end
quests.abort_quest(playername, quests.formspec_lists[playername]["list"][quests.formspec_lists[playername].id])
quests.abort_quest(playername, quests.formspec_lists[playername]["list"][quests.formspec_lists[playername].id])
if (formname == "quests:questlog") then
minetest.show_formspec(playername, "quests:questlog", quests.create_formspec(playername))
else
unified_inventory.set_inventory_formspec(player, "quests")
end
if (fields["config"]) then
end
if (fields["quests_config"]) then
if (formname == "quests:questlog") then
minetest.show_formspec(playername, "quests:config", quests.create_config(playername))
else
unified_inventory.set_inventory_formspec(player, "quests_config")
end
if (fields["info"]) then
end
if (fields["quests_info"]) then
if (formname == "quests:questlog") then
minetest.show_formspec(playername, "quests:info", quests.create_info(playername, quests.formspec_lists[playername].list[quests.formspec_lists[playername].id]))
else
unified_inventory.set_inventory_formspec(player, "quests_info")
end
end
if (formname == "quests:config") then
if (fields["enable"]) then
if (fields["enable"] == "true") then
quests.show_hud(playername)
else
quests.hide_hud(playername)
end
end
if (fields["return"]) then
minetest.show_formspec(playername, "quests:questlog", quests.create_formspec(playername))
-- config
if (fields["quests_config_enable"]) then
if (fields["quests_config_enable"] == "true") then
quests.show_hud(playername)
else
quests.hide_hud(playername)
end
end
if (formname == "quests:info") then
if (fields["abort"]) then
if (quests.formspec_lists[playername].id == nil) then
return
end
quests.abort_quest(playername, quests.formspec_lists[playername]["list"][quests.formspec_lists[playername].id])
if (fields["quests_config_return"]) then
if (formname == "quests:config") then
minetest.show_formspec(playername, "quests:questlog", quests.create_formspec(playername))
else
unified_inventory.set_inventory_formspec(player, "quests")
end
if (fields["return"]) then
end
-- info
if (fields["quests_info_abort"]) then
if (quests.formspec_lists[playername].id == nil) then
return
end
quests.abort_quest(playername, quests.formspec_lists[playername]["list"][quests.formspec_lists[playername].id])
if (formname == "quests:info") then
minetest.show_formspec(playername, "quests:questlog", quests.create_formspec(playername))
else
unified_inventory.set_inventory_formspec(player, "quests")
end
end
if (fields["quests_info_return"]) then
if (formname == "quests:info") then
minetest.show_formspec(playername, "quests:questlog", quests.create_formspec(playername))
else
unified_inventory.set_inventory_formspec(player, "quests")
end
end
end)

View File

@ -2,15 +2,46 @@ unified_inventory.register_button("quests", {
type = "image",
image = "inventory_plus_quests.png",
tooltip = "Show the questlog",
action = function(player)
quests.show_formspec(player:get_player_name())
-- action = function(player)
-- quests.show_formspec(player:get_player_name())
-- end
})
unified_inventory.register_page("quests", {
get_formspec = function(player)
local playername = player:get_player_name()
local formspec = quests.create_formspec(playername, "1", true)
return {formspec = formspec, draw_inventory=false}
end
})
--unified_inventory.register_page("quests", {
-- get_formspec = function(player, formspec)
-- local playername = player:get_player_name()
-- local formspec = quests.create_formspec(playername)
-- return {formspec = formspec, draw_inventory=false}
-- end
--})
unified_inventory.register_page("quests_successfull", {
get_formspec = function(player)
local playername = player:get_player_name()
local formspec = quests.create_formspec(playername, "2", true)
return {formspec = formspec, draw_inventory=false}
end
})
unified_inventory.register_page("quests_failed", {
get_formspec = function(player)
local playername = player:get_player_name()
local formspec = quests.create_formspec(playername, "3", true)
return {formspec = formspec, draw_inventory=false}
end
})
unified_inventory.register_page("quests_config", {
get_formspec = function(player)
local playername = player:get_player_name()
local formspec = quests.create_config(playername, true)
return {formspec = formspec, draw_inventory = false }
end
})
unified_inventory.register_page("quests_info", {
get_formspec = function(player)
local playername = player:get_player_name()
local formspec = quests.create_info(playername, quests.formspec_lists[playername].list[quests.formspec_lists[playername].id], true)
return {formspec = formspec, draw_inventory = false }
end
})