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
|
2011-12-05 19:27:07 +01:00
|
|
|
importStyles 'textmessage.otui'
|
2011-09-04 19:21:42 +02:00
|
|
|
|
2011-11-03 10:59:11 +01:00
|
|
|
-- private variables
|
|
|
|
local bottomLabelWidget, centerLabelWidget
|
2011-09-04 19:21:42 +02:00
|
|
|
local messageTypes = {
|
2011-11-03 10:59:11 +01:00
|
|
|
first = 12,
|
|
|
|
{ type = 'MessageOrange', color = '#C87832', showOnConsole = true, showOnWindow = false },
|
|
|
|
{ type = 'MessageOrange', color = '#C87832', showOnConsole = true, showOnWindow = false },
|
|
|
|
{ type = 'MessageRed', color = '#C83200', showOnConsole = true, showOnWindow = true, windowLocation = 'CenterLabel' },
|
|
|
|
{ type = 'MessageWhite', color = '#FFFFFF', showOnConsole = true, showOnWindow = true, windowLocation = 'CenterLabel' },
|
|
|
|
{ type = 'MessageWhite', color = '#FFFFFF', showOnConsole = true, showOnWindow = true, windowLocation = 'BottomLabel' },
|
|
|
|
{ type = 'MessageWhite', color = '#FFFFFF', showOnConsole = true, showOnWindow = true, windowLocation = 'BottomLabel' },
|
|
|
|
{ type = 'MessageGreen', color = '#3FBE32', showOnConsole = true, showOnWindow = true, windowLocation = 'CenterLabel' },
|
|
|
|
{ type = 'MessageWhite', color = '#FFFFFF', showOnConsole = false, showOnWindow = true, windowLocation = 'BottomLabel' },
|
|
|
|
{ type = 'MessageBlue', color = '#3264C8', showOnConsole = true, showOnWindow = false },
|
|
|
|
{ type = 'MessageRed', color = '#C83200', showOnConsole = true, showOnWindow = false }
|
2011-09-04 19:21:42 +02:00
|
|
|
}
|
2011-11-07 01:14:51 +01:00
|
|
|
local hideEvent
|
2011-09-04 19:21:42 +02:00
|
|
|
|
2011-11-03 10:59:11 +01:00
|
|
|
-- public functions
|
|
|
|
function TextMessage.create()
|
2011-09-04 19:21:42 +02:00
|
|
|
bottomLabelWidget = UILabel.create()
|
2011-11-03 13:17:10 +01:00
|
|
|
Game.gameMapPanel:addChild(bottomLabelWidget)
|
2011-11-03 10:59:11 +01:00
|
|
|
|
2011-09-04 19:21:42 +02:00
|
|
|
centerLabelWidget = UILabel.create()
|
2011-11-03 13:17:10 +01:00
|
|
|
Game.gameMapPanel:addChild(centerLabelWidget)
|
2011-09-04 19:21:42 +02:00
|
|
|
end
|
|
|
|
|
2011-11-03 10:59:11 +01:00
|
|
|
-- hooked events
|
2011-12-30 19:14:50 +01:00
|
|
|
function TextMessage.onTextMessage(type, message)
|
2011-09-04 19:21:42 +02:00
|
|
|
local messageType = messageTypes[type - messageTypes.first]
|
2011-11-03 10:59:11 +01:00
|
|
|
|
2011-09-04 19:21:42 +02:00
|
|
|
if messageType.showOnConsole then
|
|
|
|
-- TODO
|
|
|
|
end
|
2011-11-03 10:59:11 +01:00
|
|
|
|
2011-09-04 19:21:42 +02:00
|
|
|
if messageType.showOnWindow then
|
|
|
|
local label
|
|
|
|
if messageType.windowLocation == 'BottomLabel' then
|
|
|
|
label = bottomLabelWidget
|
|
|
|
elseif messageType.windowLocation == 'CenterLabel' then
|
|
|
|
label = centerLabelWidget
|
|
|
|
end
|
2011-11-03 10:59:11 +01:00
|
|
|
|
2011-09-04 19:21:42 +02:00
|
|
|
label:setVisible(true)
|
|
|
|
label:setText(message)
|
|
|
|
label:setStyle(messageType.windowLocation)
|
2011-12-30 19:14:50 +01:00
|
|
|
label:setForegroundColor(messageType.color)
|
2011-11-03 10:59:11 +01:00
|
|
|
|
2011-09-04 19:21:42 +02:00
|
|
|
time = #message * 75
|
2011-11-07 01:14:51 +01:00
|
|
|
removeEvent(hideEvent)
|
|
|
|
hideEvent = scheduleEvent(function()
|
2011-09-04 19:21:42 +02:00
|
|
|
label:setVisible(false)
|
|
|
|
end, time)
|
2011-08-30 17:12:57 +02:00
|
|
|
end
|
|
|
|
end
|
2011-11-03 23:16:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
connect(Game, { onLogin = TextMessage.create,
|
2011-12-30 19:14:50 +01:00
|
|
|
onLogout = TextMessage.destroy,
|
|
|
|
onTextMessage = TextMessage.onTextMessage })
|