2018-11-11 05:26:59 +01:00
|
|
|
local hotbar_size_default = minetest.setting_get("hotbar_size") or 16
|
2018-11-11 05:23:16 +01:00
|
|
|
|
2018-11-11 05:26:59 +01:00
|
|
|
local player_hotbar_settings = {}
|
|
|
|
|
|
|
|
local function load_hotbar_settings()
|
|
|
|
local f = io.open(minetest.get_worldpath()..DIR_DELIM.."hotbar_settings","r")
|
|
|
|
if not f then return end
|
|
|
|
local d = f:read("*all")
|
|
|
|
f:close()
|
|
|
|
player_hotbar_settings = minetest.deserialize(d)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function save_hotbar_settings()
|
|
|
|
local f = io.open(minetest.get_worldpath()..DIR_DELIM.."hotbar_settings","w")
|
|
|
|
if not f then
|
|
|
|
minetest.log("error","Failed to save hotbar settings")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local d = minetest.serialize(player_hotbar_settings)
|
|
|
|
f:write(d)
|
|
|
|
f:close()
|
|
|
|
end
|
|
|
|
|
|
|
|
local function get_hotbar_setting(name)
|
|
|
|
return tonumber(player_hotbar_settings[name]) or hotbar_size_default
|
|
|
|
end
|
|
|
|
|
|
|
|
load_hotbar_settings()
|
2018-11-11 05:23:16 +01:00
|
|
|
|
|
|
|
local function resize_hotbar(size)
|
|
|
|
if size == 8 then return "gui_hb_bg.png" end
|
|
|
|
if size == 23 then return "gui_hb_bg_23.png" end
|
|
|
|
return "gui_hb_bg_16.png"
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_on_joinplayer(function(player)
|
2018-11-11 05:26:59 +01:00
|
|
|
local hotbar_size = get_hotbar_setting(player:get_player_name())
|
2018-11-11 05:23:16 +01:00
|
|
|
player:hud_set_hotbar_itemcount(hotbar_size)
|
2018-11-11 05:26:59 +01:00
|
|
|
minetest.after(0.5,function(hotbar_size)
|
2018-11-11 05:23:16 +01:00
|
|
|
player:hud_set_hotbar_selected_image("gui_hotbar_selected.png")
|
|
|
|
player:hud_set_hotbar_image(resize_hotbar(hotbar_size))
|
2018-11-11 05:26:59 +01:00
|
|
|
end,hotbar_size)
|
2018-11-11 05:23:16 +01:00
|
|
|
end)
|
|
|
|
|
|
|
|
minetest.register_chatcommand("hotbar", {
|
|
|
|
params = "[size]",
|
|
|
|
description = "Sets the size of your hotbar",
|
|
|
|
func = function(name, slots)
|
|
|
|
if slots ~= "8" and slots ~= "23" then slots = "16" end
|
2018-11-11 05:26:59 +01:00
|
|
|
player_hotbar_settings[name] = slots
|
2018-11-11 05:23:16 +01:00
|
|
|
local player = minetest.get_player_by_name(name)
|
|
|
|
player:hud_set_hotbar_itemcount(tonumber(slots))
|
|
|
|
minetest.chat_send_player(name, "[_] Hotbar size set to " .. tonumber(slots) .. ".")
|
|
|
|
player:hud_set_hotbar_image(resize_hotbar(tonumber(slots)))
|
2018-11-11 05:26:59 +01:00
|
|
|
save_hotbar_settings()
|
2018-11-11 05:23:16 +01:00
|
|
|
end,
|
|
|
|
})
|