Fix Minor bug in back button
remove trailing white space as well
This commit is contained in:
parent
6988330919
commit
6c59fdc6e0
@ -4,13 +4,13 @@
|
|||||||
-- | _|| / -_) '_ \/ _ \ V V / -_) '_| --
|
-- | _|| / -_) '_ \/ _ \ V V / -_) '_| --
|
||||||
-- |___|_\___| .__/\___/\_/\_/\___|_| --
|
-- |___|_\___| .__/\___/\_/\_/\___|_| --
|
||||||
-- |_| --
|
-- |_| --
|
||||||
-- _____ --
|
-- _____ --
|
||||||
-- |_ _|__ _ __ ___ --
|
-- |_ _|__ _ __ ___ --
|
||||||
-- | |/ _ \ ' \/ -_) --
|
-- | |/ _ \ ' \/ -_) --
|
||||||
-- |_|\___/_|_|_\___| --
|
-- |_|\___/_|_|_\___| --
|
||||||
---------------------------------------------------
|
---------------------------------------------------
|
||||||
-- --
|
-- --
|
||||||
---------------------------------------------------
|
---------------------------------------------------
|
||||||
|
|
||||||
-- Global variable for mod
|
-- Global variable for mod
|
||||||
eletome = rawget(_G, "eletome") or {}
|
eletome = rawget(_G, "eletome") or {}
|
||||||
@ -36,11 +36,11 @@ minetest.register_craftitem("elepower_tome:tome", {
|
|||||||
inventory_image = "elepower_tome.png",
|
inventory_image = "elepower_tome.png",
|
||||||
groups = {book = 1, flammable = 3},
|
groups = {book = 1, flammable = 3},
|
||||||
on_use = function(itemstack, user, pointed_thing)
|
on_use = function(itemstack, user, pointed_thing)
|
||||||
|
|
||||||
local eletome_bg = eletome.tome_bg
|
local eletome_bg = eletome.tome_bg
|
||||||
local eletome_contents = eletome.contents_page()
|
local eletome_contents = eletome.contents_page()
|
||||||
minetest.show_formspec(user:get_player_name(), "elepower_tome:tome", eletome_bg..eletome_contents)
|
minetest.show_formspec(user:get_player_name(), "elepower_tome:tome", eletome_bg..eletome_contents)
|
||||||
|
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -53,7 +53,7 @@ end)
|
|||||||
-- Player tome meta - setup back button meta
|
-- Player tome meta - setup back button meta
|
||||||
minetest.register_on_joinplayer(function(player)
|
minetest.register_on_joinplayer(function(player)
|
||||||
local pmeta = player:get_meta()
|
local pmeta = player:get_meta()
|
||||||
local back = {}
|
local back = {}
|
||||||
pmeta:set_string("elepower_tome_back", minetest.serialize(back))
|
pmeta:set_string("elepower_tome_back", minetest.serialize(back))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@ -63,19 +63,19 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
if formname ~= "elepower_tome:tome" then
|
if formname ~= "elepower_tome:tome" then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Back Button
|
-- Back Button
|
||||||
local pmeta = player:get_meta()
|
local pmeta = player:get_meta()
|
||||||
local back = minetest.deserialize(pmeta:get_string("elepower_tome_back"))
|
local back = minetest.deserialize(pmeta:get_string("elepower_tome_back"))
|
||||||
local show_back = ""
|
local show_back = ""
|
||||||
|
|
||||||
if fields.quit == "true" then
|
if fields.quit == "true" then
|
||||||
back = {}
|
back = {}
|
||||||
pmeta:set_string("elepower_tome_back", minetest.serialize(back))
|
pmeta:set_string("elepower_tome_back", minetest.serialize(back))
|
||||||
|
|
||||||
elseif fields.back then
|
elseif fields.back then
|
||||||
local prev_page = #back-1
|
local prev_page = #back-1
|
||||||
|
|
||||||
if prev_page <= 0 then
|
if prev_page <= 0 then
|
||||||
-- must be going back to contents
|
-- must be going back to contents
|
||||||
fields = {}
|
fields = {}
|
||||||
@ -85,61 +85,60 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
else
|
else
|
||||||
fields = back[prev_page]
|
fields = back[prev_page]
|
||||||
table.remove(back,#back)
|
table.remove(back,#back)
|
||||||
table.remove(back,#back-1)
|
|
||||||
pmeta:set_string("elepower_tome_back", minetest.serialize(back))
|
pmeta:set_string("elepower_tome_back", minetest.serialize(back))
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
table.insert(back,fields)
|
table.insert(back,fields)
|
||||||
pmeta:set_string("elepower_tome_back", minetest.serialize(back))
|
pmeta:set_string("elepower_tome_back", minetest.serialize(back))
|
||||||
end
|
end
|
||||||
|
|
||||||
if #back > 0 then
|
if #back > 0 then
|
||||||
show_back = eletome.back_button
|
show_back = eletome.back_button
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Clicked contents button on any page.
|
-- Clicked contents button on any page.
|
||||||
if fields.content then
|
if fields.content then
|
||||||
local eletome_bg = eletome.tome_bg..show_back
|
local eletome_bg = eletome.tome_bg..show_back
|
||||||
local eletome_contents = eletome.contents_page()
|
local eletome_contents = eletome.contents_page()
|
||||||
minetest.show_formspec(player:get_player_name(), "elepower_tome:tome", eletome_bg..eletome_contents)
|
minetest.show_formspec(player:get_player_name(), "elepower_tome:tome", eletome_bg..eletome_contents)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Clicked a craft link on contents
|
-- Clicked a craft link on contents
|
||||||
if fields.craft_click then
|
if fields.craft_click then
|
||||||
local eletome_bg = eletome.tome_bg..show_back
|
local eletome_bg = eletome.tome_bg..show_back
|
||||||
local eletome_craft = eletome.craft_page(fields.craft_click)
|
local eletome_craft = eletome.craft_page(fields.craft_click)
|
||||||
|
|
||||||
minetest.show_formspec(player:get_player_name(), "elepower_tome:tome", eletome_bg..eletome_craft)
|
minetest.show_formspec(player:get_player_name(), "elepower_tome:tome", eletome_bg..eletome_craft)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Clicked craft bwd/fwd button on craft sub-page
|
-- Clicked craft bwd/fwd button on craft sub-page
|
||||||
if fields.craft_bwd_fwd then
|
if fields.craft_bwd_fwd then
|
||||||
local page_num = string.match(fields.craft_bwd_fwd , "%s(%w+)%s")
|
local page_num = string.match(fields.craft_bwd_fwd , "%s(%w+)%s")
|
||||||
-- eletome.craft_page() expects description in format "something:craft_description"
|
-- eletome.craft_page() expects description in format "something:craft_description"
|
||||||
local craft_value = "cd:"..fields.description
|
local craft_value = "cd:"..fields.description
|
||||||
|
|
||||||
local eletome_bg = eletome.tome_bg..show_back
|
local eletome_bg = eletome.tome_bg..show_back
|
||||||
local eletome_craft = eletome.craft_page(craft_value,page_num)
|
local eletome_craft = eletome.craft_page(craft_value,page_num)
|
||||||
|
|
||||||
minetest.show_formspec(player:get_player_name(), "elepower_tome:tome", eletome_bg..eletome_craft)
|
minetest.show_formspec(player:get_player_name(), "elepower_tome:tome", eletome_bg..eletome_craft)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Clicked Machine page
|
-- Clicked Machine page
|
||||||
if fields.machine then
|
if fields.machine then
|
||||||
local eletome_bg = eletome.tome_bg..show_back
|
local eletome_bg = eletome.tome_bg..show_back
|
||||||
local eletome_machine = eletome.machines(fields.machine)
|
local eletome_machine = eletome.machines(fields.machine)
|
||||||
|
|
||||||
minetest.show_formspec(player:get_player_name(), "elepower_tome:tome", eletome_bg..eletome_machine)
|
minetest.show_formspec(player:get_player_name(), "elepower_tome:tome", eletome_bg..eletome_machine)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Clicked Machine bwd/fwd button on Machine page
|
-- Clicked Machine bwd/fwd button on Machine page
|
||||||
if fields.mach_bwd_fwd then
|
if fields.mach_bwd_fwd then
|
||||||
local page_num = string.match(fields.mach_bwd_fwd, "%s(%w+)%s")
|
local page_num = string.match(fields.mach_bwd_fwd, "%s(%w+)%s")
|
||||||
local mach_value = fields.description
|
local mach_value = fields.description
|
||||||
|
|
||||||
local eletome_bg = eletome.tome_bg..show_back
|
local eletome_bg = eletome.tome_bg..show_back
|
||||||
local eletome_machine = eletome.machines(mach_value,page_num)
|
local eletome_machine = eletome.machines(mach_value,page_num)
|
||||||
|
|
||||||
minetest.show_formspec(player:get_player_name(), "elepower_tome:tome", eletome_bg..eletome_machine)
|
minetest.show_formspec(player:get_player_name(), "elepower_tome:tome", eletome_bg..eletome_machine)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -147,28 +146,28 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
if fields.instructions then
|
if fields.instructions then
|
||||||
local eletome_bg = eletome.tome_bg..show_back
|
local eletome_bg = eletome.tome_bg..show_back
|
||||||
local eletome_instruct = eletome.instructions_page(fields.description)
|
local eletome_instruct = eletome.instructions_page(fields.description)
|
||||||
|
|
||||||
minetest.show_formspec(player:get_player_name(), "elepower_tome:tome", eletome_bg..eletome_instruct)
|
minetest.show_formspec(player:get_player_name(), "elepower_tome:tome", eletome_bg..eletome_instruct)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Clicked Large Image page
|
-- Clicked Large Image page
|
||||||
if fields.large_image then
|
if fields.large_image then
|
||||||
local eletome_bg = eletome.tome_bg..show_back
|
local eletome_bg = eletome.tome_bg..show_back
|
||||||
local eletome_lrg_img = eletome.large_image_page(fields.description)
|
local eletome_lrg_img = eletome.large_image_page(fields.description)
|
||||||
|
|
||||||
minetest.show_formspec(player:get_player_name(), "elepower_tome:tome", eletome_bg..eletome_lrg_img)
|
minetest.show_formspec(player:get_player_name(), "elepower_tome:tome", eletome_bg..eletome_lrg_img)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Clicked Help page
|
-- Clicked Help page
|
||||||
if fields.help then
|
if fields.help then
|
||||||
local eletome_bg = eletome.tome_bg..show_back
|
local eletome_bg = eletome.tome_bg..show_back
|
||||||
local eletome_how_use = eletome.how_use_page(fields.help)
|
local eletome_how_use = eletome.how_use_page(fields.help)
|
||||||
minetest.show_formspec(player:get_player_name(), "elepower_tome:tome", eletome_bg..eletome_how_use)
|
minetest.show_formspec(player:get_player_name(), "elepower_tome:tome", eletome_bg..eletome_how_use)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Clicked How to use page
|
-- Clicked How to use page
|
||||||
if fields.description == "action:machine-ele_user" then
|
if fields.description == "action:machine-ele_user" then
|
||||||
|
|
||||||
local how_use = false
|
local how_use = false
|
||||||
local node_name
|
local node_name
|
||||||
for k,v in pairs(eletome.ai.nodes) do
|
for k,v in pairs(eletome.ai.nodes) do
|
||||||
@ -178,26 +177,26 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
node_name = k
|
node_name = k
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if how_use then
|
if how_use then
|
||||||
local eletome_bg = eletome.tome_bg..show_back
|
local eletome_bg = eletome.tome_bg..show_back
|
||||||
local eletome_how_use = eletome.how_use_page(node_name)
|
local eletome_how_use = eletome.how_use_page(node_name)
|
||||||
minetest.show_formspec(player:get_player_name(), "elepower_tome:tome", eletome_bg..eletome_how_use)
|
minetest.show_formspec(player:get_player_name(), "elepower_tome:tome", eletome_bg..eletome_how_use)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--minetest.debug(dump(fields))
|
--minetest.debug(dump(fields))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-------------------
|
-------------------
|
||||||
-- Page Defaults --
|
-- Page Defaults --
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
eletome.tome_bg = "formspec_version[4]size[18,11]"..
|
eletome.tome_bg = "formspec_version[4]size[18,11]"..
|
||||||
"bgcolor[#003782;true]".. -- fails (my understanding limitation)
|
"bgcolor[#003782;true]".. -- fails (my understanding limitation)
|
||||||
"box[0.0,0.0;18,11;#003782]".. -- workaround the above
|
"box[0.0,0.0;18,11;#003782]".. -- workaround the above
|
||||||
"box[0.5,0.5;8.5,10;#d1caaeFF]"..
|
"box[0.5,0.5;8.5,10;#d1caaeFF]"..
|
||||||
"box[9.0,0.5;8.5,10;#d1caaeFF]"..
|
"box[9.0,0.5;8.5,10;#d1caaeFF]"..
|
||||||
"style_type[button;bgcolor=#003782]"..
|
"style_type[button;bgcolor=#003782]"..
|
||||||
@ -208,30 +207,28 @@ eletome.tome_bg = "formspec_version[4]size[18,11]"..
|
|||||||
"style[fake_prev_page;textcolor=#777777]"..
|
"style[fake_prev_page;textcolor=#777777]"..
|
||||||
"button[12.5,0;2.5,0.5;fake_prev_page;<< Prev]"..
|
"button[12.5,0;2.5,0.5;fake_prev_page;<< Prev]"..
|
||||||
"style[fake_next_page;textcolor=#777777]"..
|
"style[fake_next_page;textcolor=#777777]"..
|
||||||
"button[15,0;2.5,0.5;fake_prev_page;Next >>]"..
|
"button[15,0;2.5,0.5;fake_prev_page;Next >>]"..
|
||||||
"button_exit[17.5,0;0.5,0.5;X;X]"
|
"button_exit[17.5,0;0.5,0.5;X;X]"
|
||||||
|
|
||||||
eletome.back_button = "style[back;textcolor=#ffffff]".."button[2.5,0;2.5,0.5;back;Back]"
|
eletome.back_button = "style[back;textcolor=#ffffff]".."button[2.5,0;2.5,0.5;back;Back]"
|
||||||
eletome.font_color = "#1f1f1fFF"
|
eletome.font_color = "#1f1f1fFF"
|
||||||
eletome.y_space_line = 0.4
|
eletome.y_space_line = 0.4
|
||||||
eletome.char_per_line = 60
|
eletome.char_per_line = 60
|
||||||
eletome.tooltip_color = "#30434c;#f9f9f9"
|
eletome.tooltip_color = "#30434c;#f9f9f9"
|
||||||
|
|
||||||
-- Common style components - some end duplicates but kept for ease of reading/updating later
|
-- Common style components - some end duplicates but kept for ease of reading/updating later
|
||||||
-- s = start ie pre text
|
-- s = start ie pre text
|
||||||
-- e = end ie post text
|
-- e = end ie post text
|
||||||
-- Used for hypertext
|
-- Used for hypertext
|
||||||
eletome.common_styles = {
|
eletome.common_styles = {
|
||||||
style_h0s = "<style color="..eletome.font_color.." size=26><b><center>",
|
style_h0s = "<style color="..eletome.font_color.." size=26><b><center>",
|
||||||
style_h0e = "</center></b></style>",
|
style_h0e = "</center></b></style>",
|
||||||
style_h1s = "<style color="..eletome.font_color.." size=20><b><center>",
|
style_h1s = "<style color="..eletome.font_color.." size=20><b><center>",
|
||||||
style_h1e = "</center></b></style>",
|
style_h1e = "</center></b></style>",
|
||||||
style_h2s = "<style color="..eletome.font_color.." size=18><center>",
|
style_h2s = "<style color="..eletome.font_color.." size=18><center>",
|
||||||
style_h2e = "</center></style>",
|
style_h2e = "</center></style>",
|
||||||
style_h3s = "<style color="..eletome.font_color.." size=14><center>",
|
style_h3s = "<style color="..eletome.font_color.." size=14><center>",
|
||||||
style_h3e = "</center></style>", -- approximate default "label" size
|
style_h3e = "</center></style>", -- approximate default "label" size
|
||||||
style_h4s = "<style color="..eletome.font_color.." size=12><center>",
|
style_h4s = "<style color="..eletome.font_color.." size=12><center>",
|
||||||
style_h4e = "</center></style>"
|
style_h4e = "</center></style>"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user