droneGroupHeader.py (16617B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\inflight\drones\droneGroupHeader.py 2 import dogma.attributes.format as attributeFormat 3 import eveicon 4 import trinity 5 import uthread2 6 from carbonui import TextColor, uiconst 7 from carbonui.control.buttonIcon import ButtonIcon 8 from carbonui.control.contextMenu.menuData import MenuData 9 from carbonui.control.contextMenu.menuEntryData import MenuEntryData 10 from carbonui.primitives.container import Container 11 from carbonui.primitives.containerAutoSize import ContainerAutoSize 12 from carbonui.primitives.fill import Fill 13 from carbonui.primitives.sprite import Sprite 14 from carbonui.uianimations import animations 15 from carbonui.uicore import uicore 16 from carbonui.util.various_unsorted import IsUnder 17 from dogma.data import get_attribute 18 from eve.client.script.environment import invControllers 19 from eve.client.script.ui import eveColor 20 from eve.client.script.ui.control import eveLabel 21 from eve.client.script.ui.control.tooltips import TooltipPanel 22 from eve.client.script.ui.inflight.drones import droneSignals, dronesDragData 23 from eve.client.script.ui.inflight.drones.buttonSeperatorLine import ButtonSeperatorLine 24 from eve.client.script.ui.inflight.drones.droneGroupsController import GetDroneGroupsController 25 from eve.client.script.ui.inflight.drones.droneSettings import drones_aggressive_setting, drones_focus_fire_setting 26 from eve.client.script.ui.inflight.drones.dronesConst import DRONESTATE_INSPACE, DRONESTATE_INBAY 27 from eve.client.script.ui.inflight.drones.dronesDragData import AllDronesInBayDragData, AllDronesInSpaceDragData, HasInBayDroneIDs, HasInSpaceDroneIDs 28 from eve.client.script.ui.inflight.drones.dronesUtil import LoadShortcutTooltip, GetDroneIDsInBay, GetDroneIDsInSpace, GetMaxDronesInSpace, ExpandRadialMenuForInBayGroup, ExpandRadialMenuForInSpaceGroup, GetDronesInLocalSpace, GetNumberOfDronesInBay 29 from eve.client.script.ui.services.menuSvcExtras import droneFunctions 30 from eve.client.script.ui.shared.pointerTool import pointerToolConst as pConst 31 from eve.client.script.ui.shared.shipTree.infoBubble import SkillEntry 32 from eve.client.script.util import eveMisc 33 from eve.common.lib import appConst 34 from eveservices.menu import GetMenuService 35 from fsdBuiltData.common.iconIDs import GetIconFile 36 from localization import GetByLabel 37 from menu import MenuList, MenuLabel 38 from shipfitting.droneUtil import GetDroneBandwidth 39 from signals import Signal 40 BUTTON_SIZE = 20 41 42 def GetDeleteGroupMenuEntry(): 43 delMenuEntries = [ (groupName, DeleteGroup, (groupName,)) for groupName, groupInfo in GetDroneGroupsController().GetGroupsByName().iteritems() ] 44 if delMenuEntries: 45 return MenuEntryData(MenuLabel('UI/Commands/DeleteGroup'), subMenuData=delMenuEntries) 46 47 48 def DeleteGroup(groupName): 49 GetDroneGroupsController().DeleteGroup(groupName) 50 51 52 class BaseDroneGroupHeader(Container): 53 default_state = uiconst.UI_NORMAL 54 default_height = 24 55 isDragObject = True 56 captionLabel = None 57 __notifyevents__ = ['OnExternalDragEnded'] 58 59 def __init__(self, reserved_space_right = 0, **kwargs): 60 self._reserved_space_right = reserved_space_right 61 self.buttonCont = None 62 super(BaseDroneGroupHeader, self).__init__(**kwargs) 63 64 def ApplyAttributes(self, attributes): 65 super(BaseDroneGroupHeader, self).ApplyAttributes(attributes) 66 sm.RegisterNotify(self) 67 self.isExpanded = True 68 self.on_open_changed = Signal('on_open_changed') 69 labelCont = self.ConstructLabelCont() 70 self.icon = Sprite(parent=labelCont, align=uiconst.CENTERLEFT, state=uiconst.UI_DISABLED, pos=(4, 0, 16, 16), outputMode=uiconst.OUTPUT_COLOR_AND_GLOW, glowBrightness=0.0) 71 self.label = eveLabel.EveLabelMedium(parent=labelCont, align=uiconst.CENTERLEFT, color=TextColor.HIGHLIGHT, left=24) 72 self.ConstructButtonCont() 73 self.ConstructButtons() 74 self.underlay = Fill(bgParent=self, color=(1, 1, 1, 0.05), outputMode=uiconst.OUTPUT_COLOR_AND_GLOW, glowBrightness=0.0) 75 self.blinkUnderlay = Fill(bgParent=self, color=(1, 1, 1, 0.0), outputMode=uiconst.OUTPUT_COLOR_AND_GLOW, glowBrightness=0.0) 76 self.UpdateIcon() 77 self.UpdateLabelText() 78 79 def ConstructLabelCont(self): 80 labelCont = ContainerAutoSize(parent=self, align=uiconst.TOLEFT) 81 return labelCont 82 83 @property 84 def reserved_space_right(self): 85 return self._reserved_space_right 86 87 @reserved_space_right.setter 88 def reserved_space_right(self, value): 89 if value != self._reserved_space_right: 90 self._reserved_space_right = value 91 self._update_button_cont_padding() 92 93 def _update_button_cont_padding(self): 94 if self.buttonCont is not None: 95 self.buttonCont.padding = self._get_button_cont_padding() 96 97 def _get_button_cont_padding(self): 98 return (0, 99 0, 100 max(self._reserved_space_right, 4), 101 0) 102 103 def OnExternalDragEnded(self, *args): 104 self.HideDragHighlight() 105 106 def ShowDragHighlight(self, *args): 107 animations.MorphScalar(self.underlay, 'glowBrightness', self.underlay.glowBrightness, 1.0, duration=uiconst.TIME_ENTRY) 108 animations.FadeTo(self.underlay, self.underlay.opacity, 0.1, duration=uiconst.TIME_ENTRY) 109 uicore.uilib.RegisterForTriuiEvents(uiconst.UI_DRAGEXIT, self.OnGlobalDragExit) 110 111 def OnGlobalDragExit(self, obj, *args): 112 self.HideDragHighlight() 113 114 def HideDragHighlight(self, *args): 115 animations.MorphScalar(self.underlay, 'glowBrightness', self.underlay.glowBrightness, 0.0, duration=uiconst.TIME_EXIT) 116 animations.FadeTo(self.underlay, self.underlay.opacity, 0.05, duration=uiconst.TIME_EXIT) 117 118 def UpdateLabelText(self): 119 pass 120 121 def OnClick(self, *args): 122 super(BaseDroneGroupHeader, self).OnClick(*args) 123 if self.isExpanded: 124 self.SetAsCollapsed() 125 else: 126 self.SetAsExpanded() 127 128 def SetAsExpanded(self): 129 self._SetExpanedState(True) 130 131 def SetAsCollapsed(self): 132 self._SetExpanedState(False) 133 134 def _SetExpanedState(self, isExpanded): 135 self.isExpanded = isExpanded 136 self.UpdateIcon() 137 self.on_open_changed(self.isExpanded) 138 139 def UpdateIcon(self): 140 self.icon.texturePath = eveicon.caret_down if self.isExpanded else eveicon.caret_right 141 142 def ConstructButtonCont(self): 143 self.buttonCont = ContainerAutoSize(name='buttonCont', align=uiconst.TORIGHT, parent=self, state=uiconst.UI_HIDDEN, padding=self._get_button_cont_padding(), opacity=0.0) 144 145 def ConstructButtons(self): 146 pass 147 148 def OnMouseEnter(self, *args): 149 super(BaseDroneGroupHeader, self).OnMouseEnter(*args) 150 self.ShowButtonCont() 151 uicore.uilib.RegisterForTriuiEvents(uiconst.UI_MOUSEENTER, self.OnGlobalMouseEnter) 152 animations.MorphScalar(self.icon, 'glowBrightness', self.icon.glowBrightness, 1.0, duration=uiconst.TIME_ENTRY) 153 154 def OnMouseExit(self, *args): 155 super(BaseDroneGroupHeader, self).OnMouseExit(*args) 156 animations.MorphScalar(self.icon, 'glowBrightness', self.icon.glowBrightness, 0.0, duration=uiconst.TIME_EXIT) 157 158 def OnGlobalMouseEnter(self, obj, *args): 159 if obj and not (IsUnder(obj, self) or obj == self): 160 self.HideButtonCont() 161 return False 162 else: 163 return True 164 165 def ShowButtonCont(self): 166 self.buttonCont.Show() 167 animations.FadeTo(self.buttonCont, self.buttonCont.opacity, 1.0, duration=0.1) 168 169 def HideButtonCont(self): 170 animations.FadeTo(self.buttonCont, self.buttonCont.opacity, 0.0, duration=0.1, callback=self.buttonCont.Hide) 171 172 def GetDragData(self, *args): 173 pass 174 175 def GetDroneIDs(self): 176 pass 177 178 def OnMouseDown(self, *args): 179 uthread2.StartTasklet(self.ExpandRadialMenu) 180 181 def ExpandRadialMenu(self): 182 pass 183 184 def Blink(self): 185 duration = 0.6 186 animations.MorphScalar(self.blinkUnderlay, 'glowBrightness', 1.0, 0.0, duration=duration) 187 animations.MorphScalar(self.blinkUnderlay, 'opacity', 0.25, 0.0, duration=duration) 188 189 190 class DroneGroupHeaderInBay(BaseDroneGroupHeader): 191 192 def ApplyAttributes(self, attributes): 193 super(DroneGroupHeaderInBay, self).ApplyAttributes(attributes) 194 droneSignals.on_in_bay_entry_drag_enter.connect(self.ShowDragHighlight) 195 droneSignals.on_drones_dropped_to_bay.connect(self.Blink) 196 197 def ConstructLabelCont(self): 198 labelCont = ContainerAutoSize(parent=self, align=uiconst.TOLEFT, state=uiconst.UI_NORMAL) 199 labelCont.MakeDragObject() 200 labelCont.GetDragData = self.GetDragData 201 labelCont.GetMenu = self.GetMenu 202 labelCont.OnDropData = self.OnDropData 203 labelCont.OnDragEnter = self.OnDragEnter 204 labelCont.OnClick = self.OnClick 205 labelCont.OnMouseDown = self.OnMouseDown 206 return labelCont 207 208 def GetMenu(self): 209 m = MenuList([None]) 210 delMenuEntry = GetDeleteGroupMenuEntry() 211 if delMenuEntry: 212 m.append(delMenuEntry) 213 data = GetDroneGroupsController().GetDroneDataForMainGroup(DRONESTATE_INBAY) 214 if data: 215 m += GetMenuService().InvItemMenu(data).filter([MenuLabel('UI/Inventory/ItemActions/BuyThisType'), 216 MenuLabel('UI/Inventory/ItemActions/AddTypeToMarketQuickbar'), 217 MenuLabel('UI/Inventory/ItemActions/ViewTypesMarketDetails'), 218 MenuLabel('UI/Inventory/ItemActions/FindInContracts')]) 219 return m 220 221 def ConstructButtons(self): 222 button = ButtonIcon(parent=self.buttonCont, align=uiconst.TORIGHT, width=BUTTON_SIZE, iconSize=16, texturePath=eveicon.launch_drones, func=self.OnLaunchDronesButton, hint=GetByLabel('UI/Drones/LaunchDrones'), blendMode=trinity.TR2_SBM_ADD) 223 button.LoadTooltipPanel = self.LoadLaunchDronesTooltipPanel 224 225 def LoadLaunchDronesTooltipPanel(self, tooltipPanel, *args): 226 if not GetDroneGroupsController().GetFavoriteGroupDroneIDsInBayOrSpace(): 227 tooltipPanel.LoadGeneric2ColumnTemplate() 228 shortcut = uicore.cmd.GetShortcutStringByFuncName('CmdLaunchFavoriteDrones') 229 tooltipPanel.AddLabelShortcut(GetByLabel('UI/Drones/LaunchDrones'), shortcut) 230 231 def OnLaunchDronesButton(self, *args): 232 droneInvItems = [ item for item in invControllers.ShipDroneBay().GetItems() if item.itemID in self.GetDroneIDs() ] 233 if droneInvItems: 234 eveMisc.LaunchFromShip(droneInvItems) 235 236 def GetDroneIDs(self): 237 return GetDroneIDsInBay() 238 239 def UpdateLabelText(self): 240 self.label.text = '%s (%s)' % (GetByLabel('UI/Inflight/Drone/DronesInBay'), GetNumberOfDronesInBay()) 241 242 def ExpandRadialMenu(self): 243 droneData = GetDroneGroupsController().GetDroneDataForMainGroup(DRONESTATE_INBAY) 244 if droneData: 245 ExpandRadialMenuForInBayGroup(self, self.label.text, droneData) 246 247 def GetDragData(self, *args): 248 return AllDronesInBayDragData() 249 250 def OnDragEnter(self, dragSource, dragData): 251 if HasInSpaceDroneIDs(dragData): 252 droneSignals.on_in_bay_entry_drag_enter() 253 254 def OnDropData(self, dragSource, dragData): 255 droneIDs = dronesDragData.GetInSpaceDroneIDs(dragData) 256 if droneIDs: 257 droneFunctions.ReturnToDroneBay(droneIDs) 258 droneSignals.on_drones_dropped_to_bay() 259 260 261 class DroneGroupHeaderInSpace(BaseDroneGroupHeader): 262 263 def ApplyAttributes(self, attributes): 264 super(DroneGroupHeaderInSpace, self).ApplyAttributes(attributes) 265 droneSignals.on_in_space_entry_drag_enter.connect(self.ShowDragHighlight) 266 droneSignals.on_drones_dropped_in_space.connect(self.Blink) 267 268 def ConstructButtons(self): 269 button = ButtonIcon(parent=self.buttonCont, align=uiconst.TORIGHT, width=BUTTON_SIZE, iconSize=16, texturePath=eveicon.recall_drones, func=self.OnRecallDronesButton, blendMode=trinity.TR2_SBM_ADD) 270 button.LoadTooltipPanel = lambda tooltipPanel, *args: LoadShortcutTooltip(tooltipPanel, commandName='CmdDronesReturnToBay') 271 ButtonSeperatorLine(parent=self.buttonCont, align=uiconst.TORIGHT) 272 button = ButtonIcon(parent=self.buttonCont, align=uiconst.TORIGHT, width=BUTTON_SIZE, iconSize=16, texturePath=eveicon.return_and_orbit, func=self.OnReturnAndOrbitButton, blendMode=trinity.TR2_SBM_ADD, padRight=4) 273 button.LoadTooltipPanel = lambda tooltipPanel, *args: LoadShortcutTooltip(tooltipPanel, commandName='CmdDronesReturnAndOrbit') 274 button = ButtonIcon(parent=self.buttonCont, align=uiconst.TORIGHT, width=BUTTON_SIZE, iconSize=16, texturePath=eveicon.engage_target, func=self.OnEngageButton, blendMode=trinity.TR2_SBM_ADD) 275 button.LoadTooltipPanel = lambda tooltipPanel, *args: LoadShortcutTooltip(tooltipPanel, commandName='CmdDronesEngage') 276 settingsButton = ButtonIcon(menuAlign=uiconst.TOPRIGHT, parent=self.buttonCont, align=uiconst.TORIGHT, width=BUTTON_SIZE, texturePath=eveicon.settings, padRight=4, blendMode=trinity.TR2_SBM_ADD, uniqueUiName=pConst.UNIQUE_NAME_DRONE_SETTINGS) 277 settingsButton.expandOnLeft = True 278 settingsButton.GetMenu = self.GetSettingsMenu 279 280 def GetSettingsMenu(self, *args): 281 m = MenuData() 282 m.AddCheckbox(text=GetByLabel('UI/Drones/AutoAttack'), setting=drones_aggressive_setting, hint=GetByLabel('UI/Drones/AutoAttackHint')) 283 m.AddCheckbox(text=GetByLabel('UI/Drones/AttackModeFocusFire'), setting=drones_focus_fire_setting, hint=GetByLabel('UI/Drones/AttackModeFocusFireHint')) 284 return m 285 286 def GetMenu(self): 287 m = MenuList([None]) 288 delMenuEntry = GetDeleteGroupMenuEntry() 289 if delMenuEntry: 290 m.append(delMenuEntry) 291 data = GetDroneGroupsController().GetDroneDataForMainGroup(DRONESTATE_INSPACE) 292 if data: 293 m += GetMenuService().DroneMenu(data) 294 return m 295 296 def OnReturnAndOrbitButton(self, *args): 297 droneFunctions.ReturnAndOrbit(self.GetDroneIDs()) 298 299 def OnEngageButton(self, *args): 300 droneFunctions.PerformPrimaryAction(self.GetDroneItemAndTypeIDs()) 301 302 def OnRecallDronesButton(self, *args): 303 droneFunctions.ReturnToDroneBay(self.GetDroneIDs()) 304 305 def GetDroneIDs(self): 306 return GetDroneIDsInSpace() 307 308 def GetDroneItemAndTypeIDs(self): 309 return [ (drone.droneID, drone.typeID) for drone in GetDronesInLocalSpace() ] 310 311 def UpdateLabelText(self): 312 self.label.text = '%s (%s/%s)' % (GetByLabel('UI/Inflight/Drone/DronesInSpace'), len(self.GetDroneIDs()), GetMaxDronesInSpace()) 313 314 def ExpandRadialMenu(self): 315 droneData = GetDroneGroupsController().GetDroneDataForMainGroup(DRONESTATE_INSPACE) 316 if droneData: 317 ExpandRadialMenuForInSpaceGroup(self, self.label.text, droneData) 318 319 def GetDragData(self, *args): 320 return AllDronesInSpaceDragData() 321 322 def OnDragEnter(self, dragSource, dragData): 323 if HasInBayDroneIDs(dragData): 324 droneSignals.on_in_space_entry_drag_enter() 325 326 def OnDropData(self, dragSource, dragData): 327 droneIDs = dronesDragData.GetInBayDroneIDs(dragData) 328 if droneIDs: 329 droneFunctions.LaunchDrones(droneIDs) 330 droneSignals.on_drones_dropped_in_space() 331 332 def ConstructTooltipPanel(self): 333 return DroneGroupHeaderInSpaceTooltipPanel() 334 335 336 class DroneGroupHeaderInSpaceTooltipPanel(TooltipPanel): 337 default_margin = 16 338 default_pointerDirection = uiconst.POINT_RIGHT_2 339 340 def ApplyAttributes(self, attributes): 341 super(DroneGroupHeaderInSpaceTooltipPanel, self).ApplyAttributes(attributes) 342 drones = {drone.droneID:1 for drone in GetDronesInLocalSpace()} 343 text = GetByLabel('UI/Inflight/Drone/MaxDronesInSpace', numDrones=len(drones), numMax=GetMaxDronesInSpace()) 344 self.AddLabelMedium(text=text, colSpan=2, wrapWidth=250) 345 self.AddRow(rowClass=SkillEntry, typeID=appConst.typeDrones, showLevel=False, cellPadding=(0, 0)) 346 self.AddSpacer(height=8) 347 used, total = GetDroneBandwidth(session.shipid, sm.GetService('clientDogmaIM').GetDogmaLocation(), drones) 348 texturePath = GetIconFile(attributeFormat.GetIconID(appConst.attributeDroneBandwidth)) 349 attributeType = get_attribute(appConst.attributeDroneBandwidth) 350 totalText = attributeFormat.GetFormatAndValue(attributeType, total) 351 text = '<color=%s>%s</color> %s/%s' % (eveColor.LED_GREY_HEX, 352 GetByLabel('UI/Inflight/Drone/BandwidthUsed'), 353 int(used), 354 totalText) 355 self.AddIconLabel(texturePath, text)