Advertisement
Guest User

console.lua

a guest
Jun 27th, 2013
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 38.84 KB | None | 0 0
  1. SpeakTypesSettings = {
  2.   none = {},
  3.   say = { speakType = MessageModes.Say, color = '#FFFF00' },
  4.   whisper = { speakType = MessageModes.Whisper, color = '#FFFF00' },
  5.   yell = { speakType = MessageModes.Yell, color = '#FFFF00' },
  6.   broadcast = { speakType = MessageModes.GamemasterPrivateFrom, color = '#F55E5E' },
  7.   private = { speakType = MessageModes.PrivateTo, color = '#5FF7F7', private = true },
  8.   privateRed = { speakType = MessageModes.GamemasterTo, color = '#F55E5E', private = true },
  9.   privatePlayerToPlayer = { speakType = MessageModes.PrivateTo, color = '#9F9DFD', private = true },
  10.   privatePlayerToNpc = { speakType = MessageModes.NpcTo, color = '#9F9DFD', private = true, npcChat = true },
  11.   privateNpcToPlayer = { speakType = MessageModes.NpcFrom, color = '#5FF7F7', private = true, npcChat = true },
  12.   channelYellow = { speakType = MessageModes.Channel, color = '#FFFF00' },
  13.   channelWhite = { speakType = MessageModes.ChannelManagement, color = '#FFFFFF' },
  14.   channelRed = { speakType = MessageModes.GamemasterChannel, color = '#F55E5E' },
  15.   channelOrange = { speakType = MessageModes.ChannelHighlight, color = '#FE6500' },
  16.   monsterSay = { speakType = MessageModes.MonsterSay, color = '#FE6500', hideInConsole = true},
  17.   monsterYell = { speakType = MessageModes.MonsterYell, color = '#FE6500', hideInConsole = true},
  18.   rvrAnswerFrom = { speakType = MessageModes.RVRAnswer, color = '#FE6500' },
  19.   rvrAnswerTo = { speakType = MessageModes.RVRAnswer, color = '#FE6500' },
  20.   rvrContinue = { speakType = MessageModes.RVRContinue, color = '#FFFF00' },
  21. }
  22.  
  23. SpeakTypes = {
  24.   [MessageModes.Say] = SpeakTypesSettings.say,
  25.   [MessageModes.Whisper] = SpeakTypesSettings.whisper,
  26.   [MessageModes.Yell] = SpeakTypesSettings.yell,
  27.   [MessageModes.GamemasterBroadcast] = SpeakTypesSettings.broadcast,
  28.   [MessageModes.PrivateFrom] = SpeakTypesSettings.private,
  29.   [MessageModes.GamemasterPrivateFrom] = SpeakTypesSettings.privateRed,
  30.   [MessageModes.NpcTo] = SpeakTypesSettings.privatePlayerToNpc,
  31.   [MessageModes.NpcFrom] = SpeakTypesSettings.privateNpcToPlayer,
  32.   [MessageModes.Channel] = SpeakTypesSettings.channelYellow,
  33.   [MessageModes.ChannelManagement] = SpeakTypesSettings.channelWhite,
  34.   [MessageModes.GamemasterChannel] = SpeakTypesSettings.channelRed,
  35.   [MessageModes.ChannelHighlight] = SpeakTypesSettings.channelOrange,
  36.   [MessageModes.MonsterSay] = SpeakTypesSettings.monsterSay,
  37.   [MessageModes.MonsterYell] = SpeakTypesSettings.monsterYell,
  38.   [MessageModes.RVRChannel] = SpeakTypesSettings.channelWhite,
  39.   [MessageModes.RVRContinue] = SpeakTypesSettings.rvrContinue,
  40.   [MessageModes.RVRAnswer] = SpeakTypesSettings.rvrAnswerFrom,
  41.  
  42.   -- ignored types
  43.   [MessageModes.Spell] = SpeakTypesSettings.none,
  44.   [MessageModes.BarkLow] = SpeakTypesSettings.none,
  45.   [MessageModes.BarkLoud] = SpeakTypesSettings.none,
  46. }
  47.  
  48. SayModes = {
  49.   [1] = { speakTypeDesc = 'whisper', icon = '/images/game/console/whisper' },
  50.   [2] = { speakTypeDesc = 'say', icon = '/images/game/console/say' },
  51.   [3] = { speakTypeDesc = 'yell', icon = '/images/game/console/yell' }
  52. }
  53.  
  54. MAX_HISTORY = 500
  55. MAX_LINES = 100
  56. HELP_CHANNEL = 9
  57.  
  58. consolePanel = nil
  59. consoleContentPanel = nil
  60. consoleTabBar = nil
  61. consoleTextEdit = nil
  62. channels = nil
  63. channelsWindow = nil
  64. ignoreWindow = nil
  65. ownPrivateName = nil
  66. messageHistory = {}
  67. currentMessageIndex = 0
  68. ignoreNpcMessages = false
  69. defaultTab = nil
  70. serverTab = nil
  71. violationsChannelId = nil
  72. violationWindow = nil
  73. violationReportTab = nil
  74. ignoredChannels = {}
  75. filters = {}
  76.  
  77. local ignoreSettings = {
  78.   privateMessages = false,
  79.   yelling = false,
  80.   players = {}
  81. }
  82.  
  83. function init()
  84.   connect(g_game, {
  85.     onTalk = onTalk,
  86.     onChannelList = onChannelList,
  87.     onOpenChannel = onOpenChannel,
  88.     onOpenPrivateChannel = onOpenPrivateChannel,
  89.     onOpenOwnPrivateChannel = onOpenOwnPrivateChannel,
  90.     onCloseChannel = onCloseChannel,
  91.     onRuleViolationChannel = onRuleViolationChannel,
  92.     onRuleViolationRemove = onRuleViolationRemove,
  93.     onRuleViolationCancel = onRuleViolationCancel,
  94.     onRuleViolationLock = onRuleViolationLock,
  95.     onGameStart = online,
  96.     onGameEnd = offline
  97.   })
  98.  
  99.   consolePanel = g_ui.loadUI('console', modules.game_interface.getBottomPanel())
  100.   consoleTextEdit = consolePanel:getChildById('consoleTextEdit')
  101.   consoleContentPanel = consolePanel:getChildById('consoleContentPanel')
  102.   consoleTabBar = consolePanel:getChildById('consoleTabBar')
  103.   consoleTabBar:setContentWidget(consoleContentPanel)
  104.   consoleTabBar:setTabSpacing(-1)
  105.   channels = {}
  106.  
  107.   consolePanel.onKeyPress = function(self, keyCode, keyboardModifiers)
  108.     if not (keyboardModifiers == KeyboardCtrlModifier and keyCode == KeyC) then return false end
  109.  
  110.     local tab = consoleTabBar:getCurrentTab()
  111.     if not tab then return false end
  112.  
  113.     local consoleBuffer = tab.tabPanel:getChildById('consoleBuffer')
  114.     if not consoleBuffer then return false end
  115.  
  116.     local consoleLabel = consoleBuffer:getFocusedChild()
  117.     if not consoleLabel or not consoleLabel:hasSelection() then return false end
  118.  
  119.     g_window.setClipboardText(consoleLabel:getSelection())
  120.     return true
  121.   end
  122.  
  123.   defaultTab = addTab(tr('Default'), true)
  124.   serverTab = addTab(tr('Server Log'), false)
  125.  
  126.   g_keyboard.bindKeyPress('Shift+Up', function() navigateMessageHistory(1) end, consolePanel)
  127.   g_keyboard.bindKeyPress('Shift+Down', function() navigateMessageHistory(-1) end, consolePanel)
  128.   g_keyboard.bindKeyPress('Tab', function() consoleTabBar:selectNextTab() end, consolePanel)
  129.   g_keyboard.bindKeyPress('Shift+Tab', function() consoleTabBar:selectPrevTab() end, consolePanel)
  130.   g_keyboard.bindKeyDown('Enter', sendCurrentMessage, consolePanel)
  131.   g_keyboard.bindKeyPress('Ctrl+A', function() consoleTextEdit:clearText() end, consolePanel)
  132.  
  133.   -- apply buttom functions after loaded
  134.   consolePanel:getChildById('nextChannelButton').onClick = function() consoleTabBar:selectNextTab() end
  135.   consolePanel:getChildById('prevChannelButton').onClick = function() consoleTabBar:selectPrevTab() end
  136.   consoleTabBar.onTabChange = onTabChange
  137.  
  138.   -- tibia like hotkeys
  139.   g_keyboard.bindKeyDown('Ctrl+O', g_game.requestChannels)
  140.   g_keyboard.bindKeyDown('Ctrl+E', removeCurrentTab)
  141.   g_keyboard.bindKeyDown('Ctrl+H', openHelp)
  142.  
  143.   load()
  144.   consoleTextEdit:setEnabled(false) --edited here
  145. end
  146.  
  147. function terminate()
  148.   save()
  149.   disconnect(g_game, {
  150.     onTalk = onTalk,
  151.     onChannelList = onChannelList,
  152.     onOpenChannel = onOpenChannel,
  153.     onOpenPrivateChannel = onOpenPrivateChannel,
  154.     onOpenOwnPrivateChannel = onOpenPrivateChannel,
  155.     onCloseChannel = onCloseChannel,
  156.     onRuleViolationChannel = onRuleViolationChannel,
  157.     onRuleViolationRemove = onRuleViolationRemove,
  158.     onRuleViolationCancel = onRuleViolationCancel,
  159.     onRuleViolationLock = onRuleViolationLock,
  160.     onGameStart = online,
  161.     onGameEnd = offline
  162.   })
  163.  
  164.   if g_game.isOnline() then clear() end
  165.  
  166.   g_keyboard.unbindKeyDown('Ctrl+O')
  167.   g_keyboard.unbindKeyDown('Ctrl+E')
  168.   g_keyboard.unbindKeyDown('Ctrl+H')
  169.  
  170.   saveIgnoreSettings()
  171.  
  172.   if channelsWindow then
  173.     channelsWindow:destroy()
  174.   end
  175.  
  176.   if ignoreWindow then
  177.     ignoreWindow:destroy()
  178.   end
  179.  
  180.   if violationWindow then
  181.     violationWindow:destroy()
  182.   end
  183.  
  184.   consolePanel:destroy()
  185.   ownPrivateName = nil
  186.  
  187.   Console = nil
  188. end
  189.  
  190. function save()
  191.   local settings = {}
  192.   settings.messageHistory = messageHistory
  193.   g_settings.setNode('game_console', settings)
  194. end
  195.  
  196. function load()
  197.   local settings = g_settings.getNode('game_console')
  198.   if settings then
  199.     messageHistory = settings.messageHistory or {}
  200.   end
  201.   loadIgnoreSettings()
  202. end
  203.  
  204. function onTabChange(tabBar, tab)
  205.   if tab == defaultTab or tab == serverTab then
  206.     consolePanel:getChildById('closeChannelButton'):disable()
  207.   else
  208.     consolePanel:getChildById('closeChannelButton'):enable()
  209.   end
  210. end
  211.  
  212. function clear()
  213.   -- save last open channels
  214.   local lastChannelsOpen = g_settings.getNode('lastChannelsOpen') or {}
  215.   local char = g_game.getCharacterName()
  216.   local savedChannels = {}
  217.   local set = false
  218.   for channelId, channelName in pairs(channels) do
  219.     if type(channelId) == 'number' then
  220.       savedChannels[channelName] = channelId
  221.       set = true
  222.     end
  223.   end
  224.   if set then
  225.     lastChannelsOpen[char] = savedChannels
  226.   else
  227.     lastChannelsOpen[char] = nil
  228.   end
  229.   g_settings.setNode('lastChannelsOpen', lastChannelsOpen)
  230.  
  231.   -- close channels
  232.   for _, channelName in pairs(channels) do
  233.     local tab = consoleTabBar:getTab(channelName)
  234.     consoleTabBar:removeTab(tab)
  235.   end
  236.   channels = {}
  237.  
  238.   defaultTab.tabPanel:getChildById('consoleBuffer'):destroyChildren()
  239.   serverTab.tabPanel:getChildById('consoleBuffer'):destroyChildren()
  240.  
  241.   local npcTab = consoleTabBar:getTab('NPCs')
  242.   if npcTab then
  243.     consoleTabBar:removeTab(npcTab)
  244.   end
  245.  
  246.   if violationReportTab then
  247.     consoleTabBar:removeTab(violationReportTab)
  248.     violationReportTab = nil
  249.   end
  250.  
  251.   consoleTextEdit:clearText()
  252.  
  253.   if violationWindow then
  254.     violationWindow:destroy()
  255.     violationWindow = nil
  256.   end
  257.  
  258.   if channelsWindow then
  259.     channelsWindow:destroy()
  260.     channelsWindow = nil
  261.   end
  262. end
  263.  
  264. function clearChannel(consoleTabBar)
  265.   consoleTabBar:getCurrentTab().tabPanel:getChildById('consoleBuffer'):destroyChildren()
  266. end
  267.  
  268. function setTextEditText(text)
  269.   consoleTextEdit:setText(text)
  270.   consoleTextEdit:setCursorPos(-1)
  271. end
  272.  
  273. function openHelp()
  274.   local helpChannel = 9
  275.   if g_game.getProtocolVersion() <= 810 then
  276.     helpChannel = 8
  277.   end
  278.   g_game.joinChannel(helpChannel)
  279. end
  280.  
  281. function openPlayerReportRuleViolationWindow()
  282.   if violationWindow or violationReportTab then return end
  283.   violationWindow = g_ui.loadUI('violationwindow', rootWidget)
  284.   violationWindow.onEscape = function()
  285.     violationWindow:destroy()
  286.     violationWindow = nil
  287.   end
  288.   violationWindow.onEnter = function()
  289.     local text = violationWindow:getChildById('text'):getText()
  290.     g_game.talkChannel(MessageModes.RVRChannel, 0, text)
  291.     violationReportTab = addTab(tr('Report Rule') .. '...', true)
  292.     addTabText(tr('Please wait patiently for a gamemaster to reply') .. '.', SpeakTypesSettings.privateRed, violationReportTab)
  293.     addTabText(applyMessagePrefixies(g_game.getCharacterName(), 0, text),  SpeakTypesSettings.say, violationReportTab, g_game.getCharacterName())
  294.     violationReportTab.locked = true
  295.     violationWindow:destroy()
  296.     violationWindow = nil
  297.   end
  298. end
  299.  
  300. function addTab(name, focus)
  301.   local tab = getTab(name)
  302.   if tab then -- is channel already open
  303.     if not focus then focus = true end
  304.   else
  305.     tab = consoleTabBar:addTab(name, nil, processChannelTabMenu)
  306.   end
  307.   if focus then
  308.     consoleTabBar:selectTab(tab)
  309.   end
  310.   return tab
  311. end
  312.  
  313. function removeTab(tab)
  314.   if type(tab) == 'string' then
  315.     tab = consoleTabBar:getTab(tab)
  316.   end
  317.  
  318.   if tab == defaultTab or tab == serverTab then
  319.     return
  320.   end
  321.  
  322.   if tab == violationReportTab then
  323.     g_game.cancelRuleViolation()
  324.     violationReportTab = nil
  325.   elseif tab.violationChatName then
  326.     g_game.closeRuleViolation(tab.violationChatName)
  327.   elseif tab.channelId then
  328.     -- notificate the server that we are leaving the channel
  329.     for k, v in pairs(channels) do
  330.       if (k == tab.channelId) then channels[k] = nil end
  331.     end
  332.     g_game.leaveChannel(tab.channelId)
  333.   elseif tab:getText() == "NPCs" then
  334.     g_game.closeNpcChannel()
  335.   end
  336.  
  337.   consoleTabBar:removeTab(tab)
  338. end
  339.  
  340. function removeCurrentTab()
  341.   removeTab(consoleTabBar:getCurrentTab())
  342. end
  343.  
  344. function getTab(name)
  345.   return consoleTabBar:getTab(name)
  346. end
  347.  
  348. function getChannelTab(channelId)
  349.   local channel = channels[channelId]
  350.   if channel then
  351.     return getTab(channel)
  352.   end
  353.   return nil
  354. end
  355.  
  356. function getRuleViolationsTab()
  357.   if violationsChannelId then
  358.     return getChannelTab(violationsChannelId)
  359.   end
  360.   return nil
  361. end
  362.  
  363. function getCurrentTab()
  364.   return consoleTabBar:getCurrentTab()
  365. end
  366.  
  367. function addChannel(name, id)
  368.   channels[id] = name
  369.   local focus = not table.find(ignoredChannels, id)
  370.   local tab = addTab(name, focus)
  371.   tab.channelId = id
  372.   return tab
  373. end
  374.  
  375. function addPrivateChannel(receiver)
  376.   channels[receiver] = receiver
  377.   return addTab(receiver, false)
  378. end
  379.  
  380. function addPrivateText(text, speaktype, name, isPrivateCommand, creatureName)
  381.   local focus = false
  382.   if speaktype.npcChat then
  383.     name = 'NPCs'
  384.     focus = true
  385.   end
  386.  
  387.   local privateTab = getTab(name)
  388.   if privateTab == nil then
  389.     if (modules.client_options.getOption('showPrivateMessagesInConsole') and not focus) or (isPrivateCommand and not privateTab) then
  390.       privateTab = defaultTab
  391.     else
  392.       privateTab = addTab(name, focus)
  393.       channels[name] = name
  394.     end
  395.     privateTab.npcChat = speaktype.npcChat
  396.   elseif focus then
  397.     consoleTabBar:selectTab(privateTab)
  398.   end
  399.   addTabText(text, speaktype, privateTab, creatureName)
  400. end
  401.  
  402. function addText(text, speaktype, tabName, creatureName)
  403.   local tab = getTab(tabName)
  404.   if tab ~= nil then
  405.     addTabText(text, speaktype, tab, creatureName)
  406.   end
  407. end
  408.  
  409. -- Contains letter width for font "verdana-11px-antialised" as console is based on it
  410. local letterWidth = {  -- New line (10) and Space (32) have width 1 because they are printed and not replaced with spacer
  411.   [10] = 1, [32] = 1, [33] = 3, [34] = 6, [35] = 8, [36] = 7, [37] = 13, [38] = 9, [39] = 3, [40] = 5, [41] = 5, [42] = 6, [43] = 8, [44] = 4, [45] = 5, [46] = 3, [47] = 8,
  412.   [48] = 7, [49] = 6, [50] = 7, [51] = 7, [52] = 7, [53] = 7, [54] = 7, [55] = 7, [56] = 7, [57] = 7, [58] = 3, [59] = 4, [60] = 8, [61] = 8, [62] = 8, [63] = 6,
  413.   [64] = 10, [65] = 9, [66] = 7, [67] = 7, [68] = 8, [69] = 7, [70] = 7, [71] = 8, [72] = 8, [73] = 5, [74] = 5, [75] = 7, [76] = 7, [77] = 9, [78] = 8, [79] = 8,
  414.   [80] = 7, [81] = 8, [82] = 8, [83] = 7, [84] = 8, [85] = 8, [86] = 8, [87] = 12, [88] = 8, [89] = 8, [90] = 7, [91] = 5, [92] = 8, [93] = 5, [94] = 9, [95] = 8,
  415.   [96] = 5, [97] = 7, [98] = 7, [99] = 6, [100] = 7, [101] = 7, [102] = 5, [103] = 7, [104] = 7, [105] = 3, [106] = 4, [107] = 7, [108] = 3, [109] = 11, [110] = 7,
  416.   [111] = 7, [112] = 7, [113] = 7, [114] = 6, [115] = 6, [116] = 5, [117] = 7, [118] = 8, [119] = 10, [120] = 8, [121] = 8, [122] = 6, [123] = 7, [124] = 4, [125] = 7, [126] = 8,
  417.   [127] = 1, [128] = 7, [129] = 6, [130] = 3, [131] = 7, [132] = 6, [133] = 11, [134] = 7, [135] = 7, [136] = 7, [137] = 13, [138] = 7, [139] = 4, [140] = 11, [141] = 6, [142] = 6,
  418.   [143] = 6, [144] = 6, [145] = 4, [146] = 3, [147] = 7, [148] = 6, [149] = 6, [150] = 7, [151] = 10, [152] = 7, [153] = 10, [154] = 6, [155] = 5, [156] = 11, [157] = 6, [158] = 6,
  419.   [159] = 8, [160] = 4, [161] = 3, [162] = 7, [163] = 7, [164] = 7, [165] = 8, [166] = 4, [167] = 7, [168] = 6, [169] = 10, [170] = 6, [171] = 8, [172] = 8, [173] = 16, [174] = 10,
  420.   [175] = 8, [176] = 5, [177] = 8, [178] = 5, [179] = 5, [180] = 6, [181] = 7, [182] = 7, [183] = 3, [184] = 5, [185] = 6, [186] = 6, [187] = 8, [188] = 12, [189] = 12, [190] = 12,
  421.   [191] = 6, [192] = 9, [193] = 9, [194] = 9, [195] = 9, [196] = 9, [197] = 9, [198] = 11, [199] = 7, [200] = 7, [201] = 7, [202] = 7, [203] = 7, [204] = 5, [205] = 5, [206] = 6,
  422.   [207] = 5, [208] = 8, [209] = 8, [210] = 8, [211] = 8, [212] = 8, [213] = 8, [214] = 8, [215] = 8, [216] = 8, [217] = 8, [218] = 8, [219] = 8, [220] = 8, [221] = 8, [222] = 7,
  423.   [223] = 7, [224] = 7, [225] = 7, [226] = 7, [227] = 7, [228] = 7, [229] = 7, [230] = 11, [231] = 6, [232] = 7, [233] = 7, [234] = 7, [235] = 7, [236] = 3, [237] = 4, [238] = 4,
  424.   [239] = 4, [240] = 7, [241] = 7, [242] = 7, [243] = 7, [244] = 7, [245] = 7, [246] = 7, [247] = 9, [248] = 7, [249] = 7, [250] = 7, [251] = 7, [252] = 7, [253] = 8, [254] = 7, [255] = 8
  425. }
  426.  
  427. -- Return information about start, end in the string and the highlighted words
  428. function getHighlightedText(text)
  429.   local tmpData = {}
  430.  
  431.   repeat
  432.     local tmp = {string.find(text, "{([^}]+)}", tmpData[#tmpData-1])}
  433.     for _, v in pairs(tmp) do
  434.       table.insert(tmpData, v)
  435.     end
  436.   until not(string.find(text, "{([^}]+)}", tmpData[#tmpData-1]))
  437.  
  438.   return tmpData
  439. end
  440.  
  441. function addTabText(text, speaktype, tab, creatureName)
  442.   if not tab or tab.locked or not text or #text == 0 then return end
  443.  
  444.   if modules.client_options.getOption('showTimestampsInConsole') then
  445.     text = os.date('%H:%M') .. ' ' .. text
  446.   end
  447.  
  448.   local panel = consoleTabBar:getTabPanel(tab)
  449.   local consoleBuffer = panel:getChildById('consoleBuffer')
  450.   local label = g_ui.createWidget('ConsoleLabel', consoleBuffer)
  451.   label:setId('consoleLabel' .. consoleBuffer:getChildCount())
  452.   label:setText(text)
  453.   label:setColor(speaktype.color)
  454.   consoleTabBar:blinkTab(tab)
  455.  
  456.   -- Overlay for consoleBuffer which shows highlighted words only
  457.  
  458.   if speaktype.npcChat and (g_game.getCharacterName() ~= creatureName or g_game.getCharacterName() == 'Account Manager') then
  459.     local highlightData = getHighlightedText(text)
  460.     if #highlightData > 0 then
  461.       local labelHighlight = g_ui.createWidget('ConsolePhantomLabel', label)
  462.       labelHighlight:fill('parent')
  463.  
  464.       labelHighlight:setId('consoleLabelHighlight' .. consoleBuffer:getChildCount())
  465.       labelHighlight:setColor("#1f9ffe")
  466.  
  467.       -- Remove the curly braces
  468.       for i = 1, #highlightData / 3 do
  469.         local dataBlock = { _start = highlightData[(i-1)*3+1], _end = highlightData[(i-1)*3+2], words = highlightData[(i-1)*3+3] }
  470.         text = text:gsub("%{(.-)%}", dataBlock.words, 1)
  471.  
  472.         -- Recalculate positions as braces are removed
  473.         highlightData[(i-1)*3+1] = dataBlock._start - ((i-1) * 2)
  474.         highlightData[(i-1)*3+2] = dataBlock._end - (1 + (i-1) * 2)
  475.       end
  476.       label:setText(text)
  477.  
  478.       -- Calculate the positions of the highlighted text and fill with string.char(127) [Width: 1]
  479.       local drawText = label:getDrawText()
  480.       local tmpText = ""
  481.       for i = 1, #highlightData / 3 do
  482.         local dataBlock = { _start = highlightData[(i-1)*3+1], _end = highlightData[(i-1)*3+2], words = highlightData[(i-1)*3+3] }
  483.         local lastBlockEnd = (highlightData[(i-2)*3+2] or 1)
  484.  
  485.         for letter = lastBlockEnd, dataBlock._start-1 do
  486.           local tmpChar = string.byte(drawText:sub(letter, letter))
  487.           local fillChar = (tmpChar == 10 or tmpChar == 32) and string.char(tmpChar) or string.char(127)
  488.  
  489.           tmpText = tmpText .. string.rep(fillChar, letterWidth[tmpChar])
  490.         end
  491.         tmpText = tmpText .. dataBlock.words
  492.       end
  493.  
  494.       -- Fill the highlight label to the same size as default label
  495.       local finalBlockEnd = (highlightData[(#highlightData/3-1)*3+2] or 1)
  496.       for letter = finalBlockEnd, drawText:len() do
  497.           local tmpChar = string.byte(drawText:sub(letter, letter))
  498.           local fillChar = (tmpChar == 10 or tmpChar == 32) and string.char(tmpChar) or string.char(127)
  499.  
  500.           tmpText = tmpText .. string.rep(fillChar, letterWidth[tmpChar])
  501.       end
  502.  
  503.       labelHighlight:setText(tmpText)
  504.     end
  505.   end
  506.  
  507.   label.name = creatureName
  508.   label.onMouseRelease = function (self, mousePos, mouseButton)
  509.     processMessageMenu(mousePos, mouseButton, creatureName, text, self, tab)
  510.   end
  511.  
  512.   if consoleBuffer:getChildCount() > MAX_LINES then
  513.     consoleBuffer:getFirstChild():destroy()
  514.   end
  515. end
  516.  
  517. function removeTabLabelByName(tab, name)
  518.   local panel = consoleTabBar:getTabPanel(tab)
  519.   local consoleBuffer = panel:getChildById('consoleBuffer')
  520.   for _,label in pairs(consoleBuffer:getChildren()) do
  521.     if label.name == name then
  522.       label:destroy()
  523.     end
  524.   end
  525. end
  526.  
  527. function processChannelTabMenu(tab, mousePos, mouseButton)
  528.   local menu = g_ui.createWidget('PopupMenu')
  529.  
  530.   channelName = tab:getText()
  531.   if tab ~= defaultTab and tab ~= serverTab then
  532.     menu:addOption(tr('Close'), function() removeTab(channelName) end)
  533.     --menu:addOption(tr('Show Server Messages'), function() --[[TODO]] end)
  534.     menu:addSeparator()
  535.   end
  536.  
  537.   if consoleTabBar:getCurrentTab() == tab then
  538.     menu:addOption(tr('Clear Messages'), function() clearChannel(consoleTabBar) end)
  539.   end
  540.   --menu:addOption(tr('Save Messages'), function() --[[TODO]] end)
  541.  
  542.   menu:display(mousePos)
  543. end
  544.  
  545. function processMessageMenu(mousePos, mouseButton, creatureName, text, label, tab)
  546.   if mouseButton == MouseRightButton then
  547.     local menu = g_ui.createWidget('PopupMenu')
  548.     if creatureName and #creatureName > 0 then
  549.       if creatureName ~= g_game.getCharacterName() then
  550.         menu:addOption(tr('Message to ' .. creatureName), function () g_game.openPrivateChannel(creatureName) end)
  551.         if not g_game.getLocalPlayer():hasVip(creatureName) then
  552.           menu:addOption(tr('Add to VIP list'), function () g_game.addVip(creatureName) end)
  553.         end
  554.         if modules.game_console.getOwnPrivateTab() then
  555.           menu:addSeparator()
  556.           menu:addOption(tr('Invite to private chat'), function() g_game.inviteToOwnChannel(creatureName) end)
  557.           menu:addOption(tr('Exclude from private chat'), function() g_game.excludeFromOwnChannel(creatureName) end)
  558.         end
  559.         if isIgnored(creatureName) then
  560.           menu:addOption(tr('Unignore') .. ' ' .. creatureName, function() removeIgnoredPlayer(creatureName) end)
  561.         else
  562.           menu:addOption(tr('Ignore') .. ' ' .. creatureName, function() addIgnoredPlayer(creatureName) end)
  563.         end
  564.         menu:addSeparator()
  565.       end
  566.       if modules.game_ruleviolation.hasWindowAccess() then
  567.         menu:addOption(tr('Rule Violation'), function() modules.game_ruleviolation.show(creatureName, text:match('.+%:%s(.+)')) end)
  568.         menu:addSeparator()
  569.       end
  570.  
  571.       menu:addOption(tr('Copy name'), function () g_window.setClipboardText(creatureName) end)
  572.     end
  573.     if label:hasSelection() then
  574.       menu:addOption(tr('Copy'), function() g_window.setClipboardText(label:getSelection()) end, '(Ctrl+C)')
  575.     end
  576.     menu:addOption(tr('Copy message'), function() g_window.setClipboardText(text) end)
  577.     menu:addOption(tr('Select all'), function() label:selectAll() end)
  578.     if tab.violations then
  579.       menu:addSeparator()
  580.       menu:addOption(tr('Process') .. ' ' .. creatureName, function() processViolation(creatureName, text) end)
  581.       menu:addOption(tr('Remove') .. ' ' .. creatureName, function() g_game.closeRuleViolation(creatureName) end)
  582.     end
  583.     menu:display(mousePos)
  584.   end
  585. end
  586.  
  587. function sendCurrentMessage()
  588.   if not consoleTextEdit:isEnabled() then  --edited here
  589.      consoleTextEdit:setEnabled(true)
  590.      return
  591.   end
  592.   consoleTextEdit:setEnabled(false)  --edited here
  593.  
  594.   local message = consoleTextEdit:getText()
  595.   if #message == 0 then return end
  596.   consoleTextEdit:clearText()
  597.  
  598.   -- send message
  599.   sendMessage(message)
  600. end
  601.  
  602. function addFilter(filter)
  603.   table.insert(filters, filter)
  604. end
  605.  
  606. function removeFilter(filter)
  607.   table.removevalue(filters, filter)
  608. end
  609.  
  610. function sendMessage(message, tab)
  611.   local tab = tab or getCurrentTab()
  612.   if not tab then return end
  613.  
  614.   for k,func in pairs(filters) do
  615.     if func(message) then
  616.       return true
  617.     end
  618.   end
  619.  
  620.   -- when talking on server log, the message goes to default channel
  621.   local name = tab:getText()
  622.   if tab == serverTab or tab == getRuleViolationsTab() then
  623.     tab = defaultTab
  624.     name = defaultTab:getText()
  625.   end
  626.  
  627.   -- handling chat commands
  628.   local channel = tab.channelId
  629.   local originalMessage = message
  630.   local chatCommandSayMode
  631.   local chatCommandPrivate
  632.   local chatCommandPrivateReady
  633.   local chatCommandMessage
  634.  
  635.   -- player used yell command
  636.   chatCommandMessage = message:match("^%#y (.*)")
  637.   if chatCommandMessage ~= nil then
  638.     chatCommandSayMode = 'yell'
  639.     channel = 0
  640.     message = chatCommandMessage
  641.   end
  642.  
  643.    -- player used whisper
  644.   local chatCommandMessage = message:match("^%#w (.*)")
  645.   if chatCommandMessage ~= nil then
  646.     chatCommandSayMode = 'whisper'
  647.     message = chatCommandMessage
  648.     channel = 0
  649.   end
  650.  
  651.   -- player say
  652.   local chatCommandMessage = message:match("^%#s (.*)")
  653.   if chatCommandMessage ~= nil then
  654.     chatCommandSayMode = 'say'
  655.     message = chatCommandMessage
  656.     channel = 0
  657.   end
  658.  
  659.   local findIni, findEnd, chatCommandInitial, chatCommandPrivate, chatCommandEnd, chatCommandMessage = message:find("([%*%@])(.+)([%*%@])(.*)")
  660.   if findIni ~= nil and findIni == 1 then -- player used private chat command
  661.     if chatCommandInitial == chatCommandEnd then
  662.       chatCommandPrivateRepeat = false
  663.       if chatCommandInitial == "*" then
  664.         setTextEditText('*'.. chatCommandPrivate .. '* ')
  665.       end
  666.       message = chatCommandMessage:trim()
  667.       chatCommandPrivateReady = true
  668.     end
  669.   end
  670.  
  671.   message = message:gsub("^(%s*)(.*)","%2") -- remove space characters from message init
  672.   if #message == 0 then return end
  673.  
  674.   -- add new command to history
  675.   currentMessageIndex = 0
  676.   if #messageHistory == 0 or messageHistory[#messageHistory] ~= originalMessage then
  677.     table.insert(messageHistory, originalMessage)
  678.     if #messageHistory > MAX_HISTORY then
  679.       table.remove(messageHistory, 1)
  680.     end
  681.   end
  682.  
  683.   local speaktypedesc
  684.   if (channel or tab == defaultTab) and not chatCommandPrivateReady then
  685.     if tab == defaultTab then
  686.       speaktypedesc = chatCommandSayMode or SayModes[consolePanel:getChildById('sayModeButton').sayMode].speakTypeDesc
  687.       if speaktypedesc ~= 'say' then sayModeChange(2) end -- head back to say mode
  688.     else
  689.       speaktypedesc = chatCommandSayMode or 'channelYellow'
  690.     end
  691.  
  692.     g_game.talkChannel(SpeakTypesSettings[speaktypedesc].speakType, channel, message)
  693.     return
  694.   else
  695.     local isPrivateCommand = false
  696.     local priv = true
  697.     local tabname = name
  698.     if chatCommandPrivateReady then
  699.       speaktypedesc = 'privatePlayerToPlayer'
  700.       name = chatCommandPrivate
  701.       isPrivateCommand = true
  702.     elseif tab.npcChat then
  703.       speaktypedesc = 'privatePlayerToNpc'
  704.     elseif tab == violationReportTab then
  705.       if violationReportTab.locked then
  706.         modules.game_textmessage.displayFailureMessage('Wait for a gamemaster reply.')
  707.         return
  708.       end
  709.       speaktypedesc = 'rvrContinue'
  710.       tabname = tr('Report Rule') .. '...'
  711.     elseif tab.violationChatName then
  712.       speaktypedesc = 'rvrAnswerTo'
  713.       name = tab.violationChatName
  714.       tabname = tab.violationChatName .. '\'...'
  715.     else
  716.       speaktypedesc = 'privatePlayerToPlayer'
  717.     end
  718.  
  719.  
  720.     local speaktype = SpeakTypesSettings[speaktypedesc]
  721.     local player = g_game.getLocalPlayer()
  722.     g_game.talkPrivate(speaktype.speakType, name, message)
  723.  
  724.     message = applyMessagePrefixies(g_game.getCharacterName(), player:getLevel(), message)
  725.     addPrivateText(message, speaktype, tabname, isPrivateCommand, g_game.getCharacterName())
  726.   end
  727. end
  728.  
  729. function sayModeChange(sayMode)
  730.   local buttom = consolePanel:getChildById('sayModeButton')
  731.   if sayMode == nil then
  732.     sayMode = buttom.sayMode + 1
  733.   end
  734.  
  735.   if sayMode > #SayModes then sayMode = 1 end
  736.  
  737.   buttom:setIcon(SayModes[sayMode].icon)
  738.   buttom.sayMode = sayMode
  739. end
  740.  
  741. function getOwnPrivateTab()
  742.   if not ownPrivateName then return end
  743.   return getTab(ownPrivateName)
  744. end
  745.  
  746. function setIgnoreNpcMessages(ignore)
  747.   ignoreNpcMessages = ignore
  748. end
  749.  
  750. function navigateMessageHistory(step)
  751.   local numCommands = #messageHistory
  752.   if numCommands > 0 then
  753.     currentMessageIndex = math.min(math.max(currentMessageIndex + step, 0), numCommands)
  754.     if currentMessageIndex > 0 then
  755.       local command = messageHistory[numCommands - currentMessageIndex + 1]
  756.       setTextEditText(command)
  757.     else
  758.       consoleTextEdit:clearText()
  759.     end
  760.   end
  761. end
  762.  
  763. function applyMessagePrefixies(name, level, message)
  764.   if name then
  765.     if modules.client_options.getOption('showLevelsInConsole') and level > 0 then
  766.       message = name .. ' [' .. level .. ']: ' .. message
  767.     else
  768.       message = name .. ': ' .. message
  769.     end
  770.   end
  771.   return message
  772. end
  773.  
  774. function onTalk(name, level, mode, message, channelId, creaturePos)
  775.   if mode == MessageModes.GamemasterBroadcast then
  776.     modules.game_textmessage.displayBroadcastMessage(name .. ': ' .. message)
  777.     return
  778.   end
  779.  
  780.   if ignoreNpcMessages and mode == MessageModes.NpcFrom then return end
  781.  
  782.   speaktype = SpeakTypes[mode]
  783.  
  784.   if not speaktype then
  785.     perror('unhandled onTalk message mode ' .. mode .. ': ' .. message)
  786.     return
  787.   end
  788.  
  789.   if name ~= g_game.getCharacterName() then
  790.     if mode == MessageModes.Yell and isIgnoringYelling() then
  791.       return
  792.     elseif speaktype.private and isIgnoringPrivate() and mode ~= MessageModes.NpcFrom then
  793.       return
  794.     elseif isIgnored(name) then
  795.       return
  796.     end
  797.   end
  798.  
  799.   if mode == MessageModes.RVRChannel then
  800.     channelId = violationsChannelId
  801.   end
  802.  
  803.   if (mode == MessageModes.Say or mode == MessageModes.Whisper or mode == MessageModes.Yell or
  804.       mode == MessageModes.Spell or mode == MessageModes.MonsterSay or mode == MessageModes.MonsterYell or
  805.       mode == MessageModes.NpcFrom or mode == MessageModes.BarkLow or mode == MessageModes.BarkLoud) and
  806.      creaturePos then
  807.       -- Remove curly braces from screen message
  808.       local staticMessage = message
  809.       if mode == MessageModes.NpcFrom then
  810.         local highlightData = getHighlightedText(staticMessage)
  811.         if #highlightData > 0 then
  812.           for i = 1, #highlightData / 3 do
  813.             local dataBlock = { _start = highlightData[(i-1)*3+1], _end = highlightData[(i-1)*3+2], words = highlightData[(i-1)*3+3] }
  814.             staticMessage = staticMessage:gsub("{"..dataBlock.words.."}", dataBlock.words)
  815.           end
  816.         end
  817.       end
  818.  
  819.     local staticText = StaticText.create()
  820.     staticText:addMessage(name, mode, staticMessage)
  821.     g_map.addThing(staticText, creaturePos, -1)
  822.   end
  823.  
  824.   local defaultMessage = mode <= 3 and true or false
  825.  
  826.   if speaktype == SpeakTypesSettings.none then return end
  827.  
  828.   if speaktype.hideInConsole then return end
  829.  
  830.   local composedMessage = applyMessagePrefixies(name, level, message)
  831.  
  832.   if mode == MessageModes.RVRAnswer then
  833.     violationReportTab.locked = false
  834.     addTabText(composedMessage, speaktype, violationReportTab, name)
  835.   elseif mode == MessageModes.RVRContinue then
  836.     addText(composedMessage, speaktype, name .. '\'...', name)
  837.   elseif speaktype.private then
  838.     addPrivateText(composedMessage, speaktype, name, false, name)
  839.     if modules.client_options.getOption('showPrivateMessagesOnScreen') and speaktype ~= SpeakTypesSettings.privateNpcToPlayer then
  840.       modules.game_textmessage.displayPrivateMessage(name .. ':\n' .. message)
  841.     end
  842.   else
  843.     local channel = tr('Default')
  844.     if not defaultMessage then
  845.       channel = channels[channelId]
  846.     end
  847.  
  848.     if channel then
  849.       addText(composedMessage, speaktype, channel, name)
  850.     else
  851.       -- server sent a message on a channel that is not open
  852.       pwarning('message in channel id ' .. channelId .. ' which is unknown, this is a server bug, relogin if you want to see messages in this channel')
  853.     end
  854.   end
  855. end
  856.  
  857. function onOpenChannel(channelId, channelName)
  858.   addChannel(channelName, channelId)
  859. end
  860.  
  861. function onOpenPrivateChannel(receiver)
  862.   addPrivateChannel(receiver)
  863. end
  864.  
  865. function onOpenOwnPrivateChannel(channelId, channelName)
  866.   local privateTab = getTab(channelName)
  867.   if privateTab == nil then
  868.     addChannel(channelName, channelId)
  869.   end
  870.   ownPrivateName = channelName
  871. end
  872.  
  873. function onCloseChannel(channelId)
  874.   local channel = channels[channelId]
  875.   if channel then
  876.     local tab = getTab(channel)
  877.     if tab then
  878.       consoleTabBar:removeTab(tab)
  879.     end
  880.     for k, v in pairs(channels) do
  881.       if (k == tab.channelId) then channels[k] = nil end
  882.     end
  883.   end
  884. end
  885.  
  886. function processViolation(name, text)
  887.   local tabname = name .. '\'...'
  888.   local tab = addTab(tabname, true)
  889.   channels[tabname] = tabname
  890.   tab.violationChatName = name
  891.   g_game.openRuleViolation(name)
  892.   addTabText(text, SpeakTypesSettings.say, tab, name)
  893. end
  894.  
  895. function onRuleViolationChannel(channelId)
  896.   violationsChannelId = channelId
  897.   local tab = addChannel(tr('Rule Violations'), channelId)
  898.   tab.violations = true
  899. end
  900.  
  901. function onRuleViolationRemove(name)
  902.   local tab = getRuleViolationsTab()
  903.   if not tab then return end
  904.   removeTabLabelByName(tab, name)
  905. end
  906.  
  907. function onRuleViolationCancel(name)
  908.   local tab = getTab(name .. '\'...')
  909.   if not tab then return end
  910.   addTabText(tr('%s has finished the request', name) .. '.', SpeakTypesSettings.privateRed, tab)
  911.   tab.locked = true
  912. end
  913.  
  914. function onRuleViolationLock()
  915.   if not violationReportTab then return end
  916.   violationReportTab.locked = false
  917.   addTabText(tr('Your request has been closed') .. '.', SpeakTypesSettings.privateRed, violationReportTab)
  918.   violationReportTab.locked = true
  919. end
  920.  
  921. function doChannelListSubmit()
  922.   local channelListPanel = channelsWindow:getChildById('channelList')
  923.   local openPrivateChannelWith = channelsWindow:getChildById('openPrivateChannelWith'):getText()
  924.   if openPrivateChannelWith ~= '' then
  925.     if openPrivateChannelWith:lower() ~= g_game.getCharacterName():lower() then
  926.       g_game.openPrivateChannel(openPrivateChannelWith)
  927.     else
  928.       modules.game_textmessage.displayFailureMessage('You cannot create a private chat channel with yourself.')
  929.     end
  930.   else
  931.     local selectedChannelLabel = channelListPanel:getFocusedChild()
  932.     if not selectedChannelLabel then return end
  933.     if selectedChannelLabel.channelId == 0xFFFF then
  934.       g_game.openOwnChannel()
  935.     else
  936.       g_game.joinChannel(selectedChannelLabel.channelId)
  937.     end
  938.   end
  939.  
  940.   channelsWindow:destroy()
  941. end
  942.  
  943. function onChannelList(channelList)
  944.   if channelsWindow then channelsWindow:destroy() end
  945.   channelsWindow = g_ui.displayUI('channelswindow')
  946.   local channelListPanel = channelsWindow:getChildById('channelList')
  947.   channelsWindow.onEnter = doChannelListSubmit
  948.   channelsWindow.onDestroy = function() channelsWindow = nil end
  949.   g_keyboard.bindKeyPress('Down', function() channelListPanel:focusNextChild(KeyboardFocusReason) end, channelsWindow)
  950.   g_keyboard.bindKeyPress('Up', function() channelListPanel:focusPreviousChild(KeyboardFocusReason) end, channelsWindow)
  951.  
  952.   for k,v in pairs(channelList) do
  953.     local channelId = v[1]
  954.     local channelName = v[2]
  955.  
  956.     if #channelName > 0 then
  957.       local label = g_ui.createWidget('ChannelListLabel', channelListPanel)
  958.       label.channelId = channelId
  959.       label:setText(channelName)
  960.  
  961.       label:setPhantom(false)
  962.       label.onDoubleClick = doChannelListSubmit
  963.     end
  964.   end
  965. end
  966.  
  967. function loadIgnoreSettings()
  968.   local ignoreNode = g_settings.getNode('IgnorePlayers')
  969.   if ignoreNode then
  970.     for i = 1, #ignoreNode do
  971.       table.insert(ignoreSettings.players, ignoreNode[i])
  972.     end
  973.   end
  974.   ignoreSettings.privateMessages = g_settings.getBoolean('IgnorePrivateMessages')
  975.   ignoreSettings.yelling = g_settings.getBoolean('IgnoreYelling')
  976. end
  977.  
  978. function saveIgnoreSettings()
  979.   local tmpSettings = {}
  980.   for i = 1, #ignoreSettings.players do    
  981.     table.insert(tmpSettings, ignoreSettings.players[i])
  982.   end
  983.   g_settings.set('IgnorePrivateMessages', ignoreSettings.privateMessages)
  984.   g_settings.set('IgnoreYelling', ignoreSettings.yelling)
  985.   g_settings.setNode('IgnorePlayers', tmpSettings)
  986. end
  987.  
  988. function isIgnored(name)
  989.   return table.find(ignoreSettings.players, name, true)
  990. end
  991.  
  992. function addIgnoredPlayer(name)
  993.   if not isIgnored(name) then
  994.     table.insert(ignoreSettings.players, name)
  995.   end
  996. end
  997.  
  998. function removeIgnoredPlayer(name)
  999.   table.removevalue(ignoreSettings.players, name)
  1000. end
  1001.  
  1002. function isIgnoringPrivate()
  1003.   return ignoreSettings.privateMessages
  1004. end
  1005.  
  1006. function isIgnoringYelling()
  1007.   return ignoreSettings.yelling
  1008. end
  1009.  
  1010. function onClickIgnoreButton()
  1011.   if ignoreWindow then return end
  1012.   ignoreWindow = g_ui.displayUI('ignorewindow')
  1013.   local ignoreListPanel = ignoreWindow:getChildById('ignoreList')
  1014.   ignoreWindow.onDestroy = function() ignoreWindow = nil end
  1015.  
  1016.   local removeButton = ignoreWindow:getChildById('buttonRemove')
  1017.   removeButton:disable()
  1018.   ignoreListPanel.onChildFocusChange = function() removeButton:enable() end
  1019.   removeButton.onClick = function()
  1020.     local selection = ignoreListPanel:getFocusedChild()
  1021.     if selection then
  1022.         ignoreListPanel:removeChild(selection)
  1023.         selection:destroy()
  1024.     end
  1025.     if ignoreListPanel:getChildCount() == 0 then
  1026.         removeButton:disable()
  1027.     end
  1028.   end
  1029.  
  1030.   local newlyIgnoredPlayers = {}
  1031.   local addName = ignoreWindow:getChildById('ignoreNameEdit')
  1032.   local addButton = ignoreWindow:getChildById('buttonAdd')
  1033.   local addFunction = function()
  1034.             if addName:getText() == '' then return end
  1035.             if table.find(ignoreSettings.players, addName:getText()) then return end
  1036.             if table.find(newlyIgnoredPlayers, addName:getText()) then return end
  1037.             local label = g_ui.createWidget('IgnoreListLabel', ignoreListPanel)
  1038.             label:setText(addName:getText())
  1039.             table.insert(newlyIgnoredPlayers, addName:getText())
  1040.             label:setPhantom(false)
  1041.             addName:setText('')
  1042.         end
  1043.   addButton.onClick = addFunction
  1044.   ignoreWindow.onEnter = addFunction
  1045.    
  1046.   local ignorePrivateMessageBox = ignoreWindow:getChildById('checkboxIgnorePrivateMessages')
  1047.   ignorePrivateMessageBox:setChecked(ignoreSettings.privateMessages)
  1048.   local ignoreYellingBox = ignoreWindow:getChildById('checkboxIgnoreYelling')
  1049.   ignoreYellingBox:setChecked(ignoreSettings.yelling)
  1050.    
  1051.   local saveButton = ignoreWindow:getChildById('buttonSave')
  1052.   saveButton.onClick = function()
  1053.                 ignoreSettings.players = {}
  1054.                 for i = 1, ignoreListPanel:getChildCount() do
  1055.                     addIgnoredPlayer(ignoreListPanel:getChildByIndex(i):getText())
  1056.                     --table.insert(ignoreSettings.players, ignoreListPanel:getChildByIndex(i):getText())
  1057.                 end
  1058.                
  1059.                 ignoreSettings.yelling = ignoreYellingBox:isChecked()
  1060.                 ignoreSettings.privateMessages = ignorePrivateMessageBox:isChecked()
  1061.                 ignoreWindow:destroy()
  1062.             end
  1063.    
  1064.   for _, name in pairs(ignoreSettings.players) do
  1065.       local label = g_ui.createWidget('IgnoreListLabel', ignoreListPanel)
  1066.       label:setText(name)
  1067.       label:setPhantom(false)
  1068.   end
  1069. end
  1070.  
  1071. function online()
  1072.   if g_game.getProtocolVersion() < 862 then
  1073.     g_keyboard.bindKeyDown('Ctrl+R', openPlayerReportRuleViolationWindow)
  1074.   end
  1075.   -- open last channels
  1076.   local lastChannelsOpen = g_settings.getNode('lastChannelsOpen')
  1077.   if lastChannelsOpen then
  1078.     local savedChannels = lastChannelsOpen[g_game.getCharacterName()]
  1079.     if savedChannels then
  1080.       for channelName, channelId in pairs(savedChannels) do
  1081.         channelId = tonumber(channelId)
  1082.         if channelId ~= -1 and channelId < 100 then
  1083.           if not table.find(channels, channelId) then
  1084.             g_game.joinChannel(channelId)
  1085.             table.insert(ignoredChannels, channelId)
  1086.           end
  1087.         end
  1088.       end
  1089.     end
  1090.   end
  1091.   scheduleEvent(function() ignoredChannels = {} end, 3000)
  1092. end
  1093.  
  1094. function offline()
  1095.   if g_game.getProtocolVersion() < 862 then
  1096.     g_keyboard.unbindKeyDown('Ctrl+R')
  1097.   end
  1098.   clear()
  1099. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement