Exemplo n.º 1
0
 def Setup(self, entry, size, menu, identifier):
     text = entry.caption
     self.sr.label.fontsize = size
     self.sr.label.text = text
     self.menu = menu
     menuIconSize = menu.iconSize
     icon = None
     if menuIconSize:
         icon = Sprite(parent=self, pos=(0,
          0,
          menuIconSize,
          menuIconSize), align=uiconst.RELATIVE, idx=0, state=uiconst.UI_DISABLED, name='icon')
         icon.LoadIcon(entry.icon or 'ui_1_16_101', ignoreSize=True)
         self.sr.label.left += menuIconSize
     self.id = identifier
     if not entry.enabled:
         if icon:
             icon.SetAlpha(0.5)
         self.sr.label.SetRGB(1.0, 1.0, 1.0, 0.5)
         if isinstance(entry.value, basestring):
             self.sr.label.text += ' (' + entry.value + ')'
     self.width = self.sr.label.textwidth + self.sr.label.left + self.LABELHORIZONTALPADDING
     self.height = max(menuIconSize, self.sr.label.textheight + self.LABELVERTICALPADDING)
     if not entry.enabled:
         self.state = uiconst.UI_DISABLED
     if isinstance(entry.value, (list, tuple)):
         self.triangle.state = uiconst.UI_DISABLED
         self.submenu = entry.value
Exemplo n.º 2
0
 def AddIconLabel(self, icon, label, iconSize = 32):
     self.FillRow()
     iconObj = Sprite(pos=(0,
      0,
      iconSize,
      iconSize), align=uiconst.CENTERLEFT)
     iconObj.LoadIcon(icon, ignoreSize=True)
     self.AddCell(iconObj, cellPadding=(-3, 0, 3, 0))
     labelObj = self.AddLabelMedium(text=label, align=uiconst.CENTERLEFT, bold=True, cellPadding=(0, 0, 7, 0))
     return (iconObj, labelObj)
Exemplo n.º 3
0
 def AddIconLabelValue(self, icon, label, value, valueColor = COLOR_NUMBERVALUE, iconSize = 32):
     self.FillRow()
     iconObj = Sprite(pos=(0,
      0,
      iconSize,
      iconSize), align=uiconst.CENTERLEFT)
     iconObj.LoadIcon(icon, ignoreSize=True)
     self.AddCell(iconObj, cellPadding=(-3, 0, 3, 0))
     labelObj = self.AddLabelMedium(text=label, align=uiconst.CENTERLEFT, bold=True, cellPadding=(0, 0, 7, 0))
     valueObj = self.AddLabelMedium(align=uiconst.CENTERRIGHT, bold=True, color=valueColor, top=1, colSpan=self.columns - 2, cellPadding=(7, 0, 0, 0))
     return (iconObj, labelObj, valueObj)
