[5.0.0] Formspec Theming (minor breaking change)

Post Reply
User avatar
rubenwardy
Moderator
Posts: 6978
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

[5.0.0] Formspec Theming (minor breaking change)

by rubenwardy » Post

About

Hi, 5.0.0 adds a feature which allows you to prepend a formspec string to every formspec on an opt-out basis. This can be used to theme formspecs - you can make every formspec have the same background and such by default, among other things.

Here is the code used in Minetest Game to set the default theme:

Code: Select all

minetest.register_on_joinplayer(function(player)
	player:set_formspec_prepend([[
			bgcolor[#080808BB;true]
			background[5,5;1,1;gui_formbg.png;true]
			listcolors[#00000069;#5A5A5A;#141318;#30434C;#FFF] ]])
end)

Action needed on existing mods

This will cause a minor breaking change in formspecs which don't currently use the default.gui* variables, so you'll either need to accept the consistent background or use the no_prepend[] element to disable the string being prepended to your formspec. You could instead override or modify the string set by Minetest Game's default if you wish it to be game-wide

If you have a node formspec which you'd like to modify to, eg: add no_prepend, then you will need to use an LBM:

Code: Select all

minetest.register_lbm({
	name = "mymod:formspecfix",
	nodenames = { "mymod:node" },
	action = function(pos, node)
		local meta = minetest.get_meta(pos)
		meta:set_string("formspec", mymod.get_formspec())
	end,
})
See lua_api.txt for more documentation
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

User avatar
Wuzzy
Member
Posts: 4803
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy
Contact:

Re: [5.0.0] Formspec Theming using Prepended Strings

by Wuzzy » Post

Awesome! This was much needed.
This will make formspec theming a piece of cake and hopefully the number of ugly default-themed formspecs will go down drastically.

User avatar
v-rob
Developer
Posts: 971
Joined: Thu Mar 24, 2016 03:19
GitHub: v-rob
IRC: v-rob
Location: Right behind you.

Re: [5.0.0] Formspec Theming using Prepended Strings

by v-rob » Post

Didn't this already exist? I thought I recalled seeing it somewhere. But regardless, this is awesome! Can this be used to remove the default gui things? I prefer the plain formspecs.
Core Developer | My Best Mods: Bridger - Slats - Stained Glass

User avatar
rubenwardy
Moderator
Posts: 6978
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

Re: [5.0.0] Formspec Theming using Prepended Strings

by rubenwardy » Post

v-rob wrote:Didn't this already exist? I thought I recalled seeing it somewhere.
This was added quite a few months ago, I've only just made an announcement
v-rob wrote:Can this be used to remove the default gui things? I prefer the plain formspecs.
Sure! You can make a mod to remove the background and just have a bgcolor with this feature.
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

User avatar
v-rob
Developer
Posts: 971
Joined: Thu Mar 24, 2016 03:19
GitHub: v-rob
IRC: v-rob
Location: Right behind you.

Re: [5.0.0] Formspec Theming (minor breaking change)

by v-rob » Post

Wow! This is great! This is going to be a very useful feature.
Core Developer | My Best Mods: Bridger - Slats - Stained Glass

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests