From 1784bd9f26f37568ea1fe3860d6113fee573b33d Mon Sep 17 00:00:00 2001 From: Samuel Date: Wed, 9 Jan 2013 23:03:04 +0100 Subject: [PATCH] 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 --- modules/game_console/console.lua | 126 ++++++++++++++++++++++- modules/game_console/console.otui | 12 ++- modules/game_console/icons/ignore.png | Bin 0 -> 474 bytes modules/game_console/ignorewindow.otui | 98 ++++++++++++++++++ modules/game_spelllist/spelllist.otui | 24 ++--- modules/game_textmessage/textmessage.lua | 4 + 6 files changed, 249 insertions(+), 15 deletions(-) create mode 100644 modules/game_console/icons/ignore.png create mode 100644 modules/game_console/ignorewindow.otui diff --git a/modules/game_console/console.lua b/modules/game_console/console.lua index 350a7665..150a153e 100644 --- a/modules/game_console/console.lua +++ b/modules/game_console/console.lua @@ -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,10 +127,17 @@ 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 @@ -588,6 +605,14 @@ function onTalk(name, level, mode, message, channelId, creaturePos) 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 mode == MessageModes.Spell or mode == MessageModes.MonsterSay or mode == MessageModes.MonsterYell or @@ -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 - g_game.openPrivateChannel(openPrivateChannelWith) + 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') diff --git a/modules/game_console/console.otui b/modules/game_console/console.otui index 59b5acd5..d13f8c3d 100644 --- a/modules/game_console/console.otui +++ b/modules/game_console/console.otui @@ -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 diff --git a/modules/game_console/icons/ignore.png b/modules/game_console/icons/ignore.png new file mode 100644 index 0000000000000000000000000000000000000000..8ed2df6a6d221a3ca409b96d025812133a972934 GIT binary patch literal 474 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE)4%caKYZ?lYt_f1s;*b z3=G`DAk4@xYmNj^kiEpy*OmP)Bd4H(u->8k0HBa;W=KSdbAE1aYF-JD%fR4Vl$uzQ znxasiS(2gP?&%wlqL<3fz`$td>Eak-aeD1!!@NTV60Pxz7-VN{jahK+))bEpo=A&^ z^9T8u-4jlpv)ps=z$3*KL0(p=1>dz~Coj#MaHr9V>)0aZ+R0D+zN{rv;Io31=c z-n`Mie7B*Fc5T#JsmV8=Y~0;ybYA$T3FGoD%iArN{!Q8~JH2wA!>I?gd*!w;h_W?! zbsSNB!gEOT?e3NyEkz*)jn6hewYcONWEd)D_{Bf@D4}&&U**Y^WejWbBp70x4()zu zVEvkrA?5Q=7jvzI^7TTGOq1UHW=d!(S=xSEt|XMRFhKpks2LN(3GMTBftz{Ndws$U z_MX%A^-(@HOYFn8m~SbUS$19Qe{8$F@Qh1thw@aPXNERYtPj>nfIbczV0cTuxszf Og4om5&t;ucLK6Tuhra;; literal 0 HcmV?d00001 diff --git a/modules/game_console/ignorewindow.otui b/modules/game_console/ignorewindow.otui new file mode 100644 index 00000000..47a1d84f --- /dev/null +++ b/modules/game_console/ignorewindow.otui @@ -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 diff --git a/modules/game_spelllist/spelllist.otui b/modules/game_spelllist/spelllist.otui index d8abc18e..d582ee9e 100644 --- a/modules/game_spelllist/spelllist.otui +++ b/modules/game_spelllist/spelllist.otui @@ -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 diff --git a/modules/game_textmessage/textmessage.lua b/modules/game_textmessage/textmessage.lua index 1a53ea22..e841fbd1 100644 --- a/modules/game_textmessage/textmessage.lua +++ b/modules/game_textmessage/textmessage.lua @@ -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