Ignore Window in Console / Fixes

Ignore List:
- Ignore Private Messages
- Ignore Yelling
- Ignore added Players fully

Fixes:
- Fixed cutoff text in spelllist module
- You cannot open a private chat channel with yourself now
This commit is contained in:
Samuel 2013-01-09 23:03:04 +01:00
parent cce2976156
commit 1784bd9f26
6 changed files with 249 additions and 15 deletions

View File

@ -55,6 +55,7 @@ consoleTabBar = nil
consoleTextEdit = nil consoleTextEdit = nil
channels = nil channels = nil
channelsWindow = nil channelsWindow = nil
ignoreWindow = nil
ownPrivateName = nil ownPrivateName = nil
messageHistory = {} messageHistory = {}
currentMessageIndex = 0 currentMessageIndex = 0
@ -62,6 +63,12 @@ ignoreNpcMessages = false
defaultTab = nil defaultTab = nil
serverTab = nil serverTab = nil
local ignoreSettings = {
privateMessages = false,
yelling = false,
players = {}
}
function init() function init()
connect(g_game, { onTalk = onTalk, connect(g_game, { onTalk = onTalk,
onChannelList = onChannelList, onChannelList = onChannelList,
@ -99,6 +106,9 @@ function init()
g_keyboard.bindKeyDown('Ctrl+O', g_game.requestChannels) g_keyboard.bindKeyDown('Ctrl+O', g_game.requestChannels)
g_keyboard.bindKeyDown('Ctrl+E', removeCurrentTab) g_keyboard.bindKeyDown('Ctrl+E', removeCurrentTab)
g_keyboard.bindKeyDown('Ctrl+H', openHelp) g_keyboard.bindKeyDown('Ctrl+H', openHelp)
-- Ignore List
loadIgnoreSettings()
end end
function terminate() function terminate()
@ -117,11 +127,18 @@ function terminate()
g_keyboard.unbindKeyDown('Ctrl+E') g_keyboard.unbindKeyDown('Ctrl+E')
g_keyboard.unbindKeyDown('Ctrl+H') g_keyboard.unbindKeyDown('Ctrl+H')
saveIgnoreSettings()
if channelsWindow then if channelsWindow then
channelsWindow:destroy() channelsWindow:destroy()
channelsWindow = nil channelsWindow = nil
end end
if ignoreWindow then
ignoreWindow:destroy()
ignoreWindow = nil
end
consolePanel:destroy() consolePanel:destroy()
consolePanel = nil consolePanel = nil
consoleTextEdit = nil consoleTextEdit = nil
@ -589,6 +606,14 @@ function onTalk(name, level, mode, message, channelId, creaturePos)
if ignoreNpcMessages and mode == MessageModes.NpcFrom then return end if ignoreNpcMessages and mode == MessageModes.NpcFrom then return end
speaktype = SpeakTypes[mode]
if ((mode == MessageModes.Yell and isIgnoringYelling()) or
(speaktype.private and isIgnoringPrivate()) or
(isIgnored(name) or isIgnored(name:lower()))) and
name ~= g_game.getLocalPlayer():getName() then
return
end
if (mode == MessageModes.Say or mode == MessageModes.Whisper or mode == MessageModes.Yell or if (mode == MessageModes.Say or mode == MessageModes.Whisper or mode == MessageModes.Yell or
mode == MessageModes.Spell or mode == MessageModes.MonsterSay or mode == MessageModes.MonsterYell or mode == MessageModes.Spell or mode == MessageModes.MonsterSay or mode == MessageModes.MonsterYell or
mode == MessageModes.NpcFrom or mode == MessageModes.BarkLow or mode == MessageModes.BarkLoud) and mode == MessageModes.NpcFrom or mode == MessageModes.BarkLow or mode == MessageModes.BarkLoud) and
@ -611,7 +636,6 @@ function onTalk(name, level, mode, message, channelId, creaturePos)
end end
local defaultMessage = mode <= 3 and true or false local defaultMessage = mode <= 3 and true or false
speaktype = SpeakTypes[mode]
if not speaktype then if not speaktype then
perror('unhandled onTalk message mode ' .. mode .. ': ' .. message) perror('unhandled onTalk message mode ' .. mode .. ': ' .. message)
@ -677,7 +701,11 @@ function doChannelListSubmit()
local channelListPanel = channelsWindow:getChildById('channelList') local channelListPanel = channelsWindow:getChildById('channelList')
local openPrivateChannelWith = channelsWindow:getChildById('openPrivateChannelWith'):getText() local openPrivateChannelWith = channelsWindow:getChildById('openPrivateChannelWith'):getText()
if openPrivateChannelWith ~= '' then if openPrivateChannelWith ~= '' then
if openPrivateChannelWith:lower() ~= g_game.getLocalPlayer():getName():lower() then
g_game.openPrivateChannel(openPrivateChannelWith) g_game.openPrivateChannel(openPrivateChannelWith)
else
modules.game_textmessage.displayFailureMessage('You cannot create a private chat channel with yourself.')
end
else else
local selectedChannelLabel = channelListPanel:getFocusedChild() local selectedChannelLabel = channelListPanel:getFocusedChild()
if not selectedChannelLabel then return end if not selectedChannelLabel then return end
@ -715,6 +743,100 @@ function onChannelList(channelList)
end end
end end
function loadIgnoreSettings()
local ignoreNode = g_settings.getNode('IgnorePlayers')
if ignoreNode then
for i = 1, #ignoreNode do
table.insert(ignoreSettings.players, ignoreNode[i])
end
end
ignoreSettings.privateMessages = g_settings.getBoolean('IgnorePrivateMessages')
ignoreSettings.yelling = g_settings.getBoolean('IgnoreYelling')
end
function saveIgnoreSettings()
local tmpSettings = {}
for i = 1, #ignoreSettings.players do
table.insert(tmpSettings, ignoreSettings.players[i])
end
g_settings.set('IgnorePrivateMessages', ignoreSettings.privateMessages)
g_settings.set('IgnoreYelling', ignoreSettings.yelling)
g_settings.setNode('IgnorePlayers', tmpSettings)
end
function isIgnored(name)
return table.find(ignoreSettings.players, name)
end
function isIgnoringPrivate()
return ignoreSettings.privateMessages
end
function isIgnoringYelling()
return ignoreSettings.yelling
end
function onClickIgnoreButton()
if ignoreWindow then return end
ignoreWindow = g_ui.displayUI('ignorewindow.otui')
local ignoreListPanel = ignoreWindow:getChildById('ignoreList')
ignoreWindow.onDestroy = function() ignoreWindow = nil end
g_keyboard.bindKeyPress('Down', function() ignoreListPanel:focusNextChild(KeyboardFocusReason) end, channelsWindow)
g_keyboard.bindKeyPress('Up', function() ignoreListPanel:focusPreviousChild(KeyboardFocusReason) end, channelsWindow)
local removeButton = ignoreWindow:getChildById('buttonRemove')
removeButton:disable()
ignoreListPanel.onChildFocusChange = function() removeButton:enable() end
removeButton.onClick = function()
local selection = ignoreListPanel:getFocusedChild()
if selection then
ignoreListPanel:removeChild(selection)
end
if ignoreListPanel:getChildCount() == 0 then
removeButton:disable()
end
end
local newlyIgnoredPlayers = {}
local addName = ignoreWindow:getChildById('ignoreNameEdit')
local addButton = ignoreWindow:getChildById('buttonAdd')
local addFunction = function()
if addName:getText() == '' then return end
if table.find(ignoreSettings.players, addName:getText()) then return end
if table.find(newlyIgnoredPlayers, addName:getText()) then return end
local label = g_ui.createWidget('IgnoreListLabel', ignoreListPanel)
label:setText(addName:getText())
table.insert(newlyIgnoredPlayers, addName:getText())
label:setPhantom(false)
addName:setText('')
end
addButton.onClick = addFunction
ignoreWindow.onEnter = addFunction
local ignorePrivateMessageBox = ignoreWindow:getChildById('checkboxIgnorePrivateMessages')
ignorePrivateMessageBox:setChecked(ignoreSettings.privateMessages)
local ignoreYellingBox = ignoreWindow:getChildById('checkboxIgnoreYelling')
ignoreYellingBox:setChecked(ignoreSettings.yelling)
local saveButton = ignoreWindow:getChildById('buttonSave')
saveButton.onClick = function()
ignoreSettings.players = {}
for i = 1, ignoreListPanel:getChildCount() do
table.insert(ignoreSettings.players, ignoreListPanel:getChildByIndex(i):getText())
end
ignoreSettings.yelling = ignoreYellingBox:isChecked()
ignoreSettings.privateMessages = ignorePrivateMessageBox:isChecked()
ignoreWindow:destroy()
end
for _, name in pairs(ignoreSettings.players) do
local label = g_ui.createWidget('IgnoreListLabel', ignoreListPanel)
label:setText(name)
label:setPhantom(false)
end
end
function onGameStart() function onGameStart()
-- open last channels -- open last channels
local lastChannelsOpen = g_settings.getNode('lastChannelsOpen') local lastChannelsOpen = g_settings.getNode('lastChannelsOpen')

View File

@ -118,12 +118,22 @@ Panel
id: channelsButton id: channelsButton
!tooltip: tr('Open new channel') .. ' (Ctrl+O)' !tooltip: tr('Open new channel') .. ' (Ctrl+O)'
icon: icons/channels.png icon: icons/channels.png
anchors.right: parent.right anchors.right: next.left
anchors.top: parent.top anchors.top: parent.top
margin-right: 5 margin-right: 5
margin-top: 6 margin-top: 6
@onClick: g_game.requestChannels() @onClick: g_game.requestChannels()
TabButton
id: ignoreButton
!tooltip: tr('Ignore players')
icon: icons/ignore.png
anchors.right: parent.right
anchors.top: parent.top
margin-right: 5
margin-top: 6
@onClick: onClickIgnoreButton()
Panel Panel
id: consoleContentPanel id: consoleContentPanel
anchors.top: prev.bottom anchors.top: prev.bottom

Binary file not shown.

After

Width:  |  Height:  |  Size: 474 B

View File

@ -0,0 +1,98 @@
IgnoreListLabel < Label
font: verdana-11px-monochrome
background-color: alpha
text-offset: 2 0
focusable: true
$focus:
background-color: #ffffff22
color: #ffffff
MainWindow
id: ignoreWindow
!text: tr('Ignore List')
size: 500 240
@onEscape: self:destroy()
Label
!text: tr('Ignored players:')
anchors.left: parent.left
anchors.top: parent.top
TextList
id: ignoreList
vertical-scrollbar: ignoreListScrollBar
anchors.left: parent.left
anchors.top: prev.bottom
height: 150
width: 230
margin-bottom: 10
margin-top: 3
padding: 1
focusable: false
Button
id: buttonRemove
!text: tr('Remove')
width: 64
anchors.right: prev.right
anchors.bottom: parent.bottom
TextEdit
id: ignoreNameEdit
anchors.left: ignoreList.right
anchors.top: ignoreList.top
width: 180
margin-left: 8
margin-right: 3
Button
id: buttonAdd
!text: tr('Add')
width: 48
height: 20
anchors.right: parent.right
anchors.top: prev.top
CheckBox
id: checkboxIgnorePrivateMessages
!text: tr('Ignore Private Messages')
anchors.left: ignoreList.right
anchors.top: ignoreList.top
width: 180
margin-top: 25
margin-left: 8
CheckBox
id: checkboxIgnoreYelling
!text: tr('Ignore Yelling')
anchors.left: ignoreList.right
anchors.top: prev.top
width: 180
margin-top: 25
margin-left: 8
Button
id: buttonSave
!text: tr('Save')
width: 64
anchors.right: next.left
anchors.bottom: parent.bottom
margin-right: 10
@onClick: self:getParent():onEnter()
Button
id: buttonCancel
!text: tr('Cancel')
width: 64
anchors.right: parent.right
anchors.bottom: parent.bottom
@onClick: self:getParent():destroy()
VerticalScrollBar
id: ignoreListScrollBar
anchors.top: ignoreList.top
anchors.bottom: ignoreList.bottom
anchors.right: ignoreList.right
step: 14
pixels-scroll: true

View File

@ -215,7 +215,7 @@ MainWindow
margin-top: 3 margin-top: 3
margin-left: 3 margin-left: 3
text: Any text: Any
width: 50 width: 75
CheckBox CheckBox
id: vocationBoxSorcerer id: vocationBoxSorcerer
@ -223,7 +223,7 @@ MainWindow
anchors.top: prev.bottom anchors.top: prev.bottom
margin-top: 3 margin-top: 3
text: Sorcerer text: Sorcerer
width: 50 width: 75
CheckBox CheckBox
id: vocationBoxDruid id: vocationBoxDruid
@ -231,7 +231,7 @@ MainWindow
anchors.top: prev.bottom anchors.top: prev.bottom
margin-top: 3 margin-top: 3
text: Druid text: Druid
width: 50 width: 75
CheckBox CheckBox
id: vocationBoxPaladin id: vocationBoxPaladin
@ -239,7 +239,7 @@ MainWindow
anchors.top: prev.bottom anchors.top: prev.bottom
margin-top: 3 margin-top: 3
text: Paladin text: Paladin
width: 50 width: 75
CheckBox CheckBox
id: vocationBoxKnight id: vocationBoxKnight
@ -247,7 +247,7 @@ MainWindow
anchors.top: prev.bottom anchors.top: prev.bottom
margin-top: 3 margin-top: 3
text: Knight text: Knight
width: 50 width: 75
Label Label
id: labelGroupFilter id: labelGroupFilter
@ -266,7 +266,7 @@ MainWindow
margin-top: 3 margin-top: 3
margin-left: 3 margin-left: 3
text: Any text: Any
width: 50 width: 75
CheckBox CheckBox
id: groupBoxAttack id: groupBoxAttack
@ -274,7 +274,7 @@ MainWindow
anchors.top: prev.bottom anchors.top: prev.bottom
margin-top: 3 margin-top: 3
text: Attack text: Attack
width: 50 width: 75
CheckBox CheckBox
id: groupBoxHealing id: groupBoxHealing
@ -282,7 +282,7 @@ MainWindow
anchors.top: prev.bottom anchors.top: prev.bottom
margin-top: 3 margin-top: 3
text: Healing text: Healing
width: 50 width: 75
CheckBox CheckBox
id: groupBoxSupport id: groupBoxSupport
@ -290,7 +290,7 @@ MainWindow
anchors.top: prev.bottom anchors.top: prev.bottom
margin-top: 3 margin-top: 3
text: Support text: Support
width: 50 width: 75
Label Label
id: labelPremiumFilter id: labelPremiumFilter
@ -309,7 +309,7 @@ MainWindow
margin-top: 3 margin-top: 3
margin-left: 3 margin-left: 3
text: Any text: Any
width: 50 width: 75
CheckBox CheckBox
id: premiumBoxNo id: premiumBoxNo
@ -317,7 +317,7 @@ MainWindow
anchors.top: prev.bottom anchors.top: prev.bottom
margin-top: 3 margin-top: 3
text: No text: No
width: 50 width: 75
CheckBox CheckBox
id: premiumBoxYes id: premiumBoxYes
@ -325,4 +325,4 @@ MainWindow
anchors.top: prev.bottom anchors.top: prev.bottom
margin-top: 3 margin-top: 3
text: Yes text: Yes
width: 50 width: 75

View File

@ -103,6 +103,10 @@ function displayStatusMessage(text)
displayMessage(MessageModes.Status, text) displayMessage(MessageModes.Status, text)
end end
function displayFailureMessage(text)
displayMessage(MessageModes.Failure, text)
end
function displayGameMessage(text) function displayGameMessage(text)
displayMessage(MessageModes.Game, text) displayMessage(MessageModes.Game, text)
end end