2011-11-03 10:59:11 +01:00
|
|
|
TextMessage = {}
|
2011-08-30 17:12:57 +02:00
|
|
|
|
2011-11-03 10:59:11 +01:00
|
|
|
-- require styles
|
2012-01-03 01:42:53 +01:00
|
|
|
importStyle 'textmessage.otui'
|
2011-09-04 19:21:42 +02:00
|
|
|
|
2011-11-03 10:59:11 +01: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
|
|
|
}
|
|
|
|
|
2012-01-08 19:29:41 +01:00
|
|
|
local bottomLabelWidget
|
|
|
|
local centerLabelWidget
|
2012-01-08 16:42:23 +01:00
|
|
|
local bottomLabelHideEvent
|
|
|
|
local centerLabelHideEvent
|
2011-11-03 10:59:11 +01:00
|
|
|
|
2012-01-08 16:42:23 +01:00
|
|
|
-- private functions
|
2012-01-08 19:29:41 +01:00
|
|
|
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
|
2011-11-03 10:59:11 +01:00
|
|
|
|
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-11-03 10:59:11 +01:00
|
|
|
|
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
|
|
|
|
|
2012-01-08 19:29:41 +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
|
|
|
|
|
2012-01-08 19:29:41 +01:00
|
|
|
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
|
|
|
|
|
2012-01-08 19:29:41 +01:00
|
|
|
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
|
2012-01-08 19:29:41 +01:00
|
|
|
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
|
|
|
|
2012-01-08 19:29:41 +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,
|
2011-12-30 19:14:50 +01:00
|
|
|
onLogout = TextMessage.destroy,
|
2012-01-08 19:29:41 +01:00
|
|
|
onDeath = onGameDeath,
|
|
|
|
onTextMessage = onGameTextMessage })
|