tibia-client/modules/game_textmessage/textmessage.lua

124 lines
4.8 KiB
Lua
Raw Normal View History

TextMessage = {}
2011-08-30 17:12:57 +02:00
-- require styles
2012-06-26 00:13:30 +02:00
g_ui.importStyle('textmessage.otui')
2011-09-04 19:21:42 +02:00
-- private variables
2012-01-08 16:42:23 +01:00
local MessageTypes = {
consoleRed = { color = '#F55E5E', consoleTab = tr('Default') },
consoleOrange = { color = '#FE6500', consoleTab = tr('Default') },
consoleBlue = { color = '#9F9DFD', consoleTab = tr('Default') },
warning = { color = '#F55E5E', consoleTab = tr('Server Log'), labelId = 'centerWarning' },
infoDescription = { color = '#00EB00', consoleTab = tr('Server Log'), labelId = 'centerInfo', consoleOption = 'showInfoMessagesInConsole' },
eventAdvance = { color = '#FFFFFF', consoleTab = tr('Server Log'), labelId = 'centerAdvance', consoleOption = 'showEventMessagesInConsole' },
eventDefault = { color = '#FFFFFF', consoleTab = tr('Server Log'), labelId = 'bottomStatus', consoleOption = 'showEventMessagesInConsole' },
statusDefault = { color = '#FFFFFF', consoleTab = tr('Server Log'), labelId = 'bottomStatus', consoleOption = 'showStatusMessagesInConsole' },
statusSmall = { color = '#FFFFFF', labelId = 'bottomStatus' },
private = { color = '#5FF7F7', labelId = 'centerPrivate' }
2011-09-04 19:21:42 +02:00
}
local centerTextMessagePanel
local bottomStatusLabel
local privateLabel
2012-01-08 16:42:23 +01:00
-- private functions
local function displayMessage(msgtype, msg, time)
2012-02-08 22:23:15 +01:00
if not g_game.isOnline() then return end
2012-01-08 21:11:50 +01:00
2012-01-14 02:37:15 +01:00
if msgtype.consoleTab ~= nil then
if msgtype.consoleOption == nil or Options.getOption(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
if msgtype.labelId then
local label = GameInterface.getMapPanel():recursiveGetChildById(msgtype.labelId)
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-08 16:42:23 +01:00
if not time then
time = math.max(#msg * 100, 4000)
else
time = time * 1000
end
2012-01-08 16:42:23 +01:00
removeEvent(label.hideEvent)
addEvent(function() label:setVisible(true) end)
2012-01-08 16:42:23 +01:00
label.hideEvent = scheduleEvent(function() label:setVisible(false) end, time)
end
end
local function createTextMessageLabel(id, parent, class)
2012-06-26 00:13:30 +02:00
local label = g_ui.createWidget(class, parent)
label:setFont('verdana-11px-rounded')
label:setId(id)
return label
end
2012-01-08 16:42:23 +01:00
-- public functions
function TextMessage.init()
connect(g_game, { onTextMessage = TextMessage.display,
onGameStart = TextMessage.clearMessages })
2012-06-26 00:13:30 +02:00
centerTextMessagePanel = g_ui.createWidget('Panel', GameInterface.getMapPanel())
centerTextMessagePanel:setId('centerTextMessagePanel')
local layout = UIVerticalLayout.create(centerTextMessagePanel)
layout:setFitChildren(true)
centerTextMessagePanel:setLayout(layout)
centerTextMessagePanel:setWidth(360)
centerTextMessagePanel:centerIn('parent')
createTextMessageLabel('centerWarning', centerTextMessagePanel, 'CenterLabel')
createTextMessageLabel('centerAdvance', centerTextMessagePanel, 'CenterLabel')
createTextMessageLabel('centerInfo', centerTextMessagePanel, 'CenterLabel')
privateLabel = createTextMessageLabel('centerPrivate', GameInterface.getMapPanel(), 'TopCenterLabel')
bottomStatusLabel = createTextMessageLabel('bottomStatus', GameInterface.getMapPanel(), 'BottomLabel')
2012-01-08 16:42:23 +01:00
end
function TextMessage.terminate()
disconnect(g_game, { onDeath = TextMessage.displayDeadMessage,
onTextMessage = TextMessage.display,
2012-04-27 18:23:51 +02:00
onGameStart = TextMessage.clearMessages })
removeEvent(GameInterface.getMapPanel():recursiveGetChildById('centerWarning').hideEvent)
removeEvent(GameInterface.getMapPanel():recursiveGetChildById('centerAdvance').hideEvent)
removeEvent(GameInterface.getMapPanel():recursiveGetChildById('centerInfo').hideEvent)
removeEvent(GameInterface.getMapPanel():recursiveGetChildById('centerPrivate').hideEvent)
removeEvent(GameInterface.getMapPanel():recursiveGetChildById('bottomStatus').hideEvent)
centerTextMessagePanel:destroy()
bottomStatusLabel:destroy()
privateLabel:destroy()
centerTextMessagePanel = nil
bottomStatusLabel = nil
privateLabel = nil
TextMessage = nil
end
function TextMessage.clearMessages()
GameInterface.getMapPanel():recursiveGetChildById('centerWarning'):hide()
GameInterface.getMapPanel():recursiveGetChildById('centerAdvance'):hide()
GameInterface.getMapPanel():recursiveGetChildById('centerInfo'):hide()
GameInterface.getMapPanel():recursiveGetChildById('centerPrivate'):hide()
GameInterface.getMapPanel():recursiveGetChildById('bottomStatus'):hide()
end
function TextMessage.displayStatus(msg, time)
displayMessage(MessageTypes.statusSmall, msg)
end
function TextMessage.displayEventAdvance(msg, time)
displayMessage(MessageTypes.eventAdvance, msg, time)
2012-01-08 16:42:23 +01:00
end
function TextMessage.displayPrivate(msg, time)
displayMessage(MessageTypes.private, msg, time)
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