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

plexTab.py (3803B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\neocom\wallet\tabs\plexTab.py
      2 import logging
      3 import uthread2
      4 from carbon.common.script.util.format import FmtAmt
      5 from carbonui import uiconst, Align
      6 from carbonui.uianimations import animations
      7 from carbonui.uicore import uicore
      8 from carbonui.util.color import Color
      9 from eve.client.script.ui.control.buttons import ButtonTextBoldness
     10 from eve.client.script.ui.plex.textures import PLEX_128_GRADIENT_YELLOW
     11 from eve.client.script.ui.control.eveLoadingWheel import LoadingWheel
     12 from eve.client.script.ui.shared.neocom.wallet.tabs.baseWalletTab import BaseWalletTab
     13 from fastcheckout.client.purchasepanels.purchaseButton import SecondaryPurchaseButton
     14 from fastcheckout.const import FROM_WALLET_PLUS_BUTTON
     15 from localization import GetByLabel
     16 from plex.client.api.repository import get_repository
     17 from plex.client.api.signal import on_balance_changed
     18 from signals import Signal
     19 logger = logging.getLogger(__name__)
     20 
     21 class PlexTab(BaseWalletTab):
     22     default_name = 'PlexTab'
     23     default_texturePath = PLEX_128_GRADIENT_YELLOW
     24     tabNamePath = 'UI/Common/PLEX'
     25     default_underlayColor = Color.HextoRGBA('#E7B24C')
     26     labelColor = Color.HextoRGBA('#FAB400')
     27     default_hint = GetByLabel('UI/Wallet/WalletWindow/PLEXDescription')
     28     default_padding = (2, 2, 2, 2)
     29     failed_to_load_plex_balance = Signal('failed_to_load_plex_balance')
     30 
     31     def __init__(self, *args, **kwargs):
     32         super(PlexTab, self).__init__(*args, **kwargs)
     33         self._update_thread = uthread2.start_tasklet(self._get_balance_thread)
     34         on_balance_changed.connect(self._on_balance_changed)
     35 
     36     def _kill_update_thread(self):
     37         if self._update_thread is not None:
     38             self._update_thread.kill()
     39             self._update_thread = None
     40 
     41     def Close(self):
     42         self._kill_update_thread()
     43         on_balance_changed.disconnect(self._on_balance_changed)
     44         super(PlexTab, self).Close()
     45 
     46     def PopulateBottomContainer(self):
     47         buyPlexButtonTextColor = Color.WHITE
     48         buyPlexButtonSize = 20
     49         self.buyPlexButton = SecondaryPurchaseButton(name='buyPlexButton_+', parent=self.bottomContainer, align=uiconst.CENTERRIGHT, width=buyPlexButtonSize, height=buyPlexButtonSize, left=6, func=lambda *args: uicore.cmd.CmdBuyPlex(logContext=FROM_WALLET_PLUS_BUTTON), text=GetByLabel('UI/Wallet/WalletWindow/BuyPlex'), hint=GetByLabel('UI/VirtualGoodsStore/Buttons/BuyPlex'), mouseUpTextColor=buyPlexButtonTextColor, mouseEnterTextColor=buyPlexButtonTextColor, mouseDownTextColor=buyPlexButtonTextColor, disabledTextColor=buyPlexButtonTextColor, boldText=ButtonTextBoldness.NEVER_BOLD)
     50         self.bottomLabel.SetRGBA(*Color.HextoRGBA('#FAB400'))
     51 
     52     def ConstructBottomContainer(self):
     53         super(PlexTab, self).ConstructBottomContainer()
     54         self._loading_wheel = LoadingWheel(name='loading_wheel', parent=self.bottomContainer, align=Align.CENTERLEFT, width=16, height=16)
     55 
     56     def _get_balance_thread(self):
     57         try:
     58             balance = get_repository().get_balance()
     59             self._set_balance(balance)
     60         except Exception as e:
     61             logger.error('could not get PLEX balance: %s' % e)
     62             self._set_balance_error()
     63         finally:
     64             animations.FadeOut(self._loading_wheel)
     65 
     66     def _set_balance(self, balance):
     67         self.bottomLabel.SetText(FmtAmt(balance))
     68 
     69     def _set_balance_error(self):
     70         self.bottomLabel.SetText(GetByLabel('UI/PlexVault/BalanceUnavailable'))
     71         self.bottomLabel.SetHint(GetByLabel('UI/PlexVault/PlexTabUnavailable'))
     72         self.bottomLabel.pickState = uiconst.TR2_SPS_ON
     73         self.failed_to_load_plex_balance()
     74 
     75     def _on_balance_changed(self, balance, _):
     76         self._set_balance(balance)