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

plop

git-svn-id: http://svn.net-core.org/repos/t-engine4@2775 51575b47-30f0-44d4-a5cc-537603b46e54
parent 814e1415
No related branches found
No related tags found
No related merge requests found
-- 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",
}
-- 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
-- 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
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