2012-07-26 11:12:20 +02:00
|
|
|
MessageSettings = {
|
2012-07-30 14:29:13 +02:00
|
|
|
none = {},
|
2012-07-26 11:12:20 +02:00
|
|
|
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' }
|
|
|
|
}
|
|
|
|
|
2012-07-19 21:43:51 +02:00
|
|
|
MessageTypes = {
|
2012-07-27 00:13:47 +02:00
|
|
|
[MessageModes.MonsterSay] = MessageSettings.consoleOrange,
|
|
|
|
[MessageModes.MonsterYell] = MessageSettings.consoleOrange,
|
2012-08-20 15:22:47 +02:00
|
|
|
[MessageModes.BarkLow] = MessageSettings.consoleOrange,
|
|
|
|
[MessageModes.BarkLoud] = MessageSettings.consoleOrange,
|
2012-07-26 11:12:20 +02:00
|
|
|
[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,
|
2012-07-26 14:19:01 +02:00
|
|
|
[MessageModes.PrivateFrom] = MessageSettings.consoleBlue,
|
2012-07-30 14:29:13 +02:00
|
|
|
|
2013-08-18 03:57:38 +02:00
|
|
|
[MessageModes.GamemasterBroadcast] = MessageSettings.consoleRed,
|
|
|
|
|
2012-07-30 14:29:13 +02:00
|
|
|
[MessageModes.DamageDealed] = MessageSettings.status,
|
|
|
|
[MessageModes.DamageReceived] = MessageSettings.status,
|
|
|
|
[MessageModes.Heal] = MessageSettings.status,
|
|
|
|
[MessageModes.Exp] = MessageSettings.status,
|
|
|
|
|
|
|
|
[MessageModes.DamageOthers] = MessageSettings.none,
|
|
|
|
[MessageModes.HealOthers] = MessageSettings.none,
|
|
|
|
[MessageModes.ExpOthers] = MessageSettings.none,
|
|
|
|
|
|
|
|
[MessageModes.TradeNpc] = MessageSettings.centerWhite,
|
|
|
|
[MessageModes.Guild] = MessageSettings.centerWhite,
|
2014-02-11 21:16:50 +01:00
|
|
|
[MessageModes.Party] = MessageSettings.centerGreen,
|
2012-07-30 14:29:13 +02:00
|
|
|
[MessageModes.PartyManagement] = MessageSettings.centerWhite,
|
|
|
|
[MessageModes.TutorialHint] = MessageSettings.centerWhite,
|
|
|
|
[MessageModes.BeyondLast] = MessageSettings.centerWhite,
|
|
|
|
[MessageModes.Report] = MessageSettings.consoleRed,
|
|
|
|
[MessageModes.HotkeyUse] = MessageSettings.centerGreen,
|
|
|
|
|
2012-07-26 14:19:01 +02:00
|
|
|
[254] = MessageSettings.private
|
2011-09-04 19:21:42 +02:00
|
|
|
}
|
|
|
|
|
2012-07-26 11:12:20 +02:00
|
|
|
messagesPanel = nil
|
2012-07-19 11:12:17 +02:00
|
|
|
|
|
|
|
function init()
|
2015-01-22 20:38:28 +01:00
|
|
|
for messageMode, _ in pairs(MessageTypes) do
|
|
|
|
registerMessageMode(messageMode, displayMessage)
|
|
|
|
end
|
|
|
|
|
2012-07-26 11:12:20 +02:00
|
|
|
connect(g_game, 'onGameEnd', clearMessages)
|
2013-01-18 23:39:11 +01:00
|
|
|
messagesPanel = g_ui.loadUI('textmessage', modules.game_interface.getRootPanel())
|
2012-01-08 16:42:23 +01:00
|
|
|
end
|
|
|
|
|
2012-07-19 11:12:17 +02:00
|
|
|
function terminate()
|
2015-01-22 20:38:28 +01:00
|
|
|
for messageMode, _ in pairs(MessageTypes) do
|
|
|
|
unregisterMessageMode(messageMode, displayMessage)
|
|
|
|
end
|
|
|
|
|
2013-11-18 18:58:15 +01:00
|
|
|
disconnect(g_game, 'onGameEnd', clearMessages)
|
2012-07-26 11:12:20 +02:00
|
|
|
clearMessages()
|
|
|
|
messagesPanel:destroy()
|
2012-03-18 14:34:39 +01:00
|
|
|
end
|
|
|
|
|
2012-07-26 11:12:20 +02:00
|
|
|
function calculateVisibleTime(text)
|
|
|
|
return math.max(#text * 100, 4000)
|
2012-01-08 19:29:41 +01:00
|
|
|
end
|
|
|
|
|
2012-07-26 11:12:20 +02:00
|
|
|
function displayMessage(mode, text)
|
2012-07-19 11:12:17 +02:00
|
|
|
if not g_game.isOnline() then return end
|
2012-06-09 15:00:08 +02:00
|
|
|
|
2012-07-26 11:12:20 +02:00
|
|
|
local msgtype = MessageTypes[mode]
|
|
|
|
if not msgtype then
|
|
|
|
return
|
2012-07-19 11:12:17 +02:00
|
|
|
end
|
|
|
|
|
2012-07-30 14:29:13 +02:00
|
|
|
if msgtype == MessageSettings.none then return end
|
|
|
|
|
2013-01-18 23:39:11 +01:00
|
|
|
if msgtype.consoleTab ~= nil and (msgtype.consoleOption == nil or modules.client_options.getOption(msgtype.consoleOption)) then
|
2012-07-26 11:12:20 +02:00
|
|
|
modules.game_console.addText(text, msgtype, tr(msgtype.consoleTab))
|
|
|
|
--TODO move to game_console
|
|
|
|
end
|
2012-07-19 11:12:17 +02:00
|
|
|
|
2012-07-26 11:12:20 +02:00
|
|
|
if msgtype.screenTarget then
|
|
|
|
local label = messagesPanel:recursiveGetChildById(msgtype.screenTarget)
|
|
|
|
label:setText(text)
|
2012-07-19 21:43:51 +02:00
|
|
|
label:setColor(msgtype.color)
|
2012-07-26 11:12:20 +02:00
|
|
|
label:setVisible(true)
|
2012-07-19 11:12:17 +02:00
|
|
|
removeEvent(label.hideEvent)
|
2012-07-26 11:12:20 +02:00
|
|
|
label.hideEvent = scheduleEvent(function() label:setVisible(false) end, calculateVisibleTime(text))
|
2011-08-30 17:12:57 +02:00
|
|
|
end
|
2012-01-08 16:42:23 +01:00
|
|
|
end
|
2012-07-24 07:30:08 +02:00
|
|
|
|
2012-07-30 14:29:13 +02:00
|
|
|
function displayPrivateMessage(text)
|
2012-08-07 18:33:08 +02:00
|
|
|
displayMessage(254, text)
|
2012-07-30 14:29:13 +02:00
|
|
|
end
|
|
|
|
|
2012-07-26 11:12:20 +02:00
|
|
|
function displayStatusMessage(text)
|
|
|
|
displayMessage(MessageModes.Status, text)
|
|
|
|
end
|
|
|
|
|
2013-01-09 23:03:04 +01:00
|
|
|
function displayFailureMessage(text)
|
|
|
|
displayMessage(MessageModes.Failure, text)
|
|
|
|
end
|
|
|
|
|
2012-07-26 11:12:20 +02:00
|
|
|
function displayGameMessage(text)
|
|
|
|
displayMessage(MessageModes.Game, text)
|
2012-07-24 07:30:08 +02:00
|
|
|
end
|
|
|
|
|
2012-10-23 21:15:59 +02:00
|
|
|
function displayBroadcastMessage(text)
|
|
|
|
displayMessage(MessageModes.Warning, text)
|
|
|
|
end
|
|
|
|
|
2012-07-26 11:12:20 +02:00
|
|
|
function clearMessages()
|
|
|
|
for _i,child in pairs(messagesPanel:recursiveGetChildren()) do
|
|
|
|
if child:getId():match('Label') then
|
|
|
|
child:hide()
|
|
|
|
removeEvent(child.hideEvent)
|
|
|
|
end
|
|
|
|
end
|
2012-07-24 07:30:08 +02:00
|
|
|
end
|
2013-02-18 17:16:22 +01:00
|
|
|
|
|
|
|
function LocalPlayer:onAutoWalkFail(player)
|
|
|
|
modules.game_textmessage.displayFailureMessage(tr('There is no way.'))
|
|
|
|
end
|