tibia-client/modules/game_textmessage/textmessage.lua

95 lines
3.0 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-14 02:37:15 +01:00
consoleRed = { color = '#F55E5E', consoleTab = 'Server Log' },
eventOrange = { color = '#FE6500', consoleTab = 'Default' , windowLocation = 'center', consoleOption = 'showEventMessagesInConsole' },
consoleOrange = { color = '#FE6500', consoleTab = 'Default' },
warning = { color = '#F55E5E', consoleTab = 'Server Log', windowLocation = 'center' },
eventAdvance = { color = '#FFFFFF', consoleTab = 'Server Log', windowLocation = 'center', consoleOption = 'showEventMessagesInConsole' },
eventDefault = { color = '#FFFFFF', consoleTab = 'Server Log', windowLocation = 'bottom', consoleOption = 'showEventMessagesInConsole' },
statusDefault = { color = '#FFFFFF', consoleTab = 'Server Log', windowLocation = 'bottom', consoleOption = 'showStatusMessagesInConsole' },
infoDescription = { color = '#00EB00', consoleTab = 'Server Log', windowLocation = 'center', consoleOption = 'showInfoMessagesInConsole' },
statusSmall = { color = '#FFFFFF', windowLocation = 'bottom' },
2012-01-14 02:37:15 +01:00
consoleBlue = { color = '#9F9DFD', consoleTab = 'Default' },
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
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 })