Exemplo n.º 4
0
class BracketTooltipRow(BracketTooltipRowBase):
    subLabel = None
    fleetBroadcastSprite = None
    fleetBroadcastType = None

    def ApplyAttributes(self, attributes):
        BracketTooltipRowBase.ApplyAttributes(self, attributes)
        self.selectedSprite = None
        if self.bracket.slimItem:
            selected, hilited = sm.GetService('state').GetStates(
                self.bracket.slimItem, [state.selected, state.mouseOver])
            self.SetSelected(selected)
            self.SetHilited(hilited)
        self.StartDynamicUpdates()

    def CreateIcon(self):
        self.iconObj = SpaceObjectIcon(state=uiconst.UI_DISABLED,
                                       pos=(0, 0, 16, 16),
                                       align=uiconst.CENTER,
                                       parent=self.iconParent)
        self.UpdateIcon()
        return self.iconObj

    def IsBracketStillValid(self):
        ball = self.bracket.ball
        slimItem = self.bracket.slimItem
        return ball or slimItem

    def UpdateIcon(self):
        if not self.bracket or self.bracket.destroyed:
            return
        ball = self.bracket.ball
        slimItem = self.bracket.slimItem
        if slimItem:
            self.iconObj.UpdateSpaceObjectIcon(slimItem, ball)
            self.iconObj.UpdateSpaceObjectIconColor(slimItem, ball)
            self.iconObj.UpdateSpaceObjectState(slimItem, ball)
            self.iconObj.UpdateSpaceObjectFlagAndBackgroundColor(
                slimItem, ball)
        else:
            iconNo = getattr(self.bracket, 'iconNo', None)
            if iconNo:
                self.iconObj.iconSprite.LoadIcon(iconNo)

    def SetSelected(self, selectedState):
        if selectedState:
            if not self.selectedSprite:
                self.selectedSprite = Sprite(
                    parent=self.iconObj,
                    pos=(0, 0, 30, 30),
                    name='selection',
                    state=uiconst.UI_DISABLED,
                    texturePath=
                    'res:/UI/Texture/classes/Bracket/selectionCircle.png',
                    align=uiconst.CENTER,
                    color=(1, 1, 1, 0.5))
            self.selectedSprite.display = True
        elif self.selectedSprite:
            self.selectedSprite.display = False

    def UpdateDynamicValues(self):
        if self.destroyed:
            return
        bracket = self.GetBracket()
        if not bracket or bracket.destroyed:
            self.dynamicsUpdateTimer = None
            return
        distance = None
        if getattr(bracket, 'showDistance', 1):
            distance = bracket.GetDistance()
            if distance:
                if not self.isCompact:
                    self.distanceLabel.text = FmtDist(distance)
        rightAligned = self.mainLabel.align != uiconst.CENTERLEFT
        fleetBroadcastType = getattr(bracket, 'fleetBroadcastType', None)
        if fleetBroadcastType:
            if fleetBroadcastType != self.fleetBroadcastType:
                self.fleetBroadcastType = fleetBroadcastType
                icon = fleetbr.types[fleetBroadcastType]['smallIcon']
                if not self.fleetBroadcastSprite:
                    self.fleetBroadcastSprite = Sprite(
                        parent=self.mainLabel,
                        pos=(0, 0, 16, 16),
                        state=uiconst.UI_NORMAL,
                        align=uiconst.CENTERLEFT,
                        idx=0)
                    self.fleetBroadcastSprite.DelegateEvents(self)
                self.fleetBroadcastSprite.LoadIcon(icon)
            if rightAligned:
                self.mainLabel.SetSideMargins(0, 18)
                self.fleetBroadcastSprite.align = uiconst.CENTERRIGHT
            else:
                self.mainLabel.SetSideMargins(18, 0)
        elif self.fleetBroadcastSprite:
            self.fleetBroadcastSprite.Close()
            self.fleetBroadcastSprite = None
            self.fleetBroadcastType = None
            self.mainLabel.SetSideMargins()
        tagAndTargetStr = getattr(bracket, 'tagAndTargetStr', None)
        subinfoString = None
        if hasattr(bracket, 'GetSubLabelCallback'):
            subinfoCallback = bracket.GetSubLabelCallback()
            if subinfoCallback:
                subinfoString = subinfoCallback()
        combinedString = ''
        if rightAligned:
            combinedString = '<right>'
        combinedString += bracket.displayName
        if self.isCompact and distance:
            combinedString += ' ' + FmtDist(distance)
        if subinfoString or tagAndTargetStr:
            combinedString += '<br>'
            if tagAndTargetStr:
                combinedString += '<b>' + tagAndTargetStr + '</b>'
            if subinfoString:
                if tagAndTargetStr:
                    combinedString += '  '
                combinedString += '[' + subinfoString + ']'
        self.mainLabel.text = combinedString
        self.iconParent.height = max(MINENTRYHEIGHT, self.mainLabel.height)
