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

Added /join and /part commands to the chat; you can join(and create) any...

Added /join and /part commands to the chat; you can join(and create) any channel you wish (name must be letters & - _ only)
Added a list of current channels to the options
Channels are now remembered and will reconnect when the game starts


git-svn-id: http://svn.net-core.org/repos/t-engine4@6386 51575b47-30f0-44d4-a5cc-537603b46e54
parent 0a56779e
No related branches found
No related tags found
No related merge requests found
......@@ -741,10 +741,21 @@ function _M:instanciate(mod, name, new_game, no_reboot)
-- Add user chat if needed
if mod.allow_userchat and _G.game.key then
profile.chat:setupOnGame()
profile.chat:join("global")
profile.chat:join(mod.short_name)
profile.chat:join(mod.short_name.."-spoiler")
profile.chat:selectChannel(mod.short_name)
if not config.settings.chat or not config.settings.chat.channels or not config.settings.chat.channels[mod.short_name] then
profile.chat:join("global")
profile.chat:join(mod.short_name)
profile.chat:join(mod.short_name.."-spoiler")
profile.chat:selectChannel(mod.short_name)
print("Joining default channels")
else
local def = false
for c, _ in pairs(config.settings.chat.channels[mod.short_name]) do
profile.chat:join(c)
if c == mod.short_name then def = true end
end
if def then profile.chat:selectChannel(mod.short_name) else profile.chat:selectChannel( (next(config.settings.chat.channels[mod.short_name])) ) end
print("Joining selected channels")
end
end
-- Disable the profile if ungood
......
......@@ -218,6 +218,15 @@ function _M:event(e)
if self.uc_ext then
self.uc_ext:event(e)
end
elseif e.se == "SelfJoin" then
self:addMessage("join", e.channel, profile.auth.login, e.channel, "#{italic}#Joined channel#{normal}#", nil, true)
self:updateChanList()
self:saveChannels()
elseif e.se == "SelfPart" then
self:addMessage("join", e.channel, profile.auth.login, e.channel, "#{italic}#Left channel#{normal}#", nil, true)
self.channels[e.channel] = nil
self:updateChanList()
self:saveChannels()
elseif e.se == "Join" then
local color = colors.WHITE
if e.status == 'dev' then color = colors.CRIMSON
......@@ -285,6 +294,23 @@ function _M:join(channel)
self:updateChanList(true)
end
function _M:part(channel)
if not profile.auth then return end
core.profile.pushOrder(string.format("o='ChatPart' channel=%q", channel))
self:setCurrentTarget(true, game.__mod_info.short_name)
end
function _M:saveChannels()
local l = {
"chat.channels = chat.channels or {}",
"chat.channels["..string.format("%q", game.__mod_info.short_name).."]={}"
}
for k, v in pairs(profile.chat.channels) do
if v then l[#l+1] = "chat.channels["..string.format("%q", game.__mod_info.short_name).."]["..string.format("%q", k).."]=true" end
end
game:saveSettings("chat.channels."..game.__mod_info.short_name, table.concat(l, "\n"))
end
function _M:selectChannel(channel, no_recurs)
if not self.channels[channel] then return end
self.channels[channel].changed = false
......@@ -429,6 +455,8 @@ function _M:getLog(channel, extra)
local tstr
if i.kind == "whisper" then
tstr = tstring{{"color", 0xcb,0x87,0xd2}, "<", i.name, "> "}
elseif i.kind == "join" then
tstr = tstring{{"color", "FIREBRICK"}, "[", i.name, "]" }
else
tstr = tstring{"<", {"color",unpack(colors.simple(i.color_name or colors.WHITE))}, i.name, {"color", "LAST"}, "> "}
end
......@@ -592,6 +620,8 @@ function _M:display()
local tstr
if log[z].kind == "whisper" then
tstr = tstring{{"color", 0xcb,0x87,0xd2}, "<", log[z].name, ">" }
elseif log[z].kind == "join" then
tstr = tstring{{"color", "FIREBRICK"}, "[", self:getChannelCode(log[z].channel), "-", log[z].name, "]" }
else
tstr = tstring{"[", self:getChannelCode(log[z].channel), "-", log[z].channel, "] <", {"color",unpack(colors.simple(log[z].color_name))}, log[z].name, {"color", "LAST"}, "> "}
end
......
......@@ -18,9 +18,11 @@
-- darkgod@te4.org
colors = {}
colors_simple = {}
function defineColor(name, r, g, b, br, bg, bb)
colors[name] = {r=r, g=g, b=b, br=br, bg=bg, bb=bb}
colors_simple[name] = {r, g, b}
end
function colors.simple(c) return {c.r, c.g, c.b} end
......
-- 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 Checkbox = require "engine.ui.Checkbox"
local Textzone = require "engine.ui.Textzone"
module(..., package.seeall, class.inherit(Dialog))
function _M:init(chat)
Dialog.init(self, "Chat channels", 500, 400)
local mod = game.__mod_info.short_name
local list = {
{name = "Global", kind = "global"},
{name = game.__mod_info.long_name, kind = mod},
{name = game.__mod_info.long_name.." [spoilers]", kind = mod.."-spoiler"},
}
for i, l in pairs(profile.chat.channels) do
if i ~= "global" and i ~= mod and i ~= mod.."-spoiler" then
list[#list+1] = {name=i, kind=i}
end
end
local c_desc = Textzone.new{width=self.iw - 10, height=1, auto_height=true, text="Select which channels to listen to. You can join new channels by typing '/join <channelname>' in the talkbox and leave channels by typing '/part <channelname>'"}
local uis = { {left=0, top=0, ui=c_desc} }
for i, l in ipairs(list) do
local l = l
uis[#uis+1] = {left=0, top=uis[#uis].top+uis[#uis].ui.h + 6, ui=Checkbox.new{title=l.name, default=profile.chat.channels[l.kind], fct=function() end, on_change=function(s)
if s then profile.chat:join(l.kind)
else profile.chat:part(l.kind)
end
end} }
end
self:loadUI(uis)
self:setupUI(false, true)
self.key:addBinds{
EXIT = function() game:unregisterDialog(self) end,
}
end
function _M:unload()
profile.chat:saveChannels()
end
......@@ -28,6 +28,8 @@ local Textzone = require "engine.ui.Textzone"
module(..., package.seeall, class.inherit(Dialog))
function _M:init(chat, on_end)
chat:getChannelCode("----------------")
self.on_end = on_end
self.chat = chat
self.min = 2
......@@ -136,6 +138,26 @@ end
function _M:okclick()
local text = self.c_box.text
local _, _, command, params = text:find("^/([a-z]+) (.*)$")
if command then
if command == "join" and params:find("^[a-z_-]+$") then
self.chat:join(params)
self.c_box:setText("")
game:unregisterDialog(self)
self.chat:setCurrentTarget(true, params)
return
end
if command == "part" and params:find("^[a-z_-]+$") then
self.chat:part(params)
self.c_box:setText("")
game:unregisterDialog(self)
self.chat:setCurrentTarget(true, game.__mod_info.short_name)
return
end
self:triggerHook{"Chat:Talkbox:command", command=command, params=params, talkbox=self}
end
if text:len() >= self.min and text:len() <= self.max then
game:unregisterDialog(self)
......
......@@ -228,6 +228,11 @@ function _M:generateList()
return "select to configure"
end, fct=function(item) game:registerDialog(require("engine.dialogs.ChatIgnores").new()) end,}
local zone = Textzone.new{width=self.c_desc.w, height=self.c_desc.h, text=string.toTString"Configure the chat channels to listen to.#WHITE#"}
list[#list+1] = { zone=zone, name=string.toTString"#GOLD##{bold}#Chat channels#WHITE##{normal}#", status=function(item)
return "select to configure"
end, fct=function(item) game:registerDialog(require("engine.dialogs.ChatChannels").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)
......
......@@ -61,11 +61,13 @@ end
function _M:joined(channel)
self.cjoined[channel] = true
print("[ONLINE PROFILE] connected to channel", channel)
cprofile.pushEvent(string.format("e='Chat' se='SelfJoin' channel=%q", channel))
end
function _M:parted(channel)
self.cjoined[channel] = nil
print("[ONLINE PROFILE] parted from channel", channel)
cprofile.pushEvent(string.format("e='Chat' se='SelfPart' channel=%q", channel))
end
function _M:reconnect()
......
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