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

material.py (11397B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\industry\views\material.py
      2 from math import pi
      3 import evetypes
      4 import localization
      5 import trinity
      6 from carbon.client.script.environment.AudioUtil import PlaySound
      7 from carbon.common.script.util.format import FmtAmt
      8 from carbonui import fontconst
      9 from carbonui import uiconst
     10 from carbonui.primitives.container import Container
     11 from carbonui.primitives.sprite import Sprite
     12 from carbonui.uicore import uicore
     13 from eve.client.script.ui.control.entries.generic import Generic
     14 from eve.client.script.ui.control.entries.item import Item
     15 from eve.client.script.ui.control.entries.util import GetFromClass
     16 from eve.client.script.ui.control.eveLabel import Label, EveLabelMedium
     17 from eve.client.script.ui.control.eveScroll import Scroll
     18 from eve.client.script.ui.control.gauge import Gauge
     19 from eve.client.script.ui.control.itemIcon import ItemIcon
     20 from eve.client.script.ui.control.themeColored import FillThemeColored
     21 from eve.client.script.ui.shared.industry.industryUIConst import COLOR_READY, COLOR_FRAME, COLOR_NOTREADY
     22 from eve.client.script.ui.shared.industry.views.industryTooltips import MaterialTooltipPanel
     23 from eveservices.menu import GetMenuService
     24 from menu import MenuLabel
     25 OPACITY_DEFAULT = 0.5
     26 OPACITY_HOVER = 1.5
     27 
     28 class MaterialBase(Container):
     29     __notifyevents__ = ['OnIndustryMaterialValueSettingChanged']
     30     default_name = 'Material'
     31     default_state = uiconst.UI_NORMAL
     32     default_width = 45
     33     default_height = 60
     34     isDragObject = True
     35 
     36     def ApplyAttributes(self, attributes):
     37         Container.ApplyAttributes(self, attributes)
     38         sm.RegisterNotify(self)
     39         self.jobData = attributes.jobData
     40         self.materialData = attributes.materialData
     41         self.materialData.on_updated.connect(self.OnMaterialUpdated)
     42         self.materialData.on_errors.connect(self.OnMaterialErrors)
     43         self.isReady = None
     44         self.icon = ItemIcon(parent=self, typeID=self.materialData.typeID, align=uiconst.CENTERTOP, state=uiconst.UI_DISABLED, pos=(0, 6, 32, 32), showOmegaOverlay=False)
     45         self.label = Label(parent=self, align=uiconst.CENTERBOTTOM, top=-1, fontsize=fontconst.EVE_SMALL_FONTSIZE)
     46         self.bgGlow = Sprite(name='bgGlow', parent=self, align=uiconst.TOALL, state=uiconst.UI_DISABLED, texturePath='res:/UI/Texture/Classes/Industry/Input/bgGlow.png', color=COLOR_READY, opacity=OPACITY_DEFAULT)
     47         self.bgFrame = Sprite(name='bgFrame', parent=self, align=uiconst.TOALL, state=uiconst.UI_DISABLED, texturePath='res:/UI/Texture/Classes/Industry/Input/bgFrame.png', color=COLOR_FRAME)
     48         FillThemeColored(bgParent=self, opacity=0.5)
     49         Sprite(name='valueBg', parent=self, align=uiconst.TOALL, state=uiconst.UI_DISABLED, texturePath='res:/UI/Texture/Classes/Industry/Input/valueBg.png', color=COLOR_FRAME, opacity=0.1)
     50         self.gauge = Gauge(parent=self, align=uiconst.BOTTOMLEFT, state=uiconst.UI_DISABLED, pos=(0,
     51          13,
     52          self.width + 1,
     53          0), gaugeHeight=3, gradientBrightnessFactor=1.0, backgroundColor=(0, 0, 0, 0))
     54         self.bgFill = Sprite(name='bgFill', parent=self, align=uiconst.TOALL, state=uiconst.UI_DISABLED, texturePath='res:/UI/Texture/Classes/Industry/Input/bg.png', color=COLOR_FRAME, opacity=0.1)
     55         self.ConstructBackground()
     56         self.UpdateState()
     57 
     58     def ConstructBackground(self):
     59         pass
     60 
     61     def OnMaterialUpdated(self, material):
     62         self.UpdateState()
     63 
     64     def OnMaterialErrors(self, material, errors):
     65         self.UpdateState()
     66 
     67     def UpdateState(self):
     68         pass
     69 
     70     def IsReady(self):
     71         return self.materialData.valid
     72 
     73     def OnMouseEnter(self, *args):
     74         uicore.animations.FadeIn(self.bgGlow, OPACITY_HOVER, duration=0.15)
     75         PlaySound(uiconst.SOUND_BUTTON_HOVER)
     76 
     77     def OnMouseExit(self, *args):
     78         uicore.animations.FadeIn(self.bgGlow, OPACITY_DEFAULT, duration=0.3)
     79 
     80     def GetDragData(self):
     81         return self.icon.GetDragData()
     82 
     83     def OnIndustryMaterialValueSettingChanged(self):
     84         self.UpdateLabel()
     85 
     86     def UpdateLabel(self):
     87         if settings.char.ui.Get('inputMaterialShowTotalRequired', True):
     88             value = self.materialData.quantity
     89         else:
     90             value = self.materialData.missing
     91         self.label.text = FmtAmt(value, 'ss')
     92 
     93 
     94 class Material(MaterialBase):
     95 
     96     def ConstructBackground(self):
     97         self.patternNotReady = Sprite(name='patternNotReady', parent=self, align=uiconst.TOALL, state=uiconst.UI_DISABLED, texturePath='res:/UI/Texture/Classes/Industry/Input/bgNotReady.png', color=COLOR_NOTREADY, opacity=0.0)
     98 
     99     def UpdateState(self):
    100         self.ratio = self.materialData.ratio
    101         self.gauge.SetValue(self.ratio)
    102         self.UpdateLabel()
    103         duration = 0.3
    104         wasReady = self.isReady
    105         color = COLOR_FRAME if self.IsReady() else COLOR_NOTREADY
    106         uicore.animations.SpColorMorphTo(self.bgFrame, endColor=color[:3], duration=duration)
    107         if wasReady is not None and wasReady != self.isReady:
    108             uicore.animations.FadeTo(self.bgFill, 0.8, 0.1, duration=0.3)
    109         color = COLOR_READY if self.IsReady() else COLOR_NOTREADY
    110         uicore.animations.SpColorMorphTo(self.bgGlow, endColor=color[:3], duration=duration)
    111         self.gauge.SetColor(color, animDuration=duration)
    112         opacity = 0.0 if self.IsReady() else 1.0
    113         uicore.animations.FadeIn(self.patternNotReady, opacity, duration=duration)
    114         if wasReady and not self.isReady:
    115             sm.GetService('audio').SendUIEvent('ind_insufficientMaterials')
    116         elif not wasReady and self.isReady:
    117             sm.GetService('audio').SendUIEvent('ind_sufficientMaterials')
    118 
    119     def LoadTooltipPanel(self, tooltipPanel, *args):
    120         self.tooltipPanel = MaterialTooltipPanel(jobData=self.jobData, materialData=self.materialData, tooltipPanel=tooltipPanel)
    121 
    122     def GetMenu(self):
    123         menu = GetMenuService().GetMenuFromItemIDTypeID(None, self.materialData.typeID, includeMarketDetails=True)
    124         menu.insert(0, (MenuLabel('UI/Inventory/ItemActions/BuyThisType'), GetMenuService().QuickBuy, (self.materialData.typeID, self.materialData.missing)))
    125         return menu
    126 
    127     def OnClick(self, *args):
    128         PlaySound(uiconst.SOUND_BUTTON_CLICK)
    129         bpData = sm.GetService('blueprintSvc').GetBlueprintByProduct(self.materialData.typeID)
    130         if bpData:
    131             from eve.client.script.ui.shared.industry.industryWnd import Industry
    132             Industry.OpenOrShowBlueprint(blueprintTypeID=bpData.blueprintTypeID)
    133         else:
    134             sm.GetService('info').ShowInfo(self.materialData.typeID)
    135 
    136 
    137 class OptionalMaterial(MaterialBase):
    138 
    139     def ApplyAttributes(self, attributes):
    140         MaterialBase.ApplyAttributes(self, attributes)
    141         self.gauge.Hide()
    142 
    143     def ConstructBackground(self):
    144         self.patternNotReady = Sprite(name='patternNotReady', parent=self, align=uiconst.CENTERTOP, pos=(0, 0, 45, 45), state=uiconst.UI_DISABLED, texturePath='res:/UI/Texture/Classes/Industry/Input/bgNotReadyOptional.png', textureSecondaryPath='res:/UI/Texture/Classes/Industry/Input/bgNotReadyOptionalGradient.png', spriteEffect=trinity.TR2_SFX_MODULATE, color=COLOR_FRAME, opacity=0.0)
    145         uicore.animations.MorphScalar(self.patternNotReady, 'rotationSecondary', 2 * pi, 0.0, duration=3.0, curveType=uiconst.ANIM_LINEAR, loops=uiconst.ANIM_REPEAT)
    146         self.bgOptional = Sprite(name='bgOptional', parent=self, align=uiconst.TOALL, state=uiconst.UI_DISABLED, texturePath='res:/UI/Texture/Classes/Industry/Input/bgOptional.png', opacity=0.3)
    147 
    148     def UpdateState(self):
    149         duration = 0.3
    150         self.UpdateLabel()
    151         opacity = 1.0 if self.materialData.valid else 0.5
    152         uicore.animations.FadeTo(self.bgFrame, self.bgFrame.opacity, opacity, duration=duration)
    153         opacity = 0.4 if self.materialData.valid else 0.25
    154         uicore.animations.FadeTo(self.bgOptional, self.bgOptional.opacity, opacity, duration=duration)
    155         uicore.animations.FadeTo(self.icon, 0.0, 1.0, duration=1.0)
    156         color = COLOR_READY if self.materialData.valid else (0.2, 0.2, 0.2, 1.0)
    157         uicore.animations.SpColorMorphTo(self.bgGlow, endColor=color[:3], duration=duration)
    158         if self.materialData.typeID:
    159             self.icon.SetTypeID(self.materialData.typeID)
    160             self.icon.Show()
    161         else:
    162             self.icon.Hide()
    163         opacity = 0.0 if self.materialData.typeID else 2.5
    164         uicore.animations.FadeIn(self.patternNotReady, opacity, duration=duration)
    165 
    166     def LoadTooltipPanel(self, tooltipPanel, *args):
    167         tooltipPanel.margin = 4
    168         tooltipPanel.state = uiconst.UI_NORMAL
    169         tooltipPanel.width = 250
    170         OptionalItemTooltipPanel(materialData=self.materialData, callback=self.OnOptionalItemSelected, tooltipPanel=tooltipPanel)
    171 
    172     def OnClick(self, *args):
    173         PlaySound(uiconst.SOUND_BUTTON_CLICK)
    174 
    175     def OnOptionalItemSelected(self, typeID):
    176         self.materialData.select(typeID)
    177 
    178 
    179 class OptionalItemTooltipPanel:
    180 
    181     def __init__(self, materialData, callback, tooltipPanel):
    182         tooltipPanel.margin = 8
    183         self.materialData = materialData
    184         self.callback = callback
    185         self.tooltipPanel = tooltipPanel
    186         if materialData.IsSelectable():
    187             text = localization.GetByLabel('UI/Industry/SelectInputMaterial')
    188         else:
    189             text = localization.GetByLabel('UI/Industry/SelectOptionalMaterial')
    190         label = EveLabelMedium(align=uiconst.TOTOP, text=text, padBottom=3)
    191         tooltipPanel.AddCell(label)
    192         scroll = Scroll(align=uiconst.TOPLEFT, width=250)
    193         scroll.OnSelectionChange = self.OnScrollSelectionChange
    194         scrollList = self.GetScrollContent()
    195         scroll.Load(contentList=scrollList)
    196         scroll.ScrollToSelectedNode()
    197         scroll.height = min(len(scrollList) * 29 + 2, 200)
    198         scroll.Confirm = self.Confirm
    199         tooltipPanel.AddCell(scroll)
    200 
    201     def GetScrollContent(self):
    202         entries = []
    203         for material in self.materialData.options:
    204             if material.typeID is None:
    205                 entries.append(GetFromClass(Generic, {'label': localization.GetByLabel('UI/Industry/UseNoOptionalItem'),
    206                  'OnDblClick': self.OnNodeDblClick,
    207                  'typeID': None,
    208                  'height': 29}))
    209             else:
    210                 entry = GetFromClass(OptionalMaterialEntry, {'typeID': material.typeID,
    211                  'label': evetypes.GetName(material.typeID),
    212                  'getIcon': True,
    213                  'hint': evetypes.GetDescription(material.typeID),
    214                  'isSelected': material.typeID == self.materialData.typeID,
    215                  'OnDblClick': self.OnNodeDblClick,
    216                  'isItemOwned': not material.missing})
    217                 entries.append(entry)
    218 
    219         entries = sorted(entries, key=lambda x: (x.typeID is not None, x.label))
    220         return entries
    221 
    222     def Confirm(self, *args):
    223         self.tooltipPanel.Close()
    224 
    225     def OnNodeDblClick(self, node):
    226         self.tooltipPanel.Close()
    227 
    228     def OnScrollSelectionChange(self, nodes):
    229         if not nodes:
    230             return
    231         self.callback(nodes[0].typeID)
    232 
    233 
    234 class OptionalMaterialEntry(Item):
    235 
    236     def Load(self, node):
    237         Item.Load(self, node)
    238         if not node.isItemOwned:
    239             self.sr.icon.opacity = self.sr.label.opacity = 0.25