2011-11-03 10:59:11 +01:00
|
|
|
TextMessage = {}
|
2011-08-30 17:12:57 +02:00
|
|
|
|
2011-11-03 10:59:11 +01:00
|
|
|
-- require styles
|
2012-06-26 00:13:30 +02:00
|
|
|
g_ui.importStyle('textmessage.otui')
|
2011-09-04 19:21:42 +02:00
|
|
|
|
2011-11-03 10:59:11 +01:00
|
|
|
-- private variables
|
2012-01-08 16:42:23 +01:00
|
|
|
local MessageTypes = {
|
2012-04-26 21:54:16 +02:00
|
|
|
consoleRed = { color = '#F55E5E', consoleTab = tr('Default') },
|
|
|
|
consoleOrange = { color = '#FE6500', consoleTab = tr('Default') },
|
|
|
|
consoleBlue = { color = '#9F9DFD', consoleTab = tr('Default') },
|
2012-06-09 15:00:08 +02:00
|
|
|
warning = { color = '#F55E5E', consoleTab = tr('Server Log'), labelId = 'centerWarning' },
|
|
|
|
infoDescription = { color = '#00EB00', consoleTab = tr('Server Log'), labelId = 'centerInfo', consoleOption = 'showInfoMessagesInConsole' },
|
|
|
|
eventAdvance = { color = '#FFFFFF', consoleTab = tr('Server Log'), labelId = 'centerAdvance', consoleOption = 'showEventMessagesInConsole' },
|
2012-04-26 21:54:16 +02:00
|
|
|
eventDefault = { color = '#FFFFFF', consoleTab = tr('Server Log'), labelId = 'bottomStatus', consoleOption = 'showEventMessagesInConsole' },
|
|
|
|
statusDefault = { color = '#FFFFFF', consoleTab = tr('Server Log'), labelId = 'bottomStatus', consoleOption = 'showStatusMessagesInConsole' },
|
2012-01-26 18:23:47 +01:00
|
|
|
statusSmall = { color = '#FFFFFF', labelId = 'bottomStatus' },
|
2012-06-09 15:00:08 +02:00
|
|
|
private = { color = '#5FF7F7', labelId = 'centerPrivate' }
|
2011-09-04 19:21:42 +02:00
|
|
|
}
|
|
|
|
|
2012-01-25 15:56:17 +01:00
|
|
|
local centerTextMessagePanel
|
2012-03-18 14:34:39 +01:00
|
|
|
local bottomStatusLabel
|
2012-06-09 15:00:08 +02:00
|
|
|
local privateLabel
|
2011-11-03 10:59:11 +01:00
|
|
|
|
2012-01-08 16:42:23 +01:00
|
|
|
-- private functions
|
2012-01-08 19:29:41 +01:00
|
|
|
local function displayMessage(msgtype, msg, time)
|
2012-02-08 22:23:15 +01:00
|
|
|
if not g_game.isOnline() then return end
|
2012-01-08 21:11:50 +01:00
|
|
|
|
2012-01-14 02:37:15 +01:00
|
|
|
if msgtype.consoleTab ~= nil then
|
2012-03-22 22:47:52 +01:00
|
|
|
if msgtype.consoleOption == nil or Options.getOption(msgtype.consoleOption) then
|
2012-01-14 02:37:15 +01:00
|
|
|
Console.addText(msg, msgtype, msgtype.consoleTab)
|
2012-01-09 00:28:49 +01:00
|
|
|
end
|
2011-09-04 19:21:42 +02:00
|
|
|
end
|
2011-11-03 10:59:11 +01:00
|
|
|
|
2012-05-01 08:49:48 +02:00
|
|
|
if msgtype.labelId then
|
2012-03-18 14:34:39 +01:00
|
|
|
local label = GameInterface.getMapPanel():recursiveGetChildById(msgtype.labelId)
|
2011-11-03 10:59:11 +01:00
|
|
|
|
2012-01-08 16:42:23 +01:00
|
|
|
label:setText(msg)
|
2012-01-09 19:45:28 +01:00
|
|
|
label:setColor(msgtype.color)
|
2012-01-08 16:42:23 +01:00
|
|
|
|
2012-01-08 19:29:41 +01:00
|
|
|
if not time then
|
2012-01-26 18:23:47 +01:00
|
|
|
time = math.max(#msg * 100, 4000)
|
2012-01-08 19:29:41 +01:00
|
|
|
else
|
|
|
|
time = time * 1000
|
|
|
|
end
|
2012-01-08 16:42:23 +01:00
|
|
|
removeEvent(label.hideEvent)
|
2012-03-18 14:34:39 +01:00
|
|
|
addEvent(function() label:setVisible(true) end)
|
2012-01-08 16:42:23 +01:00
|
|
|
label.hideEvent = scheduleEvent(function() label:setVisible(false) end, time)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-06-09 15:00:08 +02:00
|
|
|
local function createTextMessageLabel(id, parent, class)
|
2012-06-26 00:13:30 +02:00
|
|
|
local label = g_ui.createWidget(class, parent)
|
2012-01-25 15:56:17 +01:00
|
|
|
label:setFont('verdana-11px-rounded')
|
|
|
|
label:setId(id)
|
|
|
|
return label
|
|
|
|
end
|
|
|
|
|
2012-01-08 16:42:23 +01:00
|
|
|
-- public functions
|
2012-07-18 08:04:57 +02:00
|
|
|
function TextMessage.init()
|
2012-07-14 12:59:32 +02:00
|
|
|
connect(g_game, { onTextMessage = TextMessage.display,
|
2012-03-18 14:34:39 +01:00
|
|
|
onGameStart = TextMessage.clearMessages })
|
2012-01-25 15:56:17 +01:00
|
|
|
|
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-06-09 15:00:08 +02:00
|
|
|
createTextMessageLabel('centerWarning', centerTextMessagePanel, 'CenterLabel')
|
|
|
|
createTextMessageLabel('centerAdvance', centerTextMessagePanel, 'CenterLabel')
|
|
|
|
createTextMessageLabel('centerInfo', centerTextMessagePanel, 'CenterLabel')
|
2012-01-25 15:56:17 +01:00
|
|
|
|
2012-06-09 15:00:08 +02:00
|
|
|
privateLabel = createTextMessageLabel('centerPrivate', GameInterface.getMapPanel(), 'TopCenterLabel')
|
|
|
|
bottomStatusLabel = createTextMessageLabel('bottomStatus', GameInterface.getMapPanel(), 'BottomLabel')
|
2012-01-08 16:42:23 +01:00
|
|
|
end
|
|
|
|
|
2012-03-18 14:34:39 +01:00
|
|
|
function TextMessage.terminate()
|
|
|
|
disconnect(g_game, { onDeath = TextMessage.displayDeadMessage,
|
|
|
|
onTextMessage = TextMessage.display,
|
2012-04-27 18:23:51 +02:00
|
|
|
onGameStart = TextMessage.clearMessages })
|
2012-03-23 02:52:31 +01:00
|
|
|
removeEvent(GameInterface.getMapPanel():recursiveGetChildById('centerWarning').hideEvent)
|
|
|
|
removeEvent(GameInterface.getMapPanel():recursiveGetChildById('centerAdvance').hideEvent)
|
|
|
|
removeEvent(GameInterface.getMapPanel():recursiveGetChildById('centerInfo').hideEvent)
|
2012-06-09 15:00:08 +02:00
|
|
|
removeEvent(GameInterface.getMapPanel():recursiveGetChildById('centerPrivate').hideEvent)
|
2012-03-23 02:52:31 +01:00
|
|
|
removeEvent(GameInterface.getMapPanel():recursiveGetChildById('bottomStatus').hideEvent)
|
2012-03-18 14:34:39 +01:00
|
|
|
centerTextMessagePanel:destroy()
|
|
|
|
bottomStatusLabel:destroy()
|
2012-06-09 15:00:08 +02:00
|
|
|
privateLabel:destroy()
|
|
|
|
centerTextMessagePanel = nil
|
2012-03-18 14:34:39 +01:00
|
|
|
bottomStatusLabel = nil
|
2012-06-09 15:00:08 +02:00
|
|
|
privateLabel = nil
|
2012-03-18 14:34:39 +01:00
|
|
|
TextMessage = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
function TextMessage.clearMessages()
|
|
|
|
GameInterface.getMapPanel():recursiveGetChildById('centerWarning'):hide()
|
|
|
|
GameInterface.getMapPanel():recursiveGetChildById('centerAdvance'):hide()
|
|
|
|
GameInterface.getMapPanel():recursiveGetChildById('centerInfo'):hide()
|
2012-06-09 15:00:08 +02:00
|
|
|
GameInterface.getMapPanel():recursiveGetChildById('centerPrivate'):hide()
|
2012-03-18 14:34:39 +01:00
|
|
|
GameInterface.getMapPanel():recursiveGetChildById('bottomStatus'):hide()
|
|
|
|
end
|
|
|
|
|
2012-01-08 19:29:41 +01:00
|
|
|
function TextMessage.displayStatus(msg, time)
|
2012-03-23 15:48:00 +01:00
|
|
|
displayMessage(MessageTypes.statusSmall, msg)
|
2012-01-08 19:29:41 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function TextMessage.displayEventAdvance(msg, time)
|
|
|
|
displayMessage(MessageTypes.eventAdvance, msg, time)
|
2012-01-08 16:42:23 +01:00
|
|
|
end
|
|
|
|
|
2012-06-09 15:00:08 +02:00
|
|
|
function TextMessage.displayPrivate(msg, time)
|
|
|
|
displayMessage(MessageTypes.private, msg, time)
|
|
|
|
end
|
|
|
|
|
2012-01-08 19:29:41 +01:00
|
|
|
function TextMessage.display(msgtypedesc, msg)
|
|
|
|
local msgtype = MessageTypes[msgtypedesc]
|
2012-01-08 21:11:50 +01:00
|
|
|
if msgtype then
|
|
|
|
displayMessage(msgtype, msg)
|
2011-08-30 17:12:57 +02:00
|
|
|
end
|
2012-01-08 16:42:23 +01:00
|
|
|
end
|