infrastructureHub.py (17388B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\factionalWarfare\infrastructureHub.py 2 import math 3 from math import pi 4 import blue 5 import carbonui.const as uiconst 6 import eveformat 7 import localization 8 import uthread 9 from carbonui.control.button import Button 10 from carbonui.control.singlelineedits.singleLineEditInteger import SingleLineEditInteger 11 from carbonui.control.window import Window 12 from carbonui.primitives.container import Container 13 from carbonui.primitives.containerAutoSize import ContainerAutoSize 14 from carbonui.primitives.fill import Fill 15 from carbonui.primitives.frame import Frame 16 from carbonui.primitives.gradientSprite import GradientSprite 17 from carbonui.primitives.sprite import Sprite 18 from carbonui.uicore import uicore 19 from carbonui.util.color import Color 20 from carbonui.window.segment.underlay import WindowSegmentUnderlay 21 from eve.client.script.ui import eveThemeColor 22 from eve.client.script.ui.control import eveLabel 23 from eve.client.script.ui.control.gauge import Gauge 24 from eve.client.script.ui.shared.factionalWarfare.fwSystemBenefitIcon import FWSystemBenefitIcon 25 from eve.common.lib import appConst 26 from eve.common.script.util import facwarCommon 27 from eveexceptions import UserError 28 from player_messaging.client.ui_message import prompt_player_fsd_dialog 29 30 class FWInfrastructureHub(Window): 31 __guid__ = 'form.FWInfrastructureHub' 32 __notifyevents__ = ['OnSolarSystemLPChange', 'OnCharacterLPBalanceChange_Local'] 33 default_windowID = 'FWInfrastructureHub' 34 default_fixedWidth = 510 35 default_fixedHeight = 650 36 default_iconNum = 'res:/ui/Texture/WindowIcons/factionalwarfare.png' 37 default_caption = 'UI/FactionWarfare/IHub/IHubWndCaption' 38 PADSIDE = 0 39 PADTOP = 10 40 41 def ApplyAttributes(self, attributes): 42 Window.ApplyAttributes(self, attributes) 43 self.itemID = attributes.Get('itemID') 44 self.facwar = sm.GetService('facwar') 45 lpPool = self.facwar.GetSolarSystemLPs(session.solarsystemid2) 46 topCont = Container(name='topCont', parent=self.sr.main, align=uiconst.TOTOP, height=40, padding=(self.PADSIDE, 47 self.PADTOP, 48 self.PADSIDE, 49 self.PADSIDE)) 50 mainCont = ContainerAutoSize(name='mainCont', parent=self.sr.main, align=uiconst.TOTOP, padTop=16) 51 bottomCont = Container(name='bottomCont', parent=self.sr.main, align=uiconst.TOBOTTOM, height=90, padTop=self.PADTOP) 52 eveLabel.EveLabelLarge(parent=topCont, text=localization.GetByLabel('UI/FactionWarfare/IHub/SystemUpgradePanel', systemName=cfg.evelocations.Get(session.solarsystemid2).name), align=uiconst.TOPLEFT, top=5) 53 eveLabel.EveLabelLarge(parent=topCont, text=localization.GetByLabel('UI/FactionWarfare/IHub/TotalLP'), align=uiconst.TOPRIGHT, top=5) 54 self.lpPoolLabel = eveLabel.EveCaptionSmall(parent=topCont, align=uiconst.TOPRIGHT, top=25) 55 limits = const.facwarSolarSystemUpgradeThresholds 56 self.upgradeBars = [] 57 for i in xrange(1, 7): 58 bar = FWUpgradeLevelCont(parent=mainCont, align=uiconst.TOTOP, padding=(self.PADSIDE, 59 0, 60 0, 61 10), lowerLimit=limits[i - 1], upperLimit=limits[i], lpAmount=lpPool, level=i, idx=0) 62 self.upgradeBars.append(bar) 63 64 self.bottomGradient = WindowSegmentUnderlay(bgParent=bottomCont, padding=self._get_bottom_segment_padding()) 65 self.bottomFlashEffect = Fill(bgParent=bottomCont, padding=self._get_bottom_segment_padding(), opacity=0.0, color=eveThemeColor.THEME_ACCENT, outputMode=uiconst.OUTPUT_COLOR_AND_GLOW, glowBrightness=0.3) 66 bottomMainCont = Container(name='bottomMainCont', parent=bottomCont, align=uiconst.TOTOP, height=100) 67 self.myLPLabel = eveLabel.Label(parent=bottomMainCont, text=self.GetLPOwnedLabel(), align=uiconst.TOPLEFT, left=self.PADSIDE, top=self.PADTOP) 68 self.bottomBottomCont = Container(name='bottomBottom', align=uiconst.TOPLEFT, pos=(self.PADSIDE, 69 40, 70 self._fixedWidth, 71 25), parent=bottomMainCont) 72 self.donateAmountEdit = SingleLineEditInteger(parent=self.bottomBottomCont, name='donateAmountEdit', align=uiconst.TOLEFT, setvalue=0, width=155, OnReturn=self.OnDonateLPBtn, OnChange=self.OnDonateValueChanged) 73 self.donateBtn = Button(parent=self.bottomBottomCont, align=uiconst.TOLEFT, func=self.OnDonateLPBtn, label=localization.GetByLabel('UI/FactionWarfare/IHub/DonateLPs'), padLeft=4) 74 self.donationReceivedLabel = eveLabel.EveCaptionMedium(name='donationReceivedLabel', parent=bottomMainCont, align=uiconst.TOPLEFT, text=localization.GetByLabel('UI/FactionWarfare/IHub/DonationReceived'), left=self.PADSIDE, top=50, opacity=0.0) 75 self.bottomTaxCont = Container(name='bottomTax', align=uiconst.TOPLEFT, pos=(self.PADSIDE, 76 73, 77 400, 78 25), parent=bottomMainCont) 79 self.myLPToIhubLabel = None 80 factionID = self.facwar.GetSystemOccupier(session.solarsystemid) 81 self.myLPTaxLabel = eveLabel.Label(name='myLPTaxLabel', parent=self.bottomTaxCont, text=localization.GetByLabel('UI/FactionWarfare/IHub/maintenanceTax', tax=int(facwarCommon.GetDonationTax(factionID) * 100)), align=uiconst.TOLEFT, state=uiconst.UI_NORMAL, left=5) 82 self.SetLPPoolAmount(lpPool) 83 self.UpdateMyLPAmount() 84 self.UpdateMyLPToIHubLabel() 85 if facwarCommon.IsOccupierFWFaction(factionID): 86 self.donateBtn.Enable() 87 self.donateAmountEdit.Enable() 88 else: 89 self.donateBtn.Disable() 90 self.donateAmountEdit.Disable() 91 uthread.new(self.CheckOpenThread) 92 self.on_content_padding_changed.connect(self._on_content_padding_changed) 93 94 def _get_bottom_segment_padding(self): 95 pad_left, _, pad_right, pad_bottom = self.content_padding 96 return (-pad_left, 97 0, 98 -pad_right, 99 -pad_bottom) 100 101 def _update_bottom_segment_padding(self): 102 if self.bottomGradient: 103 self.bottomGradient.padding = self._get_bottom_segment_padding() 104 if self.bottomFlashEffect: 105 self.bottomFlashEffect.padding = self._get_bottom_segment_padding() 106 107 def _on_content_padding_changed(self, window): 108 self._update_bottom_segment_padding() 109 110 def UpdateMyLPToIHubLabel(self, refreshTax = False): 111 lpAmount = self.donateAmountEdit.GetValue() 112 donationTax = facwarCommon.GetDonationTax(session.warfactionid) 113 tax = math.ceil(donationTax * lpAmount) 114 if self.myLPToIhubLabel: 115 self.myLPToIhubLabel.Close() 116 self.myLPToIhubLabel = eveLabel.Label(name='myLPToIhubLabel', parent=self.bottomTaxCont, align=uiconst.TOLEFT, idx=0, text=localization.GetByLabel('UI/FactionWarfare/IHub/TotalDonated', loyaltyPoints=localization.formatters.FormatNumeric(int(lpAmount - tax), useGrouping=True))) 117 if refreshTax: 118 if self.myLPTaxLabel: 119 self.myLPTaxLabel.Close() 120 self.myLPTaxLabel = eveLabel.Label(name='myLPTaxLabel', parent=self.bottomTaxCont, text=localization.GetByLabel('UI/FactionWarfare/IHub/maintenanceTax', tax=int(donationTax * 100)), align=uiconst.TOLEFT, state=uiconst.UI_NORMAL, left=5) 121 self.myLPTaxLabel.hint = localization.GetByLabel('UI/FactionWarfare/LPAmount', lps=tax) 122 123 def GetLPOwnedLabel(self): 124 factionID = self.facwar.GetSystemOccupier(session.solarsystemid) 125 militiaCorpID = self.facwar.GetFactionMilitiaCorporation(factionID) 126 amount = self.GetMyLPs() 127 return localization.GetByLabel('UI/FactionWarfare/IHub/LPOwned', LPCount=localization.formatters.FormatNumeric(amount, useGrouping=True), corpName=cfg.eveowners.Get(militiaCorpID).name) 128 129 def CheckOpenThread(self): 130 bp = sm.GetService('michelle').GetBallpark() 131 while not self.destroyed: 132 blue.synchro.SleepWallclock(1000) 133 distance = bp.GetSurfaceDist(session.shipid, self.itemID) 134 if distance > const.facwarIHubInteractDist: 135 self.Close() 136 137 def OnSessionChanged(self, *args): 138 self.Close() 139 140 def OnCharacterLPBalanceChange_Local(self, *args, **kwargs): 141 self.UpdateMyLPAmount() 142 143 def SetLPPoolAmount(self, amount): 144 self.lpPoolLabel.SetText(localization.formatters.FormatNumeric(amount, useGrouping=True)) 145 146 def UpdateMyLPAmount(self): 147 amount = self.GetMyLPs() 148 self.myLPLabel.SetText(self.GetLPOwnedLabel()) 149 self.donateAmountEdit.SetMinValue(appConst.facwarMinLPDonation) 150 self.donateAmountEdit.SetMaxValue(amount) 151 152 def OnDonateValueChanged(self, value): 153 uthread.new(self.UpdateMyLPToIHubLabel) 154 155 def OnDonateLPBtn(self, *args): 156 if not self.bottomBottomCont.pickState: 157 return 158 pointsToDonate = self.donateAmountEdit.GetValue() 159 if not pointsToDonate: 160 return 161 donationTax = facwarCommon.GetDonationTax(session.warfactionid) 162 pointsToIHub = int(pointsToDonate - pointsToDonate * donationTax) 163 try: 164 self.facwar.DonateLPsToSolarSystem(pointsToDonate, pointsToIHub) 165 except UserError as e: 166 if e.msg == 'FacWarDonationTaxChanged': 167 self.facwar.objectCaching.InvalidateCachedMethodCalls([('map', 'GetFacWarZoneInfo', (session.warfactionid,))]) 168 self.UpdateMyLPToIHubLabel(refreshTax=True) 169 if prompt_player_fsd_dialog('FacWarDonationTaxChanged', e.dict, uiconst.YESNO, uiconst.ID_YES) == uiconst.ID_YES: 170 newPointsToIhub = int(pointsToDonate * (1 - e.dict['taxNow'] / 100.0)) 171 try: 172 self.facwar.DonateLPsToSolarSystem(pointsToDonate, newPointsToIhub) 173 except UserError as e: 174 if e.msg == 'FacWarDonationTaxChanged': 175 return 176 raise 177 178 else: 179 return 180 else: 181 raise 182 183 self.donateAmountEdit.SetValue('0') 184 uicore.animations.FadeIn(self.bottomFlashEffect, endVal=0.3, duration=0.3) 185 self.bottomBottomCont.Disable() 186 uicore.animations.FadeOut(self.bottomBottomCont, duration=0.1) 187 self.bottomTaxCont.Disable() 188 uicore.animations.FadeOut(self.bottomTaxCont, duration=0.1) 189 blue.synchro.Sleep(300) 190 uicore.animations.MoveInFromBottom(self.donationReceivedLabel, amount=5, duration=0.15) 191 uicore.animations.FadeIn(self.donationReceivedLabel, sleep=True, duration=0.5) 192 blue.synchro.Sleep(5000) 193 uicore.animations.FadeOut(self.bottomFlashEffect, duration=0.3, sleep=True) 194 uicore.animations.FadeOut(self.donationReceivedLabel, sleep=True, duration=0.3) 195 uicore.animations.FadeIn(self.bottomBottomCont, duration=0.3) 196 self.bottomBottomCont.Enable() 197 uicore.animations.FadeIn(self.bottomTaxCont, duration=0.3) 198 self.bottomTaxCont.Enable() 199 200 def OnSolarSystemLPChange(self, oldPoints, newPoints): 201 self.SetLPPoolAmount(newPoints) 202 myLPs = self.GetMyLPs() 203 self.donateAmountEdit.SetMinValue(appConst.facwarMinLPDonation) 204 self.donateAmountEdit.SetMaxValue(myLPs) 205 self.UpdateMyLPAmount() 206 if newPoints > oldPoints: 207 for bar in self.upgradeBars: 208 bar.SetLPAmount(newPoints) 209 210 else: 211 for bar in reversed(self.upgradeBars): 212 bar.SetLPAmount(newPoints) 213 214 def GetMyLPs(self): 215 militiaCorpID = self.facwar.GetFactionMilitiaCorporation(session.warfactionid) 216 return sm.GetService('loyaltyPointsWalletSvc').GetCharacterWalletLPBalance(militiaCorpID) 217 218 219 class FWUpgradeLevelCont(Container): 220 default_align = uiconst.TOTOP 221 default_state = uiconst.UI_NORMAL 222 default_height = 60 223 default_opacity = 0.0 224 225 def ApplyAttributes(self, attributes): 226 Container.ApplyAttributes(self, attributes) 227 self.lowerLimit = attributes.lowerLimit 228 self.upperLimit = attributes.upperLimit 229 self.lpAmount = attributes.lpAmount 230 self.lastAmount = 0 231 self.level = attributes.level 232 self.facwar = sm.GetService('facwar') 233 self.leftCont = Container(name='leftCont', parent=self, align=uiconst.TOLEFT_PROP, width=0.75) 234 self.rightCont = Container(name='rightCont', parent=self) 235 self.bgFrame = Frame(bgParent=self.leftCont, frameConst=uiconst.FRAME_BORDER1_CORNER1, color=(1.0, 1.0, 1.0, 0.5)) 236 self.bgGradient = GradientSprite(bgParent=self.leftCont, rotation=-pi / 2) 237 levelName = eveLabel.EveCaptionLarge(parent=self.leftCont, text=self.GetLevelName(), top=5, left=10) 238 if self.level == 6: 239 levelName.fontsize = 16 240 self.progressGauge = Gauge(parent=self.leftCont, value=0.0, color=(0.0, 0.31, 0.4, 1.0), backgroundColor=(0.1, 0.1, 0.1, 1.0), align=uiconst.TOBOTTOM, gaugeHeight=15, padding=2, opacity=0.0) 241 self.progressGauge.GetHint = self.GetProgressGaugeHint 242 self.iconCont = Container(name='iconCont', parent=self.leftCont, align=uiconst.TOPRIGHT, pos=(10, 4, 300, 20)) 243 self.ConstructIcons() 244 self.checkboxSprite = Sprite(name='checkboxSprite', parent=self.rightCont, align=uiconst.CENTERLEFT, pos=(15, 0, 16, 16)) 245 eveLabel.EveLabelLarge(parent=self.rightCont, text=localization.formatters.FormatNumeric(self.upperLimit, useGrouping=True), align=uiconst.CENTERLEFT, left=60) 246 self.SetLPAmount(self.lpAmount, init=True) 247 248 def GetProgressGaugeHint(self): 249 if self.lpAmount > self.lowerLimit and self.lpAmount < self.upperLimit: 250 return localization.GetByLabel('UI/FactionWarfare/IHub/LevelUnlockHint', num=self.lpAmount - self.lowerLimit, numTotal=self.upperLimit - self.lowerLimit) 251 252 def ConstructIcons(self): 253 benefits = self.facwar.GetSystemUpgradeLevelBenefits(self.level) 254 for benefitType, benefitValue in benefits: 255 FWSystemBenefitIcon(parent=self.iconCont, align=uiconst.TORIGHT, height=self.iconCont.height, padLeft=12, benefitType=benefitType, benefitValue=benefitValue) 256 257 def GetLevelName(self): 258 if self.level == 6: 259 return localization.GetByLabel('UI/FactionWarfare/IHub/Buffer') 260 return eveformat.number_roman(self.level, zero_text='N/A') 261 262 def SetLPAmount(self, lpAmount, init = False): 263 self.lastAmount = self.lpAmount 264 self.lpAmount = lpAmount 265 if not init: 266 if self.lpAmount < self.lowerLimit and self.lastAmount < self.lowerLimit: 267 return 268 if self.lpAmount >= self.upperLimit and self.lastAmount >= self.upperLimit: 269 return 270 if self.lpAmount >= self.upperLimit: 271 uicore.animations.FadeIn(self) 272 self.bgGradient.SetGradient([(0, (0.3, 0.5, 0.3))], [(0, 0.2), (1.0, 0.7)]) 273 self.HideBar(init=init) 274 self.SetBGFrameColor((0.0, 0.4, 0.0, 0.3), init) 275 self.checkboxSprite.texturePath = 'res:/UI/Texture/icons/38_16_193.png' 276 self.checkboxSprite.opacity = 1.0 277 self.iconCont.opacity = 1.0 278 elif self.lpAmount >= self.lowerLimit: 279 uicore.animations.FadeIn(self) 280 self.ShowBar(init=init) 281 self.bgGradient.SetGradient([(0, (0.3, 0.3, 0.3))], [(0, 0.2), (1.0, 0.7)]) 282 self.SetBGFrameColor(Color.GetGrayRGBA(0.5, 0.3), init) 283 self.checkboxSprite.texturePath = 'res:/UI/Texture/classes/FWInfrastructureHub/smallCircle.png' 284 self.checkboxSprite.opacity = 0.3 285 self.iconCont.opacity = 0.3 286 else: 287 uicore.animations.FadeTo(self, self.opacity, 0.3) 288 self.bgGradient.SetGradient([(0, (0.3, 0.3, 0.3))], [(0, 0.2), (1.0, 0.7)]) 289 self.HideBar(init=init) 290 self.SetBGFrameColor(Color.GetGrayRGBA(0.5, 0.3), init) 291 self.checkboxSprite.texturePath = 'res:/UI/Texture/classes/FWInfrastructureHub/smallCircle.png' 292 self.checkboxSprite.opacity = 1.0 293 self.iconCont.opacity = 1.0 294 295 def SetBGFrameColor(self, color, init): 296 color = Color.GetGrayRGBA(0.5, 0.3) 297 if not init: 298 uicore.animations.SpColorMorphTo(self.bgFrame, endColor=color) 299 else: 300 self.bgFrame.color = color 301 302 def ShowBar(self, init = False): 303 if self.lastAmount and self.lastAmount > self.lpAmount: 304 self.progressGauge.SetValueInstantly(self.GetLastValue()) 305 if init: 306 self.progressGauge.opacity = 1.0 307 else: 308 uicore.animations.FadeIn(self.progressGauge) 309 self.progressGauge.SetValue(self.GetValue()) 310 311 def HideBar(self, init = False): 312 if not init: 313 self.progressGauge.SetValueInstantly(self.GetLastValue()) 314 self.progressGauge.SetValue(self.GetValue()) 315 if self.progressGauge.opacity < 1.0: 316 uicore.animations.FadeIn(self.progressGauge, duration=0.1, sleep=True) 317 uicore.animations.FadeOut(self.progressGauge, sleep=True) 318 319 def GetValue(self): 320 value = (self.lpAmount - self.lowerLimit) / float(self.upperLimit - self.lowerLimit) 321 return max(0.0, min(value, 1.0)) 322 323 def GetLastValue(self): 324 value = (self.lastAmount - self.lowerLimit) / float(self.upperLimit - self.lowerLimit) 325 return max(0.0, min(value, 1.0))