skillPurchaseOverlay.py (5641B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\skillPlan\skillQueuePanel\skillPurchaseOverlay.py 2 import carbonui.control.button 3 import characterskills.client 4 import localization 5 import signals 6 from carbonui import uiconst 7 from carbonui.primitives.container import Container 8 from carbonui.primitives.containerAutoSize import ContainerAutoSize 9 from carbonui.primitives.flowcontainer import FlowContainer 10 from carbonui.primitives.sprite import Sprite 11 from carbonui.uianimations import animations 12 from eve.client.script.ui.control import buttons, eveLabel, primaryButton 13 from eve.client.script.ui.shared.neocom import skillConst 14 15 def show_skill_purchase_overlay(parent, type_id, position): 16 controller = SkillPurchaseOverlayController(type_id, position) 17 overlay = SkillPurchaseOverlay(parent=parent, idx=0, controller=controller, opacity=0.0, padding=-20) 18 animations.FadeIn(overlay, duration=0.3, curveType=uiconst.ANIM_OVERSHOT) 19 return controller 20 21 22 class SkillPurchaseOverlayController(object): 23 24 def __init__(self, type_id, position): 25 self.type_id = type_id 26 self._is_closed = False 27 self._position = position 28 self.on_closed = signals.Signal(signalName='on_closed') 29 self._register_event_handlers() 30 31 @property 32 def are_requirements_trained(self): 33 return len(self._get_untrained_required_skills()) == 0 34 35 @property 36 def is_available_for_purchase(self): 37 return characterskills.client.is_available_for_purchase(self.type_id) 38 39 @property 40 def price(self): 41 if not self.is_available_for_purchase: 42 return None 43 return characterskills.client.get_direct_purchase_price(self.type_id) 44 45 def buy_skill(self): 46 if self._is_closed: 47 return 48 try: 49 sm.GetService('skills').PurchaseSkills([self.type_id], confirm=False) 50 finally: 51 self.close() 52 53 def buy_and_train_skill(self): 54 if self._is_closed: 55 return 56 try: 57 sm.GetService('skills').PurchaseSkills([self.type_id], confirm=False) 58 sm.GetService('skillqueue').AddSkillToQueue(self.type_id, 1, position=self._position) 59 finally: 60 self.close() 61 62 def close(self): 63 if self._is_closed: 64 return 65 self._is_closed = True 66 self._unregister_event_handlers() 67 self.on_closed() 68 69 def view_market_details(self): 70 try: 71 sm.GetService('marketutils').ShowMarketDetails(self.type_id, None) 72 finally: 73 self.close() 74 75 def OnSkillQueueChanged(self): 76 self.close() 77 78 def _get_untrained_required_skills(self): 79 return sm.GetService('skills').GetSkillsMissingToUseItemRecursive(self.type_id) 80 81 def _register_event_handlers(self): 82 sm.RegisterForNotifyEvent(self, 'OnSkillQueueChanged') 83 84 def _unregister_event_handlers(self): 85 sm.UnregisterForNotifyEvent(self, 'OnSkillQueueChanged') 86 87 88 class SkillPurchaseOverlay(Container): 89 default_align = uiconst.TOALL 90 default_state = uiconst.UI_NORMAL 91 92 def ApplyAttributes(self, attributes): 93 super(SkillPurchaseOverlay, self).ApplyAttributes(attributes) 94 self.controller = attributes.controller 95 self._layout() 96 self.controller.on_closed.connect(self.close_animated) 97 98 def close_animated(self): 99 animations.FadeOut(self, duration=0.3, callback=self.Close) 100 101 def _layout(self): 102 Sprite(bgParent=self, texturePath='res:/UI/Texture/classes/Monetization/vignette.png', opacity=0.9) 103 content_cont = ContainerAutoSize(parent=self, align=uiconst.CENTER, width=340) 104 self._add_message(content_cont) 105 self._add_buttons(content_cont) 106 107 def _add_message(self, parent): 108 if self.controller.is_available_for_purchase: 109 text = localization.GetByLabel('UI/SkillQueue/ConfirmSkillPurchase', skill=self.controller.type_id, price=self.controller.price) 110 else: 111 text = localization.GetByLabel('UI/SkillQueue/ErrorSkillIsRare', skill=self.controller.type_id) 112 eveLabel.EveLabelMedium(parent=parent, align=uiconst.TOTOP, text=text) 113 114 def _add_buttons(self, parent): 115 button_cont = FlowContainer(parent=parent, align=uiconst.TOTOP, top=16, centerContent=True, contentSpacing=(4, 4), height=36) 116 self._add_cancel_button(button_cont) 117 if self.controller.is_available_for_purchase: 118 self._add_confirm_button(button_cont) 119 else: 120 self._add_market_details_button(button_cont) 121 122 def _add_cancel_button(self, parent): 123 carbonui.control.button.Button(parent=parent, align=uiconst.NOALIGN, label=localization.GetByLabel('UI/Common/Cancel'), func=self.controller.close, args=(), fixedheight=32, fixedwidth=120) 124 125 def _add_confirm_button(self, parent): 126 if self.controller.are_requirements_trained: 127 func = self.controller.buy_and_train_skill 128 label = localization.GetByLabel('UI/Skills/BuyAndTrain') 129 else: 130 func = self.controller.buy_skill 131 label = localization.GetByLabel('UI/Skills/BuySkill') 132 primaryButton.PrimaryButton(parent=parent, align=uiconst.NOALIGN, label=label, func=func, args=(), color=skillConst.COLOR_SKILL_1, fixedheight=32, fixedwidth=120) 133 134 def _add_market_details_button(self, parent): 135 carbonui.control.button.Button(parent=parent, align=uiconst.NOALIGN, label=localization.GetByLabel('UI/Inventory/ItemActions/ViewTypesMarketDetails'), func=self.controller.view_market_details, args=(), fixedheight=32, fixedwidth=120)