structureEntry.py (10259B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\structure\structureBrowser\entries\structureEntry.py 2 import structures 3 from carbon.common.script.util.commonutils import StripTags 4 from eve.client.script.ui.control.baseListEntry import BaseListEntryCustomColumns 5 from eve.client.script.ui.structure.structureIcon import StructureIcon 6 from eve.client.script.ui.control.eveLabel import Label 7 from eve.client.script.ui.control.glowSprite import GlowSprite 8 from carbonui.fontconst import EVE_MEDIUM_FONTSIZE 9 from eve.client.script.ui.station import stationServiceConst 10 from eve.client.script.ui.structure.structureBrowser.browserUIConst import ALL_SERVICES 11 from eve.client.script.ui.structure.structureBrowser.extaColumnUtil import ExtraColumnProvider, GetHeaderForService, FormatColumnValue 12 from eve.client.script.ui.structure.structureBrowser.controllers.structureEntryController import StructureEntryController 13 from localization import GetByLabel 14 import carbonui.const as uiconst 15 from utillib import KeyVal 16 from carbonui.uicore import uicore 17 from eveservices.menu import GetMenuService 18 HEIGHT = 48 19 ICONSIZE = 20 20 LABEL_PARAMS = (EVE_MEDIUM_FONTSIZE, 0, 0) 21 22 class StructureEntry(BaseListEntryCustomColumns): 23 default_name = 'StructureEntry' 24 25 def __init__(self, *args, **kwargs): 26 self.controller = None 27 super(StructureEntry, self).__init__(*args, **kwargs) 28 29 def ApplyAttributes(self, attributes): 30 BaseListEntryCustomColumns.ApplyAttributes(self, attributes) 31 self.controller = self.node.controller 32 self.AddColumnText(self.controller.GetNumJumps()) 33 self.AddColumnText(self.controller.GetSecurityWithColor()) 34 self.AddColumnText(self.controller.GetOwnerName()) 35 self.AddColumnName() 36 self.AddColumnServices() 37 self.AddExtraColumns() 38 39 def AddColumnName(self): 40 column = self.AddColumnContainer() 41 name = self.controller.GetName() 42 size = HEIGHT - 4 43 StructureIcon(name='structureIcon_%s' % name.replace('<br>', '_'), parent=column, align=uiconst.CENTERLEFT, typeID=self.controller.GetTypeID(), structureID=self.controller.GetItemID(), pos=(0, 44 0, 45 size, 46 size), state=uiconst.UI_PICKCHILDREN, wars=self.controller.GetWars()) 47 label = Label(parent=column, text=name, align=uiconst.CENTERLEFT, left=HEIGHT, state=uiconst.UI_NORMAL) 48 label.GetMenu = None 49 label.DelegateEventsNotImplemented(self) 50 51 def AddColumnServices(self): 52 column = self.AddColumnContainer() 53 structureServices = self.controller.GetServices() 54 structureServicesChecked = self.node.structureServicesChecked 55 for i, data in enumerate(structureServices): 56 left = i * ICONSIZE 57 opacity = 1.0 if structureServicesChecked == ALL_SERVICES or data.name in structureServicesChecked else 0.2 58 gs = StructureServiceIcon(name=data.name, parent=column, texturePath=data.iconID, pos=(left, 59 0, 60 ICONSIZE, 61 ICONSIZE), hintHeader=data.label, opacity=opacity, serviceName=data.name, controller=self.controller, serviceID=data.serviceID) 62 gs.DelegateEvents(self) 63 64 def AddExtraColumns(self): 65 structureServicesChecked = self.node.structureServicesChecked 66 if structureServicesChecked == ALL_SERVICES: 67 return 68 extraColumnProvider = ExtraColumnProvider() 69 checkedServicesWithUniqueColumns = extraColumnProvider.GetServicesForUniqueColumns(structureServicesChecked) 70 for serviceName in checkedServicesWithUniqueColumns: 71 columnText = extraColumnProvider.GetColumnText(self.controller, serviceName) 72 if columnText is not None: 73 self.AddColumnText(columnText) 74 75 def GetDragData(self): 76 nodesSelected = self.sr.node.scroll.GetSelectedNodes(self.sr.node) 77 data = [] 78 for eachNode in nodesSelected: 79 k = KeyVal(__guid__='xtriui.ListSurroundingsBtn', itemID=eachNode.controller.GetItemID(), typeID=eachNode.controller.GetTypeID(), label=StripTags(eachNode.controller.GetCleanName().replace('<br>', '-')), isMyCorpStructureEntry=True) 80 data.append(k) 81 82 return data 83 84 @staticmethod 85 def GetColumnSortValues(controller, structureServicesChecked): 86 baseColumns = (controller.GetNumJumps(), 87 controller.GetSecurity(), 88 controller.GetOwnerName().lower(), 89 '%s %s' % (controller.GetSystemName(), StripTags(controller.GetName()).lower()), 90 len(controller.GetServices())) 91 columnProvider = ExtraColumnProvider() 92 extraColumnSortValues = [] 93 if structureServicesChecked != ALL_SERVICES: 94 checkedServicesWithUniqueColumns = ExtraColumnProvider().GetServicesForUniqueColumns(structureServicesChecked) 95 for eachServiceID in checkedServicesWithUniqueColumns: 96 value = columnProvider.GetValueForColumn(controller, eachServiceID) 97 if value == columnProvider.NOT_AVAILABLE: 98 continue 99 extraColumnSortValues.append(value) 100 101 baseColumns += tuple(extraColumnSortValues) 102 return baseColumns 103 104 @staticmethod 105 def GetSortValue(node, by, sortDirection, idx): 106 return (node.columnSortValues[idx],) + tuple(node.columnSortValues) 107 108 @staticmethod 109 def GetExtraHeaders(structureServicesChecked): 110 extraHeaders = [] 111 if structureServicesChecked == ALL_SERVICES: 112 return [] 113 for serviceName in structureServicesChecked: 114 header = GetHeaderForService(serviceName) 115 if header and header not in extraHeaders: 116 extraHeaders += [header] 117 118 return extraHeaders 119 120 @staticmethod 121 def GetHeaders(structureServicesChecked): 122 extraHeaders = StructureEntry.GetExtraHeaders(structureServicesChecked) 123 baseColumns = [GetByLabel('UI/Common/Jumps'), 124 GetByLabel('UI/Common/Security'), 125 GetByLabel('UI/Common/Owner'), 126 GetByLabel('UI/Common/Name'), 127 GetByLabel('UI/Structures/Browser/ServicesColumn')] 128 return baseColumns + extraHeaders 129 130 @staticmethod 131 def GetDynamicHeight(node, width): 132 return HEIGHT 133 134 @staticmethod 135 def GetDefaultColumnWidth(): 136 return {GetByLabel('UI/Industry/System'): 70, 137 GetByLabel('UI/Common/Name'): 230} 138 139 @staticmethod 140 def GetFixedColumns(): 141 return {GetByLabel('UI/Structures/Browser/ServicesColumn'): ICONSIZE * len(stationServiceConst.serviceData) + 2} 142 143 def GetMenu(self): 144 return GetMenuService().GetMenuFromItemIDTypeID(itemID=self.controller.GetItemID(), typeID=self.controller.GetTypeID()) 145 146 @staticmethod 147 def GetColWidths(node, idx = None): 148 controller = node.controller 149 widths = [] 150 if idx is None or idx == 0: 151 jumpText = unicode(controller.GetNumJumps()) 152 widths.append(uicore.font.MeasureTabstops([(jumpText,) + LABEL_PARAMS])[0]) 153 if idx is None or idx == 1: 154 securityText = unicode(controller.GetSecurity()) 155 widths.append(uicore.font.MeasureTabstops([(securityText,) + LABEL_PARAMS])[0]) 156 if idx is None or idx == 2: 157 widths.append(uicore.font.MeasureTabstops([(controller.GetOwnerName(),) + LABEL_PARAMS])[0]) 158 if idx is None or idx == 3: 159 nameToUse = max(StripTags(controller.GetName(), ignoredTags=('br',)).split('<br>'), key=len) 160 widths.append(uicore.font.MeasureTabstops([(nameToUse,) + LABEL_PARAMS])[0] + HEIGHT - 4) 161 return widths 162 163 164 class StructureServiceIcon(GlowSprite): 165 default_align = uiconst.CENTERLEFT 166 default_state = uiconst.UI_NORMAL 167 168 def ApplyAttributes(self, attributes): 169 GlowSprite.ApplyAttributes(self, attributes) 170 self.controller = attributes.controller 171 self.hintHeader = attributes.hintHeader 172 self.serviceName = attributes.serviceName 173 self.serviceID = attributes.serviceID 174 self.isOffline = attributes.isOffline 175 if self.isOffline: 176 self.SetRGB(1.0, 1.0, 0.22) 177 178 def LoadTooltipPanel(self, tooltipPanel, *args): 179 tooltipPanel.LoadGeneric2ColumnTemplate() 180 tooltipPanel.margin = (4, 4, 4, 4) 181 tooltipPanel.cellPadding = (4, 1, 4, 1) 182 tooltipPanel.AddLabelMedium(text=self.hintHeader, colSpan=2) 183 self.AddExtraInfo(tooltipPanel) 184 185 def AddExtraInfo(self, tooltipPanel): 186 if self.serviceID == structures.SERVICE_INDUSTRY: 187 serviceIDs = structures.INDUSTRY_SERVICES 188 else: 189 serviceIDs = [self.serviceID] 190 hintTextList = self.GetServiceNamesAndValues(serviceIDs) 191 for name, value in hintTextList: 192 if value is True: 193 value = GetByLabel('UI/Common/True') 194 tooltipPanel.AddLabelMedium(text=name, align=uiconst.CENTERLEFT) 195 tooltipPanel.AddLabelMedium(text=value, align=uiconst.CENTERRIGHT) 196 197 def GetServiceNamesAndValues(self, serviceIDs): 198 namesAndValues = [] 199 for eachID in serviceIDs: 200 settingIDForService = structures.SERVICES_ACCESS_SETTINGS.get(eachID, None) 201 settingInfo = structures.SETTING_OBJECT_BY_SETTINGID.get(settingIDForService, None) 202 if not settingInfo: 203 continue 204 value = self.controller.GetInfoForExtraColumns(eachID) 205 if value is None: 206 continue 207 value = FormatColumnValue(value, settingInfo.valueType, settingIDForService) 208 label = GetByLabel(settingInfo.labelPath) 209 lineInfo = (label, value) 210 if lineInfo not in namesAndValues: 211 namesAndValues.append(lineInfo) 212 213 return namesAndValues 214 215 216 class StructureServiceIconMyCorp(StructureServiceIcon): 217 218 def AddExtraInfo(self, tooltipPanel): 219 if self.isOffline: 220 if self.serviceID == structures.SERVICE_INDUSTRY: 221 labelPath = 'UI/Structures/Browser/IndustryServicesOffline' 222 else: 223 labelPath = 'UI/Structures/Browser/ServiceIsOffline' 224 tooltipPanel.AddLabelMedium(text=GetByLabel(labelPath), align=uiconst.CENTERLEFT)