skillInjectorWindow.py (8048B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\skilltrading\skillInjectorWindow.py 2 import localization 3 import uthread 4 from carbon.common.script.util.format import FmtAmt 5 from carbonui import uiconst 6 from carbonui.primitives.container import Container 7 from carbonui.primitives.containerAutoSize import ContainerAutoSize 8 from carbonui.uianimations import animations 9 from carbonui.button.group import ButtonGroup 10 from eve.client.script.ui.control.eveLabel import Label, EveLabelMedium 11 from carbonui.control.window import Window 12 from eve.client.script.ui.control.itemIcon import ItemIcon 13 from eve.client.script.ui.skilltrading.skillInjectorBar import SkillInjectorBar 14 from eveexceptions import UserError 15 COLOR_INJECTED = (0.871, 0.118, 0.0, 1.0) 16 DEFAULT_WINDOW_HEIGHT = 280 17 SMALL_WINDOW_HEIGHT = 250 18 19 class SkillInjectorWindow(Window): 20 default_fixedHeight = DEFAULT_WINDOW_HEIGHT 21 default_fixedWidth = 550 22 default_windowID = 'SkillInjectorWindow' 23 default_captionLabelPath = 'UI/SkillTrading/SkillInjectorWindowCaption' 24 default_iconNum = 'res:/UI/Texture/WindowIcons/augmentations.png' 25 default_clipChildren = True 26 default_isCollapseable = False 27 default_isLightBackgroundConfigurable = False 28 default_isStackable = False 29 default_isMinimizable = False 30 default_isLockable = False 31 default_isOverlayable = False 32 __notifyevents__ = ['OnSessionChanged', 'OnNonDiminishingInjectionsChanged'] 33 34 def OnSessionChanged(self, isRemote, session, change): 35 if 'locationid' in change: 36 self.Close() 37 38 def OnNonDiminishingInjectionsChanged(self): 39 if not self.injectionStarted: 40 self.Reload(self) 41 42 @classmethod 43 def OpenOrReload(cls, *args, **kwargs): 44 if cls.IsOpen(): 45 wnd = cls.GetIfOpen() 46 wnd.injectorItem = kwargs.get('injectorItem') 47 wnd.quantity = kwargs.get('quantity') 48 wnd.Reload(wnd) 49 wnd.Maximize() 50 else: 51 cls.Open(*args, **kwargs) 52 53 @classmethod 54 def Reload(cls, instance): 55 uthread.new(instance._Reload) 56 57 def ApplyAttributes(self, attributes): 58 super(SkillInjectorWindow, self).ApplyAttributes(attributes) 59 self.injectorItem = attributes.injectorItem 60 self.injectionStarted = False 61 self.quantity = attributes.get('quantity', self.injectorItem.stacksize) 62 self.mainArea = self.GetMainArea() 63 self.ConstructLayout() 64 self.CheckConstraints() 65 self.totalPoints = self.GetTotalPoints() 66 self.Update() 67 68 def ConstructLayout(self): 69 self.HideHeader() 70 self.ConstructHeader() 71 self.ConstructFooter() 72 self.mainContainer = Container(name='MainContainer', parent=self.mainArea, padding=(4, 0, 4, 0)) 73 self.injectionMessage = Label(name='InjectionMessageLabel', parent=self.mainContainer, align=uiconst.TOTOP, top=20) 74 self.ConstructErrorLabel() 75 self.ConstructInjectorBar() 76 77 def ConstructFooter(self): 78 footerContainer = Container(name='footerContainer', parent=self.mainArea, align=uiconst.TOBOTTOM, height=35, bgColor=(0.133, 0.133, 0.141, 0.7), padding=(4, 0, 4, 4)) 79 self.buttonGroup = ButtonGroup(name='buttonGroup', parent=footerContainer, align=uiconst.CENTER) 80 self.buttonGroup.AddButton(localization.GetByLabel('UI/SkillTrading/ConfirmInjectionLabel'), self.StartInjection) 81 self.buttonGroup.AddButton(localization.GetByLabel('UI/SkillTrading/CancelInjectionLabel'), self.CloseByUser) 82 83 def ConstructErrorLabel(self): 84 errorLabelContainer = Container(name='ErrorLabelContainer', parent=self.mainContainer, align=uiconst.TOALL) 85 self.errorLabel = EveLabelMedium(parent=errorLabelContainer, align=uiconst.CENTERTOP, top=20, opacity=0, width=self.default_fixedWidth - 50) 86 87 def ConstructInjectorBar(self): 88 self.injectorBarContainer = Container(name='InjectorBarContainer', parent=self.mainContainer, align=uiconst.TOALL) 89 self.skillInjectorBar = SkillInjectorBar(name='SkillInjectorBar', parent=self.injectorBarContainer, align=uiconst.CENTER, injectorItem=self.injectorItem, onComplete=self.CloseByUser, opacity=0) 90 91 def ConstructHeader(self): 92 headerContainer = Container(name='HeaderContainer', parent=self.mainArea, align=uiconst.TOTOP, height=35, bgColor=(0.133, 0.133, 0.141, 0.7), padding=(4, 4, 4, 0)) 93 iconContainer = Container(name='IconContainer', parent=headerContainer, align=uiconst.TOLEFT, width=32, height=32) 94 ItemIcon(name='InjectorIcon', parent=iconContainer, typeID=self.injectorItem.typeID, align=uiconst.CENTERLEFT, state=uiconst.UI_DISABLED) 95 labelContainer = ContainerAutoSize(name='HeaderLabelContainer', parent=headerContainer, align=uiconst.TOLEFT) 96 Label(name='ConfirmInjectionLabel', parent=labelContainer, align=uiconst.CENTERLEFT, text=localization.GetByLabel('UI/SkillTrading/SkillInjectorWindowCaption')) 97 98 def _Reload(self): 99 self.mainArea.Flush() 100 self.ConstructLayout() 101 self.CheckConstraints() 102 self.totalPoints = self.GetTotalPoints() 103 self.Update() 104 105 def Update(self): 106 self.injectionMessage.SetText(localization.GetByLabel('UI/SkillTrading/InjectionMessage', amount=self.quantity, injector=self.injectorItem.typeID, charid=session.charid, totalpoints=FmtAmt(self.totalPoints))) 107 self.skillInjectorBar.SetTotalPoints(self.totalPoints + sm.GetService('skills').GetFreeSkillPoints()) 108 109 def StartInjection(self, *args): 110 try: 111 self.injectionStarted = True 112 sm.GetService('skills').ActivateSkillInjector(self.injectorItem.itemID, self.quantity) 113 except UserError: 114 self.injectionStarted = False 115 raise 116 117 self.skillInjectorBar.OnInjectionStarted() 118 animations.FadeOut(self.buttonGroup, callback=self.ReplaceButtonGroup) 119 120 def GetTotalPoints(self): 121 try: 122 return sm.GetService('skills').GetSkillPointAmountFromInjectors(self.injectorItem.typeID, self.quantity) 123 except UserError as error: 124 self.SetHeightToSmall() 125 self.HandleException(error) 126 127 def CheckConstraints(self): 128 try: 129 sm.GetService('skills').CheckInjectionConstraints(self.injectorItem.itemID, self.quantity) 130 except UserError as error: 131 self.SetHeightToSmall() 132 self.buttonGroup.buttons[0].Disable() 133 self.HandleException(error) 134 else: 135 animations.FadeIn(self.skillInjectorBar, duration=0.3) 136 self.SetHeightToDefault() 137 138 def HandleException(self, error): 139 baseText = u'<color=#FFBC711A>%s</color>' 140 errorLabel = 'UI/SkillTrading/ErrorMessages/%s' % error.msg 141 if error.msg == 'InjectorSkillPointLimitReached': 142 self.DisplayErrorMessage(baseText % localization.GetByLabel(errorLabel, typeID=error.dict['typeID'], limit=error.dict['limit'])) 143 elif error.msg == 'AlreadyInjectedToday': 144 self.DisplayErrorMessage(baseText % localization.GetByLabel(errorLabel, type=self.injectorItem.typeID, time=sm.GetService('skills').GetDurationUntilNextAlphaInjection())) 145 else: 146 self.DisplayErrorMessage(baseText % localization.GetByLabel(errorLabel)) 147 148 def DisplayErrorMessage(self, message): 149 animations.FadeOut(self.injectorBarContainer, duration=0.15, sleep=True) 150 self.errorLabel.SetText(message) 151 animations.FadeIn(self.errorLabel, duration=0.3) 152 153 def ReplaceButtonGroup(self): 154 self.buttonGroup.FlushButtons() 155 self.buttonGroup.AddButton(localization.GetByLabel('UI/SkillTrading/CloseInjectionLabel'), self.CloseByUser) 156 animations.FadeIn(self.buttonGroup) 157 158 def SetHeightToSmall(self): 159 self.SetFixedHeight(SMALL_WINDOW_HEIGHT) 160 self.SetHeight(SMALL_WINDOW_HEIGHT) 161 162 def SetHeightToDefault(self): 163 self.SetFixedHeight(DEFAULT_WINDOW_HEIGHT) 164 self.SetHeight(DEFAULT_WINDOW_HEIGHT)