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

scheduling.py (14601B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\moonmining\scheduling.py
      2 import carbonui.const as uiconst
      3 import inventorycommon.const as invConst
      4 import uthread
      5 from carbon.common.script.sys.serviceConst import ROLE_GML, ROLE_WORLDMOD
      6 from carbon.common.script.util.linkUtil import GetShowInfoLink
      7 from carbon.common.script.util.timerstuff import AutoTimer
      8 from carbonui.primitives.container import Container
      9 from carbonui.primitives.containerAutoSize import ContainerAutoSize
     10 from carbonui.primitives.layoutGrid import LayoutGrid
     11 from carbonui.control.button import Button
     12 from carbonui.control.checkbox import Checkbox
     13 from eve.client.script.ui.control.eveIcon import Icon
     14 from eve.client.script.ui.control.eveLabel import Label, EveLabelMedium
     15 from carbonui.control.window import Window
     16 from eve.client.script.ui.control.infoIcon import MoreInfoIcon
     17 from eve.client.script.ui.moonmining import COLOR_IN_PROGRESS, COLOR_READY, COLOR_STOPPED, GetExtractionStage, STAGE_IN_PROGRESS, STAGE_READY, GetTextColor, GetColorAndStatusTextForExtraction, STAGE_STOPPED
     18 from eve.client.script.ui.moonmining.inProgressCont import InProgressCont
     19 from eve.client.script.ui.moonmining.planningCont import PlanningCont
     20 from eve.client.script.ui.moonmining.schedulingController import SchedulingController
     21 from eve.common.lib.appConst import corpRoleStationManager
     22 from eveservices.scheduling import GetSchedulingService
     23 from localization import GetByLabel
     24 import blue
     25 from player_messaging.client.ui_message import prompt_player_fsd_dialog
     26 from utillib import KeyVal
     27 import locks
     28 
     29 class SchedulingWindow(Window):
     30     __guid__ = 'SchedulingWindow'
     31     __notifyevents__ = ['OnSessionChanged',
     32      'OnMoonExtractionUpdate',
     33      'OnItemChange',
     34      'OnMiningLaserFiredLocal',
     35      'OnMiningLaserFiredFailedLocal']
     36     default_width = 600
     37     default_height = 525
     38     default_windowID = 'mooonminingScheduling'
     39     default_captionLabelPath = 'UI/Moonmining/MoonMiningSchedulingHeader'
     40     default_descriptionLabelPath = 'Tooltips/Neocom/MoonMiningScheduling_description'
     41     default_iconNum = 'res:/ui/Texture/WindowIcons/moonDrillScheduler.png'
     42     default_minSize = [default_width, default_height]
     43 
     44     def ApplyAttributes(self, attributes):
     45         self.uiUpdateThread = None
     46         self.gmBtnCont = None
     47         self.currentBtnStage = None
     48         self.mainAreaContent = None
     49         self.calendarEventPending = False
     50         Window.ApplyAttributes(self, attributes)
     51         self.schedulingSvc = sm.GetService('scheduling')
     52         self.countdownThread = None
     53         self.outputContsByTypeID = {}
     54         self.schedulingController = SchedulingController(self.schedulingSvc.GetFuelExpiryTime())
     55         self.structureID = attributes.structureID
     56         self.moonID = attributes.moonID
     57         self.extraction = attributes.extraction
     58         self.structureOwnerID = attributes.structureOwnerID
     59         self.eventID = attributes.eventID
     60         padding = 10
     61         self.topCont = Container(name='topCont', parent=self.sr.main, height=128, align=uiconst.TOTOP, padding=(padding,
     62          8,
     63          padding,
     64          0))
     65         self.bottomCont = Container(name='bottomCont', parent=self.sr.main, align=uiconst.TOBOTTOM, height=48)
     66         self.mainAreaCont = Container(name='mainAreaCont', parent=self.sr.main, align=uiconst.TOALL, padLeft=padding, padRight=padding, padBottom=2)
     67         self.BuildTop()
     68         self.BuildBottom()
     69         self.RefreshUI(resourceComposition={})
     70         uthread.new(self.RefreshUI)
     71         if session.role & (ROLE_GML | ROLE_WORLDMOD):
     72             self.AddGMButtons()
     73         sm.RegisterNotify(self)
     74 
     75     def RefreshUI(self, resourceComposition = None):
     76         with locks.TempLock('RefreshUI'):
     77             if self.destroyed:
     78                 return
     79             if resourceComposition is None:
     80                 resourceComposition = self.schedulingSvc.GetMoonResourcesForStructure()
     81             c = self.MakeMainArea(resourceComposition)
     82             self.LoadTop()
     83             self.UpdateButtons()
     84             if self.uiUpdateThread:
     85                 self.uiUpdateThread.KillTimer()
     86             self.UpdateUIForStatus_thread()
     87             self.uiUpdateThread = AutoTimer(3000, self.UpdateUIForStatus_thread)
     88             if not self.stacked:
     89                 self.height = 330 + c.outputPanel.GetOutputHeight()
     90             self.ShowOrHideGMButtons()
     91 
     92     def ShowOrHideGMButtons(self):
     93         if not self.gmBtnCont:
     94             return
     95         if self.extraction:
     96             self.gmBtnCont.display = True
     97         else:
     98             self.gmBtnCont.display = False
     99 
    100     def OnMoonExtractionUpdate(self, extraction):
    101         if extraction is None:
    102             self.eventID = None
    103         elif self.eventID is None:
    104             self.calendarEventPending = True
    105             uthread.new(self._DelayedCalendarUpdate)
    106         self.extraction = extraction
    107         self.UpdateUiOnEvent()
    108 
    109     def _DelayedCalendarUpdate(self):
    110         try:
    111             blue.synchro.Sleep(1000)
    112             self.eventID, _ = self.schedulingSvc.GetExtractionAndEventIDFromStructureID()
    113             self.calendarEventPending = False
    114             self.UpdateButtons()
    115         finally:
    116             self.calendarEventPending = False
    117 
    118     def UpdateUiOnEvent(self):
    119         self.RefreshUI()
    120         self.UpdateButtons()
    121         if self.mainAreaContent:
    122             self.mainAreaContent.UpdateUI()
    123 
    124     def OnMiningLaserFiredLocal(self):
    125         self.UpdateUiOnEvent()
    126 
    127     def OnMiningLaserFiredFailedLocal(self):
    128         self.UpdateUiOnEvent()
    129 
    130     def MakeMainArea(self, resourceComposition):
    131         self.mainAreaCont.Flush()
    132         if self.extraction:
    133             c = InProgressCont(parent=self.mainAreaCont, extraction=self.extraction, moonMaterialInfo=resourceComposition)
    134         else:
    135             c = PlanningCont(parent=self.mainAreaCont, schedulingController=self.schedulingController, structureID=self.structureID, moonMaterialInfo=resourceComposition)
    136         self.mainAreaContent = c
    137         return c
    138 
    139     def BuildBottom(self):
    140         self.btnGrid = ContainerAutoSize(parent=self.bottomCont, state=uiconst.UI_PICKCHILDREN, align=uiconst.BOTTOMRIGHT, left=6, top=10, alignMode=uiconst.TORIGHT, height=32)
    141         self.stopDrillBtn = Button(parent=self.btnGrid, align=uiconst.TORIGHT, left=6, label=GetByLabel('UI/Moonmining/StopDrill'), func=self.StopDrill, color=COLOR_IN_PROGRESS[:3] + (0.5,), texturePath='res:/UI/Texture/classes/Moonmining/warning.png', iconSize=20)
    142         self.startBtn = Button(parent=self.btnGrid, align=uiconst.TORIGHT, left=6, label=GetByLabel('UI/Moonmining/StartExtraction'), func=self.StartExtraction, color=COLOR_STOPPED[:3] + (0.5,))
    143         self.fireBtn = Button(parent=self.btnGrid, align=uiconst.TORIGHT, left=6, label=GetByLabel('UI/Moonmining/FireLaser'), func=self.FireLaser, color=COLOR_READY[:3] + (0.5,))
    144         self.stopDrillBtn.width = self.fireBtn.width = max(self.stopDrillBtn.width, self.startBtn.width, self.fireBtn.width)
    145         self.btnGrid.height = max(self.stopDrillBtn.height, self.startBtn.height, self.fireBtn.height)
    146         self.stopDrillBtn.display = self.fireBtn.display = False
    147         self.addToCalendarCb = Checkbox(name='calendarCB', parent=self.bottomCont, align=uiconst.CENTERLEFT, text=GetByLabel('UI/Moonmining/AddToCalendar'), checked=True, width=200, left=10)
    148         self.addToCalendarCb.display = False
    149         self.calendarEventStatusLabel = EveLabelMedium(name='calendarLabel', parent=self.bottomCont, align=uiconst.CENTERLEFT, left=10)
    150 
    151     def FireLaser(self, *args):
    152         prompt_player_fsd_dialog('CustomNotify', {'notify': GetByLabel('Notifications/NotificationNames/MoonminingLaserFired')})
    153         self.schedulingSvc.FireLaser()
    154 
    155     def StopDrill(self, *args):
    156         self.schedulingSvc.CancelExtraction()
    157 
    158     def StartExtraction(self, *args):
    159         endtime = self.schedulingController.GetCurrentTime()
    160         addToCalendar = self.addToCalendarCb.GetValue()
    161         started = GetSchedulingService().StartMoonminingEvent(self.structureID, self.structureOwnerID, endtime, addToCalendar)
    162         if started:
    163             self.startBtn.Disable()
    164 
    165     def BuildTop(self):
    166         self.moonIcon = Icon(parent=self.topCont, align=uiconst.TOPLEFT, pos=(0, 0, 128, 128))
    167         self.moonIcon.GetDragData = self.GetMoonDragData
    168         self.moonIcon.MakeDragObject()
    169         textCont = Container(name='textCont', parent=self.topCont, align=uiconst.TOALL, padLeft=140, height=64)
    170         self.structureNameLabel = Label(name='structureNameLabel', parent=textCont, align=uiconst.TOTOP, text='', state=uiconst.UI_NORMAL, fontsize=16)
    171         self.moonNameLabel = EveLabelMedium(name='moonNameLabel', parent=textCont, align=uiconst.TOTOP, text='', state=uiconst.UI_NORMAL)
    172         layoutGrid = LayoutGrid(name='layoutGrid', parent=textCont, columns=3, align=uiconst.TOTOP, top=12)
    173         self.drillStatusHederText = EveLabelMedium(name='headerStatusText', parent=layoutGrid, align=uiconst.CENTERLEFT, text=GetByLabel('UI/Moonmining/DrillStatus'))
    174         self.drillStatusText = EveLabelMedium(name='headerStatusText', parent=layoutGrid, align=uiconst.CENTERLEFT, text='', padLeft=4)
    175         self.helpIcon = MoreInfoIcon(parent=layoutGrid, align=uiconst.CENTERRIGHT, hint='', padLeft=4)
    176         self.LoadTop()
    177 
    178     def GetMoonDragData(self):
    179         fakeNode = KeyVal()
    180         fakeNode.__guid__ = 'xtriui.ListSurroundingsBtn'
    181         fakeNode.itemID = self.moonID
    182         fakeNode.typeID = invConst.typeMoon
    183         fakeNode.label = cfg.evelocations.Get(self.moonID).name
    184         return [fakeNode]
    185 
    186     def LoadTop(self):
    187         structureInfo = sm.GetService('structureDirectory').GetStructureInfo(self.structureID)
    188         self.structureNameLabel.text = GetShowInfoLink(structureInfo.typeID, structureInfo.itemName, structureInfo.structureID)
    189         moonInfo = cfg.evelocations.Get(self.moonID)
    190         self.moonNameLabel.text = GetShowInfoLink(invConst.typeMoon, moonInfo.name, moonInfo.locationID)
    191         self.moonIcon.LoadIconByTypeID(const.typeMoon, self.moonID, size=128)
    192         headerText, headerHelp, headerColor = GetColorAndStatusTextForExtraction(self.extraction)
    193         self.drillStatusText.text = headerText.upper()
    194         textColor = GetTextColor(headerColor)
    195         self.drillStatusText.SetRGBA(*textColor)
    196         self.helpIcon.hint = headerHelp
    197 
    198     def OnSessionChanged(self, isRemote, sess, change):
    199         if not session.structureid or session.shipid != session.structureid:
    200             self.Close()
    201 
    202     def UpdateButtons(self):
    203         self.SetElementDisplayAndState([self.fireBtn,
    204          self.stopDrillBtn,
    205          self.startBtn,
    206          self.addToCalendarCb,
    207          self.calendarEventStatusLabel], False)
    208         elementsToShow = []
    209         self.currentBtnStage = GetExtractionStage(self.extraction)
    210         if self.currentBtnStage == STAGE_READY:
    211             elementsToShow.append(self.fireBtn)
    212         elif self.currentBtnStage == STAGE_STOPPED:
    213             elementsToShow.append(self.startBtn)
    214             elementsToShow.append(self.addToCalendarCb)
    215         self.SetElementDisplayAndState(elementsToShow, True)
    216         if self.currentBtnStage == STAGE_IN_PROGRESS:
    217             self.stopDrillBtn.display = True
    218             if not session.corprole & corpRoleStationManager or self.structureOwnerID != session.corpid:
    219                 self.stopDrillBtn.Disable()
    220                 self.stopDrillBtn.hint = GetByLabel('UI/Moonmining/StopDrillBtnHint')
    221             else:
    222                 self.stopDrillBtn.Enable()
    223                 self.stopDrillBtn.hint = ''
    224             if self.calendarEventPending:
    225                 calendarText = ''
    226             elif self.eventID > 0:
    227                 calendarText = GetByLabel('UI/Moonmining/CalendarEventSet')
    228             else:
    229                 calendarText = GetByLabel('UI/Moonmining/CalendarEventNotSet')
    230             self.calendarEventStatusLabel.text = calendarText
    231             self.calendarEventStatusLabel.display = True
    232 
    233     def SetElementDisplayAndState(self, btnList, doShow):
    234         for each in btnList:
    235             each.display = doShow
    236             if doShow:
    237                 each.Enable()
    238             else:
    239                 each.Disable()
    240 
    241     def UpdateUIForStatus_thread(self):
    242         if self.destroyed:
    243             self.uiUpdateThread = None
    244         currentStage = GetExtractionStage(self.extraction)
    245         if currentStage != self.currentBtnStage:
    246             self.UpdateButtons()
    247 
    248     def Close(self, *args, **kwds):
    249         self.countdownThread = None
    250         Window.Close(self, *args, **kwds)
    251 
    252     def AddGMButtons(self):
    253         if not getattr(self, 'gmBtnCont', None) or self.gmBtnCont.destroyed:
    254             self.gmBtnCont = Container(name='gmBtnCont', parent=self.bottomCont, align=uiconst.TOBOTTOM_NOPUSH, height=30, top=10)
    255         midwayBtn = Button(parent=self.gmBtnCont, label='GM:Set Chunk Midway', hint='Set extraction to mid-way between the start and stop movement positions', align=uiconst.BOTTOMLEFT, func=lambda x: sm.GetService('slash').SlashCmd('/extraction advance mid'), top=20, left=100)
    256         stopBtn = Button(parent=self.gmBtnCont, label='GM:Stop Chunk', hint="Set extraction to the stop movement position. Chunk WILL NOT be available for fracture until it reaches the 'ready' phase", align=uiconst.BOTTOMLEFT, func=lambda x: sm.GetService('slash').SlashCmd('/extraction advance stop'), left=midwayBtn.left)
    257         readyBtn = Button(parent=self.gmBtnCont, left=midwayBtn.left + midwayBtn.width + 20, label='GM:Set Chunk Ready', hint='Set extraction to the stop movement position. Chunk WILL be available for fracture immediately.', align=uiconst.BOTTOMLEFT, func=lambda x: sm.GetService('slash').SlashCmd('/extraction advance ready'), top=20)
    258         decayBtn = Button(parent=self.gmBtnCont, left=readyBtn.left, label='GM:Set to Decay point', hint='Set extraction to the point at which the chunk is about to naturally decay.', align=uiconst.BOTTOMLEFT, func=lambda x: sm.GetService('slash').SlashCmd('/extraction advance decay'))
    259 
    260     def OnItemChange(self, item, change, location):
    261         oldLocationID = change.get(const.ixLocationID, None)
    262         if session.structureid not in (oldLocationID, item.locationID):
    263             return
    264         oldFlag = change.get(const.ixFlag, None)
    265         if const.flagStructureFuel not in (oldFlag, item.flagID):
    266             return
    267         self.UpdateFuelExpiry()
    268 
    269     def UpdateFuelExpiry(self):
    270         fuelExpiryTime = self.schedulingSvc.GetFuelExpiryTime()
    271         self.schedulingController.SetFuelExpiryTime(fuelExpiryTime)