include support for path gui
include support for mob preservation gui
This commit is contained in:
parent
9b3d89f658
commit
3947003960
@ -16,11 +16,14 @@
|
||||
minetest.log("action","MOD: mobf_settings mod loading ... ")
|
||||
|
||||
mobf_settings = {}
|
||||
mobf_settings.version = "0.0.19"
|
||||
mobf_settings.version = "0.0.20"
|
||||
mobf_settings.max_list_page_num = 5
|
||||
mobf_settings.buttons = {}
|
||||
mobf_settings.buttons[1] = {}
|
||||
mobf_settings.buttons[2] = {}
|
||||
mobf_settings.tool_buttons = {}
|
||||
mobf_settings.tool_buttons[1] = {}
|
||||
mobf_settings.tool_buttons[2] = {}
|
||||
mobf_settings.menubutton = "button_exit[11,9.5;2,0.5;main; Exit]"
|
||||
mobf_settings.formspechandler = function(player,formspec)
|
||||
name = player:get_player_name()
|
||||
@ -103,7 +106,7 @@ end
|
||||
------------------------------------------------------------------------------
|
||||
-- name: contains
|
||||
--
|
||||
--! @brief ccheck if element is in table
|
||||
--! @brief check if element is in table
|
||||
--! @ingroup mobf_settings
|
||||
--
|
||||
--! @param cur_table table to check for element
|
||||
@ -131,6 +134,38 @@ function contains(cur_table,element)
|
||||
return false
|
||||
end
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- name: contains_key
|
||||
--
|
||||
--! @brief check if table contains key
|
||||
--! @ingroup mobf_settings
|
||||
--
|
||||
--! @param cur_table table to check for element
|
||||
--! @param element element to find in table
|
||||
--!
|
||||
--! @return true/false
|
||||
-------------------------------------------------------------------------------
|
||||
function get_value(cur_table,key)
|
||||
|
||||
if cur_table == nil or
|
||||
key == nil then
|
||||
--print("looking in empty table")
|
||||
return nil
|
||||
end
|
||||
|
||||
--print("looking for " .. dump(element) .. " in " .. dump(cur_table))
|
||||
|
||||
for k,v in pairs(cur_table) do
|
||||
if k == key then
|
||||
--print("found: " .. element .. " in table")
|
||||
return v
|
||||
end
|
||||
end
|
||||
|
||||
--print("didn't find " .. element)
|
||||
return nil
|
||||
end
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- name: get_known_animals_form
|
||||
@ -142,10 +177,9 @@ end
|
||||
--!
|
||||
--! @return formspec of page
|
||||
-------------------------------------------------------------------------------
|
||||
function mobf_settings.get_known_animals_form(page)
|
||||
function mobf_settings.get_main_settings_form(page)
|
||||
local retval = ""
|
||||
|
||||
|
||||
for i=0,mobf_settings.max_list_page_num,1 do
|
||||
if page == "mobf_list_page" .. i then
|
||||
local nextpage = i +1
|
||||
@ -166,8 +200,6 @@ function mobf_settings.get_known_animals_form(page)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
if page == "mobf_restart_required" then
|
||||
retval = "label[0.5,2.25;This settings require to restart Game!]"
|
||||
.."label[0.5,2.5;-------------------------------------------]"
|
||||
@ -179,6 +211,17 @@ function mobf_settings.get_known_animals_form(page)
|
||||
return retval
|
||||
end
|
||||
|
||||
if page == "mobf_tools" then
|
||||
retval = "label[0.5,2.25;Tools to be used with mobf]"
|
||||
.."label[0.5,2.5;-------------------------------------------]"
|
||||
.."label[6.5,2.5;----------------------------------------]"
|
||||
|
||||
retval = retval .. mobf_settings.draw_tool_buttons(mobf_settings.tool_buttons[1],0.5)
|
||||
retval = retval .. mobf_settings.draw_tool_buttons(mobf_settings.tool_buttons[2],6.5)
|
||||
|
||||
return retval
|
||||
end
|
||||
|
||||
return ""
|
||||
end
|
||||
|
||||
@ -230,6 +273,34 @@ function mobf_settings.draw_buttons(buttons,xpos)
|
||||
return retval
|
||||
end
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- name: draw_tool_buttons
|
||||
--
|
||||
--! @brief get formspec for button drawing
|
||||
--! @ingroup mobf_settings
|
||||
--
|
||||
--! @param buttons buttons to show
|
||||
--! @param xpos pos to show buttons at
|
||||
--!
|
||||
--! @return formspec for button list
|
||||
-------------------------------------------------------------------------------
|
||||
function mobf_settings.draw_tool_buttons(buttons,xpos)
|
||||
local retval = ""
|
||||
|
||||
local y_pos = 3.75
|
||||
|
||||
for i=1,#buttons,1 do
|
||||
|
||||
retval = retval .. "button[" .. xpos .. ",".. y_pos .. ";6,0.5;" ..
|
||||
buttons[i].id .. ";" ..
|
||||
buttons[i].text .."]"
|
||||
|
||||
y_pos = y_pos + 0.75
|
||||
end
|
||||
|
||||
return retval
|
||||
end
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- name: handle_mob_en_disable_button
|
||||
--
|
||||
@ -351,6 +422,43 @@ function mobf_settings.handle_config_changed_button(fields)
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- name: handle_tool_button
|
||||
--
|
||||
--! @brief handle press of a settings button
|
||||
--! @ingroup mobf_settings
|
||||
--
|
||||
--! @param player whoever clicked the button
|
||||
--! @param fields
|
||||
--!
|
||||
--! @return
|
||||
-------------------------------------------------------------------------------
|
||||
function mobf_settings.handle_tool_button(player,fields)
|
||||
|
||||
for i=1,2,1 do
|
||||
for j=1,#mobf_settings.tool_buttons[i],1 do
|
||||
local id = nil
|
||||
|
||||
if mobf_settings.tool_buttons[i][j] ~= nil then
|
||||
id = mobf_settings.tool_buttons[i][j].id
|
||||
end
|
||||
|
||||
local value = get_value(fields,id)
|
||||
if value ~= nil then
|
||||
|
||||
if type(mobf_settings.tool_buttons[i][j].param) == "function" then
|
||||
mobf_settings.tool_buttons[i][j].param(player,fields)
|
||||
else
|
||||
mobf_settings_debug("MOBF_SETTINGS: invalid use of tool_button")
|
||||
end
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- name: get_formspec
|
||||
--
|
||||
@ -361,7 +469,6 @@ end
|
||||
--! @param page pagename to create
|
||||
-------------------------------------------------------------------------------
|
||||
function mobf_settings.get_formspec(player,page)
|
||||
|
||||
local version = "< 1.4.5"
|
||||
|
||||
if (type(mobf_get_version) == "function") then
|
||||
@ -369,20 +476,22 @@ function mobf_settings.get_formspec(player,page)
|
||||
end
|
||||
|
||||
local playername = player:get_player_name()
|
||||
|
||||
if minetest.check_player_privs(playername, {mobfw_admin=true}) then
|
||||
local pageform = mobf_settings.get_known_animals_form(page)
|
||||
local pageform = mobf_settings.get_main_settings_form(page)
|
||||
|
||||
return "size[13,10]"
|
||||
..mobf_settings.menubutton
|
||||
.."button[0.5,0.75;3,0.5;mobf_list_page1; Known Mobs ]"
|
||||
.."button[4,0.75;3,0.5;mobf_restart_required; Settings ]"
|
||||
.."button[7.5,0.75;3,0.5;mobf_tools; Tools ]"
|
||||
.."label[5.5,0;MOBF " .. version .. "]"
|
||||
.. pageform
|
||||
else
|
||||
return "size[13,10]"
|
||||
..mobf_settings.menubutton
|
||||
.."label[0.5,1.0;You are not allowed to change any setting!]"
|
||||
.."label[0.5,2.25;Go Away!]"
|
||||
.."button[0.5,0.75;3,0.5;mobf_tools; Tools ]"
|
||||
.."label[0.5,2.0;You are not allowed to change any setting!]"
|
||||
.."label[5.5,0;MOBF " .. version .. "]"
|
||||
end
|
||||
|
||||
@ -420,11 +529,12 @@ function mobf_settings.set_mob_list_page(player,fields)
|
||||
end
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- name: register_config_button(configvalue,buttontext)
|
||||
-- name: register_config_button(index,configvalue,buttontext,inverted)
|
||||
--
|
||||
--! @brief register a button to be shown on config page
|
||||
--! @ingroup mobf_settings
|
||||
--
|
||||
--! @param index column to draw button at
|
||||
--! @param configvalue config value to change by this button
|
||||
--! @param buttontext to set for this value
|
||||
--! @param inverted invert enable/disable text on button
|
||||
@ -442,18 +552,57 @@ function mobf_settings.register_config_button(index,configvalue,buttontext,inver
|
||||
end
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- register handler for pressed buttons to inventory plus
|
||||
-- name: register_tool_button(index,id,buttontext,param)
|
||||
--
|
||||
--! @brief register a button to be shown on config page
|
||||
--! @ingroup mobf_settings
|
||||
--
|
||||
--! @param index column to draw button at
|
||||
--! @param id to use for button (has to be unique)
|
||||
--! @param buttontext to set for this value
|
||||
--! @param param function to call
|
||||
--
|
||||
-------------------------------------------------------------------------------
|
||||
function mobf_settings.register_tool_button(index,id,buttontext,param)
|
||||
|
||||
local toadd = {
|
||||
param = param,
|
||||
text = buttontext,
|
||||
id = id,
|
||||
}
|
||||
|
||||
table.insert(mobf_settings.tool_buttons[index],toadd)
|
||||
end
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- register handler for pressed buttons
|
||||
------------------------------------------------------------------------------
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
--if one of your page buttons is pressed show another moblist page
|
||||
if mobf_settings.set_mob_list_page(player,fields) then
|
||||
mobf_settings_debug("mobf_settings: abort button processing")
|
||||
return true
|
||||
end
|
||||
|
||||
--handle tool buttons (no redraw of menu as this could be done by fct
|
||||
if mobf_settings.handle_tool_button(player,fields) then
|
||||
mobf_settings_debug("mobf_settings: abort button processing")
|
||||
return true
|
||||
end
|
||||
|
||||
--handle menu buttons
|
||||
if mobf_settings.handle_config_changed_button(fields) or
|
||||
fields.mobf_restart_required ~= nil then
|
||||
fields.mobf_tools ~= nil or fields.mobf_restart_required ~= nil then
|
||||
local page = "mobf_restart_required"
|
||||
if fields.mobf_tools ~= nil then
|
||||
page = "mobf_tools"
|
||||
mobf_settings_debug("MOBF_SETTINGS: show tool page")
|
||||
else
|
||||
mobf_settings_debug("MOBF_SETTINGS: settings have been changed, show settings page: " .. dump(fields.mobf_restart_required))
|
||||
mobf_settings.formspechandler(player, mobf_settings.get_formspec(player,"mobf_restart_required"))
|
||||
end
|
||||
|
||||
mobf_settings.formspechandler(player, mobf_settings.get_formspec(player,page))
|
||||
mobf_settings_debug("mobf_settings: abort button processing")
|
||||
return true
|
||||
end
|
||||
|
||||
@ -461,6 +610,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
|
||||
if blacklist_changed_page ~= nil then
|
||||
mobf_settings.formspechandler(player, mobf_settings.get_formspec(player,blacklist_changed_page))
|
||||
mobf_settings_debug("mobf_settings: abort button processing")
|
||||
return true
|
||||
end
|
||||
|
||||
@ -493,4 +643,26 @@ mobf_settings.register_config_button(1,"mobf_log_removed_entities","Log all remo
|
||||
mobf_settings.register_config_button(1,"mobf_grief_protection","Disallow mob stealing",false)
|
||||
mobf_settings.register_config_button(2,"mobf_lifebar","lifebar",false)
|
||||
|
||||
mobf_settings.register_tool_button(1,"give_pathmaker_tool","Give pathmaker tool",
|
||||
function(player)
|
||||
player:get_inventory():add_item("main", "mobf:path_marker 1")
|
||||
end)
|
||||
mobf_settings.register_tool_button(1,"show_mobstore","Show preserved mobs",
|
||||
function(player)
|
||||
local name = player:get_player_name()
|
||||
|
||||
if name ~= nil then
|
||||
mob_preserve.handle_command(name,nil)
|
||||
end
|
||||
end)
|
||||
|
||||
mobf_settings.register_tool_button(1,"show_pathmanager","Manage paths",
|
||||
function(player)
|
||||
local name = player:get_player_name()
|
||||
|
||||
if name ~= nil then
|
||||
mobf_path.show_manage_menu(name,nil)
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.log("action","MOD: mobf_settings mod version "..mobf_settings.version.." loaded")
|
Loading…
x
Reference in New Issue
Block a user