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

moonminingExtraHudBtns.py (11541B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\moonmining\moonminingExtraHudBtns.py
      2 import evetypes
      3 import gametime
      4 import itertoolsext
      5 import structures
      6 import uthread
      7 from carbon.common.script.util.timerstuff import AutoTimer
      8 from carbonui import uiconst
      9 from carbonui.primitives.container import Container
     10 from eve.common.lib.appConst import SEC, ixFlag
     11 from dogma.const import attributeIsOnline
     12 from eve.client.script.ui.control.eveIcon import Icon
     13 from eve.client.script.ui.inflight.shipHud.leftSideButton import LeftSideButton
     14 from eve.client.script.ui.inflight.shipModuleButton.extraBtnShipSlot import ExtraBtnShipSlot
     15 from eve.client.script.ui.moonmining import GetColorAndStatusTextForExtraction, GetExtractionStage, GetTextColor, STAGE_FRACTURING, STAGE_IN_PROGRESS, STAGE_READY, STAGE_STOPPED
     16 from eve.client.script.ui.util.uix import GetTechLevelIcon
     17 from eveservices.scheduling import GetSchedulingService
     18 from inventorycommon.const import serviceSlotFlags, typeStandupMoonDrill
     19 from localization import GetByLabel
     20 from localization.formatters import FormatTimeIntervalShortWritten
     21 from moonmining.const import FRACTURE_TOTAL_DURATION
     22 from carbonui.uicore import uicore
     23 import mathext
     24 GLOW_COLOR_IN_PROGRESS = (1.0, 0.13, 0.0, 0.73)
     25 GLOW_COLOR_FRACTURE = (0.24, 0.67, 0.16, 0.75)
     26 
     27 class MoonminingExtraHudBtns(Container):
     28     default_name = 'moonminingExtraHudBtns'
     29     __notifyevents__ = ['OnDogmaAttributeChanged', 'OnItemChange']
     30 
     31     def ApplyAttributes(self, attributes):
     32         Container.ApplyAttributes(self, attributes)
     33         self.extraBtns = []
     34         sm.RegisterNotify(self)
     35 
     36     def UpdateButtonsForHull(self):
     37         self.RemoveBtns()
     38         structureID = session.structureid
     39         if structureID:
     40             self.AddBtns(structureID)
     41 
     42     def AddBtns(self, structureID):
     43         self.fireLaserBtn = MoonDrillCont(structureID=structureID, parent=self, align=uiconst.CENTERRIGHT, left=-4, moonDrillTypeID=typeStandupMoonDrill)
     44         self.fireLaserBtn.Disable()
     45         self.fireLaserBtn.display = False
     46         self.accessSchedule = SchedulerHudBtn(structureID=structureID, parent=self, align=uiconst.CENTERLEFT, top=44, left=4)
     47         self.accessSchedule.Disable()
     48         self.accessSchedule.display = False
     49         self.extraBtns.append(self.fireLaserBtn)
     50         self.extraBtns.append(self.accessSchedule)
     51         uthread.new(self.UpdateBtns, structureID)
     52 
     53     def UpdateBtns(self, structureID):
     54         self.fireLaserBtn.display = False
     55         self.accessSchedule.display = False
     56         if self.AreBtnsAvailable(structureID):
     57             self.fireLaserBtn.Enable()
     58             self.fireLaserBtn.display = True
     59             self.accessSchedule.Enable()
     60             self.accessSchedule.display = True
     61         _, extraction = GetSchedulingService().GetExtractionAndEventIDFromStructureID()
     62         self.fireLaserBtn.SetExtraction(extraction)
     63 
     64     def RemoveBtns(self):
     65         for eachBtn in self.extraBtns:
     66             eachBtn.Close()
     67 
     68         self.extraBtns = []
     69 
     70     def AreBtnsAvailable(self, structureID):
     71         if session.structureid != structureID:
     72             return False
     73         if not sm.GetService('structureSettings').CharacterHasSetting(structureID, structures.SETTING_DEFENSE_CAN_CONTROL_STRUCTURE):
     74             return False
     75         clientDogmaLM = sm.GetService('clientDogmaIM').GetDogmaLocation()
     76         itemsFittedToShip = clientDogmaLM.GetFittedItemsToShip()
     77         moonDrill = itertoolsext.first_or_default(itemsFittedToShip.values(), predicate=lambda x: x.typeID == typeStandupMoonDrill, default=None)
     78         if not moonDrill:
     79             return False
     80         return bool(moonDrill.IsOnline())
     81 
     82     def OnDogmaAttributeChanged(self, shipID, itemID, attributeID, value):
     83         if attributeID != attributeIsOnline or session.structureid is None:
     84             return
     85         dogmaLocation = sm.GetService('clientDogmaIM').GetDogmaLocation()
     86         item = dogmaLocation.SafeGetDogmaItem(itemID)
     87         if item and item.typeID == typeStandupMoonDrill:
     88             self.UpdateButtonsForHull()
     89 
     90     def OnItemChange(self, item, change, location):
     91         if item.typeID != typeStandupMoonDrill:
     92             return
     93         if ixFlag in change and change[ixFlag] in serviceSlotFlags:
     94             self.UpdateButtonsForHull()
     95 
     96 
     97 class MoonDrillCont(Container):
     98     __notifyevents__ = ['OnMoonExtractionUpdate', 'OnMiningLaserFiredLocal', 'OnMiningLaserFiredFailedLocal']
     99     default_width = 64
    100     default_height = 64
    101     default_align = uiconst.TOPLEFT
    102 
    103     def ApplyAttributes(self, attributes):
    104         self.rampThread = None
    105         self.tooltipThread = None
    106         Container.ApplyAttributes(self, attributes)
    107         self.currentExtraction = attributes.extraction
    108         self.structureID = attributes.structureID
    109         self.moonDrillTypeID = attributes.moonDrillTypeID or 45009
    110         self.moonDrillBtn = ExtraBtnShipSlot(name='moonDrillBtn', parent=self, func=self.OnBtnClickedFunction)
    111         self.moonDrillBtn.LoadTooltipPanel = self.LoadTooltipPanel
    112         self.SetStage()
    113         sm.RegisterNotify(self)
    114 
    115     def SetStage(self):
    116         stageID = GetExtractionStage(self.currentExtraction)
    117         texturePath = None
    118         self.rampThread = None
    119         self.moonDrillBtn.SetRampValue(0.0)
    120         self.moonDrillBtn.DisableBtn()
    121         glowColor = None
    122         if stageID == STAGE_STOPPED:
    123             texturePath = 'res:/UI/Texture/classes/Moonmining/iconStopped.png'
    124             self.moonDrillBtn.EnableBtn()
    125         elif stageID == STAGE_IN_PROGRESS:
    126             glowColor = GLOW_COLOR_IN_PROGRESS
    127             texturePath = 'res:/UI/Texture/classes/Moonmining/iconTransit.png'
    128             self.StartUpdateThreadForInProgress()
    129         elif stageID == STAGE_FRACTURING:
    130             glowColor = GLOW_COLOR_FRACTURE
    131             texturePath = 'res:/UI/Texture/classes/Moonmining/iconFracture.png'
    132             self.StartUpdateThreadForLaserFired()
    133         elif stageID == STAGE_READY:
    134             self.moonDrillBtn.EnableBtn()
    135             texturePath = 'res:/UI/Texture/classes/Moonmining/iconReady.png'
    136         self.moonDrillBtn.SetButtonIcon(texturePath)
    137         if glowColor:
    138             self.moonDrillBtn.BlinkGlow(glowColor)
    139         else:
    140             self.moonDrillBtn.StopBlinkGlow()
    141 
    142     def OnBtnClickedFunction(self):
    143         stageID = GetExtractionStage(self.currentExtraction)
    144         schedulingSvc = GetSchedulingService()
    145         if stageID == STAGE_READY:
    146             schedulingSvc.FireLaser()
    147         elif stageID == STAGE_STOPPED:
    148             schedulingSvc.OpenSchedulingWndForStructure(self.structureID)
    149 
    150     def StartUpdateThreadForLaserFired(self):
    151         laserFiredTimestamp = GetSchedulingService().GetLaserFiredTimestamp()
    152         endTime = laserFiredTimestamp + FRACTURE_TOTAL_DURATION * SEC
    153         self.UpdateRampThread(laserFiredTimestamp, endTime)
    154         self.rampThread = AutoTimer(50, self.UpdateRampThread, laserFiredTimestamp, endTime)
    155 
    156     def StartUpdateThreadForInProgress(self):
    157         self.UpdateRampThread(self.currentExtraction.startMoveTime, self.currentExtraction.chunkAvailableTime)
    158         self.rampThread = AutoTimer(60000, self.UpdateRampThread, self.currentExtraction.startMoveTime, self.currentExtraction.chunkAvailableTime)
    159 
    160     def GetPercentageDone(self, startTime, endTime):
    161         totalTime = endTime - startTime
    162         diff = max(0, endTime - gametime.GetWallclockTime())
    163         percentage = 1.0 - mathext.clamp(diff / float(totalTime), 0, 1.0)
    164         return percentage
    165 
    166     def OnMoonExtractionUpdate(self, extraction):
    167         self.SetExtraction(extraction)
    168 
    169     def OnMiningLaserFiredFailedLocal(self):
    170         self.SetStage()
    171 
    172     def OnMiningLaserFiredLocal(self):
    173         self.SetStage()
    174 
    175     def SetExtraction(self, extraction):
    176         self.currentExtraction = extraction
    177         self.SetStage()
    178 
    179     def UpdateRampThread(self, startTime, endTime):
    180         if self.destroyed:
    181             self.rampThread = False
    182         percentage = self.GetPercentageDone(startTime, endTime)
    183         self.moonDrillBtn.SetRampValue(percentage)
    184 
    185     def LoadTooltipPanel(self, tooltipPanel, *args):
    186         tooltipPanel.columns = 2
    187         tooltipPanel.margin = (4, 4, 4, 4)
    188         tooltipPanel.cellPadding = 0
    189         tooltipPanel.cellSpacing = 0
    190         self._LoadTooltipPanel_thread(tooltipPanel)
    191         self.tooltipThread = AutoTimer(500, self._LoadTooltipPanel_thread, tooltipPanel)
    192 
    193     def _LoadTooltipPanel_thread(self, tooltipPanel):
    194         currentMouseOver = uicore.uilib.mouseOver
    195         if self.destroyed or currentMouseOver != self and not currentMouseOver.IsUnder(self):
    196             self.tooltipThread = None
    197             return
    198         tooltipPanel.Flush()
    199         iconCont = self.GetIconCont()
    200         tooltipPanel.AddCell(iconCont, cellPadding=2)
    201         typeName = evetypes.GetName(self.moonDrillTypeID)
    202         tooltipPanel.AddLabelMedium(text=typeName, align=uiconst.CENTERLEFT, cellPadding=(4, 2, 4, 2), bold=True)
    203         text, _, color = GetColorAndStatusTextForExtraction(self.currentExtraction)
    204         textColor = GetTextColor(color)
    205         tooltipPanel.AddSpacer(height=0, width=0)
    206         labelObj = tooltipPanel.AddLabelMedium(text=text.upper(), align=uiconst.CENTERLEFT, cellPadding=(4, 2, 4, 2))
    207         labelObj.SetRGBA(*textColor)
    208         currentStage = GetExtractionStage(self.currentExtraction)
    209         if currentStage == STAGE_IN_PROGRESS:
    210             totalTime = self.currentExtraction.chunkAvailableTime - self.currentExtraction.startMoveTime
    211             diff = max(0, self.currentExtraction.chunkAvailableTime - gametime.GetWallclockTime())
    212             if diff > 0:
    213                 tooltipPanel.AddSpacer(height=0, width=0)
    214                 remainingText = GetByLabel('UI/Moonmining/RemainingTime', countdownText=FormatTimeIntervalShortWritten(diff, showFrom='day', showTo='minute'))
    215                 labelObj = tooltipPanel.AddLabelMedium(text=remainingText, align=uiconst.CENTERLEFT, cellPadding=(4, 2, 4, 2))
    216                 labelObj.SetRGBA(*textColor)
    217 
    218     def GetIconCont(self):
    219         iconSize = 26
    220         iconCont = Container(pos=(0,
    221          0,
    222          iconSize,
    223          iconSize), align=uiconst.CENTER)
    224         iconObj = Icon(parent=iconCont, pos=(0,
    225          0,
    226          iconSize,
    227          iconSize), align=uiconst.TOPLEFT, ignoreSize=True)
    228         iconObj.LoadIconByTypeID(self.moonDrillTypeID, size=iconSize, ignoreSize=True)
    229         techIcon = Icon(parent=iconCont, width=16, height=16, align=uiconst.TOPLEFT, idx=0, top=0)
    230         GetTechLevelIcon(techIcon, typeID=self.moonDrillTypeID)
    231         return iconCont
    232 
    233     def Close(self):
    234         self.rampThread = None
    235         self.tooltipThread = None
    236         Container.Close(self)
    237 
    238 
    239 class SchedulerHudBtn(LeftSideButton):
    240     default_name = 'shedulerHudBtn'
    241     default_texturePath = 'res:/UI/Texture/classes/Moonmining/iconSchedulerSmall.png'
    242     cmdName = 'OpenCargoHoldOfActiveShip'
    243     cmdDescription_override = 'Tooltips/Hud/CargoHoldStructure_description'
    244 
    245     def ApplyAttributes(self, attributes):
    246         LeftSideButton.ApplyAttributes(self, attributes)
    247         self.structureID = attributes.structureID
    248 
    249     def OnClick(self, *args):
    250         LeftSideButton.OnClick(self)
    251         GetSchedulingService().OpenSchedulingWndForStructure(self.structureID)
    252 
    253     def LoadTooltipPanel(self, tooltipPanel, *args):
    254         tooltipPanel.LoadGeneric1ColumnTemplate()
    255         tooltipPanel.AddLabelMedium(text=GetByLabel('UI/Moonmining/MoonMiningSchedulingHeader'))