2012-07-19 11:12:17 +02:00
|
|
|
MessageTypesConf = {
|
|
|
|
ConsoleRed = { color = '#F55E5E', consoleTab = tr('Default') },
|
|
|
|
ConsoleOrange = { color = '#FE6500', consoleTab = tr('Default') },
|
|
|
|
ConsoleBlue = { color = '#9F9DFD', consoleTab = tr('Default') },
|
|
|
|
Warning = { color = '#F55E5E', consoleTab = tr('Server Log'), labelId = 'warningLabel' },
|
|
|
|
Info = { color = '#00EB00', consoleTab = tr('Server Log'), labelId = 'infoLabel', consoleOption = 'showInfoMessagesInConsole' },
|
|
|
|
EventAdvance = { color = '#FFFFFF', consoleTab = tr('Server Log'), labelId = 'advanceLabel', consoleOption = 'showEventMessagesInConsole' },
|
|
|
|
EventDefault = { color = '#FFFFFF', consoleTab = tr('Server Log'), labelId = 'statusLabel', consoleOption = 'showEventMessagesInConsole' },
|
|
|
|
StatusDefault = { color = '#FFFFFF', consoleTab = tr('Server Log'), labelId = 'statusLabel', consoleOption = 'showStatusMessagesInConsole' },
|
|
|
|
StatusSmall = { color = '#FFFFFF', labelId = 'statusLabel' },
|
|
|
|
Private = { color = '#5FF7F7', labelId = 'privateLabel' }
|
2011-09-04 19:21:42 +02:00
|
|
|
}
|
|
|
|
|
2012-07-19 11:12:17 +02:00
|
|
|
centerTextMessagePanel = nil
|
|
|
|
statusLabel = nil
|
|
|
|
privateLabel = nil
|
|
|
|
warningLabel = nil
|
|
|
|
advanceLabel = nil
|
|
|
|
infoLabel = nil
|
|
|
|
|
|
|
|
function init()
|
|
|
|
connect(g_game, {
|
|
|
|
onTextMessage = displayMessage,
|
|
|
|
onGameStart = clearMessages
|
|
|
|
})
|
|
|
|
registerProtocol()
|
|
|
|
|
|
|
|
g_ui.importStyle('textmessage.otui')
|
2012-06-26 00:13:30 +02:00
|
|
|
centerTextMessagePanel = g_ui.createWidget('Panel', GameInterface.getMapPanel())
|
2012-01-25 15:56:17 +01:00
|
|
|
centerTextMessagePanel:setId('centerTextMessagePanel')
|
2012-03-18 14:34:39 +01:00
|
|
|
|
2012-01-25 15:56:17 +01:00
|
|
|
local layout = UIVerticalLayout.create(centerTextMessagePanel)
|
|
|
|
layout:setFitChildren(true)
|
|
|
|
centerTextMessagePanel:setLayout(layout)
|
|
|
|
centerTextMessagePanel:setWidth(360)
|
|
|
|
centerTextMessagePanel:centerIn('parent')
|
|
|
|
|
2012-07-19 11:12:17 +02:00
|
|
|
warningLabel = createTextMessageLabel('warningLabel', centerTextMessagePanel, 'CenterLabel')
|
|
|
|
advanceLabel = createTextMessageLabel('advanceLabel', centerTextMessagePanel, 'CenterLabel')
|
|
|
|
infoLabel = createTextMessageLabel('infoLabel', centerTextMessagePanel, 'CenterLabel')
|
|
|
|
privateLabel = createTextMessageLabel('privateLabel', GameInterface.getMapPanel(), 'TopCenterLabel')
|
|
|
|
statusLabel = createTextMessageLabel('statusLabel', GameInterface.getMapPanel(), 'BottomLabel')
|
|
|
|
|
|
|
|
export({
|
|
|
|
clearMessages = clearMessages,
|
|
|
|
displayStatus = function() displayMessage(MessageTypes.StatusSmall, msg) end,
|
|
|
|
displayEventAdvance = function() displayMessage(MessageTypes.EventAdvance, msg, time) end,
|
|
|
|
displayPrivate = function() displayPrivate(msg, time) end
|
|
|
|
}, 'TextMessage')
|
2012-01-08 16:42:23 +01:00
|
|
|
end
|
|
|
|
|
2012-07-19 11:12:17 +02:00
|
|
|
function terminate()
|
|
|
|
disconnect(g_game, {
|
|
|
|
onTextMessage = display,
|
|
|
|
onGameStart = clearMessages
|
|
|
|
})
|
|
|
|
unregisterProtocol()
|
|
|
|
|
|
|
|
removeEvent(warningLabel.hideEvent)
|
|
|
|
removeEvent(advanceLabel.hideEvent)
|
|
|
|
removeEvent(infoLabel.hideEvent)
|
|
|
|
removeEvent(privateLabel.hideEvent)
|
|
|
|
removeEvent(statusLabel.hideEvent)
|
|
|
|
|
2012-03-18 14:34:39 +01:00
|
|
|
centerTextMessagePanel:destroy()
|
2012-07-19 11:12:17 +02:00
|
|
|
statusLabel:destroy()
|
2012-06-09 15:00:08 +02:00
|
|
|
privateLabel:destroy()
|
2012-03-18 14:34:39 +01:00
|
|
|
|
2012-07-19 11:12:17 +02:00
|
|
|
unexport('TextMessage')
|
2012-03-18 14:34:39 +01:00
|
|
|
end
|
|
|
|
|
2012-07-19 11:12:17 +02:00
|
|
|
function clearMessages()
|
|
|
|
warningLabel:hide()
|
|
|
|
advanceLabel:hide()
|
|
|
|
infoLabel:hide()
|
|
|
|
privateLabel:hide()
|
|
|
|
statusLabel:hide()
|
2012-01-08 19:29:41 +01:00
|
|
|
end
|
|
|
|
|
2012-07-19 11:12:17 +02:00
|
|
|
function createTextMessageLabel(id, parent, class)
|
|
|
|
local label = g_ui.createWidget(class, parent)
|
|
|
|
label:setFont('verdana-11px-rounded')
|
|
|
|
label:setId(id)
|
|
|
|
return label
|
2012-01-08 16:42:23 +01:00
|
|
|
end
|
|
|
|
|
2012-07-19 11:12:17 +02:00
|
|
|
function displayMessage(msgtype, msg, time)
|
|
|
|
if not g_game.isOnline() then return end
|
|
|
|
msgtypeconf = MessageTypesConf[msgtype]
|
2012-06-09 15:00:08 +02:00
|
|
|
|
2012-07-19 11:12:17 +02:00
|
|
|
if msgtypeconf.consoleTab ~= nil then
|
|
|
|
if msgtypeconf.consoleOption == nil or Options.getOption(msgtypeconf.consoleOption) then
|
|
|
|
Console.addText(msg, msgtypeconf, msgtypeconf.consoleTab)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if msgtypeconf.labelId then
|
|
|
|
local label = GameInterface.getMapPanel():recursiveGetChildById(msgtypeconf.labelId)
|
|
|
|
|
|
|
|
label:setText(msg)
|
|
|
|
label:setColor(msgtypeconf.color)
|
|
|
|
|
|
|
|
if not time then
|
|
|
|
time = math.max(#msg * 100, 4000)
|
|
|
|
else
|
|
|
|
time = time * 1000
|
|
|
|
end
|
|
|
|
removeEvent(label.hideEvent)
|
|
|
|
addEvent(function() label:setVisible(true) end)
|
|
|
|
label.hideEvent = scheduleEvent(function() label:setVisible(false) end, time)
|
2011-08-30 17:12:57 +02:00
|
|
|
end
|
2012-01-08 16:42:23 +01:00
|
|
|
end
|