tibia-client/modules/game_textmessage/textmessage.lua

98 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-25 01:50:30 +01:00
consoleRed = { color = '#F55E5E', consoleTab = 'Default' }, -- 18
consoleOrange = { color = '#FE6500', consoleTab = 'Default' }, -- 19/20
consoleBlue = { color = '#9F9DFD', consoleTab = 'Default' }, -- 27
warning = { color = '#F55E5E', consoleTab = 'Server Log', windowLocation = 'center' }, -- 21
infoDescription = { color = '#00EB00', consoleTab = 'Server Log', windowLocation = 'center', consoleOption = 'showInfoMessagesInConsole' }, -- 25
eventAdvance = { color = '#FFFFFF', consoleTab = 'Server Log', windowLocation = 'center', consoleOption = 'showEventMessagesInConsole' }, -- 22
eventDefault = { color = '#FFFFFF', consoleTab = 'Server Log', windowLocation = 'bottom', consoleOption = 'showEventMessagesInConsole' }, -- 23
statusDefault = { color = '#FFFFFF', consoleTab = 'Server Log', windowLocation = 'bottom', consoleOption = 'showStatusMessagesInConsole' }, -- 24
statusSmall = { color = '#FFFFFF', windowLocation = 'bottom' }, -- 26
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-14 02:37:15 +01:00
if msgtype.consoleTab ~= nil then
2012-01-09 00:28:49 +01:00
if msgtype.consoleOption == nil or Options[msgtype.consoleOption] then
2012-01-14 02:37:15 +01:00
Console.addText(msg, msgtype, msgtype.consoleTab)
2012-01-09 00:28:49 +01:00
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-09 19:45:28 +01:00
label:setColor(msgtype.color)
2012-01-08 16:42:23 +01:00
2012-01-25 01:50:30 +01:00
if msgtype.windowLocation == 'center' then
label:wrapText()
end
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()
2012-01-19 05:12:53 +01:00
TextMessage.displayEventAdvance('You are dead.', 60)
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 })