planningCont.py (9469B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\moonmining\planningCont.py 2 import eveLocalization 3 import gametime 4 import uthread 5 from carbonui.primitives.container import Container 6 import carbonui.const as uiconst 7 from dogma.const import attributeExtractionAutoFractureDelay 8 from carbonui.control.buttonIcon import ButtonIcon 9 from eve.client.script.ui.control.dateSinglelineEdit import DatePickerControl, HourMinPickerControl 10 from eve.client.script.ui.control.eveLabel import Label 11 from eve.client.script.ui.control.infoIcon import MoreInfoIcon 12 from eve.client.script.ui.moonmining import DAY_NAME_TEXT, PARTS_IN_HOUR, GetYieldMultiplier, DAY_NAME_TEXT_SHORT 13 import blue 14 from eve.client.script.ui.moonmining.outputCont import SchedulingOutputPanel 15 from eve.client.script.ui.moonmining.timePicker import TimePicker 16 from eve.client.script.ui.shared.fitting.fittingUtil import EatSignalChangingErrors 17 from localization import GetByLabel 18 from signals import Signal 19 from signals.signalUtil import ChangeSignalConnect 20 from carbonui.uicore import uicore 21 22 class PlanningCont(Container): 23 24 def ApplyAttributes(self, attributes): 25 Container.ApplyAttributes(self, attributes) 26 self.structureID = attributes.structureID 27 self.schedulingController = attributes.schedulingController 28 self.moonMaterialInfo = attributes.moonMaterialInfo 29 self.centerCont = Container(name='centerCont', parent=self, height=140, align=uiconst.TOTOP) 30 self.bottomCont = Container(name='bottomCont', parent=self, align=uiconst.TOALL) 31 self.BuildCenter() 32 self.BuildBottom() 33 self.UpdateTimebasedUI() 34 self.ChangeSignalConnection() 35 36 def ChangeSignalConnection(self, connect = True): 37 signalAndCallback = [(self.schedulingController.on_hours_changed, self.OnHoursUpdated), (self.upDownControl.on_value_changed, self.UpDownValueChanged)] 38 ChangeSignalConnect(signalAndCallback, connect) 39 40 def UpDownValueChanged(self, diff): 41 self.schedulingController.AddNumHours(diff / float(PARTS_IN_HOUR), PARTS_IN_HOUR) 42 43 def UpdateTimebasedUI(self, wasChange = True): 44 self.SetAvailableTimeLabel() 45 self.SetCountdownLabel() 46 if wasChange: 47 timestamp = self.schedulingController.GetCurrentTime() 48 now = gametime.GetWallclockTime() 49 numSec = float(timestamp - now) / const.SEC 50 self.outputPanel.SetEstimation(numSec, GetYieldMultiplier(self.structureID)) 51 52 def BuildBottom(self): 53 self.outputPanel = SchedulingOutputPanel(parent=self.bottomCont, moonMaterialInfo=self.moonMaterialInfo, top=8) 54 55 def BuildCenter(self): 56 self.timePickerCont = Container(name='timePickerCont', parent=self.centerCont, align=uiconst.TOTOP_NOPUSH, height=10, top=12) 57 fontSize = 16 58 self.weekdayLabel = Label(name='weekdayLabel', parent=self.timePickerCont, text='', align=uiconst.CENTERLEFT, fontsize=fontSize) 59 weekdayLabelWidth = max([ uicore.font.GetTextWidth(x, fontSize, uppercase=True) for x in DAY_NAME_TEXT_SHORT ]) 60 fromTime = self.schedulingController.GetSliderStartTime() 61 toTime = self.schedulingController.GetMaxValidTime() 62 left = weekdayLabelWidth + 2 63 self.fromPicker = DatePickerControl(name='fromPicker', parent=self.timePickerCont, OnEditFieldChanged=self.OnEditFieldChanged, setValue=[0, 0, 0], left=left, ranges=(fromTime, toTime), fontSize=fontSize, align=uiconst.CENTERLEFT) 64 left += self.fromPicker.width + 10 65 self.hourMinPicker = HourMinPickerControl(parent=self.timePickerCont, left=left, setValue=(0, 0), fontSize=fontSize, OnEditFieldChanged=self.OnEditFieldChanged, onEditFieldRolledOverFunc=self.OnEditFieldRolledOver) 66 left += self.hourMinPicker.width + 10 67 self.upDownControl = UpDownControl(parent=self.timePickerCont, iconSize=9, pos=(left, 68 0, 69 16, 70 16), align=uiconst.CENTERLEFT) 71 self.traversalHelpIcon = MoreInfoIcon(parent=self.timePickerCont, align=uiconst.CENTERRIGHT, padLeft=4) 72 self.traversalHelpIcon.LoadTooltipPanel = self.LoadTraversalInfoTooltipPanel 73 self.traversalLabelTime = Label(name='traversalLabel', parent=self.timePickerCont, align=uiconst.CENTERRIGHT, text='', state=uiconst.UI_NORMAL, fontsize=16, left=20) 74 self.timePickerCont.height = self.fromPicker.height 75 self.headerCont = Container(name='headerCont', parent=self.centerCont, align=uiconst.TOTOP, height=20, top=6) 76 self.centerInnerCont = Container(name='centerInnerCont', parent=self.centerCont, align=uiconst.TOTOP, top=0, height=100) 77 TimePicker(parent=self.centerInnerCont, align=uiconst.TOTOP, schedulingController=self.schedulingController) 78 79 def OnEditFieldChanged(self, *args): 80 hourMinTimestamp = self.hourMinPicker.GetTimestamp() 81 self.SetTimestampsFromEditFields(hourMinTimestamp) 82 83 def OnEditFieldRolledOver(self, hourMinTimestamp): 84 self.SetTimestampsFromEditFields(hourMinTimestamp) 85 86 def SetTimestampsFromEditFields(self, hourMinTimestamp): 87 timeStamp = self.fromPicker.GetTimestamp() + hourMinTimestamp 88 self.schedulingController.SetTimestamp(timeStamp, numParts=2) 89 90 def SetAvailableTimeLabel(self): 91 timestamp = self.schedulingController.GetCurrentTime() 92 self.hourMinPicker.SetPickerValueFromTimestamp(timestamp) 93 self.fromPicker.SetPickerValueFromTimestamp(timestamp) 94 _, _, wd, _, _, _, _, _ = blue.os.GetTimeParts(timestamp + eveLocalization.GetTimeDelta() * const.SEC) 95 self.weekdayLabel.text = DAY_NAME_TEXT_SHORT[wd].upper() 96 97 def SetCountdownLabel(self): 98 timestamp = self.schedulingController.GetCurrentTime() 99 now = gametime.GetWallclockTime() 100 diff = timestamp - now 101 d = diff / const.DAY 102 h = diff % const.DAY / const.HOUR 103 m = diff % const.HOUR / const.MIN 104 countdownText = GetByLabel('UI/Moonmining/CountdownShort', days=d, hours=h, minutes=m) 105 self.traversalLabelTime.text = GetByLabel('UI/Moonmining/TraversalPeriod', countdownText=countdownText) 106 107 def UpdateUI(self): 108 pass 109 110 def OnHoursUpdated(self, wasChange): 111 self.UpdateTimebasedUI(wasChange) 112 113 def LoadTraversalInfoTooltipPanel(self, tooltipPanel, *args): 114 tooltipPanel.LoadGeneric1ColumnTemplate() 115 dogmaLocation = sm.GetService('clientDogmaIM').GetDogmaLocation() 116 fractureDelayInSec = dogmaLocation.GetAttributeValue(self.structureID, attributeExtractionAutoFractureDelay) 117 fractureDelay = long(fractureDelayInSec * const.SEC) 118 text = GetByLabel('UI/Moonmining/AutomaticFractureTooltip', fractureDelay=fractureDelay) 119 tooltipPanel.AddLabelMedium(text=text, wrapWidth=200) 120 121 def Close(self): 122 with EatSignalChangingErrors(errorMsg='Moonmining planning'): 123 self.ChangeSignalConnection(connect=False) 124 Container.Close(self) 125 126 127 class UpDownControl(Container): 128 default_align = uiconst.TORIGHT 129 default_width = 20 130 default_padLeft = 0 131 default_padRight = 4 132 default_padTop = 1 133 default_padBottom = 1 134 default_opacity = 0.75 135 default_iconSize = 7 136 137 def ApplyAttributes(self, attributes): 138 Container.ApplyAttributes(self, attributes) 139 iconSize = attributes.get('iconSize', self.default_iconSize) 140 buttonSize = iconSize + 2 141 centerOffset = iconSize / 2 + 1 142 self.on_value_changed = Signal(signalName='on_value_changed') 143 self.upButton = ButtonIcon(name='upButton', parent=self, align=uiconst.CENTER, pos=(0, 144 -centerOffset, 145 buttonSize, 146 buttonSize), iconSize=iconSize, texturePath='res:/UI/Texture/Shared/up.png', soundClick=uiconst.SOUND_VALUECHANGE_TICK) 147 self.upButton.OnMouseDown = self.OnNumericUpButtonMouseDown 148 self.upButton.OnMouseUp = self.OnNumericUpButtonMouseUp 149 self.downButton = ButtonIcon(name='downButton', parent=self, align=uiconst.CENTER, pos=(0, 150 centerOffset, 151 buttonSize, 152 buttonSize), iconSize=iconSize, texturePath='res:/UI/Texture/Shared/down.png', soundClick=uiconst.SOUND_VALUECHANGE_TICK) 153 self.downButton.OnMouseDown = self.OnNumericDownButtonMouseDown 154 self.downButton.OnMouseUp = self.OnNumericDownButtonMouseUp 155 156 def OnNumericUpButtonMouseDown(self, *args): 157 ButtonIcon.OnMouseDown(self.upButton, *args) 158 self.updateNumericInputThread = uthread.new(self.UpdateNumericInputThread, 1) 159 160 def OnNumericDownButtonMouseDown(self, *args): 161 ButtonIcon.OnMouseDown(self.downButton, *args) 162 self.updateNumericInputThread = uthread.new(self.UpdateNumericInputThread, -1) 163 164 def UpdateNumericInputThread(self, diff): 165 sleepTime = 500 166 while uicore.uilib.leftbtn: 167 self.on_value_changed(diff) 168 blue.synchro.SleepWallclock(sleepTime) 169 sleepTime -= 0.5 * sleepTime 170 sleepTime = max(10, sleepTime) 171 172 def KillNumericInputThread(self): 173 if self.updateNumericInputThread: 174 self.updateNumericInputThread.kill() 175 self.updateNumericInputThread = None 176 177 def OnNumericUpButtonMouseUp(self, *args): 178 ButtonIcon.OnMouseUp(self.upButton, *args) 179 self.KillNumericInputThread() 180 181 def OnNumericDownButtonMouseUp(self, *args): 182 ButtonIcon.OnMouseUp(self.downButton, *args) 183 self.KillNumericInputThread()