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

wallet_balance.py (5202B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\market\wallet_balance.py
      2 import eveformat
      3 import eveicon
      4 import eveui
      5 import localization
      6 from carbonui import TextColor, uiconst
      7 from carbonui.control.buttonIcon import ButtonIcon
      8 from carbonui.control.contextMenu.menuData import MenuData
      9 from carbonui.primitives.containerAutoSize import ContainerAutoSize
     10 from carbonui.primitives.layoutGrid import LayoutGrid
     11 from clientsettings.setting import CharSettingEnum
     12 from carbonui.uianimations import animations
     13 from eve.client.script.ui import eveColor
     14 from eve.client.script.ui.control import eveLabel
     15 from eve.client.script.ui.shared.neocom.wallet.walletUtil import HaveAccessToCorpWallet, HaveReadAccessToCorpWalletDivision
     16 from eve.client.script.ui.shared.neocom.wallet.walletWnd import WalletWindow
     17 
     18 class Wallet(object):
     19     PERSONAL = 1
     20     CORPORATION = 2
     21     _ALL = (PERSONAL, CORPORATION)
     22 
     23     @classmethod
     24     def all(cls):
     25         return list(cls._ALL)
     26 
     27     @classmethod
     28     def iter(cls):
     29         iter(cls._ALL)
     30 
     31     @classmethod
     32     def from_owner_and_account_key(cls, owner, account_key):
     33         if owner == session.charid:
     34             return cls.PERSONAL
     35         if owner == session.corpid:
     36             return cls.CORPORATION
     37 
     38 
     39 selected_wallet_setting = CharSettingEnum(settings_key='selected_market_wallet_balance', options=Wallet.all(), default_value=Wallet.PERSONAL)
     40 
     41 def get_wallet_balance_options_menu():
     42     menu = MenuData()
     43     wallet_menu = MenuData()
     44     menu.AddEntry(text=localization.GetByLabel('UI/Market/WalletBalanceOptionsMenuTitle'), subMenuData=wallet_menu, texturePath=eveicon.isk)
     45     wallet_menu.AddRadioButton(text=localization.GetByLabel('UI/Market/PersonalWallet'), value=Wallet.PERSONAL, setting=selected_wallet_setting)
     46     wallet_menu.AddRadioButton(text=localization.GetByLabel('UI/Market/CorporationWallet'), value=Wallet.CORPORATION, setting=selected_wallet_setting)
     47     return menu
     48 
     49 
     50 class WalletBalance(ContainerAutoSize):
     51     __notifyevents__ = ('OnAccountChange_Local', 'OnSessionChanged')
     52     _balance = None
     53     _balance_label = None
     54     _caption_label = None
     55     BALANCE_TEXT_COLOR = TextColor.SECONDARY
     56 
     57     def __init__(self, **kwargs):
     58         self._balance = self._get_current_balance()
     59         super(WalletBalance, self).__init__(**kwargs)
     60         self._layout()
     61         selected_wallet_setting.on_change.connect(self._on_selected_wallet_setting_changed)
     62         sm.RegisterNotify(self)
     63 
     64     @property
     65     def balance(self):
     66         return self._balance
     67 
     68     @balance.setter
     69     def balance(self, value):
     70         if self._balance != value:
     71             self._balance = value
     72             self._update_balance()
     73 
     74     def animate_balance_to(self, value):
     75         if value > self._balance:
     76             color = eveColor.SUCCESS_GREEN
     77         else:
     78             color = eveColor.WARNING_ORANGE
     79         animations.SpColorMorphTo(self._balance_label, startColor=color, endColor=self.BALANCE_TEXT_COLOR, duration=0.75)
     80         eveui.animate(self, 'balance', start_value=self.balance or 0.0, end_value=value, duration=0.75)
     81 
     82     def _layout(self):
     83         grid = LayoutGrid(parent=self, align=uiconst.CENTERLEFT, columns=2, cellSpacing=(4, 4))
     84         ButtonIcon(parent=grid, align=uiconst.CENTER, width=24, height=24, iconSize=16, texturePath=eveicon.isk, func=WalletWindow.Open, hint=localization.GetByLabel('UI/Commands/OpenWallet'))
     85         self._balance_label = eveLabel.EveLabelMedium(parent=grid, align=uiconst.CENTERLEFT, text=self._get_balance_text(), color=self.BALANCE_TEXT_COLOR)
     86 
     87     def _get_current_balance(self):
     88         wallet = selected_wallet_setting.get()
     89         if wallet == Wallet.PERSONAL:
     90             return sm.GetService('wallet').GetWealth()
     91         if wallet == Wallet.CORPORATION:
     92             if not self._have_access_to_corporation_wallet():
     93                 return None
     94             return sm.GetService('wallet').GetCorpWealth()
     95 
     96     def _have_access_to_corporation_wallet(self):
     97         if not HaveAccessToCorpWallet():
     98             return False
     99         account_key = session.corpAccountKey
    100         if account_key is None or not HaveReadAccessToCorpWalletDivision(account_key):
    101             return False
    102         return True
    103 
    104     def _get_balance_text(self):
    105         if self._balance is None:
    106             return eveformat.color(localization.GetByLabel('UI/Market/WalletBalanceUnavailable'), TextColor.DISABLED)
    107         return eveformat.isk(self._balance)
    108 
    109     def _update_balance(self):
    110         self._balance_label.text = self._get_balance_text()
    111 
    112     def _on_selected_wallet_setting_changed(self, value):
    113         self._update_displayed_wallet()
    114 
    115     def _update_displayed_wallet(self):
    116         self._balance = self._get_current_balance()
    117         self._update_balance()
    118 
    119     def OnAccountChange_Local(self, account_key, owner_id, balance):
    120         wallet = Wallet.from_owner_and_account_key(owner_id, account_key)
    121         if wallet == selected_wallet_setting.get():
    122             self.animate_balance_to(self._get_current_balance())
    123 
    124     def OnSessionChanged(self, is_remote, session, change):
    125         if 'corpAccountKey' in change:
    126             self._update_displayed_wallet()