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

messagebox.py (8526B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\messagebox.py
      2 import carbonui
      3 import carbonui.text.styles
      4 import localization
      5 from carbonui import uiconst, Align, TextColor
      6 from carbonui.control.checkbox import Checkbox
      7 from carbonui.control.scrollContainer import ScrollContainer
      8 from carbonui.control.window import Window
      9 from carbonui.primitives.containerAutoSize import ContainerAutoSize
     10 from carbonui.primitives.sprite import Sprite
     11 from carbonui.uicore import uicore
     12 from eve.client.script.ui.shared.messageboxCustom import CUSTOM_MESSAGE_BOX_CLASSES, CUSTOM_MESSAGE_BOXES
     13 from eve.client.script.ui.util import uix
     14 from localization import GetByLabel
     15 from player_messaging import PromptOptions, PromptResult, PromptIcon
     16 from player_messaging.client import get_supressed_result, set_suppress_result
     17 ICON_BY_MSG_TYPE = {PromptIcon.INFO: 'res:/ui/Texture/WindowIcons/info.png',
     18  PromptIcon.WARNING: 'res:/ui/Texture/WindowIcons/warning.png',
     19  PromptIcon.QUESTION: 'res:/ui/Texture/WindowIcons/question.png',
     20  PromptIcon.ERROR: 'res:/ui/Texture/WindowIcons/stop.png',
     21  PromptIcon.FATAL: 'res:/UI/Texture/WindowICons/criminal.png'}
     22 
     23 class MessageBox(Window):
     24     __guid__ = 'form.MessageBox'
     25     __nonpersistvars__ = ['suppress']
     26     default_windowID = 'message'
     27     default_width = 420
     28     default_height = 260
     29     default_alwaysLoadDefaults = True
     30     default_isStackable = False
     31     default_isLockable = False
     32     default_isOverlayable = False
     33     default_icon_size = 48
     34     edit = None
     35     _message_scroll = None
     36     _message_label = None
     37 
     38     def ApplyAttributes(self, attributes):
     39         super(MessageBox, self).ApplyAttributes(attributes)
     40         self.icon_size = attributes.get('icon_size', self.default_icon_size)
     41         self.suppress = 0
     42         self.name = 'modal'
     43         self.msgKey = attributes.get('msgKey', None)
     44         self.construct_layout()
     45 
     46     def construct_layout(self):
     47         self.construct_top_parent()
     48         self.construct_icon()
     49 
     50     def construct_top_parent(self):
     51         self.topParent = ContainerAutoSize(name='topParent', parent=self.content, align=Align.TOTOP, alignMode=Align.TOPLEFT, minHeight=48, clipChildren=True, padTop=16)
     52 
     53     def construct_icon(self):
     54         self.topIcon = Sprite(name='mainicon', parent=ContainerAutoSize(parent=self.topParent, align=Align.TOPLEFT, minHeight=48), align=Align.CENTER, state=uiconst.UI_DISABLED, width=self.icon_size, height=self.icon_size, texturePath=self.iconNum)
     55 
     56     def construct_caption(self, title):
     57         if title is None:
     58             title = localization.GetByLabel('UI/Common/Information')
     59         carbonui.text.styles.TextHeadline(parent=self.topParent, padLeft=self.icon_size + 16, align=uiconst.VERTICALLY_CENTERED, text=title, color=TextColor.HIGHLIGHT)
     60 
     61     def construct_message_body(self, text):
     62         self._message_scroll = ScrollContainer(parent=self.content, align=uiconst.TOALL, padTop=16)
     63         self.edit = self._message_label = carbonui.text.styles.TextBody(parent=self._message_scroll, align=uiconst.TOTOP, state=uiconst.UI_NORMAL, text=text, tabs=list((16 * i for i in range(1, 9))))
     64 
     65     def _show_message(self, text, title, buttons, icon, suppText, default = None, modal = True, okLabel = None, cancelLabel = None, isClosable = True, is_suppressable = False, **kwargs):
     66         self.__show_message(title, buttons, icon, suppText, default, modal, okLabel, cancelLabel, isClosable, is_suppressable)
     67         if text:
     68             self.construct_message_body(text)
     69 
     70     def _show_message_custom_content(self, customContentCls, title, buttons, icon, suppText, default = None, modal = True, okLabel = None, cancelLabel = None, messageData = None, isClosable = True, is_suppressable = False):
     71         self.__show_message(title, buttons, icon, suppText, default, modal, okLabel, cancelLabel, isClosable, is_suppressable)
     72         customContent = customContentCls(parent=self.sr.main, padding=uiconst.defaultPadding, messageData=messageData, align=uiconst.TOTOP)
     73         height = customContent.GetContentHeight() + 80
     74         _, self.height = self.GetWindowSizeForContentSize(height=height)
     75         if getattr(customContent, 'forceMinHeight', False):
     76             minWidth = self.GetMinWidth()
     77             self.SetMinSize([minWidth, self.height])
     78         if getattr(customContent, 'setWidth', False):
     79             contentWidth = customContent.GetContentWidth()
     80             width, _ = self.GetWindowSizeForContentSize(width=contentWidth)
     81             self.width = max(self.width, width)
     82 
     83     def __show_message(self, title, buttons, icon, suppText, default, modal, okLabel, cancelLabel, isClosable, is_suppressable = False):
     84         self.MakeUnMinimizable()
     85         self.HideHeader()
     86         self.SetMinSize((self.default_width, self.default_height))
     87         iconTexturePath = uix.GetDialogIconTexturePath(icon)
     88         self.icon = iconTexturePath
     89         self.SetTopIcon(iconTexturePath)
     90         self.construct_caption(title)
     91         self.DefineButtons(buttons, default=default, okLabel=okLabel, cancelLabel=cancelLabel)
     92         if suppText:
     93             self.construct_suppress_checkbox(suppText)
     94         if modal:
     95             uicore.registry.SetFocus(self)
     96         if not isClosable:
     97             self.MakeUnKillable()
     98 
     99     def SetTopIcon(self, texturePath):
    100         if self.topIcon is not None:
    101             self.topIcon.texturePath = texturePath
    102 
    103     def construct_suppress_checkbox(self, text):
    104         if self.sr.bottom is not None:
    105             index = self.sr.bottom.GetOrder() + 1
    106         else:
    107             index = 0
    108         bottom = ContainerAutoSize(name='suppressContainer', parent=self.content, align=uiconst.TOBOTTOM, padding=(0, 8, 0, 8), idx=index)
    109         Checkbox(parent=bottom, align=uiconst.TOTOP, pos=(0, 0, 0, 0), text=text, settingsKey='suppress', checked=0, callback=self.ChangeSupp)
    110 
    111     def ChangeSupp(self, sender):
    112         self.suppress = sender.checked
    113 
    114     def SetText(self, txt):
    115         self._message_label.text = txt
    116         self._message_scroll.ScrollToVertical(0.0)
    117 
    118     def CloseByUser(self, *etc):
    119         if self.isModal:
    120             self.SetModalResult(PromptResult.CLOSE)
    121         else:
    122             Window.CloseByUser(self)
    123 
    124     def ClickYes(self):
    125         if self.isModal:
    126             self.SetModalResult(PromptResult.YES)
    127 
    128     def ClickOk(self):
    129         if self.isModal:
    130             self.SetModalResult(PromptResult.OK)
    131 
    132     @classmethod
    133     def is_disconnect_dialog_open(cls):
    134         return cls.IsOpen(windowID='DisconnectNotice')
    135 
    136     @classmethod
    137     def prompt_player(cls, text, title = '', buttons = None, icon = None, suppress_hint = None, default_response = None, modal = True, msgkey = None, messageData = None, customMsgBox = None, isClosable = True, is_suppressable = False, ok_label = None, cancel_label = None, **kwargs):
    138         if not getattr(uicore, 'desktop', None):
    139             return
    140         if cls.is_disconnect_dialog_open():
    141             return (default_response, False)
    142         if is_suppressable and not suppress_hint:
    143             if buttons in [None, PromptOptions.OK]:
    144                 suppress_hint = GetByLabel('/Carbon/UI/Common/DoNotShowAgain')
    145             else:
    146                 suppress_hint = GetByLabel('/Carbon/UI/Common/DoNotAskAgain')
    147         msgBoxClass = cls
    148         msgBoxParams = {'useDefaultPos': True,
    149          'msgKey': msgkey}
    150         if customMsgBox is not None:
    151             msgBoxClass, extraMsgBoxParams = customMsgBox
    152             msgBoxParams.update(extraMsgBoxParams)
    153         elif msgkey in CUSTOM_MESSAGE_BOX_CLASSES:
    154             msgBoxClass = CUSTOM_MESSAGE_BOX_CLASSES[msgkey]
    155         if buttons is None:
    156             buttons = PromptOptions.OK
    157         msgbox = msgBoxClass(**msgBoxParams)
    158         msgbox.state = uiconst.UI_HIDDEN
    159         msgbox.isModal = modal
    160         if msgkey is not None and msgkey in CUSTOM_MESSAGE_BOXES:
    161             msgbox._show_message_custom_content(CUSTOM_MESSAGE_BOXES[msgkey], title, buttons, icon, suppress_hint, default=default_response, modal=modal, messageData=messageData, isClosable=isClosable, is_suppressable=is_suppressable, okLabel=ok_label, cancelLabel=cancel_label)
    162         else:
    163             msgbox._show_message(text, title, buttons, icon, suppress_hint, default=default_response, modal=modal, isClosable=isClosable, is_suppressable=is_suppressable, okLabel=ok_label, cancelLabel=cancel_label)
    164         if modal:
    165             ret = msgbox.ShowModal()
    166         else:
    167             ret = msgbox.ShowDialog()
    168         return (ret, msgbox.suppress)