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

settingSection.py (12841B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\structure\structureSettings\settingSection.py
      2 import carbonui
      3 import carbonui.control.contextMenu.contextMenu
      4 from carbonui.primitives.container import Container
      5 from carbonui.primitives.containerAutoSize import ContainerAutoSize
      6 from carbonui.primitives.sprite import Sprite
      7 from carbonui.util.bunch import Bunch
      8 from carbonui.util.sortUtil import SortListOfTuples
      9 from carbonui.control.buttonIcon import ButtonIcon
     10 from carbonui.control.checkbox import Checkbox
     11 from eve.client.script.ui.control.entries.generic import Generic
     12 from eve.client.script.ui.control.eveLabel import EveLabelMedium
     13 from eve.client.script.ui.control.themeColored import FillThemeColored
     14 from eve.client.script.ui.structure import ChangeSignalConnect
     15 from eve.client.script.ui.structure.structureSettings import AreGroupNodes, GetGroupIDFromNode, CanHaveGroups
     16 from eve.client.script.ui.structure.structureSettings.groupEntryCont import GroupEntry
     17 from eve.client.script.ui.structure.structureSettings.profileEntry import ProfileEntryBase
     18 import carbonui.const as uiconst
     19 from eve.client.script.ui.structure.structureSettings.uiSettingUtil import AddValueEdit
     20 from localization import GetByLabel
     21 from ownergroups.ownergroupConst import NO_GROUP_ID
     22 import structures
     23 from carbonui.uicore import uicore
     24 from menu import MenuLabel
     25 SECTION_LABEL_LEFT = 22
     26 UI_EXPANDED_SETTING = 'structureProfile_expanded_setting_%s'
     27 
     28 class SettingSection(ContainerAutoSize):
     29     default_name = 'SettingSection'
     30     default_align = uiconst.TOTOP
     31 
     32     def ApplyAttributes(self, attributes):
     33         ContainerAutoSize.ApplyAttributes(self, attributes)
     34         self.structureProfileController = attributes.structureProfileController
     35         self.ChangeSignalConnection()
     36         self.settingID = attributes.settingID
     37         sgControllers = self.structureProfileController.GetGroupsBySettingID(self.settingID)
     38         canHaveGroups = CanHaveGroups(self.settingID)
     39         if not canHaveGroups and not sgControllers:
     40             self.structureProfileController.AddGroup(self.settingID, groupID=NO_GROUP_ID, doSignal=False)
     41             sgControllers = self.structureProfileController.GetGroupsBySettingID(self.settingID)
     42         self.AddHeader(canHaveGroups, sgControllers)
     43         self.sectionCont = ContainerAutoSize(parent=self, name='sectionCont', align=uiconst.TOTOP)
     44         self.LoadGroups()
     45         self.OnExpandGroups()
     46 
     47     def ChangeSignalConnection(self, connect = True):
     48         signalAndCallback = [(self.structureProfileController.on_groups_added, self.OnGroupsAdded), (self.structureProfileController.on_group_changed, self.OnGroupsChanged)]
     49         ChangeSignalConnect(signalAndCallback, connect)
     50 
     51     def LoadGroups(self):
     52         self.sectionCont.Flush()
     53         canHaveGroups = CanHaveGroups(self.settingID)
     54         if not canHaveGroups:
     55             return
     56         sgControllers = self.structureProfileController.GetGroupsBySettingID(self.settingID)
     57         if sgControllers:
     58             accessGroupsController = sm.GetService('structureControllers').GetAccessGroupController()
     59             groupIDs = [ c.GetGroupID() for c in sgControllers ]
     60             accessGroupsController.PopulatePublicGroupInfo(groupIDs)
     61             toSort = []
     62             for c in sgControllers:
     63                 groupInfo = accessGroupsController.GetGroupInfoFromID(c.GetGroupID())
     64                 if groupInfo is None:
     65                     continue
     66                 nameLower = groupInfo['name'].lower()
     67                 toSort.append((nameLower, (c, groupInfo)))
     68 
     69             sortedControllers = SortListOfTuples(toSort)
     70             for c, groupInfo in sortedControllers:
     71                 GroupEntry(parent=self.sectionCont, groupID=c.GetGroupID(), settingGroupController=c, structureProfileController=self.structureProfileController, groupInfo=groupInfo)
     72 
     73         else:
     74             x = Generic(parent=self.sectionCont, height=30)
     75             x.Startup()
     76             x.Load(node=Bunch(label=GetByLabel('UI/StructureSettingWnd/NoGroups'), sublevel=1))
     77 
     78     def AddHeader(self, canHaveGroups, sgControllers):
     79         if canHaveGroups:
     80             self.header = SettingSectionHeaderWithGroups(parent=self, structureProfileController=self.structureProfileController, expanderFunc=self.OnExpandGroups, settingID=self.settingID)
     81         else:
     82             sgController = list(sgControllers)[0]
     83             if sgController.GetSettingType() == structures.SETTINGS_TYPE_PERCENTAGE:
     84                 headerClass = SettingSectionHeaderWithPercentage
     85             elif sgController.GetSettingType() == structures.SETTINGS_TYPE_BOOL:
     86                 headerClass = SettingSectionHeaderWithCheckbox
     87             else:
     88                 raise RuntimeError('Bad settingType', sgController.GetSettingType(), sgController.GetSettingID())
     89             self.header = headerClass(parent=self, structureProfileController=self.structureProfileController, sgController=sgController, settingID=self.settingID)
     90 
     91     def OnExpandGroups(self):
     92         isExpanded = settings.user.ui.Get(UI_EXPANDED_SETTING % self.settingID, True)
     93         self.sectionCont.display = isExpanded
     94 
     95     def DragChanged(self, initiated):
     96         canHaveGroups = CanHaveGroups(self.settingID)
     97         if not canHaveGroups:
     98             return
     99         self.header.OnGroupsDragged(initiated)
    100 
    101     def Close(self):
    102         self.ChangeSignalConnection(connect=False)
    103         self.structureProfileController = None
    104         ContainerAutoSize.Close(self)
    105 
    106     def OnGroupsAdded(self, settingID, groupIDs):
    107         if settingID != self.settingID:
    108             return
    109         self.LoadGroups()
    110         self.header.BlinkBgFill()
    111 
    112     def OnGroupsChanged(self):
    113         self.LoadGroups()
    114 
    115 
    116 DRAGGING_OPACITY = 0.75
    117 
    118 class SettingSectionHeaderBase(ProfileEntryBase):
    119     default_name = 'SettingSectionHeader'
    120     rightBtnTexturePath = None
    121     default_height = 30
    122     default_align = uiconst.TOTOP
    123     default_state = uiconst.UI_NORMAL
    124 
    125     def ApplyAttributes(self, attributes):
    126         ProfileEntryBase.ApplyAttributes(self, attributes)
    127         self.bgFill = None
    128         self.settingID = attributes.settingID
    129         self.structureProfileController = attributes.structureProfileController
    130         self.fillUnderlay = FillThemeColored(bgParent=self, colorType=uiconst.COLORTYPE_UIBASECONTRAST)
    131         self.fill = FillThemeColored(bgParent=self, colorType=uiconst.COLORTYPE_UIHILIGHT, padBottom=1)
    132         self.rigthCont = Container(parent=self, name='rightCont', align=uiconst.TORIGHT, width=0)
    133         self.labelCont = Container(parent=self, name='labelCont', padLeft=SECTION_LABEL_LEFT)
    134         self.sectionIcon = Sprite(name='sectionIcon', parent=self.labelCont, align=uiconst.CENTERLEFT, pos=(2, 0, 20, 20), opacity=0.5)
    135         self.sectionNameLabel = EveLabelMedium(name='sectionName', parent=self.labelCont, align=uiconst.CENTERLEFT, text='', autoFadeSides=20)
    136         self.SetSectionLabel()
    137 
    138     def SetSectionLabel(self):
    139         text, hint, settingTexturePath = self.structureProfileController.GetSettingTextAndIcon(self.settingID)
    140         self.sectionIcon.display = False
    141         self.sectionNameLabel.left = 0
    142         if settingTexturePath is not None:
    143             if settingTexturePath > 0:
    144                 self.sectionIcon.SetTexturePath(settingTexturePath)
    145                 self.sectionIcon.display = True
    146             self.sectionNameLabel.left = 30
    147         self.sectionNameLabel.text = text
    148         self.hint = hint
    149 
    150     def Close(self):
    151         self.structureProfileController = None
    152         ProfileEntryBase.Close(self)
    153 
    154     def OnGroupsDragged(self, initiated):
    155         if initiated:
    156             self.ConstructBgFill()
    157             self.FadeBgFill(endValue=DRAGGING_OPACITY)
    158         elif self.bgFill:
    159             self.FadeBgFill(endValue=0)
    160 
    161     def ConstructBgFill(self):
    162         if self.bgFill is None or self.bgFill.destroyed:
    163             self.bgFill = FillThemeColored(bgParent=self, colorType=uiconst.COLORTYPE_UIHILIGHT, opacity=0)
    164 
    165     def FadeBgFill(self, endValue):
    166         uicore.animations.FadeTo(self.bgFill, startVal=self.bgFill.opacity, endVal=endValue, duration=0.25)
    167 
    168     def BlinkBgFill(self):
    169         self.ConstructBgFill()
    170         uicore.animations.FadeTo(self.bgFill, 0.0, 0.75, duration=0.25, curveType=uiconst.ANIM_WAVE, loops=2)
    171 
    172 
    173 class SettingSectionHeaderWithGroups(SettingSectionHeaderBase):
    174 
    175     def ApplyAttributes(self, attributes):
    176         SettingSectionHeaderBase.ApplyAttributes(self, attributes)
    177         self.expanderFunc = attributes.expanderFunc
    178         arrowTexturePath = self.GetExpandedTexture()
    179         left = SECTION_LABEL_LEFT - 20
    180         self.expandArrow = ButtonIcon(name='expandArrow', parent=self, align=uiconst.CENTERLEFT, pos=(left,
    181          0,
    182          16,
    183          16), iconSize=16, texturePath=arrowTexturePath, func=self.OnExpanderClicked)
    184         self.addGroupBtn = ButtonIcon(name='addBtn', parent=self, align=uiconst.CENTERRIGHT, pos=(6, 0, 12, 12), iconSize=12, texturePath='res:/UI/Texture/Icons/Plus_Small.png', func=self.OnAddEntry)
    185         self.rigthCont.width = 20
    186         self.ChangeRightContDisplay(False)
    187 
    188     def GetExpandedTexture(self):
    189         isExpanded = settings.user.ui.Get(UI_EXPANDED_SETTING % self.settingID, True)
    190         if isExpanded:
    191             return 'res:/UI/Texture/Icons/38_16_229.png'
    192         else:
    193             return 'res:/UI/Texture/Icons/38_16_228.png'
    194 
    195     def OnClick(self, *args):
    196         self.OnExpanderClicked()
    197 
    198     def OnExpanderClicked(self, *args):
    199         isExpanded = settings.user.ui.Get(UI_EXPANDED_SETTING % self.settingID, True)
    200         settings.user.ui.Set(UI_EXPANDED_SETTING % self.settingID, not isExpanded)
    201         self.expanderFunc()
    202         newPath = self.GetExpandedTexture()
    203         self.expandArrow.texturePath = newPath
    204         self.expandArrow.SetTexturePath(newPath)
    205 
    206     def FadeSprites(self, toValue):
    207         SettingSectionHeaderBase.FadeSprites(self, toValue)
    208 
    209     def OnAddEntry(self, *args):
    210         carbonui.control.contextMenu.contextMenu.ShowMenu(self)
    211 
    212     def GetMenu(self, *args):
    213         m = []
    214         if CanHaveGroups(self.settingID):
    215             accessGroupsController = sm.GetService('structureControllers').GetAccessGroupController()
    216             myGroups = accessGroupsController.GetMyGroups()
    217             if myGroups:
    218                 m += [[MenuLabel('UI/StructureSettingWnd/AddGroupToSetting'), ('isDynamic', self._GetMyGroupsMenu, (myGroups,))]]
    219         m += [(MenuLabel('UI/StructureSettingWnd/ManageAccessGroups'), uicore.cmd.OpenAccessGroupsWindow, ())]
    220         return m
    221 
    222     def _GetMyGroupsMenu(self, myGroups):
    223         m = []
    224         groupsWithSetting = self.structureProfileController.GetGroupsBySettingID(self.settingID)
    225         groupIDs = {g.groupID for g in groupsWithSetting}
    226         for groupID, g in myGroups.iteritems():
    227             if groupID in groupIDs:
    228                 continue
    229             groupName = g.name
    230             m.append((groupName.lower(), (groupName, self.AddGroupsToSettingSection, ([groupID],))))
    231 
    232         m = SortListOfTuples(m)
    233         return m
    234 
    235     def ChangeRightContDisplay(self, show = False):
    236         self.rigthCont.display = show
    237 
    238     def OnDropData(self, dragSource, dragData):
    239         if not dragData or not CanHaveGroups(settingID=self.settingID):
    240             return
    241         if not AreGroupNodes(dragData):
    242             return
    243         groupIDsToAdd = filter(None, [ GetGroupIDFromNode(eachNode) for eachNode in dragData ])
    244         if groupIDsToAdd:
    245             self.AddGroupsToSettingSection(groupIDsToAdd)
    246 
    247     def AddGroupsToSettingSection(self, groupIDsToAdd):
    248         self.structureProfileController.AddNewGroups(self.settingID, groupIDsToAdd)
    249 
    250 
    251 class SettingSectionHeaderWithPercentage(SettingSectionHeaderBase):
    252 
    253     def ApplyAttributes(self, attributes):
    254         SettingSectionHeaderBase.ApplyAttributes(self, attributes)
    255         self.sgController = attributes.sgController
    256         self.valueEdit = AddValueEdit(self.rigthCont, self.sgController, callback=self.OnRateChanged)
    257         self.rigthCont.width = self.valueEdit.width
    258 
    259     def OnRateChanged(self, value, *args):
    260         self.sgController.SetValue(value)
    261 
    262 
    263 class SettingSectionHeaderWithCheckbox(SettingSectionHeaderBase):
    264 
    265     def ApplyAttributes(self, attributes):
    266         SettingSectionHeaderBase.ApplyAttributes(self, attributes)
    267         self.sgController = attributes.sgController
    268         checked = bool(self.sgController.GetValue())
    269         left = SECTION_LABEL_LEFT - 20 - 2
    270         self.checkbox = Checkbox(parent=self, align=uiconst.CENTERLEFT, text='', checked=checked, callback=self.CheckBoxChange, pos=(4, 0, 0, 20))
    271 
    272     def CheckBoxChange(self, cb, *args):
    273         value = cb.GetValue()
    274         self.sgController.SetValue(value)
    275 
    276     def OnClick(self, *args):
    277         self.checkbox.ToggleState()