underConstructionInputItem.py (13625B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\underConstruction\underConstructionInputItem.py 2 import itertools 3 import evetypes 4 import mathext 5 from carbonui import TextColor, TextAlign 6 from carbonui import const as uiconst 7 from carbonui.control.scrollentries import SE_BaseClassCore 8 from carbonui.control.singlelineedits.singleLineEditInteger import SingleLineEditInteger 9 from carbonui.primitives.container import Container 10 from carbonui.primitives.containerAutoSize import ContainerAutoSize 11 from carbonui.primitives.layoutGrid import LayoutGrid 12 from carbonui.primitives.line import Line 13 from carbonui.primitives.sprite import Sprite 14 from eve.client.script.ui import eveColor 15 from eve.client.script.ui.control.eveLabel import EveLabelMedium 16 from eve.client.script.ui.control.gaugeCircular import GaugeCircular 17 from eve.common.script.util.eveFormat import FmtLP, FmtISK 18 from eveservices.menu import GetMenuService 19 from localization import GetByLabel 20 21 class InputItemController(object): 22 23 def __init__(self, typeID, neededQty, iskRewards, lpRewards, isSelected = False): 24 self.typeID = typeID 25 self.neededQty = neededQty 26 self.iskRewards = iskRewards 27 self.lpRewards = lpRewards 28 self.isSelected = isSelected 29 self.qtyInCargo = 0 30 self.unitsInContainer = 0 31 self.currentValueIfSelected = 0 32 self.isCompleted = False 33 34 @property 35 def maxToAdd(self): 36 maxToAdd = max(0, min(self.qtyInCargo, self.neededQty - self.unitsInContainer)) 37 return maxToAdd 38 39 40 class UnderConstructionInputScrollEntry(SE_BaseClassCore): 41 default_state = uiconst.UI_NORMAL 42 default_padLeft = 2 43 44 def ApplyAttributes(self, attributes): 45 super(UnderConstructionInputScrollEntry, self).ApplyAttributes(attributes) 46 self.inputItemController = attributes.itemController 47 self.inputChangedCallback = attributes.inputChangedCallback 48 qtyInCargo = attributes.qtyInCargo 49 paddingValue = attributes.paddingValue 50 self.ConstructLine() 51 self.inputCont = None 52 self.inputCont = UnderConstructionInputItem(parent=self, itemController=self.inputItemController, inputFieldChangedCallback=self.OnInputFieldChanged, qtyInCargo=qtyInCargo, callback=self.UpdateSize, paddingValue=paddingValue) 53 54 def ConstructLine(self): 55 lineWidth = 2 56 lineCont = Container(parent=self, name='lineCont', align=uiconst.TOLEFT, width=lineWidth, left=-lineWidth, padBottom=1) 57 self.leftLine = Line(parent=lineCont, align=uiconst.TOLEFT, weight=lineWidth, outputMode=uiconst.OUTPUT_COLOR_AND_GLOW, color=eveColor.WHITE, glowBrightness=0.5) 58 self.leftLine.Hide() 59 60 def UpdateEntry(self, unitsInContainer, qtyInCargo): 61 self.inputItemController.unitsInContainer = unitsInContainer 62 self.inputItemController.qtyInCargo = qtyInCargo 63 self.RefreshUI() 64 65 def RefreshUI(self): 66 self.RefreshNumbers() 67 self.UpdateEnabledLook() 68 69 def UpdateCompletedState(self): 70 if self.inputItemController.unitsInContainer >= self.inputItemController.neededQty: 71 self.inputItemController.isCompleted = True 72 else: 73 self.inputItemController.isCompleted = False 74 75 def RefreshNumbers(self): 76 self.UpdateCompletedState() 77 qtyInCargo = self.inputItemController.qtyInCargo 78 maxToAdd = self.inputItemController.maxToAdd 79 self.inputCont.inputEdit.SetMaxValue(maxToAdd) 80 if not qtyInCargo or self.inputItemController.isCompleted: 81 self.inputItemController.isSelected = False 82 self.inputCont.RefreshNumbers() 83 self.inputCont.UpdateGaugeProgress() 84 85 def UpdateSize(self, *args): 86 if self.inputCont: 87 self.height = self.inputCont.height 88 89 def UpdateEnabledLook(self): 90 if self.inputItemController.isSelected: 91 self.Select() 92 else: 93 self.Deselect() 94 if self.inputItemController.isCompleted or self.inputItemController.qtyInCargo: 95 self.opacity = 1.0 96 else: 97 self.opacity = 0.25 98 self.UpdateLine() 99 self.inputCont.UpdateInputHint() 100 101 def OnClick(self, *args): 102 if self.inputItemController.isCompleted: 103 if self.inputItemController.isSelected: 104 self.SetEntryDeselected() 105 self.UpdateEnabledLook() 106 return 107 if not self.inputItemController.qtyInCargo: 108 return 109 if self.inputItemController.isSelected: 110 self.SetEntryDeselected() 111 else: 112 self.SelectNonSelectedEntry() 113 self.OnInputChanged() 114 self.RefreshUI() 115 116 def SetEntryDeselected(self): 117 self.inputItemController.isSelected = False 118 119 def SelectNonSelectedEntry(self): 120 self.inputItemController.isSelected = True 121 self.inputCont.UpdateEditFromSavedValue() 122 123 def OnInputChanged(self): 124 if self.inputChangedCallback: 125 self.inputChangedCallback() 126 127 def OnInputFieldChanged(self, *args): 128 if self.inputCont.inputEdit.GetValue() and not self.inputItemController.isSelected: 129 self.inputItemController.isSelected = True 130 self.OnInputChanged() 131 132 def GetInputQty(self): 133 return self.inputCont.GetInputQty() 134 135 def ShowHilite(self, animate = True): 136 if self.inputItemController.isCompleted: 137 return 138 return super(UnderConstructionInputScrollEntry, self).ShowHilite(animate) 139 140 def UpdateLine(self): 141 if self.inputItemController.isSelected: 142 self.leftLine.Show() 143 else: 144 self.leftLine.Hide() 145 146 147 class UnderConstructionInputItem(ContainerAutoSize): 148 default_align = uiconst.TOTOP 149 default_minHeight = 88 150 default_alignMode = uiconst.TOTOP 151 152 def ApplyAttributes(self, attributes): 153 super(UnderConstructionInputItem, self).ApplyAttributes(attributes) 154 self.inputItemController = attributes.itemController 155 self.inputFieldChangedCallback = attributes.inputFieldChangedCallback 156 self.paddingValue = attributes.paddingValue or 0 157 qtyInCargo = attributes.qtyInCargo 158 self.ConstructTypeIcon() 159 self.ConstructInput(qtyInCargo) 160 self.ConstructLabels() 161 162 def ConstructTypeIcon(self): 163 iconSize = 64 164 gaugeSize = iconSize + 10 165 leftCont = Container(parent=self, name='leftCont', align=uiconst.TOLEFT, width=gaugeSize, left=10) 166 self.iconGaugeCont = IconGaugeCont(parent=leftCont, align=uiconst.CENTERLEFT, pos=(0, 167 0, 168 gaugeSize, 169 gaugeSize), gaugeSize=gaugeSize, iconSize=iconSize, typeID=self.inputItemController.typeID) 170 171 def ConstructInput(self, qtyInCargo): 172 rightPad = self.paddingValue + 10 173 rightCont = Container(parent=self, name='rightCont', align=uiconst.TORIGHT, width=100, left=rightPad) 174 self.inputEdit = SingleLineEditInteger(parent=rightCont, width=100, OnChange=self.OnInputFieldChanged, setvalue=qtyInCargo, align=uiconst.CENTERRIGHT) 175 self.successLabel = EveLabelMedium(parent=rightCont, align=uiconst.CENTER, text=GetByLabel('UI/Inflight/SpaceComponents/UnderConstruction/MaterialCompleted'), color=TextColor.SUCCESS) 176 self.successLabel.display = False 177 178 def ConstructLabels(self): 179 textCont = ContainerAutoSize(parent=self, name='textCont', align=uiconst.TOTOP, padLeft=12) 180 EveLabelMedium(parent=textCont, align=uiconst.TOTOP, text=evetypes.GetName(self.inputItemController.typeID), autoFadeSides=16, top=16) 181 gridParent = ContainerAutoSize(parent=textCont, name='gridParent', align=uiconst.TOTOP, top=10, padBottom=10) 182 grid = LayoutGrid(parent=gridParent, align=uiconst.TOPLEFT, columns=2, cellSpacing=(24, 0)) 183 lpRewardsText = GetByLabel('UI/Inflight/SpaceComponents/UnderConstruction/LpPayout') if self.inputItemController.lpRewards else '' 184 EveLabelMedium(parent=grid, text=lpRewardsText, color=TextColor.SECONDARY) 185 iskRewardsText = GetByLabel('UI/Inflight/SpaceComponents/UnderConstruction/IskPayout') if self.inputItemController.iskRewards else '' 186 EveLabelMedium(parent=grid, text=iskRewardsText, color=TextColor.SECONDARY) 187 iskList = [self.inputItemController.iskRewards] if self.inputItemController.iskRewards else [] 188 for lpCorpAndAmountt, iskValue in itertools.izip_longest(self.inputItemController.lpRewards.items(), iskList, fillvalue=None): 189 if lpCorpAndAmountt: 190 corpID, lpAmount = lpCorpAndAmountt 191 lpText = FmtLP(lpAmount) 192 lpHint = GetByLabel('UI/Inflight/SpaceComponents/UnderConstruction/NumLpFromCorp', numLP=lpAmount, corpName=cfg.eveowners.Get(corpID).name) 193 labelState = uiconst.UI_NORMAL 194 else: 195 lpText = '' 196 lpHint = '' 197 labelState = uiconst.UI_DISABLED 198 lpLabel = EveLabelMedium(parent=grid, text=lpText, state=labelState) 199 lpLabel.hint = lpHint 200 if iskValue: 201 iskText = FmtISK(iskValue) 202 else: 203 iskText = '' 204 EveLabelMedium(parent=grid, text=iskText) 205 206 def RefreshNumbers(self): 207 maxToAdd = self.inputItemController.maxToAdd 208 self.inputEdit.SetMaxValue(maxToAdd) 209 if self.inputItemController.isCompleted: 210 self.inputEdit.SetValue(0, False) 211 self.inputEdit.Hide() 212 self.successLabel.display = True 213 else: 214 self.inputEdit.Show() 215 self.successLabel.display = False 216 if self.inputItemController.isSelected: 217 value = self.GetInputQty() 218 self.inputItemController.currentValueIfSelected = min(value, maxToAdd) 219 if value > maxToAdd: 220 self.inputEdit.SetValue(maxToAdd, False) 221 else: 222 self.inputEdit.SetValue(0, False) 223 224 def UpdateGaugeProgress(self): 225 unitsInWnd = self.GetInputQty() 226 self.iconGaugeCont.SetProgress(self.inputItemController.unitsInContainer, self.inputItemController.neededQty, unitsInWnd) 227 228 def GetInputQty(self): 229 if self.inputItemController.isSelected: 230 return self.inputEdit.GetValue() 231 return 0 232 233 def OnInputFieldChanged(self, *args): 234 if self.inputFieldChangedCallback: 235 self.inputFieldChangedCallback(*args) 236 237 def UpdateInputHint(self): 238 if self.inputItemController.qtyInCargo: 239 hint = GetByLabel('UI/Inflight/SpaceComponents/UnderConstruction/NumUnitsInCargo', qty=self.inputItemController.qtyInCargo) 240 else: 241 hint = GetByLabel('UI/Inflight/SpaceComponents/UnderConstruction/NoSuchItemInCargo') 242 self.inputEdit.hint = hint 243 244 def UpdateEditFromSavedValue(self): 245 self.inputEdit.SetValue(self.inputItemController.currentValueIfSelected, False) 246 247 248 class IconGaugeCont(Container): 249 default_state = uiconst.UI_NORMAL 250 251 def ApplyAttributes(self, attributes): 252 super(IconGaugeCont, self).ApplyAttributes(attributes) 253 self.typeID = attributes.typeID 254 iconSize = attributes.iconSize 255 gaugeSize = attributes.gaugeSize 256 self.progressLabel = EveLabelMedium(parent=self, align=uiconst.CENTERLEFT, text='', textAlign=TextAlign.CENTER) 257 self.progressLabel.Hide() 258 self.progressLabel.maxWidth = iconSize + 8 259 self.typeCont = Container(parent=self, name='typeCont', align=uiconst.CENTER, pos=(0, 260 0, 261 iconSize, 262 iconSize)) 263 typeIcon = Sprite(parent=self.typeCont, name='typeIcon', align=uiconst.CENTERRIGHT, state=uiconst.UI_DISABLED, pos=(0, 264 0, 265 iconSize, 266 iconSize)) 267 sm.GetService('photo').GetIconByType(typeIcon, self.typeID) 268 gaugeCont = Container(parent=self, name='gaugeCont', pos=(0, 269 0, 270 gaugeSize, 271 gaugeSize), align=uiconst.CENTERRIGHT) 272 self.gauge = GaugeCircular(parent=gaugeCont, colorStart=eveColor.CRYO_BLUE, colorEnd=eveColor.CRYO_BLUE, radius=gaugeSize / 2, align=uiconst.CENTER, state=uiconst.UI_DISABLED, colorBg=(0, 0, 0, 0), showMarker=False) 273 self.inWndGauge = GaugeCircular(parent=gaugeCont, radius=gaugeSize / 2, colorStart=eveColor.SILVER_GREY, colorEnd=eveColor.SILVER_GREY, align=uiconst.CENTER, state=uiconst.UI_DISABLED, showMarker=False) 274 275 def OnClick(self, *args): 276 return sm.GetService('info').ShowInfo(self.typeID) 277 278 def GetMenu(self): 279 return GetMenuService().GetMenuFromItemIDTypeID(None, self.typeID) 280 281 def SetProgress(self, unitsInContainer, neededQty, unitsInWnd): 282 progress = float(unitsInContainer) / neededQty if neededQty else 0 283 self.gauge.SetValue(progress) 284 progressText = GetByLabel('UI/Inflight/SpaceComponents/UnderConstruction/ItemProgressUnits', currentQty=unitsInContainer, requiredQty=neededQty) 285 self.progressLabel.SetText(progressText) 286 progressWithInput = mathext.clamp(float(unitsInContainer + unitsInWnd) / neededQty if neededQty else 0, 0, 1) 287 self.inWndGauge.SetValue(progressWithInput) 288 if unitsInContainer == neededQty: 289 if self.gauge.colorStart != eveColor.SUCCESS_GREEN or self.gauge.colorEnd != eveColor.SUCCESS_GREEN: 290 self.gauge.SetColor(eveColor.SUCCESS_GREEN, eveColor.SUCCESS_GREEN) 291 292 def OnMouseEnter(self, *args): 293 self.progressLabel.Show() 294 self.typeCont.opacity = 0.25 295 296 def OnMouseExit(self, *args): 297 self.progressLabel.Hide() 298 self.typeCont.opacity = 1.0