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

skillEntryPrimaryButton.py (10503B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\skillPlan\contents\skillEntryPrimaryButton.py
      2 from carbonui import ButtonStyle
      3 from carbonui.control.button import Button
      4 from carbonui.uicore import uicore
      5 from eve.client.script.ui.shared.cloneGrade import ORIGIN_SKILLPLAN
      6 from eve.client.script.ui.tooltips import tooltipUtil
      7 from eveexceptions import UserError
      8 from itertoolsext.Enum import Enum
      9 from localization import GetByLabel
     10 from localization.formatters import FormatNumeric
     11 from omega.client.clone_grade_svc import get_clone_grade_svc
     12 from skills import skillConst
     13 
     14 @Enum
     15 
     16 class State(object):
     17     OMEGA_MISSING = 'REQUIRES_OMEGA'
     18     OMEGA_MISSING_FOR_NEXT_LEVEL = 'OMEGA_MISSING_FOR_NEXT_LEVEL'
     19     SKILLBOOK_MISSING = 'SKILLBOOK_MISSING'
     20     IN_QUEUE_CAN_REMOVE = 'IN_QUEUE_CAN_REMOVE'
     21     IN_QUEUE_CANT_REMOVE = 'IN_QUEUE_CANT_REMOVE'
     22     TRAINED = 'FULLY_TRAINED'
     23     CAN_ADD_TO_QUEUE = 'CAN_ADD_TO_QUEUE'
     24     ALL_IN_QUEUE = 'ALL_IN_QUEUE'
     25 
     26 
     27 class SkillEntryPrimaryButton(Button):
     28     default_iconSize = 20
     29     STYLE_PER_STATE = {State.OMEGA_MISSING: ButtonStyle.MONETIZATION,
     30      State.OMEGA_MISSING_FOR_NEXT_LEVEL: ButtonStyle.MONETIZATION,
     31      State.SKILLBOOK_MISSING: ButtonStyle.DANGER,
     32      State.IN_QUEUE_CAN_REMOVE: ButtonStyle.NORMAL,
     33      State.IN_QUEUE_CANT_REMOVE: ButtonStyle.NORMAL,
     34      State.TRAINED: ButtonStyle.NORMAL,
     35      State.CAN_ADD_TO_QUEUE: ButtonStyle.NORMAL,
     36      State.ALL_IN_QUEUE: ButtonStyle.NORMAL}
     37     HINT_PER_STATE = {State.OMEGA_MISSING: 'UI/CloneState/RequiresOmegaClone',
     38      State.OMEGA_MISSING_FOR_NEXT_LEVEL: 'UI/SkillPlan/RequiresOmegaCloneForNextLevel',
     39      State.SKILLBOOK_MISSING: 'UI/SkillPlan/ClickToBuyMissingSkillAndRequirements',
     40      State.IN_QUEUE_CAN_REMOVE: 'UI/SkillPlan/RemoveFromQueue',
     41      State.IN_QUEUE_CANT_REMOVE: 'UI/SkillPlan/RemoveFromQueueLocked',
     42      State.TRAINED: 'UI/SkillPlan/AlreadyTrained',
     43      State.ALL_IN_QUEUE: 'UI/SkillPlan/AllInQueue',
     44      State.CAN_ADD_TO_QUEUE: 'UI/SkillPlan/AddToQueue'}
     45     TEXTUREPATH_PER_STATE = {State.OMEGA_MISSING: 'res:/UI/Texture/classes/Seasons/omega_32x32.png',
     46      State.OMEGA_MISSING_FOR_NEXT_LEVEL: 'res:/UI/Texture/classes/Seasons/omega_32x32.png',
     47      State.SKILLBOOK_MISSING: 'res:/UI/Texture/WindowIcons/skills.png',
     48      State.IN_QUEUE_CAN_REMOVE: 'res:/UI/Texture/classes/SkillPlan/buttonIcons/removeIcon.png',
     49      State.IN_QUEUE_CANT_REMOVE: 'res:/UI/Texture/classes/SkillPlan/buttonIcons/removeIcon.png',
     50      State.TRAINED: 'res:/UI/Texture/classes/SkillPlan/buttonIcons/checkMark.png',
     51      State.ALL_IN_QUEUE: 'res:/UI/Texture/classes/SkillPlan/buttonIcons/buttonIconPlus.png',
     52      State.CAN_ADD_TO_QUEUE: 'res:/UI/Texture/classes/SkillPlan/buttonIcons/buttonIconPlus.png'}
     53     DISABLED_STATES = [State.IN_QUEUE_CANT_REMOVE, State.TRAINED, State.ALL_IN_QUEUE]
     54 
     55     def ApplyAttributes(self, attributes):
     56         if 'func' not in attributes:
     57             attributes['func'] = self._OnClick
     58         super(SkillEntryPrimaryButton, self).ApplyAttributes(attributes)
     59         self.controller = attributes.get('skillController', None)
     60         self.primaryButtonState = State.CAN_ADD_TO_QUEUE
     61         self.onOmegaMissingActionCallback = attributes.get('onOmegaMissingAction', self.OnOmegaMissingAction)
     62         self.onSkillbookMissingActionCallback = attributes.get('onSkillbookMissingAction', self.OnSkillbookMissingAction)
     63         self.onAlreadyTrainedActionCallback = attributes.get('onAlreadyTrainedAction', self.OnAlreadyTrainedAction)
     64         self.onAddToQueueActionCallback = attributes.get('onAddToQueueAction', self.OnAddToQueueAction)
     65         self.onRemoveFromQueueActionCallback = attributes.get('onRemoveFromQueueAction', self.OnRemoveFromQueueAction)
     66         self.onCantRemoveFromQueueActionCallback = attributes.get('onCantRemoveFromQueueAction', self.OnCantRemoveFromQueueAction)
     67         self.onAllInQueueActionCallback = attributes.get('onAllInQueueAction', self.OnAllInQueueAction)
     68         self.onDefaultActionCallback = attributes.get('onDefaultAction', self.OnDefaultAction)
     69         self.UpdateState()
     70 
     71     def UpdateState(self):
     72         if not self.controller:
     73             return
     74         self.primaryButtonState = self._GetState()
     75         if self.primaryButtonState in self.DISABLED_STATES:
     76             self.Disable()
     77         else:
     78             self.Enable()
     79         self.texturePath = self.TEXTUREPATH_PER_STATE[self.primaryButtonState]
     80         self.style = self.STYLE_PER_STATE[self.primaryButtonState]
     81 
     82     def GetTooltipText(self):
     83         hintLabel = self.HINT_PER_STATE[self.primaryButtonState]
     84         if self.primaryButtonState == State.CAN_ADD_TO_QUEUE:
     85             hint = GetByLabel(hintLabel, skillLevel=self._GetSkillLevel() or 1)
     86         else:
     87             hint = GetByLabel(hintLabel)
     88         return hint
     89 
     90     def LoadTooltipPanel(self, panel, *args):
     91         if uicore.IsDragging():
     92             return
     93         panel.LoadStandardSpacing()
     94         panel.columns = 2
     95         text = self.GetTooltipText()
     96         panel.AddMediumHeader(text=text)
     97         if self.primaryButtonState == State.CAN_ADD_TO_QUEUE:
     98             self._AddSkillPointAndTrainingTime(panel)
     99 
    100     def _AddSkillPointAndTrainingTime(self, panel):
    101         nextLevel = self._GetSkillLevel() or 1
    102         self._AddSPRequired(nextLevel, panel)
    103         self._AddSPPerMinute(panel)
    104 
    105     def _AddSPRequired(self, nextLevel, panel):
    106         panel.AddLabelMedium(text=GetByLabel('UI/Skills/SkillPointsRequired'))
    107         skillPoints = self.controller.GetSkillPointsMissingForLevel(nextLevel)
    108         panel.AddLabelMedium(text=FormatNumeric(skillPoints, useGrouping=True))
    109 
    110     def _AddSPPerMinute(self, panel):
    111         spPerMin = sm.GetService('skills').GetSkillpointsPerMinute(self.controller.GetTypeID())
    112         panel.AddLabelMedium(text=GetByLabel('UI/CharacterSheet/CharacterSheetWindow/SkillTabs/SpPerMinute', spPerMin=spPerMin), colSpan=2)
    113 
    114     def _GetSkillLevel(self):
    115         return self.controller.GetNextLevelToAddToQueue()
    116 
    117     def _GetState(self):
    118         if self.controller.IsFullyTrained():
    119             return State.TRAINED
    120         if not get_clone_grade_svc().is_omega_with_grace_period() and not self.controller.IsCloneStateMet():
    121             return State.OMEGA_MISSING
    122         restrictLevel = self.controller.GetCurrCloneStateMaxLevel()
    123         levelToCheck = max(self.controller.GetMyLevel(), sm.GetService('skillqueue').FindHighestLevelInQueue(self.controller.GetTypeID()))
    124         levelToCheck = min(levelToCheck + 1, skillConst.skill_max_level)
    125         if levelToCheck > restrictLevel:
    126             return State.OMEGA_MISSING_FOR_NEXT_LEVEL
    127         if not self.controller.IsInjected() or not self.controller.IsAllPrereqsInjected():
    128             return State.SKILLBOOK_MISSING
    129         queueLevel = sm.GetService('skillqueue').FindHighestLevelInQueue(self.controller.GetTypeID())
    130         if queueLevel == skillConst.skill_max_level:
    131             return State.ALL_IN_QUEUE
    132         return State.CAN_ADD_TO_QUEUE
    133 
    134     def _OnClick(self, *args):
    135         if self.primaryButtonState == State.OMEGA_MISSING:
    136             self.onOmegaMissingActionCallback()
    137         elif self.primaryButtonState == State.OMEGA_MISSING_FOR_NEXT_LEVEL:
    138             self.onOmegaMissingActionCallback()
    139         elif self.primaryButtonState == State.SKILLBOOK_MISSING:
    140             self.onSkillbookMissingActionCallback()
    141         elif self.primaryButtonState == State.TRAINED:
    142             self.onAlreadyTrainedActionCallback()
    143         elif self.primaryButtonState == State.IN_QUEUE_CANT_REMOVE:
    144             self.onCantRemoveFromQueueActionCallback()
    145         elif self.primaryButtonState == State.IN_QUEUE_CAN_REMOVE:
    146             self.onRemoveFromQueueActionCallback()
    147         elif self.primaryButtonState == State.CAN_ADD_TO_QUEUE:
    148             self.onAddToQueueActionCallback()
    149         else:
    150             self.onDefaultActionCallback()
    151 
    152     def OnClick(self, *args):
    153         super(SkillEntryPrimaryButton, self).OnClick(*args)
    154         tooltipUtil.RefreshTooltipForOwner(self)
    155 
    156     def OnOmegaMissingAction(self):
    157         uicore.cmd.OpenCloneUpgradeWindow(ORIGIN_SKILLPLAN)
    158 
    159     def OnSkillbookMissingAction(self):
    160         self.controller.BuyAllRequiredSkillbooks()
    161 
    162     def OnAlreadyTrainedAction(self):
    163         pass
    164 
    165     def OnAddToQueueAction(self):
    166         sm.GetService('skillqueue').AddSkillAndRequirementsToQueue(self.controller.GetTypeID(), skillLevel=None)
    167 
    168     def OnRemoveFromQueueAction(self):
    169         levelToRemove = sm.GetService('skillqueue').FindHighestLevelInQueue(self.controller.GetTypeID())
    170         sm.GetService('skillqueue').RemoveSkillsFromQueue([(self.controller.GetTypeID(), levelToRemove)])
    171 
    172     def OnCantRemoveFromQueueAction(self):
    173         pass
    174 
    175     def OnAllInQueueAction(self):
    176         pass
    177 
    178     def OnDefaultAction(self):
    179         sm.GetService('skillqueue').AddSkillAndRequirementsToQueue(self.controller.GetTypeID(), skillLevel=None)
    180 
    181 
    182 class SkillLevelEntryPrimaryButton(SkillEntryPrimaryButton):
    183 
    184     def ApplyAttributes(self, attributes):
    185         self.level = attributes.get('skillLevel', None)
    186         super(SkillLevelEntryPrimaryButton, self).ApplyAttributes(attributes)
    187 
    188     def _GetState(self):
    189         if not get_clone_grade_svc().is_omega_with_grace_period() and self.level > self.controller.GetCurrCloneStateMaxLevel():
    190             return State.OMEGA_MISSING
    191         if not self.controller.IsInjected() or not self.controller.IsAllPrereqsInjected():
    192             return State.SKILLBOOK_MISSING
    193         if self.controller.IsInQueue(level=self.level):
    194             try:
    195                 sm.GetService('skillqueue').CheckCanRemoveSkillFromQueue(self.controller.GetTypeID(), self.level)
    196             except UserError:
    197                 return State.IN_QUEUE_CANT_REMOVE
    198 
    199             return State.IN_QUEUE_CAN_REMOVE
    200         if self.controller.GetMyLevel() >= self.level:
    201             return State.TRAINED
    202         return State.CAN_ADD_TO_QUEUE
    203 
    204     def _GetSkillLevel(self):
    205         return self.level or super(SkillLevelEntryPrimaryButton, self)._GetSkillLevel()
    206 
    207     def OnAddToQueueAction(self):
    208         sm.GetService('skillqueue').AddSkillAndRequirementsToQueue(self.controller.GetTypeID(), skillLevel=self.level)
    209 
    210     def OnRemoveFromQueueAction(self):
    211         sm.GetService('skillqueue').RemoveSkillsFromQueue([(self.controller.GetTypeID(), self.level)])
    212 
    213     def OnDefaultAction(self):
    214         sm.GetService('skillqueue').AddSkillAndRequirementsToQueue(self.controller.GetTypeID(), skillLevel=self.level)