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

donateLPPanel.py (15349B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\neocom\wallet\panels\donateLPPanel.py
      2 from featuremanagement.client.flag import flag_bool
      3 from carbon.common.script.util.format import FmtAmt
      4 from carbonui import uiconst
      5 from carbonui.control.combo import Combo
      6 from carbonui.control.singlelineedits.singleLineEditInteger import SingleLineEditInteger
      7 from carbonui.primitives.container import Container
      8 from carbonui.primitives.containerAutoSize import ContainerAutoSize
      9 from carbonui.primitives.layoutGrid import LayoutGrid
     10 from carbonui.uianimations import animations
     11 from carbonui.uicore import uicore
     12 from eve.client.script.ui import eveColor
     13 from carbonui.control.buttonIcon import ButtonIcon
     14 from carbonui.control.button import Button
     15 from eve.client.script.ui.control.eveIcon import CorpIcon
     16 from eve.client.script.ui.control.eveLabel import EveLabelMedium, EveLabelLarge
     17 from eve.client.script.ui.control.searchinput import SearchInput
     18 from eve.client.script.ui.control.themeColored import FillThemeColored
     19 from eve.client.script.ui.shared.userentry import User
     20 from eve.client.script.ui.util import searchUtil
     21 from eve.common.script.search.const import MatchBy
     22 from eveexceptions import UserError
     23 from localization import GetByLabel
     24 from lpOffers.exceptions import TransfersDisabledError
     25 from player_messaging.client.ui_message import prompt_player_fsd_dialog
     26 MAX_NAME_LENGTH = 64
     27 
     28 class DonateLPPanel(Container):
     29     default_name = 'donateLPPanel'
     30     killSwitchKey = None
     31     killSwitchDefault = None
     32     killSwitchLabel = 'UI/Wallet/WalletWindow/TransferFailedTransactionsDisabled'
     33 
     34     def __init__(self, **kw):
     35         self._amount_input = None
     36         self._transaction_result_label = None
     37         self._search_input_cont = None
     38         self._search_by_combo = None
     39         self._search_input = None
     40         self._result_cont = None
     41         self._result_icon = None
     42         self._corp_name_label = None
     43         self._transfer_button = None
     44         self._issuer_corp_combo = None
     45         self._can_make_donations = True
     46         self._evaluate_can_make_donations()
     47         self._initialize_selected_corp_id()
     48         self._selected_issuer_corp_id = self._get_selected_issuer_corp_id_setting()
     49         super(DonateLPPanel, self).__init__(**kw)
     50 
     51     def _initialize_selected_corp_id(self):
     52         self._selected_corp_id = None
     53 
     54     def _evaluate_can_make_donations(self):
     55         self._can_make_donations = True
     56 
     57     def ApplyAttributes(self, attributes):
     58         super(DonateLPPanel, self).ApplyAttributes(attributes)
     59         self._init_killswitch()
     60         sm.RegisterNotify(self)
     61         self._construct_main_cont()
     62         self._construct_layout_full()
     63         self._reset_search()
     64         self._update_amount_input()
     65 
     66     def _init_killswitch(self):
     67         if self.killSwitchKey is None or self.killSwitchDefault is None:
     68             self._killswitch = False
     69         self._killswitch = self.killSwitchDefault
     70         flag_bool(key=self.killSwitchKey, default_value=self.killSwitchDefault, callback=self._on_killswitch_changed)
     71 
     72     def OnTabSelect(self):
     73         self.on_tab_select()
     74 
     75     def _get_selected_issuer_corp_id_setting(self):
     76         raise NotImplementedError
     77 
     78     def _set_selected_issuer_corp_id_setting(self, value):
     79         raise NotImplementedError
     80 
     81     def _construct_layout_full(self):
     82         if not self._can_make_donations:
     83             return
     84         self._construct_search_input()
     85         self._construct_error()
     86         self._construct_search_result()
     87         self._construct_amount()
     88         self._construct_transfer_button()
     89 
     90     def _construct_main_cont(self):
     91         if not self._can_make_donations:
     92             self._construct_main_cont_restricted()
     93         else:
     94             self._construct_main_cont_full()
     95 
     96     def _construct_main_cont_full(self):
     97         self._main_cont = ContainerAutoSize(name='mainCont', align=uiconst.TOLEFT_PROP, alignMode=uiconst.TOTOP, width=0.5, parent=self)
     98 
     99     def _construct_main_cont_restricted(self):
    100         self._main_cont = Container(name='mainCont', align=uiconst.TOALL, parent=self)
    101 
    102     def on_tab_select(self):
    103         self._hide_transaction_result_label()
    104 
    105     def _construct_search_input(self):
    106         if not self._can_make_donations:
    107             return
    108         self._search_input_cont = Container(parent=self._main_cont, name='searchInputCont', height=32, padTop=14, align=uiconst.TOTOP)
    109         self._search_by_combo = Combo(label=GetByLabel('UI/Common/SearchBy'), parent=self._search_input_cont, options=searchUtil.GetSearchByChoices(), name='searchCombo', select=settings.user.ui.Get('ppSearchBy', MatchBy.partial_terms), width=0.4, align=uiconst.TORIGHT_PROP, padLeft=8, callback=self._change_search_by)
    110         self._search_input = SearchInput(parent=self._search_input_cont, name='searchInput', align=uiconst.TOLEFT_PROP, width=0.6, GetSearchEntries=self._search_for_corporation, maxLength=MAX_NAME_LENGTH, OnSearchEntrySelected=self._on_search_entry_selected, hintText=GetByLabel('UI/Wallet/WalletWindow/SearchForCorpHint'), allowBrowsing=True, isCharacterField=True, label=GetByLabel('UI/Wallet/WalletWindow/TransferTo'))
    111         self._search_input.SetHistoryVisibility(False)
    112 
    113     def _search_for_corporation(self, search_string):
    114         if len(search_string) < 3:
    115             self._show_no_results_error(False)
    116             return []
    117         else:
    118             search_terms = settings.user.ui.Get('ppSearchBy', MatchBy.partial_terms)
    119             valid_corps = searchUtil.SearchCorporations(search_string, searchBy=search_terms)
    120             valid_corps = self._filter_valid_corps(valid_corps)
    121             self._show_no_results_error(not valid_corps)
    122             return valid_corps
    123 
    124     def _filter_valid_corps(self, corps):
    125         raise NotImplementedError
    126 
    127     def _change_search_by(self, _entry, _header, value, *args):
    128         settings.user.ui.Set('ppSearchBy', value)
    129 
    130     def _construct_search_result(self):
    131         self._result_cont = Container(name='resultCont', parent=self._main_cont, align=uiconst.TOTOP, height=44, padTop=2)
    132         FillThemeColored(bgParent=self._result_cont, colorType=uiconst.COLORTYPE_UIBASECONTRAST)
    133         self._result_icon = CorpIcon(corpID=self._selected_corp_id, parent=self._result_cont, align=uiconst.CENTERLEFT, pos=(2, 0, 42, 42))
    134         self._corp_name_label = EveLabelMedium(parent=self._result_cont, name='corpNameLabel', align=uiconst.CENTERLEFT, text=cfg.eveowners.Get(self._selected_corp_id).name if self._selected_corp_id else '', width=150, left=50)
    135         self._construct_reset_search_button()
    136 
    137     def _construct_reset_search_button(self):
    138         if not self._can_make_donations:
    139             return
    140         ButtonIcon(parent=self._result_cont, name='resetButton', texturePath='res:/UI/Texture/Icons/73_16_210.png', align=uiconst.TOPRIGHT, func=self._reset_search, width=7, height=7, iconSize=14, left=5, top=5)
    141 
    142     def _reset_search(self, *args, **kwargs):
    143         self._reset_search_result()
    144         if self._search_input_cont:
    145             self._search_input_cont.Show()
    146         if self._search_by_combo:
    147             self._search_by_combo.Show()
    148         self._update_transfer_button()
    149         if self._search_input:
    150             uicore.registry.SetFocus(self._search_input)
    151 
    152     def _reset_search_result(self):
    153         if not self._can_make_donations:
    154             return
    155         self._selected_corp_id = None
    156         if self._result_cont:
    157             self._result_cont.Hide()
    158 
    159     def _on_search_entry_selected(self, result):
    160         if isinstance(result, User):
    161             result = result.sr.node
    162         else:
    163             result = result[0]
    164         self._selected_corp_id = result.itemID
    165         self._show_search_result()
    166 
    167     def _show_search_result(self):
    168         if self._result_icon:
    169             self._result_icon.Load(self._selected_corp_id)
    170         if self._corp_name_label:
    171             self._corp_name_label.text = cfg.eveowners.Get(self._selected_corp_id).name
    172         if self._search_input:
    173             self._search_input.SetValue('')
    174         self._hide_transaction_result_label()
    175         if self._search_input_cont:
    176             self._search_input_cont.Hide()
    177         if self._result_cont:
    178             self._result_cont.Show()
    179         if self._search_by_combo:
    180             self._search_by_combo.Hide()
    181         self._update_transfer_button()
    182         if self._search_input:
    183             self._search_input.CloseResultMenu()
    184 
    185     def _construct_error(self):
    186         self._error_label = EveLabelMedium(name='errorLabel', parent=self._main_cont, align=uiconst.TOTOP_NOPUSH, text=GetByLabel('UI/Common/NothingFound'), color=eveColor.WARNING_ORANGE, opacity=0.75, state=uiconst.UI_HIDDEN)
    187 
    188     def _show_no_results_error(self, show):
    189         self._error_label.display = show
    190 
    191     def _construct_amount(self):
    192         amount_cont = Container(parent=self._main_cont, name='amountCont', align=uiconst.TOTOP, height=32, padTop=48)
    193         self._issuer_corp_combo = Combo(parent=amount_cont, name='issuerCorpCombo', label=GetByLabel('UI/Common/Corporation'), width=0.6, align=uiconst.TOLEFT_PROP, callback=self._on_issuer_corp_changed)
    194         self._update_issuer_corp_options()
    195         self._amount_input = SingleLineEditInteger(name='lpAmountInput', parent=amount_cont, align=uiconst.TORIGHT_PROP, width=0.4, hintText=GetByLabel('UI/Wallet/WalletWindow/LP'), decimalPlaces=0, padLeft=8, label=GetByLabel('UI/Wallet/WalletWindow/GiveAmount'))
    196         self._amount_input.OnChange = self._on_amount_changed
    197 
    198     def _on_amount_changed(self, *args):
    199         self._update_transfer_button()
    200 
    201     def _update_issuer_corp_options(self):
    202         options = self._get_issuer_corp_list()
    203         if self._selected_issuer_corp_id is not None and self._selected_issuer_corp_id not in [ x for _, x in options ]:
    204             self._selected_issuer_corp_id = None
    205             if self._amount_input is not None:
    206                 self._amount_input.SetValue(0)
    207         if self._selected_issuer_corp_id is None and len(options) > 0:
    208             self._selected_issuer_corp_id = options[0][1]
    209         if self._issuer_corp_combo is not None:
    210             self._issuer_corp_combo.LoadOptions(options, self._selected_issuer_corp_id)
    211 
    212     def _get_balance(self, issuer_corp_id):
    213         raise NotImplementedError
    214 
    215     def _get_issuer_corp_list(self):
    216 
    217         def _sort_func(e):
    218             return e[0].lower()
    219 
    220         corp_ids = self._get_raw_issuer_corp_list()
    221         corp_ids = [ x for x in corp_ids if self._get_balance(x) > 0 ]
    222         corp_list = [ (cfg.eveowners.Get(corp_id).ownerName, corp_id) for corp_id in corp_ids ]
    223         corp_list.sort(key=_sort_func)
    224         return corp_list
    225 
    226     def _get_raw_issuer_corp_list(self):
    227         raise NotImplementedError
    228 
    229     def _on_issuer_corp_changed(self, _entry, _header, value, *args):
    230         self._set_selected_issuer_corp_id_setting(value)
    231         self._selected_issuer_corp_id = value
    232         self._update_amount_input()
    233         self._hide_transaction_result_label()
    234 
    235     def _update_amount_input(self):
    236         if self._amount_input is None:
    237             return
    238         max_lp_value = self._get_balance(self._selected_issuer_corp_id) if self._selected_issuer_corp_id is not None else 0
    239         if max_lp_value == 0:
    240             self._amount_input.enabled = False
    241             self._amount_input.SetMinValue(0)
    242             self._amount_input.SetMaxValue(0)
    243             self._amount_input.SetValue(0)
    244         else:
    245             self._amount_input.enabled = self._selected_issuer_corp_id is not None
    246             self._amount_input.SetMinValue(0)
    247             self._amount_input.SetMaxValue(max_lp_value)
    248             self._amount_input.SetValue(min(max_lp_value, self._amount_input.GetValue()))
    249 
    250     def _on_update_lp_balance(self):
    251         self._update_issuer_corp_options()
    252         self._update_amount_input()
    253 
    254     def _construct_transfer_button(self):
    255         cont = ContainerAutoSize(parent=self._main_cont, name='transferCont', align=uiconst.TOTOP, padTop=32)
    256         grid = LayoutGrid(parent=cont, name='transferGrid', columns=2, cellSpacing=(16, 0))
    257         self._transfer_button = Button(name='transferButton', parent=grid, align=uiconst.CENTER, label=GetByLabel('UI/HangarTransfer/TransferBtn'), func=self._transfer_lp)
    258         self._update_transfer_button()
    259         self._set_transfer_button_func()
    260         self._transaction_result_label = EveLabelLarge(parent=grid, name='transactionResultLabel', align=uiconst.CENTERLEFT, opacity=0.0)
    261 
    262     def _set_transfer_button_func(self):
    263         self._transfer_button.SetFunc(self._transfer_lp)
    264 
    265     def _update_transfer_button(self):
    266         if self._transfer_button:
    267             if self._selected_corp_id is None or self._selected_issuer_corp_id is None or self._amount_input.GetValue() <= 0:
    268                 self._transfer_button.Disable()
    269             else:
    270                 self._transfer_button.Enable()
    271 
    272     def _show_success_label(self):
    273         if self._transaction_result_label is None:
    274             return
    275         self._transaction_result_label.color = eveColor.SUCCESS_GREEN
    276         self._transaction_result_label.text = GetByLabel('UI/Wallet/WalletWindow/TransferSuccessful')
    277         animations.FadeIn(self._transaction_result_label)
    278 
    279     def _show_failure_label(self, label):
    280         if self._transaction_result_label is None:
    281             return
    282         self._transaction_result_label.color = eveColor.SUCCESS_GREEN
    283         self._transaction_result_label.text = label
    284         animations.FadeIn(self._transaction_result_label)
    285 
    286     def _hide_transaction_result_label(self):
    287         if self._transaction_result_label is None:
    288             return
    289         animations.FadeOut(self._transaction_result_label)
    290 
    291     def _get_confirmation_message(self, amount):
    292         return GetByLabel('UI/Wallet/WalletWindow/CorpLPTransactionConfirmation', amount=FmtAmt(amount), issuerCorpName=cfg.eveowners.Get(self._selected_issuer_corp_id).ownerName, corpName=cfg.eveowners.Get(self._selected_corp_id).name)
    293 
    294     def _check_killswitch_on(self):
    295         if self._killswitch is not None:
    296             return self._killswitch
    297         return False
    298 
    299     def _get_killswitch_label(self):
    300         return GetByLabel(self.killSwitchLabel)
    301 
    302     def _transfer_lp(self, *args):
    303         if self._check_killswitch_on():
    304             self._show_failure_label(self._get_killswitch_label())
    305             return
    306         amount = self._amount_input.GetValue() if self._amount_input else 0
    307         if amount <= 0:
    308             self._show_failure_label(GetByLabel('UI/Wallet/WalletWindow/TransferEmptyAmount'))
    309             return
    310         message = self._get_confirmation_message(amount)
    311         if prompt_player_fsd_dialog('AskAreYouSure', {'cons': message}, uiconst.YESNO) != uiconst.ID_YES:
    312             return
    313         try:
    314             self._do_transfer(amount)
    315             self._show_success_label()
    316         except TransfersDisabledError:
    317             self._show_failure_label(self._get_killswitch_label())
    318         except UserError as e:
    319             raise e
    320         except Exception:
    321             self._show_failure_label(GetByLabel('UI/Wallet/WalletWindow/TransferFailed'))
    322         finally:
    323             self._reset_search()
    324 
    325     def _do_transfer(self, amount):
    326         raise NotImplementedError
    327 
    328     def _on_killswitch_changed(self, evaluate_flag):
    329         self._killswitch = evaluate_flag()