You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.4 KiB

TextMessage = {}
-- require styles
importStyles 'textmessage.otui'
13 years ago
-- private variables
local bottomLabelWidget, centerLabelWidget
13 years ago
local messageTypes = {
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 }
13 years ago
}
local hideEvent
13 years ago
-- public functions
function TextMessage.create()
13 years ago
bottomLabelWidget = UILabel.create()
Game.gameMapPanel:addChild(bottomLabelWidget)
13 years ago
centerLabelWidget = UILabel.create()
Game.gameMapPanel:addChild(centerLabelWidget)
13 years ago
end
-- hooked events
function TextMessage.onTextMessage(type, message)
13 years ago
local messageType = messageTypes[type - messageTypes.first]
13 years ago
if messageType.showOnConsole then
-- TODO
end
13 years ago
if messageType.showOnWindow then
local label
if messageType.windowLocation == 'BottomLabel' then
label = bottomLabelWidget
elseif messageType.windowLocation == 'CenterLabel' then
label = centerLabelWidget
end
13 years ago
label:setVisible(true)
label:setText(message)
label:setStyle(messageType.windowLocation)
label:setForegroundColor(messageType.color)
13 years ago
time = #message * 75
removeEvent(hideEvent)
hideEvent = scheduleEvent(function()
13 years ago
label:setVisible(false)
end, time)
end
end
connect(Game, { onLogin = TextMessage.create,
onLogout = TextMessage.destroy,
onTextMessage = TextMessage.onTextMessage })