timePicker.py (14607B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\moonmining\timePicker.py 2 import datetime 3 import gametime 4 from carbon.client.script.environment.AudioUtil import PlaySound 5 from carbon.common.script.util.format import FmtDate 6 from carbonui import const as uiconst 7 from carbonui.control.slider import Slider 8 from carbonui.primitives.container import Container 9 from carbonui.primitives.fill import Fill 10 from carbonui.primitives.frame import Frame 11 from carbonui.primitives.gridcontainer import GridContainer 12 from carbonui.primitives.line import Line 13 from carbonui.uicore import uicore 14 from eve.client.script.ui import eveThemeColor, eveColor 15 from eve.client.script.ui.control.eveLabel import EveLabelSmall 16 from eve.client.script.ui.control.themeColored import FrameThemeColored, FillThemeColored, SpriteThemeColored, LineThemeColored 17 from eve.client.script.ui.moonmining import DAY_NAME_TEXT, VULNERABILITY_COLOR, NUM_HOURS_IN_BLOCK, NUM_HOURS_ZOOMER, PARTS_IN_HOUR, GetRangeTimeForSlider, DAY_NAME_TEXT_SHORT 18 from eve.client.script.ui.shared.fitting.fittingUtil import EatSignalChangingErrors 19 from localization import GetByLabel 20 from moonmining.const import MAXIMUM_EXTRACTION_DURATION 21 from signals.signalUtil import ChangeSignalConnect 22 import blue 23 MAX_EXTRACTION_HOURS = MAXIMUM_EXTRACTION_DURATION / 3600 24 25 class TimePicker(Container): 26 default_height = 130 27 default_clipChildren = True 28 29 def ApplyAttributes(self, attributes): 30 Container.ApplyAttributes(self, attributes) 31 self.schedulingController = attributes.schedulingController 32 startVal = self.schedulingController.GetCurrentTimeAsPercentage() 33 self.areaSlider = AreaSlider(parent=self, name='areaSlider', align=uiconst.TOTOP, padTop=20, minValue=0.0, maxValue=1.0, startVal=startVal, callback=self.OnSliderChanged, height=24, barHeight=24, on_dragging=self.OnSliderSetValue, schedulingController=self.schedulingController) 34 self.zoomerCont = Container(parent=self, align=uiconst.TOTOP, height=36, padTop=20) 35 self.zoomer = Zoomer(parent=self.zoomerCont, barHeight=16, schedulingController=self.schedulingController) 36 self.ChangeSignalConnection() 37 38 def ChangeSignalConnection(self, connect = True): 39 signalAndCallback = [(self.schedulingController.on_hours_changed, self.OnHoursUpdated)] 40 ChangeSignalConnect(signalAndCallback, connect) 41 42 def OnSliderChanged(self, *args): 43 pass 44 45 def OnSliderSetValue(self, slider): 46 value = slider.GetValue() 47 self.schedulingController.SetTimestampFromPercentage(value) 48 49 def OnHoursUpdated(self, wasChange): 50 currentTime = self.schedulingController.GetCurrentTime() 51 valuePercentage = self.schedulingController.GetCurrentTimeAsPercentage() 52 self.areaSlider.SetValue(valuePercentage) 53 self.zoomer.LoadZoomer(currentTime) 54 55 def Close(self, *args, **kwds): 56 with EatSignalChangingErrors(errorMsg='TimePicker'): 57 self.ChangeSignalConnection(connect=False) 58 Container.Close(self) 59 60 61 class SchedulingTimeline(Container): 62 default_name = 'schedulingTimeline' 63 default_state = uiconst.TOALL 64 weekLineColor = (1, 1, 1, 0.3) 65 fuelExpiryLineColor = (1, 0.25, 0, 1.0) 66 67 def ApplyAttributes(self, attributes): 68 Container.ApplyAttributes(self, attributes) 69 self.schedulingController = attributes.schedulingController 70 self.fuelLine = None 71 numBlocks = MAX_EXTRACTION_HOURS / NUM_HOURS_IN_BLOCK 72 gridCont = GridContainer(name='mainCont', parent=self, align=uiconst.TOALL, lines=1, columns=numBlocks) 73 self.hourContList = [] 74 self.hourContDict = {} 75 startTime, _ = GetRangeTimeForSlider() 76 for x in xrange(numBlocks): 77 blockTimeStart = startTime + x * NUM_HOURS_IN_BLOCK * const.HOUR 78 _, _, wd, day, hour, _, _, _ = blue.os.GetTimeParts(blockTimeStart) 79 cName = '%s_%s_%s' % (wd, day, hour) 80 c = Container(name=cName, parent=gridCont) 81 if GetISOWeekDay(wd) == 0 and hour < NUM_HOURS_IN_BLOCK: 82 Line(parent=c, align=uiconst.TOLEFT_NOPUSH, weight=1, color=self.weekLineColor) 83 c.blockTimeStart = blockTimeStart 84 self.hourContList.append(c) 85 86 Fill(bgParent=self, color=(0.9, 0.9, 0.9, 0.075)) 87 self.MarkFuelExpiryTime() 88 self.ChangeSignalConnection() 89 90 def ChangeSignalConnection(self, connect = True): 91 signalAndCallback = [(self.schedulingController.on_fuel_changed, self.MarkFuelExpiryTime)] 92 ChangeSignalConnect(signalAndCallback, connect) 93 94 def MarkFuelExpiryTime(self): 95 fuelExpiryTime = self.schedulingController.GetFuelExpiryTime() 96 if self.fuelLine and not self.fuelLine.destroyed: 97 self.fuelLine.Close() 98 self.fuelLine = None 99 for each in self.hourContList: 100 if each.blockTimeStart <= fuelExpiryTime < each.blockTimeStart + NUM_HOURS_IN_BLOCK * const.HOUR: 101 self.fuelLine = Line(parent=each, align=uiconst.TOLEFT_NOPUSH, weight=2, color=self.fuelExpiryLineColor, padTop=-4, padBottom=-4, state=uiconst.UI_NORMAL) 102 self.fuelLine.hint = GetByLabel('UI/Moonmining/FuelExpires', timestamp=FmtDate(fuelExpiryTime, 'ls')) 103 return 104 105 def Close(self): 106 with EatSignalChangingErrors(errorMsg='Scheduling wnd'): 107 self.ChangeSignalConnection(connect=False) 108 Container.Close(self) 109 110 111 class AreaSlider(Slider): 112 __guid__ = 'AreaSlider' 113 default_barHeight = 13 114 default_state = uiconst.UI_NORMAL 115 zoomerFramePercentage = float(NUM_HOURS_ZOOMER) / MAX_EXTRACTION_HOURS 116 117 def ApplyAttributes(self, attributes): 118 self.sliderFillCont = None 119 self.zoomerBinding = None 120 self.curveSet = None 121 self.schedulingController = attributes.schedulingController 122 super(AreaSlider, self).ApplyAttributes(attributes) 123 self.barCont.OnMouseEnter = self.OnMouseEnter 124 self.barCont.OnMouseExit = self.OnMouseExit 125 timeline = SchedulingTimeline(parent=self, schedulingController=self.schedulingController, idx=0) 126 timeline.OnClick = self.OnSliderClicked 127 timeline.OnMouseWheel = self.OnMouseWheel 128 self.handle.SetOrder(0) 129 self.zoomerFrameCont.SetOrder(0) 130 startValue = self.schedulingController.GetCurrentTimeAsPercentage() 131 self.SetValue(startValue) 132 133 def _ConstructBackground(self): 134 bgCont = Container(name='bgCont', parent=self, align=uiconst.TOTOP_NOPUSH, height=self.height, idx=0, state=uiconst.UI_DISABLED, padRight=2) 135 self.sliderFillCont = Container(parent=bgCont, align=uiconst.TOLEFT_PROP) 136 FillThemeColored(name='handleFill', parent=self.sliderFillCont, align=uiconst.TORIGHT_NOPUSH, state=uiconst.UI_DISABLED, colorType=uiconst.COLORTYPE_UIHILIGHTGLOW, width=3, padRight=-2, opacity=5.0) 137 FrameThemeColored(parent=self.sliderFillCont, colorType=uiconst.COLORTYPE_UIHILIGHTGLOW, padLeft=0) 138 FillThemeColored(parent=self.sliderFillCont, colorType=uiconst.COLORTYPE_UIHILIGHTGLOW, opacity=0.25) 139 140 def _ConstructHandle(self): 141 self.handleOffset = 0 142 self.handle = Container(name='handle', parent=self, align=uiconst.BOTTOMLEFT, state=uiconst.UI_NORMAL, pos=(0, 143 0, 144 1, 145 self.height), colorType=uiconst.COLORTYPE_UIHILIGHTGLOW, idx=0) 146 self.handleFill = SpriteThemeColored(name='handleArrows', parent=self.handle, align=uiconst.CENTER, state=uiconst.UI_DISABLED, pos=(0, 0, 26, 24), color=eveThemeColor.THEME_FOCUS, outputMode=uiconst.OUTPUT_COLOR_AND_GLOW, texturePath='res:/UI/Texture/classes/moonmining/sliderHandle3.png') 147 self.zoomerFrameCont = ZoomerFrameCont(name='zoomerFrameCont', parent=self, align=uiconst.CENTERLEFT, pos=(0, 148 0, 149 60, 150 self.height), state=uiconst.UI_NORMAL) 151 Frame(parent=self.zoomerFrameCont, texturePath='res:/UI/Texture/Classes/Moonmining/zoomerFrame.png', cornerSize=6, padding=-1, color=eveThemeColor.THEME_ACCENT) 152 self.SetZoomerFrameWidth() 153 self.curveSet = uicore.animations.CreateCurveSet(useRealTime=True) 154 self.curveSet.name = 'zoomerCurveSet' 155 import trinity 156 self.zoomerBinding = trinity.CreatePythonBinding(self.curveSet, self.handle, 'left', self.zoomerFrameCont, 'myLeft') 157 self.curveSet.Play() 158 self.handle.OnMouseDown = self.OnHandleMouseDown 159 self.zoomerFrameCont.OnMouseDown = self.OnHandleMouseDown 160 self.handle.OnMouseUp = self.OnHandleMouseUp 161 self.zoomerFrameCont.OnMouseUp = self.OnHandleMouseUp 162 self.handle.OnMouseMove = self.OnHandleMouseMove 163 self.zoomerFrameCont.OnMouseMove = self.OnHandleMouseMove 164 self.zoomerFrameCont.OnMouseEnter = self.OnHandleMouseEnter 165 166 def OnMouseWheel(self, delta, *args): 167 if delta < 0: 168 direction = 1 169 else: 170 direction = -1 171 self.schedulingController.AddNumHours(direction) 172 173 def _ConstructLabel(self): 174 pass 175 176 def SetValue(self, value, *args, **kwargs): 177 Slider.SetValue(self, value, *args, **kwargs) 178 self.SetFill() 179 180 def SetFill(self): 181 value = self.schedulingController.GetCurrentTimeAsPercentage() 182 self.sliderFillCont.width = value 183 184 def Disable(self, *args): 185 Slider.Disable(self, args) 186 self.handle.state = uiconst.UI_HIDDEN 187 188 def Enable(self, *args): 189 Slider.Enable(self, args) 190 self.handle.state = uiconst.UI_NORMAL 191 192 def _OnResize(self, *args): 193 if getattr(self, 'zoomerFrameCont', None): 194 self.SetZoomerFrameWidth() 195 if getattr(self, 'handle', None): 196 self._UpdateHandlePosition(self.value) 197 198 def SetZoomerFrameWidth(self): 199 width = self.absoluteRight - self.absoluteLeft 200 self.zoomerFrameCont.width = self.zoomerFramePercentage * width 201 202 def Close(self): 203 self.RemoveZoomerBinding() 204 Slider.Close(self) 205 206 def RemoveZoomerBinding(self): 207 if self.zoomerBinding: 208 self.curveSet.bindings.fremove(self.zoomerBinding) 209 self.zoomerBinding = None 210 self.curveSet = None 211 212 213 class Zoomer(Container): 214 default_align = uiconst.TOALL 215 default_state = uiconst.UI_NORMAL 216 default_name = 'zoomer' 217 LIGHT_FILL_COLOR = (1.0, 1.0, 1.0, 0.1) 218 DARK_FILL_COLOR = (1.0, 1.0, 1.0, 0.05) 219 FILL_COLORS = [LIGHT_FILL_COLOR, DARK_FILL_COLOR] 220 221 def ApplyAttributes(self, attributes): 222 Container.ApplyAttributes(self, attributes) 223 self.schedulingController = attributes.schedulingController 224 barHeight = attributes.barHeight 225 Frame(parent=self, color=(0.5, 0.5, 0.5, 0.2)) 226 SpriteThemeColored(parent=self, texturePath='res:/UI/Texture/classes/Moonmining/scheduleMarker.png', pos=(0, -10, 17, 9), align=uiconst.CENTERTOP, colorType=uiconst.COLORTYPE_UIHILIGHTGLOW, opacity=1.0, state=uiconst.UI_DISABLED) 227 line = LineThemeColored(parent=self, align=uiconst.CENTERTOP, weight=2, height=barHeight, width=3, colorType=uiconst.COLORTYPE_UIHILIGHTGLOW) 228 gridCont = GridContainer(name='hourGrid', parent=self, align=uiconst.TOTOP, height=barHeight, lines=1, columns=NUM_HOURS_ZOOMER) 229 self.hourConts = [] 230 for x in xrange(NUM_HOURS_ZOOMER): 231 c = Container(parent=gridCont, state=uiconst.UI_NORMAL) 232 c.dayLine = Line(parent=c, align=uiconst.TOLEFT_NOPUSH, color=(1, 1, 1, 0.2)) 233 c.dayLine.display = False 234 fillColor = self.FILL_COLORS[x % 2] 235 c.fill = Fill(bgParent=c, color=fillColor) 236 c.startTime = None 237 c.OnClick = self.OnClick 238 self.hourConts.append(c) 239 240 currentTime = self.schedulingController.GetCurrentTime() 241 self.LoadZoomer(currentTime) 242 243 def LoadZoomer(self, currentTime): 244 zoomCurrentTime = currentTime - NUM_HOURS_ZOOMER / 2 * const.HOUR 245 year, month, wd, day, hour, min, sec, ms = blue.os.GetTimeParts(gametime.GetWallclockTime()) 246 currentWeek = datetime.date(year, month, day).isocalendar()[1] 247 for i in xrange(NUM_HOURS_ZOOMER): 248 year, month, wd, day, hour, min, sec, ms = blue.os.GetTimeParts(zoomCurrentTime) 249 c = self.hourConts[i] 250 c.startTime = zoomCurrentTime 251 if hour == 0: 252 c.dayLine.display = True 253 self.ShowDayLabel(c, zoomCurrentTime, wd) 254 else: 255 c.dayLine.display = False 256 self.HideDayLabel(c) 257 zoomCurrentTime += const.HOUR 258 259 def ShowDayLabel(self, parent, timestamp, wd): 260 label = self.GetDayLabel(parent, create=True) 261 dayName = DAY_NAME_TEXT_SHORT[wd] 262 dateText = FmtDate(timestamp, fmt='ln') 263 text = '%s | %s' % (dayName, dateText) 264 label.text = text.upper() 265 label.display = True 266 267 def HideDayLabel(self, parent): 268 label = self.GetDayLabel(parent, create=False) 269 if label: 270 label.display = False 271 272 def GetDayLabel(self, parent, create = False): 273 label = getattr(parent, 'dayLabel', None) 274 if label or not create: 275 return label 276 parent.dayLabel = EveLabelSmall(name='dayLabel', parent=parent, align=uiconst.BOTTOMLEFT, text='', state=uiconst.UI_NORMAL, top=-16) 277 return parent.dayLabel 278 279 def OnSliderSetValue(self, slider): 280 value = slider.GetValue() 281 currentPos = value * NUM_HOURS_ZOOMER 282 hoursToAdd = currentPos - NUM_HOURS_ZOOMER / 2 283 hoursToAdd = int(round(hoursToAdd, 0)) 284 if hoursToAdd: 285 self.schedulingController.AddNumHours(hoursToAdd) 286 287 def OnMouseWheel(self, delta, *args): 288 if delta < 0: 289 direction = 1 290 else: 291 direction = -1 292 self.schedulingController.AddNumHours(direction / float(PARTS_IN_HOUR), PARTS_IN_HOUR) 293 294 def OnClick(self, *args): 295 currentMouseOver = uicore.uilib.mouseOver 296 if currentMouseOver in self.hourConts: 297 timestamp = currentMouseOver.startTime 298 self.schedulingController.SetTimestamp(timestamp) 299 PlaySound(uiconst.SOUND_BUTTON_CLICK) 300 301 302 class ZoomerFrameCont(Container): 303 304 def ApplyAttributes(self, attributes): 305 Container.ApplyAttributes(self, attributes) 306 307 @apply 308 def myLeft(): 309 310 def fset(self, value): 311 self.left = int(value - self.width / 2) 312 313 return property(**locals()) 314 315 316 def GetISOWeekDay(wd): 317 newWd = wd - 1 318 if newWd < 0: 319 newWd = 6 320 return newWd