NovaBryan/EVE_Dump
Log | Files | 📦 下载最新源码 (.zip) | Refs | README

corpCheckoutPanel.py (5651B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\cosmetics\structure\components\corpCheckoutPanel.py
      2 import blue
      3 from appConst import corpHeraldry
      4 from carbon.common.script.util.format import FmtAmt
      5 from carbonui.primitives.container import Container
      6 from carbonui.primitives.containerAutoSize import ContainerAutoSize
      7 from carbonui.primitives.sprite import Sprite
      8 from carbonui import const as uiconst, TextColor, TextAlign
      9 from carbonui.uianimations import animations
     10 from eve.client.script.ui import eveColor
     11 from eve.client.script.ui.control.eveLabel import EveLabelMedium, EveCaptionMedium
     12 from eve.client.script.ui.cosmetics.structure import paintToolSignals, paintToolUtils
     13 from localization import GetByLabel
     14 BALANCE_ICON_SIZE = 40
     15 TOTAL_ICON_SIZE = 18
     16 
     17 class CorpCheckoutPanel(Container):
     18     default_height = BALANCE_ICON_SIZE
     19     __notifyevents__ = ['OnCorporationLPBalanceChange_Local']
     20 
     21     def __init__(self, **kw):
     22         super(CorpCheckoutPanel, self).__init__(**kw)
     23         self._current_balance = 0
     24         self._construct_layout()
     25         paintToolSignals.on_structure_selection_changed.connect(self._on_structure_selection_changed)
     26         paintToolSignals.on_duration_selection_changed.connect(self._on_duration_selection_changed)
     27         sm.RegisterNotify(self)
     28 
     29     def Close(self):
     30         paintToolSignals.on_structure_selection_changed.disconnect(self._on_structure_selection_changed)
     31         paintToolSignals.on_duration_selection_changed.disconnect(self._on_duration_selection_changed)
     32         super(CorpCheckoutPanel, self).Close()
     33 
     34     def update(self):
     35         self._update_total_price()
     36         self._update_balance()
     37 
     38     def _construct_layout(self):
     39         left_cont = Container(parent=self, name='leftCont', align=uiconst.TOLEFT_PROP, width=0.5)
     40         Sprite(parent=left_cont, name='evermarksBalanceIcon', align=uiconst.TOLEFT, texturePath='res:/UI/Texture/Icons/evermarks_trimmed.png', width=BALANCE_ICON_SIZE, height=BALANCE_ICON_SIZE)
     41         balance_parent_cont = Container(parent=left_cont, name='balanceParentCont', align=uiconst.TOALL, padLeft=15)
     42         EveLabelMedium(parent=balance_parent_cont, name='balanceTitle', align=uiconst.TOTOP, text=GetByLabel('UI/Personalization/PaintTool/EvermarksBalance'))
     43         balance_cont = Container(parent=balance_parent_cont, name='balanceCont', align=uiconst.TOALL)
     44         balance_label_cont = ContainerAutoSize(parent=balance_cont, name='balanceLabelCont', align=uiconst.TOLEFT)
     45         self._balance_label = EveCaptionMedium(parent=balance_label_cont, name='balanceLabel', align=uiconst.CENTER, padRight=4)
     46         icon_center_cont = Container(parent=balance_cont, name='iconCenterCont', align=uiconst.TOLEFT, width=32)
     47         self._insufficient_funds_icon = Sprite(parent=icon_center_cont, name='insufficientFundsIcon', align=uiconst.CENTER, width=32, height=32, texturePath='res:/UI/Texture/classes/paintTool/insufficient_funds.png', opacity=0, state=uiconst.UI_NORMAL, hint=GetByLabel('UI/Personalization/PaintTool/InsufficientFundsTooltip'))
     48         self._update_balance()
     49         right_cont = Container(parent=self, name='rightCont', align=uiconst.TORIGHT_PROP, width=0.5)
     50         EveLabelMedium(parent=right_cont, name='totalTitle', align=uiconst.TOTOP, textAlign=TextAlign.RIGHT, text=GetByLabel('UI/Personalization/PaintTool/TotalCostTitle'))
     51         total_cont = Container(parent=right_cont, name='totalCont', align=uiconst.TOBOTTOM, height=TOTAL_ICON_SIZE)
     52         total_label_cont = ContainerAutoSize(parent=total_cont, name='totalLabelCont', align=uiconst.TORIGHT)
     53         self._total_label = EveCaptionMedium(parent=total_label_cont, name='balanceLabel', align=uiconst.CENTER, text=FmtAmt(0))
     54         Sprite(parent=total_cont, name='evermarksTotalIcon', align=uiconst.TORIGHT, texturePath='res:/UI/Texture/Icons/evermarks_trimmed.png', width=TOTAL_ICON_SIZE, height=TOTAL_ICON_SIZE, padRight=12)
     55 
     56     def _on_structure_selection_changed(self, *_args):
     57         self._update_total_price()
     58 
     59     def _on_duration_selection_changed(self):
     60         self._update_total_price()
     61 
     62     def _update_total_price(self):
     63         self._total_label.text = FmtAmt(paintToolUtils.get_total_price())
     64         self._update_balance()
     65 
     66     def _update_balance(self, animate = False):
     67         balance = paintToolUtils.get_evermark_balance()
     68         if animate:
     69             original_balance = self._current_balance if self._current_balance else 0
     70             self._animate_balance_change(balance, original_balance)
     71         else:
     72             self._balance_label.text = FmtAmt(balance)
     73         self._current_balance = balance
     74         insufficient_funds = not paintToolUtils.has_sufficient_funds()
     75         target_color = eveColor.DANGER_RED if insufficient_funds else TextColor.NORMAL
     76         target_opacity = 1.0 if insufficient_funds else 0.0
     77         animations.FadeTo(self._insufficient_funds_icon, self._insufficient_funds_icon.opacity, target_opacity, 0.25)
     78         animations.SpColorMorphTo(self._balance_label, self._balance_label.GetRGBA(), target_color, duration=0.25)
     79 
     80     def OnCorporationLPBalanceChange_Local(self, issuerCorpID):
     81         if issuerCorpID == corpHeraldry:
     82             self._update_balance(animate=True)
     83 
     84     def _animate_balance_change(self, balance, original_balance):
     85         total_iterations = 20
     86         difference = balance - original_balance
     87         for i in range(total_iterations):
     88             increment = (i + 1) / (1.0 * total_iterations)
     89             value = original_balance + difference * increment
     90             self._balance_label.text = FmtAmt(value)
     91             blue.synchro.Sleep(25)