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

emblemsPanel.py (10017B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\neocom\charsheet\emblemsPanel.py
      2 from carbon.common.script.sys.serviceConst import ROLE_GML
      3 from carbonui.primitives.layoutGrid import LayoutGrid
      4 from eve.client.script.ui.cosmetics.structure.cosmeticLicenseErrorScreen import CosmeticLicenseErrorScreen
      5 from cosmetics.common.cosmeticsConst import ICON_PATH_BY_TYPE, CATEGORY_NAME_BY_TYPE
      6 from functools import partial
      7 import evetypes
      8 import eveicon
      9 import localization
     10 from carbonui import const as uiconst
     11 from carbonui.primitives.container import Container
     12 from carbonui.primitives.containerAutoSize import ContainerAutoSize
     13 from eve.client.script.ui.control.entries.item import Item
     14 from eve.client.script.ui.control.entries.util import GetFromClass
     15 from eve.client.script.ui.control.eveLabel import EveLabelMedium
     16 from eve.client.script.ui.control.eveScroll import Scroll
     17 from eve.client.script.ui.control.listgroup import ListGroup
     18 from eve.client.script.ui.control.utilMenu import UtilMenu
     19 from eve.client.script.ui.quickFilter import QuickFilterEdit
     20 from shipcosmetics.client.licensegateway.licenseSignals import on_ship_cosmetics_license_change
     21 SETTING_SHOW_EMBLEMS = 'charsheet_shipEmblems_showEmblems'
     22 SHOW_ALL_EMBLEMS = 'all_emblems'
     23 SHOW_OWNED_EMBLEMS = 'owned_emblems'
     24 SHOW_UNOWNED_EMBLEMS = 'unowned_emblems'
     25 SETTING_DEFAULTS = {SETTING_SHOW_EMBLEMS: SHOW_ALL_EMBLEMS}
     26 
     27 class EmblemsPanel(Container):
     28     default_name = 'EmblemsPanel'
     29     default_padTop = 16
     30 
     31     def ApplyAttributes(self, attributes):
     32         super(EmblemsPanel, self).ApplyAttributes(attributes)
     33         self.cosmeticsLicenseSvc = sm.GetService('cosmeticsLicenseSvc')
     34         self.ConstructErrorScreen(attributes.errorScreenPadding)
     35         on_ship_cosmetics_license_change.connect(self._OnLicenseStatusChanged)
     36         self.isConstructed = False
     37 
     38     def Close(self):
     39         super(EmblemsPanel, self).Close()
     40         on_ship_cosmetics_license_change.disconnect(self._OnLicenseStatusChanged)
     41 
     42     def ConstructLayout(self):
     43         if self.isConstructed:
     44             return
     45         self.isConstructed = True
     46         menuBar = ContainerAutoSize(parent=self, align=uiconst.TOTOP, padBottom=16, alignMode=uiconst.CENTERLEFT)
     47         UtilMenu(parent=menuBar, align=uiconst.CENTERLEFT, GetUtilMenu=self.GetSettingsMenu, texturePath=eveicon.settings, width=24, height=24, iconSize=16)
     48         self.filter = QuickFilterEdit(parent=menuBar, name='filter', align=uiconst.CENTERRIGHT, left=2, width=150, hintText=localization.GetByLabel('UI/Inventory/Filter'))
     49         Container(parent=menuBar, name='spacer', align=uiconst.CENTERLEFT, pos=(0,
     50          0,
     51          1,
     52          self.filter.height))
     53         self.counterText = EveLabelMedium(parent=ContainerAutoSize(parent=menuBar, align=uiconst.TOLEFT, left=30), align=uiconst.CENTERLEFT, text='')
     54         self.filter.ReloadFunction = self.LoadPanel
     55         self.scroll = Scroll(parent=self, align=uiconst.TOALL)
     56 
     57     def ConstructErrorScreen(self, errorScreenPadding):
     58         self.errorScreen = CosmeticLicenseErrorScreen(name='errorScreen', parent=self, align=uiconst.TOALL, padding=(-errorScreenPadding[0],
     59          -errorScreenPadding[1],
     60          -errorScreenPadding[2],
     61          -errorScreenPadding[3]))
     62         self.errorScreen.CloseScreen(animate=False)
     63 
     64     def _OnSizeChange_NoBlock(self, *args):
     65         super(EmblemsPanel, self)._OnSizeChange_NoBlock(*args)
     66         if hasattr(self, 'errorScreen'):
     67             self.errorScreen.AdjustWidth(args[0])
     68 
     69     @property
     70     def filterText(self):
     71         return self.filter.GetValue().strip().lower()
     72 
     73     def LoadPanel(self, *args):
     74         self.ConstructLayout()
     75         self.scroll.Clear()
     76         try:
     77             licensesByType = self._GetFilteredLicensesByType()
     78             entries = []
     79             for licenseType, licenses in licensesByType.iteritems():
     80                 entry = self._CreateGroupEntry(licenseType, licenses)
     81                 if entry is not None:
     82                     entries.append(entry)
     83 
     84             self.scroll.Load(contentList=entries, noContentHint=localization.GetByLabel('UI/SkillQueue/NoResultsForFilters'))
     85             numOwnedLicenses = len(self.cosmeticsLicenseSvc.get_owned_ship_licenses())
     86             self.counterText.text = localization.GetByLabel('UI/CharacterSheet/CharacterSheetWindow/ShipEmblems/YouHaveNumShipEmblems', numEmblems=numOwnedLicenses)
     87         except RuntimeError:
     88             self.errorScreen.ShowScreen(localization.GetByLabel('UI/CharacterSheet/CharacterSheetWindow/ShipEmblems/FetchLicensesFailedErrorMessage'), localization.GetByLabel('UI/CharacterSheet/CharacterSheetWindow/ShipEmblems/FetchLicensesFailedErrorSubtext'), localization.GetByLabel('UI/CharacterSheet/CharacterSheetWindow/ShipEmblems/FetchingFailedButton'), self._RetryFetchingCosmeticsLicenses)
     89 
     90     def _RetryFetchingCosmeticsLicenses(self):
     91         self.errorScreen.CloseScreen(True)
     92         self.LoadPanel()
     93 
     94     def _GetFilteredLicensesByType(self):
     95         licenses = []
     96         showFilter = GetSetting(SETTING_SHOW_EMBLEMS)
     97         if showFilter == SHOW_ALL_EMBLEMS:
     98             licenses = self.cosmeticsLicenseSvc.get_all_ship_licenses()
     99         elif showFilter == SHOW_OWNED_EMBLEMS:
    100             licenses = self.cosmeticsLicenseSvc.get_owned_ship_licenses()
    101         elif showFilter == SHOW_UNOWNED_EMBLEMS:
    102             licenses = self.cosmeticsLicenseSvc.get_unowned_ship_licenses()
    103         licensesByType = {}
    104         for license in licenses:
    105             if self.filterText == '' or self.filterText in evetypes.GetName(license.fsdTypeID).lower():
    106                 if license.cosmeticType not in licensesByType:
    107                     licensesByType[license.cosmeticType] = []
    108                 licensesByType[license.cosmeticType].append(license)
    109 
    110         return licensesByType
    111 
    112     def _CreateGroupEntry(self, cosmeticType, licenses):
    113         licensesByLicenseID = {license.licenseID:(license, self.cosmeticsLicenseSvc.is_ship_license_owned(license.licenseID)) for license in licenses}
    114         groupName = localization.GetByLabel(CATEGORY_NAME_BY_TYPE[cosmeticType])
    115         emblemsOwned = sum((1 for each in licensesByLicenseID.values() if each[1]))
    116         emblemsTotal = len(licensesByLicenseID)
    117         iconPath = ICON_PATH_BY_TYPE[cosmeticType]
    118         return GetFromClass(ListGroup, {'label': localization.GetByLabel('UI/CharacterSheet/CharacterSheetWindow/ShipEmblems/EmblemsGroupWithCount', groupName=groupName, emblemsOwned=emblemsOwned, emblemsTotal=emblemsTotal),
    119          'id': ('ShipEmblems', groupName),
    120          'showicon': iconPath,
    121          'groupItems': licensesByLicenseID,
    122          'GetSubContent': self._GetEmblemSubContent,
    123          'showlen': False,
    124          'BlockOpenWindow': True,
    125          'state': 'locked'})
    126 
    127     def _GetEmblemSubContent(self, nodedata, *args):
    128         licensesByLicenseID = nodedata.groupItems
    129         nodes = []
    130         for licenseID, (license, owned) in licensesByLicenseID.iteritems():
    131             data = self._GetDataForEmblemEntry(license, owned)
    132             entry = GetFromClass(ShipEmblemEntry, data)
    133             nodes.append(entry)
    134 
    135         nodes = sorted(nodes, key=lambda x: x.label)
    136         return nodes
    137 
    138     def _GetDataForEmblemEntry(self, license, owned):
    139         data = {'typeID': license.shipTypeID,
    140          'licenseID': license.licenseID,
    141          'itemID': None,
    142          'label': evetypes.GetName(license.shipTypeID),
    143          'getIcon': True,
    144          'sublevel': 1,
    145          'skin': license,
    146          'owned': owned}
    147         return data
    148 
    149     def GetSettingsMenu(self, menuParent):
    150         menuParent.AddRadioButton(text=localization.GetByLabel('UI/CharacterSheet/CharacterSheetWindow/ShipEmblems/ShowAllEmblems'), checked=GetSetting(SETTING_SHOW_EMBLEMS) == SHOW_ALL_EMBLEMS, callback=partial(self.SetSettingAndReload, SETTING_SHOW_EMBLEMS, SHOW_ALL_EMBLEMS))
    151         menuParent.AddRadioButton(text=localization.GetByLabel('UI/CharacterSheet/CharacterSheetWindow/ShipEmblems/ShowOwnedEmblems'), checked=GetSetting(SETTING_SHOW_EMBLEMS) == SHOW_OWNED_EMBLEMS, callback=partial(self.SetSettingAndReload, SETTING_SHOW_EMBLEMS, SHOW_OWNED_EMBLEMS))
    152         menuParent.AddRadioButton(text=localization.GetByLabel('UI/CharacterSheet/CharacterSheetWindow/ShipEmblems/ShowNotOwnedEmblems'), checked=GetSetting(SETTING_SHOW_EMBLEMS) == SHOW_UNOWNED_EMBLEMS, callback=partial(self.SetSettingAndReload, SETTING_SHOW_EMBLEMS, SHOW_UNOWNED_EMBLEMS))
    153 
    154     def SetSettingAndReload(self, key, value):
    155         SetSetting(key, value)
    156         self.LoadPanel()
    157 
    158     def _OnLicenseStatusChanged(self, _cosmeticsLicenseID, _enable):
    159         if self.display:
    160             self.LoadPanel()
    161 
    162 
    163 class ShipEmblemEntry(Item):
    164 
    165     def Startup(self, *args):
    166         super(ShipEmblemEntry, self).Startup(*args)
    167 
    168     def Load(self, node):
    169         super(ShipEmblemEntry, self).Load(node)
    170         self.sr.label.opacity = 1 if node.owned else 0.5
    171         self.sr.icon.opacity = 1 if node.owned else 0.5
    172         if node.owned:
    173             grid = LayoutGrid(parent=self, align=uiconst.CENTERRIGHT, columns=2, left=26)
    174             EveLabelMedium(parent=grid, text=localization.GetByLabel('UI/CharacterSheet/CharacterSheetWindow/ShipEmblems/ShipEmblemAcquired'))
    175 
    176     def GetMenu(self):
    177         menu = super(ShipEmblemEntry, self).GetMenu()
    178         if session.role & ROLE_GML:
    179             menu.insert(0, ('GM: Revoke me this emblem', self._DebugRevokeCosmeticLicense))
    180             menu.insert(0, ('GM: Grant me this emblem', self._DebugGrantCosmeticLicense))
    181         return menu
    182 
    183     def _DebugRevokeCosmeticLicense(self):
    184         sm.GetService('cosmeticsLicenseSvc').debug_revoke_ship_cosmetics_license(self.sr.node.licenseID)
    185 
    186     def _DebugGrantCosmeticLicense(self):
    187         sm.GetService('cosmeticsLicenseSvc').debug_grant_ship_cosmetics_license(self.sr.node.licenseID)
    188 
    189 
    190 def GetSetting(key):
    191     return settings.user.ui.Get(key, SETTING_DEFAULTS[key])
    192 
    193 
    194 def SetSetting(key, value):
    195     settings.user.ui.Set(key, value)