Exemplo n.º 5
0
class MenuEntryViewCore(Container):
    __guid__ = 'uicls.MenuEntryViewCore'
    LABELVERTICALPADDING = 2
    LABELHORIZONTALPADDING = 8
    default_hiliteColor = (0.0, 0.0, 0.0, 0.25)
    default_fontsize = 10
    default_fontStyle = None
    default_fontFamily = None
    default_fontPath = None

    def ApplyAttributes(self, attributes):
        Container.ApplyAttributes(self, attributes)
        self.fontStyle = attributes.get('fontStyle', self.default_fontStyle)
        self.fontFamily = attributes.get('fontFamily', self.default_fontFamily)
        self.fontPath = attributes.get('fontPath', self.default_fontPath)
        self.fontsize = attributes.get('fontsize', self.default_fontsize)
        self.cursor = 1
        self.clicked = 0
        self.submenu = None
        self.submenuview = None
        self.sr.hilite = None
        self._hiliteColor = attributes.get('hiliteColor', self.default_hiliteColor)
        self.Prepare()

    def Prepare(self, *args):
        self.Prepare_Triangle_()
        self.Prepare_Label_()
        self.sr.label.OnMouseDown = self.OnMouseDown
        self.sr.label.OnMouseUp = self.OnMouseUp

    def Prepare_Triangle_(self, *args):
        self.triangle = Sprite(parent=self, align=uiconst.CENTERRIGHT, state=uiconst.UI_HIDDEN, idx=0)
        self.triangle.LoadIcon('ui_1_16_14')

    def Prepare_Label_(self, *args):
        label = Label(parent=self, pos=(8, 1, 0, 0), align=uiconst.CENTERLEFT, letterspace=1, fontStyle=self.fontStyle, fontFamily=self.fontFamily, fontPath=self.fontPath, fontsize=self.fontsize, state=uiconst.UI_DISABLED)
        self.sr.label = label

    def Prepare_Hilite_(self, *args):
        self.sr.hilite = Fill(parent=self, color=self._hiliteColor)

    def Setup(self, entry, size, menu, identifier):
        text = entry.caption
        self.sr.label.fontsize = size
        self.sr.label.text = text
        self.menu = menu
        menuIconSize = menu.iconSize
        icon = None
        if menuIconSize:
            icon = Sprite(parent=self, pos=(0,
             0,
             menuIconSize,
             menuIconSize), align=uiconst.RELATIVE, idx=0, state=uiconst.UI_DISABLED, name='icon')
            icon.LoadIcon(entry.icon or 'ui_1_16_101', ignoreSize=True)
            self.sr.label.left += menuIconSize
        self.id = identifier
        if not entry.enabled:
            if icon:
                icon.SetAlpha(0.5)
            self.sr.label.SetRGB(1.0, 1.0, 1.0, 0.5)
            if isinstance(entry.value, basestring):
                self.sr.label.text += ' (' + entry.value + ')'
        self.width = self.sr.label.textwidth + self.sr.label.left + self.LABELHORIZONTALPADDING
        self.height = max(menuIconSize, self.sr.label.textheight + self.LABELVERTICALPADDING)
        if not entry.enabled:
            self.state = uiconst.UI_DISABLED
        if isinstance(entry.value, (list, tuple)):
            self.triangle.state = uiconst.UI_DISABLED
            self.submenu = entry.value

    def _OnClose(self):
        if self.submenuview is not None and not self.submenuview.destroyed:
            self.submenuview.Close()
            self.submenuview = None
        self.menu = None
        self.submenu = None
        self.expandTimer = None
        self.collapseTimer = None
        Container._OnClose(self)

    def OnMouseDown(self, *etc):
        uthread.new(self.MouseDown)

    def MouseDown(self):
        if not self.destroyed and self.submenu:
            self.Expand()

    def OnMouseUp(self, *etc):
        if not self.submenu and uicore.uilib.mouseOver in (self, self.sr.label):
            self.menu.ActivateEntry(self.id)
            uthread.new(CloseContextMenus)

    def OnMouseEnter(self, *args):
        uicore.Message('ContextMenuEnter')
        for each in self.parent.children:
            if each.sr.hilite:
                each.sr.hilite.Close()
                each.sr.hilite = None

        if self.sr.hilite is None:
            self.Prepare_Hilite_()
        self.expandTimer = AutoTimer(10, self.ExpandMenu)

    def ExpandMenu(self):
        for each in self.parent.children:
            if each != self and getattr(each, 'submenuview', None):
                each.Collapse()

        self.expandTimer = None
        if uicore.uilib.mouseOver in (self, self.sr.label) and self.submenu:
            self.Expand()

    def OnMouseExit(self, *args):
        pass

    def toggle(self):
        if self.submenuview:
            self.Collapse()
        else:
            self.Expand()

    def Collapse(self):
        self.collapseTimer = None
        if self.submenuview and self.submenuview.destroyed:
            self.submenuview = None
        elif self.submenuview:
            self.submenuview.Collapse()
            self.submenuview = None

    def Expand(self):
        if not self.submenuview:
            for each in self.parent.children:
                if each != self and getattr(each, 'submenuview', None):
                    each.Collapse()

            if self.submenu[0] == 'isDynamic':
                menu = CreateMenuView(CreateMenuFromList(apply(self.submenu[1], self.submenu[2])), self.parent)
            else:
                menu = CreateMenuView(CreateMenuFromList(self.submenu), self.parent)
            if not menu:
                return
            w = uicore.desktop.width
            h = uicore.desktop.height
            aL, aT, aW, aH = self.GetAbsolute()
            menu.top = max(0, min(h - menu.height, aT))
            if aL + aW + menu.width <= w:
                menu.left = aL + aW + 3
            else:
                aL, aT, aW, aH = self.GetAbsolute()
                menu.left = aL - menu.width + 5
            uicore.layer.menu.children.insert(0, menu)
            if self.destroyed:
                CloseContextMenus()
                return
            self.submenuview = menu