tibia-client/modules/game_textmessage/textmessage.lua

95 lines
3.1 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 = {
2012-01-09 00:28:49 +01:00
warning = { color = '#F55E5E', showOnConsole = true, windowLocation = 'center', consoleOption = 'showInfoMessagesInConsole' },
eventAdvance = { color = '#FFFFFF', showOnConsole = true, windowLocation = 'center', consoleOption = 'showEventMessagesInConsole' },
eventDefault = { color = '#FFFFFF', showOnConsole = true, windowLocation = 'bottom', consoleOption = 'showEventMessagesInConsole' },
eventOrange = { color = '#FE6500', showOnConsole = true, windowLocation = 'bottom', consoleOption = 'showEventMessagesInConsole' },
statusDefault = { color = '#FFFFFF', showOnConsole = true, windowLocation = 'bottom', consoleOption = 'showStatusMessagesInConsole' },
infoDescription = { color = '#00EB00', showOnConsole = true, windowLocation = 'center', consoleOption = 'showInfoMessagesInConsole' },
2012-01-08 21:11:50 +01:00
statusSmall = { color = '#FFFFFF', showOnConsole = false, windowLocation = 'bottom' },
consoleOrange = { color = '#FE6500', showOnConsole = true },
consoleBlue = { color = '#9F9DFD', showOnConsole = true },
consoleRed = { color = '#F55E5E', showOnConsole = true }
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 21:11:50 +01:00
if not Game.isOnline() then return end
2012-01-08 16:42:23 +01:00
if msgtype.showOnConsole then
2012-01-09 00:28:49 +01:00
if msgtype.consoleOption == nil or Options[msgtype.consoleOption] then
Console.addText(msg, msgtype.color)
end
2011-09-04 19:21:42 +02:00
end
2012-01-08 21:11:50 +01:00
if msgtype.windowLocation then
2011-09-04 19:21:42 +02:00
local label
2012-01-08 21:11:50 +01:00
local style
if msgtype.windowLocation == 'bottom' then
2011-09-04 19:21:42 +02:00
label = bottomLabelWidget
2012-01-08 21:11:50 +01:00
style = 'BottomLabel'
elseif msgtype.windowLocation == 'center' then
2011-09-04 19:21:42 +02:00
label = centerLabelWidget
2012-01-08 21:11:50 +01:00
style = 'CenterLabel'
2011-09-04 19:21:42 +02:00
end
2011-09-04 19:21:42 +02:00
label:setVisible(true)
2012-01-08 16:42:23 +01:00
label:setText(msg)
2012-01-08 21:11:50 +01:00
label:setStyle(style)
2012-01-08 16:42:23 +01:00
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 21:11:50 +01:00
if msgtype then
displayMessage(msgtype, msg)
2011-08-30 17:12:57 +02:00
end
2012-01-08 16:42:23 +01:00
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 })