summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRealBadAngel <maciej.kasatkin@yahoo.com>2014-01-27 12:15:25 +0100
committerRealBadAngel <maciej.kasatkin@yahoo.com>2014-01-27 12:15:25 +0100
commit3306676910b903abf9b9e844dbc1d7c293054979 (patch)
treecd9c030f7604b6440e9a4b7fb681a6c21f00fa2c
parent34a52a4c0fa6cf9c060b8076202278de30d1004c (diff)
Initial waypoints tab upload
-rw-r--r--bags.lua3
-rw-r--r--datastorage.lua83
-rw-r--r--init.lua2
-rw-r--r--register.lua8
-rw-r--r--textures/ui_cancel_icon.pngbin0 -> 3593 bytes
-rw-r--r--textures/ui_ok_icon.pngbin0 -> 2427 bytes
-rw-r--r--textures/ui_pencil_icon.pngbin0 -> 1258 bytes
-rw-r--r--textures/ui_waypoint_set_icon.pngbin0 -> 2036 bytes
-rw-r--r--waypoints.lua121
9 files changed, 213 insertions, 4 deletions
diff --git a/bags.lua b/bags.lua
index 2a21d5d..40943eb 100644
--- a/bags.lua
+++ b/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]"
diff --git a/datastorage.lua b/datastorage.lua
new file mode 100644
index 0000000..096e35e
--- /dev/null
+++ b/datastorage.lua
@@ -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
+)
diff --git a/init.lua b/init.lua
index ec4105f..9c9c44c 100644
--- a/init.lua
+++ b/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")
diff --git a/register.lua b/register.lua
index 7725aaa..4f258a6 100644
--- a/register.lua
+++ b/register.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]
diff --git a/textures/ui_cancel_icon.png b/textures/ui_cancel_icon.png
new file mode 100644
index 0000000..6c36fae
--- /dev/null
+++ b/textures/ui_cancel_icon.png
Binary files differ
diff --git a/textures/ui_ok_icon.png b/textures/ui_ok_icon.png
new file mode 100644
index 0000000..779fc3b
--- /dev/null
+++ b/textures/ui_ok_icon.png
Binary files differ
diff --git a/textures/ui_pencil_icon.png b/textures/ui_pencil_icon.png
new file mode 100644
index 0000000..af77c2f
--- /dev/null
+++ b/textures/ui_pencil_icon.png
Binary files differ
diff --git a/textures/ui_waypoint_set_icon.png b/textures/ui_waypoint_set_icon.png
new file mode 100644
index 0000000..6eb46e3
--- /dev/null
+++ b/textures/ui_waypoint_set_icon.png
Binary files differ
diff --git a/waypoints.lua b/waypoints.lua
new file mode 100644
index 0000000..a195469
--- /dev/null
+++ b/waypoints.lua
@@ -0,0 +1,121 @@
+unified_inventory.register_page("waypoints", {
+ get_formspec = function(player)
+ local player_name = player:get_player_name()
+ local need_save = false
+ 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]"
+ for i = 1, 5, 1 do
+ formspec = formspec .. "label[0,".. 0.2 + i*0.7 ..";".. i ..".]"
+ if waypoints[i].edit then
+ formspec = formspec ..
+ "image_button[1.7,".. 0.2 + i*0.7 ..";.8,.8;ui_ok_icon.png;confirm_rename".. i .. ";]"..
+ "field[2.7,".. 0.5 + i*0.7 ..";5,.8;rename_box".. i ..";;".. waypoints[i].name .."]"
+ else
+ formspec = formspec ..
+ "image_button[1.7,".. 0.2 + i*0.7 ..";.8,.8;ui_pencil_icon.png;rename_waypoint".. i .. ";]"..
+ "label[3,".. 0.2 + i*0.7 ..";("..
+ waypoints[i].world_pos.x .. "," ..
+ waypoints[i].world_pos.y .. "," ..
+ waypoints[i].world_pos.z .. "), "..
+ waypoints[i].name .. "]"
+ end
+ formspec = formspec .. "image_button[1.0,".. 0.2 + i*0.7 ..";.8,.8;ui_waypoint_set_icon.png;set_waypoint".. i .. ";]"
+ if not waypoints[i].active then
+ formspec = formspec .. "image_button[0.3,".. 0.2 + i*0.7 ..";.8,.8;ui_off_icon.png;toggle_waypoint".. i .. ";]"
+ else
+ formspec = formspec .. "image_button[0.3,".. 0.2 + i*0.7 ..";.8,.8;ui_on_icon.png;toggle_waypoint".. i .. ";]"
+ end
+ end
+ return {formspec=formspec}
+ end,
+})
+
+unified_inventory.register_button("waypoints", {
+ type = "image",
+ image = "ui_waypoints_icon.png",
+})
+
+minetest.register_on_player_receive_fields(function(player, formname, fields)
+ if formname ~= "" then
+ return
+ end
+ local waypoints = datastorage.get_container (player, "waypoints")
+ for i = 1, 5, 1 do
+ if fields["toggle_waypoint"..i] then
+ waypoints[i].active = not (waypoints[i].active)
+ unified_inventory.set_inventory_formspec(player, "waypoints")
+ if waypoints[i].active == true then
+ waypoints[i].hud = player:hud_add({
+ hud_elem_type = "waypoint",
+ number = 0xFFFFFF ,
+ name = waypoints[i].name,
+ text = "m",
+ world_pos = waypoints[i].world_pos
+ })
+ else
+ if waypoints[i].hud ~= nil then
+ player:hud_remove(waypoints[i].hud)
+ end
+ end
+ 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
+ if waypoints[i].active == true then
+ player:hud_remove(waypoints[i].hud)
+ waypoints[i].hud = player:hud_add({
+ hud_elem_type = "waypoint",
+ number = 0xFFFFFF ,
+ name = waypoints[i].name,
+ text = "m",
+ world_pos = waypoints[i].world_pos
+ })
+ end
+ unified_inventory.set_inventory_formspec(player, "waypoints")
+ end
+
+ if fields["rename_waypoint"..i] then
+ waypoints[i].edit = true
+ unified_inventory.set_inventory_formspec(player, "waypoints")
+ end
+ if fields["confirm_rename"..i] then
+ waypoints[i].edit = false
+ waypoints[i].name = fields["rename_box"..i]
+ unified_inventory.set_inventory_formspec(player, "waypoints")
+ player:hud_remove(waypoints[i].hud)
+ if waypoints[i].active == true then
+ waypoints[i].hud = player:hud_add({
+ hud_elem_type = "waypoint",
+ number = 0xFFFFFF ,
+ name = waypoints[i].name,
+ text = "m",
+ world_pos = waypoints[i].world_pos
+ })
+ end
+ end
+ end
+end)
+
+minetest.register_on_joinplayer(function(player)
+ local waypoints = datastorage.get_container (player, "waypoints")
+ if waypoints[1] == nil then
+ for i = 1, 5, 1 do
+ waypoints[i] = {
+ edit = false,
+ active = false,
+ name = "Waypoint ".. i,
+ world_pos = {x = 0, y = 0, z = 0},
+ }
+ end
+ datastorage.save_container(player)
+ end
+ for i = 1, 5, 1 do
+ waypoints[i].edit = false
+ end
+end)