autopilotSettings.py (11795B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\autopilotSettings.py 2 import blue 3 import carbonui.const as uiconst 4 import evetypes 5 import localization 6 from carbonui.control.checkbox import Checkbox 7 from carbonui.primitives.container import Container 8 from carbonui.primitives.containerAutoSize import ContainerAutoSize 9 from carbonui.primitives.fill import Fill 10 from carbonui.util.various_unsorted import GetAttrs 11 from eve.client.script.ui.control import eveLabel, eveScroll 12 from carbonui.button.group import ButtonGroup 13 from eve.client.script.ui.control.entries.item import Item 14 from eve.client.script.ui.control.entries.universe import LocationTextEntry 15 from eve.client.script.ui.control.entries.util import GetFromClass 16 from carbonui.control.window import Window 17 from carbonui.control.tabGroup import TabGroup 18 19 class AutopilotSettings(Window): 20 __guid__ = 'form.AutopilotSettings' 21 default_windowID = 'AutopilotSettings' 22 default_width = 600 23 default_height = 450 24 default_minSize = (100, 140) 25 default_captionLabelPath = 'UI/Map/MapPallet/ManageAutopilotRoute' 26 __notifyevents__ = ['OnDestinationSet', 'OnAutopilotUpdated'] 27 28 def ApplyAttributes(self, attributes): 29 Window.ApplyAttributes(self, attributes) 30 self.isChangingOrder = False 31 self.loadedTab = None 32 self.waypointBtns = ButtonGroup(parent=self.sr.main, btns=[[localization.GetByLabel('UI/Map/MapPallet/btnOptimizeRoute'), 33 sm.GetService('autoPilot').OptimizeRoute, 34 (), 35 66]]) 36 waypointOptionCont = ContainerAutoSize(name='waypointopt', parent=self.sr.main, align=uiconst.TOBOTTOM, clipChildren=True, padding=(const.defaultPadding, 37 0, 38 const.defaultPadding, 39 0)) 40 self.sr.scroll2 = eveScroll.Scroll(parent=self.sr.main, padding=const.defaultPadding) 41 self.sr.scroll2.sr.id = 'autopilotSettings' 42 self.sr.scroll2.sr.content.OnDropData = self.MoveWaypoints 43 eveLabel.EveLabelMedium(text=localization.GetByLabel('UI/Map/MapPallet/lblChangeWaypointPriority'), parent=waypointOptionCont, padTop=4, align=uiconst.TOTOP) 44 checkbox = Checkbox(text=localization.GetByLabel('UI/Map/MapPallet/cbExpandWaypoints'), parent=waypointOptionCont, settingsKey='expandwaypoints', checked=settings.user.ui.Get('expandwaypoints', 1), callback=self.OnCheckboxWaypoints, align=uiconst.TOTOP, padTop=8) 45 autopilottabs = TabGroup(name='tabparent', parent=self.sr.main, idx=0) 46 autopilottabs.Startup([[localization.GetByLabel('UI/Map/MapPallet/tabWaypoints'), 47 self.sr.scroll2, 48 self, 49 'waypointconf', 50 waypointOptionCont], [localization.GetByLabel('UI/Map/MapPallet/tabMapAdvoidance'), 51 self.sr.scroll2, 52 self, 53 'avoidconf', 54 None]], 'autopilottabs', autoselecttab=1) 55 self.sr.autopilottabs = autopilottabs 56 57 def Load(self, key): 58 self.SetHint() 59 self.waypointBtns.display = False 60 if key == 'waypointconf': 61 self.waypointBtns.display = True 62 self.LoadWaypoints() 63 elif key == 'avoidconf': 64 self.LoadAvoidance() 65 if self.destroyed: 66 return 67 self.loadedTab = key 68 69 def MoveWaypoints(self, dragObj, entries, orderID = -1, *args): 70 self.ChangeWaypointSorting(orderID=orderID) 71 72 def ChangeWaypointSorting(self, orderID = -1, *args): 73 if self.isChangingOrder: 74 return 75 try: 76 self.isChangingOrder = True 77 sel = self.sr.scroll2.GetSelected() 78 starmapSvc = sm.GetService('starmap') 79 if not len(sel): 80 return 81 waypoints = starmapSvc.GetWaypoints() 82 waypointIndex = sel[0].orderID 83 if waypointIndex < 0: 84 return 85 if waypointIndex > len(waypoints): 86 return 87 waypoint = waypoints[waypointIndex] 88 del waypoints[waypointIndex] 89 if waypointIndex < orderID: 90 orderID -= 1 91 if orderID == -1: 92 orderID = len(waypoints) 93 waypoints.insert(orderID, waypoint) 94 starmapSvc.SetWaypoints(waypoints) 95 finally: 96 self.isChangingOrder = False 97 98 def OnCheckboxWaypoints(self, checkbox): 99 settings.user.ui.Set('expandwaypoints', checkbox.checked) 100 self.LoadWaypoints() 101 102 def LoadWaypoints(self, *args): 103 mapSvc = sm.GetService('map') 104 starmapSvc = sm.GetService('starmap') 105 structureDirectory = sm.GetService('structureDirectory') 106 waypoints = starmapSvc.GetWaypoints() 107 tmplst = [] 108 fromID = session.solarsystemid2 109 scrolllist = [] 110 actualID = 0 111 selectedItem = None 112 if waypoints and len(waypoints): 113 self.SetHint() 114 counter = 0 115 currentPlace = mapSvc.GetItem(session.solarsystemid2) 116 scrolllist.append(GetFromClass(Item, {'itemID': currentPlace.itemID, 117 'typeID': currentPlace.typeID, 118 'label': localization.GetByLabel('UI/Map/MapPallet/lblCurrentLocation', locationName=currentPlace.itemName), 119 'orderID': -1, 120 'actualID': 0})) 121 for waypointID in waypoints: 122 blue.pyos.BeNice() 123 actualID = actualID + 1 124 wasID, waypointName, waypointTypeID = self._GetWaypointInfo(waypointID, mapSvc, structureDirectory) 125 if wasID is None: 126 continue 127 description = localization.GetByLabel('UI/Map/MapPallet/lblActiveColorCategory', activeLabel=evetypes.GetName(waypointTypeID)) 128 while wasID: 129 wasID = mapSvc.GetParent(wasID) 130 if wasID: 131 item = mapSvc.GetItem(wasID) 132 if item is not None: 133 description = description + ' / ' + item.itemName 134 135 if settings.user.ui.Get('expandwaypoints', 1) == 1: 136 solarsystems = starmapSvc.GetRouteBetween(fromID, waypointID) 137 if len(solarsystems): 138 for solarsystemID in solarsystems[1:-1]: 139 actualID = actualID + 1 140 sunItem = mapSvc.GetItem(solarsystemID) 141 scrolllist.append(GetFromClass(AutoPilotItem, {'itemID': solarsystemID, 142 'typeID': sunItem.typeID, 143 'label': localization.GetByLabel('UI/Map/MapPallet/lblWaypointListEntryNoCount', itemName=sunItem.itemName), 144 'orderID': -1, 145 'actualID': actualID})) 146 147 lblTxt = localization.GetByLabel('UI/Map/MapPallet/lblWaypointListEntry', counter=counter + 1, itemName=waypointName, description=description) 148 scrolllist.append(GetFromClass(AutoPilotItem, {'itemID': waypointID, 149 'typeID': waypointTypeID, 150 'label': lblTxt, 151 'orderID': counter, 152 'actualID': actualID, 153 'canDrag': 1})) 154 if self.sr.Get('selectedWaypoint', None) is not None and self.sr.selectedWaypoint < len(waypoints) and waypointID == waypoints[self.sr.selectedWaypoint]: 155 selectedItem = actualID 156 counter = counter + 1 157 fromID = waypointID 158 159 if self == None: 160 return 161 destinationPath = starmapSvc.GetDestinationPath() 162 self.sr.scroll2.Load(contentList=scrolllist) 163 if not len(scrolllist): 164 self.SetHint(localization.GetByLabel('UI/Map/MapPallet/hintNoWaypoints')) 165 if selectedItem is not None: 166 self.sr.scroll2.SetSelected(selectedItem) 167 168 def _GetWaypointInfo(self, waypointID, mapSvc, structureDirectory): 169 each = mapSvc.GetItem(waypointID) 170 if each: 171 return (each.itemID, each.itemName, each.typeID) 172 structureInfo = structureDirectory.GetStructureInfo(waypointID) 173 if structureInfo: 174 return (structureInfo.solarSystemID, cfg.evelocations.Get(waypointID).name, structureInfo.typeID) 175 return (None, None, None) 176 177 def LoadAvoidance(self, *args): 178 mapSvc = sm.StartService('map') 179 items = sm.GetService('clientPathfinderService').GetAvoidanceItems() 180 scrolllist = [] 181 if items and len(items): 182 self.SetHint() 183 counter = 0 184 for itemsID in items: 185 blue.pyos.BeNice() 186 each = mapSvc.GetItem(itemsID) 187 description = localization.GetByLabel('UI/Map/MapPallet/lblActiveColorCategory', activeLabel=evetypes.GetGroupNameByGroup(each.typeID)) 188 wasID = each.itemID 189 while wasID: 190 wasID = mapSvc.GetParent(wasID) 191 if wasID: 192 item = mapSvc.GetItem(wasID) 193 if item is not None: 194 description = description + ' / ' + item.itemName 195 196 itemName = each.itemName 197 text = localization.GetByLabel('UI/Map/MapPallet/lblAdvoidanceListEntry', itemName=itemName, description=description) 198 entry = GetFromClass(LocationTextEntry, {'itemID': itemsID, 199 'typeID': each.typeID, 200 'text': text, 201 'locationID': itemsID, 202 'genericDisplayLabel': itemName}) 203 scrolllist.append(entry) 204 205 self.sr.scroll2.Load(contentList=scrolllist) 206 if not len(scrolllist): 207 self.SetHint(localization.GetByLabel('UI/Map/MapPallet/hintNoAdvoidanceItems')) 208 209 def SetHint(self, hintstr = None): 210 if self.sr.scroll2: 211 self.sr.scroll2.ShowHint(hintstr) 212 213 def OnDestinationSet(self, *args): 214 if self.sr.autopilottabs.GetSelectedArgs() == 'waypointconf': 215 self.LoadWaypoints() 216 217 def OnAutopilotUpdated(self): 218 if self.sr.autopilottabs.GetSelectedArgs() == 'avoidconf': 219 self.LoadAvoidance() 220 221 222 class AutoPilotItem(Item): 223 __guid__ = 'listentry.AutoPilotItem' 224 isDragObject = True 225 226 def Startup(self, *args): 227 super(AutoPilotItem, self).Startup(*args) 228 self.sr.posIndicatorCont = Container(name='posIndicator', parent=self, align=uiconst.TOTOP, state=uiconst.UI_DISABLED, height=2) 229 self.sr.posIndicatorNo = Fill(parent=self.sr.posIndicatorCont, color=(0.61, 0.05, 0.005, 1.0)) 230 self.sr.posIndicatorNo.state = uiconst.UI_HIDDEN 231 self.sr.posIndicatorYes = Fill(parent=self.sr.posIndicatorCont, color=(1.0, 1.0, 1.0, 0.5)) 232 self.sr.posIndicatorYes.state = uiconst.UI_HIDDEN 233 234 def GetDragData(self, *args): 235 if not self.sr.node.canDrag: 236 return 237 self.sr.node.scroll.SelectNode(self.sr.node) 238 return [self.sr.node] 239 240 def OnDropData(self, dragObj, nodes, *args): 241 self.sr.posIndicatorNo.state = uiconst.UI_HIDDEN 242 self.sr.posIndicatorYes.state = uiconst.UI_HIDDEN 243 if GetAttrs(self, 'parent', 'OnDropData'): 244 node = nodes[0] 245 if self.sr.node.canDrag: 246 if GetAttrs(node, 'panel'): 247 self.parent.OnDropData(dragObj, nodes, orderID=self.sr.node.orderID) 248 249 def OnDragEnter(self, dragObj, nodes, *args): 250 node = nodes[0] 251 if self.sr.node.canDrag: 252 self.sr.posIndicatorYes.state = uiconst.UI_DISABLED 253 else: 254 self.sr.posIndicatorNo.state = uiconst.UI_DISABLED 255 256 def OnDragExit(self, *args): 257 self.sr.posIndicatorNo.state = uiconst.UI_HIDDEN 258 self.sr.posIndicatorYes.state = uiconst.UI_HIDDEN