diff --git a/mods/artifact_characters/textures/artifact_key_splash_low.png b/mods/artifact_characters/textures/artifact_key_splash_low.png index 3d804ee..d31b992 100644 Binary files a/mods/artifact_characters/textures/artifact_key_splash_low.png and b/mods/artifact_characters/textures/artifact_key_splash_low.png differ diff --git a/mods/artifact_characters/textures/artifact_vix_splash.png b/mods/artifact_characters/textures/artifact_vix_splash.png index d87be46..74076f3 100644 Binary files a/mods/artifact_characters/textures/artifact_vix_splash.png and b/mods/artifact_characters/textures/artifact_vix_splash.png differ diff --git a/mods/artifact_characters/textures/artifact_vix_splash_low.png b/mods/artifact_characters/textures/artifact_vix_splash_low.png index 5d1c625..8ddb52d 100644 Binary files a/mods/artifact_characters/textures/artifact_vix_splash_low.png and b/mods/artifact_characters/textures/artifact_vix_splash_low.png differ diff --git a/mods/artifact_chat/init.lua b/mods/artifact_chat/init.lua new file mode 100644 index 0000000..99ae760 --- /dev/null +++ b/mods/artifact_chat/init.lua @@ -0,0 +1,149 @@ +local ns = artifact + +local hud_pop_times = {} + +function ns.push_chat_message(msg, sender, splash, duration) + for name, m in pairs(artifact.players) do + local box = {} + local w = minetest.get_player_window_information(name).size.x + local y = (#m.chat *75) + box.left = artifact.hud_add(m, { + type = "image", + name = ""..math.random(), + pos = {x=0,y=0}, + offset={x=8,y=12 +y}, + align = {x=1,y=1}, + scale = {x=4,y=4}, + image = "artifact_chat_box_side.png" + }) + box.middle = artifact.hud_add(m, { + type = "image", + name = ""..math.random(), + pos = {x=0,y=0}, + offset={x=12,y=12 +y}, + align = {x=1,y=1}, + scale = {x=w -24,y=4}, + image = "artifact_chat_box_middle.png" + }) + box.right = artifact.hud_add(m, { + type = "image", + name = ""..math.random(), + pos = {x=1,y=0}, + offset={x=-8,y=12 +y}, + align = {x=-1,y=1}, + scale = {x=4,y=4}, + image = "artifact_chat_box_side.png" + }) + if sender then msg = "["..sender.."] "..msg end + local i = 0 + local str = "" + for x in msg:gmatch("(%s*[^%s]+%s*)") do + if (#str +#x) *8 < w -100 then + str = str..x + else + box["text"..i] = artifact.hud_add(m, { + type = "text", + name = ""..math.random(), + pos = {x=0,y=0}, + padding_y = 10 +(i *18), + offset={x=64,y=22 +(i *18) +y}, + align = {x=1,y=1}, + text = str + }) + str = x + i = i +1 + end + end + box["text"..i] = artifact.hud_add(m, { + type = "text", + name = ""..math.random(), + pos = {x=0,y=0}, + padding_y = 10 +(i *18), + offset={x=64,y=22 +(i *18) +y}, + align = {x=1,y=1}, + text = str + }) +-- if sender then +-- box.name = artifact.hud_add(m, { +-- type = "text", +-- pos = {x=0,y=0}, +-- padding_y = 30, +-- offset={x=15,y=42 +y}, +-- align = {x=1,y=1}, +-- text = sender +-- }) +-- end + if splash then + box.splash = artifact.hud_add(m, { + type = "image", + pos = {x=0,y=0}, + padding_y = 25, + offset={x=32,y=37 +y}, + align = {x=0,y=0}, +-- scale = {x=0.5,y=0.5}, + image = splash + }) + end + m.chat[#m.chat +1] = box + end + -- Ensure that messages auto-pop strictly in order, in case of different durations. + -- If a message would cause a pop before its predecessor expires, its pop time is + -- pushed forward to immediately follow that of the last visible message. + table.insert(hud_pop_times, math.max(hud_pop_times[#hud_pop_times] or 0, (duration or 15) *1000000 +minetest.get_us_time())) + -- Track pop jobs to get the number of active messages, since the actual HUD is stored in each player. + if #hud_pop_times > 5 then + ns.pop_chat_message() + end + -- Write the message to the chat log. (Note that `msg` is updated above to include the sender name, if present.) + minetest.chat_send_all(msg) +end + +function ns.pop_chat_message() + table.remove(hud_pop_times, 1) + for _, m in pairs(artifact.players) do + for _, x in pairs(m.chat[1]) do + x:remove(m) + end + table.remove(m.chat, 1) + for i, x in ipairs(m.chat) do + local y = (i -1) *75 + for _, el in pairs(x) do + el:animate { + offset = { + value = {x=el.offset.x, y=12 +y +(el.padding_y or 0)}, + duration = 0.3 + } + } + end + end + end +end + + +minetest.register_on_chat_message(function(name, msg) + ns.push_chat_message(msg, name) + return true +end) + +minetest.register_globalstep(function() + local time = minetest.get_us_time() + if time >= (hud_pop_times[1] or math.huge) then + ns.pop_chat_message() + end +end) + +if artifact.debug then + + minetest.register_chatcommand("key", { + func = function(name, args) + ns.push_chat_message(args, "Key", "artifact_key_splash_low.png") + end + }) + + minetest.register_chatcommand("vix", { + func = function(name, args) + ns.push_chat_message(args, "Vix", "artifact_vix_splash_low.png") + end + }) + +end diff --git a/mods/artifact_chat/mod.conf b/mods/artifact_chat/mod.conf new file mode 100644 index 0000000..fcf1e4a --- /dev/null +++ b/mods/artifact_chat/mod.conf @@ -0,0 +1,2 @@ +name = artifact_chat +depends = artifact_hud \ No newline at end of file diff --git a/mods/artifact_chat/textures/artifact_chat_box_middle.png b/mods/artifact_chat/textures/artifact_chat_box_middle.png new file mode 100644 index 0000000..15097d8 Binary files /dev/null and b/mods/artifact_chat/textures/artifact_chat_box_middle.png differ diff --git a/mods/artifact_chat/textures/artifact_chat_box_side.png b/mods/artifact_chat/textures/artifact_chat_box_side.png new file mode 100644 index 0000000..b688404 Binary files /dev/null and b/mods/artifact_chat/textures/artifact_chat_box_side.png differ diff --git a/mods/artifact_hud/init.lua b/mods/artifact_hud/init.lua index 8049304..9290eb6 100644 --- a/mods/artifact_hud/init.lua +++ b/mods/artifact_hud/init.lua @@ -77,6 +77,11 @@ function ns.hud_add(m, def) if type.defaults then def = extend(table.copy(type.defaults), def) end + -- Create a random name if none is given, since the + -- assumption is that the user doesn't care about the name. + if not def.name then + def.name = ""..math.random() + end local el if m.hud[def.name] then el = m.hud[def.name] @@ -222,8 +227,11 @@ ns.register_hud_type { end end, remove = function(e, m) + m.hud[e.name] = nil m.object:hud_remove(e._id) e._id = nil + -- Prevent ongoing animations from attempting to change a nonexistent element. + e.update = function() end end } @@ -270,5 +278,7 @@ ns.register_hud_type { m.hud[e.name] = nil m.object:hud_remove(e._id) e._id = nil + -- Prevent ongoing animations from attempting to change a nonexistent element. + e.update = function() end end } diff --git a/mods/artifact_player/init.lua b/mods/artifact_player/init.lua index fcbcc1f..d52e3c9 100644 --- a/mods/artifact_player/init.lua +++ b/mods/artifact_player/init.lua @@ -47,11 +47,13 @@ Player = setmetatable({ breathbar = false, hotbar = artifact.debug, minimap = false, - basic_debug = false + basic_debug = false, + chat = false, -- We provide our own implementation of the chat HUD. } m.hud = {} m.poi = {} + m.chat = {} m:create_hud() m:set_hotbar_size(8)