summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcheapie <no-email-for-you@example.com>2017-04-10 19:04:51 -0500
committercheapie <no-email-for-you@example.com>2017-04-10 19:05:07 -0500
commitf48e36a2c3ab15a8dbe558a14a1ed813ad9b0ec9 (patch)
tree0b3d68160677c07f46c621f617ece09a5bec96e2
parentea492d89d08bc48a413f2c29f6a143c2f308070e (diff)
downloadchat6-f48e36a2c3ab15a8dbe558a14a1ed813ad9b0ec9.tar
chat6-f48e36a2c3ab15a8dbe558a14a1ed813ad9b0ec9.tar.gz
chat6-f48e36a2c3ab15a8dbe558a14a1ed813ad9b0ec9.tar.bz2
chat6-f48e36a2c3ab15a8dbe558a14a1ed813ad9b0ec9.tar.xz
chat6-f48e36a2c3ab15a8dbe558a14a1ed813ad9b0ec9.zip
Add settings support
-rw-r--r--init.lua92
1 files changed, 76 insertions, 16 deletions
diff --git a/init.lua b/init.lua
index a7abe63..f38cae8 100644
--- a/init.lua
+++ b/init.lua
@@ -1,10 +1,70 @@
-local player_name = "cheapie"
-local highlight_color = "#4E9A06"
-local send_nick_color = "#A40000"
-local send_message_color = "#888A85"
-local join_color = "#CE5C00"
-local part_color = "#C4A000"
-local timestamps = true
+chat6 = {}
+
+local player_name = "UNKNOWN"
+minetest.register_on_connect(function()
+ player_name = minetest.localplayer:get_name()
+end)
+
+local function default_settings()
+ chat6.settings.fields.highlight_color = "#4E9A06"
+ chat6.settings.fields.send_nick_color = "#A40000"
+ chat6.settings.fields.send_message_color = "#888A85"
+ chat6.settings.fields.join_color = "#CE5C00"
+ chat6.settings.fields.part_color = "#C4A000"
+ chat6.settings.fields.timestamps = "true"
+ chat6.settings.fields.initialized = "true"
+ chat6.storage:from_table(chat6.settings)
+ minetest.display_chat_message("[chat6] Default settings loaded")
+ minetest.display_chat_message("[chat6] You can edit the settings with the \".chat6\" command.")
+end
+
+local function display_settings()
+ minetest.show_formspec("chat6:settings",
+ "size[4,7]"..
+ "label[1.25,0;chat6 Settings]"..
+ "field[0.75,1;3,1;highlight;Highlight Color;"..chat6.settings.fields.highlight_color.."]"..
+ "field[0.75,2;3,1;sendnick;Sent Message Nick Color;"..chat6.settings.fields.send_nick_color.."]"..
+ "field[0.75,3;3,1;sendmsg;Sent Message Color;"..chat6.settings.fields.send_message_color.."]"..
+ "field[0.75,4;3,1;join;Join Color;"..chat6.settings.fields.join_color.."]"..
+ "field[0.75,5;3,1;part;Part Color;"..chat6.settings.fields.part_color.."]"..
+ --"checkbox[0.75,5.5;timestamps;Show Timestamps;"..chat6.settings.fields.timestamps.."]"..
+ "button_exit[1,6.25;2,1;save;OK]"
+ )
+end
+
+chat6.storage = minetest.get_mod_storage()
+chat6.settings = chat6.storage:to_table()
+if chat6.settings.fields.initialized ~= "true" then
+ default_settings()
+end
+
+minetest.register_chatcommand("chat6",{
+ params = "",
+ description = "Open the chat6 settings menu",
+ func = display_settings,
+})
+
+local function validate_hex_color(color,default)
+ local ret = string.match(color,"^#?(%x%x%x%x%x%x)$")
+ if ret then return "#"..ret end
+ minetest.display_chat_message(string.format("[chat6] \"%s\" is not a valid hex color",color))
+ return default
+end
+
+minetest.register_on_formspec_input(function(formname,fields)
+ if formname ~= "chat6:settings" then return false end
+ if fields.save then
+ print(dump(fields))
+ chat6.settings.fields.highlight_color = validate_hex_color(fields.highlight,chat6.settings.fields.highlight_color)
+ chat6.settings.fields.send_nick_color = validate_hex_color(fields.sendnick,chat6.settings.fields.send_nick_color)
+ chat6.settings.fields.send_message_color = validate_hex_color(fields.sendmsg,chat6.settings.fields.send_message_color)
+ chat6.settings.fields.join_color = validate_hex_color(fields.join,chat6.settings.fields.join_color)
+ chat6.settings.fields.part_color = validate_hex_color(fields.part,chat6.settings.fields.part_color)
+ --chat6.settings.fields.timestamps = (fields.timestamps and "true" or "false")
+ chat6.storage:from_table(chat6.settings)
+ end
+ return true
+end)
local nick_colors = {
"#4E9A06", --19
@@ -37,7 +97,7 @@ minetest.register_on_receiving_chat_messages(function(message)
local user
local text
local timestamp = ""
- if timestamps then
+ if chat6.settings.fields.timestamps == "true" then
local date = os.date("*t",os.time())
timestamp = string.format("[%02d:%02d:%02d] ",date.hour,date.min,date.sec)
end
@@ -75,10 +135,10 @@ minetest.register_on_receiving_chat_messages(function(message)
if msgtype == "special" then
minetest.display_chat_message(timestamp..text)
elseif msgtype == "joined" then
- local coloredmsg = minetest.colorize(join_color,string.format("* %s has joined",user))
+ local coloredmsg = minetest.colorize(chat6.settings.fields.join_color,string.format("* %s has joined",user))
minetest.display_chat_message(timestamp..coloredmsg)
elseif msgtype == "left" then
- local coloredmsg = minetest.colorize(part_color,string.format("* %s has quit %s",user,text))
+ local coloredmsg = minetest.colorize(chat6.settings.fields.part_color,string.format("* %s has quit %s",user,text))
minetest.display_chat_message(timestamp..coloredmsg)
elseif msgtype == "channel" then
local colorednick = minetest.colorize(get_nick_color(user),user)
@@ -87,17 +147,17 @@ minetest.register_on_receiving_chat_messages(function(message)
local colorednick = minetest.colorize(get_nick_color(user),user)
minetest.display_chat_message(timestamp..string.format("* %s %s",colorednick,text))
elseif msgtype == "sent_channel" then
- local colorednick = minetest.colorize(send_nick_color,user)
- local coloredtext = minetest.colorize(send_message_color,text)
+ local colorednick = minetest.colorize(chat6.settings.fields.send_nick_color,user)
+ local coloredtext = minetest.colorize(chat6.settings.fields.send_message_color,text)
minetest.display_chat_message(timestamp..string.format("<%s> %s",colorednick,coloredtext))
elseif msgtype == "sent_action" then
- local colorednick = minetest.colorize(send_nick_color,user)
- local coloredtext = minetest.colorize(send_message_color,text)
+ local colorednick = minetest.colorize(chat6.settings.fields.send_nick_color,user)
+ local coloredtext = minetest.colorize(chat6.settings.fields.send_message_color,text)
minetest.display_chat_message(timestamp..string.format("* %s %s",colorednick,coloredtext))
elseif msgtype == "highlight_channel" then
- minetest.display_chat_message(timestamp..minetest.colorize(highlight_color,string.format("<%s> %s",user,text)))
+ minetest.display_chat_message(timestamp..minetest.colorize(chat6.settings.fields.highlight_color,string.format("<%s> %s",user,text)))
elseif msgtype == "highlight_action" then
- minetest.display_chat_message(timestamp..minetest.colorize(highlight_color,string.format("* %s %s",user,text)))
+ minetest.display_chat_message(timestamp..minetest.colorize(chat6.settings.fields.highlight_color,string.format("* %s %s",user,text)))
end
return true
end)