Ejemplo n.º 1
0
class JobStateContainer(Container):
    default_state = uiconst.UI_NORMAL

    def ApplyAttributes(self, attributes):
        Container.ApplyAttributes(self, attributes)
        self.jobData = attributes.jobData
        self.ConstructLayout()
        self.UpdateValue()

    def ConstructLayout(self):
        if not self.jobData:
            return
        if self.jobData.status == industry.STATUS_READY:
            self.deliverBtn = Button(name='deliverBtn', parent=self, align=uiconst.TOALL, label='<b>' + localization.GetByLabel('UI/Industry/Deliver'), func=self.OnDeliverBtn, padding=2)
            self.deliverBtn.width = self.deliverBtn.height = 0
            self.deliverBtn.Blink(time=3000)
            self.Enable()
        else:
            self.Disable()
            gaugeCont = ContainerAutoSize(name='gaugeCont', parent=self, align=uiconst.TOBOTTOM)
            mainCont = Container(name='mainCont', parent=self)
            self.deliverBtn = None
            self.valueLabel = EveLabelMedium(parent=mainCont, align=uiconst.CENTERLEFT, left=4)
        if self.jobData.status == industry.STATUS_INSTALLED:
            color = industryUIConst.COLOR_MANUFACTURING if self.jobData.activityID == industry.MANUFACTURING else industryUIConst.COLOR_SCIENCE
            self.gauge = Gauge(parent=gaugeCont, align=uiconst.TOTOP, state=uiconst.UI_DISABLED, color=color, height=6, gaugeHeight=6, padTop=1, backgroundColor=(1.0, 1.0, 1.0, 0.05))

    def OnStatusChanged(self):
        self.Flush()
        self.ConstructLayout()
        if self.jobData.status == industry.STATUS_DELIVERED:
            uicore.animations.FadeTo(self.valueLabel, 0.0, 1.0)

    def UpdateValue(self, animate = False, num = 0):
        if not self.jobData or self.jobData.status in (industry.STATUS_READY, industry.STATUS_UNSUBMITTED):
            return
        if self.jobData.status == industry.STATUS_INSTALLED:
            progressRatio = self.jobData.GetJobProgressRatio()
            if progressRatio:
                self.gauge.SetValueInstantly(progressRatio)
                if animate and progressRatio != 1.0:
                    self.gauge.AnimFlash(1.0, duration=3.0, timeOffset=num * 0.1)
        self.valueLabel.text = self.jobData.GetJobStateLabel()

    def OnDeliverBtn(self, *args):
        sm.GetService('industrySvc').CompleteJob(self.jobData.jobID)
        sm.GetService('audio').SendUIEvent('ind_jobDelivered')

    def OnNewJobData(self, jobData):
        self.jobData = jobData
        self.OnStatusChanged()
        self.UpdateValue(animate=True)

    def StartUpdate(self):
        uthread.new(self._UpdateThread)

    def _UpdateThread(self):
        while not self.destroyed:
            self.UpdateValue()
            blue.synchro.SleepWallclock(500)
