Compare commits

..

4 Enmetoj

Author SHA1 Message Date
Jaidyn Ann f336172dfb Add /themes and /set_theme commands
Allowing the user to set their preferred theme!
2024-08-05 23:01:59 -05:00
Jaidyn Ann 26e655e2e2 Add bare-bones README 2024-08-05 22:42:56 -05:00
Jaidyn Ann 84debd93ba Adds the “Rose” theme, also by Tirifto 2024-08-05 22:25:09 -05:00
Jaidyn Ann d67bdbc27e Finish the “Restaurant” theme
Lovely theme by Tirifto <tirifto@posteo.cz>, made
originally for jam.xwx.moe.
2024-08-05 22:25:02 -05:00
14 changed files with 128 additions and 19 deletions

9
README.md Normal file
View File

@ -0,0 +1,9 @@
# fs_themes
## Credits
The themes Restaurant and Rose were made by the lovely [Tirifto](https://tirifto.xwx.moe), originally for the fediverse server [Mansardo Jamada](https://jam.xwx.moe/users/Tirifto).
## Meta
* License: [GNU LGPLv3+](COPYING.LESSER)
* Author: Jaidyn Ann (jadedctrl AT posteo.net)
* Source: https://hak.xwx.moe/jadedctrl/minetest-fs_themes

View File

@ -15,17 +15,22 @@
fs_themes = {}
fs_themes.themes = {}
fs_themes.modpath = minetest.get_modpath(minetest.get_current_modname())
local storage = minetest.get_mod_storage()
local modpath = minetest.get_modpath(minetest.get_current_modname())
-- Set a players theme by a registered themes name.
function fs_themes.set_theme(player, theme_name)
-- If dont_save is provided, the players default theme wont change.
function fs_themes.set_theme(player, theme_name, dont_save)
if not fs_themes.themes[theme_name] then
minetest.log("warning", string.format("Theme “%s” was not found.", theme_name))
return
return false
elseif not dont_save then
storage:set_string(player:get_player_name(), theme_name)
end
player:set_formspec_prepend(fs_themes.themes[theme_name])
return true
end
@ -34,25 +39,82 @@ function fs_themes.register_theme(name, formspecs_file_path)
local fs_file, open_err = io.open(formspecs_file_path, "r")
if fs_file == nil then
minetest.log("warning", string.format("Theme “%s” could not be opened: %s", name, open_err))
return
return false
end
local fs_file_contents = fs_file:read("*all")
fs_themes.themes[name] = fs_file_contents
return true
end
-- Whenever a play joins, set their formspecs theme.
minetest.register_chatcommand(
"themes",
{
description = "Lists available GUI (Formspecs) themes.",
func = function(name, param)
local ret = nil
for name,fs in pairs(fs_themes.themes) do
if ret == nil then
ret = name
else
ret = ret .. ", " .. name
end
end
if ret == nil then
ret = "No themes are installed!"
end
return true, ret
end
}
)
minetest.register_chatcommand(
"set_theme",
{
params = "<theme_name>",
description = "Sets your theme for GUI (Formspecs) windows.",
func = function(name, param)
if fs_themes.set_theme(minetest.get_player_by_name(name), param) then
return true, "Theme set!"
elseif param ~= "" then
return false, string.format("No such theme “%s”.", param)
else
return false
end
end
}
)
-- Whenever a player joins, set their formspecs theme.
minetest.register_on_joinplayer(
function(player)
local default_theme = minetest.settings:get("fs_default_theme") or "restoracio"
fs_themes.set_theme(player, default_theme)
local player_name = player:get_player_name()
local default_theme = minetest.settings:get("fs_default_theme") or "restaurant"
local player_theme = storage:get_string(player_name)
-- If a player has a preferred theme we cannot use, complain & use default.
if player_theme ~= "" and not fs_themes.set_theme(player, player_theme) then
minetest.chat_send_player(
player_name,
string.format("The theme “%s” no longer exists! Resetting preference.", player_theme))
player_theme = ""
storage:set_string(player_name, "")
end
if player_theme == "" then
fs_themes.set_theme(player, default_theme)
end
end
)
-- Register all themes in the ./themes/ directory, one by one.
local theme_dir_path = fs_themes.modpath .. "/themes/"
local theme_dir_path = modpath .. "/themes/"
local theme_file_paths = minetest.get_dir_list(theme_dir_path, false)
for _, file_name in pairs(theme_file_paths) do
fs_themes.register_theme(file_name, theme_dir_path .. file_name)

View File

@ -1 +1 @@
fs_default_theme (Default theme for Formspecs) string restoracio
fs_default_theme (Default theme for Formspecs) string restaurant

View File

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 152 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 272 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 111 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 109 B

BIN
textures/rose_gui_bg.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 154 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 168 B

24
themes/restaurant Normal file
View File

@ -0,0 +1,24 @@
style[*; textcolor=#532b2b]
bgcolor[#fadcbe;true]
background9[
5,5;1,1;restaurant_gui_bg.png;
true;
10
]
tableoptions[background=#fadcbe;highlight=#d7ff87;color=#532b2b]
listcolors[#fadcbe;#d7ff87;#a65200;#ce7f7f;#fff]
style_type[
button,image_button;
bgimg=restaurant_gui_button_bg_inactive.png;
border=false;
bgimg_middle=3,3,-4,-5
]
style_type[
button:pressed,image_button:pressed;
bgimg=restaurant_gui_button_bg_active.png;
border=false;
bgimg_middle=3,3,-3,-4
]

View File

@ -1,10 +0,0 @@
style[*;textcolor=#532b2b]
bgcolor[#fadcbe;true]
background9[5,5;1,1;restoracio_gui_bg.png;true;10]
tableoptions[background=#fadcbe;highlight=#d7ff87;color=#532b2b]
listcolors[#fadcbe;#fadcbe;#141318;#30434C;#FFF] ]]
style_type[button,image_button;bgimg=restoracio_gui_button_bg_inactive.png;border=false;bgimg_middle=4,4,-4,-6;content_offset=0,0]
style_type[button:pressed,image_button:pressed;bgimg=restoracio_gui_button_bg_active.png;border=false;bgimg_middle=4,5,-4,-6;content_offset=0,2]

24
themes/rose Normal file
View File

@ -0,0 +1,24 @@
style[*; textcolor=#532b2b]
bgcolor[#ffc7c7;true]
background9[
5,5;1,1;rose_gui_bg.png;
true;
10
]
tableoptions[background=#ffc7c7;highlight=#e0a7a7;color=#532b2b]
listcolors[#ffc7c7;#e0a7a7;#a60808;#d26767;#fff]
style_type[
button,image_button;
bgimg=rose_gui_button_bg_inactive.png;
border=false;
bgimg_middle=4,3,-4,-5
]
style_type[
button:pressed,image_button:pressed;
bgimg=rose_gui_button_bg_active.png;
border=false;
bgimg_middle=4,3,-3,-4
]