tibia-client/modules/game_textmessage/textmessage.lua

97 lines
3.7 KiB
Lua

MessageSettings = {
consoleRed = { color = TextColors.red, consoleTab='Default' },
consoleOrange = { color = TextColors.orange, consoleTab='Default' },
consoleBlue = { color = TextColors.blue, consoleTab='Default' },
centerRed = { color = TextColors.red, consoleTab='Server Log', screenTarget='lowCenterLabel' },
centerGreen = { color = TextColors.green, consoleTab='Server Log', screenTarget='highCenterLabel', consoleOption='showInfoMessagesInConsole' },
centerWhite = { color = TextColors.white, consoleTab='Server Log', screenTarget='middleCenterLabel', consoleOption='showEventMessagesInConsole' },
bottomWhite = { color = TextColors.white, consoleTab='Server Log', screenTarget='statusLabel', consoleOption='showEventMessagesInConsole' },
status = { color = TextColors.white, consoleTab='Server Log', screenTarget='statusLabel', consoleOption='showStatusMessagesInConsole' },
statusSmall = { color = TextColors.white, screenTarget='statusLabel' },
private = { color = TextColors.lightblue, screenTarget='privateLabel' }
}
MessageTypes = {
[MessageModes.MonsterSay] = MessageSettings.consoleOrange,
[MessageModes.MonsterYell] = MessageSettings.consoleOrange,
[MessageModes.Failure] = MessageSettings.statusSmall,
[MessageModes.Login] = MessageSettings.bottomWhite,
[MessageModes.Game] = MessageSettings.centerWhite,
[MessageModes.Status] = MessageSettings.status,
[MessageModes.Warning] = MessageSettings.centerRed,
[MessageModes.Look] = MessageSettings.centerGreen,
[MessageModes.Loot] = MessageSettings.centerGreen,
[MessageModes.Red] = MessageSettings.consoleRed,
[MessageModes.Blue] = MessageSettings.consoleBlue,
[MessageModes.PrivateFrom] = MessageSettings.consoleBlue,
[254] = MessageSettings.private
}
messagesPanel = nil
function init()
connect(g_game, 'onTextMessage', displayMessage)
connect(g_game, 'onGameEnd', clearMessages)
messagesPanel = g_ui.loadUI('textmessage.otui', modules.game_interface.getRootPanel())
end
function terminate()
disconnect(g_game, 'onTextMessage', displayMessage)
disconnect(g_game, 'onPrivateTalk', onPrivateTalk)
disconnect(g_game, 'onGameEnd',clearMessages)
clearMessages()
messagesPanel:destroy()
end
function calculateVisibleTime(text)
return math.max(#text * 100, 4000)
end
function displayMessage(mode, text)
if not g_game.isOnline() then return end
local msgtype = MessageTypes[mode]
if not msgtype then
perror('unhandled onTextMessage message mode ' .. mode)
return
end
if msgtype.consoleTab ~= nil and (msgtype.consoleOption == nil or Options.getOption(msgtype.consoleOption)) then
modules.game_console.addText(text, msgtype, tr(msgtype.consoleTab))
--TODO move to game_console
end
if msgtype.screenTarget then
local label = messagesPanel:recursiveGetChildById(msgtype.screenTarget)
label:setText(text)
label:setColor(msgtype.color)
label:setVisible(true)
removeEvent(label.hideEvent)
label.hideEvent = scheduleEvent(function() label:setVisible(false) end, calculateVisibleTime(text))
end
end
function displayStatusMessage(text)
displayMessage(MessageModes.Status, text)
end
function displayGameMessage(text)
displayMessage(MessageModes.Game, text)
end
function clearMessages()
for _i,child in pairs(messagesPanel:recursiveGetChildren()) do
if child:getId():match('Label') then
child:hide()
removeEvent(child.hideEvent)
end
end
end
function onPrivateTalk(code, text, speaker, speakerlevel, statmentid)
if Options.getOption('showPrivateMessagesOnScreen') then
displayMessage(254, speaker .. ':\n' .. text)
end
end