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

Added chat channel number aliases (1, 2, 3, ..) and usable quickly by /1 /2 /3 ...

git-svn-id: http://svn.net-core.org/repos/t-engine4@6379 51575b47-30f0-44d4-a5cc-537603b46e54
parent ffb52471
No related branches found
No related tags found
No related merge requests found
......@@ -37,6 +37,8 @@ function _M:init()
self.channels_changed = true
self.cur_channel = "global"
self.channels = {}
self.channel_codes = {}
self.channel_codes_rev = {}
self.max = 500
self.do_display_chans = true
self.on_event = {}
......@@ -68,6 +70,25 @@ function _M:setupOnGame()
if ok and UC then self.uc_ext = UC.new(self) end
end
function _M:getChannelCode(chan)
if not game then return "0" end
if not self.channel_codes[chan] then
local chans = table.keys(self.channels)
table.sort(chans, function(a, b)
if a == game.__mod_info.short_name then return 1
elseif b == game.__mod_info.short_name then return nil
elseif a == game.__mod_info.short_name.."-spoiler" then return 1
elseif b == game.__mod_info.short_name.."-spoiler" then return nil
else return a < b
end
end)
self.channel_codes_rev = chans
self.channel_codes = table.keys_to_values(chans)
end
return tostring(self.channel_codes[chan])
end
--- Filter messages
function _M:filterMessage(item)
if config.settings.chat.filter[item.kind] then return true end
......@@ -552,7 +573,7 @@ function _M:display()
local old_style = self.font:getStyle()
for z = 1 + self.scroll, #log do
local stop = false
local tstr = tstring{"[", log[z].channel, "] <", {"color",unpack(colors.simple(log[z].color_name))}, log[z].name, {"color", "LAST"}, "> "}
local tstr = tstring{"[", self:getChannelCode(log[z].channel), "-", 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
......
......@@ -108,6 +108,15 @@ function _M:checkTarget(text)
self.c_box:setText("")
end
end
if text:sub(1, 1) == "/" then
local _, _, chancode = text:find("^/([0-9]+) ")
chancode = tonumber(chancode)
if chancode and self.chat.channel_codes_rev and self.chat.channel_codes_rev[chancode] then
self.chat:setCurrentTarget(true, self.chat.channel_codes_rev[chancode])
self:updateTitle(self:getTitle())
self.c_box:setText("")
end
end
end
function _M:okclick()
......
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