Add pretty creative mode tab
This commit is contained in:
parent
1fa07b17d7
commit
770ead8aa2
@ -1,8 +1,20 @@
|
|||||||
local S = minetest.get_translator("creative")
|
local S = minetest.get_translator("creative")
|
||||||
local F = minetest.formspec_escape
|
local F = minetest.formspec_escape
|
||||||
|
|
||||||
local creative_inventory = {}
|
creative = {}
|
||||||
creative_inventory.creative_inventory_size = 0
|
|
||||||
|
local playerdata = {}
|
||||||
|
|
||||||
|
local form = default.ui.get_page("default:2part")
|
||||||
|
|
||||||
|
form = form .. "list[current_player;main;0.25,4.75;8,4;]"
|
||||||
|
form = form .. default.ui.get_hotbar_itemslot_bg(0.25, 4.75, 8, 1)
|
||||||
|
form = form .. default.ui.get_itemslot_bg(0.25, 5.75, 8, 3)
|
||||||
|
|
||||||
|
default.ui.register_page("creative:creative", form)
|
||||||
|
|
||||||
|
creative.creative_inventory_size = 0
|
||||||
|
creative.slots_num = 7*4
|
||||||
|
|
||||||
-- Create detached creative inventory after loading all mods
|
-- Create detached creative inventory after loading all mods
|
||||||
minetest.register_on_mods_loaded(function()
|
minetest.register_on_mods_loaded(function()
|
||||||
@ -46,7 +58,7 @@ minetest.register_on_mods_loaded(function()
|
|||||||
for _,itemstring in ipairs(creative_list) do
|
for _,itemstring in ipairs(creative_list) do
|
||||||
inv:add_item("main", ItemStack(itemstring))
|
inv:add_item("main", ItemStack(itemstring))
|
||||||
end
|
end
|
||||||
creative_inventory.creative_inventory_size = #creative_list
|
creative.creative_inventory_size = #creative_list
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Create the trash field
|
-- Create the trash field
|
||||||
@ -67,60 +79,106 @@ local trash = minetest.create_detached_inventory("creative_trash", {
|
|||||||
trash:set_size("main", 1)
|
trash:set_size("main", 1)
|
||||||
|
|
||||||
|
|
||||||
creative_inventory.set_creative_formspec = function(player, start_i, pagenum)
|
creative.get_creative_formspec = function(player, start_i, pagenum)
|
||||||
pagenum = math.floor(pagenum)
|
pagenum = math.floor(pagenum)
|
||||||
local pagemax = math.floor((creative_inventory.creative_inventory_size-1) / (6*4) + 1)
|
local pagemax = math.floor((creative.creative_inventory_size-1) / (creative.slots_num) + 1)
|
||||||
player:set_inventory_formspec(
|
return
|
||||||
"size[13,7.5]"..
|
"list[detached:creative;main;0.25,0.25;7,4;"..tostring(start_i).."]"..
|
||||||
"list[current_player;main;5,3.5;8,1;]"..
|
"label[7.5,0.75;"..F(S("@1/@2", pagenum, pagemax)).."]"..
|
||||||
"list[current_player;main;5,4.75;8,3;8]"..
|
default.ui.button(7.25, 1.25, 1, 1, "creative_prev", "<<")..
|
||||||
"list[detached:creative;main;0.3,0.5;4,6;"..tostring(start_i).."]"..
|
default.ui.button(7.25, 2.25, 1, 1, "creative_next", ">>")..
|
||||||
"label[2.0,6.55;"..F(S("@1/@2", pagenum, pagemax)).."]"..
|
|
||||||
"button[0.3,6.5;1.6,1;creative_prev;<<]"..
|
default.ui.get_itemslot_bg(0.25, 0.25, 7,4)..
|
||||||
"button[2.7,6.5;1.6,1;creative_next;>>]"..
|
-- TODO: Add trash icon
|
||||||
"label[5,1.5;"..F(S("Trash:")).."]"..
|
"list[detached:creative_trash;main;7.25,3.25;1,1;]"..
|
||||||
"list[detached:creative_trash;main;5,2;1,1;]"..
|
default.ui.get_itemslot_bg(7.25, 3.25, 1,1)..
|
||||||
"listring[current_player;main]"..
|
"listring[current_player;main]"..
|
||||||
"listring[detached:creative_trash;main]"..
|
"listring[detached:creative_trash;main]"..
|
||||||
"listring[detached:creative;main]"..
|
"listring[detached:creative;main]"..
|
||||||
"listring[current_player;main]"
|
"listring[current_player;main]"
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local get_page_and_start_i = function(playername)
|
||||||
|
local page = playerdata[playername].page
|
||||||
|
local start_i = (page - 1) * creative.slots_num
|
||||||
|
return page, start_i
|
||||||
|
end
|
||||||
|
|
||||||
|
creative.get_formspec = function(playername)
|
||||||
|
if not minetest.settings:get_bool("creative_mode") then
|
||||||
|
return ""
|
||||||
|
end
|
||||||
|
local player = minetest.get_player_by_name(playername)
|
||||||
|
if player then
|
||||||
|
local form = default.ui.get_page("creative:creative")
|
||||||
|
local page, start_i = get_page_and_start_i(playername)
|
||||||
|
form = form .. creative.get_creative_formspec(player, start_i, page)
|
||||||
|
return form
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
minetest.register_on_joinplayer(function(player)
|
minetest.register_on_joinplayer(function(player)
|
||||||
-- If in creative mode, modify player's inventory forms
|
-- If in creative mode, modify player's inventory forms
|
||||||
if not minetest.settings:get_bool("creative_mode") then
|
if not minetest.settings:get_bool("creative_mode") then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
creative_inventory.set_creative_formspec(player, 0, 1)
|
playerdata[player:get_player_name()] = { page = 1 }
|
||||||
end)
|
end)
|
||||||
|
minetest.register_on_leaveplayer(function(player)
|
||||||
|
playerdata[player:get_player_name()] = nil
|
||||||
|
end)
|
||||||
|
|
||||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||||
if not minetest.settings:get_bool("creative_mode") then
|
if not minetest.settings:get_bool("creative_mode") then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
local playername = player:get_player_name()
|
||||||
-- Figure out current page from formspec
|
-- Figure out current page from formspec
|
||||||
local current_page = 0
|
local current_page = 0
|
||||||
local formspec = player:get_inventory_formspec()
|
local formspec = player:get_inventory_formspec()
|
||||||
local start_i = string.match(formspec, "list%[detached:creative;main;[%d.]+,[%d.]+;[%d.]+,[%d.]+;(%d+)%]")
|
local page, start_i = get_page_and_start_i(playername)
|
||||||
start_i = tonumber(start_i) or 0
|
|
||||||
|
|
||||||
|
local changed = false
|
||||||
if fields.creative_prev then
|
if fields.creative_prev then
|
||||||
start_i = start_i - 4*6
|
page = page - 1
|
||||||
|
start_i = start_i - creative.slots_num
|
||||||
|
changed = true
|
||||||
end
|
end
|
||||||
if fields.creative_next then
|
if fields.creative_next then
|
||||||
start_i = start_i + 4*6
|
page = page + 1
|
||||||
|
start_i = start_i + creative.slots_num
|
||||||
|
changed = true
|
||||||
end
|
end
|
||||||
|
|
||||||
if start_i < 0 then
|
if start_i < 0 then
|
||||||
start_i = start_i + 4*6
|
start_i = start_i + creative.slots_num
|
||||||
|
page = page + 1
|
||||||
end
|
end
|
||||||
if start_i >= creative_inventory.creative_inventory_size then
|
if start_i >= creative.creative_inventory_size then
|
||||||
start_i = start_i - 4*6
|
start_i = start_i - creative.slots_num
|
||||||
|
page = page - 1
|
||||||
end
|
end
|
||||||
|
playerdata[playername].page = page
|
||||||
|
|
||||||
if start_i < 0 or start_i >= creative_inventory.creative_inventory_size then
|
if start_i < 0 or start_i >= creative.creative_inventory_size then
|
||||||
start_i = 0
|
start_i = 0
|
||||||
|
page = 1
|
||||||
end
|
end
|
||||||
|
|
||||||
creative_inventory.set_creative_formspec(player, start_i, start_i / (6*4) + 1)
|
local form = default.ui.get_page("creative:creative")
|
||||||
|
form = form .. creative.get_creative_formspec(player, start_i, start_i / (creative.slots_num) + 1)
|
||||||
|
if changed then
|
||||||
|
minetest.show_formspec(playername, "creative:creative", form)
|
||||||
|
player:set_inventory_formspec(form)
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
-- Dummy implementation
|
||||||
|
-- TODO: Implement per-player creative mode
|
||||||
|
creative.is_enabled_for = function(player)
|
||||||
|
if minetest.settings:get_bool("creative_mode") then
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
@ -279,6 +279,9 @@ end
|
|||||||
if minetest.get_modpath("player_skins") ~= nil then
|
if minetest.get_modpath("player_skins") ~= nil then
|
||||||
form_default_default = form_default_default .. default.ui.tab(-0.9, 2.84, "tab_player_skins", "ui_icon_player_skins.png", S("Player Skins"))
|
form_default_default = form_default_default .. default.ui.tab(-0.9, 2.84, "tab_player_skins", "ui_icon_player_skins.png", S("Player Skins"))
|
||||||
end
|
end
|
||||||
|
if minetest.get_modpath("creative") ~= nil and minetest.settings:get_bool("creative_mode") then
|
||||||
|
form_default_default = form_default_default .. default.ui.tab(-0.9, 3.64, "tab_creative", "ui_icon_creative.png", S("Creative Inventory"))
|
||||||
|
end
|
||||||
form_default_default = form_default_default .. "background[0,0;8.5,9;ui_formspec_bg_tall.png]"
|
form_default_default = form_default_default .. "background[0,0;8.5,9;ui_formspec_bg_tall.png]"
|
||||||
default.ui.register_page("default:default", form_default_default)
|
default.ui.register_page("default:default", form_default_default)
|
||||||
default.ui.register_page("default:2part", form_default_default .. "background[0,0;8.5,4.5;ui_formspec_bg_short.png]")
|
default.ui.register_page("default:2part", form_default_default .. "background[0,0;8.5,4.5;ui_formspec_bg_short.png]")
|
||||||
@ -322,6 +325,8 @@ function default.ui.receive_fields(player, form_name, fields)
|
|||||||
minetest.show_formspec(name, "achievements:achievements", achievements.get_formspec(name))
|
minetest.show_formspec(name, "achievements:achievements", achievements.get_formspec(name))
|
||||||
elseif minetest.get_modpath("player_skins") ~= nil and fields.tab_player_skins then
|
elseif minetest.get_modpath("player_skins") ~= nil and fields.tab_player_skins then
|
||||||
minetest.show_formspec(name, "player_skins:player_skins", player_skins.get_formspec(name))
|
minetest.show_formspec(name, "player_skins:player_skins", player_skins.get_formspec(name))
|
||||||
|
elseif minetest.get_modpath("creative") ~= nil and minetest.settings:get_bool("creative_mode") and fields.tab_creative then
|
||||||
|
minetest.show_formspec(name, "creative:creative", creative.get_formspec(name))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -149,3 +149,4 @@ Any planks=Beliebige Planken
|
|||||||
Any soil=Beliebiger Boden
|
Any soil=Beliebiger Boden
|
||||||
Any stone=Beliebiger Stein
|
Any stone=Beliebiger Stein
|
||||||
Any tree=Beliebiger Baum
|
Any tree=Beliebiger Baum
|
||||||
|
Creative Inventory=Kreativinventar
|
||||||
|
@ -149,3 +149,4 @@ Any planks=
|
|||||||
Any soil=
|
Any soil=
|
||||||
Any stone=
|
Any stone=
|
||||||
Any tree=
|
Any tree=
|
||||||
|
Creative Inventory=
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 314 B After Width: | Height: | Size: 1.7 KiB |
Binary file not shown.
BIN
mods/default/textures/ui_icon_creative.png
Normal file
BIN
mods/default/textures/ui_icon_creative.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.6 KiB |
Loading…
Reference in New Issue
Block a user