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 00:28:49 +01:00
|
|
|
monsterSay = { color = '#FE6500', hideInConsole = false},
|
2012-01-08 23:32:55 +01:00
|
|
|
npcToPlayer = { color = '#5FF7F7' },
|
|
|
|
channelYellow = { color = '#FFFF00' },
|
|
|
|
channelWhite = { color = '#FFFFFF' },
|
|
|
|
channelRed = { color = '#F55E5E' },
|
|
|
|
channelOrange = { color = '#FE6500' },
|
|
|
|
private = { color = '#FFFF00' },
|
|
|
|
playerToNpc = { color = '#9F9DFD' },
|
|
|
|
broadcast = { color = '#F55E5E' },
|
|
|
|
privateRed = { color = '#F55E5E' }
|
|
|
|
}
|
|
|
|
|
|
|
|
local consolePanel
|
|
|
|
local consoleBuffer
|
|
|
|
|
|
|
|
-- public functions
|
|
|
|
function Console.create()
|
|
|
|
consolePanel = displayUI('console.otui', { parent = Game.gameBottomPanel } )
|
|
|
|
consoleBuffer = consolePanel:getChildById('consoleBuffer')
|
|
|
|
end
|
|
|
|
|
|
|
|
function Console.destroy()
|
|
|
|
consolePanel:destroy()
|
|
|
|
consolePanel = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
function Console.addText(text, color)
|
|
|
|
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-08 23:32:55 +01:00
|
|
|
local label = createWidget('ConsoleLabel', consoleBuffer)
|
|
|
|
label:setText(text)
|
|
|
|
label:setForegroundColor(color)
|
|
|
|
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 00:28:49 +01:00
|
|
|
if speaktype == SpeakTypes.monsterSay 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
|
|
|
|
|
|
|
|
Console.addText(message, speaktype.color)
|
|
|
|
end
|
|
|
|
|
|
|
|
connect(Game, { onLogin = Console.create,
|
|
|
|
onLogout = Console.destroy,
|
|
|
|
onCreatureSpeak = onCreatureSpeak})
|