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

fleetregister.py (16795B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\fleet\fleetregister.py
      2 import evefleet
      3 import localization
      4 import mathext
      5 from carbonui import uiconst
      6 from carbonui.control.singlelineedits.singleLineEditInteger import SingleLineEditInteger
      7 from carbonui.control.singlelineedits.singleLineEditText import SingleLineEditText
      8 from carbonui.control.slider import Slider
      9 from carbonui.primitives.container import Container
     10 from carbonui.primitives.gridcontainer import GridContainer
     11 from carbonui.primitives.line import Line
     12 from eve.client.script.ui.control import eveLabel
     13 from carbonui.button.group import ButtonGroup
     14 from carbonui.control.checkbox import Checkbox
     15 from carbonui.control.radioButton import RadioButton
     16 from eve.client.script.ui.control.eveEditPlainText import EditPlainText
     17 from carbonui.control.window import Window
     18 from eve.common.lib.appConst import contactGoodStanding, contactHighStanding
     19 from eveexceptions import UserError
     20 from evefleet.fleetAdvertObject import FleetAdvertCreationObject
     21 from player_messaging.client.ui_message import prompt_player_fsd_dialog
     22 WINDOW_WIDTH = 600
     23 DEFAULT_JOIN_LIMIT = 250
     24 
     25 class RegisterFleetWindow(Window):
     26     __guid__ = 'form.RegisterFleetWindow'
     27     default_windowID = 'RegisterFleetWindow'
     28     default_width = WINDOW_WIDTH
     29 
     30     def ApplyAttributes(self, attributes):
     31         Window.ApplyAttributes(self, attributes)
     32         fleetInfo = attributes.fleetInfo
     33         self.SetCaption(localization.GetByLabel('UI/Fleet/CreateAdvert'))
     34         self.MakeUnResizeable()
     35         self.sr.scopeRadioButtons = []
     36         self.SetupStuff(fleetInfo)
     37 
     38     def SetupStuff(self, fleetInfo = None):
     39         publicIsGood = False
     40         publicIsHigh = False
     41         localIsGood = False
     42         localIsHigh = False
     43         if not fleetInfo:
     44             fleetInfo = settings.char.ui.Get('fleetAdvert_lastAdvert', {})
     45         fleetName = fleetInfo.get('fleetName', localization.GetByLabel('UI/Fleet/DefaultFleetName', char=session.charid))
     46         description = fleetInfo.get('description', '')
     47         needsApproval = fleetInfo.get('joinNeedsApproval', False)
     48         hideInfo = fleetInfo.get('hideInfo', False)
     49         updateOnBossChange = fleetInfo.get('updateOnBossChange', False)
     50         advertJoinLimit = fleetInfo.get('advertJoinLimit', None)
     51         membergroupsMinStanding = fleetInfo.get('membergroups_minStanding', None)
     52         membergroupsMinSecurity = fleetInfo.get('membergroups_minSecurity', None)
     53         publicMinStanding = fleetInfo.get('public_minStanding', None)
     54         publicMinSecurity = fleetInfo.get('public_minSecurity', None)
     55         myCorp = evefleet.IsOpenToCorp(fleetInfo)
     56         myAlliance = evefleet.IsOpenToAlliance(fleetInfo)
     57         myMilitia = evefleet.IsOpenToMilitia(fleetInfo)
     58         isPublic = evefleet.IsOpenToPublic(fleetInfo)
     59         if publicMinStanding == contactGoodStanding:
     60             publicIsGood = True
     61         elif publicMinStanding == contactHighStanding:
     62             publicIsHigh = True
     63         if membergroupsMinStanding == contactGoodStanding:
     64             localIsGood = True
     65         elif membergroupsMinStanding == contactHighStanding:
     66             localIsHigh = True
     67         self.sr.main.Flush()
     68         self.sr.submitButtons = ButtonGroup(btns=[[localization.GetByLabel('UI/Common/Buttons/Submit'), self.Submit, ()], [localization.GetByLabel('UI/Common/Buttons/Cancel'), self.CloseByUser, ()]], parent=self.sr.main, idx=0, padLeft=-self.sr.main.padLeft, padRight=-self.sr.main.padRight)
     69         gridContainer = GridContainer(name='myGridCont', parent=self.sr.main, align=uiconst.TOALL, columns=2, lines=1)
     70         leftCont = Container(name='leftCont', parent=gridContainer, padding=(14, 0, 10, 0))
     71         rightCont = Container(name='rightCont', parent=gridContainer, padding=(10, 0, 14, 0))
     72         Line(parent=leftCont, align=uiconst.TORIGHT_NOPUSH, padRight=-10)
     73         eveLabel.EveLabelSmall(text=localization.GetByLabel('UI/Fleet/NameOfFleet'), parent=leftCont, align=uiconst.TOTOP)
     74         self.sr.fleetName = SingleLineEditText(name='fleetName', parent=leftCont, align=uiconst.TOTOP, maxLength=evefleet.FLEETNAME_MAXLENGTH, setvalue=fleetName)
     75         eveLabel.EveLabelSmall(text=localization.GetByLabel('UI/Fleet/Description'), parent=leftCont, padTop=10, align=uiconst.TOTOP_NOPUSH)
     76         self.sr.description = EditPlainText(setvalue=description, parent=leftCont, align=uiconst.TOTOP, height=150, maxLength=evefleet.FLEETDESC_MAXLENGTH, showattributepanel=True, padTop=6)
     77         self.sr.description.sr.attribPanel.HideEditOptions()
     78         eveLabel.EveLabelSmall(text=localization.GetByLabel('UI/Fleet/FleetRegistry/OpenFleetTo'), parent=rightCont, align=uiconst.TOTOP, state=uiconst.UI_NORMAL)
     79         self.sr.myCorpButton = Checkbox(text=localization.GetByLabel('UI/Fleet/FleetRegistry/MyCorporation'), parent=rightCont, settingsKey='corp', checked=myCorp, hint=localization.GetByLabel('UI/Fleet/FleetRegistry/CorpOnlyHint'), callback=self.OnGroupCbChanged)
     80         if session.allianceid is not None:
     81             self.sr.myAllianceButton = Checkbox(text=localization.GetByLabel('UI/Fleet/FleetRegistry/MyAlliance'), parent=rightCont, settingsKey='alliance', checked=myAlliance, hint=localization.GetByLabel('UI/Fleet/FleetRegistry/AllianceOnlyHint'), align=uiconst.TOTOP, callback=self.OnGroupCbChanged)
     82         if session.warfactionid is not None:
     83             self.sr.myMilitiaButton = Checkbox(text=localization.GetByLabel('UI/Fleet/FleetRegistry/MyMilitia'), parent=rightCont, settingsKey='militia', checked=myMilitia, hint=localization.GetByLabel('UI/Fleet/FleetRegistry/MyMilitiahint'), align=uiconst.TOTOP, callback=self.OnGroupCbChanged)
     84         self.sr.requireLocalStandingButton = Checkbox(text=localization.GetByLabel('UI/Fleet/FleetRegistry/RequireStanding'), parent=rightCont, settingsKey='requireLocalStanding', checked=bool(membergroupsMinStanding), align=uiconst.TOTOP, hint=localization.GetByLabel('UI/Fleet/FleetRegistry/RequireStandingHint'), padLeft=18)
     85         self.sr.localGoodStandingCB = RadioButton(text=localization.GetByLabel('UI/Standings/Good'), parent=rightCont, settingsKey='localgood', retval=contactGoodStanding, checked=localIsGood, groupname='localStanding', align=uiconst.TOTOP, padLeft=36)
     86         self.sr.localHighStandingCB = RadioButton(text=localization.GetByLabel('UI/Standings/Excellent'), parent=rightCont, settingsKey='localhigh', retval=contactHighStanding, checked=localIsHigh, groupname='localStanding', align=uiconst.TOTOP, padLeft=36)
     87         startVal = 0.5
     88         if membergroupsMinSecurity is not None:
     89             startVal = membergroupsMinSecurity / 20.0 + 0.5
     90         self.sr.requireLocalSecurityButton = Checkbox(text=localization.GetByLabel('UI/Fleet/FleetRegistry/RequireSecurity', securityLevel=startVal), parent=rightCont, settingsKey='requireLocalSecurity', checked=membergroupsMinSecurity is not None, align=uiconst.TOTOP, padLeft=18, hint=localization.GetByLabel('UI/Fleet/FleetRegistry/RequireSecurityHint'))
     91         self.sr.localSecuritySlider = self.AddSlider(rightCont, 'localSecurity', -10, 10.0, '', startVal=startVal, padLeft=18)
     92         self.sr.publicButton = Checkbox(text=localization.GetByLabel('UI/Fleet/FleetRegistry/BasedOnStandings'), parent=rightCont, settingsKey='public', checked=isPublic, align=uiconst.TOTOP, hint=localization.GetByLabel('UI/Fleet/FleetRegistry/AddPilots'), callback=self.OnStandingCbChanged)
     93         self.sr.requireStandingLabel = eveLabel.EveLabelSmall(text=localization.GetByLabel('UI/Fleet/FleetRegistry/RequireStanding'), parent=rightCont, align=uiconst.TOTOP, state=uiconst.UI_NORMAL, padLeft=18)
     94         self.sr.publicGoodStandingCB = RadioButton(text=localization.GetByLabel('UI/Standings/Good'), parent=rightCont, settingsKey='publicgood', retval=contactGoodStanding, checked=publicIsGood, groupname='publicStanding', align=uiconst.TOTOP, padLeft=18)
     95         self.sr.publicHighStandingCB = RadioButton(text=localization.GetByLabel('UI/Standings/Excellent'), parent=rightCont, settingsKey='publichigh', retval=contactHighStanding, checked=publicIsHigh, groupname='publicStanding', align=uiconst.TOTOP, padLeft=18)
     96         startVal = 0.5
     97         if publicMinSecurity is not None:
     98             startVal = publicMinSecurity / 20.0 + 0.5
     99         self.sr.requirePublicSecurityButton = Checkbox(text=localization.GetByLabel('UI/Fleet/FleetRegistry/RequireSecurity', securityLevel=startVal), parent=rightCont, settingsKey='requirePublicSecurity', checked=publicMinSecurity is not None, hint=localization.GetByLabel('UI/Fleet/FleetRegistry/RequireSecurityHint'), padLeft=18)
    100         self.sr.publicSecuritySlider = self.AddSlider(rightCont, 'publicSecurity', -10, 10.0, '', startVal=startVal, padLeft=18)
    101         self.sr.needsApprovalButton = Checkbox(text=localization.GetByLabel('UI/Fleet/FleetRegistry/RequireApproval'), parent=leftCont, settingsKey='needsApproval', checked=needsApproval, hint=localization.GetByLabel('UI/Fleet/FleetRegistry/RequireApprovalHint'))
    102         self.sr.hideInfoButton = Checkbox(text=localization.GetByLabel('UI/Fleet/FleetRegistry/HideInfo'), parent=leftCont, settingsKey='hideInfo', checked=hideInfo, hint=localization.GetByLabel('UI/Fleet/FleetRegistry/HideInfoHint'))
    103         self.sr.updateOnBossChangeCb = Checkbox(text=localization.GetByLabel('UI/Fleet/FleetRegistry/UpdateOnBossChange'), parent=leftCont, settingsKey='updateOnBossChange', checked=updateOnBossChange, hint=localization.GetByLabel('UI/Fleet/FleetRegistry/UpdateOnBossChangeHint'))
    104         self.sr.canJoinThroughAdLimitCb = Checkbox(text=localization.GetByLabel('UI/Fleet/FleetRegistry/AdvertJoinLimit'), parent=leftCont, settingsKey='advertJoinLimit', checked=bool(advertJoinLimit), padBottom=6, callback=self.OnLimitJoinCb)
    105         self.sr.canJoinThroughAdLimitCb.GetHint = self.GetAdvertJoinLimitHint
    106         self.sr.limtedJoinEdit = SingleLineEditInteger(name='edit', parent=leftCont, align=uiconst.TOTOP, padding=(30, 0, 150, 0), minValue=1, maxValue=evefleet.MAX_MEMBERS_IN_FLEET, setvalue=advertJoinLimit or DEFAULT_JOIN_LIMIT)
    107         leftChildrenHeight = sum([ each.height + each.padTop + each.padBottom for each in leftCont.children ])
    108         rightChildrenHeight = sum([ each.height + each.padTop + each.padBottom for each in rightCont.children ])
    109         childrenHeight = max(leftChildrenHeight, rightChildrenHeight)
    110         windowHeight = childrenHeight + self.header_height + gridContainer.padTop + gridContainer.padBottom + self.sr.submitButtons.height
    111         self.SetMinSize([WINDOW_WIDTH, windowHeight], refresh=True)
    112         self.ChangeLocalDisplay()
    113         self.ChangePublicDisplay()
    114         self.ChangeLimitJoinDisplay()
    115 
    116     def GetAdvertJoinLimitHint(self, *args):
    117         limit = self.sr.limtedJoinEdit.GetValue()
    118         hint = localization.GetByLabel('UI/Fleet/FleetRegistry/AdvertJoinLimitHint', advertJoinLimit=limit)
    119         return hint
    120 
    121     def OnGroupCbChanged(self, *args):
    122         self.ChangeLocalDisplay()
    123 
    124     def ChangeLocalDisplay(self):
    125         groupCbs = filter(None, [self.sr.myCorpButton, self.sr.myAllianceButton, self.sr.myMilitiaButton])
    126         groupChecked = any((x.GetValue() for x in groupCbs))
    127         subElements = [self.sr.requireLocalStandingButton,
    128          self.sr.localGoodStandingCB,
    129          self.sr.localHighStandingCB,
    130          self.sr.requireLocalSecurityButton,
    131          self.sr.localSecuritySlider]
    132         self.EnableOrDisableElements(groupChecked, subElements)
    133 
    134     def OnStandingCbChanged(self, *args):
    135         self.ChangePublicDisplay()
    136 
    137     def ChangePublicDisplay(self):
    138         isChecked = self.sr.publicButton.GetValue()
    139         subElements = [self.sr.requireStandingLabel,
    140          self.sr.publicGoodStandingCB,
    141          self.sr.publicHighStandingCB,
    142          self.sr.requirePublicSecurityButton,
    143          self.sr.publicSecuritySlider]
    144         self.EnableOrDisableElements(isChecked, subElements)
    145 
    146     def EnableOrDisableElements(self, isEnabled, subElements):
    147         for eachElement in subElements:
    148             if isEnabled:
    149                 eachElement.Enable()
    150                 eachElement.opacity = 1.0
    151             else:
    152                 eachElement.Disable()
    153                 eachElement.opacity = 0.3
    154 
    155     def OnLimitJoinCb(self, *args):
    156         self.ChangeLimitJoinDisplay()
    157 
    158     def ChangeLimitJoinDisplay(self):
    159         self.EnableOrDisableElements(self.sr.canJoinThroughAdLimitCb.GetValue(), [self.sr.limtedJoinEdit])
    160 
    161     def AddSlider(self, where, config, minval, maxval, header, hint = '', startVal = 0, padLeft = 0):
    162         _par = Container(name=config + '_slider', parent=where, align=uiconst.TOTOP, padLeft=padLeft, height=10)
    163         if startVal < minval:
    164             startVal = minval
    165         slider = Slider(name=config + '_slider_sub', parent=_par, align=uiconst.TOPLEFT, pos=(18, 0, 180, 10), minValue=minval, maxValue=maxval, value=startVal, config=config, hint=hint, on_dragging=getattr(self, 'OnSetValue_%s' % config))
    166         return slider
    167 
    168     def OnSetValue_localSecurity(self, slider):
    169         self.sr.requireLocalSecurityButton.SetLabelText(localization.GetByLabel('UI/Fleet/FleetRegistry/RequireSecurity', securityLevel=slider.GetValue()))
    170 
    171     def OnSetValue_publicSecurity(self, slider):
    172         self.sr.requirePublicSecurityButton.SetLabelText(localization.GetByLabel('UI/Fleet/FleetRegistry/RequireSecurity', securityLevel=slider.GetValue()))
    173 
    174     def Submit(self):
    175         fleetSvc = sm.GetService('fleet')
    176         adInfo = FleetAdvertCreationObject(fleetName=self.sr.fleetName.GetValue(), description=self.sr.description.GetValue(), useAdvanceOptions=True)
    177         if self.sr.myCorpButton.checked:
    178             adInfo.AddToInviteScopeMask(evefleet.INVITE_CORP)
    179         if session.allianceid and self.sr.myAllianceButton.checked:
    180             adInfo.AddToInviteScopeMask(evefleet.INVITE_ALLIANCE)
    181         if session.warfactionid and self.sr.myMilitiaButton.checked:
    182             adInfo.AddToInviteScopeMask(evefleet.INVITE_MILITIA)
    183         if self.sr.publicButton.checked:
    184             adInfo.AddToInviteScopeMask(evefleet.INVITE_PUBLIC)
    185             if self.sr.publicGoodStandingCB.checked:
    186                 minPublicStandings = contactGoodStanding
    187             elif self.sr.publicHighStandingCB.checked:
    188                 minPublicStandings = contactHighStanding
    189             else:
    190                 raise UserError('FleetInviteAllWithoutStanding')
    191             adInfo.public_minStanding = minPublicStandings
    192             adInfo.public_allowedEntities = self.GetAllowedEntities(minPublicStandings)
    193             if self.sr.requirePublicSecurityButton.checked:
    194                 adInfo.public_minSecurity = self.sr.publicSecuritySlider.value
    195         noAccess = False
    196         if adInfo.IsOpenToMemberEntities():
    197             if self.sr.requireLocalStandingButton.checked:
    198                 if self.sr.localGoodStandingCB.checked:
    199                     minMembergroupStandings = contactGoodStanding
    200                 elif self.sr.localHighStandingCB.checked:
    201                     minMembergroupStandings = contactHighStanding
    202                 else:
    203                     raise UserError('FleetInviteAllWithoutStanding')
    204                 adInfo.membergroups_minStanding = minMembergroupStandings
    205                 adInfo.membergroups_allowedEntities = self.GetAllowedEntities(minMembergroupStandings)
    206             else:
    207                 allowedGroups = fleetSvc.GetAllowedGroupIDs(adInfo)
    208                 adInfo.membergroups_allowedEntities = allowedGroups
    209             if self.sr.requireLocalSecurityButton.checked:
    210                 adInfo.membergroups_minSecurity = self.sr.localSecuritySlider.value
    211         elif not evefleet.IsOpenToPublic(adInfo):
    212             noAccess = True
    213         if adInfo.IsOpenToPublicThroughStandings():
    214             if not adInfo.GetNumAllowedEntities():
    215                 noAccess = True
    216         if noAccess:
    217             if prompt_player_fsd_dialog('FleetNobodyHasAccess', {}, uiconst.YESNO, suppress=uiconst.ID_YES) != uiconst.ID_YES:
    218                 return
    219         adInfo.joinNeedsApproval = bool(self.sr.needsApprovalButton.checked)
    220         adInfo.hideInfo = bool(self.sr.hideInfoButton.checked)
    221         adInfo.updateOnBossChange = bool(self.sr.updateOnBossChangeCb.GetValue())
    222         if self.sr.canJoinThroughAdLimitCb.GetValue():
    223             limit = self.sr.limtedJoinEdit.GetValue()
    224             limit = mathext.clamp(limit, 1, evefleet.MAX_MEMBERS_IN_FLEET)
    225             adInfo.advertJoinLimit = limit
    226         fleetSvc.RegisterFleet(adInfo)
    227         settings.char.ui.Set('fleetAdvert_lastAdvertAdvancedOptions', dict(adInfo.GetLimitedAdvancedOptionsData()))
    228         self.CloseByUser()
    229 
    230     def GetAllowedEntities(self, minRelationship):
    231         return sm.GetService('addressbook').GetContactsByMinRelationship(minRelationship)