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

offices.py (7638B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\dockedUI\offices.py
      2 import logging
      3 import blue
      4 import eveformat
      5 import localization
      6 import threadutils
      7 from carbon.common.lib.const import DAY
      8 from carbonui import AxisAlignment, uiconst
      9 from carbonui.control.button import Button
     10 from carbonui.control.scroll import Scroll
     11 from carbonui.primitives.container import Container
     12 from carbonui.primitives.flowcontainer import FlowContainer
     13 from carbonui.util.sortUtil import SortListOfTuples
     14 from carbonui.button.group import ButtonGroup, ButtonSizeMode
     15 from eve.client.script.ui.control.entries.header import Header
     16 from eve.client.script.ui.control.entries.util import GetFromClass
     17 from eve.client.script.ui.shared.dockedUI.officeEntry import OfficeEntry
     18 from eve.common.lib.appConst import corpRoleDirector, rentalPeriodOffice
     19 from player_messaging.client.ui_message import prompt_player_fsd_dialog
     20 logger = logging.getLogger(__name__)
     21 
     22 class LoadState(object):
     23     UNLOADED = 1
     24     LOAD_PENDING = 2
     25     LOADING = 3
     26     LOADED = 4
     27 
     28 
     29 class PanelDestroyedError(Exception):
     30     pass
     31 
     32 
     33 class OfficesPanel(Container):
     34     __notifyevents__ = ('OnCorporationChanged', 'OnCorporationMemberChanged', 'OnOfficeRentalChanged')
     35     _button_cont = None
     36     _load_state = LoadState.UNLOADED
     37     _rent_office_locked = False
     38     _scroll = None
     39     _initialized = False
     40 
     41     def __init__(self, station_controller, **kwargs):
     42         self._station_controller = station_controller
     43         super(OfficesPanel, self).__init__(**kwargs)
     44 
     45     def LoadPanel(self):
     46         self._load()
     47 
     48     def _layout(self):
     49         self._button_cont = ButtonGroup(name='officesButtons', parent=self, align=uiconst.TOBOTTOM, button_alignment=AxisAlignment.START, button_size_mode=ButtonSizeMode.STRETCH)
     50         self._scroll = Scroll(parent=self)
     51 
     52     @threadutils.threaded
     53     def _load(self):
     54         if not self._initialized:
     55             self._initialized = True
     56             self._layout()
     57             sm.RegisterNotify(self)
     58         is_loading = self._load_state in {LoadState.LOADING, LoadState.LOAD_PENDING}
     59         self._load_state = LoadState.LOAD_PENDING
     60         if is_loading:
     61             return
     62         try:
     63             while self._load_state == LoadState.LOAD_PENDING:
     64                 self._load_state = LoadState.LOADING
     65                 self._load_buttons()
     66                 self._load_offices_scroll()
     67                 self._load_state = LoadState.LOADED
     68 
     69         except PanelDestroyedError:
     70             pass
     71         except Exception:
     72             logger.exception('Failed to load the offices panel')
     73 
     74     def ShowOffices(self):
     75         self._load()
     76 
     77     def _load_offices_scroll(self):
     78         self._scroll.ShowLoading()
     79         try:
     80             corporations_with_office = self._station_controller.CorpsWithOffices()
     81             cfg.eveowners.Prime(corporations_with_office)
     82             cfg.corptickernames.Prime(corporations_with_office)
     83             entries = []
     84             for corporation_id in corporations_with_office:
     85                 corporation_name = cfg.eveowners.Get(corporation_id).ownerName
     86                 entry = GetFromClass(OfficeEntry, {'corpName': corporation_name,
     87                  'corpID': corporation_id})
     88                 entries.append((corporation_name.lower(), entry))
     89 
     90             entries = SortListOfTuples(entries)
     91             available_office_slots = self._station_controller.GetNumberOfUnrentedOffices()
     92             if available_office_slots is not None:
     93                 entries.insert(0, GetFromClass(Header, {'label': localization.GetByLabel('UI/Station/Lobby/NumAvailableOffices', numOffices=available_office_slots)}))
     94             if not self._scroll or self._scroll.destroyed:
     95                 return
     96             self._scroll.Load(contentList=entries)
     97         finally:
     98             if self._scroll and not self._scroll.destroyed:
     99                 self._scroll.HideLoading()
    100 
    101     def _load_buttons(self):
    102         self._button_cont.Flush()
    103         can_rent = self._station_controller.CanRent()
    104         office_exists = self._station_controller.GetMyCorpOffice() is not None
    105         if can_rent and not office_exists:
    106             self._add_button(text=localization.GetByLabel('UI/Station/Lobby/RentOffice'), callback=self._rent_office)
    107         can_unrent = self._station_controller.CanUnrent()
    108         if can_unrent and office_exists:
    109             self._add_button(text=localization.GetByLabel('UI/Station/Hangar/UnrentOffice'), callback=self._unrent_office)
    110         can_move_hq = self._station_controller.CanMoveHQ()
    111         hq_allowed = self._station_controller.IsHqAllowed()
    112         if can_move_hq and hq_allowed:
    113             is_hq_here = self._station_controller.IsMyHQ()
    114             if not is_hq_here:
    115                 self._add_button(text=localization.GetByLabel('UI/Station/Lobby/MoveHeadquartersHere'), callback=self._set_hq)
    116         has_impounded_items = self._station_controller.HasCorpItemsImpounded()
    117         is_director = session.corprole & corpRoleDirector
    118         if not office_exists and has_impounded_items and is_director:
    119             self._add_button(text=localization.GetByLabel('UI/Inventory/ReleaseItems'), callback=self._release_impounded_items)
    120 
    121     def _add_button(self, text, callback):
    122         if not self._button_cont or self._button_cont.destroyed:
    123             raise PanelDestroyedError()
    124         Button(parent=self._button_cont, align=uiconst.TOPLEFT, label=text, func=callback, args=())
    125 
    126     def _rent_office(self):
    127         if self._rent_office_locked:
    128             return
    129         self._rent_office_locked = True
    130         try:
    131             cost = self._station_controller.GetCostForOpeningOffice()
    132             response = prompt_player_fsd_dialog('AskPayOfficeRentalFee', {'cost': cost,
    133              'duration': rentalPeriodOffice * DAY}, uiconst.YESNO)
    134             if response == uiconst.ID_YES:
    135                 self._station_controller.RentOffice(cost)
    136         finally:
    137             self._rent_office_locked = False
    138 
    139     def _unrent_office(self):
    140         if not self._station_controller.GetMyCorpOffice():
    141             return
    142         if not self._station_controller.IsEmptyOffice():
    143             response = prompt_player_fsd_dialog('crpUnrentOfficeWithContent', {}, uiconst.YESNO)
    144             if response != uiconst.ID_YES:
    145                 return
    146         else:
    147             station_id = self._station_controller.GetItemID()
    148             office_name = cfg.evelocations.Get(station_id).name
    149             response = prompt_player_fsd_dialog('crpUnrentOffice', {'officeName': office_name}, uiconst.YESNO)
    150             if response != uiconst.ID_YES:
    151                 return
    152         self._station_controller.UnrentOffice()
    153 
    154     def _release_impounded_items(self):
    155         cost = self._station_controller.GetCostForGettingCorpJunkBack()
    156         if cost is not None:
    157             if prompt_player_fsd_dialog('CrpJunkAcceptCost', {'cost': eveformat.number(cost)}, uiconst.YESNO) != uiconst.ID_YES:
    158                 return
    159             self._station_controller.ReleaseImpoundedItems(cost)
    160         self._load()
    161 
    162     def _set_hq(self):
    163         self._station_controller.SetHQ()
    164 
    165     def OnCorporationChanged(self, corpID, change):
    166         blue.pyos.synchro.Sleep(750)
    167         self._load()
    168 
    169     def OnCorporationMemberChanged(self, corporationID, memberID, change):
    170         if memberID == session.charid:
    171             self._load()
    172 
    173     def OnOfficeRentalChanged(self, corporationID, officeID):
    174         invalidate_office_inventory_cache(officeID)
    175         self._load()
    176 
    177 
    178 def invalidate_office_inventory_cache(office_id):
    179     sm.GetService('invCache').InvalidateLocationCache(office_id)