Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
763eca424e | ||
|
3306676910 |
3
bags.lua
@ -7,7 +7,8 @@ unified_inventory.register_page("bags", {
|
||||
get_formspec = function(player)
|
||||
local player_name = player:get_player_name()
|
||||
local formspec = "background[0.06,0.99;7.92,7.52;ui_bags_main_form.png]"
|
||||
formspec = formspec.."label[0,0;Bags]"
|
||||
formspec = formspec.."image[0,0;1,1;ui_bags_icon.png]"
|
||||
formspec = formspec.."label[1,0;Bags]"
|
||||
formspec = formspec.."button[0,2;2,0.5;bag1;Bag 1]"
|
||||
formspec = formspec.."button[2,2;2,0.5;bag2;Bag 2]"
|
||||
formspec = formspec.."button[4,2;2,0.5;bag3;Bag 3]"
|
||||
|
83
datastorage.lua
Normal file
@ -0,0 +1,83 @@
|
||||
datastorage={}
|
||||
datastorage["!registered_players"]={}
|
||||
|
||||
datastorage.save_data = function(table_pointer)
|
||||
local data = minetest.serialize( datastorage[table_pointer] )
|
||||
local path = minetest.get_worldpath().."/datastorage_"..table_pointer..".data"
|
||||
local file = io.open( path, "w" )
|
||||
if( file ) then
|
||||
file:write( data )
|
||||
file:close()
|
||||
return true
|
||||
else return nil
|
||||
end
|
||||
end
|
||||
|
||||
datastorage.load_data = function(table_pointer)
|
||||
local path = minetest.get_worldpath().."/datastorage_"..table_pointer..".data"
|
||||
local file = io.open( path, "r" )
|
||||
if( file ) then
|
||||
local data = file:read("*all")
|
||||
datastorage[table_pointer] = minetest.deserialize( data )
|
||||
file:close()
|
||||
return true
|
||||
else return nil
|
||||
end
|
||||
end
|
||||
|
||||
datastorage.get_container = function (player, key)
|
||||
local player_name = player:get_player_name()
|
||||
local container = datastorage[player_name]
|
||||
if container[key] == nil then
|
||||
container[key] = {}
|
||||
end
|
||||
datastorage.save_data(player_name)
|
||||
return container[key]
|
||||
end
|
||||
|
||||
-- forced save of all player's data
|
||||
datastorage.save_container = function (player)
|
||||
local player_name = player:get_player_name()
|
||||
datastorage.save_data(player_name)
|
||||
end
|
||||
|
||||
|
||||
-- Init
|
||||
if datastorage.load_data("!registered_players") == nil then
|
||||
datastorage["!registered_players"]={}
|
||||
datastorage.save_data("!registered_players")
|
||||
end
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
local player_name = player:get_player_name()
|
||||
local registered = nil
|
||||
for __,tab in ipairs(datastorage["!registered_players"]) do
|
||||
if tab["player_name"] == player_name then registered = true break end
|
||||
end
|
||||
if registered == nil then
|
||||
local new={}
|
||||
new["player_name"]=player_name
|
||||
table.insert(datastorage["!registered_players"],new)
|
||||
datastorage[player_name]={}
|
||||
datastorage.save_data("!registered_players")
|
||||
datastorage.save_data(player_name)
|
||||
else
|
||||
datastorage.load_data(player_name)
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
minetest.register_on_leaveplayer(function(player)
|
||||
local player_name = player:get_player_name()
|
||||
datastorage.save_data(player_name)
|
||||
datastorage[player_name] = nil
|
||||
end
|
||||
)
|
||||
|
||||
minetest.register_on_shutdown(function()
|
||||
for __,tab in ipairs(datastorage["!registered_players"]) do
|
||||
if datastorage[tab["player_name"]] == nil then break end
|
||||
datastorage.save_data(tab["player_name"])
|
||||
end
|
||||
end
|
||||
)
|
2
init.lua
@ -35,8 +35,10 @@ if creative_inventory then
|
||||
end
|
||||
end
|
||||
|
||||
dofile(modpath.."/datastorage.lua")
|
||||
dofile(modpath.."/api.lua")
|
||||
dofile(modpath.."/internal.lua")
|
||||
dofile(modpath.."/callbacks.lua")
|
||||
dofile(modpath.."/register.lua")
|
||||
dofile(modpath.."/bags.lua")
|
||||
dofile(modpath.."/waypoints.lua")
|
||||
|
@ -120,7 +120,8 @@ unified_inventory.register_page("craft", {
|
||||
local player_name = player:get_player_name()
|
||||
local formspec = "background[0,1;8,3;ui_crafting_form.png]"
|
||||
formspec = formspec.."background[0,4.5;8,4;ui_main_inventory.png]"
|
||||
formspec = formspec.."label[0,0;Crafting]"
|
||||
formspec = formspec.."image[0,0;1,1;ui_craft_icon.png]"
|
||||
formspec = formspec.."label[1,0;Crafting]"
|
||||
formspec = formspec.."listcolors[#00000000;#00000000]"
|
||||
formspec = formspec.."list[current_player;craftpreview;6,1;1,1;]"
|
||||
formspec = formspec.."list[current_player;craft;2,1;3,3;]"
|
||||
@ -139,14 +140,15 @@ unified_inventory.register_page("craftguide", {
|
||||
local player_name = player:get_player_name()
|
||||
local formspec = "background[0,1;8,3;ui_craftguide_form.png]"
|
||||
formspec = formspec.."background[0,4.5;8,4;ui_main_inventory.png]"
|
||||
formspec = formspec.."label[0,0;Crafting Guide]"
|
||||
formspec = formspec.."image[0,0;1,1;ui_craftguide_icon.png]"
|
||||
formspec = formspec.."label[1,0;Crafting Guide]"
|
||||
formspec = formspec.."listcolors[#00000000;#00000000]"
|
||||
formspec = formspec.."list[detached:"..player_name.."craftrecipe;output;6,1;1,1;]"
|
||||
formspec = formspec.."label[6,3.35;Method:]"
|
||||
local item_name = unified_inventory.current_item[player_name]
|
||||
local craft = nil
|
||||
if item_name then
|
||||
formspec = formspec.."textarea[0.3,0.6;10,1;;Result: "..item_name..";]"
|
||||
formspec = formspec.."textarea[1.3,0.6;10,1;;Result: "..item_name..";]"
|
||||
local alternates = 0
|
||||
local alternate = unified_inventory.alternate[player_name]
|
||||
local crafts = unified_inventory.crafts_table[item_name]
|
||||
|
BIN
textures/ui_1_icon.png
Normal file
After Width: | Height: | Size: 321 B |
BIN
textures/ui_2_icon.png
Normal file
After Width: | Height: | Size: 567 B |
BIN
textures/ui_3_icon.png
Normal file
After Width: | Height: | Size: 647 B |
BIN
textures/ui_4_icon.png
Normal file
After Width: | Height: | Size: 420 B |
BIN
textures/ui_5_icon.png
Normal file
After Width: | Height: | Size: 554 B |
BIN
textures/ui_blue_icon_background.png
Normal file
After Width: | Height: | Size: 2.9 KiB |
BIN
textures/ui_cancel_icon.png
Normal file
After Width: | Height: | Size: 3.5 KiB |
BIN
textures/ui_circular_arrows_icon.png
Normal file
After Width: | Height: | Size: 3.0 KiB |
BIN
textures/ui_green_icon_background.png
Normal file
After Width: | Height: | Size: 2.9 KiB |
BIN
textures/ui_ok_icon.png
Normal file
After Width: | Height: | Size: 2.4 KiB |
BIN
textures/ui_pencil_icon.png
Normal file
After Width: | Height: | Size: 1.2 KiB |
BIN
textures/ui_red_icon_background.png
Normal file
After Width: | Height: | Size: 2.5 KiB |
BIN
textures/ui_waypoint_set_icon.png
Normal file
After Width: | Height: | Size: 2.0 KiB |
BIN
textures/ui_xyz_icon.png
Normal file
After Width: | Height: | Size: 753 B |
BIN
textures/ui_xyz_off_icon.png
Normal file
After Width: | Height: | Size: 5.9 KiB |
BIN
textures/ui_xyz_on_icon.png
Normal file
After Width: | Height: | Size: 817 B |
208
waypoints.lua
Normal file
@ -0,0 +1,208 @@
|
||||
unified_inventory.hud_colors = {
|
||||
{"#FFFFFF", 0xFFFFFF, "White"},
|
||||
{"#DBBB00", 0xf1d32c, "Yellow"},
|
||||
{"#DD0000", 0xDD0000, "Red"},
|
||||
{"#2cf136", 0x2cf136, "Green"},
|
||||
{"#2c4df1", 0x2c4df1, "Blue"},
|
||||
}
|
||||
unified_inventory.hud_colors_max = #unified_inventory.hud_colors
|
||||
|
||||
unified_inventory.register_page("waypoints", {
|
||||
get_formspec = function(player)
|
||||
local waypoints = datastorage.get_container (player, "waypoints")
|
||||
local formspec = "background[0,4.5;8,4;ui_main_inventory.png]"..
|
||||
"image[0,0;1,1;ui_waypoints_icon.png]"..
|
||||
"label[1,0;Waypoints]"
|
||||
|
||||
-- Tabs buttons:
|
||||
local i
|
||||
for i = 1, 5, 1 do
|
||||
if i == waypoints.selected then
|
||||
formspec = formspec ..
|
||||
"image_button[0.0,".. 0.2 + i*0.7 ..";.8,.8;ui_blue_icon_background.png^ui_"..
|
||||
i .."_icon.png;select_waypoint".. i .. ";]"
|
||||
else
|
||||
formspec = formspec ..
|
||||
"image_button[0.0,".. 0.2 + i*0.7 ..";.8,.8;ui_"..
|
||||
i .."_icon.png;select_waypoint".. i .. ";]"
|
||||
end
|
||||
end
|
||||
|
||||
i = waypoints.selected
|
||||
|
||||
-- Main buttons:
|
||||
formspec = formspec ..
|
||||
"image_button[4.5,3.7;.8,.8;ui_waypoint_set_icon.png;set_waypoint".. i .. ";]"
|
||||
|
||||
if waypoints[i].active then
|
||||
formspec = formspec ..
|
||||
"image_button[5.2,3.7;.8,.8;ui_on_icon.png;toggle_waypoint".. i .. ";]"
|
||||
else
|
||||
formspec = formspec ..
|
||||
"image_button[5.2,3.7;.8,.8;ui_off_icon.png;toggle_waypoint".. i .. ";]"
|
||||
end
|
||||
|
||||
if waypoints[i].display_pos then
|
||||
formspec = formspec ..
|
||||
"image_button[5.9,3.7;.8,.8;ui_green_icon_background.png^ui_xyz_icon.png;toggle_display_pos".. i .. ";]"
|
||||
else
|
||||
formspec = formspec ..
|
||||
"image_button[5.9,3.7;.8,.8;ui_red_icon_background.png^ui_xyz_icon.png;toggle_display_pos".. i .. ";]"
|
||||
end
|
||||
|
||||
formspec = formspec ..
|
||||
"image_button[6.6,3.7;.8,.8;ui_circular_arrows_icon.png;toggle_color".. i .. ";]"..
|
||||
"image_button[7.3,3.7;.8,.8;ui_pencil_icon.png;rename_waypoint".. i .. ";]"
|
||||
|
||||
-- Waypoint's info:
|
||||
if waypoints[i].active then
|
||||
formspec = formspec .. "label[1,0.8;Waypoint active]"
|
||||
else
|
||||
formspec = formspec .. "label[1,0.8;Waypoint inactive]"
|
||||
end
|
||||
|
||||
formspec = formspec .. "label[1,1.3;World position: " ..
|
||||
minetest.pos_to_string(waypoints[i].world_pos) .. "]" ..
|
||||
"label[1,1.8;Name: ]".. waypoints[i].name .. "]" ..
|
||||
"label[1,2.3;Hud text color: " ..
|
||||
unified_inventory.hud_colors[waypoints[i].color][3] .. "]"
|
||||
|
||||
return {formspec=formspec}
|
||||
end,
|
||||
})
|
||||
|
||||
unified_inventory.register_button("waypoints", {
|
||||
type = "image",
|
||||
image = "ui_waypoints_icon.png",
|
||||
})
|
||||
|
||||
unified_inventory.update_hud = function (player, waypoint)
|
||||
local name
|
||||
if waypoint.display_pos then
|
||||
name = "("..
|
||||
waypoint.world_pos.x .. "," ..
|
||||
waypoint.world_pos.y .. "," ..
|
||||
waypoint.world_pos.z .. ")"
|
||||
if waypoint.name ~= "" then
|
||||
name = name .. ", " ..
|
||||
waypoint.name
|
||||
end
|
||||
else
|
||||
name = waypoint.name
|
||||
end
|
||||
if waypoint.active then
|
||||
player:hud_remove(waypoint.hud)
|
||||
waypoint.hud = player:hud_add({
|
||||
hud_elem_type = "waypoint",
|
||||
number = unified_inventory.hud_colors[waypoint.color][2] ,
|
||||
name = name,
|
||||
text = "m",
|
||||
world_pos = waypoint.world_pos
|
||||
})
|
||||
else
|
||||
if waypoint.hud ~= nil then
|
||||
player:hud_remove(waypoint.hud)
|
||||
waypoint.hud = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
if formname ~= "" then
|
||||
return
|
||||
end
|
||||
|
||||
local update_formspec = false
|
||||
local update_hud = false
|
||||
|
||||
local waypoints = datastorage.get_container (player, "waypoints")
|
||||
for i = 1, 5, 1 do
|
||||
|
||||
if fields["select_waypoint"..i] then
|
||||
waypoints.selected = i
|
||||
update_formspec = true
|
||||
end
|
||||
|
||||
if fields["toggle_waypoint"..i] then
|
||||
waypoints[i].active = not (waypoints[i].active)
|
||||
update_hud = true
|
||||
update_formspec = true
|
||||
end
|
||||
|
||||
if fields["set_waypoint"..i] then
|
||||
local pos = player:getpos()
|
||||
pos.x = math.floor(pos.x)
|
||||
pos.y = math.floor(pos.y)
|
||||
pos.z = math.floor(pos.z)
|
||||
waypoints[i].world_pos = pos
|
||||
update_hud = true
|
||||
update_formspec = true
|
||||
end
|
||||
|
||||
if fields["rename_waypoint"..i] then
|
||||
waypoints[i].edit = true
|
||||
update_formspec = true
|
||||
end
|
||||
|
||||
if fields["toggle_display_pos"..i] then
|
||||
waypoints[i].display_pos = not waypoints[i].display_pos
|
||||
update_hud = true
|
||||
update_formspec = true
|
||||
end
|
||||
|
||||
if fields["toggle_color"..i] then
|
||||
local color = waypoints[i].color
|
||||
color = color + 1
|
||||
if color > unified_inventory.hud_colors_max then
|
||||
color = 1
|
||||
end
|
||||
waypoints[i].color = color
|
||||
update_hud = true
|
||||
update_formspec = true
|
||||
end
|
||||
|
||||
if fields["confirm_rename"..i] then
|
||||
waypoints[i].edit = false
|
||||
waypoints[i].name = fields["rename_box"..i]
|
||||
update_hud = true
|
||||
update_formspec = true
|
||||
end
|
||||
|
||||
if update_hud then
|
||||
unified_inventory.update_hud (player, waypoints[i])
|
||||
end
|
||||
|
||||
if update_formspec then
|
||||
unified_inventory.set_inventory_formspec(player, "waypoints")
|
||||
end
|
||||
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
local waypoints = datastorage.get_container (player, "waypoints")
|
||||
|
||||
-- Create new waypoints data
|
||||
if waypoints[1] == nil then
|
||||
for i = 1, 5, 1 do
|
||||
waypoints[i] = {
|
||||
edit = false,
|
||||
active = false,
|
||||
display_pos = true,
|
||||
color = 2,
|
||||
name = "Waypoint ".. i,
|
||||
world_pos = {x = 0, y = 0, z = 0},
|
||||
}
|
||||
end
|
||||
datastorage.save_container(player)
|
||||
end
|
||||
|
||||
-- Initialize waypoints
|
||||
minetest.after(0.5, function()
|
||||
waypoints.selected = 1
|
||||
for i = 1, 5, 1 do
|
||||
waypoints[i].edit = false
|
||||
unified_inventory.update_hud (player, waypoints[i])
|
||||
end
|
||||
end)
|
||||
end)
|