NovaBryan/EVE_Dump
Log | Files | 📦 下载最新源码 (.zip) | Refs | README

hide_messages.py (6571B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\chat\client\hide_messages.py
      2 import carbonui.text.styles
      3 import re
      4 import localization
      5 import carbonui
      6 from carbonui.control.button import Button
      7 from carbonui.button.group import ButtonGroup
      8 from carbonui.control.checkbox import Checkbox
      9 from carbonui.control.window import Window
     10 from eve.client.script.ui.control.eveEditPlainText import EditPlainText
     11 from carbonui.primitives.container import Container
     12 from carbon.common.script.util.commonutils import StripTags
     13 from chat.common.const import ChatCategory, CATEGORY_LABEL_PATH
     14 SPLITTER = ','
     15 MAX_LENGTH = 500
     16 HIDE_MESSAGE_PATTERNS = {}
     17 NON_FILTERABLE_CATEGORIES = (ChatCategory.PRIVATE, ChatCategory.FLEET)
     18 HAS_PER_CHANNEL_SETTING = (ChatCategory.LOCAL, ChatCategory.SYSTEM, ChatCategory.PLAYER)
     19 
     20 def open_hide_message_settings(category_id, channel_id, channel_name):
     21     window = HideMessageSettingWindow.GetIfOpen()
     22     if window:
     23         window.Close()
     24     if category_id in NON_FILTERABLE_CATEGORIES:
     25         return
     26     HideMessageSettingWindow.Open(category_id=category_id, channel_id=channel_id, channel_name=channel_name)
     27 
     28 
     29 def has_hide_message_setting(category_id):
     30     return category_id not in NON_FILTERABLE_CATEGORIES
     31 
     32 
     33 def get_hide_message_pattern(channel_id, category_id):
     34     if settings.user.ui.HasKey(_get_setting_key(channel_id)):
     35         return _get_hide_message_pattern(channel_id)
     36     if settings.user.ui.HasKey(_get_setting_key(category_id)):
     37         return _get_hide_message_pattern(category_id)
     38 
     39 
     40 def _hide_message_setting_changed(channel_id, category_id):
     41     global HIDE_MESSAGE_PATTERNS
     42     if channel_id:
     43         HIDE_MESSAGE_PATTERNS.pop(channel_id, None)
     44     if category_id:
     45         HIDE_MESSAGE_PATTERNS.pop(category_id, None)
     46 
     47 
     48 def _get_hide_message_pattern(key):
     49     if key not in HIDE_MESSAGE_PATTERNS:
     50         channel_hide_word_list = settings.user.ui.Get(_get_setting_key(key), None)
     51         if channel_hide_word_list:
     52             text = '|'.join((re.escape(word) for word in channel_hide_word_list))
     53             pattern = re.compile(text, re.IGNORECASE)
     54         else:
     55             pattern = None
     56         HIDE_MESSAGE_PATTERNS[key] = pattern
     57     return HIDE_MESSAGE_PATTERNS[key]
     58 
     59 
     60 def _get_setting_key(key):
     61     return 'chat_hide_message_{}'.format(key)
     62 
     63 
     64 class HideMessageSettingWindow(Window):
     65     default_width = 380
     66     default_height = 480
     67     default_isCompact = True
     68     default_minSize = (default_width, default_height)
     69     default_windowID = 'HideMessageSettingWindow'
     70     default_captionLabelPath = 'UI/Chat/MessageFilterWindowTitle'
     71 
     72     def ApplyAttributes(self, attributes):
     73         Window.ApplyAttributes(self, attributes)
     74         self._channel_id = attributes.channel_id
     75         self._category_id = attributes.category_id
     76         if self._category_id not in HAS_PER_CHANNEL_SETTING or self._category_id == self._channel_id:
     77             self._channel_id = None
     78         btnGroup = ButtonGroup(parent=self.sr.main, align=carbonui.Align.TOBOTTOM, padTop=16)
     79         Button(parent=btnGroup, label=localization.GetByLabel('UI/Common/Buttons/Save'), func=self._save)
     80         Button(parent=btnGroup, label=localization.GetByLabel('UI/Common/Buttons/Cancel'), func=self._cancel)
     81         if self._channel_id:
     82             channel_container = Container(name='channel_container', parent=self.sr.main, align=carbonui.Align.TOBOTTOM_PROP, height=0.5)
     83             carbonui.text.styles.TextHeader(parent=channel_container, align=carbonui.Align.TOTOP, text=localization.GetByLabel('UI/Chat/MessageFilterChannelSection', channel_name=attributes.channel_name), padTop=16)
     84             is_overriding = settings.user.ui.HasKey(_get_setting_key(self._channel_id))
     85             self._override_checkbox = Checkbox(parent=channel_container, align=carbonui.Align.TOTOP, text=localization.GetByLabel('UI/Chat/MessageFilterChannelOverride'), hint=localization.GetByLabel('UI/Chat/MessageFilterChannelOverrideHint'), checked=is_overriding, callback=self._override_checked, padBottom=4, padTop=4)
     86             channel_hide_word_list = settings.user.ui.Get(_get_setting_key(self._channel_id), [])
     87             channel_hide_words = SPLITTER.join(channel_hide_word_list)
     88             self._channel_field = EditPlainText(name='channel_field', parent=channel_container, align=carbonui.Align.TOALL, ignoreTags=True, setvalue=channel_hide_words, hintText=localization.GetByLabel('UI/Chat/MessageFilterDetails'), maxLength=MAX_LENGTH)
     89             if not is_overriding:
     90                 self._channel_field.Disable()
     91         category_container = Container(parent=self.sr.main, name='category_container', align=carbonui.Align.TOALL)
     92         category_name = localization.GetByLabel(CATEGORY_LABEL_PATH.get(self._category_id, ''))
     93         carbonui.text.styles.TextHeader(parent=category_container, align=carbonui.Align.TOTOP, text=localization.GetByLabel('UI/Chat/MessageFilterCategorySection', category_name=category_name))
     94         category_hide_word_list = settings.user.ui.Get(_get_setting_key(self._category_id), [])
     95         category_hide_words = SPLITTER.join(category_hide_word_list)
     96         self._category_field = EditPlainText(name='category_field', parent=category_container, align=carbonui.Align.TOALL, ignoreTags=True, setvalue=category_hide_words, hintText=localization.GetByLabel('UI/Chat/MessageFilterDetails'), maxLength=MAX_LENGTH)
     97 
     98     def _override_checked(self, checkbox):
     99         if checkbox.GetValue():
    100             self._channel_field.Enable()
    101         else:
    102             self._channel_field.Disable()
    103 
    104     def _save(self, *args, **kwargs):
    105 
    106         def GetTextParts(editField):
    107             text = editField.GetValue()
    108             text = StripTags(text)
    109             textParts = text.strip(SPLITTER).split(SPLITTER)
    110             textParts = filter(None, (word.strip() for word in textParts))
    111             return textParts
    112 
    113         if self._channel_id:
    114             override = self._override_checkbox.GetValue()
    115             if override:
    116                 channel_hide_words = GetTextParts(self._channel_field)
    117                 settings.user.ui.Set(_get_setting_key(self._channel_id), channel_hide_words)
    118             else:
    119                 settings.user.ui.Delete(_get_setting_key(self._channel_id))
    120         category_hide_words = GetTextParts(self._category_field)
    121         settings.user.ui.Set(_get_setting_key(self._category_id), category_hide_words)
    122         _hide_message_setting_changed(self._channel_id, self._category_id)
    123         self.CloseByUser()
    124 
    125     def _cancel(self, *args, **kwargs):
    126         self.CloseByUser()