added settings tab + added default.register_gui_color_theme

This commit is contained in:
cale 2016-09-29 17:53:12 +02:00
parent b2784e0bfc
commit 4ecd4b33de
2 changed files with 78 additions and 57 deletions

View File

@ -33,20 +33,38 @@ function character_editor.set_texture(player, pos, texture)
character_editor.update_character(player)
end
character_editor.window = "size[8,7.5;]"
character_editor.window = character_editor.window .. default.gui_colors
character_editor.window = character_editor.window .. default.gui_bg
character_editor.window = character_editor.window .. "label[0,0;Select your language! All dialogs will be translated\nin this language. Items are not translated.\nIf you cant find your language in this list,\n pls send a private message to cd2 on the minetest forums.]"
character_editor.window = character_editor.window .. "button[3,2;2,1;lang_EN;EN]"
character_editor.window = character_editor.window .. "button[3,3;2,1;lang_DE;DE]"
character_editor.window = character_editor.window .. "button[3,4;2,1;lang_FR;FR]"
character_editor.window = character_editor.window .. "button[3,6;2,1;lang_ID;ID]"
character_editor.window = character_editor.window .. "button[3,5;2,1;lang_TR;TR]"
function character_editor.show_window(player)
local name = player:get_player_name()
minetest.show_formspec(name, "character_editor:language", character_editor.window)
end
default.player_inventory.register_tab({
name = "Settings",
type = "normal",
formspec = "size[8,7.5;]" ..
default.gui_colors ..
default.gui_bg ..
"label[0,0;Language:]" ..
"button[0,0.5;1,1;lang_EN;EN]" ..
"button[1,0.5;1,1;lang_DE;DE]" ..
"button[2,0.5;1,1;lang_FR;FR]" ..
"button[3,0.5;1,1;lang_ID;ID]" ..
"button[4,0.5;1,1;lang_TR;TR]",
on_event = function(player, fields)
local name = player:get_player_name()
if fields["lang_EN"] then
print("EN")
character_editor.language[name] = ""
elseif fields["lang_DE"] then
print("DE")
character_editor.language[name] = "de/"
elseif fields["lang_FR"] then
print("FR")
character_editor.language[name] = "fr/"
elseif fields["lang_ID"] then
print("ID")
character_editor.language[name] = "id/"
elseif fields["lang_TR"] then
print("TR")
character_editor.language[name] = "tr/"
end
end
})
minetest.register_chatcommand("shirt", {
params = "<name>",
@ -67,29 +85,5 @@ minetest.register_on_joinplayer(function(player)
character_editor.mesh[player:get_player_name()] = "character.x"
character_editor.characters[player:get_player_name()] = {}
character_editor.set_texture(player, 1, "character.png")
character_editor.show_window(player)
end)
minetest.register_on_player_receive_fields(function(player, formname, fields)
if formname == "character_editor:language" then
print("FORM")
print("Player "..player:get_player_name().." submitted fields "..dump(fields))
local name = player:get_player_name()
if fields["lang_EN"] then
print("EN")
character_editor.language[name] = ""
elseif fields["lang_DE"] then
print("DE")
character_editor.language[name] = "de/"
elseif fields["lang_FR"] then
print("FR")
character_editor.language[name] = "fr/"
elseif fields["lang_ID"] then
print("ID")
character_editor.language[name] = "id/"
elseif fields["lang_TR"] then
print("TR")
character_editor.language[name] = "tr/"
end
end
end)

View File

@ -4,15 +4,22 @@ default.player_inventory.tabs = {}
default.player_inventory.contexts = {}
function default.player_inventory.register_tab(def)
def.type = def.type or "normal"
table.insert(default.player_inventory.tabs, def)
end
function default.player_inventory.get_formspec(tab)
function default.player_inventory.get_formspec(tab, name)
if not(default.player_inventory.tabs[tab]) then
return ""
end
local formspec = default.player_inventory.tabs[tab].formspec
local formspec = ""
if default.player_inventory.tabs[tab].type == "function" then
formspec = default.player_inventory.tabs[tab].get_formspec(name)
else
formspec = default.player_inventory.tabs[tab].formspec
end
local tabs = {}
for i,v in ipairs(default.player_inventory.tabs) do
@ -47,7 +54,7 @@ function default.player_inventory.update(player)
end
local tab = default.player_inventory.contexts[name].tab or 1
local formspec = default.player_inventory.get_formspec(tab)
local formspec = default.player_inventory.get_formspec(tab, name)
player:set_inventory_formspec(string.format(formspec, player:get_player_name()))
end
@ -69,6 +76,11 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if fields.tabs then
default.player_inventory.set_tab(name, tonumber(fields.tabs))
default.player_inventory.update(player)
else
if not(default.player_inventory.contexts[name]) then return end
if not(default.player_inventory.tabs[default.player_inventory.contexts[name].tab]) then return end
if not(default.player_inventory.tabs[default.player_inventory.contexts[name].tab]).on_event then return end
default.player_inventory.tabs[default.player_inventory.contexts[name].tab].on_event(player, fields)
end
end)
@ -86,24 +98,39 @@ function default.itemslot_bg(x,y,w,h)
end
end
if default.gui_color_theme == 1 then
default.gui_bg = "bgcolor[#a88e69FF;false]"
default.gui_colors = "listcolors[#00000000;#10101030;#00000000;#68B259;#FFF]"
default.text_color = "#FFF"
elseif default.gui_color_theme == 2 then
default.gui_bg = "bgcolor[#333333FF;false]"
default.gui_colors = "listcolors[#222222FF;#333333FF;#000000FF;#444444FF;#FFF]"
default.text_color = "#FFF"
elseif default.gui_color_theme == 3 then
default.gui_bg = "bgcolor[#CCCCCCFF;false]"
default.gui_colors = "listcolors[#AAAAAAFF;#777777FF;#666666FF;#444444FF;#FFF]"
default.text_color = "#000"
elseif default.gui_color_theme == 4 then
default.gui_bg = "bgcolor[#00000000;false]"
default.gui_colors = "listcolors[#00000022;#44444477;#000000FF;#444444FF;#FFF]"
default.text_color = "#FFF"
default.gui_color_themes = {}
function default.register_gui_color_theme(def)
table.insert(default.gui_color_themes, def)
end
function default.set_gui_color_theme(x)
default.gui_bg = default.gui_color_themes[x].background
default.gui_colors = default.gui_color_themes[x].colors
end
default.register_gui_color_theme({
background = "bgcolor[#a88e69FF;false]",
colors = "listcolors[#00000000;#10101030;#00000000;#68B259;#FFF]"
})
default.register_gui_color_theme({
background = "bgcolor[#333333FF;false]",
colors = "listcolors[#222222FF;#333333FF;#000000FF;#444444FF;#FFF]"
})
default.register_gui_color_theme({
background = "bgcolor[#CCCCCCFF;false]",
colors = "listcolors[#AAAAAAFF;#777777FF;#666666FF;#444444FF;#FFF]"
})
default.register_gui_color_theme({
background = "bgcolor[#99999933;false]",
colors = "listcolors[#00000022;#44444477;#000000FF;#444444FF;#FFF]"
})
default.set_gui_color_theme(default.gui_color_theme)
default.inv_form = default.player_inventory.get_default_inventory_formspec()
default.inv_form = default.inv_form.."list[current_player;craft;1.5,1;3,1;]"
default.inv_form = default.inv_form..default.itemslot_bg(1.5,1,3,1)