2012-01-08 23:32:55 +01:00
|
|
|
Console = {}
|
|
|
|
|
|
|
|
-- private variables
|
2012-02-03 05:32:39 +01:00
|
|
|
local SpeakTypesSettings = {
|
|
|
|
say = { speakType = SpeakSay, color = '#FFFF00' },
|
|
|
|
whisper = { speakType = SpeakWhisper, color = '#FFFF00' },
|
|
|
|
yell = { speakType = SpeakYell, color = '#FFFF00' },
|
|
|
|
broadcast = { speakType = SpeakBroadcast, color = '#F55E5E' },
|
|
|
|
private = { speakType = SpeakPrivate, color = '#5FF7F7', private = true },
|
|
|
|
privateRed = { speakType = SpeakPrivateRed, color = '#F55E5E', private = true },
|
|
|
|
privatePlayerToPlayer = { speakType = SpeakPrivate, color = '#9F9DFD', private = true },
|
|
|
|
privatePlayerToNpc = { speakType = SpeakPrivatePlayerToNpc, color = '#9F9DFD', private = true, npcChat = true },
|
|
|
|
privateNpcToPlayer = { speakType = SpeakPrivateNpcToPlayer, color = '#5FF7F7', private = true, npcChat = true },
|
|
|
|
channelYellow = { speakType = SpeakChannelYellow, color = '#FFFF00' },
|
|
|
|
channelWhite = { speakType = SpeakChannelWhite, color = '#FFFFFF' },
|
|
|
|
channelRed = { speakType = SpeakChannelRed, color = '#F55E5E' },
|
|
|
|
channelOrange = { speakType = SpeakChannelOrange, color = '#FE6500' },
|
|
|
|
monsterSay = { speakType = SpeakMonsterSay, color = '#FE6500', hideInConsole = true},
|
|
|
|
monsterYell = { speakType = SpeakMonsterYell, color = '#FE6500', hideInConsole = true},
|
|
|
|
}
|
|
|
|
|
2012-01-08 23:32:55 +01:00
|
|
|
local SpeakTypes = {
|
2012-02-03 06:24:45 +01:00
|
|
|
[SpeakSay] = SpeakTypesSettings.say,
|
|
|
|
[SpeakWhisper] = SpeakTypesSettings.whisper,
|
|
|
|
[SpeakYell] = SpeakTypesSettings.yell,
|
|
|
|
[SpeakBroadcast] = SpeakTypesSettings.broadcast,
|
|
|
|
[SpeakPrivate] = SpeakTypesSettings.private,
|
|
|
|
[SpeakPrivateRed] = SpeakTypesSettings.privateRed,
|
|
|
|
[SpeakPrivatePlayerToNpc] = SpeakTypesSettings.privatePlayerToNpc,
|
|
|
|
[SpeakPrivateNpcToPlayer] = SpeakTypesSettings.privateNpcToPlayer,
|
|
|
|
[SpeakChannelYellow] = SpeakTypesSettings.channelYellow,
|
|
|
|
[SpeakChannelWhite] = SpeakTypesSettings.channelWhite,
|
|
|
|
[SpeakChannelRed] = SpeakTypesSettings.channelRed,
|
|
|
|
[SpeakChannelOrange] = SpeakTypesSettings.channelOrange,
|
|
|
|
[SpeakMonsterSay] = SpeakTypesSettings.monsterSay,
|
|
|
|
[SpeakMonsterYell] = SpeakTypesSettings.monsterYell,
|
2012-01-08 23:32:55 +01:00
|
|
|
}
|
|
|
|
|
2012-02-03 10:59:04 +01:00
|
|
|
local SayModes = {
|
2012-06-19 10:46:49 +02:00
|
|
|
[1] = { speakTypeDesc = 'whisper', icon = 'icons/whisper.png' },
|
|
|
|
[2] = { speakTypeDesc = 'say', icon = 'icons/say.png' },
|
|
|
|
[3] = { speakTypeDesc = 'yell', icon = 'icons/yell.png' }
|
2012-02-03 10:59:04 +01:00
|
|
|
}
|
|
|
|
|
2012-04-27 06:54:14 +02:00
|
|
|
local MAX_HISTORY = 1000
|
|
|
|
local MAX_LINES = 100
|
2012-06-08 18:58:08 +02:00
|
|
|
local HELP_CHANNEL = 9
|
2012-04-27 06:54:14 +02:00
|
|
|
|
2012-01-08 23:32:55 +01:00
|
|
|
local consolePanel
|
2012-03-25 19:10:19 +02:00
|
|
|
local consoleContentPanel
|
2012-01-13 00:47:31 +01:00
|
|
|
local consoleTabBar
|
2012-03-31 15:43:01 +02:00
|
|
|
local consoleTextEdit
|
2012-01-14 02:37:15 +01:00
|
|
|
local channels
|
2012-03-22 22:47:52 +01:00
|
|
|
local channelsWindow
|
2012-04-24 13:20:14 +02:00
|
|
|
local ownPrivateName
|
2012-04-27 06:54:14 +02:00
|
|
|
local messageHistory = {}
|
|
|
|
local currentMessageIndex = 0
|
2012-06-11 10:17:52 +02:00
|
|
|
local ignoreNpcMessages = false
|
2012-01-14 02:37:15 +01:00
|
|
|
|
|
|
|
-- private functions
|
2012-02-03 21:27:13 +01:00
|
|
|
local function navigateMessageHistory(step)
|
|
|
|
local numCommands = #messageHistory
|
|
|
|
if numCommands > 0 then
|
|
|
|
currentMessageIndex = math.min(math.max(currentMessageIndex + step, 0), numCommands)
|
|
|
|
if currentMessageIndex > 0 then
|
|
|
|
local command = messageHistory[numCommands - currentMessageIndex + 1]
|
2012-03-31 15:43:01 +02:00
|
|
|
consoleTextEdit:setText(command)
|
2012-02-03 21:27:13 +01:00
|
|
|
else
|
2012-03-31 15:43:01 +02:00
|
|
|
consoleTextEdit:clearText()
|
2012-02-03 21:27:13 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-01-14 02:37:15 +01:00
|
|
|
function applyMessagePrefixies(name, level, message)
|
|
|
|
if name then
|
2012-03-22 22:47:52 +01:00
|
|
|
if Options.getOption('showLevelsInConsole') and level > 0 then
|
2012-01-14 02:37:15 +01:00
|
|
|
message = name .. ' [' .. level .. ']: ' .. message
|
|
|
|
else
|
|
|
|
message = name .. ': ' .. message
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return message
|
|
|
|
end
|
2012-01-08 23:32:55 +01:00
|
|
|
|
2012-03-18 14:34:39 +01:00
|
|
|
-- hooked events
|
|
|
|
local function onCreatureSpeak(name, level, speaktype, message, channelId, creaturePos)
|
2012-06-11 10:17:52 +02:00
|
|
|
if ignoreNpcMessages and speaktype == SpeakPrivateNpcToPlayer then return end
|
2012-04-24 06:01:59 +02:00
|
|
|
local defaultMessage = speaktype < 3 and true or false
|
2012-03-18 14:34:39 +01:00
|
|
|
speaktype = SpeakTypes[speaktype]
|
|
|
|
if speaktype.hideInConsole then return end
|
|
|
|
|
2012-06-09 15:00:08 +02:00
|
|
|
local composedMessage = applyMessagePrefixies(name, level, message)
|
2012-03-18 14:34:39 +01:00
|
|
|
|
|
|
|
if speaktype.private then
|
2012-06-09 15:00:08 +02:00
|
|
|
Console.addPrivateText(composedMessage, speaktype, name, false, name)
|
|
|
|
if Options.getOption('showPrivateMessagesOnScreen') then
|
|
|
|
TextMessage.displayPrivate(name .. ':\n' .. message)
|
|
|
|
end
|
2012-03-18 14:34:39 +01:00
|
|
|
else
|
2012-04-26 21:54:16 +02:00
|
|
|
local channel = tr('Default')
|
2012-04-24 06:01:59 +02:00
|
|
|
if not defaultMessage then
|
|
|
|
channel = channels[channelId]
|
|
|
|
end
|
2012-04-28 22:18:36 +02:00
|
|
|
|
2012-03-18 14:34:39 +01:00
|
|
|
if channel then
|
2012-06-09 15:00:08 +02:00
|
|
|
Console.addText(composedMessage, speaktype, channel, name)
|
2012-04-30 18:40:12 +02:00
|
|
|
elseif channelId ~= 0 then
|
2012-04-28 22:18:36 +02:00
|
|
|
-- server sent a message on a channel that is not open
|
2012-06-20 02:15:56 +02:00
|
|
|
pwarning('message in channel id ' .. channelId .. ' which is unknown, this is a server bug, relogin if you want to see messages in this channel')
|
2012-03-18 14:34:39 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function onOpenChannel(channelId, channelName)
|
2012-04-30 23:57:17 +02:00
|
|
|
Console.addChannel(channelName, channelId)
|
2012-03-18 14:34:39 +01:00
|
|
|
end
|
|
|
|
|
2012-04-24 13:39:45 +02:00
|
|
|
local function onOpenPrivateChannel(receiver)
|
|
|
|
local privateTab = Console.getTab(receiver)
|
|
|
|
if privateTab == nil then
|
2012-04-30 23:57:17 +02:00
|
|
|
channels[receiver] = receiver
|
2012-04-27 08:30:54 +02:00
|
|
|
Console.addTab(receiver, true)
|
2012-04-24 13:39:45 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function onOpenOwnPrivateChannel(channelId, channelName)
|
2012-04-24 13:20:14 +02:00
|
|
|
local privateTab = Console.getTab(channelName)
|
2012-03-18 14:34:39 +01:00
|
|
|
if privateTab == nil then
|
2012-04-30 23:57:17 +02:00
|
|
|
--channels[channelId] = channelName (this should be tested)
|
2012-04-24 13:20:14 +02:00
|
|
|
Console.addChannel(channelName, channelId, true)
|
2012-03-18 14:34:39 +01:00
|
|
|
end
|
2012-04-24 13:20:14 +02:00
|
|
|
ownPrivateName = channelName
|
2012-03-18 14:34:39 +01:00
|
|
|
end
|
|
|
|
|
2012-04-08 06:13:52 +02:00
|
|
|
local function onCloseChannel(channelId)
|
|
|
|
local channel = channels[channelId]
|
|
|
|
if channel then
|
|
|
|
local tab = Console.getTab(channel)
|
|
|
|
if tab then
|
|
|
|
consoleTabBar:removeTab(tab)
|
2012-04-24 13:39:45 +02:00
|
|
|
end
|
2012-04-08 06:13:52 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-03-22 22:47:52 +01:00
|
|
|
local function doChannelListSubmit()
|
2012-03-18 14:34:39 +01:00
|
|
|
local channelListPanel = channelsWindow:getChildById('channelList')
|
|
|
|
local openPrivateChannelWith = channelsWindow:getChildById('openPrivateChannelWith'):getText()
|
|
|
|
if openPrivateChannelWith ~= '' then
|
|
|
|
g_game.openPrivateChannel(openPrivateChannelWith)
|
|
|
|
else
|
|
|
|
local selectedChannelLabel = channelListPanel:getFocusedChild()
|
|
|
|
if not selectedChannelLabel then return end
|
2012-04-24 13:20:14 +02:00
|
|
|
if selectedChannelLabel.channelId == 0xFFFF then
|
|
|
|
g_game.openOwnChannel()
|
|
|
|
else
|
|
|
|
g_game.joinChannel(selectedChannelLabel.channelId)
|
|
|
|
end
|
2012-03-18 14:34:39 +01:00
|
|
|
end
|
2012-03-22 22:47:52 +01:00
|
|
|
|
2012-03-18 14:34:39 +01:00
|
|
|
channelsWindow:destroy()
|
|
|
|
end
|
|
|
|
|
|
|
|
local function onChannelList(channelList)
|
2012-03-22 22:47:52 +01:00
|
|
|
if channelsWindow then channelsWindow:destroy() end
|
2012-06-26 00:13:30 +02:00
|
|
|
channelsWindow = g_ui.displayUI('channelswindow.otui')
|
2012-03-18 14:34:39 +01:00
|
|
|
local channelListPanel = channelsWindow:getChildById('channelList')
|
2012-03-22 22:47:52 +01:00
|
|
|
channelsWindow.onEnter = doChannelListSubmit
|
|
|
|
channelsWindow.onDestroy = function() channelsWindow = nil end
|
2012-06-26 00:13:30 +02:00
|
|
|
g_keyboard.bindKeyPress('Down', function() channelListPanel:focusNextChild(KeyboardFocusReason) end, channelsWindow)
|
|
|
|
g_keyboard.bindKeyPress('Up', function() channelListPanel:focusPreviousChild(KeyboardFocusReason) end, channelsWindow)
|
2012-03-18 14:34:39 +01:00
|
|
|
|
|
|
|
for k,v in pairs(channelList) do
|
|
|
|
local channelId = v[1]
|
|
|
|
local channelName = v[2]
|
|
|
|
|
2012-04-24 05:19:01 +02:00
|
|
|
if #channelName > 0 then
|
2012-06-26 00:13:30 +02:00
|
|
|
local label = g_ui.createWidget('ChannelListLabel', channelListPanel)
|
2012-03-18 14:34:39 +01:00
|
|
|
label.channelId = channelId
|
|
|
|
label:setText(channelName)
|
|
|
|
|
|
|
|
label:setPhantom(false)
|
2012-03-22 22:47:52 +01:00
|
|
|
label.onDoubleClick = doChannelListSubmit
|
2012-03-18 14:34:39 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-04-26 02:15:48 +02:00
|
|
|
local function onGameStart()
|
2012-04-26 21:54:16 +02:00
|
|
|
local tab = Console.getTab(tr('Default'))
|
2012-04-26 02:15:48 +02:00
|
|
|
if tab then
|
|
|
|
addEvent(function() consoleTabBar:selectTab(tab) end, false)
|
|
|
|
end
|
|
|
|
end
|
2012-03-18 14:34:39 +01:00
|
|
|
|
2012-01-08 23:32:55 +01:00
|
|
|
-- public functions
|
2012-03-18 14:34:39 +01:00
|
|
|
function Console.init()
|
|
|
|
connect(g_game, { onCreatureSpeak = onCreatureSpeak,
|
|
|
|
onChannelList = onChannelList,
|
|
|
|
onOpenChannel = onOpenChannel,
|
2012-04-24 13:39:45 +02:00
|
|
|
onOpenPrivateChannel = onOpenPrivateChannel,
|
|
|
|
onOpenOwnPrivateChannel = onOpenOwnPrivateChannel,
|
2012-04-08 06:13:52 +02:00
|
|
|
onCloseChannel = onCloseChannel,
|
2012-04-26 02:15:48 +02:00
|
|
|
onGameStart = onGameStart,
|
2012-03-23 14:48:05 +01:00
|
|
|
onGameEnd = Console.clear })
|
2012-03-18 14:34:39 +01:00
|
|
|
|
2012-06-26 00:13:30 +02:00
|
|
|
consolePanel = g_ui.loadUI('console.otui', GameInterface.getBottomPanel())
|
2012-03-31 15:43:01 +02:00
|
|
|
consoleTextEdit = consolePanel:getChildById('consoleTextEdit')
|
2012-03-25 19:10:19 +02:00
|
|
|
consoleContentPanel = consolePanel:getChildById('consoleContentPanel')
|
2012-01-13 00:47:31 +01:00
|
|
|
consoleTabBar = consolePanel:getChildById('consoleTabBar')
|
2012-03-25 19:10:19 +02:00
|
|
|
consoleTabBar:setContentWidget(consoleContentPanel)
|
2012-01-14 02:37:15 +01:00
|
|
|
channels = {}
|
|
|
|
|
2012-04-26 21:54:16 +02:00
|
|
|
Console.addTab(tr('Default'), true)
|
|
|
|
Console.addTab(tr('Server Log'), false)
|
2012-02-04 03:11:18 +01:00
|
|
|
|
2012-06-26 00:13:30 +02:00
|
|
|
g_keyboard.bindKeyPress('Shift+Up', function() navigateMessageHistory(1) end, consolePanel)
|
|
|
|
g_keyboard.bindKeyPress('Shift+Down', function() navigateMessageHistory(-1) end, consolePanel)
|
|
|
|
g_keyboard.bindKeyPress('Tab', function() consoleTabBar:selectNextTab() end, consolePanel)
|
|
|
|
g_keyboard.bindKeyPress('Shift+Tab', function() consoleTabBar:selectPrevTab() end, consolePanel)
|
|
|
|
g_keyboard.bindKeyDown('Enter', Console.sendCurrentMessage, consolePanel)
|
|
|
|
g_keyboard.bindKeyPress('Ctrl+A', function() consoleTextEdit:clearText() end, consolePanel)
|
2012-02-04 03:11:18 +01:00
|
|
|
|
2012-02-03 06:24:45 +01:00
|
|
|
-- apply buttom functions after loaded
|
2012-03-18 14:34:39 +01:00
|
|
|
consolePanel:getChildById('nextChannelButton').onClick = function() consoleTabBar:selectNextTab() end
|
|
|
|
consolePanel:getChildById('prevChannelButton').onClick = function() consoleTabBar:selectPrevTab() end
|
|
|
|
consoleTabBar.onTabChange = Console.onTabChange
|
2012-02-04 03:11:18 +01:00
|
|
|
|
2012-02-03 06:24:45 +01:00
|
|
|
-- tibia like hotkeys
|
2012-06-26 00:13:30 +02:00
|
|
|
g_keyboard.bindKeyDown('Ctrl+O', g_game.requestChannels)
|
|
|
|
g_keyboard.bindKeyDown('Ctrl+E', Console.removeCurrentTab)
|
|
|
|
g_keyboard.bindKeyDown('Ctrl+H', Console.openHelp)
|
2012-01-08 23:32:55 +01:00
|
|
|
end
|
|
|
|
|
2012-03-18 14:34:39 +01:00
|
|
|
function Console.terminate()
|
|
|
|
disconnect(g_game, { onCreatureSpeak = onCreatureSpeak,
|
|
|
|
onChannelList = onChannelList,
|
|
|
|
onOpenChannel = onOpenChannel,
|
2012-04-24 13:39:45 +02:00
|
|
|
onOpenPrivateChannel = onOpenPrivateChannel,
|
2012-04-24 13:20:14 +02:00
|
|
|
onOpenOwnPrivateChannel = onOpenPrivateChannel,
|
2012-04-08 06:13:52 +02:00
|
|
|
onCloseChannel = onCloseChannel,
|
2012-04-26 02:15:48 +02:00
|
|
|
onGameStart = onGameStart,
|
2012-03-23 14:48:05 +01:00
|
|
|
onGameEnd = Console.clear })
|
2012-03-18 14:34:39 +01:00
|
|
|
|
2012-03-22 22:47:52 +01:00
|
|
|
for channelid, channelname in pairs(channels) do
|
2012-06-04 00:55:26 +02:00
|
|
|
if tonumber(channelid) and tonumber(channelid) ~= 0 then
|
2012-03-22 22:47:52 +01:00
|
|
|
g_game.leaveChannel(channelid)
|
|
|
|
end
|
2012-03-18 14:34:39 +01:00
|
|
|
end
|
2012-03-22 22:47:52 +01:00
|
|
|
channels = {}
|
2012-03-18 14:34:39 +01:00
|
|
|
|
2012-06-26 00:13:30 +02:00
|
|
|
g_keyboard.unbindKeyDown('Ctrl+O')
|
|
|
|
g_keyboard.unbindKeyDown('Ctrl+E')
|
|
|
|
g_keyboard.unbindKeyDown('Ctrl+H')
|
2012-03-18 14:34:39 +01:00
|
|
|
|
2012-03-22 22:47:52 +01:00
|
|
|
if channelsWindow then
|
|
|
|
channelsWindow:destroy()
|
|
|
|
channelsWindow = nil
|
|
|
|
end
|
|
|
|
|
2012-01-08 23:32:55 +01:00
|
|
|
consolePanel:destroy()
|
|
|
|
consolePanel = nil
|
2012-03-31 15:43:01 +02:00
|
|
|
consoleTextEdit = nil
|
2012-03-25 19:10:19 +02:00
|
|
|
consoleContentPanel = nil
|
2012-03-18 14:34:39 +01:00
|
|
|
consoleTabBar = nil
|
|
|
|
|
2012-04-24 13:20:14 +02:00
|
|
|
ownPrivateName = nil
|
2012-04-27 06:54:14 +02:00
|
|
|
|
|
|
|
Console = nil
|
2012-01-08 23:32:55 +01:00
|
|
|
end
|
|
|
|
|
2012-03-23 14:48:05 +01:00
|
|
|
function Console.clear()
|
2012-03-22 22:47:52 +01:00
|
|
|
for channelid, channelname in pairs(channels) do
|
2012-04-24 06:01:59 +02:00
|
|
|
local tab = consoleTabBar:getTab(channelname)
|
|
|
|
consoleTabBar:removeTab(tab)
|
2012-03-22 22:47:52 +01:00
|
|
|
end
|
2012-06-20 02:15:56 +02:00
|
|
|
|
2012-03-22 22:47:52 +01:00
|
|
|
channels = {}
|
|
|
|
|
2012-04-26 21:54:16 +02:00
|
|
|
consoleTabBar:getTab(tr('Default')).tabPanel:getChildById('consoleBuffer'):destroyChildren()
|
|
|
|
consoleTabBar:getTab(tr('Server Log')).tabPanel:getChildById('consoleBuffer'):destroyChildren()
|
2012-03-26 00:14:00 +02:00
|
|
|
|
|
|
|
local npcTab = consoleTabBar:getTab('NPCs')
|
|
|
|
if npcTab then
|
|
|
|
consoleTabBar:removeTab(npcTab)
|
|
|
|
end
|
|
|
|
|
2012-03-31 15:43:01 +02:00
|
|
|
consoleTextEdit:clearText()
|
2012-03-22 22:47:52 +01:00
|
|
|
|
|
|
|
if channelsWindow then
|
|
|
|
channelsWindow:destroy()
|
|
|
|
channelsWindow = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-03-31 15:43:01 +02:00
|
|
|
function Console.setTextEditText(text)
|
|
|
|
consoleTextEdit:setText(text)
|
2012-02-07 06:52:48 +01:00
|
|
|
end
|
|
|
|
|
2012-06-08 18:58:08 +02:00
|
|
|
function Console.openHelp()
|
|
|
|
g_game.joinChannel(HELP_CHANNEL)
|
|
|
|
end
|
|
|
|
|
2012-02-03 05:32:39 +01:00
|
|
|
function Console.addTab(name, focus)
|
2012-01-14 02:37:15 +01:00
|
|
|
local tab = consoleTabBar:addTab(name)
|
2012-02-03 05:32:39 +01:00
|
|
|
if focus then
|
2012-02-04 04:03:46 +01:00
|
|
|
consoleTabBar:selectTab(tab)
|
2012-04-26 21:54:16 +02:00
|
|
|
elseif name ~= tr('Server Log') then
|
2012-02-04 04:03:46 +01:00
|
|
|
consoleTabBar:blinkTab(tab)
|
2012-02-03 05:32:39 +01:00
|
|
|
end
|
2012-01-14 02:37:15 +01:00
|
|
|
return tab
|
|
|
|
end
|
2012-01-08 23:32:55 +01:00
|
|
|
|
2012-02-03 05:32:39 +01:00
|
|
|
function Console.onTabChange(tabBar, tab)
|
2012-04-26 21:54:16 +02:00
|
|
|
if tab:getText() == tr('Default') or tab:getText() == tr('Server Log') then
|
2012-02-03 06:24:45 +01:00
|
|
|
consolePanel:getChildById('closeChannelButton'):disable()
|
|
|
|
else
|
|
|
|
consolePanel:getChildById('closeChannelButton'):enable()
|
|
|
|
end
|
2012-02-03 05:32:39 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function Console.removeCurrentTab()
|
|
|
|
local tab = consoleTabBar:getCurrentTab()
|
2012-04-26 21:54:16 +02:00
|
|
|
if tab:getText() == tr('Default') or tab:getText() == tr('Server Log') then return end
|
2012-02-04 03:11:18 +01:00
|
|
|
|
2012-02-04 04:03:46 +01:00
|
|
|
-- notificate the server that we are leaving the channel
|
|
|
|
if tab.channelId then
|
2012-02-08 22:23:15 +01:00
|
|
|
g_game.leaveChannel(tab.channelId)
|
2012-02-04 04:03:46 +01:00
|
|
|
elseif tab:getText() == "NPCs" then
|
2012-02-08 22:23:15 +01:00
|
|
|
g_game.closeNpcChannel()
|
2012-02-04 04:03:46 +01:00
|
|
|
end
|
2012-04-07 00:14:39 +02:00
|
|
|
|
|
|
|
consoleTabBar:removeTab(tab)
|
2012-02-03 05:32:39 +01:00
|
|
|
end
|
|
|
|
|
2012-01-14 02:37:15 +01:00
|
|
|
function Console.getTab(name)
|
|
|
|
return consoleTabBar:getTab(name)
|
|
|
|
end
|
|
|
|
|
|
|
|
function Console.getCurrentTab()
|
|
|
|
return consoleTabBar:getCurrentTab()
|
|
|
|
end
|
|
|
|
|
|
|
|
function Console.addChannel(name, id)
|
|
|
|
channels[id] = name
|
2012-02-03 05:32:39 +01:00
|
|
|
local tab = Console.addTab(name, true)
|
2012-01-14 02:37:15 +01:00
|
|
|
tab.channelId = id
|
|
|
|
return tab
|
|
|
|
end
|
|
|
|
|
2012-05-01 08:49:48 +02:00
|
|
|
function Console.addPrivateText(text, speaktype, name, isPrivateCommand, creatureName)
|
2012-02-04 04:03:46 +01:00
|
|
|
local focus = false
|
2012-02-03 07:20:58 +01:00
|
|
|
if speaktype.speakType == SpeakPrivateNpcToPlayer then
|
|
|
|
name = 'NPCs'
|
2012-02-04 04:03:46 +01:00
|
|
|
focus = true
|
2012-02-03 07:20:58 +01:00
|
|
|
end
|
|
|
|
|
2012-01-14 02:37:15 +01:00
|
|
|
local privateTab = Console.getTab(name)
|
|
|
|
if privateTab == nil then
|
2012-06-09 15:00:08 +02:00
|
|
|
if (Options.getOption('showPrivateMessagesInConsole') and not focus) or (isPrivateCommand and not privateTab) then
|
2012-04-26 21:54:16 +02:00
|
|
|
privateTab = Console.getTab(tr('Default'))
|
2012-01-14 02:37:15 +01:00
|
|
|
else
|
2012-02-04 04:03:46 +01:00
|
|
|
privateTab = Console.addTab(name, focus)
|
2012-06-10 02:12:28 +02:00
|
|
|
channels[name] = name
|
2012-01-14 02:37:15 +01:00
|
|
|
end
|
|
|
|
privateTab.npcChat = speaktype.npcChat
|
2012-02-04 04:03:46 +01:00
|
|
|
elseif focus then
|
|
|
|
consoleTabBar:selectTab(privateTab)
|
2012-01-14 02:37:15 +01:00
|
|
|
end
|
2012-05-01 08:49:48 +02:00
|
|
|
Console.addTabText(text, speaktype, privateTab, creatureName)
|
2012-01-14 02:37:15 +01:00
|
|
|
end
|
|
|
|
|
2012-05-01 08:49:48 +02:00
|
|
|
function Console.addText(text, speaktype, tabName, creatureName)
|
2012-01-14 02:37:15 +01:00
|
|
|
local tab = Console.getTab(tabName)
|
2012-02-03 10:59:04 +01:00
|
|
|
if tab ~= nil then
|
2012-05-01 08:49:48 +02:00
|
|
|
Console.addTabText(text, speaktype, tab, creatureName)
|
2012-02-03 10:59:04 +01:00
|
|
|
end
|
2012-01-14 02:37:15 +01:00
|
|
|
end
|
|
|
|
|
2012-05-01 08:49:48 +02:00
|
|
|
function Console.addTabText(text, speaktype, tab, creatureName)
|
2012-03-23 23:02:58 +01:00
|
|
|
if Options.getOption('showTimestampsInConsole') then
|
2012-01-09 00:28:49 +01:00
|
|
|
text = os.date('%H:%M') .. ' ' .. text
|
|
|
|
end
|
|
|
|
|
2012-01-14 21:14:40 +01:00
|
|
|
local panel = consoleTabBar:getTabPanel(tab)
|
2012-03-25 19:10:19 +02:00
|
|
|
local consoleBuffer = panel:getChildById('consoleBuffer')
|
2012-06-26 00:13:30 +02:00
|
|
|
local label = g_ui.createWidget('ConsoleLabel', consoleBuffer)
|
2012-03-25 19:10:19 +02:00
|
|
|
label:setId('consoleLabel' .. panel:getChildCount())
|
2012-01-08 23:32:55 +01:00
|
|
|
label:setText(text)
|
2012-01-14 02:37:15 +01:00
|
|
|
label:setColor(speaktype.color)
|
|
|
|
consoleTabBar:blinkTab(tab)
|
2012-01-14 21:14:40 +01:00
|
|
|
|
2012-05-01 08:49:48 +02:00
|
|
|
label.onMouseRelease = function (self, mousePos, mouseButton) Console.popupMenu(mousePos, mouseButton, creatureName, text) end
|
2012-06-09 15:00:08 +02:00
|
|
|
|
2012-03-25 19:10:19 +02:00
|
|
|
if consoleBuffer:getChildCount() > MAX_LINES then
|
|
|
|
consoleBuffer:getFirstChild():destroy()
|
2012-01-14 21:14:40 +01:00
|
|
|
end
|
2012-01-13 00:47:31 +01:00
|
|
|
end
|
|
|
|
|
2012-05-01 08:49:48 +02:00
|
|
|
function Console.popupMenu(mousePos, mouseButton, creatureName, text)
|
|
|
|
if mouseButton == MouseRightButton then
|
2012-06-26 00:13:30 +02:00
|
|
|
local menu = g_ui.createWidget('PopupMenu')
|
2012-05-01 08:49:48 +02:00
|
|
|
if creatureName then
|
2012-06-04 02:28:19 +02:00
|
|
|
if creatureName ~= g_game.getCharacterName() then
|
2012-05-01 08:49:48 +02:00
|
|
|
menu:addOption(tr('Message to ' .. creatureName), function () g_game.openPrivateChannel(creatureName) end)
|
|
|
|
menu:addOption(tr('Add to VIP list'), function () g_game.addVip(creatureName) end) --TODO not show if creature already in vip
|
|
|
|
-- TODO ignore creatureName
|
|
|
|
menu:addSeparator()
|
|
|
|
end
|
|
|
|
--TODO select all
|
|
|
|
menu:addOption(tr('Copy message'), function () g_window.setClipboardText(text) end)
|
2012-06-20 02:15:56 +02:00
|
|
|
|
2012-05-01 08:49:48 +02:00
|
|
|
if RuleViolation.hasWindowAccess() then
|
|
|
|
menu:addSeparator()
|
|
|
|
menu:addOption(tr('Rule Violation'), function() RuleViolation.show(creatureName, text:match('.+%:%s(.+)')) end)
|
|
|
|
end
|
2012-06-20 02:15:56 +02:00
|
|
|
|
2012-05-01 08:49:48 +02:00
|
|
|
menu:addSeparator()
|
|
|
|
menu:addOption(tr('Copy name'), function () g_window.setClipboardText(creatureName) end)
|
|
|
|
else
|
|
|
|
--TODO select all
|
|
|
|
menu:addOption(tr('Copy message'), function () g_window.setClipboardText(text) end)
|
|
|
|
end
|
|
|
|
menu:display(mousePos)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-01-14 02:37:15 +01:00
|
|
|
function Console.sendCurrentMessage()
|
2012-03-31 15:43:01 +02:00
|
|
|
local message = consoleTextEdit:getText()
|
2012-01-14 02:37:15 +01:00
|
|
|
if #message == 0 then return end
|
2012-03-31 15:43:01 +02:00
|
|
|
consoleTextEdit:clearText()
|
2012-01-14 02:37:15 +01:00
|
|
|
|
2012-01-14 06:54:20 +01:00
|
|
|
-- get current channel
|
2012-01-14 02:37:15 +01:00
|
|
|
local tab = Console.getCurrentTab()
|
|
|
|
|
2012-02-03 10:59:04 +01:00
|
|
|
-- handling chat commands
|
2012-02-03 21:27:13 +01:00
|
|
|
local originalMessage = message
|
2012-02-03 10:59:04 +01:00
|
|
|
local chatCommandSayMode
|
|
|
|
local chatCommandPrivate
|
2012-02-03 22:37:42 +01:00
|
|
|
local chatCommandPrivateReady
|
2012-02-04 03:11:18 +01:00
|
|
|
|
2012-02-03 10:59:04 +01:00
|
|
|
local chatCommandMessage = message:match("^%#y (.*)")
|
|
|
|
if chatCommandMessage ~= nil then chatCommandSayMode = 'yell' end -- player used yell command
|
|
|
|
message = chatCommandMessage or message
|
2012-02-04 03:11:18 +01:00
|
|
|
|
2012-02-03 10:59:04 +01:00
|
|
|
local chatCommandMessage = message:match("^%#w (.*)")
|
|
|
|
if chatCommandMessage ~= nil then chatCommandSayMode = 'whisper' end -- player used whisper
|
|
|
|
message = chatCommandMessage or message
|
2012-02-04 03:11:18 +01:00
|
|
|
|
|
|
|
local findIni, findEnd, chatCommandInitial, chatCommandPrivate, chatCommandEnd, chatCommandMessage = message:find("([%*%@])(.+)([%*%@])(.*)")
|
2012-02-03 10:59:04 +01:00
|
|
|
if findIni ~= nil and findIni == 1 then -- player used private chat command
|
|
|
|
if chatCommandInitial == chatCommandEnd then
|
|
|
|
chatCommandPrivateRepeat = false
|
|
|
|
if chatCommandInitial == "*" then
|
2012-03-31 15:43:01 +02:00
|
|
|
consoleTextEdit:setText('*'.. chatCommandPrivate .. '* ')
|
2012-02-04 03:11:18 +01:00
|
|
|
end
|
2012-02-03 10:59:04 +01:00
|
|
|
message = chatCommandMessage:trim()
|
2012-02-03 22:37:42 +01:00
|
|
|
chatCommandPrivateReady = true
|
2012-02-03 10:59:04 +01:00
|
|
|
end
|
|
|
|
end
|
2012-02-04 03:11:18 +01:00
|
|
|
|
2012-02-03 10:59:04 +01:00
|
|
|
message = message:gsub("^(%s*)(.*)","%2") -- remove space characters from message init
|
|
|
|
if #message == 0 then return end
|
|
|
|
|
2012-02-03 21:27:13 +01:00
|
|
|
-- add new command to history
|
|
|
|
currentMessageIndex = 0
|
2012-05-01 08:49:48 +02:00
|
|
|
if #messageHistory == 0 or messageHistory[#messageHistory] ~= originalMessage then
|
|
|
|
table.insert(messageHistory, originalMessage)
|
|
|
|
if #messageHistory > MAX_HISTORY then
|
|
|
|
table.remove(messageHistory, 1)
|
|
|
|
end
|
2012-02-03 21:27:13 +01:00
|
|
|
end
|
2012-02-04 03:11:18 +01:00
|
|
|
|
2012-01-14 06:54:20 +01:00
|
|
|
-- when talking on server log, the message goes to default channel
|
|
|
|
local name = tab:getText()
|
2012-04-26 21:54:16 +02:00
|
|
|
if name == tr('Server Log') then
|
|
|
|
tab = Console.getTab(tr('Default'))
|
|
|
|
name = tr('Default')
|
2012-01-14 02:37:15 +01:00
|
|
|
end
|
2012-06-09 15:00:08 +02:00
|
|
|
|
2012-01-14 06:54:20 +01:00
|
|
|
local speaktypedesc
|
2012-04-26 21:54:16 +02:00
|
|
|
if (tab.channelId or name == tr('Default')) and not chatCommandPrivateReady then
|
|
|
|
if name == tr('Default') then
|
2012-02-03 10:59:04 +01:00
|
|
|
speaktypedesc = chatCommandSayMode or SayModes[consolePanel:getChildById('sayModeButton').sayMode].speakTypeDesc
|
|
|
|
if speaktypedesc ~= 'say' then Console.sayModeChange(2) end -- head back to say mode
|
2012-01-14 06:54:20 +01:00
|
|
|
else
|
2012-01-14 02:37:15 +01:00
|
|
|
speaktypedesc = 'channelYellow'
|
|
|
|
end
|
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
g_game.talkChannel(SpeakTypesSettings[speaktypedesc].speakType, tab.channelId, message)
|
2012-01-14 02:37:15 +01:00
|
|
|
return
|
|
|
|
else
|
2012-02-03 10:59:04 +01:00
|
|
|
local isPrivateCommand = false
|
2012-02-03 22:37:42 +01:00
|
|
|
if chatCommandPrivateReady then
|
2012-02-03 10:59:04 +01:00
|
|
|
speaktypedesc = 'privatePlayerToPlayer'
|
|
|
|
name = chatCommandPrivate
|
|
|
|
isPrivateCommand = true
|
|
|
|
elseif tab.npcChat then
|
2012-02-03 05:32:39 +01:00
|
|
|
speaktypedesc = 'privatePlayerToNpc'
|
2012-01-14 06:54:20 +01:00
|
|
|
else
|
2012-02-03 05:32:39 +01:00
|
|
|
speaktypedesc = 'privatePlayerToPlayer'
|
2012-01-14 06:54:20 +01:00
|
|
|
end
|
2012-02-04 03:11:18 +01:00
|
|
|
|
2012-01-14 06:54:20 +01:00
|
|
|
|
2012-02-03 05:32:39 +01:00
|
|
|
local speaktype = SpeakTypesSettings[speaktypedesc]
|
2012-02-08 22:23:15 +01:00
|
|
|
local player = g_game.getLocalPlayer()
|
|
|
|
g_game.talkPrivate(speaktype.speakType, name, message)
|
2012-01-14 06:54:20 +01:00
|
|
|
|
2012-01-14 02:37:15 +01:00
|
|
|
message = applyMessagePrefixies(player:getName(), player:getLevel(), message)
|
2012-06-04 02:28:19 +02:00
|
|
|
Console.addPrivateText(message, speaktype, name, isPrivateCommand, g_game.getCharacterName())
|
2012-01-13 00:47:31 +01:00
|
|
|
end
|
2012-01-08 23:32:55 +01:00
|
|
|
end
|
|
|
|
|
2012-02-03 10:59:04 +01:00
|
|
|
function Console.sayModeChange(sayMode)
|
|
|
|
local buttom = consolePanel:getChildById('sayModeButton')
|
|
|
|
if sayMode == nil then
|
|
|
|
sayMode = buttom.sayMode + 1
|
|
|
|
end
|
2012-02-04 03:11:18 +01:00
|
|
|
|
2012-02-03 10:59:04 +01:00
|
|
|
if sayMode > #SayModes then sayMode = 1 end
|
|
|
|
|
|
|
|
buttom:setIcon(SayModes[sayMode].icon)
|
2012-02-04 03:11:18 +01:00
|
|
|
buttom.sayMode = sayMode
|
2012-02-03 10:59:04 +01:00
|
|
|
end
|
2012-04-24 13:20:14 +02:00
|
|
|
|
|
|
|
function Console.getOwnPrivateTab()
|
|
|
|
if not ownPrivateName then return end
|
|
|
|
return Console.getTab(ownPrivateName)
|
|
|
|
end
|
2012-06-11 10:17:52 +02:00
|
|
|
|
|
|
|
function Console.ignoreNpcMessages(ignore)
|
2012-06-11 10:25:04 +02:00
|
|
|
ignoreNpcMessages = ignore
|
2012-06-11 10:17:52 +02:00
|
|
|
end
|