Compare commits

..

No commits in common. "b2c53ad0325932ca067b819e959b6224d9d43dad" and "f336172dfbbb16046856562b70f8e9699596f2e1" have entirely different histories.

4 changed files with 19 additions and 34 deletions

View File

@ -19,7 +19,6 @@ fs_themes.themes = {}
local storage = minetest.get_mod_storage() local storage = minetest.get_mod_storage()
local modpath = minetest.get_modpath(minetest.get_current_modname()) local modpath = minetest.get_modpath(minetest.get_current_modname())
-- Set a players theme by a registered themes name. -- Set a players theme by a registered themes name.
-- If dont_save is provided, the players default theme wont change. -- If dont_save is provided, the players default theme wont change.
function fs_themes.set_theme(player, theme_name, dont_save) function fs_themes.set_theme(player, theme_name, dont_save)
@ -35,9 +34,16 @@ function fs_themes.set_theme(player, theme_name, dont_save)
end end
-- Register a theme, given a name and a formspec string. -- Register a theme, given a name and a formspec-files path.
function fs_themes.register_theme(name, formspec_str) function fs_themes.register_theme(name, formspecs_file_path)
fs_themes.themes[name] = formspec_str 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 false
end
local fs_file_contents = fs_file:read("*all")
fs_themes.themes[name] = fs_file_contents
return true return true
end end
@ -55,9 +61,11 @@ minetest.register_chatcommand(
ret = ret .. ", " .. name ret = ret .. ", " .. name
end end
end end
if ret == nil then if ret == nil then
ret = "No themes are installed!" ret = "No themes are installed!"
end end
return true, ret return true, ret
end end
} }
@ -86,14 +94,9 @@ minetest.register_chatcommand(
minetest.register_on_joinplayer( minetest.register_on_joinplayer(
function(player) function(player)
local player_name = player:get_player_name() local player_name = player:get_player_name()
local default_theme = minetest.settings:get("fs_default_theme") local default_theme = minetest.settings:get("fs_default_theme") or "restaurant"
local player_theme = storage:get_string(player_name) local player_theme = storage:get_string(player_name)
-- Set the “default” theme (inherited from whatever mods load before fs_themes)
if not fs_themes.themes["default"] then
fs_themes.themes["default"] = player:get_formspec_prepend()
end
-- If a player has a preferred theme we cannot use, complain & use default. -- 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 if player_theme ~= "" and not fs_themes.set_theme(player, player_theme) then
minetest.chat_send_player( minetest.chat_send_player(
@ -103,7 +106,7 @@ minetest.register_on_joinplayer(
storage:set_string(player_name, "") storage:set_string(player_name, "")
end end
if player_theme == "" and default_theme and default_theme ~= "" then if player_theme == "" then
fs_themes.set_theme(player, default_theme) fs_themes.set_theme(player, default_theme)
end end
end end
@ -114,12 +117,5 @@ minetest.register_on_joinplayer(
local theme_dir_path = modpath .. "/themes/" local theme_dir_path = modpath .. "/themes/"
local theme_file_paths = minetest.get_dir_list(theme_dir_path, false) local theme_file_paths = minetest.get_dir_list(theme_dir_path, false)
for _, file_name in pairs(theme_file_paths) do for _, file_name in pairs(theme_file_paths) do
local fs_file, open_err = io.open(theme_dir_path .. file_name, "r") fs_themes.register_theme(file_name, theme_dir_path .. file_name)
if fs_file == nil then
minetest.log("warning", string.format("Theme “%s” could not be opened: %s", name, open_err))
return false
end
local fs_file_contents = fs_file:read("*all")
fs_themes.register_theme(file_name, fs_file_contents)
end end

View File

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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 243 B

View File

@ -1,6 +1,6 @@
style[*; textcolor=#532b2b] style[*; textcolor=#532b2b]
bgcolor[#fadcbe] bgcolor[#fadcbe;true]
background9[ background9[
5,5;1,1;restaurant_gui_bg.png; 5,5;1,1;restaurant_gui_bg.png;
true; true;
@ -11,25 +11,14 @@ tableoptions[background=#fadcbe;highlight=#d7ff87;color=#532b2b]
listcolors[#fadcbe;#d7ff87;#a65200;#ce7f7f;#fff] listcolors[#fadcbe;#d7ff87;#a65200;#ce7f7f;#fff]
style_type[ style_type[
button,image_button,item_image_button; button,image_button;
bgimg=restaurant_gui_button_bg_inactive.png; bgimg=restaurant_gui_button_bg_inactive.png;
border=false; border=false;
bgimg_middle=3,3,-4,-5 bgimg_middle=3,3,-4,-5
] ]
style_type[ style_type[
button:hovered,image_button:hovered,item_image_button:hovered; button:pressed,image_button:pressed;
bgimg=restaurant_gui_button_bg_hovered.png;
border=false;
bgimg_middle=3,3,-4,-5
]
style_type[
button:pressed,image_button:pressed,item_image_button:pressed;
bgimg=restaurant_gui_button_bg_active.png; bgimg=restaurant_gui_button_bg_active.png;
border=false; border=false;
bgimg_middle=3,3,-3,-4 bgimg_middle=3,3,-3,-4
] ]
style_type[
tabheader;
textcolor=white
]