Ejemplo n.º 2
0
class BaseContainerMETE(Container):
    default_align = uiconst.TOPLEFT
    default_state = uiconst.UI_NORMAL

    def ApplyAttributes(self, attributes):
        Container.ApplyAttributes(self, attributes)
        self.value = 0.0
        iconPath = attributes.iconPath
        iconSize = attributes.iconSize
        minValue = attributes.minValue
        maxValue = attributes.maxValue
        showBG = attributes.get('showBG', True)
        isCompact = attributes.get('isCompact', False)
        self.jobData = attributes.jobData
        self.gauge = Gauge(parent=self,
                           align=uiconst.TOBOTTOM,
                           state=uiconst.UI_DISABLED,
                           height=6,
                           gaugeHeight=6,
                           padTop=1,
                           backgroundColor=(1.0, 1.0, 1.0, 0.05))
        if isCompact:
            self.icon = None
            self.valueLabel = None
            return
        mainCont = Container(name='mainCont', parent=self)
        if showBG:
            self.bg = StretchSpriteHorizontal(
                bgParent=mainCont,
                texturePath='res:/UI/Texture/Classes/Industry/Center/bgMETE.png'
            )
            FillThemeColored(bgParent=self, opacity=0.5)
        else:
            self.bg = None
        left = 8 if showBG else 2
        self.icon = Sprite(name='icon',
                           parent=mainCont,
                           align=uiconst.TOPLEFT,
                           state=uiconst.UI_DISABLED,
                           pos=(left, 3, self.ICONSIZE, self.ICONSIZE),
                           texturePath=self.ICONPATH,
                           opacity=0.6)
        self.valueLabel = EveLabelMediumBold(parent=mainCont,
                                             align=uiconst.TOPRIGHT,
                                             top=4,
                                             left=left)
        self.removeIcon = Sprite(
            parent=mainCont,
            align=uiconst.CENTERRIGHT,
            state=uiconst.UI_HIDDEN,
            texturePath='res:/ui/texture/icons/73_16_45.png',
            pos=(0, 0, 12, 12),
            color=Color.RED,
            hint=localization.GetByLabel('UI/Industry/PreviewModeHint'))
        self.removeIcon.OnClick = self.OnRemoveIconClick
        self.previewEdit = SinglelineEdit(name='previewEdit',
                                          parent=mainCont,
                                          align=uiconst.CENTERRIGHT,
                                          state=uiconst.UI_HIDDEN,
                                          ints=(0, self.MAXVAL),
                                          OnChange=self.OnPreviewEdit,
                                          pos=(12, 0, 34, 20))
        self.errorFrame = ErrorFrame(bgParent=self, padding=(1, 1, 1, 8))

    def SetValue(self, value):
        if self.value * (value or 1) < 0.0:
            self.gauge.SetValueInstantly(0.0)
        self.value = value
        if value < 0:
            self.gauge.SetGaugeAlign(uiconst.TORIGHT_PROP)
            self.gauge.SetValue(float(value) / self.MINVAL)
            self.gauge.SetColor(COLOR_NOTREADY)
        else:
            self.gauge.SetGaugeAlign(uiconst.TOLEFT_PROP)
            self.gauge.SetValue(float(value) / self.MAXVAL)
            self.gauge.SetColor(COLOR_READY)
        if not self.valueLabel:
            return
        if value < 0:
            self.valueLabel.text = '<color=%s>%s%%' % (Color.RGBtoHex(
                *COLOR_NOTREADY), value)
        elif value == 0:
            self.valueLabel.text = '<color=%s>%s%%' % (Color.RGBtoHex(
                *COLOR_FRAME), value)
        else:
            self.valueLabel.text = '<color=%s>%s%%' % (Color.RGBtoHex(
                *COLOR_READY), value)

    def OnMouseEnter(self, *args):
        sm.GetService('audio').SendUIEvent('ind_mouseEnter')

    def OnRemoveIconClick(self):
        self.ExitPreviewMode()

    def EnterPreviewMode(self):
        if not self.IsPreviewEnabled():
            return
        self.previewEdit.Show()
        self.previewEdit.SetValue(self.GetPreviewEditValue())
        self.valueLabel.Hide()
        self.errorFrame.Show()
        self.removeIcon.Show()
        uicore.registry.SetFocus(self.previewEdit)

    def ExitPreviewMode(self):
        self.previewEdit.Hide()
        self.valueLabel.Show()
        self.errorFrame.Hide()
        self.removeIcon.Hide()
        if self.jobData:
            self.jobData.timeEfficiency = None
            self.jobData.materialEfficiency = None
            self.jobData.update(self.jobData)

    def OnClick(self, *args):
        self.EnterPreviewMode()

    def OnMouseEnter(self, *args):
        if self.bg and self.IsPreviewEnabled():
            uicore.animations.FadeTo(self.bg,
                                     self.bg.opacity,
                                     1.5,
                                     duration=0.3)

    def OnMouseExit(self, *args):
        if self.bg:
            uicore.animations.FadeTo(self.bg,
                                     self.bg.opacity,
                                     1.0,
                                     duration=0.3)

    def OnNewJobData(self, jobData):
        self.jobData = jobData
        self.ExitPreviewMode()

    def IsPreviewEnabled(self):
        if not self.jobData or self.jobData.activityID != industry.MANUFACTURING or self.jobData.jobID:
            return False
        return True

    def IsPreviewActive(self):
        return self.errorFrame.display

    def GetHint(self):
        if self.IsPreviewEnabled() and not self.IsPreviewActive():
            return '<br><br>' + localization.GetByLabel(
                'UI/Industry/EnterPreviewModeHint')
        return ''