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

storeFleetSetupWnd.py (10043B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\fleet\storeFleetSetupWnd.py
      2 import eveicon
      3 import localization
      4 from carbonui import uiconst
      5 from carbonui.control.scrollContainer import ScrollContainer
      6 from carbonui.control.singlelineedits.singleLineEditText import SingleLineEditText
      7 from carbonui.primitives.containerAutoSize import ContainerAutoSize
      8 from carbonui.primitives.sprite import Sprite
      9 from eve.client.script.ui.control import eveLabel
     10 from carbonui.control.buttonIcon import ButtonIcon
     11 from carbonui.control.checkbox import Checkbox
     12 from carbonui.control.window import Window
     13 from carbonui.button.group import ButtonGroup
     14 from carbonui.primitives.container import Container
     15 from carbonui.uicore import uicore
     16 from eve.client.script.ui.control.eveWindowUnderlay import ListEntryUnderlay
     17 import evefleet.fleetSetupConst as fsConst
     18 from evefleet import MAX_MEMBERS_IN_FLEET
     19 from player_messaging.client.ui_message import prompt_player_fsd_dialog
     20 CONTENT_WIDTH = 360
     21 
     22 class StoreFleetSetupWnd(Window):
     23     default_width = CONTENT_WIDTH
     24     default_height = 300
     25     default_windowID = 'StoreFleetSetupWnd'
     26     default_captionLabelPath = 'UI/Fleet/FleetWindow/StoreFleetSetup'
     27 
     28     def ApplyAttributes(self, attributes):
     29         super(StoreFleetSetupWnd, self).ApplyAttributes(attributes)
     30         self.maxFleetSizeCb = None
     31         self.defaultSquadCb = None
     32         self.currentFleetInfo = attributes.get('currentFleetInfo')
     33         self.funcValidator = self.CheckName
     34         self.ConstructLayout(self.currentFleetInfo.oldSetupName)
     35 
     36     def ConstructLayout(self, oldSetupName):
     37         self._main_cont = ContainerAutoSize(parent=self.content, align=uiconst.TOTOP, callback=self._on_main_cont_size_changed, only_use_callback_when_size_changes=True)
     38         if oldSetupName:
     39             label = localization.GetByLabel('UI/Fleet/FleetWindow/StoreFleetSetupTextWithLastLoaded', oldFleetSetupName=oldSetupName)
     40         else:
     41             label = localization.GetByLabel('UI/Fleet/FleetWindow/StoreFleetSetupText')
     42         eveLabel.EveLabelSmall(name='nameLabel', parent=self._main_cont, align=uiconst.TOTOP, text=label)
     43         self.newName = SingleLineEditText(name='namePopup', parent=self._main_cont, align=uiconst.TOTOP, maxLength=15, OnReturn=self.Confirm)
     44         uicore.registry.SetFocus(self.newName)
     45         hint = localization.GetByLabel('UI/Fleet/FleetWindow/CurrentMotdHint', motd=self.currentFleetInfo.currentMotd)
     46         self.motdCb = Checkbox(parent=self._main_cont, align=uiconst.TOTOP, top=16, text=localization.GetByLabel('UI/Fleet/FleetWindow/IncludeMotd'), settingsKey='motdCb', checked=False, hint=hint)
     47         hint = localization.GetByLabel('UI/Fleet/FleetWindow/CurrentFreeMoveHint', value=self.currentFleetInfo.currentOptions.isFreeMove)
     48         self.freeMoveCb = Checkbox(parent=self._main_cont, align=uiconst.TOTOP, text=localization.GetByLabel('UI/Fleet/FleetWindow/IncludeFreeMoveSetting'), settingsKey='freeMoveCb', checked=False, hint=hint)
     49         currentMaxSize = self.currentFleetInfo.currentMaxSize
     50         if currentMaxSize != MAX_MEMBERS_IN_FLEET:
     51             hint = localization.GetByLabel('UI/Fleet/FleetWindow/CurrentFleetMaxSize', value=currentMaxSize)
     52             self.maxFleetSizeCb = Checkbox(parent=self._main_cont, align=uiconst.TOTOP, text=localization.GetByLabel('UI/Fleet/FleetWindow/IncludeMaxSize'), settingsKey='maxFleetSizeCb', checked=False, hint=hint)
     53         if self.currentFleetInfo.currentDefaultSquadName:
     54             hint = localization.GetByLabel('UI/Fleet/FleetWindow/CurrentDefaultSquadHint', value=self.currentFleetInfo.currentDefaultSquadName)
     55             self.defaultSquadCb = Checkbox(parent=self._main_cont, align=uiconst.TOTOP, text=localization.GetByLabel('UI/Fleet/FleetWindow/IncludeDefaultSquad'), settingsKey='defaultSquadCb', checked=False, hint=hint)
     56         buttons = ButtonGroup(parent=self._main_cont, align=uiconst.TOTOP, top=16)
     57         buttons.AddButton(label=localization.GetByLabel('UI/Common/Buttons/OK'), func=self.Confirm, isDefault=True)
     58         buttons.AddButton(label=localization.GetByLabel('UI/Common/Buttons/Cancel'), func=self.Cancel)
     59 
     60     def CheckName(self, name, *args):
     61         name = self.newName.GetValue()
     62         if not len(name) or len(name) and len(name.strip()) < 1:
     63             return localization.GetByLabel('UI/Common/PleaseTypeSomething')
     64 
     65     def Confirm(self, *args):
     66         newName = self.newName.GetValue()
     67         storeMotd = self.motdCb.GetValue()
     68         storeFreeMove = self.freeMoveCb.GetValue()
     69         storeMaxSize = self.maxFleetSizeCb.GetValue() if self.maxFleetSizeCb else False
     70         storeDefaultSquad = self.defaultSquadCb.GetValue() if self.defaultSquadCb else False
     71         error = self.funcValidator(newName)
     72         if error:
     73             prompt_player_fsd_dialog('CustomInfo', {'info': error})
     74         else:
     75             results = StoreFleetSetupResults()
     76             results.setupName = newName
     77             results.storeMotd = storeMotd
     78             results.storeFreeMove = storeFreeMove
     79             results.storeDefaultSquad = storeDefaultSquad
     80             results.storeMaxSize = storeMaxSize
     81             self.result = results
     82             self.SetModalResult(1)
     83 
     84     def Cancel(self, *args):
     85         self.result = None
     86         self.SetModalResult(0)
     87 
     88     def _on_main_cont_size_changed(self):
     89         content_height = self._main_cont.height
     90         width, height = self.GetWindowSizeForContentSize(width=CONTENT_WIDTH, height=content_height)
     91         self.SetFixedWidth(width)
     92         self.SetFixedHeight(height)
     93 
     94 
     95 class StoredFleetSetupListWnd(Window):
     96     default_width = 360
     97     default_height = 300
     98     default_minSize = (default_width, default_height)
     99     default_windowID = 'StoredFleetSetupListWnd'
    100     __notifyevents__ = ['OnFleetSetupChanged']
    101 
    102     def ApplyAttributes(self, attributes):
    103         Window.ApplyAttributes(self, attributes)
    104         self.fleetSvc = attributes.fleetSvc
    105         self.SetCaption(localization.GetByLabel('UI/Fleet/FleetWindow/SetupsOverview'))
    106         self.scroll = ScrollContainer(parent=self.sr.main)
    107         self.LoadSetups()
    108 
    109     def LoadSetups(self):
    110         fleetSetups = self.fleetSvc.GetFleetSetups()
    111         orderedFleetSetups = [ (fleetSetupName, setup) for fleetSetupName, setup in fleetSetups.iteritems() ]
    112         orderedFleetSetups.sort()
    113         for fleetSetupName, setup in orderedFleetSetups:
    114             StoredFleetSetupEntry(parent=self.scroll, name=fleetSetupName, setupInfo=setup, settingConfigName=fleetSetupName, fleetSvc=self.fleetSvc)
    115 
    116     def OnFleetSetupChanged(self):
    117         self.scroll.Flush()
    118         self.LoadSetups()
    119 
    120 
    121 class StoredFleetSetupEntry(Container):
    122     default_height = 30
    123     default_align = uiconst.TOTOP
    124     default_state = uiconst.UI_NORMAL
    125     disabledOpacity = 0.3
    126 
    127     def ApplyAttributes(self, attributes):
    128         Container.ApplyAttributes(self, attributes)
    129         self.fleetSvc = attributes.fleetSvc
    130         self.setupInfo = setupInfo = attributes.get('setupInfo', {})
    131         motd = setupInfo.get(fsConst.FS_MOTD, None)
    132         isFreeMove = setupInfo.get(fsConst.FS_IS_FREE_MOVE, None)
    133         settingName = setupInfo.get(fsConst.FS_NAME)
    134         self.settingConfigName = attributes.get('settingConfigName', settingName)
    135         nameLabel = eveLabel.EveLabelSmall(name='nameLabel', parent=self, align=uiconst.CENTERLEFT, state=uiconst.UI_DISABLED, text=settingName, padLeft=8)
    136         iconCont = ContainerAutoSize(parent=self, height=16, align=uiconst.CENTERRIGHT, width=54, padRight=8)
    137         ButtonIcon(parent=iconCont, texturePath=eveicon.refresh, width=16, padLeft=4, align=uiconst.TORIGHT, func=self.LoadSetup, hint=localization.GetByLabel('UI/Fleet/FleetWindow/LoadFleetSetup'))
    138         ButtonIcon(parent=iconCont, texturePath=eveicon.trashcan, width=16, padLeft=4, align=uiconst.TORIGHT, func=self.DeleteSetup, hint=localization.GetByLabel('UI/Common/Buttons/Delete'))
    139         if motd is not None:
    140             sprite = Sprite(parent=iconCont, width=16, padLeft=4, align=uiconst.TORIGHT, texturePath='res:/ui/texture/icons/6_64_7.png')
    141             sprite.hint = localization.GetByLabel('UI/Chat/ChannelMotd', motd=motd)
    142             if not motd:
    143                 sprite.opacity = self.disabledOpacity
    144         if isFreeMove is not None:
    145             sprite = Sprite(parent=iconCont, width=16, padLeft=4, align=uiconst.TORIGHT, texturePath='res:/ui/texture/icons/44_32_32.png')
    146             if isFreeMove:
    147                 sprite.hint = localization.GetByLabel('UI/Fleet/FleetWindow/FreeMoveOn')
    148             else:
    149                 sprite.hint = localization.GetByLabel('UI/Fleet/FleetWindow/FreeMoveOff')
    150                 sprite.opacity = self.disabledOpacity
    151         self.underlay = ListEntryUnderlay(bgParent=self)
    152 
    153     def DeleteSetup(self):
    154         self.fleetSvc.DeleteFleetSetup(setupName=self.settingConfigName)
    155 
    156     def LoadSetup(self):
    157         self.fleetSvc.LoadSetup(self.settingConfigName)
    158 
    159     def GetHint(self):
    160         return self.GetMouseOver(self.setupInfo)
    161 
    162     def GetMouseOver(self, setup):
    163         allWingsInfo = setup[fsConst.FS_WINGS_INFO]
    164         textList = []
    165         unnamedText = localization.GetByLabel('UI/Fleet/FleetWindow/UnnamedSquad')
    166         for wingInfo in allWingsInfo.itervalues():
    167             textList.append('* %s' % wingInfo[fsConst.FS_WING_NAME])
    168             textList += [ '  - %s' % (squadName or unnamedText) for squadName in wingInfo[fsConst.FS_SQUAD_NAMES] ]
    169 
    170         text = '<br>'.join(textList)
    171         return text
    172 
    173     def OnMouseEnter(self, *args):
    174         super(StoredFleetSetupEntry, self).OnMouseEnter(*args)
    175         self.underlay.hovered = True
    176 
    177     def OnMouseExit(self, *args):
    178         super(StoredFleetSetupEntry, self).OnMouseExit(*args)
    179         self.underlay.hovered = False
    180 
    181 
    182 class StoreFleetSetupResults(object):
    183 
    184     def __init__(self):
    185         self.setupName = ''
    186         self.storeMotd = False
    187         self.storeFreeMove = False
    188         self.storeDefaultSquad = False
    189         self.storeMaxSize = False