diff --git a/game/engines/default/data/keybinds/chat.lua b/game/engines/default/data/keybinds/chat.lua new file mode 100644 index 0000000000000000000000000000000000000000..c7245f5773925651445515b61ad4dee533e90cd9 --- /dev/null +++ b/game/engines/default/data/keybinds/chat.lua @@ -0,0 +1,25 @@ +-- TE4 - T-Engine 4 +-- Copyright (C) 2009, 2010 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 + +defineAction{ + default = { "sym:32:false:false:false:false" }, + type = "USERCHAT_TALK", + group = "user chat", + name = "Talk to people", +} diff --git a/game/engines/default/engine/UserChat.lua b/game/engines/default/engine/UserChat.lua new file mode 100644 index 0000000000000000000000000000000000000000..7c1190a20cf8598263dd5f0c94b4799e3cd01b77 --- /dev/null +++ b/game/engines/default/engine/UserChat.lua @@ -0,0 +1,73 @@ +-- TE4 - T-Engine 4 +-- Copyright (C) 2009, 2010 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" +require "engine.ui.Base" +local KeyBind = require "engine.KeyBind" + +--- Module that handles multiplayer chats +module(..., package.seeall, class.inherit(engine.ui.Base)) + +--- Creates the log zone +function _M:init() + self.cur_channel = "global" + self.channels = {} +end + +--- Hook up in the current running game +function _M:setupOnGame() + KeyBind:load("chat") + _G.game.key:bindKeys() -- Make sure it updates + + _G.game.key:addBinds{ + USERCHAT_TALK = function() + self:talkBox() + end, + } +end + +function _M:event(e) + if e.se == "Talk" then + self.channels[e.channel] = self.channels[e.channel] or {users={}, log={}} + local log = self.channels[e.channel].log + table.insert(log, 1, ("<%s> %s"):format(e.user, e.msg)) + while #log > 50 do table.remove(log) end + game.log("#YELLOW#"..log[1]) + elseif e.se == "Join" then + self.channels[e.channel] = self.channels[e.channel] or {users={}, log={}} + self.channels[e.channel].users[e.user] = true + elseif e.se == "Part" then + self.channels[e.channel] = self.channels[e.channel] or {users={}, log={}} + self.channels[e.channel].users[e.user] = nil + end +end + +function _M:talk(msg) + if not msg then return end + core.profile.pushOrder(string.format("o='ChatTalk' channel=%q msg=%q", self.cur_channel, msg)) +end + +--- Request a line to send +-- TODO: make it betetr than a simple dialog +function _M:talkBox() + local d = require("engine.dialogs.GetText").new("Talk", self.cur_channel..":", 0, 250, function(text) + self:talk(text) + end) + game:registerDialog(d) +end diff --git a/game/profile-thread/UserChat.lua b/game/profile-thread/UserChat.lua new file mode 100644 index 0000000000000000000000000000000000000000..b7a099fd553145b5ffd6cc341a73a0e7c6215566 --- /dev/null +++ b/game/profile-thread/UserChat.lua @@ -0,0 +1,45 @@ +-- TE4 - T-Engine 4 +-- Copyright (C) 2009, 2010 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 socket = require "socket" + +module(..., package.seeall, class.make) + +function _M:init(client) + self.client = client + self.channels = {} +end + +function _M:event(e) + if e.e == "ChatTalk" then + cprofile.pushEvent(string.format("e='Chat' se='Talk' channel=%q user=%q msg=%q", e.channel, e.user, e.msg)) + print("[USERCHAT] channel talk", e.user, e.channel, e.msg) + elseif e.e == "ChatJoin" then + self.channels[e.channel] = self.channels[e.channel] or {} + self.channels[e.channel][e.user] = true + cprofile.pushEvent(string.format("e='Chat' se='Join' channel=%q user=%q", e.channel, e.user)) + print("[USERCHAT] channel join", e.user, e.channel) + elseif e.e == "ChatPart" then + self.channels[e.channel] = self.channels[e.channel] or {} + self.channels[e.channel][e.user] = nil + cprofile.pushEvent(string.format("e='Chat' se='Part' channel=%q user=%q", e.channel, e.user)) + print("[USERCHAT] channel part", e.user, e.channel) + end +end