mirror of
https://github.com/sirrobzeroone/elepower.git
synced 2024-11-30 10:33:44 +01:00
Tome Functionality - Add Back Button
~ Add back button to Tome/Guide ~ Move Help and Instructions into there own lua files ~ Fix minor mistake in electrolyzer tome txt Biofuel to Biomass
This commit is contained in:
parent
2e5298d40f
commit
0c13366b5a
@ -634,7 +634,7 @@ eletome.ai.nodes["elepower_machines:alloy_furnace"] = {lb_top_img = "defaul
|
||||
}
|
||||
|
||||
eletome.ai.nodes["elepower_machines:electrolyzer"] = {how_use_1 = "The Electrolyzer is used to create gases out of certain fluids. The electrolyzer can accept three "..
|
||||
"fluids/liquids, although not at the same time - water, heavy water and biofuel. The electrolyzer will "..
|
||||
"fluids/liquids, although not at the same time - water, heavy water and biomass. The electrolyzer will "..
|
||||
"at the cost of 128 EpUs a second break each down into different gases, see table below\n ",
|
||||
how_use_2 = "To extract gas from the electrolyzer you will need a fluid pump, bucketeer and an empty gas canister. "..
|
||||
"The electrolyzer can only output to a single bucketeer so you will need to empty one gas completely before "..
|
||||
|
106
elepower_tome/i_page_help.lua
Normal file
106
elepower_tome/i_page_help.lua
Normal file
@ -0,0 +1,106 @@
|
||||
---------------------------------------------------
|
||||
-- ___ _ --
|
||||
-- | __| |___ _ __ _____ __ _____ _ _ --
|
||||
-- | _|| / -_) '_ \/ _ \ V V / -_) '_| --
|
||||
-- |___|_\___| .__/\___/\_/\_/\___|_| --
|
||||
-- |_| --
|
||||
-- _____ --
|
||||
-- |_ _|__ _ __ ___ --
|
||||
-- | |/ _ \ ' \/ -_) --
|
||||
-- |_|\___/_|_|_\___| --
|
||||
---------------------------------------------------
|
||||
-- How to use/Help --
|
||||
---------------------------------------------------
|
||||
|
||||
function eletome.how_use_page(name_value)
|
||||
-- Page to view how to use a node/getting started
|
||||
--"action:getting_started"
|
||||
--"elepower_machines:electrolyzer" = ""
|
||||
|
||||
local t_split = string.split(name_value,":")
|
||||
local is_help = false
|
||||
|
||||
if t_split[1] == "action" then
|
||||
is_help = true
|
||||
end
|
||||
|
||||
-- get page heading and sub-heading
|
||||
local pg_heading
|
||||
local pg_subhead
|
||||
|
||||
if is_help then
|
||||
pg_heading = string.gsub(t_split[2],"_", " ")
|
||||
-- change all 1st letters to upper -
|
||||
-- https://stackoverflow.com/questions/20284515/capitalize-first-letter-of-every-word-in-lua
|
||||
pg_heading = string.gsub(" "..pg_heading, "%W%l", string.upper):sub(2)
|
||||
pg_subhead = "Help"
|
||||
name_value = t_split[2]
|
||||
else
|
||||
pg_heading = minetest.registered_nodes[name_value].description
|
||||
pg_subhead = "How to use"
|
||||
end
|
||||
|
||||
-- Assign Common styles to local vars
|
||||
local sty_h0s = eletome.common_styles.style_h0s
|
||||
local sty_h0e = eletome.common_styles.style_h0e
|
||||
local sty_h1s = eletome.common_styles.style_h1s
|
||||
local sty_h1e = eletome.common_styles.style_h1e
|
||||
local sty_h2s = eletome.common_styles.style_h2s
|
||||
local sty_h2e = eletome.common_styles.style_h2e
|
||||
local sty_h3s = eletome.common_styles.style_h3s
|
||||
local sty_h3e = eletome.common_styles.style_h3e
|
||||
local sty_h4s = eletome.common_styles.style_h4s
|
||||
local sty_h4e = eletome.common_styles.style_h4e
|
||||
|
||||
-- Additional Info Table
|
||||
local add_info = eletome.ai.nodes
|
||||
|
||||
---------------
|
||||
-- left page --
|
||||
---------------
|
||||
local left_image = add_info[name_value].hu_img_1 or "elepower_tome_empty.png"
|
||||
local lp_offset = 0
|
||||
|
||||
if left_image == "elepower_tome_empty.png" then
|
||||
lp_offset = 3.75
|
||||
end
|
||||
|
||||
if type(left_image) == "table" then
|
||||
left_image = add_info[name_value].hu_img_1[1]
|
||||
else
|
||||
left_image = "image[2.25,6.6;5,3.75;"..left_image.."]"
|
||||
end
|
||||
|
||||
local lp_heading = "hypertext[0.5,0.7;8.5,0.95;lp_heading;"..sty_h0s..pg_heading..sty_h0e.."]"
|
||||
local lp_sub_head = "hypertext[0.5,1.4;8.5,0.9;lp_sub_heading;"..sty_h1s..pg_subhead..sty_h1e.."]"
|
||||
local lp_image = left_image
|
||||
local lp_text = "hypertext[0.75,2.1;8.0,"..(4.5+lp_offset)..";use_txt;"..sty_h4s..(add_info[name_value].how_use_1 or "")..sty_h4e.."]"
|
||||
----------------
|
||||
-- Right page --
|
||||
----------------
|
||||
local right_image = add_info[name_value].hu_img_2 or "elepower_tome_empty.png"
|
||||
local right_txt = add_info[name_value].how_use_2 or ""
|
||||
local rp_txt_offset = 0
|
||||
local rp_img_offset = 0
|
||||
|
||||
if right_image == "elepower_tome_empty.png" then
|
||||
rp_txt_offset = 3.75
|
||||
end
|
||||
|
||||
if right_txt == "" or right_txt == nil then
|
||||
rp_img_offset = -6.1
|
||||
end
|
||||
|
||||
if type(right_image) == "table" then
|
||||
right_image = "container[9.25,"..(6.6+rp_img_offset).."]"..add_info[name_value].hu_img_2[1].."container_end[]"
|
||||
else
|
||||
right_image = "image[10.75,"..(6.6+rp_img_offset)..";5,3.75;"..right_image.."]"
|
||||
end
|
||||
|
||||
local rp_text = "hypertext[9.25,1.4;8.0,"..(4.5+rp_txt_offset)..";use_txt;"..sty_h4s..right_txt..sty_h4e.."]"
|
||||
local rp_image = right_image
|
||||
|
||||
local eletome_how_use = lp_heading..lp_sub_head..lp_image..lp_text..rp_text ..rp_image
|
||||
|
||||
return eletome_how_use
|
||||
end
|
135
elepower_tome/i_page_instructions.lua
Normal file
135
elepower_tome/i_page_instructions.lua
Normal file
@ -0,0 +1,135 @@
|
||||
---------------------------------------------------
|
||||
-- ___ _ --
|
||||
-- | __| |___ _ __ _____ __ _____ _ _ --
|
||||
-- | _|| / -_) '_ \/ _ \ V V / -_) '_| --
|
||||
-- |___|_\___| .__/\___/\_/\_/\___|_| --
|
||||
-- |_| --
|
||||
-- _____ --
|
||||
-- |_ _|__ _ __ ___ --
|
||||
-- | |/ _ \ ' \/ -_) --
|
||||
-- |_|\___/_|_|_\___| --
|
||||
---------------------------------------------------
|
||||
-- Simple Machines/Node Instructions --
|
||||
---------------------------------------------------
|
||||
|
||||
local modname = minetest.get_current_modname()
|
||||
local modpath = minetest.get_modpath(modname)
|
||||
|
||||
function eletome.instructions_page(machine)
|
||||
-- instructions page structured as 2 pages ie an open book
|
||||
-- a single column on left page and single column on the right
|
||||
-- machine structure; description = "action:machine-Miner"
|
||||
|
||||
-- remove "description = action:machine-" from string
|
||||
local machine_name = string.match(machine, "-(.*)")
|
||||
|
||||
-- remove "_"
|
||||
local mach_name = string.gsub(machine_name,"_", " ")
|
||||
|
||||
|
||||
-- Assign Common styles to local vars
|
||||
local sty_h0s = eletome.common_styles.style_h0s
|
||||
local sty_h0e = eletome.common_styles.style_h0e
|
||||
local sty_h1s = eletome.common_styles.style_h1s
|
||||
local sty_h1e = eletome.common_styles.style_h1e
|
||||
local sty_h2s = eletome.common_styles.style_h2s
|
||||
local sty_h2e = eletome.common_styles.style_h2e
|
||||
local sty_h3s = eletome.common_styles.style_h3s
|
||||
local sty_h3e = eletome.common_styles.style_h3e
|
||||
local sty_h4s = eletome.common_styles.style_h4s
|
||||
local sty_h4e = eletome.common_styles.style_h4e
|
||||
|
||||
local file_exists
|
||||
function file_exists(img_name)
|
||||
local file=io.open(img_name,"r")
|
||||
if file~=nil then
|
||||
io.close(file)
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
---------------
|
||||
-- left page --
|
||||
---------------
|
||||
local lp_heading = "hypertext[0.5,0.7;8.5,1.1;lp_heading;"..sty_h0s..mach_name..sty_h0e.."]"
|
||||
local lp_sub_head = "hypertext[0.5,1.4;8.5,1.0;lp_sub_heading;"..sty_h1s.."Instructions"..sty_h1e.."]"
|
||||
local lp_content = ""
|
||||
local rp_content = ""
|
||||
local li = 1
|
||||
local ri = 4
|
||||
|
||||
while li <= 3 do
|
||||
local img_path = modpath.."/textures/eletome_instructions_"..machine_name:lower().."_".. li ..".png"
|
||||
local file_check = file_exists(img_path)
|
||||
|
||||
if file_check then
|
||||
if (li % 2 == 0) then -- even
|
||||
lp_content = lp_content.."image[4.5,"..(2.0+(2.5*(li-1)))..";4,3;eletome_instructions_"..machine_name:lower().."_".. li ..".png]"
|
||||
else
|
||||
lp_content = lp_content.."image[1.00,"..(2.0+(2.5*(li-1)))..";4,3;eletome_instructions_"..machine_name:lower().."_".. li ..".png]"
|
||||
end
|
||||
else
|
||||
break
|
||||
end
|
||||
|
||||
li=li+1
|
||||
end
|
||||
|
||||
----------------
|
||||
-- right page --
|
||||
----------------
|
||||
while ri <= 7 do
|
||||
local img_path = modpath.."/textures/eletome_instructions_"..machine_name:lower().."_".. ri ..".png"
|
||||
local file_check = file_exists(img_path)
|
||||
|
||||
if file_check then
|
||||
if (ri % 2 ~= 0) then -- odd
|
||||
rp_content = rp_content.."image[13,"..(0.26+(2.4*(ri-4)))..";4,3;eletome_instructions_"..machine_name:lower().."_".. ri ..".png]"
|
||||
else
|
||||
rp_content = rp_content.."image[9.5,"..(0.26+(2.4*(ri-4)))..";4,3;eletome_instructions_"..machine_name:lower().."_".. ri ..".png]"
|
||||
end
|
||||
else
|
||||
break
|
||||
end
|
||||
|
||||
ri=ri+1
|
||||
end
|
||||
|
||||
|
||||
-------------------
|
||||
-- Assemble page --
|
||||
-------------------
|
||||
local eletome_inst = lp_heading..lp_sub_head..lp_content..rp_content
|
||||
|
||||
return eletome_inst
|
||||
end
|
||||
|
||||
|
||||
function eletome.large_image_page(machine)
|
||||
-- Page to view the complex machine image large size
|
||||
|
||||
-- remove "description = action:machine-" from string
|
||||
local machine_name = string.match(machine, "-(.*)")
|
||||
|
||||
-- remove "_"
|
||||
local mach_name = string.gsub(machine_name,"_", " ")
|
||||
|
||||
-- Assign Common styles to local vars
|
||||
local sty_h0s = eletome.common_styles.style_h0s
|
||||
local sty_h0e = eletome.common_styles.style_h0e
|
||||
|
||||
local heading = "hypertext[0.5,0.7;17.5,1.1;lp_heading;"..sty_h0s..mach_name..sty_h0e.."]"
|
||||
local image ="style_type[image_button;bgimg=elepower_tome_bgimg_1.png]"..
|
||||
"image_button[2.33,0.5;13.33,10;"..eletome.ai[machine_name:lower()].img..";instructions;]"..
|
||||
"tooltip[2.33,0.5;13.33,10;Click for detailed\ninstructions;"..eletome.tooltip_color.."]"
|
||||
|
||||
|
||||
-- Pass page reference value to player recieve fields when fwd/bwd pressed - not visible on formspec
|
||||
heading = heading .."field[10,12;1,0.5;description;;action:machine-"..machine_name.."]"
|
||||
|
||||
local eletome_lrg_img = image..heading
|
||||
|
||||
return eletome_lrg_img
|
||||
end
|
@ -27,6 +27,8 @@ dofile(modpath .. "/i_functions.lua")
|
||||
dofile(modpath .. "/i_page_contents.lua")
|
||||
dofile(modpath .. "/i_page_crafts.lua")
|
||||
dofile(modpath .. "/i_page_machines.lua")
|
||||
dofile(modpath .. "/i_page_instructions.lua")
|
||||
dofile(modpath .. "/i_page_help.lua")
|
||||
|
||||
-- register our Tome/Book item
|
||||
minetest.register_craftitem("elepower_tome:tome", {
|
||||
@ -43,27 +45,70 @@ minetest.register_craftitem("elepower_tome:tome", {
|
||||
})
|
||||
|
||||
|
||||
-- Give player elepower tome on initaial logon
|
||||
-- Give player elepower tome on initial logon
|
||||
minetest.register_on_newplayer(function(player)
|
||||
player:get_inventory():add_item("main", "elepower_tome:tome")
|
||||
end)
|
||||
|
||||
-- Player tome meta - setup back button meta
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
local pmeta = player:get_meta()
|
||||
local back = {}
|
||||
pmeta:set_string("elepower_tome_back", minetest.serialize(back))
|
||||
end)
|
||||
|
||||
-- register our recieve field callback
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
|
||||
if formname ~= "elepower_tome:tome" then
|
||||
return
|
||||
end
|
||||
|
||||
-- Back Button
|
||||
local pmeta = player:get_meta()
|
||||
local back = minetest.deserialize(pmeta:get_string("elepower_tome_back"))
|
||||
local show_back = ""
|
||||
|
||||
if fields.quit == "true" then
|
||||
back = {}
|
||||
pmeta:set_string("elepower_tome_back", minetest.serialize(back))
|
||||
|
||||
elseif fields.back then
|
||||
local prev_page = #back-1
|
||||
|
||||
if prev_page <= 0 then
|
||||
-- must be going back to contents
|
||||
fields = {}
|
||||
back = {}
|
||||
pmeta:set_string("elepower_tome_back", minetest.serialize(back))
|
||||
fields.content = "Content"
|
||||
else
|
||||
fields = back[prev_page]
|
||||
table.remove(back,#back)
|
||||
table.remove(back,#back-1)
|
||||
pmeta:set_string("elepower_tome_back", minetest.serialize(back))
|
||||
end
|
||||
else
|
||||
table.insert(back,fields)
|
||||
pmeta:set_string("elepower_tome_back", minetest.serialize(back))
|
||||
end
|
||||
|
||||
minetest.debug(dump(back))
|
||||
|
||||
if #back > 0 then
|
||||
show_back = eletome.back_button
|
||||
end
|
||||
|
||||
-- Clicked contents button on any page.
|
||||
if fields.content then
|
||||
local eletome_bg = eletome.tome_bg
|
||||
local eletome_bg = eletome.tome_bg..show_back
|
||||
local eletome_contents = eletome.contents_page()
|
||||
minetest.show_formspec(player:get_player_name(), "elepower_tome:tome", eletome_bg..eletome_contents)
|
||||
end
|
||||
|
||||
-- Clicked a craft link on contents
|
||||
if fields.craft_click then
|
||||
local eletome_bg = eletome.tome_bg
|
||||
local eletome_bg = eletome.tome_bg..show_back
|
||||
local eletome_craft = eletome.craft_page(fields.craft_click)
|
||||
|
||||
minetest.show_formspec(player:get_player_name(), "elepower_tome:tome", eletome_bg..eletome_craft)
|
||||
@ -75,7 +120,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
-- eletome.craft_page() expects description in format "something:craft_description"
|
||||
local craft_value = "cd:"..fields.description
|
||||
|
||||
local eletome_bg = eletome.tome_bg
|
||||
local eletome_bg = eletome.tome_bg..show_back
|
||||
local eletome_craft = eletome.craft_page(craft_value,page_num)
|
||||
|
||||
minetest.show_formspec(player:get_player_name(), "elepower_tome:tome", eletome_bg..eletome_craft)
|
||||
@ -83,7 +128,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
|
||||
-- Clicked Machine page
|
||||
if fields.machine then
|
||||
local eletome_bg = eletome.tome_bg
|
||||
local eletome_bg = eletome.tome_bg..show_back
|
||||
local eletome_machine = eletome.machines(fields.machine)
|
||||
|
||||
minetest.show_formspec(player:get_player_name(), "elepower_tome:tome", eletome_bg..eletome_machine)
|
||||
@ -94,7 +139,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
local page_num = string.match(fields.mach_bwd_fwd, "%s(%w+)%s")
|
||||
local mach_value = fields.description
|
||||
|
||||
local eletome_bg = eletome.tome_bg
|
||||
local eletome_bg = eletome.tome_bg..show_back
|
||||
local eletome_machine = eletome.machines(mach_value,page_num)
|
||||
|
||||
minetest.show_formspec(player:get_player_name(), "elepower_tome:tome", eletome_bg..eletome_machine)
|
||||
@ -102,7 +147,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
|
||||
-- Clicked Instructions page
|
||||
if fields.instructions then
|
||||
local eletome_bg = eletome.tome_bg
|
||||
local eletome_bg = eletome.tome_bg..show_back
|
||||
local eletome_instruct = eletome.instructions_page(fields.description)
|
||||
|
||||
minetest.show_formspec(player:get_player_name(), "elepower_tome:tome", eletome_bg..eletome_instruct)
|
||||
@ -110,7 +155,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
|
||||
-- Clicked Large Image page
|
||||
if fields.large_image then
|
||||
local eletome_bg = eletome.tome_bg
|
||||
local eletome_bg = eletome.tome_bg..show_back
|
||||
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)
|
||||
@ -118,7 +163,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
|
||||
-- Clicked Help page
|
||||
if fields.help then
|
||||
local eletome_bg = eletome.tome_bg
|
||||
local eletome_bg = eletome.tome_bg..show_back
|
||||
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)
|
||||
end
|
||||
@ -139,7 +184,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
end
|
||||
|
||||
if how_use then
|
||||
local eletome_bg = eletome.tome_bg
|
||||
local eletome_bg = eletome.tome_bg..show_back
|
||||
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)
|
||||
end
|
||||
@ -168,7 +213,7 @@ eletome.tome_bg = "formspec_version[4]size[18,11]"..
|
||||
"button[15,0;2.5,0.5;fake_prev_page;Next >>]"..
|
||||
"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.font_color = "#1f1f1fFF"
|
||||
eletome.y_space_line = 0.4
|
||||
eletome.char_per_line = 60
|
||||
@ -191,214 +236,4 @@ eletome.common_styles = {
|
||||
style_h4e = "</center></style>"
|
||||
|
||||
}
|
||||
|
||||
function eletome.instructions_page(machine)
|
||||
-- instructions page structured as 2 pages ie an open book
|
||||
-- a single column on left page and single column on the right
|
||||
-- machine structure; description = "action:machine-Miner"
|
||||
|
||||
-- remove "description = action:machine-" from string
|
||||
local machine_name = string.match(machine, "-(.*)")
|
||||
|
||||
-- remove "_"
|
||||
local mach_name = string.gsub(machine_name,"_", " ")
|
||||
|
||||
|
||||
-- Assign Common styles to local vars
|
||||
local sty_h0s = eletome.common_styles.style_h0s
|
||||
local sty_h0e = eletome.common_styles.style_h0e
|
||||
local sty_h1s = eletome.common_styles.style_h1s
|
||||
local sty_h1e = eletome.common_styles.style_h1e
|
||||
local sty_h2s = eletome.common_styles.style_h2s
|
||||
local sty_h2e = eletome.common_styles.style_h2e
|
||||
local sty_h3s = eletome.common_styles.style_h3s
|
||||
local sty_h3e = eletome.common_styles.style_h3e
|
||||
local sty_h4s = eletome.common_styles.style_h4s
|
||||
local sty_h4e = eletome.common_styles.style_h4e
|
||||
|
||||
function file_exists(img_name)
|
||||
local file=io.open(img_name,"r")
|
||||
if file~=nil then
|
||||
io.close(file)
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
---------------
|
||||
-- left page --
|
||||
---------------
|
||||
local lp_heading = "hypertext[0.5,0.7;8.5,1.1;lp_heading;"..sty_h0s..mach_name..sty_h0e.."]"
|
||||
local lp_sub_head = "hypertext[0.5,1.4;8.5,1.0;lp_sub_heading;"..sty_h1s.."Instructions"..sty_h1e.."]"
|
||||
local lp_content = ""
|
||||
local rp_content = ""
|
||||
local li = 1
|
||||
local ri = 4
|
||||
|
||||
while li <= 3 do
|
||||
local img_path = modpath.."/textures/eletome_instructions_"..machine_name:lower().."_".. li ..".png"
|
||||
local file_check = file_exists(img_path)
|
||||
|
||||
if file_check then
|
||||
if (li % 2 == 0) then -- even
|
||||
lp_content = lp_content.."image[4.5,"..(2.0+(2.5*(li-1)))..";4,3;eletome_instructions_"..machine_name:lower().."_".. li ..".png]"
|
||||
else
|
||||
lp_content = lp_content.."image[1.00,"..(2.0+(2.5*(li-1)))..";4,3;eletome_instructions_"..machine_name:lower().."_".. li ..".png]"
|
||||
end
|
||||
else
|
||||
break
|
||||
end
|
||||
|
||||
li=li+1
|
||||
end
|
||||
|
||||
----------------
|
||||
-- right page --
|
||||
----------------
|
||||
while ri <= 7 do
|
||||
local img_path = modpath.."/textures/eletome_instructions_"..machine_name:lower().."_".. ri ..".png"
|
||||
local file_check = file_exists(img_path)
|
||||
|
||||
if file_check then
|
||||
if (ri % 2 ~= 0) then -- odd
|
||||
rp_content = rp_content.."image[13,"..(0.26+(2.4*(ri-4)))..";4,3;eletome_instructions_"..machine_name:lower().."_".. ri ..".png]"
|
||||
else
|
||||
rp_content = rp_content.."image[9.5,"..(0.26+(2.4*(ri-4)))..";4,3;eletome_instructions_"..machine_name:lower().."_".. ri ..".png]"
|
||||
end
|
||||
else
|
||||
break
|
||||
end
|
||||
|
||||
ri=ri+1
|
||||
end
|
||||
|
||||
|
||||
-------------------
|
||||
-- Assemble page --
|
||||
-------------------
|
||||
local eletome_inst = lp_heading..lp_sub_head..lp_content..rp_content
|
||||
|
||||
return eletome_inst
|
||||
end
|
||||
|
||||
|
||||
function eletome.large_image_page(machine)
|
||||
-- Page to view the complex machine image large size
|
||||
|
||||
-- remove "description = action:machine-" from string
|
||||
local machine_name = string.match(machine, "-(.*)")
|
||||
|
||||
-- remove "_"
|
||||
local mach_name = string.gsub(machine_name,"_", " ")
|
||||
|
||||
-- Assign Common styles to local vars
|
||||
local sty_h0s = eletome.common_styles.style_h0s
|
||||
local sty_h0e = eletome.common_styles.style_h0e
|
||||
|
||||
local heading = "hypertext[0.5,0.7;17.5,1.1;lp_heading;"..sty_h0s..mach_name..sty_h0e.."]"
|
||||
local image ="style_type[image_button;bgimg=elepower_tome_bgimg_1.png]"..
|
||||
"image_button[2.33,0.5;13.33,10;"..eletome.ai[machine_name:lower()].img..";instructions;]"..
|
||||
"tooltip[2.33,0.5;13.33,10;Click for detailed\ninstructions;"..eletome.tooltip_color.."]"
|
||||
|
||||
|
||||
-- Pass page reference value to player recieve fields when fwd/bwd pressed - not visible on formspec
|
||||
heading = heading .."field[10,12;1,0.5;description;;action:machine-"..machine_name.."]"
|
||||
|
||||
local eletome_lrg_img = image..heading
|
||||
|
||||
return eletome_lrg_img
|
||||
end
|
||||
|
||||
function eletome.how_use_page(name_value)
|
||||
-- Page to view how to use a node/getting started
|
||||
--"action:getting_started"
|
||||
--"elepower_machines:electrolyzer" = ""
|
||||
|
||||
local t_split = string.split(name_value,":")
|
||||
local is_help = false
|
||||
|
||||
if t_split[1] == "action" then
|
||||
is_help = true
|
||||
end
|
||||
|
||||
-- get page heading and sub-heading
|
||||
local pg_heading
|
||||
local pg_subhead
|
||||
|
||||
if is_help then
|
||||
pg_heading = string.gsub(t_split[2],"_", " ")
|
||||
-- change all 1st letters to upper -
|
||||
-- https://stackoverflow.com/questions/20284515/capitalize-first-letter-of-every-word-in-lua
|
||||
pg_heading = string.gsub(" "..pg_heading, "%W%l", string.upper):sub(2)
|
||||
pg_subhead = "Help"
|
||||
name_value = t_split[2]
|
||||
else
|
||||
pg_heading = minetest.registered_nodes[name_value].description
|
||||
pg_subhead = "How to use"
|
||||
end
|
||||
|
||||
-- Assign Common styles to local vars
|
||||
local sty_h0s = eletome.common_styles.style_h0s
|
||||
local sty_h0e = eletome.common_styles.style_h0e
|
||||
local sty_h1s = eletome.common_styles.style_h1s
|
||||
local sty_h1e = eletome.common_styles.style_h1e
|
||||
local sty_h2s = eletome.common_styles.style_h2s
|
||||
local sty_h2e = eletome.common_styles.style_h2e
|
||||
local sty_h3s = eletome.common_styles.style_h3s
|
||||
local sty_h3e = eletome.common_styles.style_h3e
|
||||
local sty_h4s = eletome.common_styles.style_h4s
|
||||
local sty_h4e = eletome.common_styles.style_h4e
|
||||
|
||||
-- Additional Info Table
|
||||
local add_info = eletome.ai.nodes
|
||||
|
||||
---------------
|
||||
-- left page --
|
||||
---------------
|
||||
local left_image = add_info[name_value].hu_img_1 or "elepower_tome_empty.png"
|
||||
local lp_offset = 0
|
||||
|
||||
if left_image == "elepower_tome_empty.png" then
|
||||
lp_offset = 3.75
|
||||
end
|
||||
|
||||
if type(left_image) == "table" then
|
||||
left_image = add_info[name_value].hu_img_1[1]
|
||||
else
|
||||
left_image = "image[2.25,6.6;5,3.75;"..left_image.."]"
|
||||
end
|
||||
|
||||
local lp_heading = "hypertext[0.5,0.7;8.5,0.95;lp_heading;"..sty_h0s..pg_heading..sty_h0e.."]"
|
||||
local lp_sub_head = "hypertext[0.5,1.4;8.5,0.9;lp_sub_heading;"..sty_h1s..pg_subhead..sty_h1e.."]"
|
||||
local lp_image = left_image
|
||||
local lp_text = "hypertext[0.75,2.1;8.0,"..(4.5+lp_offset)..";use_txt;"..sty_h4s..(add_info[name_value].how_use_1 or "")..sty_h4e.."]"
|
||||
----------------
|
||||
-- Right page --
|
||||
----------------
|
||||
local right_image = add_info[name_value].hu_img_2 or "elepower_tome_empty.png"
|
||||
local right_txt = add_info[name_value].how_use_2 or ""
|
||||
local rp_txt_offset = 0
|
||||
local rp_img_offset = 0
|
||||
|
||||
if right_image == "elepower_tome_empty.png" then
|
||||
rp_txt_offset = 3.75
|
||||
end
|
||||
|
||||
if right_txt == "" or right_txt == nil then
|
||||
rp_img_offset = -6.1
|
||||
end
|
||||
|
||||
if type(right_image) == "table" then
|
||||
right_image = "container[9.25,"..(6.6+rp_img_offset).."]"..add_info[name_value].hu_img_2[1].."container_end[]"
|
||||
else
|
||||
right_image = "image[10.75,"..(6.6+rp_img_offset)..";5,3.75;"..right_image.."]"
|
||||
end
|
||||
|
||||
local rp_text = "hypertext[9.25,1.4;8.0,"..(4.5+rp_txt_offset)..";use_txt;"..sty_h4s..right_txt..sty_h4e.."]"
|
||||
local rp_image = right_image
|
||||
|
||||
local eletome_how_use = lp_heading..lp_sub_head..lp_image..lp_text..rp_text ..rp_image
|
||||
|
||||
return eletome_how_use
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user