message.py (11617B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\carbonui\control\message.py 2 import math 3 import blue 4 import carbonui 5 import carbonui.text.styles 6 import eveicon 7 import localization 8 import uthread 9 from carbon.common.script.util import timerstuff 10 from carbonui import uiconst 11 from carbonui.control.buttonIcon import ButtonIcon 12 from carbonui.decorative.menuUnderlay import MenuUnderlay 13 from carbonui.primitives.container import Container 14 from carbonui.primitives.sprite import Sprite 15 from carbonui.uianimations import animations 16 from carbonui.uicore import uicore 17 from eve.client.script.ui import eveColor 18 from eve.client.script.ui.control.themeColored import FillThemeColored 19 from eve.client.script.util.settings import IsShipHudTopAligned 20 21 class MessageData: 22 23 def __init__(self, time_stamp, text, icons = None, damage_html = None, icon_color = None): 24 self.time_stamp = time_stamp 25 self.text = text 26 self.icons = icons or [] 27 self.icon_color = icon_color or eveColor.WHITE 28 self.damage_html = damage_html 29 30 31 class MessageParentClass(Container): 32 __guid__ = 'uicls.MessageParentClass' 33 __notifyevents__ = ['OnEndChangeDevice', 'OnSessionChanged'] 34 35 def ApplyAttributes(self, attributes): 36 Container.ApplyAttributes(self, attributes) 37 self.myLayer = uicore.layer.abovemain 38 self.minTop = 0 39 config = settings.char.ui.Get(self.configName, self.defaultConfig) 40 if not isinstance(config, tuple) or len(config) != 4: 41 config = self.defaultConfig 42 self.SetAllAlignments(config) 43 self.inDragMode = False 44 sm.RegisterNotify(self) 45 46 def SetAllAlignments(self, config, *args): 47 align, textAlign, left, topOffset = config 48 self.SetAlign(align) 49 self.currentTextAlignment = textAlign 50 self.left = left 51 self.topOffset = topOffset 52 53 def EnterDragMode(self, *args): 54 self.dragFill = Sprite(parent=self, name='dragFill', texturePath='res:/UI/Texture/classes/Neocom/buttonDown.png', state=uiconst.UI_DISABLED, align=uiconst.TOALL, idx=2) 55 func = sm.GetService('logger').MoveNotifications 56 self.exitMoveModeBtn = ButtonIcon(name='close', parent=self, align=uiconst.TOPRIGHT, state=uiconst.UI_NORMAL, width=24, height=24, iconSize=16, texturePath=eveicon.close, func=lambda : func(False), hint=localization.GetByLabel('UI/Accessories/Log/ExitMessageMovingMode'), idx=0) 57 self.state = uiconst.UI_NORMAL 58 self.inDragMode = True 59 uicore.animations.SpSwoopBlink(self.dragFill, rotation=math.pi - 0.5, duration=1.5, loops=10) 60 61 def BeginDrag(self, *args): 62 layerOffset = self.GetLayerOffset() 63 mouseX = uicore.uilib.x - layerOffset 64 self.lastx = mouseX 65 fromTop = self.absoluteTop - uicore.uilib.y 66 while not self.destroyed and getattr(self, 'dragging', 0): 67 self.CalculateRepositioning(fromTop) 68 blue.pyos.synchro.SleepWallclock(1) 69 70 def GetLayerOffset(self): 71 return uicore.layer.abovemain.absoluteLeft 72 73 def CalculateRepositioning(self, fromTop, *args): 74 mouseX = uicore.uilib.x - self.GetLayerOffset() 75 xDiff = mouseX - self.lastx 76 uicore.uilib.SetCursor(uiconst.UICURSOR_NONE) 77 self.top = max(self.minTop, uicore.uilib.y + fromTop) 78 self.topOffset = self.top + self.height 79 self.DoAlignment(xDiff) 80 self.lastx = mouseX 81 82 def DoAlignment(self, xDiff = 0, *args): 83 layerOffset = self.GetLayerOffset() 84 if self.myLayer.display: 85 fullWidth, fullHeight = self.myLayer.GetAbsoluteSize() 86 else: 87 fullWidth = uicore.desktop.width - layerOffset 88 fromRightBorder = fullWidth - (self.absoluteRight - layerOffset) 89 alignmentMode = settings.user.ui.Get(self.settingNameAlign, 'auto') 90 autoAlign = alignmentMode == 'auto' 91 if autoAlign and fromRightBorder < 200 or alignmentMode == 'right': 92 if self.align != uiconst.TOPRIGHT: 93 self.SetAlign(uiconst.TOPRIGHT) 94 self.left = fromRightBorder 95 else: 96 self.left = max(0, self.left - xDiff) 97 self.left = min(self.left, fullWidth - 100) 98 self.left = max(self.left, 0) 99 self.SetTextAlignmentIfNeeded('right') 100 elif autoAlign and self.absoluteLeft - layerOffset < 200 or alignmentMode == 'left': 101 if self.align != uiconst.TOPLEFT: 102 left = self.absoluteLeft - layerOffset 103 self.SetAlign(uiconst.TOPLEFT) 104 self.left = left 105 else: 106 self.left = max(0, self.left + xDiff) 107 self.left = min(self.left, fullWidth - 100) 108 self.left = max(self.left, 0) 109 self.SetTextAlignmentIfNeeded('left') 110 else: 111 if self.align != uiconst.CENTERTOP: 112 self.left = self.absoluteLeft - layerOffset + self.width / 2 - fullWidth / 2 113 self.SetAlign(uiconst.CENTERTOP) 114 else: 115 self.left = self.left + xDiff 116 self.left = max(self.left, -(fullWidth - 100) / 2) 117 self.left = min(self.left, (fullWidth - 100) / 2) 118 self.SetTextAlignmentIfNeeded('center') 119 self.SaveSettings() 120 121 def OnMouseDown(self, *args): 122 self.dragging = 1 123 uthread.new(self.BeginDrag) 124 125 def OnMouseUp(self, *args): 126 self.dragging = 0 127 128 def ExitDragMode(self, *args): 129 self.dragging = 0 130 dragFill = getattr(self, 'dragFill', None) 131 if dragFill: 132 dragFill.Close() 133 fakeText = getattr(self, 'fakeText', None) 134 if fakeText: 135 fakeText.Close() 136 exitMoveModeBtn = getattr(self, 'exitMoveModeBtn', None) 137 if exitMoveModeBtn: 138 exitMoveModeBtn.Close() 139 self.SaveSettings() 140 self.inDragMode = False 141 142 def SetTextAlignmentIfNeeded(self, alignment, *args): 143 pass 144 145 def SaveSettings(self, *args): 146 pass 147 148 def OnEndChangeDevice(self, *args): 149 self.defaultConfig = self.GetDefaultAlignmentValues() 150 if settings.char.ui.Get(self.configName, None) is None: 151 self.SetAllAlignments(self.defaultConfig) 152 153 def OnSessionChanged(self, isRemote, sess, change): 154 pass 155 156 def ResetAlignment(self, *args): 157 self.SetAllAlignments(self.defaultConfig) 158 self.SetSizeAndPosition() 159 160 def GetFakeText(self): 161 if getattr(self, 'fakeText', None) and not self.fakeText.destroyed: 162 return self.fakeText 163 164 165 class QuickMessage(MessageParentClass): 166 default_width = 300 167 168 def ApplyAttributes(self, attributes): 169 self.configName = 'generalMessages_config' 170 self.settingNameAlign = 'generalnotifictions_alignment' 171 self.defaultConfig = self.GetDefaultAlignmentValues() 172 MessageParentClass.ApplyAttributes(self, attributes) 173 self.layerOffset = 0 174 self.myLayer = uicore.layer.abovemain 175 self.minTop = 0 176 self.scope = uiconst.SCOPE_INGAME 177 self.message = None 178 self.allLabels = [] 179 self.pureText = '' 180 self.Prepare_Text_() 181 self.Prepare_Underlay_() 182 183 def GetLayerOffset(self): 184 return 0 185 186 def GetDefaultAlignmentValues(self, *args): 187 offset = sm.GetService('window').GetCameraLeftOffset(300, align=uiconst.CENTERTOP, left=0) 188 if IsShipHudTopAligned(): 189 top = uicore.desktop.height * 0.75 190 else: 191 top = max(uicore.desktop.height * 0.2, 175) 192 defaultConfig = (uiconst.CENTERTOP, 193 'center', 194 offset, 195 top) 196 return defaultConfig 197 198 def Prepare_Text_(self): 199 self.message = carbonui.text.styles.TextBody(text='', parent=self, pos=(8, 8, 284, 0), state=uiconst.UI_DISABLED) 200 self.allLabels.append(self.message) 201 202 def Prepare_Underlay_(self): 203 self.flashBG = FillThemeColored(bgParent=self, colorType=uiconst.COLORTYPE_FLASH) 204 MenuUnderlay(bgParent=self) 205 206 def ShowMsg(self, text, flash = True): 207 if getattr(self, 'fakeText', None) is not None: 208 self.fakeText.Close() 209 self.message.text = '<%s>%s' % (self.currentTextAlignment, text) 210 self.pureText = text 211 self.SetSizeAndPosition() 212 if not self.inDragMode: 213 self.state = uiconst.UI_DISABLED 214 self.SetOrder(0) 215 if flash: 216 self.AnimFlash() 217 if not self.inDragMode: 218 self.timer = timerstuff.AutoTimer(5000, self.hide) 219 220 def AnimEntry(self): 221 animations.FadeTo(self, self.opacity, 1.0, duration=0.3) 222 animations.MorphScalar(self, 'height', 0, self.height, duration=0.15) 223 224 def AnimFlash(self): 225 animations.FadeTo(self.flashBG, 2.0, 0.0, duration=0.3) 226 227 def SetSizeAndPosition(self, *args): 228 fakeText = self.GetFakeText() 229 if self.message.textheight == 0 and fakeText is not None: 230 self.height = fakeText.textheight 231 else: 232 self.height = self.message.textheight 233 self.height += 16 234 self.top = max(self.minTop, min(uicore.desktop.height - self.height, self.topOffset - self.height)) 235 236 def hide(self): 237 self.Close() 238 239 def kill_timer(self): 240 self.timer = None 241 242 def EnterDragMode(self, *args): 243 self.isVisible = self.state != uiconst.UI_HIDDEN 244 self.kill_timer() 245 if not self.isVisible: 246 if self.message is None: 247 self.Prepare_Text_() 248 self.Prepare_Underlay_() 249 self.message.text = '' 250 fakeText = self.GetFakeText() 251 if fakeText is None: 252 self.fakeText = carbonui.text.styles.TextBody(text='', parent=self, name='faketext', left=6, top=5, width=288, state=uiconst.UI_DISABLED, idx=0) 253 self.fakeText.text = '<br><%s>%s' % (self.currentTextAlignment, localization.GetByLabel('UI/Accessories/Log/ExampleText')) 254 self.height = self.fakeText.textheight + 10 255 MessageParentClass.EnterDragMode(self, *args) 256 257 def ExitDragMode(self, *args): 258 MessageParentClass.ExitDragMode(self, *args) 259 isVisible = getattr(self, 'isVisible', False) 260 if isVisible: 261 self.state = uiconst.UI_DISABLED 262 self.timer = timerstuff.AutoTimer(5000, self.hide) 263 else: 264 self.hide() 265 266 def SetTextAlignmentIfNeeded(self, alignment, *args): 267 if self.currentTextAlignment != alignment: 268 self.currentTextAlignment = alignment 269 fakeText = self.GetFakeText() 270 if fakeText: 271 fakeText.text = '<br><%s>%s' % (alignment, localization.GetByLabel('UI/Accessories/Log/ExampleText')) 272 else: 273 self.message.text = '<br><%s>%s' % (alignment, self.pureText) 274 275 def SaveSettings(self, *args): 276 settings.char.ui.Set('generalMessages_config', (self.align, 277 self.currentTextAlignment, 278 self.left, 279 self.topOffset)) 280 281 def _OnClose(self, *args): 282 self.kill_timer() 283 284 def ChangeFontSize(self, *args): 285 if self.message: 286 self.message.fontsize = settings.user.ui.Get('dmgnotifictions_fontsize', 12) 287 288 @classmethod 289 def show_message(cls, text, flash_existing = True): 290 layer = uicore.layer.abovemain 291 for each in layer.children[:]: 292 if isinstance(each, QuickMessage): 293 each.ShowMsg(text, flash_existing) 294 return 295 296 message = QuickMessage(parent=layer) 297 message.ShowMsg(text) 298 message.AnimEntry()