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

Players can now whisper one another in the ingame chat system. Either select...

Players can now whisper one another in the ingame chat system. Either select the user to whisp in the talkbox or just type her/his name followed by :


git-svn-id: http://svn.net-core.org/repos/t-engine4@3642 51575b47-30f0-44d4-a5cc-537603b46e54
parent 9b7574cc
No related branches found
No related tags found
No related merge requests found
......@@ -83,7 +83,7 @@ function _M:event(e)
e.msg = e.msg:removeColorCodes()
self.channels[self.cur_channel] = self.channels[self.cur_channel] or {users={}, log={}}
self:addMessage(self.cur_channel, e.login, e.name, "#GOLD#<whisper>#LAST#"..e.msg)
self:addMessage(self.cur_channel, e.login, e.name, "#GOLD#<whisper> #LAST#"..e.msg)
if type(game) == "table" and game.logChat then
game.logChat("#GOLD#<Whisper from %s> %s", e.name, e.msg)
......@@ -151,7 +151,7 @@ function _M:join(channel)
self:updateChanList(true)
end
function _M:selectChannel(channel)
function _M:selectChannel(channel, no_recurs)
if not self.channels[channel] then return end
self.channels[channel].changed = false
self.cur_channel = channel
......@@ -159,6 +159,7 @@ function _M:selectChannel(channel)
self.changed = true
self.scroll = 0
self:updateChanList(true)
if not no_recurs then self:setCurrentTarget(true, channel, true) end
end
function _M:talk(msg)
......@@ -173,6 +174,9 @@ function _M:whisper(to, msg)
if not to or not msg or msg == "" then return end
msg = msg:removeColorCodes()
core.profile.pushOrder(string.format("o='ChatWhisper' target=%q msg=%q", to, msg))
self:addMessage(self.cur_channel, to, to, "#GOLD#<whisper to "..to.."> #LAST#"..msg)
if type(game) == "table" and game.logChat then game.logChat("#GOLD#<Whisper to %s> %s", to, msg) end
end
function _M:achievement(name)
......@@ -191,10 +195,10 @@ function _M:talkBox()
end
--- Sets the current talk target, channel or whisper
function _M:setCurrentTarget(channel, name)
function _M:setCurrentTarget(channel, name, no_switch)
if channel and not self.channels[name] then return end
self.cur_target = {channel and "channel" or "whisper", name}
if channel then self:selectChannel(name) end
if channel and not no_switch then self:selectChannel(name) end
end
--- Gets the current talk target, channel or whisper
......
......@@ -22,6 +22,8 @@ local Module = require "engine.Module"
local Dialog = require "engine.ui.Dialog"
local Button = require "engine.ui.Button"
local Textbox = require "engine.ui.Textbox"
local Dropdown = require "engine.ui.Dropdown"
local Textzone = require "engine.ui.Textzone"
module(..., package.seeall, class.inherit(Dialog))
......@@ -33,22 +35,32 @@ function _M:init(chat)
Dialog.init(self, self:getTitle(), 320, 110)
local c_box = Textbox.new{title="Say: ", text="", chars=30, max_len=max,
local c_box = Textbox.new{title="Say: ", text="", chars=60, max_len=max,
fct=function(text) self:okclick() end,
on_change = function(text) self:checkTarget(text) end,
}
self.c_box = c_box
local ok = require("engine.ui.Button").new{text="Accept", fct=function() self:okclick() end}
local cancel = require("engine.ui.Button").new{text="Cancel", fct=function() self:cancelclick() end}
local ok = Button.new{text="Accept", fct=function() self:okclick() end}
local cancel = Button.new{text="Cancel", fct=function() self:cancelclick() end}
local list = self:getTargets()
self.c_list_text = Textzone.new{auto_width=true, auto_height=true, text="Target: "}
self.c_list = Dropdown.new{width=250, fct=function(item) self:checkTarget(item.id..":") self:setFocus(c_box) end, list=list, nb_items=math.min(#list, 10), scrollbar=true}
self:loadUI{
{left=0, top=0, padding_h=10, ui=c_box},
{left=0, top=0, ui=self.c_box},
{left=self.c_box.w - self.c_list.w - self.c_list_text.w - 6, top=self.c_box.h + 10, ui=self.c_list_text},
{left=self.c_box.w - self.c_list.w, top=self.c_box.h + 10, ui=self.c_list},
{left=0, bottom=0, ui=ok},
{right=0, bottom=0, ui=cancel},
{left=self.c_box.w - ok.w, bottom=0, ui=cancel},
}
self:setFocus(c_box)
self:setupUI(true, true)
self:getTitle()
self.key:addBinds{
EXIT = function() game:unregisterDialog(self) end,
}
......@@ -58,8 +70,20 @@ function _M:init(chat)
-- end)
end
function _M:getTargets()
local list = {}
for name, _ in pairs(self.chat.channels) do list[#list+1] = {name="Channel: "..name, id=name} end
if self.chat.channels[self.chat.cur_channel] then
for login, data in pairs(self.chat.channels[self.chat.cur_channel].users) do list[#list+1] = {name="User: "..data.name, id=data.name} end
end
return list
end
function _M:getTitle()
local type, name = self.chat:getCurrentTarget()
if self.c_list then for i = 1, #self.c_list.c_list.list do
if self.c_list.c_list.list[i].id == name then self.c_list.c_list.sel = i break end
end end
if type == "channel" then
return "Talk on channel: "..name
elseif type == "whisper" then
......
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