orbitalConfiguration.py (15407B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\inflight\orbitalConfiguration.py 2 import carbonui.control.checkbox 3 import carbonui.text.styles 4 import localization 5 import utillib 6 from carbonui import ButtonVariant, uiconst 7 from carbonui.button.group import ButtonGroup 8 from carbonui.control.button import Button 9 from carbonui.control.combo import Combo 10 from carbonui.control.singlelineedits.singleLineEditFloat import SingleLineEditFloat 11 from carbonui.control.window import Window 12 from carbonui.primitives.container import Container 13 from carbonui.primitives.containerAutoSize import ContainerAutoSize 14 from carbonui.primitives.layoutGrid import LayoutGrid 15 from carbonui.primitives.line import Line 16 from carbonui.util.effect import UIEffects 17 from eve.client.script.ui.shared.bookmarks.bookmarkContainerWindow import DropCombo 18 from eve.client.script.ui.shared.standings.levelSelector import StandingLevelSelector 19 from eve.client.script.ui.control import eveLabel 20 from eve.common.lib import appConst as const 21 from eve.common.script.net import eveMoniker 22 from eve.common.script.sys import idCheckers 23 from eve.common.script.sys.idCheckers import IsNPCCorporation, IsSkyhook 24 from mathext import clamp 25 26 class OrbitalConfigurationWindow(Window): 27 __guid__ = 'form.OrbitalConfigurationWindow' 28 default_windowID = 'configureOrbital' 29 default_clipChildren = 1 30 default_iconNum = 'res:/ui/Texture/WindowIcons/settings.png' 31 WIDTH_COLLAPSED = 270 32 WIDTH_EXPANDED = 445 33 HEIGHT = 190 34 HOVER_ALPHA = 1.0 35 NORMAL_ALPHA = 0.8 36 37 def ApplyAttributes(self, attributes): 38 Window.ApplyAttributes(self, attributes) 39 self.aclCombo = None 40 self._accessGroupOptions = None 41 orbitalItem = attributes.get('orbitalItem') 42 if not idCheckers.IsOrbital(orbitalItem.categoryID): 43 raise RuntimeError('Cannot open an orbital configuration window for a non-orbital') 44 self.locationID = orbitalItem.locationID 45 self.orbitalID = orbitalItem.itemID 46 self.typeID = orbitalItem.typeID 47 self.isSkyhook = IsSkyhook(self.typeID) 48 self.remoteOrbitalRegistry = eveMoniker.GetPlanetOrbitalRegistry(self.locationID) 49 self.orbitalData = self.remoteOrbitalRegistry.GetSettingsInfo(self.orbitalID) 50 self.selectedHour, self.taxRateValues, self.standingLevel, self.allowAlliance, self.allowStandings, self.selectedAcl = self.orbitalData 51 self.taxRates = [utillib.KeyVal(key='corporation'), 52 utillib.KeyVal(key='alliance'), 53 utillib.KeyVal(key='standingHorrible', standing=const.contactHorribleStanding), 54 utillib.KeyVal(key='standingBad', standing=const.contactBadStanding), 55 utillib.KeyVal(key='standingNeutral', standing=const.contactNeutralStanding), 56 utillib.KeyVal(key='standingGood', standing=const.contactGoodStanding), 57 utillib.KeyVal(key='standingHigh', standing=const.contactHighStanding)] 58 for taxRate in self.taxRates: 59 taxRate.value = getattr(self.taxRateValues, taxRate.key) 60 61 self.variance = sm.GetService('clientDogmaStaticSvc').GetTypeAttribute(self.typeID, const.attributeReinforcementVariance) 62 self.reinforceHours = [ ('%.2d:00 - %.2d:00' % ((x - self.variance / 3600) % 24, (x + self.variance / 3600) % 24), x) for x in xrange(0, 24) ] 63 caption = self._GetCaption() 64 self.effects = UIEffects() 65 self.scope = uiconst.SCOPE_INFLIGHT 66 self.SetMinSize([self.WIDTH_COLLAPSED, self.HEIGHT]) 67 self.SetCaption(caption) 68 self.MakeUnResizeable() 69 self.ConstructLayout() 70 self.Redraw() 71 72 def _GetCaption(self): 73 ballpark = sm.GetService('michelle').GetBallpark() 74 planetName = None 75 if ballpark is not None and self.orbitalID in ballpark.slimItems: 76 planetName = cfg.evelocations.Get(ballpark.slimItems[self.orbitalID].planetID).name 77 if planetName: 78 if self.isSkyhook: 79 caption = localization.GetByLabel('UI/OrbitalSkyhook/ConfigWnd/SkyhookNameWithPlanet', planetName=planetName) 80 else: 81 caption = localization.GetByLabel('UI/PI/Common/PlanetaryCustomsOfficeName', planetName=planetName) 82 elif self.isSkyhook: 83 caption = localization.GetByLabel('UI/OrbitalSkyhook/ConfigWnd/SkyhookConfig') 84 else: 85 caption = localization.GetByLabel('UI/DustLink/OrbitalConfiguration') 86 return caption 87 88 def ConstructLayout(self): 89 self.main_container = ContainerAutoSize(parent=self.content, align=uiconst.TOPLEFT, callback=self._on_main_cont_size_changed, only_use_callback_when_size_changes=True) 90 layout_container = LayoutGrid(parent=self.main_container, columns=2, align=uiconst.TOPLEFT, cellSpacing=(8, 8)) 91 if self.isSkyhook: 92 self._skyhook_container(layout_container) 93 self._left_container(layout_container) 94 self._right_container(layout_container) 95 self._footer_container(layout_container) 96 97 def _on_main_cont_size_changed(self): 98 width, height = self.GetWindowSizeForContentSize(height=self.main_container.height, width=self.main_container.width) 99 self.SetMinSize(size=(width, height), refresh=True) 100 101 def _skyhook_container(self, parent): 102 header = carbonui.text.styles.TextHeader(text=localization.GetByLabel('UI/OrbitalSkyhook/ConfigWnd/SkyhookSettings'), align=uiconst.TOPLEFT, top=8) 103 parent.AddCell(cellObject=header, colSpan=2) 104 self.AddReinforceDropDown(parent) 105 label = eveLabel.EveLabelSmall(text=localization.GetByLabel('UI/OrbitalSkyhook/ConfigWnd/TakeAccess'), parent=parent, align=uiconst.CENTERLEFT) 106 self.aclCombo = DropCombo(parent=parent, name='aclCombo', align=uiconst.TOPLEFT, options=self.accessGroupOptions, select=self.selectedAcl, dropped=self.OnDroppedGroup, emptyTooltip=localization.GetByLabel('UI/OrbitalSkyhook/ConfigWnd/TakeAccessComboHint')) 107 comboWidth = clamp(max(self.aclCombo.width, self.reinforceHourCombo.width), 140, 200) 108 self.aclCombo.width = self.reinforceHourCombo.width = comboWidth 109 110 def _left_container(self, parent): 111 if self.isSkyhook: 112 parent.AddCell(cellObject=Line(top=8, padBottom=8), colSpan=2) 113 header = carbonui.text.styles.TextHeader(text=localization.GetByLabel('UI/OrbitalSkyhook/ConfigWnd/CustomsOfficeSettings'), align=uiconst.TOPLEFT) 114 parent.AddCell(header, colSpan=3) 115 self.left_container = LayoutGrid(name='left_container', parent=parent, align=uiconst.TOPLEFT, columns=3, cellSpacing=(8, 8), padRight=32) 116 if not self.isSkyhook: 117 self.AddReinforceDropDown(self.left_container) 118 self.corporationLabel = eveLabel.EveLabelSmall(text=localization.GetByLabel('UI/PI/OrbitalConfigurationWindow/CorporationTax'), parent=self.left_container, state=uiconst.UI_NORMAL, align=uiconst.CENTERLEFT, hint=localization.GetByLabel('UI/PI/OrbitalConfigurationWindow/StandingTooltip', typeID=self.typeID)) 119 taxRateValue = self.taxRates[0].value 120 taxRateInput = SingleLineEditFloat(parent=self.left_container, name='taxRateEdit', align=uiconst.TOPLEFT, setvalue='' if taxRateValue is None else str(100 * taxRateValue), idx=0, width=90, maxValue=100) 121 eveLabel.EveLabelMedium(align=uiconst.CENTERLEFT, text='%', parent=self.left_container) 122 self.taxRates[0].input = taxRateInput 123 self.allianceCheckbox = carbonui.control.checkbox.Checkbox(parent=self.left_container, align=uiconst.CENTERLEFT, text=localization.GetByLabel('UI/PI/OrbitalConfigurationWindow/AllianceTax'), checked=self.allowAlliance, callback=self.Redraw) 124 taxRateValue = self.taxRates[1].value 125 taxRateInput = SingleLineEditFloat(parent=self.left_container, name='taxRateEdit', align=uiconst.TOPLEFT, setvalue='' if taxRateValue is None else str(100 * taxRateValue), idx=0, width=90, maxValue=100) 126 eveLabel.EveLabelMedium(align=uiconst.CENTERLEFT, text='%', parent=self.left_container) 127 self.taxRates[1].input = taxRateInput 128 self.standingsCheckbox = carbonui.control.checkbox.Checkbox(text=localization.GetByLabel('UI/PI/OrbitalConfigurationWindow/Standing'), checked=self.allowStandings, callback=self.Redraw) 129 self.left_container.AddCell(self.standingsCheckbox, colSpan=3) 130 131 def AddReinforceDropDown(self, parent): 132 self.reinforcementLabel = eveLabel.EveLabelSmall(text=localization.GetByLabel('UI/PI/OrbitalConfigurationWindow/ReinforcementExit'), align=uiconst.CENTERLEFT, parent=parent, state=uiconst.UI_NORMAL, hint=localization.GetByLabel('UI/PI/OrbitalConfigurationWindow/ReinforcementExitTooltip', typeID=self.typeID)) 133 self.reinforceHourCombo = Combo(name='orbitalReinforceHourCombo', align=uiconst.TOPLEFT, select=self.selectedHour, options=self.reinforceHours, nothingSelectedText=localization.GetByLabel('UI/OrbitalSkyhook/ConfigWnd/NothingSelected')) 134 parent.AddCell(self.reinforceHourCombo, colSpan=2) 135 136 def _right_container(self, parent): 137 self.standingsContainer = ContainerAutoSize(name='standingsContainer', parent=parent, align=uiconst.TOPLEFT, left=24) 138 self.standingLevelSelector = StandingLevelSelector(name='standingLevelSelector', parent=self.standingsContainer, align=uiconst.TOPLEFT, level=self.standingLevel, vertical=True, callback=self.Redraw, width=90, height=100 + 4 * (Combo.default_height - 12), top=(Combo.default_height - 20) / 2, iconPadding=Combo.default_height - 12) 139 for i, taxRate in enumerate(self.taxRates[2:]): 140 self.LayoutTaxInput(taxRate, self.standingsContainer, 28, i * (Combo.default_height + 8)) 141 142 def _footer_container(self, parent): 143 parent.AddCell(ButtonGroup(align=uiconst.TOTOP, top=16, buttons=[Button(label=localization.GetByLabel('UI/Common/Submit'), func=self.Submit, variant=ButtonVariant.PRIMARY), Button(label=localization.GetByLabel('UI/Common/Cancel'), func=self.Cancel)]), colSpan=2) 144 145 def LayoutTaxInput(self, taxRate, parent, left = 0, top = 0): 146 taxRateValue = taxRate.value 147 taxRateInput = SingleLineEditFloat(parent=parent, name='taxRateEdit', align=uiconst.TOPLEFT, setvalue='' if taxRateValue is None else str(100 * taxRateValue), width=90, left=left, top=top, idx=0, maxValue=100) 148 eveLabel.EveLabelMedium(align=uiconst.TOPLEFT, text='%', parent=parent, left=left + 97, top=top + taxRateInput.default_height / 2 - 8) 149 taxRate.input = taxRateInput 150 151 def OnMouseEnterInteractable(self, obj, *args): 152 obj.SetOpacity(self.HOVER_ALPHA) 153 154 def OnMouseExitInteractable(self, obj, *args): 155 obj.SetOpacity(self.NORMAL_ALPHA) 156 157 def Redraw(self, *args): 158 level = self.standingLevelSelector.GetValue() 159 taxRateVisible = True 160 for taxRate in self.taxRates[2:]: 161 if taxRate.standing == level: 162 taxRateVisible = False 163 self.SetTaxRateVisible(taxRate.input, taxRateVisible) 164 165 self.SetTaxRateVisible(self.taxRates[1].input, not self.allianceCheckbox.GetValue()) 166 if self.standingsCheckbox.GetValue(): 167 self.standingsContainer.EnableAutoSize() 168 else: 169 self.standingsContainer.DisableAutoSize() 170 self.standingsContainer.width = 0 171 172 def ResizeWindowWidth(self, width): 173 self.effects.MorphUIMassSpringDamper(self, 'width', width, newthread=True, float=0, dampRatio=0.99, frequency=15.0) 174 175 def HideElement(self, element): 176 self.effects.MorphUIMassSpringDamper(element, 'opacity', 0, dampRatio=0.99, frequency=30.0) 177 178 def ShowElement(self, element): 179 self.effects.MorphUIMassSpringDamper(element, 'opacity', 1, dampRatio=0.99, frequency=30.0) 180 181 def SetTaxRateVisible(self, field, visible): 182 if visible and field.state == uiconst.UI_NORMAL: 183 field.hiddenValue = field.GetValue() 184 field.SetText(localization.GetByLabel('UI/PI/Common/CustomsOfficeAccessDenied')) 185 field.SelectNone() 186 field.state = uiconst.UI_DISABLED 187 field.textLabel.SetAlpha(0.5) 188 self.effects.MorphUIMassSpringDamper(field, 'opacity', 0.5, dampRatio=0.99) 189 elif not visible and field.state == uiconst.UI_DISABLED: 190 field.SetValue(field.hiddenValue) 191 field.hiddenValue = None 192 field.state = uiconst.UI_NORMAL 193 field.textLabel.SetAlpha(1) 194 self.effects.MorphUIMassSpringDamper(field, 'opacity', 1, dampRatio=0.99) 195 196 def GetTaxRateValue(self, field): 197 value = getattr(field, 'hiddenValue', None) 198 if value is None: 199 value = field.GetValue() 200 return value / 100 201 202 def OnDroppedGroup(self, newGroupID): 203 for groupName, groupID in self.accessGroupOptions: 204 if groupID == newGroupID: 205 self.aclCombo.SetValue(newGroupID) 206 return 207 208 self.AddGroup(newGroupID) 209 self.aclCombo.entries = self.accessGroupOptions 210 self.aclCombo.SetValue(newGroupID) 211 212 def AddGroup(self, newGroupID): 213 if newGroupID: 214 newGroup = sm.GetService('structureControllers').GetAccessGroupController().GetGroupInfoFromID(newGroupID, fetchToServer=True) 215 groupDisplayName = cfg.eveowners.Get(newGroup.creatorID).name if IsNPCCorporation(newGroup.creatorID) else newGroup.name 216 self.accessGroupOptions.append((groupDisplayName, newGroupID)) 217 218 @property 219 def accessGroupOptions(self): 220 if self._accessGroupOptions is None: 221 self._accessGroupOptions = GetAccessGroupOptions() 222 return self._accessGroupOptions 223 224 def Submit(self, *args): 225 reinforcementHour = self.reinforceHourCombo.GetValue() 226 if reinforcementHour is None: 227 raise UserError('CustomNotify', {'notify': localization.GetByLabel('UI/OrbitalSkyhook/ConfigWnd/NoReinforcementTimeSelected')}) 228 reinforceValue = int(reinforcementHour) 229 standingValue = self.standingLevelSelector.GetValue() 230 allowAllianceValue = self.allianceCheckbox.GetValue() 231 allowStandingsValue = self.standingsCheckbox.GetValue() 232 taxRateValues = utillib.KeyVal({taxRate.key:self.GetTaxRateValue(taxRate.input) for taxRate in self.taxRates}) 233 aclGroupID = None 234 if self.aclCombo: 235 aclValue = self.aclCombo.GetValue() 236 aclGroupID = aclValue if aclValue > 0 else None 237 remoteOrbitalRegistry = eveMoniker.GetPlanetOrbitalRegistry(self.locationID) 238 remoteOrbitalRegistry.UpdateSettings(self.orbitalID, reinforceValue, taxRateValues, standingValue, allowAllianceValue, allowStandingsValue, aclGroupID) 239 self.CloseByUser() 240 241 def Cancel(self, *args): 242 self.CloseByUser() 243 244 245 def GetAccessGroupOptions(): 246 accessGroupsController = sm.GetService('structureControllers').GetAccessGroupController() 247 accessGroups = accessGroupsController.GetMyGroups() 248 accessGroupOptions = [] 249 for accessGroupID, accessGroup in accessGroups.iteritems(): 250 groupDisplayName = cfg.eveowners.Get(accessGroup.creatorID).name if IsNPCCorporation(accessGroup.creatorID) else accessGroup.name 251 accessGroupOptions.append((groupDisplayName, accessGroupID)) 252 253 accessGroupOptions.sort() 254 accessGroupOptions.insert(0, (localization.GetByLabel('UI/AclBookmarks/NoAccessList'), None)) 255 return accessGroupOptions