fleetFormations.py (11600B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\fleet\fleetFormations.py 2 import localization 3 from carbonui import uiconst 4 from carbonui.control.combo import Combo 5 from carbonui.control.comboEntries import ComboEntry 6 from carbonui.window.widget import WidgetWindow 7 from carbonui.primitives.container import Container 8 from carbonui.primitives.containerAutoSize import ContainerAutoSize 9 from carbonui.primitives.layoutGrid import LayoutGrid 10 from carbonui.primitives.line import Line 11 from carbonui.control.buttonIcon import ButtonIcon 12 from carbonui.control.window import Window 13 from eve.client.script.ui.control.toggleButtonGroup import ToggleButtonGroup 14 from eve.client.script.ui.control.eveLabel import EveLabelMedium, EveLabelMediumBold 15 from eve.client.script.ui.control.toggleButtonGroupButton import ToggleButtonGroupButtonIcon 16 from eve.client.script.ui.shared.tooltip.skill import LoadSkillEntryTooltip 17 from evefleet import FLEET_FORMATIONS, FLEET_FORMATION_SETTING, FLEET_FORMATION_SIZE, FLEET_FORMATION_SIZE_SETTING, FLEET_FORMATION_SPACING, FLEET_FORMATION_SPACING_SETTING, FORMATION_DISTANCE_SKILL, FORMATION_ICONS, FORMATION_SKILL, FORMATION_USES_SIZE, FORMATION_USES_SPACING, LOCALIZED_FORMATIONS, LOCALIZED_FORMATION_DESCRIPTIONS 18 from evefleet.client.util import GetFormationSizeSelected, GetFormationSpacingSelected, GetFormationSelected 19 ORANGE = (1.0, 0.5, 0.0, 1) 20 SKILL_BOOK_ORANGE = (0.6, 0.3, 0.0, 1.0) 21 LIGHT_GREY = (1.0, 1.0, 1.0, 0.3) 22 COMBO_TOP = 20 23 24 class FleetFormationsPanel(Container): 25 __notifyevents__ = ['OnSkillsChanged'] 26 default_clipChildren = True 27 hasDetachBtn = True 28 29 def ApplyAttributes(self, attributes): 30 self.inited = False 31 super(FleetFormationsPanel, self).ApplyAttributes(attributes) 32 33 def LoadPanel(self): 34 if not self.inited: 35 self.ContructContainer() 36 37 def ContructContainer(self): 38 self.skillsSvc = sm.GetService('skills') 39 sm.RegisterNotify(self) 40 if self.hasDetachBtn: 41 self.ConstructDetachIcon() 42 self.ConstructFormationSettings() 43 self.inited = True 44 45 def ConstructDetachIcon(self): 46 iconCont = Container(name='iconCont', parent=self, height=20, align=uiconst.TOTOP, opacity=0.6) 47 ButtonIcon(name='openInWindow', parent=iconCont, iconSize=16, pos=(0, 0, 16, 16), texturePath='res:/UI/Texture/classes/DockPanel/floatButton.png', align=uiconst.CENTERRIGHT, func=self.DetachPanel, hint=localization.GetByLabel('UI/Inflight/Scanner/OpenInWindow')) 48 49 def ConstructFormationSettings(self): 50 selectedFormation = self.ConstructFormationButtonGroup() 51 self.ConstructFormationSize(selectedFormation) 52 self.ConstructFormationSpacing(selectedFormation) 53 54 def ConstructFormationButtonGroup(self): 55 skillLevel = self.GetSkillLevel(FORMATION_SKILL) 56 selectedFormationValue = GetFormationSelected(skillLevel) 57 self.formationSelection = FormationSelectionButtons(parent=self, align=uiconst.TOTOP, callback=self.OnFormationSelected, selected=selectedFormationValue, skillLevel=skillLevel, autoHeight=True) 58 return selectedFormationValue 59 60 def ConstructFormationSize(self, selectedFormation, parent = None): 61 skillLevel = self.GetSkillLevel(FORMATION_DISTANCE_SKILL) 62 comboOptions = [ self.GetDistanceOption(i, index, skillLevel) for index, i in enumerate(FLEET_FORMATION_SIZE) ] 63 parent = parent or self 64 self.formationSizeSelection = FleetFormationCombo(align=uiconst.TOTOP, top=COMBO_TOP, parent=parent, state=uiconst.UI_NORMAL, label=localization.GetByLabel('UI/Fleet/FleetFormations/SetFleetFormationSize'), options=comboOptions, callback=self.OnFormationSizeSelected, select=GetFormationSizeSelected(skillLevel), padTop=4) 65 self.formationSizeSelection.display = self.ShowHideSizeSelection(selectedFormation) 66 67 def ConstructFormationSpacing(self, selectedFormation, parent = None): 68 skillLevel = self.GetSkillLevel(FORMATION_DISTANCE_SKILL) 69 comboOptions = [ self.GetDistanceOption(i, index, skillLevel) for index, i in enumerate(FLEET_FORMATION_SPACING) ] 70 parent = parent or self 71 self.formationSpacingSelection = FleetFormationCombo(align=uiconst.TOTOP, top=COMBO_TOP, parent=parent, state=uiconst.UI_NORMAL, label=localization.GetByLabel('UI/Fleet/FleetFormations/SetFleetFormationSpacing'), options=comboOptions, callback=self.OnFormationSpacingSelected, select=GetFormationSpacingSelected(skillLevel), padTop=4) 72 self.formationSpacingSelection.display = self.ShowHideSpacingSelection(selectedFormation) 73 74 def OnFormationSelected(self, formationID, *args): 75 settings.char.ui.Set(FLEET_FORMATION_SETTING, formationID) 76 self.formationSizeSelection.display = self.ShowHideSizeSelection(formationID) 77 self.formationSpacingSelection.display = self.ShowHideSpacingSelection(formationID) 78 79 def OnFormationSizeSelected(self, comboBox, size, sizeValue): 80 settings.char.ui.Set(FLEET_FORMATION_SIZE_SETTING, sizeValue) 81 82 def OnFormationSpacingSelected(self, comboBox, spacing, spacingValue): 83 settings.char.ui.Set(FLEET_FORMATION_SPACING_SETTING, spacingValue) 84 85 def ShowHideSizeSelection(self, formation): 86 if formation not in FORMATION_USES_SIZE: 87 return False 88 else: 89 return True 90 91 def ShowHideSpacingSelection(self, formation): 92 if formation not in FORMATION_USES_SPACING: 93 return False 94 else: 95 return True 96 97 def GetDistanceOption(self, distance, index, skillLevel): 98 if index > skillLevel: 99 resPath = 'res:/ui/Texture/classes/Fitting/warningSkills.png' 100 else: 101 resPath = None 102 option = (self.FormatDistanceInKilometers(float(distance)), 103 distance, 104 None, 105 resPath) 106 return option 107 108 def GetSkillLevel(self, skillTypeID): 109 return self.skillsSvc.GetEffectiveLevel(skillTypeID) or 0 110 111 def OnSkillsChanged(self, skillInfoChange): 112 self.Flush() 113 if FORMATION_SKILL in skillInfoChange or FORMATION_DISTANCE_SKILL in skillInfoChange: 114 self.ConstructFormationSettings() 115 116 def _OnClose(self, *args): 117 sm.UnregisterNotify(self) 118 Container._OnClose(self) 119 120 def FormatDistanceInKilometers(self, dist): 121 dist = long(round(dist / 1000.0)) 122 distStr = localization.formatters.FormatNumeric(dist, useGrouping=True, decimalPlaces=None) 123 return localization.GetByLabel('/Carbon/UI/Common/FormatDistance/fmtDistInKiloMeters', distance=distStr) 124 125 def DetachPanel(self, *args): 126 settings.char.ui.Set('fleetFormationStandalone', True) 127 FleetFormationWnd.Open() 128 sm.ScatterEvent('OnFleetFormationWndChanged') 129 130 131 class FleetFormationContForWnd(FleetFormationsPanel): 132 hasDetachBtn = False 133 134 def ApplyAttributes(self, attributes): 135 super(FleetFormationContForWnd, self).ApplyAttributes(attributes) 136 self.ContructContainer() 137 138 def ConstructFormationSettings(self): 139 self.ConstructFormationButtonGroup() 140 skillLevel = self.GetSkillLevel(FORMATION_SKILL) 141 selectedFormation = GetFormationSelected(skillLevel) 142 spacingParent = ContainerAutoSize(name='spacingParent', parent=self, align=uiconst.TOTOP) 143 self.ConstructFormationSpacing(selectedFormation, parent=spacingParent) 144 sizeParent = ContainerAutoSize(name='sizeParent', parent=self, align=uiconst.TOTOP) 145 self.ConstructFormationSize(selectedFormation, parent=sizeParent) 146 147 148 class FleetFormationComboEntry(ComboEntry): 149 150 def LoadTooltipPanel(self, tooltipPanel, *args): 151 if self.sr.icon: 152 LoadSkillEntryTooltip(tooltipPanel, FORMATION_DISTANCE_SKILL, self.sr.node.idx) 153 154 def Load(self, node): 155 super(FleetFormationComboEntry, self).Load(node) 156 if self.sr.icon: 157 self.sr.icon.top = -1 158 self.sr.icon.color = SKILL_BOOK_ORANGE 159 self.sr.label.color = LIGHT_GREY 160 self.OnClick = None 161 162 163 class FleetFormationCombo(Combo): 164 165 def GetEntryClass(self): 166 return FleetFormationComboEntry 167 168 169 class FormationToggleButtonGroupButton(ToggleButtonGroupButtonIcon): 170 171 def ApplyAttributes(self, attributes): 172 super(FormationToggleButtonGroupButton, self).ApplyAttributes(attributes) 173 self.formationID = attributes.formationID 174 175 def LoadTooltipPanel(self, tooltipPanel, *args): 176 if self.isDisabled: 177 LoadSkillEntryTooltip(tooltipPanel, FORMATION_SKILL, skillLevel=self.formationID) 178 self.constructLine(tooltipPanel) 179 self.constructDescription(tooltipPanel) 180 181 def constructLine(self, tooltipPanel): 182 grid = LayoutGrid(columns=1) 183 grid.AddCell(cellPadding=(256, 8, 0, 0), colSpan=1) 184 grid.AddCell(Line(align=uiconst.TOTOP, height=1, opacity=0.5), cellPadding=(0, 0, 0, 0)) 185 tooltipPanel.AddCell(grid, cellPadding=(12, 0, 8, 8), colSpan=tooltipPanel.columns).SetOrder(idx=0) 186 187 def constructDescription(self, panel): 188 grid = LayoutGrid(columns=1) 189 grid.AddCell(cellPadding=(256, 8, 0, 0), colSpan=1) 190 grid.AddCell(EveLabelMediumBold(align=uiconst.TOPLEFT, text=localization.GetByLabel(LOCALIZED_FORMATIONS[self.formationID]), width=244), cellPadding=(0, 0, 0, 0)) 191 grid.AddCell(EveLabelMedium(align=uiconst.TOPLEFT, text=localization.GetByLabel(LOCALIZED_FORMATION_DESCRIPTIONS[self.formationID]), width=244), cellPadding=(0, 0, 0, 0)) 192 panel.AddCell(grid, cellPadding=(12, 0, 8, 8), colSpan=panel.columns).SetOrder(idx=0) 193 194 195 class FormationSelectionButtons(ToggleButtonGroup): 196 default_btnClass = FormationToggleButtonGroupButton 197 198 def ApplyAttributes(self, attributes): 199 super(FormationSelectionButtons, self).ApplyAttributes(attributes) 200 self.skillLevel = attributes.skillLevel 201 self.ReconstructButtons() 202 self.UpdateSelectedBtn(attributes.selected) 203 204 def ReconstructButtons(self): 205 self.ClearButtons() 206 for formationID in FLEET_FORMATIONS: 207 isDisabled = self.skillLevel < formationID 208 if isDisabled: 209 color = ORANGE 210 else: 211 color = None 212 self.AddButton(formationID, iconPath=FORMATION_ICONS[formationID], iconSize=26, isDisabled=isDisabled, colorSelected=color, formationID=formationID) 213 214 def UpdateSelectedBtn(self, formationID): 215 self.SetSelectedByID(formationID) 216 217 def OnFormationSelected(self, formationID, *args): 218 self.UpdateSelectedBtn(formationID) 219 self.callback(formationID) 220 221 222 class FleetFormationWnd(WidgetWindow): 223 default_height = 250 224 default_width = 350 225 default_minSize = (Window.default_width, 156) 226 default_windowID = 'FleetFormationWnd' 227 default_captionLabelPath = 'UI/Fleet/FleetFormations/FleetFormationMenu' 228 __notifyevents__ = ['OnSessionChanged'] 229 230 def ApplyAttributes(self, attributes): 231 super(FleetFormationWnd, self).ApplyAttributes(attributes) 232 FleetFormationContForWnd(parent=self.sr.main) 233 234 def OnSessionChanged(self, isRemote, sess, change): 235 if 'fleetid' in change and not session.fleetid: 236 self.Close() 237 238 def CloseByUser(self, *args): 239 settings.char.ui.Set('fleetFormationStandalone', False) 240 super(FleetFormationWnd, self).CloseByUser(*args) 241 242 def Close(self, setClosed = False, *args, **kwds): 243 super(FleetFormationWnd, self).Close(setClosed, *args, **kwds) 244 sm.ScatterEvent('OnFleetFormationWndChanged')