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

medals.py (8519B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\services\medals.py
      2 import types
      3 import carbonui.control.radioButton
      4 import localization
      5 from carbon.common.script.sys.service import Service
      6 from carbonui import uiconst
      7 from eve.client.script.ui.control.entries.generic import Generic
      8 from eve.client.script.ui.shared.neocom.corporation import corpUISignals
      9 from eve.client.script.ui.util import uix, utilWindows
     10 from eve.common.script.util import eveFormat
     11 from eveexceptions import UserError
     12 from player_messaging.client.ui_message import prompt_player_fsd_dialog
     13 
     14 class Medals(Service):
     15     __exportedcalls__ = {'CreateMedal': [],
     16      'SetMedalStatus': [],
     17      'GetAllCorpMedals': [],
     18      'GetRecipientsOfMedal': [],
     19      'GetMedalsReceived': [],
     20      'GetMedalDetails': [],
     21      'GiveMedalToCharacters': []}
     22     __guid__ = 'svc.medals'
     23     __servicename__ = 'medals'
     24     __displayname__ = 'Medals'
     25     __dependencies__ = ['objectCaching']
     26     __notifyevents__ = ['OnCorporationMedalAdded', 'OnMedalIssued', 'OnMedalStatusChanged']
     27 
     28     def __init__(self):
     29         Service.__init__(self)
     30 
     31     def Run(self, memStream = None):
     32         self.LogInfo('Starting Medal Svc')
     33 
     34     def CreateMedal(self, title, description, graphics):
     35         roles = const.corpRoleDirector | const.corpRolePersonnelManager
     36         if session.corprole & roles == 0:
     37             raise UserError('CrpAccessDenied', {'reason': localization.GetByLabel('UI/Corporations/CreateDecorationWindow/NeedRolesError')})
     38         if len(title) > const.medalMaxNameLength:
     39             raise UserError('MedalNameTooLong', {'maxLength': str(const.medalMaxNameLength)})
     40         if len(description) > const.medalMaxDescriptionLength:
     41             raise UserError('MedalDescriptionTooLong', {'maxLength': str(const.medalMaxDescriptionLength)})
     42         try:
     43             sm.RemoteSvc('corporationSvc').CreateMedal(title, description, graphics)
     44         except UserError as e:
     45             if e.args[0] == 'ConfirmCreatingMedal':
     46                 d = dict(cost=localization.GetByLabel('UI/Map/StarMap/lblBoldName', name=eveFormat.FmtISK(e.dict.get('cost', 0))))
     47                 ret = prompt_player_fsd_dialog(e.msg, d, uiconst.YESNO, suppress=uiconst.ID_YES)
     48                 if ret == uiconst.ID_YES:
     49                     sm.RemoteSvc('corporationSvc').CreateMedal(title, description, graphics, True)
     50             else:
     51                 raise
     52 
     53     def SetMedalStatus(self, statusdict = None):
     54         if statusdict is None:
     55             return
     56         sm.RemoteSvc('corporationSvc').SetMedalStatus(statusdict)
     57 
     58     def GetAllCorpMedals(self, corpID):
     59         medals, medalDetails = sm.RemoteSvc('corporationSvc').GetAllCorpMedals(corpID)
     60         return [medals, medalDetails]
     61 
     62     def GetRecipientsOfMedal(self, medalID):
     63         recipients = sm.RemoteSvc('corporationSvc').GetRecipientsOfMedal(medalID)
     64         for recipient in recipients:
     65             recipient.reason = recipient.reason
     66 
     67         return recipients
     68 
     69     def GetMedalsReceivedWithFlag(self, characterID, status = None):
     70         if status is None:
     71             status = [2, 3]
     72         ret = {}
     73         medals = self.GetMedalsReceived(characterID)
     74         medalInfo, medalGraphics = medals
     75         for medal in medalInfo:
     76             if medal.status in status:
     77                 if medal.medalID in ret:
     78                     ret[medal.medalID].append(medal)
     79                 else:
     80                     ret[medal.medalID] = [medal]
     81 
     82         return ret
     83 
     84     def GetMedalsReceived(self, characterID):
     85         return sm.RemoteSvc('corporationSvc').GetMedalsReceived(characterID)
     86 
     87     def GetMedalDetails(self, medalID):
     88         return sm.RemoteSvc('corporationSvc').GetMedalDetails(medalID)
     89 
     90     def GiveMedalToCharacters(self, medalID, recipientID, reason = ''):
     91         roles = const.corpRoleDirector | const.corpRolePersonnelManager
     92         if session.corprole & roles == 0:
     93             raise UserError('CrpAccessDenied', {'reason': localization.GetByLabel('UI/Corporations/CreateDecorationWindow/NeedRolesError')})
     94         if reason == '':
     95             ret = utilWindows.NamePopup(localization.GetByLabel('UI/Corporations/CorporationWindow/Members/AwardReasonTitle'), localization.GetByLabel('UI/Corporations/CorporationWindow/Members/PromptForReason'), reason, maxLength=200)
     96             if ret:
     97                 reason = ret
     98             else:
     99                 return
    100         if type(recipientID) == types.IntType:
    101             recipientID = [recipientID]
    102         try:
    103             sm.RemoteSvc('corporationSvc').GiveMedalToCharacters(medalID, recipientID, reason)
    104         except UserError as e:
    105             if e.args[0].startswith('ConfirmGivingMedal'):
    106                 d = dict(amount=len(recipientID), members=localization.GetByLabel('UI/Corporations/MedalsToUsers', numMembers=len(recipientID)), cost=eveFormat.FmtISK(e.dict.get('cost', 0)))
    107                 ret = prompt_player_fsd_dialog(e.msg, d, uiconst.YESNO, suppress=uiconst.ID_YES)
    108                 if ret == uiconst.ID_YES:
    109                     sm.RemoteSvc('corporationSvc').GiveMedalToCharacters(medalID, recipientID, reason, True)
    110             elif e.args[0] == 'NotEnoughMoney':
    111                 prompt_player_fsd_dialog(e.msg, e.dict)
    112             else:
    113                 raise
    114 
    115     def OnCorporationMedalAdded(self, *args):
    116         invalidate = [('corporationSvc', 'GetAllCorpMedals', (session.corpid,)), ('corporationSvc', 'GetRecipientsOfMedal', (args[0],))]
    117         self.objectCaching.InvalidateCachedMethodCalls(invalidate)
    118         corpUISignals.on_corporation_medal_added()
    119 
    120     def OnMedalIssued(self, *args):
    121         invalidate = [('corporationSvc', 'GetMedalsReceived', (session.charid,))]
    122         self.objectCaching.InvalidateCachedMethodCalls(invalidate)
    123         sm.ScatterEvent('OnUpdatedMedalsAvailable')
    124 
    125     def OnMedalStatusChanged(self, *args):
    126         invalidate = [('corporationSvc', 'GetMedalsReceived', (session.charid,))]
    127         self.objectCaching.InvalidateCachedMethodCalls(invalidate)
    128         sm.ScatterEvent('OnUpdatedMedalStatusAvailable')
    129 
    130 
    131 class PermissionEntry(Generic):
    132     __guid__ = 'listentry.PermissionEntry'
    133     __params__ = ['label', 'itemID']
    134 
    135     def ApplyAttributes(self, attributes):
    136         super(PermissionEntry, self).ApplyAttributes(attributes)
    137         self.columns = [0, 1, 2]
    138 
    139     def Startup(self, *args):
    140         super(PermissionEntry, self).Startup(*args)
    141         self.sr.checkBoxes = {}
    142         i = 220
    143         for column in self.columns:
    144             cbox = carbonui.control.radioButton.RadioButton(text='', parent=self, settingsKey='', retval=column, callback=self.VisibilityFlagsChange, align=uiconst.TOPLEFT, pos=(i + 7,
    145              1,
    146              16,
    147              0))
    148             self.sr.checkBoxes[column] = cbox
    149             i += 30
    150 
    151         self.sr.label.top = 0
    152         self.sr.label.left = 6
    153         self.sr.label.SetAlign(uiconst.CENTERLEFT)
    154         self.flag = 0
    155 
    156     def Load(self, node):
    157         Generic.Load(self, node)
    158         data = self.sr.node
    159         self.flag = data.visibilityFlags
    160         if data.Get('tempFlag', None) is not None:
    161             self.flag = data.tempFlag
    162         for cboxID, cbox in self.sr.checkBoxes.iteritems():
    163             cbox.state = uiconst.UI_NORMAL
    164             cbox.SetGroup(data.itemID)
    165             if self.flag == cboxID:
    166                 cbox.SetChecked(1, 0)
    167             else:
    168                 cbox.SetChecked(0, 0)
    169 
    170         if self.sr.node.scroll.sr.tabs:
    171             self.OnColumnChanged()
    172 
    173     def OnColumnChanged(self, *args):
    174         tabs = self.sr.node.scroll.sr.tabs
    175         for i, key in enumerate(self.columns):
    176             width = tabs[i + 1] - tabs[i]
    177             self.sr.checkBoxes[key].left = self.sr.node.scroll.sr.tabs[i] + width / 2 - 8
    178 
    179     def GetHeight(self, *args):
    180         node, _ = args
    181         node.height = max(19, uix.GetTextHeight(node.label, maxLines=1) + 4)
    182         return node.height
    183 
    184     def VisibilityFlagsChange(self, radioButton):
    185         self.flag = radioButton.GetReturnValue()
    186 
    187     def HasChanged(self):
    188         return self.flag != self.sr.node.visibilityFlags
    189 
    190 
    191 class DecorationPermissionsEntry(PermissionEntry):
    192     __guid__ = 'listentry.DecorationPermissions'
    193     __params__ = ['label', 'itemID']
    194 
    195     def ApplyAttributes(self, attributes):
    196         PermissionEntry.ApplyAttributes(self, attributes)
    197         self.columns = [2, 3, 1]
    198 
    199     def Startup(self, *args):
    200         PermissionEntry.Startup(self)
    201 
    202     def Load(self, node):
    203         PermissionEntry.Load(self, node)