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

cleanupSovSystemWindow.py (13619B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\sov\sovHub\skyhooksCleanup\cleanupSovSystemWindow.py
      2 import carbonui.text.styles
      3 import eveicon
      4 from brennivin.itertoolsext import Bundle
      5 from carbon.common.script.sys.serviceConst import ROLE_PROGRAMMER
      6 from carbonui import Align, ButtonVariant, TextColor, uiconst
      7 from carbonui.text.styles import TextDetail
      8 from carbonui.button.group import ButtonGroup, ButtonSizeMode
      9 from carbonui.decorative.panelUnderlay import PanelUnderlay
     10 from carbonui.primitives.container import Container
     11 from carbonui.primitives.frame import Frame
     12 from carbonui.primitives.layoutGrid import LayoutGrid
     13 from carbonui.primitives.line import Line
     14 from carbonui.primitives.sprite import Sprite
     15 from eve.client.script.ui.control.infoIcon import InfoIcon
     16 from eve.client.script.ui.control.scrollUtil import TabFinder, TabAdjuster
     17 from eve.client.script.ui.shared.bookmarks.bookmarkContainerWindow import DropCombo
     18 from eve.client.script.ui.shared.sov.sovHub.skyhooksCleanup.cleanupSkyhookEntry import CleanupSkyhookEntry
     19 import carbonui
     20 from carbonui.control.window import Window
     21 from carbonui.window.control.action import CloseWindowAction
     22 from carbonui.primitives.containerAutoSize import ContainerAutoSize
     23 from carbonui.control.scroll import Scroll
     24 from carbonui.control.button import Button
     25 from carbonui.control.checkbox import Checkbox
     26 from eve.client.script.ui.control.entries.util import GetFromClass
     27 from player_messaging.client.ui_message import message_player, prompt_player_fsd_dialog
     28 from eve.client.script.ui.shared.sov.sovHub.skyhooksCleanup.cleanupWndController import CleanupSovSystemWindowController
     29 from eve.client.script.ui.shared.sov.sovHub.skyhooksCleanup.summary import SovCleanupSummary
     30 from eveexceptions import ExceptionEater
     31 from localization import GetByLabel
     32 from signals.signalUtil import ConnectSignals, DisconnectSignals
     33 PADDING_8 = 8
     34 PADDING_16 = 16
     35 PADDING_32 = 32
     36 LEFT_WIDTH = 354
     37 ICON_OPACITY = TextColor.NORMAL[3]
     38 ICON_OPACITY_SEC = TextColor.SECONDARY[3]
     39 
     40 def open_sov_system_cleanup():
     41     CleanupSovSystemWindow.CloseIfOpen()
     42     if not sm.GetService('sov').CanCleanUpSystem():
     43         message_player(GetByLabel('UI/Sovereignty/SovHub/SystemCleanup/NotAllowedMessage'))
     44         return
     45     if not bool(sm.GetService('sov').GetStructuresAvailableToCleanUp()):
     46         message_player(GetByLabel('UI/Sovereignty/SovHub/SystemCleanup/NoStructuresMessage'))
     47         return
     48     skyhookSlimItems = sm.GetService('sov').GetStructuresAvailableToCleanUp()
     49     window = CleanupSovSystemWindow.Open(skyhookSlimItems=skyhookSlimItems)
     50 
     51 
     52 class CleanupSovSystemWindow(Window):
     53     default_name = 'CleanupSovSystemWindow'
     54     default_windowID = 'cleanup_sov_system'
     55     default_captionLabelPath = 'UI/Sovereignty/SovHub/SystemCleanup/WindowTitle'
     56     default_width = 900
     57     default_height = 550
     58     default_minSize = [750, 350]
     59     default_isStackable = False
     60     default_isCollapseable = False
     61     default_isCompact = True
     62     __notifyevents__ = ['OnSessionChanged']
     63 
     64     def OnSessionChanged(self, isRemote, session, change):
     65         if 'locationid' in change:
     66             self.Close()
     67 
     68     def DebugReload(self, *args):
     69         open_sov_system_cleanup()
     70 
     71     def ApplyAttributes(self, attributes):
     72         Window.ApplyAttributes(self, attributes)
     73         skyhookSlimItems = attributes.skyhookSlimItems
     74         self._freezeUpdate = False
     75         self.wndController = CleanupSovSystemWindowController(skyhookSlimItems)
     76         self.rightCont = Container(name='rightCont', parent=self.content, align=carbonui.Align.TORIGHT, width=LEFT_WIDTH)
     77         self.leftCont = Container(name='leftCont', parent=self.content, padRight=PADDING_16, clipChildren=True)
     78         self._construct_buttons()
     79         self._construct_summary()
     80         self._construct_top()
     81         self._scroll = Scroll(parent=self.leftCont, align=carbonui.Align.TOALL, id='sov_system_cleanup', pos=(0,
     82          PADDING_8,
     83          0,
     84          PADDING_8))
     85         self._scroll.sr.fixedColumns = {x.columnText:x.fixedWidth for x in CleanupSkyhookEntry.headerInfo.itervalues() if x.fixedWidth}
     86         self._scroll.GetTabStops = self.GetTabStops
     87         self._scroll.ChangeSortBy = self.ChangeSortBy
     88         self._update_button_state()
     89         self.LoadEntries()
     90         signalsAndCallbacks = self.GetSignalsAndCallbacks()
     91         ConnectSignals(signalsAndCallbacks)
     92 
     93     def GetTabStops(self, headertabs, idx = None):
     94         ownerColumnIdx = CleanupSkyhookEntry.headerInfo.keys().index('owner')
     95         tabAdjuster = TabAdjuster(self._scroll, CleanupSkyhookEntry, ownerColumnIdx)
     96         tabStops = tabAdjuster.GetAdjustedTabStops(headertabs, idx)
     97         return tabStops
     98 
     99     def ChangeSortBy(self, by, *args):
    100         toggleColumnInfo = CleanupSkyhookEntry.headerInfo['toggle']
    101         if by == toggleColumnInfo.columnText:
    102             return
    103         return Scroll.ChangeSortBy(self._scroll, by, *args)
    104 
    105     def GetSignalsAndCallbacks(self):
    106         return [(self.wndController.on_any_entry_updated, self.OnAnyEntryUpdated), (self.on_end_scale, self.OnEndScale)]
    107 
    108     def _construct_buttons(self):
    109         button_group = ButtonGroup(parent=self.rightCont, align=Align.TOBOTTOM, button_size_mode=ButtonSizeMode.STRETCH, padding=PADDING_8)
    110         self.cancelButton = Button(parent=button_group, align=carbonui.Align.CENTERRIGHT, label=GetByLabel('UI/Generic/Cancel'), func=self.CloseWnd, variant=ButtonVariant.GHOST)
    111         self.confirmButton = Button(parent=button_group, align=carbonui.Align.CENTERRIGHT, label=GetByLabel('UI/Sovereignty/SovHub/SystemCleanup/ConfirmButton'), func=self.ConfirmTransition)
    112 
    113     def _construct_summary(self):
    114         PanelUnderlay(parent=self.rightCont)
    115         self.summaryCont = SovCleanupSummary(parent=self.rightCont, align=carbonui.Align.TOALL, wndController=self.wndController)
    116 
    117     def _construct_top(self):
    118         cont = ContainerAutoSize(name='topCont', parent=self.leftCont, align=carbonui.Align.TOTOP, padLeft=PADDING_8, top=PADDING_8)
    119         labelCont = ContainerAutoSize(name='labelCont', parent=cont, align=carbonui.Align.TOTOP)
    120         grid = LayoutGrid(name='topGrid', parent=labelCont, cellSpacing=PADDING_8)
    121         carbonui.text.styles.TextHeader(parent=grid, align=carbonui.Align.CENTERLEFT, text=GetByLabel('UI/Sovereignty/SovHub/SystemCleanup/WindowTitle'), bold=True)
    122         moreInfoIcon = InfoIcon(parent=grid, align=Align.CENTERLEFT)
    123         moreInfoIcon.LoadTooltipPanel = self.LoadMoreInfoTooltipPanel
    124         deadline = self.wndController.GetDeadlineTimestamp()
    125         text = GetByLabel('UI/Sovereignty/SovHub/SystemCleanup/AvailableUntil', dateTime=deadline)
    126         self.availableUntil = TextDetail(parent=cont, align=carbonui.Align.TOTOP, top=PADDING_8, text=text, color=TextColor.SECONDARY)
    127         secondCont = ContainerAutoSize(name='secondCont', parent=cont, align=carbonui.Align.TOTOP, alignMode=carbonui.Align.TOTOP, top=24)
    128         self.aclCombo = DropCombo(parent=secondCont, name='aclCombo', align=carbonui.Align.CENTERRIGHT, options=self.wndController.accessGroupOptions, nothingSelectedText=GetByLabel('UI/Sovereignty/SovHub/HubWnd/SetACL'), dropped=self.OnDroppedGroup, emptyTooltip=GetByLabel('UI/OrbitalSkyhook/ConfigWnd/TakeAccessComboHint'), width=140)
    129         secondCont.minHeight = self.aclCombo.height
    130         checkboxCont = ContainerAutoSize(name='checkboxCont', parent=secondCont, align=carbonui.Align.TOTOP, padRight=self.aclCombo.width)
    131         self._select_all_checkbox = Checkbox(parent=checkboxCont, align=carbonui.Align.TOPLEFT, callback=self._select_all, text=GetByLabel('UI/Sovereignty/SovHub/SystemCleanup/AllSkyhooks'))
    132         Line(parent=cont, top=PADDING_8)
    133 
    134     def OnDroppedGroup(self, newGroupID):
    135         for groupName, groupID in self.wndController.accessGroupOptions:
    136             if groupID == newGroupID:
    137                 self.aclCombo.SetValue(newGroupID)
    138                 return
    139 
    140         self.wndController.AddGroup(newGroupID)
    141         self.aclCombo.entries = self.wndController.accessGroupOptions
    142         self.aclCombo.SetValue(newGroupID)
    143 
    144     def LoadEntries(self):
    145         skyhook_entries = self._get_entries()
    146         self._scroll.LoadContent(contentList=skyhook_entries, headers=CleanupSkyhookEntry.GetHeaders())
    147         self.UpdateCheckbox()
    148 
    149     def _get_entries(self):
    150         result = []
    151         skyhookEntryControllers = self.wndController.GetEntryControllers()
    152         for entryController in skyhookEntryControllers.itervalues():
    153             entry = GetFromClass(CleanupSkyhookEntry, {'entryController': entryController,
    154              'ignoreRightClick': True})
    155             result.append(entry)
    156 
    157         return result
    158 
    159     def _update_button_state(self):
    160         walletBalance = self.wndController.GetCorpWalletBalance()
    161         totalCost = self.wndController.GetTotalPrice()
    162         self.confirmButton.enabled = not self.confirmButton.busy and any((c.IsChecked() and not c.IsProcessed() for c in self.wndController.GetEntryControllers().itervalues())) and walletBalance >= totalCost
    163 
    164     def _select_all(self, checkbox, *args, **kwargs):
    165         self._freezeUpdate = True
    166         try:
    167             self.wndController.ToggleAllAvailable()
    168         finally:
    169             self._freezeUpdate = False
    170 
    171         self.UpdateWnd()
    172 
    173     def CloseWnd(self, *args):
    174         self.Close()
    175 
    176     def ConfirmTransition(self, *args, **kwargs):
    177         self.confirmButton.disabled = True
    178         self.cancelButton.disabled = True
    179         self.confirmButton.busy = True
    180         if not sm.GetService('sov').CanCleanUpSystem():
    181             message_player(GetByLabel('UI/Sovereignty/SovHub/SystemCleanup/NotAllowedMessage'))
    182             self.Close()
    183             return
    184         selectedACLEntry = self.aclCombo.GetSelectedEntry()
    185         if selectedACLEntry:
    186             aclName = selectedACLEntry.label
    187         else:
    188             aclName = None
    189         data = {'controller': self.wndController,
    190          'aclName': aclName}
    191         if self.wndController.GetTotalPrice():
    192             yesBtnLabelPath = 'UI/Sovereignty/SovHub/SystemCleanup/ConfirmButton'
    193         else:
    194             yesBtnLabelPath = 'UI/Sovereignty/SovHub/SystemCleanup/ConfirmButtonWithoutCost'
    195         buttons = [Bundle(id=uiconst.ID_CANCEL, label=GetByLabel('UI/Common/Buttons/Cancel')), Bundle(id=uiconst.ID_YES, label=GetByLabel(yesBtnLabelPath))]
    196         if prompt_player_fsd_dialog('ConfirmSkyhookSovManagement', data, buttons=buttons, suppress=uiconst.ID_YES, default=uiconst.ID_YES) != uiconst.ID_YES:
    197             self.confirmButton.busy = False
    198             self.cancelButton.disabled = False
    199             self._update_button_state()
    200             return
    201         accessListID = self.aclCombo.GetValue()
    202         acquiredSkyhookIDs, destroyedSkyhookIDs, success = self.wndController.ProcessSkyhooks(accessListID)
    203         if not success:
    204             message_player(GetByLabel('UI/Sovereignty/SovHub/SystemCleanup/FailedMessage'))
    205             self.Close()
    206             return
    207         self.confirmButton.busy = False
    208         self._update_button_state()
    209         self.LoadEntries()
    210         self.UpdateWnd()
    211 
    212     def OnAnyEntryUpdated(self, *args):
    213         if not self._freezeUpdate:
    214             self.UpdateWnd()
    215 
    216     def UpdateWnd(self):
    217         self.UpdateCheckbox()
    218         self.summaryCont.UpdateCost(self.wndController)
    219         self.summaryCont.UpdateCorpWallet()
    220         self._update_button_state()
    221 
    222     def UpdateCheckbox(self):
    223         numUnchecked = self.wndController.GetNumUnprocessedAndUnchecked()
    224         if numUnchecked:
    225             isChecked = False
    226         else:
    227             isChecked = True
    228         self._select_all_checkbox.SetChecked(isChecked, False)
    229 
    230     def _get_window_actions(self):
    231         return [CloseWindowAction(self)]
    232 
    233     def LoadMoreInfoTooltipPanel(self, tooltipPanel, *args):
    234         tooltipPanel.LoadStandardSpacing()
    235         tooltipPanel.columns = 2
    236         tooltipPanel.AddTextBodyLabel(text=GetByLabel('UI/Sovereignty/SovHub/SystemCleanup/WindowTitle'), colSpan=2)
    237         iconSize = 16
    238         Sprite(parent=tooltipPanel, pos=(0,
    239          0,
    240          iconSize,
    241          iconSize), texturePath=eveicon.trade, align=Align.CENTERLEFT, opacity=ICON_OPACITY_SEC)
    242         tooltipPanel.AddTextBodyLabel(text=GetByLabel('UI/Sovereignty/SovHub/SystemCleanup/ConvertedSkyhooksIconHint'), colSpan=2, color=TextColor.SECONDARY)
    243         Sprite(parent=tooltipPanel, pos=(0,
    244          0,
    245          iconSize,
    246          iconSize), texturePath=eveicon.trashcan, align=Align.CENTERLEFT, opacity=ICON_OPACITY_SEC)
    247         tooltipPanel.AddTextBodyLabel(text=GetByLabel('UI/Sovereignty/SovHub/SystemCleanup/DestroyedSkyhooksIconHint'), colSpan=2, color=TextColor.SECONDARY)
    248         Frame(parent=tooltipPanel, align=carbonui.Align.CENTERLEFT, pos=(0,
    249          0,
    250          iconSize,
    251          iconSize), texturePath='res:/UI/Texture/classes/checkbox/underlay.png', cornerSize=3)
    252         tooltipPanel.AddTextBodyLabel(text=GetByLabel('UI/Sovereignty/SovHub/SystemCleanup/UnselectedSkyhooksIconHint'), colSpan=2, color=TextColor.SECONDARY)
    253 
    254     def OnEndScale(self, *args):
    255         if self._scroll and not self._scroll.destroyed:
    256             self._scroll.UpdateTabStops()
    257 
    258     def OnResizeUpdate(self, *args):
    259         if self._scroll and not self._scroll.destroyed:
    260             self._scroll.UpdateTabStops()
    261 
    262     def Close(self, *args, **kwargs):
    263         with ExceptionEater('Closing CleanupSkyhookEntry'):
    264             signalsAndCallbacks = self.GetSignalsAndCallbacks()
    265             DisconnectSignals(signalsAndCallbacks)
    266         super(CleanupSovSystemWindow, self).Close(*args, **kwargs)