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

entry.py (7514B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\auraguidance\client\ui\entry.py
      2 import blue
      3 import uthread2
      4 from auraguidance.client.aura_guidance_signals import on_suggestion_clicked
      5 from auraguidance.client.ui.const import AURA_CHAT_ICON_PATH, AURA_NAME_PATH, LOADING_LABEL_PATH, MESSAGE_PORTRAIT_SIZE, NO_ASSESS_LABEL_PATH, SENDER_NAME_FORMAT, SENDER_TYPE_PLAYER, SENDER_TYPE_SERVER, SUGGESTIONS
      6 from auraguidance.client.ui.suggestions import AuraSuggestionsButton
      7 from carbonui import Align, ButtonFrameType, ButtonVariant, Density, PickState, TextColor, uiconst
      8 from carbonui.control.baseScrollContEntry import BaseScrollContEntry
      9 from carbonui.control.button import Button
     10 from carbonui.primitives.container import Container
     11 from carbonui.primitives.containerAutoSize import ContainerAutoSize
     12 from carbonui.primitives.sprite import Sprite
     13 from carbonui.text.custom import TextCustom
     14 from carbonui.uianimations import animations
     15 from chat.client.util import parse_chat_message
     16 from eve.client.script.ui.control.eveLoadingWheel import LoadingWheel
     17 from eveui import CurveType
     18 from localization import GetByLabel
     19 
     20 class ChatMessageEntry(BaseScrollContEntry):
     21     default_name = 'aura_chat_message_entry'
     22 
     23     def ApplyAttributes(self, attributes):
     24         self._sender_type = attributes.Get('sender_type', SENDER_TYPE_PLAYER)
     25         self._message_label = None
     26         self._portrait = None
     27         self._is_error = False
     28         self._message_color = TextColor.NORMAL
     29         if self._sender_type == SENDER_TYPE_PLAYER:
     30             self.message_text = '...'
     31         else:
     32             self.message_text = GetByLabel(LOADING_LABEL_PATH)
     33         if self._sender_type == SENDER_TYPE_PLAYER:
     34             self._is_waiting = False
     35             self._sender_name = cfg.eveowners.Get(session.charid).name
     36             self._name_color = TextColor.NORMAL
     37         else:
     38             self._is_waiting = True
     39             self._sender_name = GetByLabel(AURA_NAME_PATH)
     40             self._name_color = TextColor.AURA
     41         self.thread_tasklet = None
     42         self.loading_indicator = None
     43         super(ChatMessageEntry, self).ApplyAttributes(attributes)
     44         self._layout()
     45 
     46     @property
     47     def message_text(self):
     48         return self._message_text or ''
     49 
     50     @message_text.setter
     51     def message_text(self, value):
     52         self._message_text = value
     53         if not self.destroyed and self._message_label:
     54             self._message_label.SetText(self._message_text)
     55             self.update_height()
     56 
     57     @property
     58     def message_color(self):
     59         return self._message_color
     60 
     61     @message_color.setter
     62     def message_color(self, value):
     63         self._message_color = value
     64         if self._message_label:
     65             self._message_label.color = self._message_color
     66 
     67     def set_response_text(self, text, is_fallback):
     68         self._is_waiting = False
     69         if self._sender_type == SENDER_TYPE_PLAYER:
     70             self.message_color = TextColor.NORMAL
     71         elif is_fallback:
     72             self.message_color = TextColor.SECONDARY
     73         else:
     74             self.message_color = TextColor.NORMAL
     75         self.message_text = text
     76         if self.loading_indicator:
     77             self.loading_indicator.Close()
     78             self.loading_indicator = None
     79         if self._message_label:
     80             if is_fallback:
     81                 animations.Play(animations.GetColorCurve(TextColor.WARNING, TextColor.SECONDARY, 5.0, curveType=CurveType.smooth), self._message_label, 'color')
     82 
     83     def set_error_state(self):
     84         self._is_waiting = False
     85         self._is_error = True
     86         self.message_color = TextColor.DANGER
     87         self.message_text = GetByLabel(NO_ASSESS_LABEL_PATH)
     88         if self.loading_indicator:
     89             self.loading_indicator.Close()
     90             self.loading_indicator = None
     91 
     92     def stop_animation(self):
     93         if self.thread_tasklet:
     94             self._is_waiting = False
     95             self.thread_tasklet.Kill()
     96             self.thread_tasklet = None
     97 
     98     def _layout(self):
     99         self._portrait_container = Container(name='portrait_container', parent=self, align=Align.TOPLEFT, width=MESSAGE_PORTRAIT_SIZE, height=MESSAGE_PORTRAIT_SIZE, top=2)
    100         if self._sender_type == SENDER_TYPE_SERVER:
    101             self._portrait = Sprite(name='aura_icon', parent=self._portrait_container, align=Align.TOALL, texturePath=AURA_CHAT_ICON_PATH)
    102         else:
    103             self._portrait = Sprite(name='player_portrait', parent=self._portrait_container, align=Align.TOALL, texturePath='res:/UI/Texture/silhouette_64.png')
    104             uthread2.start_tasklet(self._load_player_portrait)
    105         self._content_container = ContainerAutoSize(name='content_container', parent=self, align=Align.TOTOP, alignMode=Align.TOTOP, padLeft=MESSAGE_PORTRAIT_SIZE + 8, callback=self.update_height, only_use_callback_when_size_changes=True)
    106         self._name_label = TextCustom(name='sender_name', parent=self._content_container, align=Align.TOTOP, text=GetByLabel(SENDER_NAME_FORMAT) % self._sender_name, color=self._name_color, pickState=PickState.ON)
    107         self._message_label = TextCustom(name='message_text', parent=self._content_container, align=Align.TOTOP, text=self.message_text, color=self._message_color, padTop=2, linkStyle=uiconst.LINKSTYLE_REGULAR, pickState=PickState.ON)
    108         self._message_label.CopyText = self.copy_text
    109         self._name_label.GetMenu = self._message_label.GetMenu
    110         if self._is_waiting:
    111             self.loading_indicator = LoadingWheel(parent=self._content_container, align=Align.BOTTOMLEFT, width=24, height=24)
    112 
    113     def _load_player_portrait(self):
    114         if session.charid and self._portrait:
    115             sm.GetService('photo').GetPortrait(session.charid, MESSAGE_PORTRAIT_SIZE, self._portrait, orderIfMissing=True)
    116 
    117     def update_width(self, new_width):
    118         if self._message_label:
    119             new_width = new_width - MESSAGE_PORTRAIT_SIZE - 16
    120             if self._message_label.width != new_width:
    121                 self._message_label.width = new_width
    122                 self.update_height()
    123 
    124     def update_height(self):
    125         if self._message_label:
    126             total_height = max(MESSAGE_PORTRAIT_SIZE, self._content_container.height) + 4
    127             if self.height != total_height:
    128                 self.height = total_height
    129 
    130     def copy_text(self):
    131         if self._sender_type == SENDER_TYPE_SERVER:
    132             text = parse_chat_message(self.message_text, truncate=False)
    133         else:
    134             text = self.message_text
    135         blue.pyos.SetClipboardData(text)
    136 
    137     def get_formatted_text(self):
    138         text = self.message_text.text.replace('>', '>').replace('&', '&')
    139         text += '%s > %s\r\n' % (self._sender_name, text)
    140 
    141 
    142 class AuraSuggestionsEntry(BaseScrollContEntry):
    143 
    144     def ApplyAttributes(self, attributes):
    145         self.default_height = 60
    146         super(AuraSuggestionsEntry, self).ApplyAttributes(attributes)
    147         self.button_top_help = Button(parent=self, align=Align.TOPLEFT, label=SUGGESTIONS[0], padLeft=MESSAGE_PORTRAIT_SIZE + 8, padTop=4, padRight=4, padBottom=4, func=lambda value: on_suggestion_clicked(SUGGESTIONS[0]), density=Density.COMPACT)
    148         self.button_show_more = AuraSuggestionsButton(variant=ButtonVariant.GHOST, frame_type=ButtonFrameType.CUT_BOTTOM_RIGHT, parent=self, align=Align.TOPLEFT, label=SUGGESTIONS[1], padLeft=MESSAGE_PORTRAIT_SIZE + 8, padTop=self.button_top_help.GetSize()[1], padRight=4, padBottom=4, density=Density.COMPACT)
    149         self.hint = None