coloniesPanel.py (9238B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\planet\planetsWindow\coloniesPanel.py 2 import uthread 3 import eve.common.lib.appConst as appConst 4 from carbonui import uiconst 5 from carbonui.control.scrollContainer import ScrollContainer 6 from carbonui.primitives.container import Container 7 from carbonui.button.group import ButtonGroup 8 from eve.client.script.ui.control.eveLoadingWheel import LoadingWheel 9 from eve.client.script.ui.services.menuSvcExtras import movementFunctions 10 from eve.client.script.ui.shared.planet.planetsWindow.colonyEntry import ColonyEntry, ColonyEntryCompact, ColonyEntryEmpty, ColonyEntryEmptyCompact 11 from eve.client.script.ui.view.viewStateConst import ViewState 12 from eve.common.lib import appConst 13 from localization import GetByLabel 14 import blue 15 MAX_NUM_COLONIES = 6 16 ACTION_SETDEST = 1 17 ACTION_WARPTO = 2 18 ACTION_APPROACH = 3 19 20 class ColoniesPanel(Container): 21 default_name = 'ColoniesPanel' 22 __notifyevents__ = ['OnPlanetCommandCenterDeployedOrRemoved', 23 'OnPlanetPinsChanged', 24 'OnColonyPinCountUpdated', 25 'OnSessionChanged', 26 'OnClientEvent_WarpFinished', 27 'OnViewStateChanged'] 28 29 def ApplyAttributes(self, attributes): 30 Container.ApplyAttributes(self, attributes) 31 sm.RegisterNotify(self) 32 self.isCompact = attributes.isCompact 33 self.entries = [] 34 self.scrollCont = ScrollContainer(name='scrollCont', parent=self) 35 self.btnGroup = ButtonGroup(parent=self, align=uiconst.TOBOTTOM, idx=0, padTop=8) 36 self.viewBtn = self.btnGroup.AddButton(GetByLabel('UI/Common/View'), self.ViewPlanet, hint=GetByLabel('UI/PI/Common/ViewInPlanetMode')) 37 self.actionBtn = self.btnGroup.AddButton(GetByLabel('UI/Commands/WarpTo'), self.OnActionBtnClicked) 38 self.accessBtn = self.btnGroup.AddButton(GetByLabel('UI/PI/Common/Access'), self.OnAccessBtnClicked, hint=GetByLabel('UI/PI/Common/AccessCustomOffice')) 39 self.loadingWheel = LoadingWheel(parent=self, align=uiconst.CENTER, state=uiconst.UI_HIDDEN) 40 uthread.new(self.UpdateThread) 41 42 def UpdateThread(self): 43 while not self.destroyed: 44 for entry in self.entries: 45 entry.Update() 46 47 blue.pyos.synchro.SleepWallclock(1000) 48 49 def OnTabSelect(self): 50 self.LoadPlanetScroll() 51 52 def LoadPlanetScroll(self): 53 scrollPos = self.scrollCont.GetPositionVertical() 54 self.scrollCont.Flush() 55 self.loadingWheel.Show() 56 self.entries = [] 57 planetSvc = sm.GetService('planetSvc') 58 planetsData = planetSvc.GetMyPlanetsData() 59 self.ConstructEntries(planetsData) 60 self.ConstructEmptyEntries(planetsData) 61 self.viewBtn.Disable() 62 self.actionBtn.Disable() 63 self.accessBtn.Disable() 64 self.loadingWheel.Hide() 65 if scrollPos: 66 self.scrollCont.ScrollToVertical(scrollPos) 67 68 def ConstructEmptyEntries(self, planetsData): 69 numColonies = len(planetsData) 70 skillLvl = sm.GetService('skills').GetMyLevel(appConst.typeInterplanetaryConsolidation) or 0 71 maxColonies = skillLvl + 1 72 if numColonies < MAX_NUM_COLONIES: 73 for i in xrange(numColonies, MAX_NUM_COLONIES): 74 cls = ColonyEntryEmptyCompact if self.isCompact else ColonyEntryEmpty 75 entry = cls(parent=self.scrollCont, align=uiconst.TOTOP, padBottom=2, slotIndex=i, slotsTotal=maxColonies) 76 self.entries.append(entry) 77 78 def ConstructEntries(self, planetsData): 79 for planetData in planetsData: 80 cls = ColonyEntryCompact if self.isCompact else ColonyEntry 81 entry = cls(parent=self.scrollCont, align=uiconst.TOTOP, planetData=planetData, padBottom=2, onClickCallback=self.OnEntryClicked) 82 self.entries.append(entry) 83 84 def OnEntryClicked(self, entryClicked): 85 for entry in self.entries: 86 if entry == entryClicked: 87 entry.SetSelected() 88 self.viewBtn.Enable() 89 elif entry.isSelected: 90 entry.SetDeselected() 91 92 self.UpdateButtons() 93 94 def ViewPlanet(self, *args): 95 entry = self.GetSelectedEntry() 96 if entry: 97 sm.GetService('viewState').ActivateView('planet', planetID=entry.planetData.planetID) 98 99 def UpdateViewPlanetBtn(self): 100 entry = self.GetSelectedEntry() 101 if not entry: 102 self.viewBtn.Disable() 103 return 104 viewState = sm.GetService('viewState').GetView(ViewState.Planet) 105 if viewState.IsActive(): 106 if viewState.lastPlanetID == entry.GetPlanetID(): 107 self.viewBtn.Disable() 108 return 109 self.viewBtn.Enable() 110 111 def UpdateAccessButton(self): 112 entry = self.GetSelectedEntry() 113 if entry: 114 customsOfficeID = self.GetCustomsOfficeID(entry.planetData.planetID) 115 if customsOfficeID is None: 116 self.accessBtn.Disable() 117 return 118 solarSystemID = entry.planetData.solarSystemID 119 if self.IsWarpToPossible(solarSystemID): 120 self.accessBtn.Enable() 121 return 122 self.accessBtn.Disable() 123 124 def UpdateButtons(self): 125 self.UpdateViewPlanetBtn() 126 self.UpdateActionButton() 127 self.UpdateAccessButton() 128 129 def UpdateActionButton(self): 130 entry = self.GetSelectedEntry() 131 if entry: 132 actionID = self._GetActionButtonActionID(entry) 133 if actionID: 134 self.actionBtn.Enable() 135 else: 136 self.actionBtn.Disable() 137 self.UpdateActionBtnLabel(actionID) 138 else: 139 self.actionBtn.Disable() 140 141 def _GetActionButtonActionID(self, entryClicked): 142 solarSystemID = entryClicked.planetData.solarSystemID 143 if self.IsWarpToPossible(solarSystemID): 144 customsOfficeID = self.GetCustomsOfficeID(entryClicked.planetData.planetID) 145 ball = sm.GetService('michelle').GetBall(customsOfficeID) 146 if ball and ball.surfaceDist < appConst.minWarpDistance: 147 return ACTION_APPROACH 148 else: 149 return ACTION_WARPTO 150 elif solarSystemID != session.solarsystemid2: 151 return ACTION_SETDEST 152 153 def UpdateActionBtnLabel(self, actionID): 154 if actionID == ACTION_APPROACH: 155 self.actionBtn.SetLabel(GetByLabel('UI/Inflight/ApproachObject')) 156 self.actionBtn.SetHint(GetByLabel('UI/PI/Common/ApproachHint')) 157 elif actionID == ACTION_WARPTO: 158 self.actionBtn.SetLabel(GetByLabel('UI/Commands/WarpTo')) 159 self.actionBtn.SetHint(GetByLabel('UI/PI/Common/WarpToPlanetHint')) 160 else: 161 self.actionBtn.SetLabel(GetByLabel('UI/Inflight/SetDestination')) 162 self.actionBtn.SetHint('') 163 self.btnGroup.ResetLayout() 164 165 def IsWarpToPossible(self, solarSystemID): 166 return session.solarsystemid2 and solarSystemID == session.solarsystemid and not session.structureid 167 168 def OnActionBtnClicked(self, *args): 169 entry = self.GetSelectedEntry() 170 actionID = self._GetActionButtonActionID(entry) 171 if actionID == ACTION_WARPTO: 172 self.WarpToPlanet(entry) 173 elif actionID == ACTION_APPROACH: 174 self.ApproachPlanet(entry) 175 else: 176 self.SetDestinationToSystem(entry) 177 178 def OnAccessBtnClicked(self, *args): 179 entry = self.GetSelectedEntry() 180 self.AccessCustomsOffice(entry) 181 182 def AccessCustomsOffice(self, entry): 183 customsOfficeID = self.GetCustomsOfficeID(entry.planetData.planetID) 184 sm.GetService('planetUI').OpenPlanetCustomsOfficeImportWindow(customsOfficeID) 185 186 def SetDestinationToSystem(self, entry): 187 sm.StartService('starmap').SetWaypoint(entry.planetData.solarSystemID, clearOtherWaypoints=True) 188 189 def WarpToPlanet(self, entry): 190 itemID = self._GetItemIDToNavigateTo(entry) 191 movementFunctions.WarpToItem(itemID) 192 193 def ApproachPlanet(self, entry): 194 itemID = self._GetItemIDToNavigateTo(entry) 195 movementFunctions.Approach(itemID) 196 197 def _GetItemIDToNavigateTo(self, entry): 198 planetID = entry.planetData.planetID 199 customsOfficeID = self.GetCustomsOfficeID(planetID) 200 itemID = customsOfficeID or planetID 201 return itemID 202 203 def GetCustomsOfficeID(self, planetID): 204 customsOfficeIDs = sm.GetService('planetInfo').GetFunctionalCustomOfficeOrbitalsForPlanet(planetID) 205 if customsOfficeIDs: 206 return list(customsOfficeIDs)[0] 207 208 def GetSelectedEntry(self): 209 for entry in self.entries: 210 if entry.isSelected: 211 return entry 212 213 def OnPlanetCommandCenterDeployedOrRemoved(self): 214 self.LoadPlanetScroll() 215 216 def OnPlanetPinsChanged(self, planetID): 217 self.LoadPlanetScroll() 218 219 def OnColonyPinCountUpdated(self, planetID): 220 self.LoadPlanetScroll() 221 222 def OnSessionChanged(self, isRemote, sess, change): 223 self.UpdateButtons() 224 225 def OnClientEvent_WarpFinished(self, *args): 226 self.UpdateButtons() 227 228 def OnViewStateChanged(self, oldView, newView): 229 self.UpdateButtons()