mirror of
https://github.com/ExeVirus/formspec_editor.git
synced 2025-03-15 06:01:25 +00:00
mcl2 and mtg styling support
This commit is contained in:
parent
0bb9ecd798
commit
b0be851f2d
8 changed files with 104 additions and 54 deletions
|
@ -9,12 +9,14 @@ The file *formspec.spec* in your:
|
||||||
|
|
||||||
```minetest_folder/games/formspec_editor/mods/formspec_edit```
|
```minetest_folder/games/formspec_editor/mods/formspec_edit```
|
||||||
|
|
||||||
contains a formspec you can edit and see updates of in real time.
|
contains a formspec you can edit and see updates of in real time. (You can also specify a file location with the `formspec_editor.file_path` setting.)
|
||||||
Simply add the game to MT, load up a level of *Formspec Editor*, and
|
Simply add the game to MT, load up a level of *Formspec Editor*, and
|
||||||
you will be greeted with the *formspec.spec* formspec.
|
you will be greeted with the formspec.
|
||||||
|
|
||||||
- To make edits, open the file (formspec.spec) in your editor of choice and make changes as you see fit. When you hit save, the formspec will auto-update. Best when used side by side.
|
- To make edits, open the file in your editor of choice and make changes as you see fit. When you hit save, the formspec will auto-update. Best when used side by side.
|
||||||
- To exit just hit <escape> or use a button_exit[] button. Both send the
|
- To exit just hit <escape> or use a button_exit[] button. Both send the
|
||||||
fields.quit message.
|
fields.quit message.
|
||||||
- You can test with images if you want, adding a "textures" folder to the
|
- You can test with images if you want, adding a "textures" folder to the
|
||||||
formspec_edit gamemod folder, otherwise images will default to random colors.
|
formspec_edit gamemod folder, otherwise images will default to random colors.
|
||||||
|
- You can show the formspec with builtin, minetest_game or mineclone2 styling (see the `formspec_editor.style` setting)
|
||||||
|
- You can change the refresh rate by changing the `formspec_editor.update_time` setting
|
||||||
|
|
|
@ -10,6 +10,7 @@ minetest.register_alias("mapgen_water_source", "air")
|
||||||
--Variables
|
--Variables
|
||||||
local modpath = minetest.get_modpath("formspec_edit")
|
local modpath = minetest.get_modpath("formspec_edit")
|
||||||
local insecure_env = minetest.request_insecure_environment()
|
local insecure_env = minetest.request_insecure_environment()
|
||||||
|
local io = insecure_env.io
|
||||||
local update_time = tonumber(minetest.settings:get("formspec_editor.update_time")) or 0.2
|
local update_time = tonumber(minetest.settings:get("formspec_editor.update_time")) or 0.2
|
||||||
|
|
||||||
--Load provided file if present
|
--Load provided file if present
|
||||||
|
@ -18,6 +19,12 @@ if not filepath or filepath == "" then
|
||||||
filepath = modpath .. "/formspec.spec"
|
filepath = modpath .. "/formspec.spec"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--Get styling presets
|
||||||
|
local styling = minetest.settings:get("formspec_editor.style")
|
||||||
|
if not styling or styling == "" then
|
||||||
|
styling = "builtin"
|
||||||
|
end
|
||||||
|
|
||||||
local error_formspec = [[
|
local error_formspec = [[
|
||||||
formspec_version[4]
|
formspec_version[4]
|
||||||
size[8,2]
|
size[8,2]
|
||||||
|
@ -31,51 +38,12 @@ if not minetest.is_singleplayer() then
|
||||||
error("[formspec_editor] This game doesn't work in multiplayer!")
|
error("[formspec_editor] This game doesn't work in multiplayer!")
|
||||||
end
|
end
|
||||||
|
|
||||||
--function declarations
|
|
||||||
local update_formspec = nil
|
|
||||||
local load_formspec = nil
|
|
||||||
local turn_off_hud = nil
|
|
||||||
local set_sky
|
|
||||||
|
|
||||||
--Registrations
|
|
||||||
|
|
||||||
-----------------------------------
|
|
||||||
--on_joinplayer()
|
|
||||||
-----------------------------------
|
|
||||||
minetest.register_on_joinplayer(
|
|
||||||
function(player_ref,_)
|
|
||||||
turn_off_hud(player_ref)
|
|
||||||
set_sky(player_ref)
|
|
||||||
end
|
|
||||||
)
|
|
||||||
-----------------------------------
|
|
||||||
--on_player_receive_fields()
|
|
||||||
-----------------------------------
|
|
||||||
minetest.register_on_player_receive_fields(
|
|
||||||
function(player_ref, _, fields)
|
|
||||||
if(fields.quit) then
|
|
||||||
minetest.request_shutdown()
|
|
||||||
end
|
|
||||||
update_formspec(player_ref:get_player_name())
|
|
||||||
end
|
|
||||||
)
|
|
||||||
|
|
||||||
--function definitions
|
--function definitions
|
||||||
|
|
||||||
-----------------------------------
|
|
||||||
--update_formspec()
|
|
||||||
-----------------------------------
|
|
||||||
update_formspec = function(player_name)
|
|
||||||
minetest.after(0.1, function(name)
|
|
||||||
minetest.show_formspec(name, "fs", load_formspec())
|
|
||||||
end, player_name)
|
|
||||||
end
|
|
||||||
|
|
||||||
-----------------------------------
|
-----------------------------------
|
||||||
--load_formspec()
|
--load_formspec()
|
||||||
-----------------------------------
|
-----------------------------------
|
||||||
load_formspec = function()
|
local function load_formspec()
|
||||||
local io = insecure_env.io
|
|
||||||
local file = io.open(filepath, "rb")
|
local file = io.open(filepath, "rb")
|
||||||
if file == nil then
|
if file == nil then
|
||||||
return error_formspec
|
return error_formspec
|
||||||
|
@ -90,11 +58,58 @@ load_formspec = function()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-----------------------------------
|
||||||
|
--update_formspec()
|
||||||
|
-----------------------------------
|
||||||
|
local function update_formspec(player_name)
|
||||||
|
minetest.after(0.1, function(name)
|
||||||
|
minetest.show_formspec(name, "fs", load_formspec())
|
||||||
|
end, player_name)
|
||||||
|
end
|
||||||
|
|
||||||
|
-----------------------------------
|
||||||
|
--apply_styling()
|
||||||
|
-----------------------------------
|
||||||
|
local function apply_styling(player_ref)
|
||||||
|
local prepend = ""
|
||||||
|
if styling == "minetest_game" then
|
||||||
|
------------------------------------------------
|
||||||
|
---------------Minetest Game code---------------
|
||||||
|
------------------------------------------------
|
||||||
|
prepend = [[
|
||||||
|
bgcolor[#080808BB;true]
|
||||||
|
listcolors[#00000069;#5A5A5A;#141318;#30434C;#FFF]
|
||||||
|
]]
|
||||||
|
local name = player_ref:get_player_name()
|
||||||
|
local info = minetest.get_player_information(name)
|
||||||
|
if info.formspec_version > 1 then
|
||||||
|
prepend = prepend .. "background9[5,5;1,1;mtg_gui_formbg.png;true;10]"
|
||||||
|
else
|
||||||
|
prepend = prepend .. "background[5,5;1,1;mtg_gui_formbg.png;true]"
|
||||||
|
end
|
||||||
|
elseif styling == "mineclone2" then
|
||||||
|
------------------------------------------------
|
||||||
|
---------------MineClone2 code------------------
|
||||||
|
------------------------------------------------
|
||||||
|
--Sadly, this code doesn't support inventory slot styling (texture based)
|
||||||
|
prepend = "listcolors[#9990;#FFF7;#FFF0;#000;#FFF]"..
|
||||||
|
"style_type[image_button;border=false;bgimg=mcl_inventory_button9.png;bgimg_pressed=mcl_inventory_button9_pressed.png;bgimg_middle=2,2]"..
|
||||||
|
"style_type[button;border=false;bgimg=mcl_inventory_button9.png;bgimg_pressed=mcl_inventory_button9_pressed.png;bgimg_middle=2,2]"..
|
||||||
|
"style_type[field;textcolor=#323232]"..
|
||||||
|
"style_type[label;textcolor=#323232]"..
|
||||||
|
"style_type[textarea;textcolor=#323232]"..
|
||||||
|
"style_type[checkbox;textcolor=#323232]"..
|
||||||
|
"bgcolor[#00000000]"..
|
||||||
|
"background9[1,1;1,1;mcl_base_textures_background9.png;true;7]"
|
||||||
|
end
|
||||||
|
player_ref:set_formspec_prepend(prepend)
|
||||||
|
end
|
||||||
|
|
||||||
-----------------------------------
|
-----------------------------------
|
||||||
--turn_off_hud()
|
--turn_off_hud()
|
||||||
-----------------------------------
|
-----------------------------------
|
||||||
turn_off_hud = function(player_ref)
|
local function turn_off_hud(player_ref)
|
||||||
local flags = {
|
player_ref:hud_set_flags({
|
||||||
hotbar = false,
|
hotbar = false,
|
||||||
healthbar = false,
|
healthbar = false,
|
||||||
crosshair = false,
|
crosshair = false,
|
||||||
|
@ -102,28 +117,49 @@ turn_off_hud = function(player_ref)
|
||||||
breathbar = false,
|
breathbar = false,
|
||||||
minimap = false,
|
minimap = false,
|
||||||
minimap_radar = false,
|
minimap_radar = false,
|
||||||
}
|
})
|
||||||
player_ref:hud_set_flags(flags)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-----------------------------------
|
-----------------------------------
|
||||||
--set_sky()
|
--set_sky()
|
||||||
-----------------------------------
|
-----------------------------------
|
||||||
set_sky = function(player_ref)
|
local function set_sky(player_ref)
|
||||||
local sky = {
|
player_ref:set_sky({
|
||||||
base_color = "#AAF",
|
base_color = "#AAF",
|
||||||
type = "plain",
|
type = "plain",
|
||||||
clouds = false,
|
clouds = false,
|
||||||
}
|
})
|
||||||
player_ref:set_sky(sky)
|
player_ref:set_stars({visible = false})
|
||||||
|
player_ref:set_sun({visible = false})
|
||||||
|
player_ref:set_moon({visible = false})
|
||||||
player_ref:override_day_night_ratio(0)
|
player_ref:override_day_night_ratio(0)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--Registrations
|
||||||
|
|
||||||
|
-----------------------------------
|
||||||
|
--on_joinplayer()
|
||||||
|
-----------------------------------
|
||||||
|
minetest.register_on_joinplayer(function(player_ref,_)
|
||||||
|
apply_styling(player_ref)
|
||||||
|
turn_off_hud(player_ref)
|
||||||
|
set_sky(player_ref)
|
||||||
|
end)
|
||||||
|
-----------------------------------
|
||||||
|
--on_player_receive_fields()
|
||||||
|
-----------------------------------
|
||||||
|
minetest.register_on_player_receive_fields(function(player_ref, _, fields)
|
||||||
|
if fields.quit then
|
||||||
|
minetest.request_shutdown()
|
||||||
|
end
|
||||||
|
update_formspec(player_ref:get_player_name())
|
||||||
|
end)
|
||||||
|
|
||||||
local time = 0
|
local time = 0
|
||||||
minetest.register_globalstep(function(dtime)
|
minetest.register_globalstep(function(dtime)
|
||||||
time = time + dtime
|
time = time + dtime
|
||||||
if time >= update_time then
|
if time >= update_time then
|
||||||
local player = minetest.get_connected_players()[1]
|
local player = minetest.get_connected_players()[1] --The game isn't supposed to work in multiplayer
|
||||||
if player then
|
if player then
|
||||||
update_formspec(player:get_player_name())
|
update_formspec(player:get_player_name())
|
||||||
end
|
end
|
||||||
|
|
9
mods/formspec_edit/textures/CREDITS.md
Normal file
9
mods/formspec_edit/textures/CREDITS.md
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
These textures are copied from Minetest Game and MineClone2 projects
|
||||||
|
|
||||||
|
# Minetest Game (CC BY-SA 3.0)
|
||||||
|
mtg_gui_formbg.png
|
||||||
|
|
||||||
|
# MineClone2 (CC BY-SA 3.0)
|
||||||
|
mcl_inventory_button9.png
|
||||||
|
mcl_inventory_button9_pressed.png
|
||||||
|
mcl_base_textures_background9.png
|
Binary file not shown.
After Width: | Height: | Size: 171 B |
BIN
mods/formspec_edit/textures/mcl2/mcl_inventory_button9.png
Normal file
BIN
mods/formspec_edit/textures/mcl2/mcl_inventory_button9.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 86 B |
Binary file not shown.
After Width: | Height: | Size: 86 B |
BIN
mods/formspec_edit/textures/mtg/mtg_gui_formbg.png
Normal file
BIN
mods/formspec_edit/textures/mtg/mtg_gui_formbg.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 886 B |
|
@ -1,5 +1,8 @@
|
||||||
# Formspec update time (in seconds)
|
# Formspec update time (in seconds)
|
||||||
formspec_editor.update_time (Update time) float 0.2
|
formspec_editor.update_time (Update time) float 0.2
|
||||||
|
|
||||||
# Path to the default font.
|
# Path of the formspec file
|
||||||
formspec_editor.file_path (File path) filepath
|
formspec_editor.file_path (File path) filepath
|
||||||
|
|
||||||
|
# Style type
|
||||||
|
formspec_editor.style (Formspec style) enum builtin builtin,minetest_game,mineclone2
|
Loading…
Add table
Reference in a new issue