tibia-client/modules/game_textmessage/textmessage.lua

89 lines
2.8 KiB
Lua
Raw Normal View History

TextMessage = {}
2011-08-30 17:12:57 +02:00
-- require styles
importStyle 'textmessage.otui'
2011-09-04 19:21:42 +02:00
-- private variables
2012-01-08 16:42:23 +01:00
local MessageTypes = {
warning = { color = '#F55E5E', showOnConsole = true, showOnWindow = true, windowLocation = 'CenterLabel' },
eventAdvance = { color = '#FFFFFF', showOnConsole = true, showOnWindow = true, windowLocation = 'CenterLabel' },
eventDefault = { color = '#FFFFFF', showOnConsole = true, showOnWindow = true, windowLocation = 'BottomLabel' },
statusDefault = { color = '#FFFFFF', showOnConsole = true, showOnWindow = true, windowLocation = 'BottomLabel' },
infoDesc = { color = '#00EB00', showOnConsole = true, showOnWindow = true, windowLocation = 'CenterLabel' },
statusSmall = { color = '#FFFFFF', showOnConsole = false, showOnWindow = true, windowLocation = 'BottomLabel' },
consoleOrange = { color = '#FE6500', showOnConsole = true, showOnWindow = false },
consoleBlue = { color = '#9F9DFD', showOnConsole = true, showOnWindow = false },
consoleRed = { color = '#F55E5E', showOnConsole = true, showOnWindow = false }
2011-09-04 19:21:42 +02:00
}
local bottomLabelWidget
local centerLabelWidget
2012-01-08 16:42:23 +01:00
local bottomLabelHideEvent
local centerLabelHideEvent
2012-01-08 16:42:23 +01:00
-- private functions
local function displayMessage(msgtype, msg, time)
2012-01-08 16:42:23 +01:00
if msgtype.showOnConsole then
2011-09-04 19:21:42 +02:00
-- TODO
end
2012-01-08 16:42:23 +01:00
if msgtype.showOnWindow then
2011-09-04 19:21:42 +02:00
local label
2012-01-08 16:42:23 +01:00
if msgtype.windowLocation == 'BottomLabel' then
2011-09-04 19:21:42 +02:00
label = bottomLabelWidget
2012-01-08 16:42:23 +01:00
elseif msgtype.windowLocation == 'CenterLabel' then
2011-09-04 19:21:42 +02:00
label = centerLabelWidget
end
2011-09-04 19:21:42 +02:00
label:setVisible(true)
2012-01-08 16:42:23 +01:00
label:setText(msg)
label:setStyle(msgtype.windowLocation)
label:setForegroundColor(msgtype.color)
if not time then
time = math.max(#msg * 75, 3000)
else
time = time * 1000
end
2012-01-08 16:42:23 +01:00
removeEvent(label.hideEvent)
label.hideEvent = scheduleEvent(function() label:setVisible(false) end, time)
end
end
-- public functions
function TextMessage.create()
bottomLabelWidget = createWidget('UILabel', Game.gameMapPanel)
centerLabelWidget = createWidget('UILabel', Game.gameMapPanel)
end
function TextMessage.displayStatus(msg, time)
displayMessage(MessageTypes.warning, msg)
end
function TextMessage.displayEventAdvance(msg, time)
displayMessage(MessageTypes.eventAdvance, msg, time)
2012-01-08 16:42:23 +01:00
end
function TextMessage.display(msgtypedesc, msg)
local msgtype = MessageTypes[msgtypedesc]
2012-01-08 16:42:23 +01:00
if msgtype == nil then
error('unknown text msg type ' .. msgtype)
2012-01-08 16:42:23 +01:00
return
2011-08-30 17:12:57 +02:00
end
2012-01-08 16:42:23 +01:00
displayMessage(msgtype, msg)
end
-- hooked events
local function onGameDeath()
TextMessage.displayEventAdvance('You are dead.', 10)
2011-08-30 17:12:57 +02:00
end
2011-11-03 23:16:47 +01:00
local function onGameTextMessage(msgtype, msg)
TextMessage.display(msgtype, msg)
end
2011-11-03 23:16:47 +01:00
connect(Game, { onLogin = TextMessage.create,
onLogout = TextMessage.destroy,
onDeath = onGameDeath,
onTextMessage = onGameTextMessage })