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
channels = nil
channelsWindow = nil
ignoreWindow = nil
ownPrivateName = nil
messageHistory = {}
currentMessageIndex = 0
@ -62,6 +63,12 @@ ignoreNpcMessages = false
defaultTab = nil
serverTab = nil
local ignoreSettings = {
privateMessages = false,
yelling = false,
players = {}
}
function init()
connect(g_game, { onTalk = onTalk,
onChannelList = onChannelList,
@ -99,6 +106,9 @@ function init()
g_keyboard.bindKeyDown('Ctrl+O', g_game.requestChannels)
g_keyboard.bindKeyDown('Ctrl+E', removeCurrentTab)
g_keyboard.bindKeyDown('Ctrl+H', openHelp)
-- Ignore List
loadIgnoreSettings()
end
function terminate()
@ -117,11 +127,18 @@ function terminate()
g_keyboard.unbindKeyDown('Ctrl+E')
g_keyboard.unbindKeyDown('Ctrl+H')
saveIgnoreSettings()
if channelsWindow then
channelsWindow:destroy()
channelsWindow = nil
end
if ignoreWindow then
ignoreWindow:destroy()
ignoreWindow = nil
end
consolePanel:destroy()
consolePanel = nil
consoleTextEdit = nil
@ -589,6 +606,14 @@ function onTalk(name, level, mode, message, channelId, creaturePos)
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
mode == MessageModes.Spell or mode == MessageModes.MonsterSay or mode == MessageModes.MonsterYell or
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
local defaultMessage = mode <= 3 and true or false
speaktype = SpeakTypes[mode]
if not speaktype then
perror('unhandled onTalk message mode ' .. mode .. ': ' .. message)
@ -677,7 +701,11 @@ function doChannelListSubmit()
local channelListPanel = channelsWindow:getChildById('channelList')
local openPrivateChannelWith = channelsWindow:getChildById('openPrivateChannelWith'):getText()
if openPrivateChannelWith ~= '' then
if openPrivateChannelWith:lower() ~= g_game.getLocalPlayer():getName():lower() then
g_game.openPrivateChannel(openPrivateChannelWith)
else
modules.game_textmessage.displayFailureMessage('You cannot create a private chat channel with yourself.')
end
else
local selectedChannelLabel = channelListPanel:getFocusedChild()
if not selectedChannelLabel then return end
@ -715,6 +743,100 @@ function onChannelList(channelList)
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()
-- open last channels
local lastChannelsOpen = g_settings.getNode('lastChannelsOpen')

View File

@ -118,12 +118,22 @@ Panel
id: channelsButton
!tooltip: tr('Open new channel') .. ' (Ctrl+O)'
icon: icons/channels.png
anchors.right: parent.right
anchors.right: next.left
anchors.top: parent.top
margin-right: 5
margin-top: 6
@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
id: consoleContentPanel
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-left: 3
text: Any
width: 50
width: 75
CheckBox
id: vocationBoxSorcerer
@ -223,7 +223,7 @@ MainWindow
anchors.top: prev.bottom
margin-top: 3
text: Sorcerer
width: 50
width: 75
CheckBox
id: vocationBoxDruid
@ -231,7 +231,7 @@ MainWindow
anchors.top: prev.bottom
margin-top: 3
text: Druid
width: 50
width: 75
CheckBox
id: vocationBoxPaladin
@ -239,7 +239,7 @@ MainWindow
anchors.top: prev.bottom
margin-top: 3
text: Paladin
width: 50
width: 75
CheckBox
id: vocationBoxKnight
@ -247,7 +247,7 @@ MainWindow
anchors.top: prev.bottom
margin-top: 3
text: Knight
width: 50
width: 75
Label
id: labelGroupFilter
@ -266,7 +266,7 @@ MainWindow
margin-top: 3
margin-left: 3
text: Any
width: 50
width: 75
CheckBox
id: groupBoxAttack
@ -274,7 +274,7 @@ MainWindow
anchors.top: prev.bottom
margin-top: 3
text: Attack
width: 50
width: 75
CheckBox
id: groupBoxHealing
@ -282,7 +282,7 @@ MainWindow
anchors.top: prev.bottom
margin-top: 3
text: Healing
width: 50
width: 75
CheckBox
id: groupBoxSupport
@ -290,7 +290,7 @@ MainWindow
anchors.top: prev.bottom
margin-top: 3
text: Support
width: 50
width: 75
Label
id: labelPremiumFilter
@ -309,7 +309,7 @@ MainWindow
margin-top: 3
margin-left: 3
text: Any
width: 50
width: 75
CheckBox
id: premiumBoxNo
@ -317,7 +317,7 @@ MainWindow
anchors.top: prev.bottom
margin-top: 3
text: No
width: 50
width: 75
CheckBox
id: premiumBoxYes
@ -325,4 +325,4 @@ MainWindow
anchors.top: prev.bottom
margin-top: 3
text: Yes
width: 50
width: 75

View File

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