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.

62 lines
2.3 KiB

TextMessage = {}
-- require styles
importStyles '/textmessage/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
}
-- 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
13 years ago
function Game.onTextMessage(type, message)
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:setForegroundColor(messageType.color)
label:setText(message)
13 years ago
label:setStyle(messageType.windowLocation)
13 years ago
time = #message * 75
scheduleEvent(function()
label:setVisible(false)
end, time)
end
end
connect(Game, { onLogin = TextMessage.create,
onLogout = TextMessage.destroy })