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 15:56:17 +01:00
|
|
|
consoleRed = { color = '#F55E5E', consoleTab = 'Default' },
|
|
|
|
consoleOrange = { color = '#FE6500', consoleTab = 'Default' },
|
|
|
|
consoleBlue = { color = '#9F9DFD', consoleTab = 'Default' },
|
|
|
|
warning = { color = '#F55E5E', consoleTab = 'Server Log', labelId = 'centerWarning', wrap = true },
|
|
|
|
infoDescription = { color = '#00EB00', consoleTab = 'Server Log', labelId = 'centerInfo', consoleOption = 'showInfoMessagesInConsole', wrap = true },
|
|
|
|
eventAdvance = { color = '#FFFFFF', consoleTab = 'Server Log', labelId = 'centerAdvance', consoleOption = 'showEventMessagesInConsole', wrap = true },
|
|
|
|
eventDefault = { color = '#FFFFFF', consoleTab = 'Server Log', labelId = 'bottomStatus', consoleOption = 'showEventMessagesInConsole' },
|
|
|
|
statusDefault = { color = '#FFFFFF', consoleTab = 'Server Log', labelId = 'bottomStatus', consoleOption = 'showStatusMessagesInConsole' },
|
2012-01-26 18:23:47 +01:00
|
|
|
statusSmall = { color = '#FFFFFF', labelId = 'bottomStatus' },
|
2011-09-04 19:21:42 +02:00
|
|
|
}
|
|
|
|
|
2012-01-25 15:56:17 +01:00
|
|
|
local centerTextMessagePanel
|
|
|
|
local centerLabel
|
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-25 15:56:17 +01:00
|
|
|
if msgtype.labelId then
|
|
|
|
local label = Game.gameMapPanel:recursiveGetChildById(msgtype.labelId)
|
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-09 19:45:28 +01:00
|
|
|
label:setColor(msgtype.color)
|
2012-01-25 15:56:17 +01:00
|
|
|
label:resizeToText()
|
2012-01-08 16:42:23 +01:00
|
|
|
|
2012-01-25 15:56:17 +01:00
|
|
|
if msgtype.wrap then
|
|
|
|
label:setWidth(label:getParent():getWidth())
|
2012-01-25 01:50:30 +01:00
|
|
|
label:wrapText()
|
2012-01-25 15:56:17 +01:00
|
|
|
label:setHeight(label:getTextSize().height)
|
2012-01-25 01:50:30 +01:00
|
|
|
end
|
|
|
|
|
2012-01-08 19:29:41 +01:00
|
|
|
if not time then
|
2012-01-26 18:23:47 +01:00
|
|
|
time = math.max(#msg * 100, 4000)
|
2012-01-08 19:29:41 +01:00
|
|
|
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
|
|
|
|
|
2012-01-25 15:56:17 +01:00
|
|
|
local function createTextMessageLabel(id, parent)
|
|
|
|
local label = createWidget('UILabel', parent)
|
|
|
|
label:setFont('verdana-11px-rounded')
|
|
|
|
label:setTextAlign(AlignCenter)
|
|
|
|
label:setId(id)
|
|
|
|
label:setMarginBottom(2)
|
|
|
|
label:setVisible(false)
|
|
|
|
return label
|
|
|
|
end
|
|
|
|
|
2012-01-08 16:42:23 +01:00
|
|
|
-- public functions
|
2012-01-25 15:56:17 +01:00
|
|
|
|
2012-01-08 16:42:23 +01:00
|
|
|
function TextMessage.create()
|
2012-01-25 15:56:17 +01:00
|
|
|
centerTextMessagePanel = createWidget('Panel', Game.gameMapPanel)
|
|
|
|
centerTextMessagePanel:setId('centerTextMessagePanel')
|
|
|
|
local layout = UIVerticalLayout.create(centerTextMessagePanel)
|
|
|
|
layout:setFitChildren(true)
|
|
|
|
centerTextMessagePanel:setLayout(layout)
|
|
|
|
centerTextMessagePanel:setWidth(360)
|
|
|
|
centerTextMessagePanel:centerIn('parent')
|
|
|
|
|
|
|
|
createTextMessageLabel('centerWarning', centerTextMessagePanel)
|
|
|
|
createTextMessageLabel('centerAdvance', centerTextMessagePanel)
|
|
|
|
createTextMessageLabel('centerInfo', centerTextMessagePanel)
|
|
|
|
|
|
|
|
bottomStatusLabel = createTextMessageLabel('bottomStatus', Game.gameMapPanel)
|
|
|
|
bottomStatusLabel:setHeight(16)
|
|
|
|
bottomStatusLabel:addAnchor(AnchorBottom, 'parent', AnchorBottom)
|
|
|
|
bottomStatusLabel:addAnchor(AnchorLeft, 'parent', AnchorLeft)
|
|
|
|
bottomStatusLabel:addAnchor(AnchorRight, 'parent', AnchorRight)
|
2012-01-08 16:42:23 +01:00
|
|
|
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-25 15:56:17 +01:00
|
|
|
local advanceLabel = Game.gameMapPanel:recursiveGetChildById('centerAdvance')
|
|
|
|
if advanceLabel:isVisible() then return end
|
|
|
|
TextMessage.displayEventAdvance('You are dead.')
|
2011-08-30 17:12:57 +02:00
|
|
|
end
|
2011-11-03 23:16:47 +01:00
|
|
|
|
2012-01-25 15:56:17 +01:00
|
|
|
local function onGameTextMessage(msgtypedesc, msg)
|
|
|
|
TextMessage.display(msgtypedesc, msg)
|
2012-01-08 19:29:41 +01:00
|
|
|
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 })
|