diff --git a/game/engines/default/engine/UserChat.lua b/game/engines/default/engine/UserChat.lua index f075994cd326030ae991b57b39597b5960a7f830..f903c3d6a565f7286f4aa11fbd431926641aa30f 100644 --- a/game/engines/default/engine/UserChat.lua +++ b/game/engines/default/engine/UserChat.lua @@ -35,6 +35,7 @@ function _M:init() self.channels = {} self.max = 500 self.do_display_chans = true + self.on_event = {} end --- Hook up in the current running game @@ -80,6 +81,16 @@ function _M:addMessage(kind, channel, login, name, msg, extra_data, no_change) if not no_change and channel ~= self.cur_channel then self.channels[channel].changed = true self.channels_changed = true end end +--- Register to receive events +function _M:registerTalkEvents(fct) + self.on_event[fct] = true +end + +--- Register to not receive events +function _M:unregisterTalkEvents(fct) + self.on_event[fct] = nil +end + function _M:event(e) if e.se == "Talk" then e.msg = e.msg:removeColorCodes() @@ -150,6 +161,10 @@ function _M:event(e) end self.channels_changed = true end + + for fct, _ in pairs(self.on_event) do + fct(e) + end end function _M:join(channel) diff --git a/game/modules/tome/dialogs/ArenaFinish.lua b/game/modules/tome/dialogs/ArenaFinish.lua index 515a35d18e7b7e4238b209947e916edd515422ff..954c637e6b83c3c7e84b5e4bc3feeada66f084f5 100644 --- a/game/modules/tome/dialogs/ArenaFinish.lua +++ b/game/modules/tome/dialogs/ArenaFinish.lua @@ -148,6 +148,8 @@ function _M:use(item) self:resurrectBasic(self.actor) elseif act == "dump" then game:registerDialog(require("mod.dialogs.CharacterSheet").new(self.actor)) + elseif act == "log" then + game:registerDialog(require("mod.dialogs.ShowChatLog").new("Message Log", 0.6, game.logdisplay, profile.chat)) end end @@ -155,6 +157,7 @@ function _M:generateList() local list = {} if config.settings.cheat then list[#list+1] = {name="Resurrect by cheating", action="cheat"} end + list[#list+1] = {name=(not profile.auth and "Message Log" or "Message/Chat log (allows to talk)"), action="log"} list[#list+1] = {name="Character dump", action="dump"} list[#list+1] = {name="Restart the same character", action="exit", subaction="restart"} list[#list+1] = {name="Restart with a new character", action="exit", subaction="restart-new"} diff --git a/game/modules/tome/dialogs/DeathDialog.lua b/game/modules/tome/dialogs/DeathDialog.lua index 550ed6815939fab832e6e4445ffa63027b9154ac..c616a8114e40348eeb85f37075ee61e48770e7f5 100644 --- a/game/modules/tome/dialogs/DeathDialog.lua +++ b/game/modules/tome/dialogs/DeathDialog.lua @@ -187,6 +187,8 @@ function _M:use(item) end elseif act == "dump" then game:registerDialog(require("mod.dialogs.CharacterSheet").new(self.actor)) + elseif act == "log" then + game:registerDialog(require("mod.dialogs.ShowChatLog").new("Message Log", 0.6, game.logdisplay, profile.chat)) elseif act == "cheat" then game.logPlayer(self.actor, "#LIGHT_BLUE#You resurrect! CHEATER!") @@ -272,6 +274,7 @@ function _M:generateList() end) end + list[#list+1] = {name=(not profile.auth and "Message Log" or "Message/Chat log (allows to talk)"), action="log"} list[#list+1] = {name="Character dump", action="dump"} list[#list+1] = {name="Restart the same character", action="exit", subaction="restart"} list[#list+1] = {name="Restart with a new character", action="exit", subaction="restart-new"} diff --git a/game/modules/tome/dialogs/ShowChatLog.lua b/game/modules/tome/dialogs/ShowChatLog.lua index 9b27cd108e4cee775da27e2ea2debe3052d02ef1..1a1c864de2405deccaa654dcc4135e21ed67a38e 100644 --- a/game/modules/tome/dialogs/ShowChatLog.lua +++ b/game/modules/tome/dialogs/ShowChatLog.lua @@ -33,6 +33,9 @@ function _M:init(title, shadow, log, chat) self.log, self.chat = log, chat + self.event_fct = function(e) self:onTalkEvent(e) end + chat:registerTalkEvents(self.event_fct) + local tabs = {} local order = {} @@ -65,6 +68,16 @@ function _M:init(title, shadow, log, chat) self:switchTo(self.last_tab or "__log") end +function _M:unload() + self.chat:unregisterTalkEvents(self.event_fct) +end + +function _M:onTalkEvent(e) + if not e.channel then return end + if e.channel ~= self.last_tab then return end + self:switchTo(self.last_tab) +end + function _M:generate() Dialog.generate(self) @@ -83,6 +96,15 @@ function _M:generate() _PAGEUP = function() self:setScroll(self.scroll - self.max_display) end, _PAGEDOWN = function() self:setScroll(self.scroll + self.max_display) end, } + + for i, tab in ipairs(tabs) do + local tab = tab + tab.ui.key:addBind("USERCHAT_TALK", function() + local type, name = profile.chat:getCurrentTarget() + if type == "channel" and self.last_tab ~= "__log" then profile.chat:setCurrentTarget(true, self.last_tab) end + profile.chat:talkBox() + end) + end end function _M:mouseEvent(button, x, y, xrel, yrel, bx, by, event)