Add "mobf_settings" mod from "mobf_core" modpack.
This commit is contained in:
parent
e88098b650
commit
bc8d235112
@ -44,7 +44,8 @@ The following mods are also included:
|
||||
* [mesecons (modpack)][mesecons] ([LGPL/CC-BY-SA](mods/mesecons/COPYING.txt))
|
||||
* mob_engines/
|
||||
* [creatures (Creatures MOB-Engine)][cme] ([zlib/CC-BY-SA](doc/modpacks/cme/README.txt))
|
||||
* [mobf (MOB Framework core)][mobf] ([CC-BY-SA](doc/modpacks/mobf_core/License.txt))
|
||||
* [mobf (mobf_core modpack)][mobf] ([CC-BY-SA](doc/modpacks/mobf_core/License.txt))
|
||||
* [mobf_settings (mobf_core modpack)][mobf]
|
||||
* [pipeworks][] ([WTFPL](mods/pipeworks/LICENSE))
|
||||
* plantlife/
|
||||
* player/
|
||||
|
97
mods/mob_engines/mobf_settings/common.lua
Normal file
97
mods/mob_engines/mobf_settings/common.lua
Normal file
@ -0,0 +1,97 @@
|
||||
--------------------------------------------------------------------------------
|
||||
-- Mob Framework Settings Mod by Sapier
|
||||
--
|
||||
-- You may copy, use, modify or do nearly anything except removing this
|
||||
-- copyright notice.
|
||||
-- And of course you are NOT allowed to pretend you have written it.
|
||||
--
|
||||
--! @file tab_feature_config.lua
|
||||
--! @brief settings gui for mobf
|
||||
--! @copyright Sapier
|
||||
--! @author Sapier
|
||||
--! @date 2014-05-30
|
||||
--
|
||||
-- Contact sapier a t gmx net
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
assert(not core.global_exists("mobf_settings"))
|
||||
mobf_settings = {}
|
||||
|
||||
COLOR_RED = "#FF0000"
|
||||
COLOR_GREEN = "#00FF00"
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- name: setting_gettext(name)
|
||||
-- @function [parent=#mobf_settings] setting_gettext
|
||||
--
|
||||
--! @brief convert bool to textual value
|
||||
--! @ingroup mobf_settings
|
||||
--
|
||||
--! @param value string
|
||||
-------------------------------------------------------------------------------
|
||||
function mobf_settings.setting_gettext(value)
|
||||
|
||||
local value = mobf_get_world_setting(value)
|
||||
|
||||
if value == nil then
|
||||
return "false"
|
||||
end
|
||||
|
||||
if value then
|
||||
return "true"
|
||||
end
|
||||
|
||||
return "false"
|
||||
end
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- name: printfac
|
||||
-- @function [parent=#mobf_settings] printfac
|
||||
--
|
||||
--! @brief update formspec to tools tab
|
||||
--! @ingroup mobf_settings
|
||||
--
|
||||
--! @param name of facility
|
||||
--! @param data data to add label
|
||||
--! @param yval ypos of label
|
||||
--! @param vs formatstring
|
||||
--
|
||||
--! @return formspec label element string
|
||||
-------------------------------------------------------------------------------
|
||||
function mobf_settings.printfac(name,data,yval,fs)
|
||||
|
||||
return
|
||||
"label[0.75," .. yval .. ";" .. string.sub(name,1,20) .. "]" ..
|
||||
"label[2.75," .. yval .. ";" ..
|
||||
string.format("%10s",string.format(fs,data.current)).. "]" ..
|
||||
"label[4.25," .. yval .. ";" ..
|
||||
string.format("%10s",data.maxabs).. "]" ..
|
||||
"label[6," .. yval .. ";" ..
|
||||
string.format("%10s",string.format(fs,data.max)).. "]"
|
||||
end
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- name: contains
|
||||
--
|
||||
--! @brief check if element is in table
|
||||
--! @ingroup mobf_settings
|
||||
--
|
||||
--! @param cur_table table to check for element
|
||||
--! @param element element to find in table
|
||||
--!
|
||||
--! @return true/false
|
||||
-------------------------------------------------------------------------------
|
||||
function contains(cur_table, element)
|
||||
|
||||
if cur_table == nil then
|
||||
return false
|
||||
end
|
||||
|
||||
for i,v in ipairs(cur_table) do
|
||||
if v == element then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
1
mods/mob_engines/mobf_settings/depends.txt
Normal file
1
mods/mob_engines/mobf_settings/depends.txt
Normal file
@ -0,0 +1 @@
|
||||
mobf
|
77
mods/mob_engines/mobf_settings/fstk/dialog.lua
Normal file
77
mods/mob_engines/mobf_settings/fstk/dialog.lua
Normal file
@ -0,0 +1,77 @@
|
||||
--Minetest
|
||||
--Copyright (C) 2014 sapier
|
||||
--
|
||||
--self program is free software; you can redistribute it and/or modify
|
||||
--it under the terms of the GNU Lesser General Public License as published by
|
||||
--the Free Software Foundation; either version 2.1 of the License, or
|
||||
--(at your option) any later version.
|
||||
--
|
||||
--self program is distributed in the hope that it will be useful,
|
||||
--but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
--MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
--GNU Lesser General Public License for more details.
|
||||
--
|
||||
--You should have received a copy of the GNU Lesser General Public License along
|
||||
--with self program; if not, write to the Free Software Foundation, Inc.,
|
||||
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
local function dialog_event_handler(self,event)
|
||||
if self.user_eventhandler == nil or
|
||||
self.user_eventhandler(event) == false then
|
||||
|
||||
--close dialog on esc
|
||||
if event == "MenuQuit" then
|
||||
self:delete()
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local dialog_metatable = {
|
||||
eventhandler = dialog_event_handler,
|
||||
get_formspec = function(self)
|
||||
if not self.hidden then return self.formspec(self.data) end
|
||||
end,
|
||||
handle_buttons = function(self,fields)
|
||||
if not self.hidden then return self.buttonhandler(self,fields) end
|
||||
end,
|
||||
handle_events = function(self,event)
|
||||
if not self.hidden then return self.eventhandler(self,event) end
|
||||
end,
|
||||
hide = function(self) self.hidden = true end,
|
||||
show = function(self) self.hidden = false end,
|
||||
delete = function(self)
|
||||
if self.parent ~= nil then
|
||||
self.parent:show()
|
||||
end
|
||||
|
||||
if self.parent_ui ~= nil then
|
||||
self.parent_ui:delete(self)
|
||||
end
|
||||
end,
|
||||
set_parent = function(self,parent) self.parent = parent end
|
||||
}
|
||||
dialog_metatable.__index = dialog_metatable
|
||||
|
||||
function dialog_create(name, get_formspec, buttonhandler, eventhandler,
|
||||
parent_ui)
|
||||
local self = {}
|
||||
|
||||
self.name = name
|
||||
self.type = "toplevel"
|
||||
self.hidden = true
|
||||
self.data = {}
|
||||
self.parent_ui = parent_ui
|
||||
|
||||
self.formspec = get_formspec
|
||||
self.buttonhandler = buttonhandler
|
||||
self.user_eventhandler = eventhandler
|
||||
|
||||
setmetatable(self,dialog_metatable)
|
||||
|
||||
if self.parent_ui ~= nil then
|
||||
self.parent_ui:add(self)
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
317
mods/mob_engines/mobf_settings/fstk/tabview.lua
Normal file
317
mods/mob_engines/mobf_settings/fstk/tabview.lua
Normal file
@ -0,0 +1,317 @@
|
||||
--Minetest
|
||||
--Copyright (C) 2014 sapier
|
||||
--
|
||||
--self program is free software; you can redistribute it and/or modify
|
||||
--it under the terms of the GNU Lesser General Public License as published by
|
||||
--the Free Software Foundation; either version 2.1 of the License, or
|
||||
--(at your option) any later version.
|
||||
--
|
||||
--self program is distributed in the hope that it will be useful,
|
||||
--but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
--MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
--GNU Lesser General Public License for more details.
|
||||
--
|
||||
--You should have received a copy of the GNU Lesser General Public License along
|
||||
--with self program; if not, write to the Free Software Foundation, Inc.,
|
||||
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- A tabview implementation --
|
||||
-- Usage: --
|
||||
-- tabview.create: returns initialized tabview raw element --
|
||||
-- element.add(tab): add a tab declaration --
|
||||
-- element.handle_buttons() --
|
||||
-- element.handle_events() --
|
||||
-- element.getFormspec() returns formspec of tabview --
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
local function add_tab(self, tab, data)
|
||||
assert(tab.size == nil or (type(tab.size) == table and
|
||||
tab.size.x ~= nil and tab.size.y ~= nil))
|
||||
assert(tab.cbf_formspec ~= nil and type(tab.cbf_formspec) == "function")
|
||||
assert(tab.cbf_button_handler == nil or
|
||||
type(tab.cbf_button_handler) == "function")
|
||||
assert(tab.cbf_events == nil or type(tab.cbf_events) == "function")
|
||||
|
||||
local newtab = {
|
||||
name = tab.name,
|
||||
caption = tab.caption,
|
||||
button_handler = tab.cbf_button_handler,
|
||||
event_handler = tab.cbf_events,
|
||||
get_formspec = tab.cbf_formspec,
|
||||
tabsize = tab.tabsize,
|
||||
on_change = tab.on_change,
|
||||
tabdata = {},
|
||||
}
|
||||
|
||||
if data then
|
||||
newtab.tabdata = data
|
||||
end
|
||||
|
||||
table.insert(self.tablist,newtab)
|
||||
|
||||
if self.last_tab_index == #self.tablist then
|
||||
self.current_tab = tab.name
|
||||
if tab.on_activate ~= nil then
|
||||
tab.on_activate(nil,tab.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
local function get_formspec(self)
|
||||
local formspec = ""
|
||||
|
||||
if not self.hidden and (self.parent == nil or not self.parent.hidden) then
|
||||
|
||||
if self.parent == nil then
|
||||
local tsize = self.tablist[self.last_tab_index].tabsize or
|
||||
{width=self.width, height=self.height}
|
||||
formspec = formspec ..
|
||||
string.format("size[%f,%f,%s]",tsize.width,tsize.height,
|
||||
dump(self.fixed_size))
|
||||
end
|
||||
formspec = formspec .. self:tab_header()
|
||||
formspec = formspec ..
|
||||
self.tablist[self.last_tab_index].get_formspec(
|
||||
self,
|
||||
self.tablist[self.last_tab_index].name,
|
||||
self.tablist[self.last_tab_index].tabdata,
|
||||
self.tablist[self.last_tab_index].tabsize
|
||||
)
|
||||
end
|
||||
return formspec
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
local function handle_buttons(self,fields)
|
||||
|
||||
if self.hidden then
|
||||
return false
|
||||
end
|
||||
|
||||
if self:handle_tab_buttons(fields) then
|
||||
return true
|
||||
end
|
||||
|
||||
if self.glb_btn_handler ~= nil and
|
||||
self.glb_btn_handler(self,fields) then
|
||||
return true
|
||||
end
|
||||
|
||||
if self.tablist[self.last_tab_index].button_handler ~= nil then
|
||||
return
|
||||
self.tablist[self.last_tab_index].button_handler(
|
||||
self,
|
||||
fields,
|
||||
self.tablist[self.last_tab_index].name,
|
||||
self.tablist[self.last_tab_index].tabdata
|
||||
)
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
local function handle_events(self,event)
|
||||
|
||||
if self.hidden then
|
||||
return false
|
||||
end
|
||||
|
||||
if self.glb_evt_handler ~= nil and
|
||||
self.glb_evt_handler(self,event) then
|
||||
return true
|
||||
end
|
||||
|
||||
if self.tablist[self.last_tab_index].evt_handler ~= nil then
|
||||
return
|
||||
self.tablist[self.last_tab_index].evt_handler(
|
||||
self,
|
||||
event,
|
||||
self.tablist[self.last_tab_index].name,
|
||||
self.tablist[self.last_tab_index].tabdata
|
||||
)
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
local function tab_header(self)
|
||||
|
||||
local toadd = ""
|
||||
|
||||
for i=1,#self.tablist,1 do
|
||||
|
||||
if toadd ~= "" then
|
||||
toadd = toadd .. ","
|
||||
end
|
||||
|
||||
toadd = toadd .. self.tablist[i].caption
|
||||
end
|
||||
return string.format("tabheader[%f,%f;%s;%s;%i;true;false]",
|
||||
self.header_x, self.header_y, self.name, toadd, self.last_tab_index);
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
local function switch_to_tab(self, index)
|
||||
--first call on_change for tab to leave
|
||||
if self.tablist[self.last_tab_index].on_change ~= nil then
|
||||
self.tablist[self.last_tab_index].on_change("LEAVE",
|
||||
self.current_tab, self.tablist[index].name, self)
|
||||
end
|
||||
|
||||
--update tabview data
|
||||
self.last_tab_index = index
|
||||
local old_tab = self.current_tab
|
||||
self.current_tab = self.tablist[index].name
|
||||
|
||||
if (self.autosave_tab) then
|
||||
core.setting_set(self.name .. "_LAST",self.current_tab)
|
||||
end
|
||||
|
||||
-- call for tab to enter
|
||||
if self.tablist[index].on_change ~= nil then
|
||||
self.tablist[index].on_change("ENTER",
|
||||
old_tab,self.current_tab, self)
|
||||
end
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
local function handle_tab_buttons(self,fields)
|
||||
--save tab selection to config file
|
||||
if fields[self.name] then
|
||||
local index = tonumber(fields[self.name])
|
||||
switch_to_tab(self, index)
|
||||
return true
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
local function set_tab_by_name(self, name)
|
||||
for i=1,#self.tablist,1 do
|
||||
if self.tablist[i].name == name then
|
||||
switch_to_tab(self, i)
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
local function hide_tabview(self)
|
||||
self.hidden=true
|
||||
|
||||
-- if we don't have a current tab don't try to call on_change
|
||||
if not self.tablist[self.last_tab_index] then
|
||||
return
|
||||
end
|
||||
|
||||
-- call on_change as we're not gonna show self tab any longer
|
||||
if self.tablist[self.last_tab_index].on_change ~= nil then
|
||||
self.tablist[self.last_tab_index].on_change("LEAVE",
|
||||
self.current_tab, nil, self)
|
||||
end
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
local function show_tabview(self)
|
||||
self.hidden=false
|
||||
|
||||
-- call for tab to enter
|
||||
if self.tablist[self.last_tab_index].on_change ~= nil then
|
||||
self.tablist[self.last_tab_index].on_change("ENTER",
|
||||
nil,self.current_tab, self)
|
||||
end
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
local function delete(self)
|
||||
if self.parent_ui ~= nil then
|
||||
self.parent_ui:delete(self)
|
||||
end
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
local function get_tabdata(self, name)
|
||||
assert(self ~= nil)
|
||||
|
||||
for i=1, #self.tablist, 1 do
|
||||
if self.tablist[self.last_tab_index].name == name then
|
||||
return self.tablist[self.last_tab_index].tabdata
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
local function set_parent(self, parent)
|
||||
if parent == nil then
|
||||
self.type = "toplevel"
|
||||
else
|
||||
self.type = "addon"
|
||||
end
|
||||
|
||||
self.parent = parent
|
||||
end
|
||||
|
||||
local tabview_metatable = {
|
||||
add = add_tab,
|
||||
handle_buttons = handle_buttons,
|
||||
handle_events = handle_events,
|
||||
get_formspec = get_formspec,
|
||||
show = show_tabview,
|
||||
hide = hide_tabview,
|
||||
delete = delete,
|
||||
set_parent = set_parent,
|
||||
set_autosave_tab =
|
||||
function(self,value) self.autosave_tab = value end,
|
||||
set_tab = set_tab_by_name,
|
||||
get_tabdata = get_tabdata,
|
||||
set_global_button_handler =
|
||||
function(self,handler) self.glb_btn_handler = handler end,
|
||||
set_global_event_handler =
|
||||
function(self,handler) self.glb_evt_handler = handler end,
|
||||
set_fixed_size =
|
||||
function(self,state) self.fixed_size = state end,
|
||||
tab_header = tab_header,
|
||||
handle_tab_buttons = handle_tab_buttons
|
||||
}
|
||||
|
||||
tabview_metatable.__index = tabview_metatable
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
function tabview_create(name, size, tabheaderpos, parent_ui)
|
||||
local self = {}
|
||||
|
||||
self.name = name
|
||||
self.type = "toplevel"
|
||||
self.width = size.x
|
||||
self.height = size.y
|
||||
self.header_x = tabheaderpos.x
|
||||
self.header_y = tabheaderpos.y
|
||||
|
||||
setmetatable(self, tabview_metatable)
|
||||
|
||||
self.fixed_size = true
|
||||
self.hidden = true
|
||||
self.current_tab = nil
|
||||
self.last_tab_index = 1
|
||||
self.tablist = {}
|
||||
self.parent_ui = parent_ui
|
||||
|
||||
self.autosave_tab = false
|
||||
|
||||
if parent_ui ~= nil then
|
||||
parent_ui:add(self)
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
203
mods/mob_engines/mobf_settings/fstk/ui_mod.lua
Normal file
203
mods/mob_engines/mobf_settings/fstk/ui_mod.lua
Normal file
@ -0,0 +1,203 @@
|
||||
--Minetest
|
||||
--Copyright (C) 2014 sapier
|
||||
--
|
||||
--self program is free software; you can redistribute it and/or modify
|
||||
--it under the terms of the GNU Lesser General Public License as published by
|
||||
--the Free Software Foundation; either version 2.1 of the License, or
|
||||
--(at your option) any later version.
|
||||
--
|
||||
--self program is distributed in the hope that it will be useful,
|
||||
--but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
--MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
--GNU Lesser General Public License for more details.
|
||||
--
|
||||
--You should have received a copy of the GNU Lesser General Public License along
|
||||
--with self program; if not, write to the Free Software Foundation, Inc.,
|
||||
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
|
||||
local ui_registry = {}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
local function add(self, child)
|
||||
assert(child ~= nil)
|
||||
|
||||
if (self.childlist[child.name] ~= nil) then
|
||||
return false
|
||||
end
|
||||
self.childlist[child.name] = child
|
||||
|
||||
return child.name
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
local function delete(self, child)
|
||||
if self.childlist[child.name] == nil then
|
||||
return false
|
||||
end
|
||||
|
||||
self.childlist[child.name] = nil
|
||||
return true
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
local function set_default(self, name)
|
||||
self.default = name
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
local function find_by_name(self, name)
|
||||
return self.childlist[name]
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
local function hide(self)
|
||||
for key,value in pairs(self.childlist) do
|
||||
if type(value.hide) == "function" then
|
||||
value:hide()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
local function update(self)
|
||||
local formspec = ""
|
||||
local active_toplevel_ui_elements = 0
|
||||
|
||||
for key,value in pairs(self.childlist) do
|
||||
if (value.type == "toplevel") then
|
||||
local retval = value:get_formspec()
|
||||
|
||||
if retval ~= nil and retval ~= "" then
|
||||
active_toplevel_ui_elements = active_toplevel_ui_elements +1
|
||||
formspec = formspec .. retval
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- no need to show addons if there ain't a toplevel element
|
||||
if (active_toplevel_ui_elements > 0) then
|
||||
for key,value in pairs(self.childlist) do
|
||||
if (value.type == "addon") then
|
||||
local retval = value:get_formspec()
|
||||
|
||||
if retval ~= nil and retval ~= "" then
|
||||
formspec = formspec .. retval
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if (active_toplevel_ui_elements == 0) then
|
||||
core.log("WARNING: not a single toplevel ui element active switching " ..
|
||||
"to default")
|
||||
self.childlist[self.default]:show()
|
||||
formspec = self.childlist[self.default]:get_formspec()
|
||||
end
|
||||
|
||||
core.show_formspec(self.playername, self.formname, formspec)
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
local ui_metatable = {
|
||||
add = add,
|
||||
delete = delete,
|
||||
set_default = set_default,
|
||||
find_by_name = find_by_name,
|
||||
hide = hide,
|
||||
update = update
|
||||
}
|
||||
|
||||
ui_metatable.__index = ui_metatable
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
function create_ui(playername, unique_id)
|
||||
|
||||
if (ui_registry[playername] == nil) then
|
||||
ui_registry[playername] = {}
|
||||
end
|
||||
|
||||
if ui_registry[playername][unique_id] ~= nil then
|
||||
return nil
|
||||
end
|
||||
|
||||
local self = {}
|
||||
|
||||
setmetatable(self, ui_metatable)
|
||||
|
||||
ui_registry[playername][unique_id] = self
|
||||
|
||||
self.childlist = {}
|
||||
self.default = nil
|
||||
self.formname = unique_id
|
||||
self.playername = playername
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
function get_ui_by_unique_id(playername, unique_id)
|
||||
|
||||
if (ui_registry[playername] == nil) then
|
||||
return nil
|
||||
end
|
||||
|
||||
return ui_registry[playername][unique_id]
|
||||
end
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
--------------------------------------------------------------------------------
|
||||
-- Internal functions not to be called from user
|
||||
--------------------------------------------------------------------------------
|
||||
--------------------------------------------------------------------------------
|
||||
--------------------------------------------------------------------------------
|
||||
local function handle_buttons(player, formname, fields)
|
||||
|
||||
if not player:is_player() then
|
||||
return
|
||||
end
|
||||
|
||||
local playername = player:get_player_name()
|
||||
|
||||
if playername == nil or
|
||||
ui_registry[playername] == nil then
|
||||
return
|
||||
end
|
||||
|
||||
if ui_registry[playername][formname] == nil then
|
||||
return
|
||||
end
|
||||
|
||||
for key,value in pairs(ui_registry[playername][formname].childlist) do
|
||||
|
||||
local retval = value:handle_buttons(fields)
|
||||
|
||||
if retval then
|
||||
ui_registry[playername][formname]:update()
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
local function player_leave(player)
|
||||
|
||||
if not player:is_player() then
|
||||
return
|
||||
end
|
||||
|
||||
local playername = player:get_player_name()
|
||||
|
||||
if playername == nil then
|
||||
return
|
||||
end
|
||||
|
||||
ui_registry[playername] = nil
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
minetest.register_on_player_receive_fields(handle_buttons)
|
||||
minetest.register_on_leaveplayer(player_leave)
|
24
mods/mob_engines/mobf_settings/init.lua
Normal file
24
mods/mob_engines/mobf_settings/init.lua
Normal file
@ -0,0 +1,24 @@
|
||||
-------------------------------------------------------------------------------
|
||||
-- Mob Framework Settings Mod by Sapier
|
||||
--
|
||||
-- You may copy, use, modify or do nearly anything except removing this
|
||||
-- copyright notice.
|
||||
-- And of course you are NOT allowed to pretend you have written it.
|
||||
--
|
||||
--! @file init.lua
|
||||
--! @brief settings gui for mobf
|
||||
--! @copyright Sapier
|
||||
--! @author Sapier
|
||||
--! @date 2014-05-30
|
||||
--
|
||||
-- Contact sapier a t gmx net
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
function fgettext(text)
|
||||
return text
|
||||
end
|
||||
|
||||
--!path of mod
|
||||
local modpath = minetest.get_modpath("mobf_settings")
|
||||
dofile (modpath .. DIR_DELIM .. "settings.lua")
|
||||
|
113
mods/mob_engines/mobf_settings/settings.lua
Normal file
113
mods/mob_engines/mobf_settings/settings.lua
Normal file
@ -0,0 +1,113 @@
|
||||
--------------------------------------------------------------------------------
|
||||
-- Mob Framework Settings Mod by Sapier
|
||||
--
|
||||
-- You may copy, use, modify or do nearly anything except removing this
|
||||
-- copyright notice.
|
||||
-- And of course you are NOT allowed to pretend you have written it.
|
||||
--
|
||||
--! @file settings_v3.lua
|
||||
--! @brief settings gui for mobf
|
||||
--! @copyright Sapier
|
||||
--! @author Sapier
|
||||
--! @date 2014-05-30
|
||||
--
|
||||
-- Contact sapier a t gmx net
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
--!version
|
||||
local mobf_settings_version = "1.9.0"
|
||||
|
||||
--!path of mod
|
||||
local modpath = minetest.get_modpath("mobf_settings")
|
||||
|
||||
--!basepath of tools
|
||||
--TODO remove included fstk once minetest is updated
|
||||
--local basepath = core.get_builtin_path()
|
||||
local basepath = modpath
|
||||
|
||||
--!unique id of ui
|
||||
local unique_id = "mobf_settings"
|
||||
|
||||
dofile(basepath .. DIR_DELIM .. "fstk" .. DIR_DELIM .. "dialog.lua")
|
||||
dofile(basepath .. DIR_DELIM .. "fstk" .. DIR_DELIM .. "tabview.lua")
|
||||
dofile(basepath .. DIR_DELIM .. "fstk" .. DIR_DELIM .. "ui_mod.lua")
|
||||
|
||||
dofile(modpath .. DIR_DELIM .. "common.lua")
|
||||
dofile(modpath .. DIR_DELIM .. "tab_main.lua")
|
||||
dofile(modpath .. DIR_DELIM .. "tab_info.lua")
|
||||
dofile(modpath .. DIR_DELIM .. "tab_feature_config.lua")
|
||||
dofile(modpath .. DIR_DELIM .. "tab_factions.lua")
|
||||
dofile(modpath .. DIR_DELIM .. "tab_mobs.lua")
|
||||
dofile(modpath .. DIR_DELIM .. "tab_restore_mobs.lua")
|
||||
dofile(modpath .. DIR_DELIM .. "tab_path_manager.lua")
|
||||
|
||||
|
||||
local function is_admin(playername)
|
||||
local privcheck = core.check_player_privs(playername, {mobfw_admin=true})
|
||||
|
||||
return privcheck or (playername == "singleplayer")
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
local function init_player_ui(playername, param)
|
||||
|
||||
local playerui = get_ui_by_unique_id(playername, unique_id)
|
||||
|
||||
if not playerui then
|
||||
playerui = create_ui(playername, unique_id)
|
||||
|
||||
assert( playerui ~= nil)
|
||||
|
||||
local tv_main = tabview_create("mainview",{x=8,y=9},{x=0,y=0}, playerui)
|
||||
|
||||
tv_main:add(mobf_settings_tab_main)
|
||||
|
||||
if is_admin(playername) then
|
||||
tv_main:add(mobf_settings_tab_features, { is_admin=is_admin(playername) })
|
||||
tv_main:add(mobf_settings_tab_mobs, { is_admin=is_admin(playername) })
|
||||
end
|
||||
|
||||
tv_main:add(mobf_settings_tab_info)
|
||||
|
||||
if mobf_rtd.factions_available then
|
||||
tv_main:add(mobf_settings_tab_factions,
|
||||
{
|
||||
is_admin = is_admin(playername),
|
||||
playername = playername
|
||||
})
|
||||
end
|
||||
|
||||
tv_main:add(mobf_settings_tab_preserve,
|
||||
{
|
||||
is_admin = is_admin(playername),
|
||||
playername = playername
|
||||
})
|
||||
|
||||
tv_main:add(mobf_settings_tab_paths,
|
||||
{
|
||||
is_admin = is_admin(playername),
|
||||
playername = playername
|
||||
})
|
||||
end
|
||||
|
||||
playerui:hide()
|
||||
|
||||
local main_tab = playerui:find_by_name("mainview")
|
||||
|
||||
if not main_tab then
|
||||
return
|
||||
end
|
||||
|
||||
main_tab:show()
|
||||
playerui:update()
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
minetest.register_chatcommand("mobf",
|
||||
{
|
||||
params = "",
|
||||
description = "show mobf settings" ,
|
||||
privs = {},
|
||||
func = init_player_ui
|
||||
})
|
||||
minetest.log("action","MOD: mobf_settings mod version "..mobf_settings_version.." loaded")
|
237
mods/mob_engines/mobf_settings/tab_factions.lua
Normal file
237
mods/mob_engines/mobf_settings/tab_factions.lua
Normal file
@ -0,0 +1,237 @@
|
||||
--------------------------------------------------------------------------------
|
||||
-- Mob Framework Settings Mod by Sapier
|
||||
--
|
||||
-- You may copy, use, modify or do nearly anything except removing this
|
||||
-- copyright notice.
|
||||
-- And of course you are NOT allowed to pretend you have written it.
|
||||
--
|
||||
--! @file tab_feature_config.lua
|
||||
--! @brief settings gui for mobf
|
||||
--! @copyright Sapier
|
||||
--! @author Sapier
|
||||
--! @date 2014-05-30
|
||||
--
|
||||
-- Contact sapier a t gmx net
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
local function get_formspec(tabview, name, tabdata)
|
||||
|
||||
if not tabdata.is_admin then
|
||||
return "label[0.75,0.25;" ..
|
||||
fgettext("Insufficient permissions to view this tab.")
|
||||
.. "]"
|
||||
end
|
||||
|
||||
if tabdata.available_factions_selected == nil then
|
||||
tabdata.available_factions_selected = 0
|
||||
end
|
||||
|
||||
if tabdata.faction_reputation_selected == nil then
|
||||
tabdata.faction_reputation_selected = 0
|
||||
end
|
||||
|
||||
local retval = ""
|
||||
retval = retval ..
|
||||
"label[0.25,-0.25;Available factions:]" ..
|
||||
"textlist[0.25,0.25;3.5,7.5;tl_factions_available_factions;"
|
||||
|
||||
local factionlist = factions.get_faction_list()
|
||||
|
||||
local first_element = true
|
||||
if #factionlist ~= 0 then
|
||||
for i=1,#factionlist,1 do
|
||||
if not first_element then
|
||||
retval = retval .. ","
|
||||
else
|
||||
first_element = false
|
||||
end
|
||||
retval = retval .. factionlist[i]
|
||||
end
|
||||
else
|
||||
retval = retval .. "no factions available"
|
||||
end
|
||||
|
||||
retval = retval .. ";" .. tabdata.available_factions_selected .. "]"
|
||||
|
||||
if tabdata.is_admin then
|
||||
retval = retval ..
|
||||
"button[0.25,8;3.75,0.5;btn_factions_delete;Delete]" ..
|
||||
"field[4.3,0.75;4,0.5;te_factionname;New Faction;]" ..
|
||||
"button[4,1.25;4,0.25;btn_factions_create;Create]"
|
||||
end
|
||||
|
||||
if core.check_player_privs(tabdata.playername, {faction_admin=true}) or
|
||||
core.check_player_privs(tabdata.playername, {faction_user=true})
|
||||
or tabdata.playername == "singleplayer" then
|
||||
retval = retval ..
|
||||
"field[4.3,2.75;4,0.5;te_inviteename;Playername:;]" ..
|
||||
"button[4,3.25;4,0.25;btn_factions_invite;Invite]"
|
||||
end
|
||||
|
||||
|
||||
local selected_rep = ""
|
||||
retval = retval ..
|
||||
"label[4,3.75;Base reputation:]" ..
|
||||
"textlist[4,4.25;3.75,3.5;tl_factions_faction_reputation;"
|
||||
|
||||
if tabdata.available_factions_selected > 0 and
|
||||
tabdata.available_factions_selected <= #factionlist then
|
||||
local first_rep = true
|
||||
for i=1,#factionlist,1 do
|
||||
local current_rep = factions.get_base_reputation(
|
||||
factionlist[i],
|
||||
factionlist[tabdata.available_factions_selected])
|
||||
|
||||
if not first_rep then
|
||||
retval = retval .. ","
|
||||
else
|
||||
first_rep = false
|
||||
end
|
||||
if tonumber(current_rep) > 0 then
|
||||
retval = retval .. COLOR_GREEN
|
||||
elseif tonumber(current_rep) < 0 then
|
||||
retval = retval .. COLOR_RED
|
||||
end
|
||||
retval = retval .. "(" .. current_rep .. ") " .. factionlist[i]
|
||||
end
|
||||
|
||||
if tabdata.faction_reputation_selected > 0 and
|
||||
tabdata.faction_reputation_selected <= #factionlist then
|
||||
selected_rep = factions.get_base_reputation(
|
||||
factionlist[tabdata.faction_reputation_selected],
|
||||
factionlist[tabdata.available_factions_selected])
|
||||
end
|
||||
end
|
||||
|
||||
retval = retval ..
|
||||
";" .. tabdata.faction_reputation_selected .."]" ..
|
||||
"label[4,7.9;New Baserep:]" ..
|
||||
"field[6.2,8.3;1.1,0.5;te_baserep;;" .. selected_rep .."]" ..
|
||||
"button[6.9,8;1,0.5;btn_factions_set_reputation;set]"
|
||||
|
||||
if tabdata.errormessage then
|
||||
retval = retval ..
|
||||
"label[0.25,8.5;" .. tabdata.errormessage .. "]"
|
||||
end
|
||||
|
||||
return retval
|
||||
end
|
||||
|
||||
local function handle_settings_buttons(self, fields, tabname, tabdata)
|
||||
|
||||
if not tabdata.is_admin then
|
||||
core.log("error", "MOBF_Settings: someone managed to press a button " ..
|
||||
"she/he shouldn't even see!")
|
||||
end
|
||||
|
||||
if fields["btn_factions_delete"] then
|
||||
tabdata.errormessage = "delete faction is not implemented yet"
|
||||
return true
|
||||
end
|
||||
|
||||
if fields["btn_factions_create"] then
|
||||
if fields["te_factionname"] ~= nil then
|
||||
if fields["te_factionname"] == "" then
|
||||
tabdata.errormessage ="Refusing to create faction with no name!"
|
||||
elseif not factions.exists(fields["te_factionname"]) then
|
||||
if not factions.add_faction(fields["te_factionname"]) then
|
||||
tabdata.errormessage = "Failed to add faction \""
|
||||
.. fields["te_factionname"] .. "\""
|
||||
else
|
||||
local player = minetest.get_player_by_name(tabdata.playername)
|
||||
if not player or not factions.member_add(
|
||||
fields["te_factionname"], player) then
|
||||
tabdata.errormessage = "Unable to add creator to faction!"
|
||||
elseif not factions.set_admin(
|
||||
fields["te_factionname"],
|
||||
tabdata.playername, true) then
|
||||
tabdata.errormessage = "Unable to give admin privileges to creator!"
|
||||
end
|
||||
end
|
||||
else
|
||||
tabdata.errormessage = "Faction \""
|
||||
.. sender_data.fields["te_factionname"] .. "\" already exists"
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
if fields["btn_factions_invite"] then
|
||||
--get faction from faction list
|
||||
local factionlist = factions.get_faction_list()
|
||||
if tabdata.available_factions_selected > 0 and
|
||||
tabdata.available_factions_selected < #factionlist then
|
||||
|
||||
local faction_to_invite = factionlist[tabdata.available_factions_selected]
|
||||
|
||||
--check if player is in faction he wants to invite for
|
||||
--TODO privs check
|
||||
if factions.is_admin(faction_to_invite, tabdata.playername) or
|
||||
factions.is_free(faction_to_invite) then
|
||||
if fields["te_inviteename"] ~= nil and
|
||||
fields["te_inviteename"] ~= "" then
|
||||
factions.member_invite(faction_to_invite,fields["te_inviteename"])
|
||||
else
|
||||
tabdata.errormessage = "You can't invite nobody!"
|
||||
end
|
||||
else
|
||||
tabdata.errormessage = "Not allowed to invite for faction " .. faction_to_invite
|
||||
end
|
||||
else
|
||||
tabdata.errormessage = "No faction selected to invite to"
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
if fields["btn_factions_set_reputation"] then
|
||||
if tabdata.available_factions_selected ==
|
||||
tabdata.faction_reputation_selected then
|
||||
tabdata.errormessage = "Can't set base reputation of faction to itself!"
|
||||
else
|
||||
local factionlist = factions.get_faction_list()
|
||||
local faction1 = factionlist[tabdata.available_factions_selected]
|
||||
local faction2 = factionlist[tabdata.faction_reputation_selected]
|
||||
|
||||
if faction1 ~= nil and faction2 ~= nil and
|
||||
fields["te_baserep"] ~= nil and
|
||||
fields["te_baserep"] ~= "" then
|
||||
if not factions.set_base_reputation(faction1, faction2,
|
||||
fields["te_baserep"]) then
|
||||
tabdata.errormessage = "Failed to set base reputation"
|
||||
end
|
||||
else
|
||||
tabdata.errormessage = "Only one faction selected or no value given!"
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
if fields["tl_factions_available_factions"] then
|
||||
local event = core.explode_textlist_event(
|
||||
fields["tl_factions_available_factions"])
|
||||
|
||||
if event.typ ~= "INV" then
|
||||
tabdata.available_factions_selected = event.index
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
if fields["tl_factions_faction_reputation"] then
|
||||
local event = core.explode_textlist_event(
|
||||
fields["tl_factions_faction_reputation"])
|
||||
|
||||
if event.typ ~= "INV" then
|
||||
tabdata.faction_reputation_selected = event.index
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
mobf_settings_tab_factions = {
|
||||
name = "factions",
|
||||
caption = fgettext("Factions"),
|
||||
cbf_formspec = get_formspec,
|
||||
cbf_button_handler = handle_settings_buttons
|
||||
}
|
216
mods/mob_engines/mobf_settings/tab_feature_config.lua
Normal file
216
mods/mob_engines/mobf_settings/tab_feature_config.lua
Normal file
@ -0,0 +1,216 @@
|
||||
--------------------------------------------------------------------------------
|
||||
-- Mob Framework Settings Mod by Sapier
|
||||
--
|
||||
-- You may copy, use, modify or do nearly anything except removing this
|
||||
-- copyright notice.
|
||||
-- And of course you are NOT allowed to pretend you have written it.
|
||||
--
|
||||
--! @file tab_feature_config.lua
|
||||
--! @brief settings gui for mobf
|
||||
--! @copyright Sapier
|
||||
--! @author Sapier
|
||||
--! @date 2014-05-30
|
||||
--
|
||||
-- Contact sapier a t gmx net
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
local function get_formspec(tabview, name, tabdata)
|
||||
|
||||
if not tabdata.is_admin then
|
||||
return "label[0.75,0.25;" ..
|
||||
fgettext("Insufficient permissions to view this tab.")
|
||||
.. "]"
|
||||
end
|
||||
|
||||
local retval = ""
|
||||
local ypos = 0.5
|
||||
|
||||
retval = retval .. "checkbox[1," .. ypos .. ";" ..
|
||||
"cb_features_disable_animal_spawning;" ..
|
||||
"Disable mob spawning;" ..
|
||||
mobf_settings.setting_gettext("mobf_disable_animal_spawning") .."]"
|
||||
ypos = ypos + 0.5
|
||||
|
||||
retval = retval .. "checkbox[1," .. ypos .. ";" ..
|
||||
"cb_features_disable_3d_mode;" ..
|
||||
"Disable 3D mobs;" ..
|
||||
mobf_settings.setting_gettext("mobf_disable_3d_mode") .."]"
|
||||
ypos = ypos + 0.5
|
||||
|
||||
retval = retval .. "checkbox[1," .. ypos .. ";" ..
|
||||
"cb_features_animal_spawning_secondary;" ..
|
||||
"Enable secondary spawning;" ..
|
||||
mobf_settings.setting_gettext("mobf_animal_spawning_secondary") .."]"
|
||||
ypos = ypos + 0.5
|
||||
|
||||
retval = retval .. "checkbox[1," .. ypos .. ";" ..
|
||||
"cb_features_delete_disabled_mobs;" ..
|
||||
"Delete disabled mobs+spawners;" ..
|
||||
mobf_settings.setting_gettext("mobf_delete_disabled_mobs") .."]"
|
||||
ypos = ypos + 0.5
|
||||
|
||||
retval = retval .. "checkbox[1," .. ypos .. ";" ..
|
||||
"cb_features_log_bug_warnings;" ..
|
||||
"Log MOBF bug warnings;" ..
|
||||
mobf_settings.setting_gettext("mobf_log_bug_warnings") .."]"
|
||||
ypos = ypos + 0.5
|
||||
|
||||
retval = retval .. "checkbox[1," .. ypos .. ";" ..
|
||||
"cb_features_vombie_3d_burn_animation_enabled;" ..
|
||||
"Vombie 3D burn animation;" ..
|
||||
mobf_settings.setting_gettext("vombie_3d_burn_animation_enabled") .."]"
|
||||
ypos = ypos + 0.5
|
||||
|
||||
retval = retval .. "checkbox[1," .. ypos .. ";" ..
|
||||
"cb_features_log_removed_entities;" ..
|
||||
"Log all removed mobs;" ..
|
||||
mobf_settings.setting_gettext("mobf_log_removed_entities") .."]"
|
||||
ypos = ypos + 0.5
|
||||
|
||||
retval = retval .. "checkbox[1," .. ypos .. ";" ..
|
||||
"cb_features_grief_protection;" ..
|
||||
"Enable grief protection;" ..
|
||||
mobf_settings.setting_gettext("mobf_grief_protection") .."]"
|
||||
ypos = ypos + 0.5
|
||||
|
||||
retval = retval .. "checkbox[1," .. ypos .. ";" ..
|
||||
"cb_features_lifebar;" ..
|
||||
"Show mob lifebar;" ..
|
||||
mobf_settings.setting_gettext("mobf_lifebar") .."]"
|
||||
ypos = ypos + 0.5
|
||||
|
||||
retval = retval .. "checkbox[1," .. ypos .. ";" ..
|
||||
"cb_features_enable_statistics;" ..
|
||||
"Enable statistics;" ..
|
||||
mobf_settings.setting_gettext("mobf_enable_statistics") .."]"
|
||||
ypos = ypos + 0.5
|
||||
|
||||
retval = retval .. "checkbox[1," .. ypos .. ";" ..
|
||||
"cb_features_disable_pathfinding;" ..
|
||||
"Disable core pathfinding support;" ..
|
||||
mobf_settings.setting_gettext("mobf_disable_pathfinding") .."]"
|
||||
ypos = ypos + 0.5
|
||||
|
||||
local showspawner = core.setting_get("adv_spawning.debug")
|
||||
local spawner_setting_text = "false"
|
||||
if (showspawner) then
|
||||
spawner_setting_text = "true"
|
||||
end
|
||||
|
||||
retval = retval .. "checkbox[1," .. ypos .. ";" ..
|
||||
"cb_features_show_spawners;" ..
|
||||
"Show spawner entities;" .. spawner_setting_text .."]"
|
||||
ypos = ypos + 0.5
|
||||
|
||||
retval = retval .. "checkbox[1," .. ypos .. ";" ..
|
||||
"cb_adv_spawning_refresh_spawners;" ..
|
||||
"Refresh spawners (spawn mobs in old maps);" ..
|
||||
(core.setting_get("adv_spawning_validate_spawners") or "false") .."]"
|
||||
ypos = ypos + 0.5
|
||||
|
||||
|
||||
|
||||
return retval
|
||||
end
|
||||
|
||||
local function handle_settings_buttons(self, fields, tabname, tabdata)
|
||||
|
||||
if not tabdata.is_admin then
|
||||
core.log("error", "MOBF_Settings: someone managed to press a button " ..
|
||||
"she/he shouldn't even see!")
|
||||
return false
|
||||
end
|
||||
|
||||
if fields["cb_features_disable_animal_spawning"] then
|
||||
mobf_set_world_setting("mobf_disable_animal_spawning",
|
||||
core.is_yes(fields["cb_features_disable_animal_spawning"]))
|
||||
return true
|
||||
end
|
||||
|
||||
if fields["cb_features_disable_3d_mode"] then
|
||||
mobf_set_world_setting("mobf_disable_3d_mode",
|
||||
core.is_yes(fields["cb_features_disable_3d_mode"]))
|
||||
return true
|
||||
end
|
||||
|
||||
if fields["cb_features_animal_spawning_secondary"] then
|
||||
mobf_set_world_setting("mobf_animal_spawning_secondary",
|
||||
core.is_yes(fields["cb_features_animal_spawning_secondary"]))
|
||||
return true
|
||||
end
|
||||
|
||||
if fields["cb_features_delete_disabled_mobs"] then
|
||||
mobf_set_world_setting("mobf_delete_disabled_mobs",
|
||||
core.is_yes(fields["cb_features_delete_disabled_mobs"]))
|
||||
return true
|
||||
end
|
||||
|
||||
if fields["cb_features_log_bug_warnings"] then
|
||||
mobf_set_world_setting("mobf_log_bug_warnings",
|
||||
core.is_yes(fields["cb_features_log_bug_warnings"]))
|
||||
return true
|
||||
end
|
||||
|
||||
if fields["cb_features_vombie_3d_burn_animation_enabled"] then
|
||||
mobf_set_world_setting("vombie_3d_burn_animation_enabled",
|
||||
core.is_yes(fields["cb_features_vombie_3d_burn_animation_enabled"]))
|
||||
return true
|
||||
end
|
||||
|
||||
if fields["cb_features_log_removed_entities"] then
|
||||
mobf_set_world_setting("mobf_log_removed_entities",
|
||||
core.is_yes(fields["cb_features_log_removed_entities"]))
|
||||
return true
|
||||
end
|
||||
|
||||
if fields["cb_features_grief_protection"] then
|
||||
mobf_set_world_setting("mobf_grief_protection",
|
||||
core.is_yes(fields["cb_features_grief_protection"]))
|
||||
return true
|
||||
end
|
||||
|
||||
if fields["cb_features_lifebar"] then
|
||||
mobf_set_world_setting("mobf_lifebar",
|
||||
core.is_yes(fields["cb_features_lifebar"]))
|
||||
return true
|
||||
end
|
||||
|
||||
if fields["cb_features_enable_statistics"] then
|
||||
mobf_set_world_setting("mobf_enable_statistics",
|
||||
core.is_yes(fields["cb_features_enable_statistics"]))
|
||||
return true
|
||||
end
|
||||
|
||||
if fields["cb_features_delayed_spawning"] then
|
||||
mobf_set_world_setting("mobf_delayed_spawning",
|
||||
core.is_yes(fields["cb_features_delayed_spawning"]))
|
||||
return true
|
||||
end
|
||||
|
||||
if fields["cb_features_disable_pathfinding"] then
|
||||
mobf_set_world_setting("mobf_disable_pathfinding",
|
||||
core.is_yes(fields["cb_features_disable_pathfinding"]))
|
||||
return true
|
||||
end
|
||||
|
||||
if fields["cb_features_show_spawners"] then
|
||||
core.setting_set("adv_spawning.debug",
|
||||
fields["cb_features_show_spawners"])
|
||||
return true
|
||||
end
|
||||
|
||||
if fields["cb_adv_spawning_refresh_spawners"] then
|
||||
core.setting_set("adv_spawning_validate_spawners",
|
||||
fields["cb_adv_spawning_refresh_spawners"])
|
||||
return true
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
mobf_settings_tab_features = {
|
||||
name = "features",
|
||||
caption = fgettext("Features"),
|
||||
cbf_formspec = get_formspec,
|
||||
cbf_button_handler = handle_settings_buttons
|
||||
}
|
147
mods/mob_engines/mobf_settings/tab_info.lua
Normal file
147
mods/mob_engines/mobf_settings/tab_info.lua
Normal file
@ -0,0 +1,147 @@
|
||||
--------------------------------------------------------------------------------
|
||||
-- Mob Framework Settings Mod by Sapier
|
||||
--
|
||||
-- You may copy, use, modify or do nearly anything except removing this
|
||||
-- copyright notice.
|
||||
-- And of course you are NOT allowed to pretend you have written it.
|
||||
--
|
||||
--! @file tab_info.lua
|
||||
--! @brief settings gui for mobf
|
||||
--! @copyright Sapier
|
||||
--! @author Sapier
|
||||
--! @date 2014-05-30
|
||||
--
|
||||
-- Contact sapier a t gmx net
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
local function get_formspec(tabview, name, tabdata)
|
||||
|
||||
local adv_stats = nil
|
||||
if mobf_rtd.have_adv_spawning then
|
||||
adv_stats = adv_spawning.get_statistics()
|
||||
end
|
||||
local mobs_offline = spawning.total_offline_mobs()
|
||||
local statistics = mobf_get_statistics()
|
||||
|
||||
local retval =
|
||||
"label[0.75,1.25;Timesource:]" ..
|
||||
"label[2.75,1.25;" .. mobf_fixed_size_string(mobf_rtd.timesource,30) .. "]"
|
||||
|
||||
|
||||
if mobf_rtd.have_adv_spawning then
|
||||
retval = retval ..
|
||||
"label[0.75,2.25;Mobs spawned by adv_spawning this session:]" ..
|
||||
"label[6,2.25;" .. string.format("%10d",adv_stats.session.entities_created) .. "]"
|
||||
end
|
||||
retval = retval ..
|
||||
mobf_settings.printfac("Type",{current="cur count",maxabs="",max="max count"},3,"%s") ..
|
||||
"box[0.75,3.5;6.75,0.05;#FFFFFF]" ..
|
||||
mobf_settings.printfac("Active mobs",statistics.data.mobs,3.5,"%6d") ..
|
||||
mobf_settings.printfac("Offline mobs",{current=mobs_offline,maxabs="",max=-1},4,"%6d") ..
|
||||
mobf_settings.printfac("Jobs in queue",statistics.data.queue,4.5,"%6d") ..
|
||||
"label[0.75,6.0;Daytime:]" ..
|
||||
"label[2.5,6.0;" .. string.format("%5d",minetest.get_timeofday()*24000) .. "]"
|
||||
|
||||
return retval
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
mobf_settings_tab_info_sub = {
|
||||
name = "info",
|
||||
caption = fgettext("Generic"),
|
||||
cbf_formspec = get_formspec
|
||||
}
|
||||
|
||||
---------------------------------------------------------------------------------
|
||||
local function get_formspec(tabview, name, tabdata)
|
||||
local adv_stats = nil
|
||||
if mobf_rtd.have_adv_spawning then
|
||||
adv_stats = adv_spawning.get_statistics()
|
||||
end
|
||||
local statistics = mobf_get_statistics()
|
||||
|
||||
local retval =
|
||||
mobf_settings.printfac("Facility",
|
||||
{
|
||||
current = "Current",
|
||||
maxabs = "Abs.Max (ms)",
|
||||
max = "Maximum"
|
||||
},
|
||||
"0.5","%s") ..
|
||||
"box[0.75,1;6.75,0.05;#FFFFFF]" ..
|
||||
mobf_settings.printfac("Total", statistics.data.total, "1", "%2.2f%%") ..
|
||||
mobf_settings.printfac("Onstep", statistics.data.onstep, "1.5", "%2.2f%%") ..
|
||||
mobf_settings.printfac("Job processing", statistics.data.queue_load, "2", "%2.2f%%") ..
|
||||
mobf_settings.printfac("ABM", statistics.data.abm, "2.5", "%.2f%%") ..
|
||||
mobf_settings.printfac("MapGen", statistics.data.mapgen, "3", "%2.2f%%") ..
|
||||
mobf_settings.printfac("Spawn onstep", statistics.data.spawn_onstep,"3.5", "%2.2f%%") ..
|
||||
mobf_settings.printfac("Activate", statistics.data.activate, "4", "%2.2f%%") ..
|
||||
mobf_settings.printfac("User 1", statistics.data.user_1, "7", "%2.2f%%") ..
|
||||
mobf_settings.printfac("User 2", statistics.data.user_2, "7.5", "%2.2f%%") ..
|
||||
mobf_settings.printfac("User 3", statistics.data.user_3, "8", "%2.2f%%")
|
||||
|
||||
if mobf_rtd.have_adv_spawning then
|
||||
retval = retval ..
|
||||
mobf_settings.printfac("Adv.Spawning",
|
||||
{
|
||||
current = adv_stats.load.cur,
|
||||
maxabs = adv_stats.step.max,
|
||||
max = adv_stats.load.max
|
||||
},
|
||||
"4.5","%2.2f%%")
|
||||
end
|
||||
|
||||
return retval
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
mobf_settings_tab_statistics = {
|
||||
name = "statistics",
|
||||
caption = fgettext("Statistics"),
|
||||
cbf_formspec = get_formspec
|
||||
}
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
local function init_tab(type, from, to, tabview)
|
||||
if (to == "info_top") then
|
||||
local tabdata = tabview:get_tabdata("info_top")
|
||||
assert(tabdata ~= nil)
|
||||
|
||||
if tabdata.subtabview == nil then
|
||||
tabdata.subtabview = tabview_create("infoview",
|
||||
{x=8,y=8},{x=0,y=0.75}, tabview.parent_ui)
|
||||
tabdata.subtabview:add(mobf_settings_tab_info_sub)
|
||||
if core.world_setting_get("mobf_enable_statistics") then
|
||||
tabdata.subtabview:add(mobf_settings_tab_statistics)
|
||||
end
|
||||
tabdata.subtabview:set_parent(tabview)
|
||||
end
|
||||
tabdata.subtabview:show()
|
||||
elseif (from == "info_top") then
|
||||
local tabdata = tabview:get_tabdata("info_top")
|
||||
assert(tabdata ~= nil)
|
||||
if tabdata.subtabview ~= nil then
|
||||
tabdata.subtabview:hide()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
local function get_formspec_tab(tabview, name, tabdata)
|
||||
return ""
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
local function btn_handler_tab(tabview, fields, tabname, tabdata)
|
||||
return false
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
mobf_settings_tab_info = {
|
||||
name = "info_top",
|
||||
caption = fgettext("Info"),
|
||||
cbf_button_handler = btn_handler_tab,
|
||||
cbf_formspec = get_formspec_tab,
|
||||
on_change = init_tab
|
||||
}
|
133
mods/mob_engines/mobf_settings/tab_main.lua
Normal file
133
mods/mob_engines/mobf_settings/tab_main.lua
Normal file
@ -0,0 +1,133 @@
|
||||
--------------------------------------------------------------------------------
|
||||
-- Mob Framework Settings Mod by Sapier
|
||||
--
|
||||
-- You may copy, use, modify or do nearly anything except removing this
|
||||
-- copyright notice.
|
||||
-- And of course you are NOT allowed to pretend you have written it.
|
||||
--
|
||||
--! @file tab_main.lua
|
||||
--! @brief settings gui for mobf
|
||||
--! @copyright Sapier
|
||||
--! @author Sapier
|
||||
--! @date 2014-05-30
|
||||
--
|
||||
-- Contact sapier a t gmx net
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
local function get_formspec_cheat_leftclick(tabview, name, tabdata)
|
||||
return
|
||||
"box[0.25,2.90;7.25,6.05;#000000]" ..
|
||||
"label[0.5,3.2;" .. fgettext("target: own mob,") .. "]" ..
|
||||
"label[3,3.2;" .. fgettext("wielditem: hand") .. "]" ..
|
||||
"label[0.75,3.5;" .. fgettext("-->rotate mob by 45°") .. "]" ..
|
||||
"label[0.5,4;" .. fgettext("target: own mob,") .. "]" ..
|
||||
"label[3,4;" .. fgettext("wielditem: various weapons") .. "]" ..
|
||||
"label[0.75,4.3;" .. fgettext("-->attack") .. "]" ..
|
||||
"label[0.5,4.8;" .. fgettext("target: any mob,") .. "]" ..
|
||||
"label[3,4.8;" .. fgettext("wielditem: catching (net/lasso/...)") .. "]" ..
|
||||
"label[0.75,5.1;" .. fgettext("-->catch") .."]" ..
|
||||
"label[0.5,5.6;" .. fgettext("target: (small) barn,") .. "]" ..
|
||||
"label[3,5.6;" .. fgettext("wielditem: grass/leaves") .. "]" ..
|
||||
"label[0.75,5.9;" .. fgettext("-->fill barn for breeding") .. "]" ..
|
||||
"label[0.5,6.4;" .. fgettext("target: (small) barn,") .. "]" ..
|
||||
"label[3,6.4;" .. fgettext("wielditem: hand/tool") .. "]" ..
|
||||
"label[0.75,6.7;" .. fgettext("-->take barn") .. "]" ..
|
||||
"label[0.5,7.2;" .. fgettext("target: mob,") .. "]" ..
|
||||
"label[3,7.2;" .. fgettext("wielditem: harvest-tool") .. "]" ..
|
||||
"label[0.75,7.5;" .. fgettext("-->harvest e.g. gather wool or milk") .. "]" ..
|
||||
"label[0.5,8;" .. fgettext("target: ridable mob,") .. "]" ..
|
||||
"label[3,8;" .. fgettext("wielditem: saddle (mob specific)") .. "]" ..
|
||||
"label[0.75,8.3;" .. fgettext("--> mount a mob to ride") .. "]"
|
||||
end
|
||||
|
||||
local function get_formspec_cheat_rightclick(tabview, name, tabdata)
|
||||
return
|
||||
"box[0.25,2.90;7.25,6.05;#000000]" ..
|
||||
"label[0.5,3.2;" .. fgettext("Rightclicking a mob opens a mob specific rightclick menu,") .. "]" ..
|
||||
"label[0.5,3.5;" .. fgettext("following menu elements are possible:") .. "]" ..
|
||||
"label[0.5,4;" .. fgettext("Show debuginfo") .. "]" ..
|
||||
"label[0.75,4.3;" .. fgettext("print debuginfo about this mob to console") .. "]" ..
|
||||
"label[0.5,4.8;" .. fgettext("Select path") .. "]" ..
|
||||
"label[0.75,5.1;" .. fgettext("Select a path to put mob in guard mode") .. "]" ..
|
||||
"label[0.5,5.6;" .. fgettext("Factions") .. "]" ..
|
||||
"label[0.75,5.9;" .. fgettext("configure factions for this mob") .. "]" ..
|
||||
"label[0.5,6.4;" .. fgettext("heal / nothing to heal(full health)") .. "]" ..
|
||||
"label[0.75,6.7;" .. fgettext("heal mob using the currently wielded food") .. "]" ..
|
||||
"label[0.5,7.2;" .. fgettext("Trade") .. "]" ..
|
||||
"label[0.75,7.5;" .. fgettext("open trade inventory") .. "]"
|
||||
end
|
||||
|
||||
local function get_formspec_cheat_mixed(tabview, name, tabdata)
|
||||
|
||||
return "box[0.25,2.90;7.25,6.05;#000000]" ..
|
||||
"label[0.5,3.2;" .. fgettext("Missing mobs") .. "]" ..
|
||||
"label[0.75,3.5;" .. fgettext("Case you're missing any of your mobs have a look at") .. "]" ..
|
||||
"label[0.75,3.8;" .. fgettext("\"Lost mobs\" in control panel, they may be preserved") .. "]" ..
|
||||
"label[0.5,4.3;" .. fgettext("Path configuration for guard mode") .. "]" ..
|
||||
"label[0.75,4.6;" .. fgettext("See \"Paths\" in control panel") .. "]"
|
||||
end
|
||||
|
||||
|
||||
local mobf_settings_tab_cheat_leftclick = {
|
||||
name = "cheat_left",
|
||||
caption = fgettext("Left click"),
|
||||
cbf_formspec = get_formspec_cheat_leftclick
|
||||
}
|
||||
|
||||
local mobf_settings_tab_cheat_rightclick = {
|
||||
name = "cheat_left",
|
||||
caption = fgettext("Right click"),
|
||||
cbf_formspec = get_formspec_cheat_rightclick
|
||||
}
|
||||
|
||||
local mobf_settings_tab_cheat_mixed = {
|
||||
name = "cheat_mixed",
|
||||
caption = fgettext("Other"),
|
||||
cbf_formspec = get_formspec_cheat_mixed
|
||||
}
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
local function init_tab(type, from, to, tabview)
|
||||
if (to == "main") then
|
||||
local tabdata = tabview:get_tabdata("main")
|
||||
assert(tabdata ~= nil)
|
||||
|
||||
if tabdata.subtabview == nil then
|
||||
tabdata.subtabview = tabview_create("cheatsheets",
|
||||
{x=8,y=8},{x=0.5,y=3.25}, tabview.parent_ui)
|
||||
tabdata.subtabview:add(mobf_settings_tab_cheat_leftclick)
|
||||
tabdata.subtabview:add(mobf_settings_tab_cheat_rightclick)
|
||||
tabdata.subtabview:add(mobf_settings_tab_cheat_mixed)
|
||||
tabdata.subtabview:set_parent(tabview)
|
||||
end
|
||||
tabdata.subtabview:show()
|
||||
elseif (from == "main") then
|
||||
local tabdata = tabview:get_tabdata("main")
|
||||
assert(tabdata ~= nil)
|
||||
if tabdata.subtabview ~= nil then
|
||||
tabdata.subtabview:hide()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function get_formspec(tabview, name, tabdata)
|
||||
|
||||
local retval = ""
|
||||
|
||||
retval = retval ..
|
||||
"label[0.25,0.25;" .. fgettext("Mob Framework") .. "]" ..
|
||||
"label[0.25,0.4;" .. "-------------------------" .. "]" ..
|
||||
"label[0.25,0.8;" .. fgettext("You're at mobf control panel various settings and tweeks") .. "]" ..
|
||||
"label[0.25,1.1;" .. fgettext("can be controled in here. Some options require \"mobf_admin\"") .."]" ..
|
||||
"label[0.25,1.4;" .. fgettext("privilege to be visible.") .. "]" ..
|
||||
"label[0.25,8.9;" .. fgettext("For more help see: http://github.com/sapier/animals_modpack") .."]"
|
||||
|
||||
return retval
|
||||
end
|
||||
|
||||
mobf_settings_tab_main = {
|
||||
name = "main",
|
||||
caption = fgettext("Main"),
|
||||
cbf_formspec = get_formspec,
|
||||
on_change = init_tab
|
||||
}
|
122
mods/mob_engines/mobf_settings/tab_mobs.lua
Normal file
122
mods/mob_engines/mobf_settings/tab_mobs.lua
Normal file
@ -0,0 +1,122 @@
|
||||
--------------------------------------------------------------------------------
|
||||
-- Mob Framework Settings Mod by Sapier
|
||||
--
|
||||
-- You may copy, use, modify or do nearly anything except removing this
|
||||
-- copyright notice.
|
||||
-- And of course you are NOT allowed to pretend you have written it.
|
||||
--
|
||||
--! @file tab_feature_config.lua
|
||||
--! @brief settings gui for mobf
|
||||
--! @copyright Sapier
|
||||
--! @author Sapier
|
||||
--! @date 2014-05-30
|
||||
--
|
||||
-- Contact sapier a t gmx net
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
local function get_formspec(tabview, name, tabdata)
|
||||
|
||||
if not tabdata.is_admin then
|
||||
return "label[0.75,0.25;" ..
|
||||
fgettext("Insufficient permissions to view this tab.")
|
||||
.. "]"
|
||||
end
|
||||
|
||||
local retval = ""
|
||||
|
||||
if tabdata.lastselected ~= nil then
|
||||
local mobdef = minetest.registered_entities[tabdata.lastselected]
|
||||
|
||||
if mobdef ~= nil and mobdef.data ~= nil then
|
||||
|
||||
retval = retval ..
|
||||
"label[2.25,0.25;Name:]label[4,0.25;" .. mobdef.data.name .. "]" ..
|
||||
"label[2.25,0.75;Mod:]label[4,0.75;" .. mobdef.data.modname .. "]" ..
|
||||
"label[2.25,1.25;Description:]label[4,1.25;" .. mobdef.data.generic.description .. "]" ..
|
||||
"image[0.25,0.25;2,2;" .. mobdef.data.modname .. "_" .. mobdef.data.name .. "_item.png]"
|
||||
end
|
||||
end
|
||||
|
||||
retval = retval ..
|
||||
"label[0.5,2;Mobs:]"
|
||||
.. "label[0.5,8.5;doubleclick to change!]"
|
||||
.. "label[4,8.5;green=enabled, red=disabled]"
|
||||
.. "textlist[0.5,2.5;7,6;tl_mobs_moblist;"
|
||||
|
||||
local mobf_mob_blacklist_string = minetest.world_setting_get("mobf_blacklist")
|
||||
local mobf_mobs_blacklisted = nil
|
||||
if mobf_mob_blacklist_string ~= nil then
|
||||
mobf_mobs_blacklisted = core.deserialize(mobf_mob_blacklist_string)
|
||||
end
|
||||
|
||||
local toadd = ""
|
||||
|
||||
for i,val in ipairs(mobf_rtd.registred_mob) do
|
||||
if toadd ~= "" then
|
||||
toadd = toadd .. ","
|
||||
end
|
||||
if contains(mobf_mobs_blacklisted,val) then
|
||||
toadd = toadd .. COLOR_RED .. val
|
||||
else
|
||||
toadd = toadd .. COLOR_GREEN .. val
|
||||
end
|
||||
end
|
||||
|
||||
retval = retval .. toadd .. ";]"
|
||||
return retval
|
||||
end
|
||||
|
||||
local function handle_settings_buttons(self, fields, tabname, tabdata)
|
||||
|
||||
if not tabdata.is_admin then
|
||||
core.log("error", "MOBF_Settings: someone managed to press a button " ..
|
||||
"she/he shouldn't even see!")
|
||||
return false
|
||||
end
|
||||
|
||||
if fields["tl_mobs_moblist"] then
|
||||
local tl_event = core.explode_textlist_event(fields["tl_mobs_moblist"])
|
||||
if tl_event.type == "DCL" and
|
||||
tl_event.index <= #mobf_rtd.registred_mob then
|
||||
local clicked_mob = mobf_rtd.registred_mob[tl_event.index]
|
||||
|
||||
local mobf_mob_blacklist_string = minetest.world_setting_get("mobf_blacklist")
|
||||
local mobf_mobs_blacklisted = nil
|
||||
if mobf_mob_blacklist_string ~= nil then
|
||||
mobf_mobs_blacklisted = core.deserialize(mobf_mob_blacklist_string)
|
||||
else
|
||||
mobf_mobs_blacklisted = {}
|
||||
end
|
||||
|
||||
local new_blacklist = {}
|
||||
|
||||
if contains(mobf_mobs_blacklisted,clicked_mob) then
|
||||
for i=1,#mobf_mobs_blacklisted,1 do
|
||||
if mobf_mobs_blacklisted[i] ~= clicked_mob then
|
||||
table.insert(new_blacklist,mobf_mobs_blacklisted[i])
|
||||
end
|
||||
end
|
||||
else
|
||||
new_blacklist = mobf_mobs_blacklisted
|
||||
table.insert(mobf_mobs_blacklisted,clicked_mob)
|
||||
end
|
||||
|
||||
minetest.world_setting_set("mobf_blacklist",core.serialize(new_blacklist))
|
||||
end
|
||||
|
||||
if tl_event.type == "CHG" and
|
||||
tl_event.index <= #mobf_rtd.registred_mob then
|
||||
tabdata.lastselected = mobf_rtd.registred_mob[tl_event.index]
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
mobf_settings_tab_mobs = {
|
||||
name = "mobs",
|
||||
caption = fgettext("Mobs"),
|
||||
cbf_formspec = get_formspec,
|
||||
cbf_button_handler = handle_settings_buttons
|
||||
}
|
187
mods/mob_engines/mobf_settings/tab_path_manager.lua
Normal file
187
mods/mob_engines/mobf_settings/tab_path_manager.lua
Normal file
@ -0,0 +1,187 @@
|
||||
--------------------------------------------------------------------------------
|
||||
-- Mob Framework Settings Mod by Sapier
|
||||
--
|
||||
-- You may copy, use, modify or do nearly anything except removing this
|
||||
-- copyright notice.
|
||||
-- And of course you are NOT allowed to pretend you have written it.
|
||||
--
|
||||
--! @file tab_restore_mobs.lua
|
||||
--! @brief settings gui for mobf
|
||||
--! @copyright Sapier
|
||||
--! @author Sapier
|
||||
--! @date 2014-05-30
|
||||
--
|
||||
-- Contact sapier a t gmx net
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
local function get_formspec(tabview, name, tabdata)
|
||||
|
||||
if tabdata.selected_entry == nil then
|
||||
tabdata.selected_entry = 0
|
||||
end
|
||||
|
||||
if tabdata.selected_point_entry == nil then
|
||||
tabdata.selected_point_entry = 0
|
||||
end
|
||||
|
||||
local retval = "button[0.25,0.0;6,0.5;btn_give_pathmarker; Give pathmarker tool]" ..
|
||||
"label[0.25,0.5;Pathname]" ..
|
||||
"label[4,0.5;Owner]"
|
||||
|
||||
local content = ""
|
||||
|
||||
local all_paths = mobf_path.get_pathlist(tabdata.playername,tabdata.is_admin)
|
||||
|
||||
if all_paths ~= nil then
|
||||
for i=1,#all_paths,1 do
|
||||
content = content .. all_paths[i].pathname .. ",(" ..
|
||||
all_paths[i].ownername .. ")"
|
||||
|
||||
if i ~= #all_paths then
|
||||
content = content .. ","
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
retval = retval ..
|
||||
"tablecolumns[text,width=16;text]" ..
|
||||
"table[0.25,1;6,8;tbl_pathlist;" .. content .. ";"
|
||||
.. tabdata.selected_entry .. "]"
|
||||
|
||||
if tabdata.selected_entry ~= 0 then
|
||||
local selected_path = all_paths[tabdata.selected_entry]
|
||||
|
||||
if selected_path == nil then
|
||||
return retval
|
||||
end
|
||||
|
||||
local path_data = mobf_rtd.path_data.users
|
||||
[selected_path.ownername].paths[selected_path.pathname]
|
||||
|
||||
if path_data == nil then
|
||||
return retval
|
||||
end
|
||||
|
||||
local point_content = ""
|
||||
local first = true
|
||||
|
||||
for i,v in ipairs(path_data.points) do
|
||||
|
||||
if not first then
|
||||
point_content = point_content ..","
|
||||
else
|
||||
first = false
|
||||
end
|
||||
|
||||
point_content = point_content ..
|
||||
i .. ":," ..
|
||||
v.x .. "," ..
|
||||
v.y .. "," ..
|
||||
v.z
|
||||
end
|
||||
|
||||
retval = retval ..
|
||||
"tablecolumns[text,width=5,align=right;"..
|
||||
"text,align=right;" ..
|
||||
"text,align=right;" ..
|
||||
"text,align=right]" ..
|
||||
"table[6.5,0;5.25,8;tbl_path_points;" .. point_content .. ";"
|
||||
.. tabdata.selected_point_entry .. "]"
|
||||
|
||||
if path_data.locked then
|
||||
retval = retval ..
|
||||
"button[6.5,8.5;1.5,0.5;btn_unlock_path;unlock]"
|
||||
else
|
||||
retval = retval ..
|
||||
"button[6.5,8.5;1.5,0.5;btn_lock_path;lock]"
|
||||
end
|
||||
|
||||
retval = retval ..
|
||||
"button[8,8.5;2,0.5;btn_show_points;show points]" ..
|
||||
"button[10,8.5;2,0.5;btn_delete_path;delete path]"
|
||||
end
|
||||
|
||||
return retval
|
||||
end
|
||||
|
||||
local function handle_settings_buttons(self, fields, tabname, tabdata)
|
||||
|
||||
if fields["btn_give_pathmarker"] then
|
||||
local player = core.get_player_by_name(tabdata.playername)
|
||||
|
||||
if not player then
|
||||
return true
|
||||
end
|
||||
player:get_inventory():add_item("main", "mobf:path_marker 1")
|
||||
return true
|
||||
end
|
||||
|
||||
if fields["tbl_pathlist"] then
|
||||
local event = core.explode_table_event(fields["tbl_pathlist"])
|
||||
|
||||
if event.type == "CHG" then
|
||||
tabdata.selected_entry = event.row
|
||||
end
|
||||
|
||||
return true;
|
||||
end
|
||||
|
||||
if fields["btn_lock_path"] or fields["btn_unlock_path"] then
|
||||
local all_paths = mobf_path.get_pathlist(tabdata.playername,tabdata.is_admin)
|
||||
local selected_path = all_paths[tabdata.selected_entry]
|
||||
|
||||
if selected_path == nil then
|
||||
return true
|
||||
end
|
||||
|
||||
local path_data = mobf_rtd.path_data.users
|
||||
[selected_path.ownername].paths[selected_path.pathname]
|
||||
|
||||
if path_data == nil then
|
||||
return true
|
||||
end
|
||||
|
||||
if fields["btn_unlock_path"] then
|
||||
path_data.locked = false
|
||||
else
|
||||
path_data.locked = true
|
||||
end
|
||||
mobf_path.save()
|
||||
return true
|
||||
end
|
||||
|
||||
if fields["btn_show_points"] then
|
||||
local all_paths = mobf_path.get_pathlist(tabdata.playername,tabdata.is_admin)
|
||||
local selected_path = all_paths[tabdata.selected_entry]
|
||||
|
||||
if selected_path == nil then
|
||||
return true
|
||||
end
|
||||
|
||||
mobf_path.show_pathmarkers(selected_path.ownername,selected_path.pathname)
|
||||
return true
|
||||
end
|
||||
|
||||
if fields["btn_delete_path"] then
|
||||
local all_paths = mobf_path.get_pathlist(tabdata.playername,tabdata.is_admin)
|
||||
local selected_path = all_paths[tabdata.selected_entry]
|
||||
|
||||
if selected_path == nil then
|
||||
return true
|
||||
end
|
||||
|
||||
--TODO add confirmation dialog
|
||||
mobf_path.delete_path(selected_path.ownername,selected_path.pathname)
|
||||
return true
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
mobf_settings_tab_paths = {
|
||||
name = "paths",
|
||||
caption = fgettext("Paths"),
|
||||
cbf_formspec = get_formspec,
|
||||
cbf_button_handler = handle_settings_buttons,
|
||||
tabsize = {width=12,height=9}
|
||||
}
|
116
mods/mob_engines/mobf_settings/tab_restore_mobs.lua
Normal file
116
mods/mob_engines/mobf_settings/tab_restore_mobs.lua
Normal file
@ -0,0 +1,116 @@
|
||||
--------------------------------------------------------------------------------
|
||||
-- Mob Framework Settings Mod by Sapier
|
||||
--
|
||||
-- You may copy, use, modify or do nearly anything except removing this
|
||||
-- copyright notice.
|
||||
-- And of course you are NOT allowed to pretend you have written it.
|
||||
--
|
||||
--! @file tab_restore_mobs.lua
|
||||
--! @brief settings gui for mobf
|
||||
--! @copyright Sapier
|
||||
--! @author Sapier
|
||||
--! @date 2014-05-30
|
||||
--
|
||||
-- Contact sapier a t gmx net
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
local function get_formspec(tabview, name, tabdata)
|
||||
|
||||
if tabdata.selected_entry == nil then
|
||||
tabdata.selected_entry = 0
|
||||
end
|
||||
|
||||
local tablehead = "Mobtype,Reason,Owner,"
|
||||
|
||||
local content = ""
|
||||
|
||||
for n=1,#mobf.current_preserve_list, 1 do
|
||||
if mobf.current_preserve_list[n].owner == tabdata.playername or
|
||||
tabdata.is_admin then
|
||||
content = content ..
|
||||
mobf.current_preserve_list[n].modname .. ":" ..
|
||||
mobf.current_preserve_list[n].name .. "," ..
|
||||
mobf.current_preserve_list[n].reason .. "," ..
|
||||
mobf.current_preserve_list[n].owner
|
||||
|
||||
if n ~= #mobf.current_preserve_list then
|
||||
content = content .. ","
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local retval =
|
||||
"tablecolumns[text,width=16;text,width=25;text,width=6]" ..
|
||||
"table[0.25,0.25;11.25,8;tbl_lost_and_found;" .. tablehead .. content .. ";"
|
||||
.. tabdata.selected_entry .. "]"
|
||||
|
||||
if tabdata.selected_entry ~= 0 then
|
||||
|
||||
retval = retval ..
|
||||
"button[0.25,8.5;3.75,0.5;btn_restore_mob;" .. fgettext("Take") .. "]"
|
||||
end
|
||||
|
||||
return retval
|
||||
end
|
||||
|
||||
local function handle_settings_buttons(self, fields, tabname, tabdata)
|
||||
|
||||
if fields["tbl_lost_and_found"] then
|
||||
|
||||
local event = core.explode_table_event(fields["tbl_lost_and_found"])
|
||||
|
||||
if event.type == "CHG" then
|
||||
tabdata.selected_entry = event.row
|
||||
end
|
||||
|
||||
return true;
|
||||
end
|
||||
|
||||
if fields["btn_restore_mob"] then
|
||||
|
||||
local elementcount = 0
|
||||
local player = core.get_player_by_name(tabdata.playername)
|
||||
|
||||
if not player then
|
||||
return true
|
||||
end
|
||||
|
||||
for i=1,#mobf.current_preserve_list,1 do
|
||||
mobf_assert_backtrace(tabdata ~= nil)
|
||||
mobf_assert_backtrace(mobf.current_preserve_list[i] ~= nil)
|
||||
|
||||
if mobf.current_preserve_list[i].owner == tabdata.playername or
|
||||
tabdata.isadmin then
|
||||
elementcount = elementcount +1
|
||||
end
|
||||
|
||||
if elementcount == (tabdata.selected_entry-1) then
|
||||
--ADD to inventory
|
||||
local inventory_add_result = player:get_inventory():add_item("main",
|
||||
mobf.current_preserve_list[i].modname ..":"..
|
||||
mobf.current_preserve_list[i].name.." 1")
|
||||
|
||||
--remove from list
|
||||
if inventory_add_result:is_empty() then
|
||||
table.remove(mobf.current_preserve_list,i)
|
||||
mobf_set_world_setting("mobf_preserve_mobs",
|
||||
core.serialize(mobf.current_preserve_list))
|
||||
end
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
mobf_settings_tab_preserve = {
|
||||
name = "preserve",
|
||||
caption = fgettext("Lost mobs"),
|
||||
cbf_formspec = get_formspec,
|
||||
cbf_button_handler = handle_settings_buttons,
|
||||
tabsize = {width=12,height=9}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user