Skip to content
Snippets Groups Projects
Commit c5b9a30e authored by dg's avatar dg
Browse files

Added an ignore option to the chat

git-svn-id: http://svn.net-core.org/repos/t-engine4@6366 51575b47-30f0-44d4-a5cc-537603b46e54
parent afaa9346
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
-- 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
......@@ -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
......
......@@ -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)
......
......@@ -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)
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment