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.4 KiB

TextMessage = {}
-- require styles
importStyle 'textmessage.otui'
13 years ago
-- private variables
local bottomLabelWidget, centerLabelWidget
13 years ago
local messageTypes = {
first = 12,
{ msgtype = 'MessageOrange', color = '#C87832', showOnConsole = true, showOnWindow = false },
{ msgtype = 'MessageOrange', color = '#C87832', showOnConsole = true, showOnWindow = false },
{ msgtype = 'MessageRed', color = '#C83200', showOnConsole = true, showOnWindow = true, windowLocation = 'CenterLabel' },
{ msgtype = 'MessageWhite', color = '#FFFFFF', showOnConsole = true, showOnWindow = true, windowLocation = 'CenterLabel' },
{ msgtype = 'MessageWhite', color = '#FFFFFF', showOnConsole = true, showOnWindow = true, windowLocation = 'BottomLabel' },
{ msgtype = 'MessageWhite', color = '#FFFFFF', showOnConsole = true, showOnWindow = true, windowLocation = 'BottomLabel' },
{ msgtype = 'MessageGreen', color = '#3FBE32', showOnConsole = true, showOnWindow = true, windowLocation = 'CenterLabel' },
{ msgtype = 'MessageWhite', color = '#FFFFFF', showOnConsole = false, showOnWindow = true, windowLocation = 'BottomLabel' },
{ msgtype = 'MessageBlue', color = '#3264C8', showOnConsole = true, showOnWindow = false },
{ msgtype = 'MessageRed', color = '#C83200', showOnConsole = true, showOnWindow = false }
13 years ago
}
local hideEvent
13 years ago
-- public functions
function TextMessage.create()
bottomLabelWidget = createWidget('UILabel', Game.gameMapPanel)
centerLabelWidget = createWidget('UILabel', Game.gameMapPanel)
13 years ago
end
-- hooked events
function TextMessage.onTextMessage(msgtype, message)
local messageType = messageTypes[msgtype - 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 })