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

lpExchangeDialog.py (6833B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\station\loyaltyPointStore\lpExchangeDialog.py
      2 import math
      3 import localization
      4 from carbon.common.script.util.format import FmtAmt
      5 from carbonui import Density, uiconst
      6 from carbonui.button.const import HEIGHT_COMPACT
      7 from carbonui.control.singlelineedits.singleLineEditInteger import SingleLineEditInteger
      8 from carbonui.control.window import Window
      9 from carbonui.primitives.container import Container
     10 from carbonui.primitives.containerAutoSize import ContainerAutoSize
     11 from eve.client.script.ui.control import eveLabel
     12 from carbonui.button.group import ButtonGroup
     13 from eve.client.script.ui.station.loyaltyPointStore.lpLabels import LPStoreEntryLabel
     14 from eve.common.lib import appConst as const
     15 ENTRY_HEIGHT = HEIGHT_COMPACT
     16 
     17 class LPExhangeDialog(Window):
     18     __guid__ = 'form.LPExhangeDialog'
     19     __notifyevents__ = ['OnLPStoreFilterChange', 'OnLPStoreCurrentPresetChange', 'OnLPStorePresetsChange']
     20     default_fixedWidth = 300
     21     default_fixedHeight = 225
     22     default_isMinimizable = False
     23     default_isCollapseable = False
     24     default_scope = uiconst.SCOPE_STATION
     25     default_captionLabelPath = 'UI/LPStore/LPExchangeDialogTitle'
     26     default_iconNum = 'res:/ui/Texture/WindowIcons/lpstore.png'
     27 
     28     def ApplyAttributes(self, attributes):
     29         super(LPExhangeDialog, self).ApplyAttributes(attributes)
     30         self.lpSvc = sm.GetService('lpstore')
     31         self.toCorpID = attributes.Get('toCorpID')
     32         self.toCorpName = cfg.eveowners.Get(self.toCorpID).ownerName
     33         self.fromCorpName = cfg.eveowners.Get(attributes.get('fromCorpID', const.ownerCONCORD)).ownerName
     34         self.currentFromCorpLPs = attributes.get('currentFromCorpLPs')
     35         self.currentToCorpLPs = attributes.get('currentToCorpLPs')
     36         self.exchangeRate = attributes.get('exchangeRate')
     37         self.maxCorporationLPs = int(self.currentFromCorpLPs * self.exchangeRate)
     38         self.mainCont = ContainerAutoSize(name='mainCont', parent=self.sr.main, align=uiconst.TOTOP, callback=self.OnMainContResized)
     39         eveLabel.EveLabelMedium(parent=self.mainCont, align=uiconst.TOTOP, text=localization.GetByLabel('UI/LPStore/ConvertLPMsg', toCorpName=self.toCorpName, exchangeRate=self.exchangeRate, fromCorpName=self.fromCorpName))
     40         eveLabel.EveCaptionSmall(parent=self.mainCont, text=self.toCorpName, padTop=16, align=uiconst.TOTOP)
     41         cont = Container(name='toCorpLPAmountContainer', parent=self.mainCont, align=uiconst.TOTOP, height=ENTRY_HEIGHT, state=uiconst.UI_PICKCHILDREN, padTop=4)
     42         eveLabel.EveLabelMedium(parent=cont, text=localization.GetByLabel('UI/LPStore/ExchangePurchaseAmount'), align=uiconst.CENTERLEFT)
     43         eveLabel.EveLabelMedium(parent=cont, text=localization.GetByLabel('UI/LPStore/LP'), align=uiconst.TORIGHT)
     44         self.amountEdit = SingleLineEditInteger(name='lpAmountEdit', parent=cont, pos=(17, 0, 80, 0), maxValue=self.maxCorporationLPs, align=uiconst.TOPRIGHT, OnChange=self.OnChangeEdit, density=Density.COMPACT)
     45         zeroLP = 0.0
     46         cont = Container(name='toCorpCurrentLPContainer', parent=self.mainCont, align=uiconst.TOTOP, height=ENTRY_HEIGHT, padTop=4)
     47         eveLabel.EveLabelMedium(parent=cont, text=localization.GetByLabel('UI/Common/Current'), align=uiconst.CENTERLEFT)
     48         self.toCorpCurrentLP = eveLabel.EveLabelMedium(parent=cont, text=localization.GetByLabel('UI/LPStore/AmountLP', lpAmount=str(FmtAmt(zeroLP))), align=uiconst.CENTERRIGHT)
     49         cont = Container(name='toCorpTotalLPContainer', parent=self.mainCont, align=uiconst.TOTOP, height=ENTRY_HEIGHT, padTop=4)
     50         eveLabel.EveLabelMedium(parent=cont, text=localization.GetByLabel('UI/Common/Total'), align=uiconst.CENTERLEFT)
     51         self.toCorpTotalLP = eveLabel.EveLabelMedium(parent=cont, text=localization.GetByLabel('UI/LPStore/AmountLP', lpAmount=str(FmtAmt(zeroLP))), align=uiconst.CENTERRIGHT)
     52         eveLabel.EveCaptionSmall(parent=self.mainCont, text=self.fromCorpName, padTop=16, align=uiconst.TOTOP)
     53         cont = Container(name='fromCorpCostLPContainer', parent=self.mainCont, align=uiconst.TOTOP, height=ENTRY_HEIGHT, padTop=4)
     54         eveLabel.EveLabelMedium(parent=cont, text=localization.GetByLabel('UI/Common/Cost'), align=uiconst.CENTERLEFT)
     55         self.fromCorpCostLP = LPStoreEntryLabel(parent=cont, text=localization.GetByLabel('UI/LPStore/AmountLP', lpAmount=str(FmtAmt(zeroLP))), align=uiconst.CENTERRIGHT)
     56         cont = Container(name='fromCorpFinalLPContainer', parent=self.mainCont, align=uiconst.TOTOP, height=ENTRY_HEIGHT, padTop=4)
     57         eveLabel.EveLabelMedium(parent=cont, text=localization.GetByLabel('UI/Common/Remaining'), align=uiconst.CENTERLEFT)
     58         self.fromCorpFinalLP = LPStoreEntryLabel(parent=cont, text=localization.GetByLabel('UI/LPStore/AmountLP', lpAmount=str(FmtAmt(zeroLP))), align=uiconst.CENTERRIGHT)
     59         self.ConstructButtonGroup()
     60         self.SetDetails(1)
     61 
     62     def OnMainContResized(self):
     63         _, height = self.GetWindowSizeForContentSize(height=self.mainCont.height)
     64         self.SetFixedHeight(height)
     65 
     66     def ConstructButtonGroup(self):
     67         self.buttons = ButtonGroup(parent=self.mainCont, align=uiconst.TOTOP, padTop=16)
     68         self.buttons.AddButton(localization.GetByLabel('UI/Common/Buttons/OK'), self.OnOK)
     69         self.buttons.AddButton(localization.GetByLabel('UI/Common/Buttons/Cancel'), self.OnCancel)
     70 
     71     def SetDetails(self, lpToExchange):
     72         concordLPCost = int(math.ceil(lpToExchange / self.exchangeRate))
     73         concordLPAfter = self.currentFromCorpLPs - concordLPCost
     74         corporationLPAfter = self.currentToCorpLPs + lpToExchange
     75         self.fromCorpCostLP.SetText(localization.GetByLabel('UI/LPStore/AmountLP', lpAmount=FmtAmt(concordLPCost)))
     76         self.fromCorpFinalLP.SetText(localization.GetByLabel('UI/LPStore/AmountLP', lpAmount=FmtAmt(concordLPAfter)))
     77         self.toCorpTotalLP.SetText(localization.GetByLabel('UI/LPStore/AmountLP', lpAmount=FmtAmt(corporationLPAfter)))
     78         self.toCorpCurrentLP.SetText(localization.GetByLabel('UI/LPStore/AmountLP', lpAmount=FmtAmt(self.currentToCorpLPs)))
     79 
     80     def OnChangeEdit(self, *args):
     81         self.SetDetails(self.amountEdit.GetValue())
     82 
     83     def OnOK(self, *args):
     84         try:
     85             amount = self.amountEdit.GetValue()
     86             if amount:
     87                 self.lpSvc.ConvertConcordLP(self.toCorpID, int(self.amountEdit.GetValue()))
     88         finally:
     89             self.EnableButton()
     90             self.Close()
     91 
     92     def _OnClose(self, *args):
     93         self.EnableButton()
     94 
     95     def OnCancel(self, *args):
     96         self.Close()
     97 
     98     def EnableButton(self):
     99         from eve.client.script.ui.station.loyaltyPointStore.lpStoreWindow import LPStoreWindow
    100         wnd = LPStoreWindow.GetIfOpen()
    101         if wnd:
    102             wnd.Refresh()