chargeButtons.py (6058B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\fittingScreen\fittingPanels\chargeButtons.py 2 import evetypes 3 import inventorycommon 4 import signals 5 import trinity 6 from carbonui.primitives.container import Container 7 from carbonui.primitives.fill import Fill 8 import carbonui.const as uiconst 9 from carbonui.primitives.sprite import Sprite 10 from carbonui.control.buttonIcon import ButtonIcon 11 from eve.client.script.ui.control.eveIcon import Icon 12 from eve.client.script.ui.control.themeColored import FrameThemeColored 13 from eve.client.script.ui.shared.fittingScreen import CHARGE_FILTER_ALL_CHARGES 14 from signals.signalUtil import ChangeSignalConnect 15 from utillib import KeyVal 16 from eveservices.menu import GetMenuService 17 18 class ModuleChargeRadioButton(ButtonIcon): 19 isDragObject = True 20 default_iconClass = Icon 21 default_iconBlendMode = trinity.TR2_SBM_BLEND 22 default_iconSize = 32 23 checkmarkTexturePath = 'res:/ui/Texture/classes/Fitting/checkSmall.png' 24 25 def ApplyAttributes(self, attributes): 26 self.moduleTypeID = attributes.typeID 27 self.usedWithChargesIDs = attributes.usedWithChargesIDs 28 attributes.texturePath = inventorycommon.typeHelpers.GetIconFile(self.moduleTypeID) if self.moduleTypeID else '' 29 ButtonIcon.ApplyAttributes(self, attributes) 30 self.isSelected = attributes.isSelected 31 self.controller = attributes.controller 32 self.checkmark = None 33 self.ChangeSignalConnection() 34 self.colorSelected = sm.GetService('uiColor').GetUIColor(uiconst.COLORTYPE_UIHILIGHT) 35 self.hint = attributes.moduleName 36 self.frame = FrameThemeColored(bgParent=self, colorType=uiconst.COLORTYPE_UIBASECONTRAST, opacity=0.75) 37 sm.GetService('photo').GetIconByType(self.icon, self.moduleTypeID) 38 if self.isSelected: 39 self.SetSelected() 40 41 def ChangeSignalConnection(self, connect = True): 42 signalAndCallback = [(self.controller.on_selected_changed, self.OnSelectedChanged)] 43 ChangeSignalConnect(signalAndCallback, connect) 44 45 def GetModuleType(self): 46 return self.moduleTypeID 47 48 def GetMenu(self): 49 return GetMenuService().GetMenuFromItemIDTypeID(None, self.moduleTypeID, includeMarketDetails=True) 50 51 def OnClick(self, *args): 52 if self.isSelected: 53 self.SetDeselected() 54 else: 55 self.SetSelected() 56 self.controller.OnBtnClicked(self.moduleTypeID, self.usedWithChargesIDs) 57 58 def SetSelected(self): 59 self.isSelected = True 60 self.ConstructCheckmark() 61 self.checkmark.display = True 62 self.frame.SetColorType(uiconst.COLORTYPE_UIHILIGHT) 63 64 def SetDeselected(self): 65 self.isSelected = False 66 if self.checkmark: 67 self.checkmark.display = False 68 self.frame.SetColorType(uiconst.COLORTYPE_UIBASECONTRAST) 69 70 def OnSelectedChanged(self, moduleTypeID): 71 if moduleTypeID == self.moduleTypeID: 72 self.SetSelected() 73 else: 74 self.SetDeselected() 75 76 def Close(self): 77 self.ChangeSignalConnection(connect=False) 78 self.controller = None 79 Container.Close(self) 80 81 def ConstructCheckmark(self): 82 if self.checkmark: 83 return 84 self.checkmark = Container(name='checkmark', parent=self, pos=(0, 0, 12, 12), align=uiconst.BOTTOMRIGHT, idx=0) 85 Fill(bgParent=self.checkmark, color=self.colorSelected) 86 Sprite(parent=self.checkmark, texturePath=self.checkmarkTexturePath, align=uiconst.CENTER, pos=(0, 0, 12, 12), state=uiconst.UI_DISABLED) 87 88 def GetDragData(self): 89 keyVal = KeyVal(__guid__='listentry.GenericMarketItem', typeID=self.moduleTypeID, label=evetypes.GetName(self.moduleTypeID)) 90 return [keyVal] 91 92 def SetModuleTypeID(self, typeID, usedWithChargesIDs): 93 self.moduleTypeID = typeID 94 self.usedWithChargesIDs = usedWithChargesIDs 95 self.UpdateModuleIcon() 96 97 def UpdateModuleIcon(self): 98 texturePath = inventorycommon.typeHelpers.GetIconFile(self.moduleTypeID) if self.moduleTypeID else '' 99 self.SetTexturePath(texturePath) 100 101 102 class ModuleChargeController(object): 103 104 def __init__(self, charge_filter_settings, isToggle = True): 105 self.charge_filter_settings = charge_filter_settings 106 self.isToggle = isToggle 107 self.moduleTypeSelected = charge_filter_settings.module_type_selected.get() 108 if self.moduleTypeSelected: 109 self.isActive = True 110 if self.moduleTypeSelected == CHARGE_FILTER_ALL_CHARGES: 111 self.selectedUsedWith = set() 112 else: 113 self.selectedUsedWith = sm.GetService('info').GetUsedWithTypeIDs(self.moduleTypeSelected) 114 else: 115 self.isActive = False 116 self.selectedUsedWith = set() 117 self.on_selected_changed = signals.Signal(signalName='on_selected_changed') 118 119 def OnBtnClicked(self, moduleTypeID, usedWith): 120 return self.SetSelected(moduleTypeID, usedWith) 121 122 def SetSelected(self, moduleTypeID, usedWith): 123 if self.isToggle and self.moduleTypeSelected == moduleTypeID: 124 self.moduleTypeSelected = None 125 self.selectedUsedWith = set() 126 else: 127 self.moduleTypeSelected = moduleTypeID 128 self.selectedUsedWith = usedWith 129 self.isActive = bool(moduleTypeID) 130 self.charge_filter_settings.module_type_selected.set(self.moduleTypeSelected or 0) 131 self.on_selected_changed(self.moduleTypeSelected) 132 133 def GetSelectModuleTypeID(self): 134 return self.moduleTypeSelected 135 136 def GetUsedWithForSelectedModule(self): 137 return self.selectedUsedWith 138 139 def IsFilterActive(self): 140 return self.isActive > 0 141 142 def ResetSelected(self): 143 self.moduleTypeSelected = None 144 self.selectedUsedWith = set() 145 self.SetActiveState(False) 146 147 def SetActiveState(self, isActive): 148 self.isActive = isActive 149 150 def ClearSignals(self): 151 self.on_selected_changed.clear()