2012-01-08 23:32:55 +01:00
|
|
|
Console = {}
|
|
|
|
|
|
|
|
-- private variables
|
|
|
|
local SpeakTypes = {
|
|
|
|
say = { color = '#FFFF00' },
|
|
|
|
whisper = { color = '#FFFF00' },
|
|
|
|
yell = { color = '#FFFF00' },
|
2012-01-09 06:23:39 +01:00
|
|
|
monsterSay = { color = '#FE6500', hideInConsole = true},
|
|
|
|
monsterYell = { color = '#FE6500', hideInConsole = true},
|
2012-01-08 23:32:55 +01:00
|
|
|
npcToPlayer = { color = '#5FF7F7' },
|
|
|
|
channelYellow = { color = '#FFFF00' },
|
|
|
|
channelWhite = { color = '#FFFFFF' },
|
|
|
|
channelRed = { color = '#F55E5E' },
|
|
|
|
channelOrange = { color = '#FE6500' },
|
2012-01-09 07:46:44 +01:00
|
|
|
private = { color = '#5FF7F7' },
|
2012-01-08 23:32:55 +01:00
|
|
|
playerToNpc = { color = '#9F9DFD' },
|
|
|
|
broadcast = { color = '#F55E5E' },
|
|
|
|
privateRed = { color = '#F55E5E' }
|
|
|
|
}
|
|
|
|
|
|
|
|
local consolePanel
|
|
|
|
local consoleBuffer
|
2012-01-13 00:47:31 +01:00
|
|
|
local consoleTabBar
|
|
|
|
local defaultChannelTab
|
|
|
|
local serverLogTab
|
|
|
|
local current
|
2012-01-08 23:32:55 +01:00
|
|
|
|
|
|
|
-- public functions
|
|
|
|
function Console.create()
|
|
|
|
consolePanel = displayUI('console.otui', { parent = Game.gameBottomPanel } )
|
|
|
|
consoleBuffer = consolePanel:getChildById('consoleBuffer')
|
2012-01-13 00:47:31 +01:00
|
|
|
consoleTabBar = consolePanel:getChildById('consoleTabBar')
|
|
|
|
consoleTabBar:setContentWidget(consoleBuffer)
|
|
|
|
defaultChannelTab = consoleTabBar:addTab('Default')
|
|
|
|
serverLogTab = consoleTabBar:addTab('Server Log')
|
2012-01-08 23:32:55 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function Console.destroy()
|
|
|
|
consolePanel:destroy()
|
|
|
|
consolePanel = nil
|
|
|
|
end
|
|
|
|
|
2012-01-13 00:47:31 +01:00
|
|
|
function Console.addText(text, color, channelTab)
|
2012-01-08 23:32:55 +01:00
|
|
|
color = color or 'white'
|
|
|
|
|
2012-01-09 00:28:49 +01:00
|
|
|
if Options.showTimestampsInConsole then
|
|
|
|
text = os.date('%H:%M') .. ' ' .. text
|
|
|
|
end
|
|
|
|
|
2012-01-13 00:47:31 +01:00
|
|
|
local label = createWidget('ConsoleLabel', consoleTabBar:getTabPanel(channelTab))
|
2012-01-08 23:32:55 +01:00
|
|
|
label:setText(text)
|
2012-01-09 19:45:28 +01:00
|
|
|
label:setColor(color)
|
2012-01-13 00:47:31 +01:00
|
|
|
consoleTabBar:blinkTab(channelTab)
|
|
|
|
end
|
|
|
|
|
|
|
|
function Console.addChannelMessage(text, color, channel)
|
|
|
|
if channel == 'Server Log' then
|
|
|
|
Console.addText(text, color, serverLogTab)
|
|
|
|
elseif channel == 'Default' then
|
|
|
|
Console.addText(text, color, defaultChannelTab)
|
|
|
|
end
|
2012-01-08 23:32:55 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- hooked events
|
2012-01-09 00:28:49 +01:00
|
|
|
local function onCreatureSpeak(name, level, speaktypedesc, message, channelId, creaturePos)
|
2012-01-08 23:32:55 +01:00
|
|
|
speaktype = SpeakTypes[speaktypedesc]
|
2012-01-09 06:23:39 +01:00
|
|
|
if speaktype.hideInConsole then return end
|
2012-01-08 23:32:55 +01:00
|
|
|
|
|
|
|
if name then
|
2012-01-09 00:28:49 +01:00
|
|
|
if Options.showLevelsInConsole and level > 0 then
|
2012-01-08 23:32:55 +01:00
|
|
|
message = name .. ' [' .. level .. ']: ' .. message
|
|
|
|
else
|
|
|
|
message = name .. ': ' .. message
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-01-13 07:32:47 +01:00
|
|
|
Console.addText(message, speaktype.color, defaultChannelTab)
|
2012-01-08 23:32:55 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
connect(Game, { onLogin = Console.create,
|
|
|
|
onLogout = Console.destroy,
|
|
|
|
onCreatureSpeak = onCreatureSpeak})
|