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

giveIskPanel.py (8290B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\neocom\wallet\panels\personal\giveIskPanel.py
      2 from carbon.common.script.util.format import FmtAmt
      3 from carbonui import uiconst
      4 from carbonui.control.combo import Combo
      5 from carbonui.control.singlelineedits.singleLineEditFloat import SingleLineEditFloat
      6 from carbonui.primitives.container import Container
      7 from carbonui.primitives.containerAutoSize import ContainerAutoSize
      8 from carbonui.primitives.layoutGrid import LayoutGrid
      9 from carbonui.primitives.sprite import Sprite
     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.eveLabel import EveLabelMedium, EveLabelLarge
     16 from eve.client.script.ui.control.searchinput import SearchInput
     17 from eve.client.script.ui.control.themeColored import FillThemeColored
     18 from eve.client.script.ui.shared.userentry import User
     19 from eve.client.script.ui.util import searchUtil
     20 from eve.common.script.search.const import MatchBy
     21 from localization import GetByLabel
     22 from player_messaging.client.ui_message import prompt_player_fsd_dialog
     23 from qtyTooltip.qtyConst import EDIT_INPUT_TYPE_ISK
     24 from qtyTooltip.tooltip import GetQtyText
     25 MAX_NAME_LENGTH = 64
     26 
     27 class GiveIskPanel(Container):
     28     __notifyevents__ = ['OnPersonalAccountChangedClient']
     29     default_name = 'GiveIskPanel'
     30 
     31     def ApplyAttributes(self, attributes):
     32         super(GiveIskPanel, self).ApplyAttributes(attributes)
     33         sm.RegisterNotify(self)
     34         self.photoSvc = sm.GetService('photo')
     35         self.walletSvc = sm.GetService('wallet')
     36         self.selectedCharacterID = None
     37         self.minISKvalue = 0.1
     38         self.maxISKvalue = self.walletSvc.GetWealth()
     39         self.ConstructLayout()
     40 
     41     def ConstructLayout(self):
     42         self.mainCont = ContainerAutoSize(name='mainCont', align=uiconst.CENTERTOP, alignMode=uiconst.TOTOP, width=360, parent=self)
     43         self.searchInputCont = Container(parent=self.mainCont, name='searchInputCont', height=32, padTop=14, align=uiconst.TOTOP)
     44         self.resultParCont = ContainerAutoSize(name='resultParCont', parent=self.mainCont, align=uiconst.TOTOP)
     45         self.ConstructSearchTermsCombo()
     46         self.ConstructSearchInput()
     47         self.ConstructErrorLabel()
     48         self.ConstructResultContainer()
     49         self.ConstructAmountContainer()
     50         self.ConstructAmountLabel()
     51         self.ConstructTransferButton()
     52 
     53     def ConstructAmountLabel(self):
     54         self.amountLabel = EveLabelMedium(parent=self.mainCont, align=uiconst.TOTOP_NOPUSH, opacity=0.75)
     55 
     56     def OnAmountFocusLost(self, amountInput):
     57         self.UpdateAmountLabel(amountInput.text)
     58 
     59     def OnPersonalAccountChangedClient(self, newBalance, transaction):
     60         self._UpdateMaxISKValue(newBalance)
     61 
     62     def _UpdateMaxISKValue(self, value):
     63         self.maxISKvalue = value
     64         if self.amountInput:
     65             self.amountInput.SetMaxValue(self.maxISKvalue)
     66 
     67     def UpdateAmountLabel(self, amount):
     68         if not amount:
     69             return
     70         self.amountLabel.SetText(GetQtyText(float(amount), EDIT_INPUT_TYPE_ISK))
     71 
     72     def ConstructAmountContainer(self):
     73         self.amountInput = SingleLineEditFloat(name='iskAmountInput', parent=self.mainCont, align=uiconst.TOTOP, padTop=48, hintText=GetByLabel('UI/Wallet/WalletWindow/ISK'), minValue=self.minISKvalue, maxValue=self.maxISKvalue, decimalPlaces=2, OnChange=self.UpdateAmountLabel, OnFocusLost=self.OnAmountFocusLost, label=GetByLabel('UI/Wallet/WalletWindow/GiveAmount'))
     74 
     75     def ConstructTransferButton(self):
     76         cont = ContainerAutoSize(parent=self.mainCont, align=uiconst.TOTOP, padTop=32)
     77         grid = LayoutGrid(parent=cont, columns=2, cellSpacing=(16, 0))
     78         self.transferButton = Button(name='transferButton', parent=grid, align=uiconst.CENTERLEFT, label=GetByLabel('UI/HangarTransfer/TransferBtn'), func=self.TransferISK)
     79         self.transferButton.Disable()
     80         self.successLabel = EveLabelLarge(parent=grid, align=uiconst.CENTERLEFT, color=eveColor.SUCCESS_GREEN, text=GetByLabel('UI/Wallet/WalletWindow/TransferSuccessful'), opacity=0.0)
     81 
     82     def TransferISK(self, *args):
     83         amount = self.amountInput.GetValue()
     84         if amount <= 0:
     85             return
     86         message = GetByLabel('UI/Wallet/WalletWindow/TransactionConfirmation', amount=FmtAmt(amount), player=self.selectedCharacterID)
     87         if prompt_player_fsd_dialog('AskAreYouSure', {'cons': message}, uiconst.YESNO) != uiconst.ID_YES:
     88             return
     89         ret = sm.RemoteSvc('account').GiveCash(self.selectedCharacterID, amount)
     90         if ret:
     91             self.ResetSearch()
     92             self.amountInput.SetValue(0)
     93             animations.FadeIn(self.successLabel)
     94 
     95     def ConstructSearchInput(self):
     96         self.searchInput = SearchInput(parent=self.searchInputCont, align=uiconst.TOALL, pos=(0, 0, 0, 0), GetSearchEntries=self.SearchForCharacter, maxLength=MAX_NAME_LENGTH, OnSearchEntrySelected=self.OnSearchEntrySelected, hintText=GetByLabel('UI/ActivatePlex/SearchHint'), allowBrowsing=True, isCharacterField=True, label=GetByLabel('UI/Wallet/WalletWindow/TransferTo'))
     97         self.searchInput.SetHistoryVisibility(False)
     98 
     99     def ConstructResultContainer(self):
    100         self.resultContainer = Container(name='resultContainer', parent=self.resultParCont, align=uiconst.TOTOP, height=44, padTop=2, state=uiconst.UI_HIDDEN)
    101         FillThemeColored(bgParent=self.resultContainer, colorType=uiconst.COLORTYPE_UIBASECONTRAST)
    102         self.resultIcon = Sprite(name='resultIcon', parent=self.resultContainer, align=uiconst.CENTERLEFT, pos=(2, 0, 42, 42))
    103         self.characterNameLabel = EveLabelMedium(parent=self.resultContainer, align=uiconst.CENTERLEFT, text='', width=150, left=50)
    104         self.entryContainerButton = ButtonIcon(parent=self.resultContainer, texturePath='res:/UI/Texture/Icons/73_16_210.png', align=uiconst.TOPRIGHT, func=self.ResetSearch, width=7, height=7, iconSize=14, left=5, top=5)
    105 
    106     def ConstructSearchTermsCombo(self):
    107         self.searchTermsCombo = Combo(label=GetByLabel('UI/Common/SearchBy'), parent=self.searchInputCont, options=searchUtil.GetSearchByChoices(), name='walletGiveISKComboSearchBy', select=settings.user.ui.Get('ppSearchBy', MatchBy.partial_terms), width=115, align=uiconst.TORIGHT, padLeft=8, callback=self.ChangeSearchBy)
    108 
    109     def ConstructErrorLabel(self):
    110         self.errorLabel = EveLabelMedium(name='errorLabel', parent=self.mainCont, align=uiconst.TOTOP_NOPUSH, text=GetByLabel('UI/Common/NothingFound'), color=eveColor.WARNING_ORANGE, opacity=0.75, state=uiconst.UI_HIDDEN)
    111 
    112     def ChangeSearchBy(self, entry, header, value, *args):
    113         settings.user.ui.Set('ppSearchBy', value)
    114 
    115     def ResetSearch(self, *args, **kwargs):
    116         self.searchInputCont.Show()
    117         self.resultContainer.Hide()
    118         self.searchTermsCombo.Show()
    119         self.transferButton.Disable()
    120         self.selectedCharacterID = None
    121         uicore.registry.SetFocus(self.searchInput)
    122 
    123     def OnSearchEntrySelected(self, result):
    124         if isinstance(result, User):
    125             result = result.sr.node
    126         else:
    127             result = result[0]
    128         self.selectedCharacterID = result.charID
    129         self.photoSvc.GetPortrait(self.selectedCharacterID, size=64, sprite=self.resultIcon)
    130         self.characterNameLabel.SetText(result.label)
    131         self.searchInput.SetValue('')
    132         self.successLabel.SetAlpha(0)
    133         self.searchInputCont.Hide()
    134         self.resultContainer.Show()
    135         self.searchTermsCombo.Hide()
    136         self.transferButton.Enable()
    137         self.searchInput.CloseResultMenu()
    138 
    139     def SearchForCharacter(self, search_string):
    140         if len(search_string) < 3:
    141             return []
    142         else:
    143             searchTerms = settings.user.ui.Get('ppSearchBy', MatchBy.partial_terms)
    144             validCharacters = searchUtil.SearchCharacters(search_string, searchBy=searchTerms)
    145             if not validCharacters:
    146                 self.ShowNoResultsError()
    147             else:
    148                 self.errorLabel.Hide()
    149             return validCharacters
    150 
    151     def ShowNoResultsError(self):
    152         self.errorLabel.Show()