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:
parent
d9658b8b49
commit
0d6868cff6
150
formspecs.lua
150
formspecs.lua
@ -9,7 +9,8 @@ end
|
|||||||
|
|
||||||
|
|
||||||
-- construct the questlog
|
-- construct the questlog
|
||||||
function quests.create_formspec(playername, tab)
|
function quests.create_formspec(playername, tab, integrated)
|
||||||
|
print(tab)
|
||||||
local queststringlist = {}
|
local queststringlist = {}
|
||||||
local questlist = {}
|
local questlist = {}
|
||||||
quests.formspec_lists[playername] = quests.formspec_lists[playername] or {}
|
quests.formspec_lists[playername] = quests.formspec_lists[playername] or {}
|
||||||
@ -39,52 +40,61 @@ function quests.create_formspec(playername, tab)
|
|||||||
no_quests = false
|
no_quests = false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local formspec = "size[7,10]"..
|
local formspec = ""
|
||||||
"tabheader[0,0;header;" .. S("Open quests") .. "," .. S("Finished quests") .. "," .. S("Failed quests") .. ";" .. tab .. "]"
|
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
|
if (no_quests) then
|
||||||
formspec = formspec .. "label[0.25,0.25;" .. S("There are no quests in this category.") .. "]"
|
formspec = formspec .. "label[0.25,0.25;" .. S("There are no quests in this category.") .. "]"
|
||||||
else
|
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
|
end
|
||||||
if (quests.formspec_lists[playername].tab == "1") then
|
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
|
end
|
||||||
formspec = formspec .. "button[3.75,8;3,.7;config;" .. S("Configure") .. "]"..
|
formspec = formspec .. "button[3.75,7;3,.7;quests_config;" .. S("Configure") .. "]"..
|
||||||
"button[.25,9;3,.7;info;" .. S("Info") .. "]"..
|
"button[.25,8;3,.7;quests_info;" .. S("Info") .. "]"..
|
||||||
"button_exit[3.75,9;3,.7;exit;" .. S("Exit") .. "]"
|
"button_exit[3.75,8;3,.7;quests_exit;" .. S("Exit") .. "]"
|
||||||
return formspec
|
return formspec
|
||||||
end
|
end
|
||||||
|
|
||||||
-- construct the configuration
|
-- construct the configuration
|
||||||
function quests.create_config(playername)
|
function quests.create_config(playername, integrated)
|
||||||
local formspec = "size[7,3]" ..
|
local formspec = ""
|
||||||
"checkbox[.25,.25;enable;" .. S("Enable HUD") .. ";"
|
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
|
if(quests.hud[playername] ~= nil) then
|
||||||
formspec = formspec .. "true"
|
formspec = formspec .. "true"
|
||||||
else
|
else
|
||||||
formspec = formspec .. "false"
|
formspec = formspec .. "false"
|
||||||
end
|
end
|
||||||
formspec = formspec .. "]"..
|
formspec = formspec .. "]"..
|
||||||
"button[.25,1.25;3,.7;return;" .. S("Return") .. "]"
|
"button[.25,1.25;3,.7;quests_config_return;" .. S("Return") .. "]"
|
||||||
return formspec
|
return formspec
|
||||||
end
|
end
|
||||||
|
|
||||||
-- construct the info formspec
|
-- construct the info formspec
|
||||||
function quests.create_info(playername, questname)
|
function quests.create_info(playername, questname, integrated)
|
||||||
local formspec = "size[7,6.5]" ..
|
local formspec = ""
|
||||||
"label[0.5,0.5;"
|
if (not integrated) then
|
||||||
|
formspec = formspec .. "size[7,6.5]"
|
||||||
|
end
|
||||||
|
formspec = formspec .. "label[0.5,0.5;"
|
||||||
|
|
||||||
if (questname) then
|
if (questname) then
|
||||||
formspec = formspec .. quests.registered_quests[questname].title .. "]" ..
|
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
|
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
|
end
|
||||||
else
|
else
|
||||||
formspec = formspec .. S("No quest specified.") .. "]"
|
formspec = formspec .. S("No quest specified.") .. "]"
|
||||||
end
|
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
|
return formspec
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -112,55 +122,89 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
if (playername == "") then
|
if (playername == "") then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if (formname == "quests:questlog") then
|
|
||||||
if (fields["header"]) then
|
-- questlog
|
||||||
minetest.show_formspec(playername, "quests:questlog", quests.create_formspec(playername, fields["header"]))
|
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
|
return
|
||||||
end
|
end
|
||||||
if (fields["questlist"]) then
|
quests.abort_quest(playername, quests.formspec_lists[playername]["list"][quests.formspec_lists[playername].id])
|
||||||
local event = minetest.explode_textlist_event(fields["questlist"])
|
if (formname == "quests:questlog") then
|
||||||
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])
|
|
||||||
minetest.show_formspec(playername, "quests:questlog", quests.create_formspec(playername))
|
minetest.show_formspec(playername, "quests:questlog", quests.create_formspec(playername))
|
||||||
|
else
|
||||||
|
unified_inventory.set_inventory_formspec(player, "quests")
|
||||||
end
|
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))
|
minetest.show_formspec(playername, "quests:config", quests.create_config(playername))
|
||||||
|
else
|
||||||
|
unified_inventory.set_inventory_formspec(player, "quests_config")
|
||||||
end
|
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]))
|
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
|
||||||
end
|
end
|
||||||
if (formname == "quests:config") then
|
|
||||||
if (fields["enable"]) then
|
-- config
|
||||||
if (fields["enable"] == "true") then
|
if (fields["quests_config_enable"]) then
|
||||||
quests.show_hud(playername)
|
if (fields["quests_config_enable"] == "true") then
|
||||||
else
|
quests.show_hud(playername)
|
||||||
quests.hide_hud(playername)
|
else
|
||||||
end
|
quests.hide_hud(playername)
|
||||||
end
|
|
||||||
if (fields["return"]) then
|
|
||||||
minetest.show_formspec(playername, "quests:questlog", quests.create_formspec(playername))
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if (formname == "quests:info") then
|
if (fields["quests_config_return"]) then
|
||||||
if (fields["abort"]) then
|
if (formname == "quests:config") 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])
|
|
||||||
minetest.show_formspec(playername, "quests:questlog", quests.create_formspec(playername))
|
minetest.show_formspec(playername, "quests:questlog", quests.create_formspec(playername))
|
||||||
|
else
|
||||||
|
unified_inventory.set_inventory_formspec(player, "quests")
|
||||||
end
|
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))
|
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
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,15 +2,46 @@ unified_inventory.register_button("quests", {
|
|||||||
type = "image",
|
type = "image",
|
||||||
image = "inventory_plus_quests.png",
|
image = "inventory_plus_quests.png",
|
||||||
tooltip = "Show the questlog",
|
tooltip = "Show the questlog",
|
||||||
action = function(player)
|
-- action = function(player)
|
||||||
quests.show_formspec(player:get_player_name())
|
-- 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
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
--unified_inventory.register_page("quests", {
|
unified_inventory.register_page("quests_successfull", {
|
||||||
-- get_formspec = function(player, formspec)
|
get_formspec = function(player)
|
||||||
-- local playername = player:get_player_name()
|
local playername = player:get_player_name()
|
||||||
-- local formspec = quests.create_formspec(playername)
|
local formspec = quests.create_formspec(playername, "2", true)
|
||||||
-- return {formspec = formspec, draw_inventory=false}
|
return {formspec = formspec, draw_inventory=false}
|
||||||
-- end
|
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
|
||||||
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user