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

corpPlansPanel.py (11305B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\skillPlan\browser\corpPlansPanel.py
      2 import math
      3 import localization
      4 import uthread2
      5 from carbonui import uiconst
      6 from carbonui.control.button import Button
      7 from carbonui.primitives.container import Container
      8 from characterdata import careerpath
      9 from eve.client.script.ui import eveColor
     10 from eve.client.script.ui.control.eveLabel import EveLabelMedium
     11 from eve.client.script.ui.control.eveLoadingWheel import LoadingWheel
     12 from eve.client.script.ui.control.toggleButtonGroupCircular import ToggleButtonGroupCircular
     13 from eve.client.script.ui.quickFilter import QuickFilterEdit
     14 from eve.client.script.ui.shared.careerPortal import careerConst
     15 from eve.client.script.ui.skillPlan import skillPlanUISignals, skillPlanUtil
     16 from eve.client.script.ui.skillPlan.browser.noContentHintContainer import NoContentHintContainer
     17 from eve.client.script.ui.skillPlan.browser.skillPlanScroll import SkillPlanScroll
     18 from eve.client.script.ui.skillPlan.skillPlanConst import BUTTON_GROUP_ID_SKILL_PLANS, BUTTON_GROUP_ID_TOP_LEVEL, PANEL_CERTIFIED, PANEL_SKILLS_CATALOGUE
     19 from eve.common.lib import appConst
     20 from localization import GetByLabel, GetByMessageID
     21 from skills.skillplan import skillPlanSignals, skillPlanConst
     22 from skills.skillplan.errors import SkillPlanConnectionError
     23 from skills.skillplan.skillPlanService import GetSkillPlanSvc
     24 NUM_PER_PAGE = 12
     25 
     26 def CreateNew(self, *args):
     27     skillPlanUISignals.on_create_new_corp_button()
     28 
     29 
     30 class CreateCorpPlanButton(Button):
     31     default_minWidth = 200
     32     default_width = 200
     33     default_height = 70
     34     default_label = GetByLabel('UI/SkillPlan/CreateNewSkillPlan')
     35     default_func = CreateNew
     36 
     37     def ApplyAttributes(self, attributes):
     38         super(CreateCorpPlanButton, self).ApplyAttributes(attributes)
     39         self.numPlans = None
     40 
     41     def UpdateState(self, numPlans):
     42         self.numPlans = numPlans
     43         if not session.corprole & appConst.corpRoleSkillPlanManager:
     44             self.Disable()
     45         elif numPlans >= skillPlanConst.MAX_CORP_PLANS:
     46             self.Disable()
     47         else:
     48             self.Enable()
     49 
     50     def LoadTooltipPanel(self, tooltipPanel, owner):
     51         tooltipPanel.LoadStandardSpacing()
     52         tooltipPanel.columns = 1
     53         tooltipPanel.AddMediumHeader(text=GetByLabel('UI/SkillPlan/CreateCorpSkillPlan'))
     54         tooltipPanel.AddLabelMedium(text=GetByLabel('UI/SkillPlan/PlansInTotal', numPlans=self.numPlans, numTotal=skillPlanConst.MAX_CORP_PLANS))
     55         warningText = self._GetWarningText()
     56         if warningText:
     57             tooltipPanel.AddLabelMedium(text=warningText, color=eveColor.WARNING_ORANGE, wrapWidth=200)
     58 
     59     def _GetWarningText(self):
     60         if not session.corprole & appConst.corpRoleSkillPlanManager:
     61             warningText = GetByLabel('UI/SkillPlan/CorpPlanCreateRequiresRoleHint')
     62         elif self.numPlans >= skillPlanConst.MAX_CORP_PLANS:
     63             warningText = GetByLabel('UI/SkillPlan/MaximumSkillPlanReached', numPlans=skillPlanConst.MAX_CORP_PLANS)
     64         else:
     65             warningText = ''
     66         return warningText
     67 
     68 
     69 class CorpSkillPlansPaginationController(object):
     70 
     71     def __init__(self, numPerPage):
     72         self.numPerPage = numPerPage
     73         self.currPage = 0
     74         self.categoryID = None
     75         self.filterText = None
     76 
     77     def GetData(self):
     78         allData = self.GetAllData()
     79         start = self.currPage * self.numPerPage
     80         end = min(len(allData), (self.currPage + 1) * self.numPerPage)
     81         return allData[start:end]
     82 
     83     def GetNumPages(self):
     84         return int(math.ceil(len(self.GetAllData()) / float(self.numPerPage)))
     85 
     86     def SetNumPerPage(self, numPerPage):
     87         self.numPerPage = numPerPage
     88 
     89     def SetCurrPage(self, currPage):
     90         self.currPage = currPage
     91 
     92     def GetAllData(self):
     93         skillPlans = GetSkillPlanSvc().GetAllCorp().values()
     94         skillPlans = filter(self._ApplyFilters, skillPlans)
     95         skillPlans = localization.util.Sort(skillPlans, key=lambda x: x.GetName())
     96         return skillPlans
     97 
     98     def _ApplyFilters(self, skillPlan):
     99         categoryID = self.categoryID
    100         if categoryID and categoryID != skillPlan.GetCategoryID():
    101             return False
    102         if self.filterText:
    103             return self.filterText in skillPlan.GetName().lower()
    104         return True
    105 
    106     def SetCategoryID(self, value):
    107         self.categoryID = value
    108 
    109     def SetFilterText(self, value):
    110         if value:
    111             self.filterText = value.lower()
    112         else:
    113             self.filterText = None
    114 
    115 
    116 class CorpPlansPanel(Container):
    117 
    118     def ApplyAttributes(self, attributes):
    119         super(CorpPlansPanel, self).ApplyAttributes(attributes)
    120         skillPlanSignals.on_deleted.connect(self.OnSkillPlanDeleted)
    121         skillPlanSignals.on_created.connect(self.OnSkillPlanCreated)
    122         skillPlanSignals.on_saved.connect(self.OnSkillPlanSaved)
    123         self.ConstructLayout()
    124         self.paginationController = CorpSkillPlansPaginationController(NUM_PER_PAGE)
    125 
    126     def Show(self, *args):
    127         super(CorpPlansPanel, self).Show(*args)
    128         uthread2.start_tasklet(self.ReconstructPagination)
    129 
    130     def ConstructLayout(self):
    131         self.filtersCont = Container(name='filtersCont', parent=self, align=uiconst.TOTOP, height=48, padding=(0, 10, 10, 10))
    132         self.quickFilterEdit = QuickFilterEdit(parent=self.filtersCont, align=uiconst.CENTERRIGHT, width=200, height=32, callback=self.OnQuickFilterEdit)
    133         self.numShownLabel = EveLabelMedium(parent=self.filtersCont, align=uiconst.CENTERRIGHT, left=210)
    134         self.categoryButtonGroup = ToggleButtonGroupCircular(parent=self.filtersCont, align=uiconst.TOLEFT, callback=self.OnCategoryButtonGroup, isOptional=True)
    135         for label, careerPathID in self.GetCategoryButtonData():
    136             self.categoryButtonGroup.AddButton(btnID=careerPathID, iconPath=careerConst.CAREERS_32_SIZES.get(careerPathID), iconSize=32, btnSize=48, hint=label)
    137 
    138         self.noContentHint = NoContentHintContainer(parent=self, align=uiconst.VERTICALLY_CENTERED, state=uiconst.UI_HIDDEN, btnClass=CreateCorpPlanButton)
    139         self.buttonCont = Container(name='buttonCont', parent=self, align=uiconst.TOBOTTOM, state=uiconst.UI_HIDDEN, padTop=12, height=30)
    140         self.paginationButtonGroup = ToggleButtonGroupCircular(parent=self.buttonCont, align=uiconst.TOLEFT, callback=self.OnPaginationButton)
    141         self.createBtn = CreateCorpPlanButton(name='createBtn', parent=self.buttonCont, align=uiconst.CENTER)
    142         self.loadingWheel = LoadingWheel(parent=self, align=uiconst.CENTER, state=uiconst.UI_HIDDEN, idx=0)
    143         self.scroll = SkillPlanScroll(parent=self, padTop=20, padBottom=10)
    144         self.scroll.onSizeChangeSignal.connect(self.OnScrollSizeChanged)
    145 
    146     def OnQuickFilterEdit(self):
    147         self.paginationController.SetFilterText(self.quickFilterEdit.GetValue())
    148         self.ReconstructPagination()
    149 
    150     def ReconstructPagination(self):
    151         try:
    152             numPages = self.paginationController.GetNumPages()
    153             show_pagination = numPages > 1
    154             self.paginationButtonGroup.display = show_pagination
    155             self.paginationButtonGroup.ClearButtons()
    156             self.createBtn.align = uiconst.TORIGHT if show_pagination else uiconst.CENTER
    157             for i in range(numPages):
    158                 self.paginationButtonGroup.AddButton(btnID=i, label=str(i + 1), btnSize=32)
    159 
    160             if numPages:
    161                 self.paginationButtonGroup.SelectByID(0)
    162             else:
    163                 self.PopulateScroll()
    164         except SkillPlanConnectionError:
    165             self.HandleSkillPlanConnectionError()
    166 
    167     def HandleSkillPlanConnectionError(self):
    168         skillPlanUtil.SetPersistedPanelID(BUTTON_GROUP_ID_TOP_LEVEL, PANEL_SKILLS_CATALOGUE)
    169         skillPlanUtil.SetPersistedPanelID(BUTTON_GROUP_ID_SKILL_PLANS, PANEL_CERTIFIED)
    170         self.filtersCont.Hide()
    171         self.scroll.Hide()
    172         self.noContentHint.Show()
    173         self.noContentHint.SetText(GetByLabel('UI/SkillPlan/ConnectionError'))
    174         self.noContentHint.HideCreateBtn()
    175 
    176     def OnPaginationButton(self, *args):
    177         self.paginationController.SetCurrPage(self.paginationButtonGroup.GetValue())
    178         self.PopulateScroll()
    179 
    180     def OnCategoryButtonGroup(self, *args):
    181         self.paginationController.SetCategoryID(self.categoryButtonGroup.GetValue())
    182         self.ReconstructPagination()
    183 
    184     def GetCategoryButtonData(self):
    185         return [ (GetByMessageID(c.nameID), cID) for cID, c in careerpath.get_career_paths().iteritems() ]
    186 
    187     def OnScrollSizeChanged(self, width, height):
    188         uthread2.start_tasklet(self.UpdateState)
    189 
    190     def UpdateState(self):
    191         if self.destroyed:
    192             return
    193         numPlansTotal = self.GetNumPlansTotal()
    194         self._UpdateFilterCont(numPlansTotal)
    195         self._UpdateButtonCont()
    196         self.createBtn.UpdateState(numPlansTotal)
    197         self.noContentHint.UpdateState(numPlansTotal)
    198         numShown = len(self.paginationController.GetData())
    199         self.numShownLabel.text = GetByLabel('UI/SkillPlan/NumShown', numShown=numShown, numTotal=numPlansTotal)
    200 
    201     def GetNumPlansTotal(self):
    202         numPlans = len(GetSkillPlanSvc().GetAllCorp())
    203         return numPlans
    204 
    205     def _UpdateFilterCont(self, numPlans):
    206         self.filtersCont.display = numPlans > 0
    207 
    208     def _UpdateButtonCont(self):
    209         if not self.scroll.display:
    210             self.buttonCont.Hide()
    211             self.buttonCont.SetParent(self, 0)
    212         elif not self.scroll.IsVerticalScrollBarVisible():
    213             self.buttonCont.SetAlign(uiconst.TOTOP)
    214             self.buttonCont.SetParent(self.scroll)
    215         else:
    216             self.buttonCont.SetAlign(uiconst.TOBOTTOM)
    217             self.buttonCont.SetParent(self, 0)
    218 
    219     def PopulateScroll(self):
    220         if self.destroyed:
    221             return
    222         skillPlansShown = self._GetSkillPlans()
    223         if skillPlansShown:
    224             self.scroll.Show()
    225             self.buttonCont.SetParent(self, 0)
    226             self.scroll.ConstructSkillPlanEntries(skillPlansShown)
    227         else:
    228             self.scroll.Hide()
    229         self._UpdateNoContentHint()
    230         self.UpdateState()
    231 
    232     def _UpdateNoContentHint(self):
    233         noContentHint = self._GetNoContentHint()
    234         if noContentHint:
    235             self.noContentHint.SetText(noContentHint)
    236             self.noContentHint.state = uiconst.UI_PICKCHILDREN
    237         else:
    238             self.noContentHint.Hide()
    239 
    240     def _GetNoContentHint(self):
    241         if self.paginationController.GetData():
    242             return None
    243         elif self.GetNumPlansTotal():
    244             return GetByLabel('UI/SkillPlan/NoSkillPlansMatchingFilters')
    245         else:
    246             return GetByLabel('UI/SkillPlan/NoCorpSkillPlans')
    247 
    248     def _GetSkillPlans(self):
    249         self.loadingWheel.Show()
    250         self.buttonCont.Hide()
    251         try:
    252             skillPlans = self.paginationController.GetData()
    253             self.buttonCont.Show()
    254         finally:
    255             self.loadingWheel.Hide()
    256 
    257         return skillPlans
    258 
    259     def OnSkillPlanDeleted(self, skillPlanID):
    260         self.ReconstructPagination()
    261 
    262     def OnSkillPlanCreated(self, skillPlanID):
    263         self.ReconstructPagination()
    264 
    265     def OnSkillPlanSaved(self, skillPlan):
    266         self.ReconstructPagination()