diff --git a/game/engines/default/engine/UserChat.lua b/game/engines/default/engine/UserChat.lua index dfee826be73eb09c6eceddbc52af46ef5eaa5fa4..3b936d3a4664842b74fcf6da666fa6aa2a4a0959 100644 --- a/game/engines/default/engine/UserChat.lua +++ b/game/engines/default/engine/UserChat.lua @@ -27,6 +27,10 @@ local Base = require "engine.ui.Base" --- Module that handles multiplayer chats module(..., package.seeall, class.inherit(Base)) +local channel_colors = { + +} + --- Creates the log zone function _M:init() self.changed = true @@ -36,6 +40,7 @@ function _M:init() self.max = 500 self.do_display_chans = true self.on_event = {} + self.full_log = {} end --- Hook up in the current running game @@ -66,12 +71,28 @@ end --- Filter messages function _M:filterMessage(item) if config.settings.chat.filter[item.kind] then return true end + if config.settings.chat.ignores[item.login] then return true end +end + +function _M:ignoreUser(login) + config.settings.chat.ignores[login] = true + if game.log then game.log("Ignoring all new messages from %s.", login) end + self:saveIgnores() +end + +function _M:saveIgnores() + local l = {} + for k, v in pairs(config.settings.chat.ignores) do + if v then l[#l+1] = "chat.ignores["..("%q"):format(k).."]=true" end + end + game:saveSettings("chat.ignores", table.concat(l, "\n")) end local urlfind = (lpeg.P"http://" + lpeg.P"https://") * (1-lpeg.P" ")^0 local urlmatch = lpeg.anywhere(lpeg.C(urlfind)) function _M:addMessage(kind, channel, login, name, msg, extra_data, no_change) + local color_name = colors.WHITE if type(name) == "table" then name, color_name = name[1], name[2] end @@ -80,7 +101,7 @@ function _M:addMessage(kind, channel, login, name, msg, extra_data, no_change) msg = msg:lpegSub(urlfind, "#LIGHT_BLUE##{italic}#"..url.."#{normal}##LAST#") end - local item = {kind=kind, login=login, name=name, color_name=color_name, msg=msg, url=url, extra_data=extra_data, timestamp=core.game.getTime()} + local item = {channel=channel, kind=kind, login=login, name=name, color_name=color_name, msg=msg, url=url, extra_data=extra_data, timestamp=core.game.getTime()} if self:filterMessage(item) then return end if self.uc_ext and self.uc_ext.filterMessage then if self.uc_ext:filterMessage(item) then return end @@ -90,6 +111,10 @@ function _M:addMessage(kind, channel, login, name, msg, extra_data, no_change) while #log > self.max do table.remove(log) end self.changed = true if not no_change and channel ~= self.cur_channel then self.channels[channel].changed = true self.channels_changed = true end + + local log = self.full_log + table.insert(log, 1, item) + while #log > self.max do table.remove(log) end end --- Register to receive events @@ -523,11 +548,11 @@ function _M:display() self.dlist = {} local h = 0 local log = {} - if self.channels[self.cur_channel] then log = self.channels[self.cur_channel].log end + if self.full_log then log = self.full_log end local old_style = self.font:getStyle() for z = 1 + self.scroll, #log do local stop = false - local tstr = tstring{"<", {"color",unpack(colors.simple(log[z].color_name))}, log[z].name, {"color", "LAST"}, "> "} + local tstr = tstring{"[", log[z].channel, "] <", {"color",unpack(colors.simple(log[z].color_name))}, log[z].name, {"color", "LAST"}, "> "} tstr:merge(log[z].msg:toTString()) local gen = tstring.makeLineTextures(tstr, self.w, self.font_mono) for i = #gen, 1, -1 do diff --git a/game/engines/default/engine/dialogs/ChatIgnores.lua b/game/engines/default/engine/dialogs/ChatIgnores.lua new file mode 100644 index 0000000000000000000000000000000000000000..a948c5620f8511f4715e15db98121826acda4ebf --- /dev/null +++ b/game/engines/default/engine/dialogs/ChatIgnores.lua @@ -0,0 +1,62 @@ +-- TE4 - T-Engine 4 +-- Copyright (C) 2009, 2010, 2011, 2012 Nicolas Casalini +-- +-- This program is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation, either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see <http://www.gnu.org/licenses/>. +-- +-- Nicolas Casalini "DarkGod" +-- darkgod@te4.org + +require "engine.class" +local Dialog = require "engine.ui.Dialog" +local List = require "engine.ui.List" +local Textzone = require "engine.ui.Textzone" + +module(..., package.seeall, class.inherit(Dialog)) + +function _M:init() + Dialog.init(self, "Chat ignore list", 500, 400) + + local list = {} + for l, _ in pairs(config.settings.chat.ignores) do if _ then list[#list+1] = {name=l} end end + + local c_list = List.new{width=self.iw - 10, height=400, scrollbar=true, list=list, fct=function(item) + Dialog:yesnoPopup("Stop ignoring", "Really stop ignoring: "..item.name, function(ret) if ret then + config.settings.chat.ignores[item.name] = nil + self:regen() + end end) + end} + + local c_desc = Textzone.new{width=self.iw - 10, height=1, auto_height=true, text="Click a user to stop ignoring her/his messages."} + local uis = { + {left=0, top=0, ui=c_desc}, + {left=0, top=c_desc.h+5, ui=c_list}, + } + self:loadUI(uis) + self:setupUI(false, true) + + self.key:addBinds{ + EXIT = function() game:unregisterDialog(self) end, + } +end + +function _M:unload() + profile.chat:saveIgnores() +end + +function _M:regen() + local d = new() + d.__showup = false + game:replaceDialog(self, d) + self.next_dialog = d +end diff --git a/game/engines/default/engine/init.lua b/game/engines/default/engine/init.lua index 9116580f5acae194f12a5532c10ea85fd9690998..0491ec76002d43daf0f62baf1e25c8b7119d21cf 100644 --- a/game/engines/default/engine/init.lua +++ b/game/engines/default/engine/init.lua @@ -61,6 +61,7 @@ gamma_correction = 120 mouse_move = true censor_boot = true chat.filter = {} +chat.ignores = {} addons = {} ]] for i, file in ipairs(fs.list("/settings/")) do diff --git a/game/modules/tome/class/uiset/Minimalist.lua b/game/modules/tome/class/uiset/Minimalist.lua index 98b47eee6f8efa02537b86c24dff3192fcb6b953..354ef27e4bd26190792f90597fc7ffd1bed344a3 100644 --- a/game/modules/tome/class/uiset/Minimalist.lua +++ b/game/modules/tome/class/uiset/Minimalist.lua @@ -2020,6 +2020,7 @@ function _M:setupMouse(mouse) extra.add_map_action = { { name="Show chat user", fct=function() profile.chat:showUserInfo(user.login) end }, { name="Whisper", fct=function() profile.chat:setCurrentTarget(false, user.login) profile.chat:talkBox() end }, + { name="Ignore", fct=function() Dialog:yesnoPopup("Ignore user", "Really ignore all messages from: "..user.login, function(ret) if ret then profile.chat:ignoreUser(user.login) end end) end }, { name="Report user for bad behavior", fct=function() game:registerDialog(require('engine.dialogs.GetText').new("Reason to report: "..user.login, "Reason", 4, 500, function(text) profile.chat:reportUser(user.login, text) diff --git a/game/modules/tome/dialogs/GameOptions.lua b/game/modules/tome/dialogs/GameOptions.lua index 2615b620fa59fc9273b9af121902ea4382f8b7e3..535c25d36bf5ca5e913cf18fb6244204ed48c981 100644 --- a/game/modules/tome/dialogs/GameOptions.lua +++ b/game/modules/tome/dialogs/GameOptions.lua @@ -223,6 +223,11 @@ function _M:generateList() })) end,} + local zone = Textzone.new{width=self.c_desc.w, height=self.c_desc.h, text=string.toTString"Configure the chat ignore filter.#WHITE#"} + list[#list+1] = { zone=zone, name=string.toTString"#GOLD##{bold}#Chat ignore list#WHITE##{normal}#", status=function(item) + return "select to configure" + end, fct=function(item) game:registerDialog(require("engine.dialogs.ChatIgnores").new()) end,} + if game.uiset:checkGameOption("icons_temp_effects") then local zone = Textzone.new{width=self.c_desc.w, height=self.c_desc.h, text=string.toTString"Uses the icons for status effects instead of text.#WHITE#"} list[#list+1] = { zone=zone, name=string.toTString"#GOLD##{bold}#Icons status effects#WHITE##{normal}#", status=function(item) diff --git a/game/profile-thread/Client.lua b/game/profile-thread/Client.lua index 595be981a51fc482bb6cae9bf03f91964e4d61f3..2584ff256f11fd35ef686d9b6e98fa8ad27b246a 100644 --- a/game/profile-thread/Client.lua +++ b/game/profile-thread/Client.lua @@ -23,7 +23,7 @@ local UserChat = require "profile-thread.UserChat" module(..., package.seeall, class.make) -local debug = false +local debug = true local mport = debug and 2259 or 2257 local pport = debug and 2260 or 2258