class VitaeMeter(DirectFrame):

    def __init__(self, parent, **kw):
        DirectFrame.__init__(self, parent)
        self.initialiseoptions(VitaeMeter)
        toplevel_gui = loader.loadModel('models/gui/toplevel_gui')
        self.vitaeDial = DialMeter(parent = self, meterColor = Vec4(0.80000000000000004, 0.20000000000000001, 0.20000000000000001, 1), baseColor = Vec4(0, 0, 0, 1), scale = 0.28000000000000003)
        icon = toplevel_gui.find('**/morale_skull*')
        self.vitaeIcon = DirectFrame(parent = self, state = DGG.NORMAL, relief = None, image = icon, image_scale = 0.625)
        detailLabel = DirectLabel(relief = None, state = DGG.DISABLED, text = PLocalizer.VitaeDesc, text_align = TextNode.ALeft, text_scale = PiratesGuiGlobals.TextScaleExtraLarge, text_fg = PiratesGuiGlobals.TextFG1, text_wordwrap = 15, text_shadow = (0, 0, 0, 1), pos = (0.0, 0, -0.025000000000000001), textMayChange = 0, sortOrder = 91)
        height = -(detailLabel.getHeight() + 0.01)
        width = max(0.25, detailLabel.getWidth() + 0.040000000000000001)
        self.helpBox = BorderFrame(parent = self, state = DGG.DISABLED, modelName = 'general_frame_f', frameSize = (-0.040000000000000001, width, height, 0.050000000000000003), pos = (0.050000000000000003, 0, -0.050000000000000003), sortOrder = 90)
        detailLabel.reparentTo(self.helpBox)
        self.helpBox.hide()
        self.helpBox.setClipPlaneOff()
        self.meterLabel = DirectLabel(parent = self.vitaeDial, relief = None, pos = (0, 0, -0.45000000000000001), text = PLocalizer.Vitae, text_scale = 0.20000000000000001, text_align = TextNode.ACenter, text_fg = PiratesGuiGlobals.TextFG1, text_shadow = PiratesGuiGlobals.TextShadow, text_font = PiratesGlobals.getPirateOutlineFont(), textMayChange = 1)
        self.vitaeIcon.bind(DGG.WITHIN, self.showDetails)
        self.vitaeIcon.bind(DGG.WITHOUT, self.hideDetails)


    def showDetails(self, event):
        self.helpBox.show()


    def hideDetails(self, event):
        self.helpBox.hide()


    def update(self, level, range, val):
        self.vitaeDial.hide()
        Range = range * 1.0009999999999999
        if level > 0:
            self.vitaeDial.update(val, Range)
            self.vitaeDial.show()
class BuffIcon(DirectFrame):
    Background = None
    Card = None

    def __init__(self, parent, effectId, duration, attackerId, **kw):
        optiondefs = (('relief', None, None),)
        self.defineoptions(kw, optiondefs)
        DirectFrame.__init__(self, parent)
        self.initialiseoptions(BuffIcon)
        if not self.Background:
            self.Background = loader.loadModel('models/gui/lookout_gui').find('**/lookout_submit')
            self.Background.setScale(0.33000000000000002)

        if not self.Card:
            self.Card = loader.loadModel('models/textureCards/buff_icons')

        self.myIcon = None
        self.detailFrame = None
        self.dial = None
        self.iconScale = 0.070000000000000007
        self.effectId = effectId
        self.maxDuration = duration
        self.timeLeft = duration
        self.lastTimestamp = None
        self.attackerId = attackerId
        self.setDepthWrite(0)
        self.setFogOff()
        self.setLightOff()
        self.setBin('gui-fixed', 0)


    def makeIcons(self):
        self.Background.copyTo(self)
        self.dial = DialMeter(parent = self, meterColor = Vec4(0.29999999999999999, 0.0, 0.80000000000000004, 1), baseColor = Vec4(0, 0, 0, 1), scale = 0.17000000000000001, sortOrder = 0)
        if self.effectId in buffTable:
            info = buffTable.get(self.effectId)
        else:
            info = buffTable.get(WeaponGlobals.C_UNKNOWN_EFFECT)
        self.myIcon = DirectButton(parent = self, relief = None, geom = self.Card.find('**/' + info[0]), geom_scale = self.iconScale, sortOrder = 1)
        self.myIcon.bind(DGG.ENTER, self.showDetails)
        self.myIcon.bind(DGG.EXIT, self.hideDetails)
        self.updateIconInfo()


    def makeDetails(self):
        if self.detailFrame:
            return None

        normalScale = 0.97307200000000005
        parent = self.getParent()
        if parent:
            for i in range(0, 2):
                parent = parent.getParent()
                if not parent:
                    break
                    continue


        if parent:
            parentScale = parent.getScale()[0]
        else:
            parentScale = normalScale
        durationStr = str(int(self.maxDuration))
        if self.effectId in buffTable:
            text = buffTable[self.effectId][1] + PLocalizer.BuffDuration % durationStr
        else:
            text = buffTable[WeaponGlobals.C_UNKNOWN_EFFECT][1] + PLocalizer.BuffDuration % durationStr
        self.detailBox = DirectLabel(state = DGG.DISABLED, relief = None, text = text, text_align = TextNode.ALeft, text_scale = PiratesGuiGlobals.TextScaleExtraLarge * normalScale / parentScale, text_fg = (1, 1, 1, 1), text_wordwrap = 15, text_shadow = (0, 0, 0, 1), textMayChange = 1)
        height = -(self.detailBox.getHeight() + 0.01)
        width = max(0.25, self.detailBox.getWidth() + 0.040000000000000001)
        self.detailFrame = BorderFrame(parent = self.myIcon, state = DGG.DISABLED, frameSize = (-0.040000000000000001, width, height, 0.070000000000000007), pos = (0.050000000000000003, 0, -0.050000000000000003))
        self.detailBox.reparentTo(self.detailFrame)
        self.detailFrame.setBin('gui-popup', 0)
        self.detailFrame.hide()


    def showDetails(self, event):
        self.makeDetails()
        self.detailFrame.show()
        self.updateIconInfo()


    def hideDetails(self, event):
        if self.detailFrame:
            self.detailFrame.hide()



    def updateIconInfo(self):
        if self.lastTimestamp == None:
            timeOffset = 0.0
        else:
            timeOffset = globalClockDelta.localElapsedTime(self.lastTimestamp)
        duration = max(0.0, self.timeLeft - timeOffset)
        self.dial.update(duration, self.maxDuration)
        if self.detailFrame and not self.detailFrame.isHidden():
            if duration > 0:
                durationStr = PLocalizer.BuffDuration % str(int(duration) + 1)
            else:
                durationStr = ''
            if self.effectId in buffTable:
                text = buffTable[self.effectId][1] + durationStr
            else:
                text = buffTable[WeaponGlobals.C_UNKNOWN_EFFECT][1] + durationStr
            self.detailBox['text'] = text



    def destroy(self):
        DirectFrame.destroy(self)
class GuiButton(DirectButton):
    notify = directNotify.newCategory('GuiButton')
    genericButton = None
    redGenericButton = None
    blueGenericButton = None

    def __init__(self, parent = None, hotkeys = (), hotkeyLabel = None, hotkeyLabelX = 0.091999999999999998, hotkeyArgs = True, helpText = '', helpPos = (0, 0, 0), helpDelay = PiratesGuiGlobals.HelpPopupTime, helpColorOff = False, helpLeftAlign = False, helpCenterAlign = False, **kw):
        self.loadGui()
        self.helpBox = None
        self.helpWatcher = None
        self.canRepositon = False
        optiondefs = (('relief', None, None), ('pos', (0, 0, 0), None), ('image', GuiButton.genericButton, None), ('image_scale', (0.23999999999999999, 0.22, 0.22), None), ('image_pos', (0, 0, 0), None), ('pressEffect', 0, None), ('text', '', None), ('text_font', PiratesGlobals.getInterfaceFont(), None), ('text_scale', PiratesGuiGlobals.TextScaleLarge, None), ('text0_fg', PiratesGuiGlobals.TextFG2, None), ('text1_fg', PiratesGuiGlobals.TextFG2, None), ('text2_fg', PiratesGuiGlobals.TextFG2, None), ('text3_fg', PiratesGuiGlobals.TextFG3, None), ('text_shadow', PiratesGuiGlobals.TextShadow, None), ('text_pos', (0, -0.01), None), ('text_wordwrap', 8, None), ('text_align', TextNode.ACenter, None), ('textMayChange', 1, None), ('helpText', helpText, self.helpTextUpdated), ('helpPos', helpPos, self.setHelpPos), ('helpDelay', helpDelay, None), ('helpColorOff', helpColorOff, None), ('helpLeftAlign', helpLeftAlign, None), ('helpCenterAlign', helpCenterAlign, None), ('helpBin', 'gui-popup', None), ('helpBinSort', 0, None), ('helpOpaque', 0, None), ('canReposition', False, None), ('sortOrder', 100, None), ('baseImage', None, None), ('selected', False, None), ('selectedImage', GuiButton.genericButton, None), ('state', DGG.NORMAL, self.setState))
        self.defineoptions(kw, optiondefs)
        DirectButton.__init__(self, parent = NodePath())
        self.initialiseoptions(GuiButton)
        self.hotkeys = ()
        self.setupHotkeys(hotkeys, hotkeyLabel, self['command'], self['extraArgs'], hotkeyLabelX, hotkeyArgs)
        if not parent:
            pass
        self.reparentTo(aspect2d)
        self.helpTaskName = None


    def destroy(self):
        self.hideDetails()
        if self.helpWatcher:
            self.helpWatcher.unbind(DGG.WITHIN)
            self.helpWatcher.unbind(DGG.WITHOUT)
            self.helpWatcher.destroy()
            self.helpWatcher = None

        self.unbind(DGG.ENTER)
        self.unbind(DGG.EXIT)
        self.ignoreAll()
        DirectButton.destroy(self)


    def loadGui(self):
        if GuiButton.genericButton:
            return None

        gui = loader.loadModel('models/gui/toplevel_gui')
        GuiButton.genericButton = (gui.find('**/generic_button'), gui.find('**/generic_button_down'), gui.find('**/generic_button_over'), gui.find('**/generic_button_disabled'))
        GuiButton.redGenericButton = (gui.find('**/pir_t_gui_but_generic'), gui.find('**/pir_t_gui_but_generic_down'), gui.find('**/pir_t_gui_but_generic_over'), gui.find('**/pir_t_gui_but_generic_disabled'))
        GuiButton.blueGenericButton = (gui.find('**/pir_t_gui_but_generic_blue'), gui.find('**/pir_t_gui_but_generic_blue_down'), gui.find('**/pir_t_gui_but_generic_blue_over'), gui.find('**/pir_t_gui_but_generic_blue_disabled'))


    def setupHotkeys(self, hotkeys, hotkeyLabel, command, extraArgs, hotkeyLabelX = 0.091999999999999998, hotkeyArgs = True):
        if self.hotkeys:
            self.ignoreHotkeys()
            self.hotkeyLabel.destroy()

        self.hotkeys = hotkeys
        self.command = command
        self.extraArgs = extraArgs
        self.hotkeyLabel = hotkeyLabel
        self.hotkeyLabelX = hotkeyLabelX
        self.hotkeyArgs = hotkeyArgs
        if self.hotkeys:
            self.hotkeyLabel = DirectLabel(parent = self, relief = None, state = DGG.DISABLED, text = hotkeyLabel, text_font = PiratesGlobals.getPirateBoldOutlineFont(), text_scale = PiratesGuiGlobals.TextScaleMed, text_pos = (hotkeyLabelX, 0.01), text_fg = PiratesGuiGlobals.TextFG2, text_shadow = PiratesGuiGlobals.TextShadow, textMayChange = 1)
            self.acceptHotkeys()
        

    
    def ignoreHotkeys(self):
        if self.hotkeys:
            for hotkey in self.hotkeys:
                self.ignore(hotkey)
            
        

    
    def acceptHotkeys(self):
        if self.hotkeys:
            for hotkey in self.hotkeys:
                if self.hotkeyArgs:
                    self.accept(hotkey, self.command, self.extraArgs + [
                        hotkey])
                    continue
                self.accept(hotkey, self.command, self.extraArgs)




    def createHelpWatcher(self):
        if self['helpOpaque']:
            self.bind(DGG.ENTER, self.waitShowDetails)
            self.bind(DGG.EXIT, self.hideDetails)
        else:
            w = self.getWidth()
            h = self.getHeight()
            pos = self._GuiButton__discoverHelpWatcherPos()
            if not self['frameSize']:
                pass
            frameSize = self.getBounds()
            self.helpWatcher = DirectFrame(parent = self, relief = base.config.GetBool('show-helpwatchers', 0), state = DGG.NORMAL, frameColor = (1, 1, 0, 0.5), frameSize = frameSize, sortOrder = self['sortOrder'] - 1)
            self.helpWatcher.wrtReparentTo(self.getParent())
            self.reparentTo(self.getParent())
            self.helpWatcher.bind(DGG.WITHIN, self.waitShowDetails)
            self.helpWatcher.bind(DGG.WITHOUT, self.hideDetails)


    def _GuiButton__discoverHelpWatcherPos(self):
        w = self.getWidth()
        h = self.getHeight()
        if not self['frameSize']:
            pass
        bounds = self.getBounds()
        pos = Vec3(bounds[0] + w / 2, 0, bounds[2] + h / 2)
        return pos


    def resetHelpWatcher(self):
        if self.helpWatcher:
            self.helpWatcher.setPos(self, 0, 0, 0)



    def createHelpBox(self):
        if not self.helpWatcher:
            self.createHelpWatcher()

        helpLabel = DirectLabel(relief = None, state = DGG.DISABLED, text = self['helpText'], text_align = TextNode.ACenter, text_scale = PiratesGuiGlobals.TextScaleMed, text_fg = PiratesGuiGlobals.TextFG1, text_wordwrap = 12, text_shadow = (0, 0, 0, 1), textMayChange = 0, sortOrder = 91)
        height = helpLabel.getHeight()
        width = helpLabel.getWidth() + 0.050000000000000003
        if self['helpLeftAlign']:
            fs = [
                0.0,
                width,
                -height,
                0.044999999999999998]
            pos = [
                width / 2.0,
                0,
                -0.01]
        elif self['helpCenterAlign']:
            pos = [
                0.0,
                0.0,
                -0.01]
            fs = [
                -(width / 2 + 0.01),
                width / 2 + 0.01,
                -(height / 2 + 0.014999999999999999),
                height / 2 + 0.014999999999999999]
        else:
            fs = [
                0.25 - width,
                0.25,
                -height,
                0.044999999999999998]
            pos = [
                0.25 - width / 2.0,
                0,
                -0.01]
        self.helpBox = BorderFrame(parent = self, state = DGG.DISABLED, frameSize = (fs[0], fs[1], fs[2], fs[3]), modelName = 'general_frame_f', pos = self['helpPos'], sortOrder = 90)
        helpLabel.reparentTo(self.helpBox)
        helpLabel.setPos(pos[0], pos[1], pos[2])
        self.helpBox.hide()
        self.helpBox.setClipPlaneOff()
        pos = self.helpBox.getPos(aspect2d)
        x = min(pos[0], base.a2dRight - width)
        z = max(pos[2], base.a2dBottom - height)
        self.helpBox.setPos(aspect2d, x, 0, z)
        if self['helpColorOff']:
            self.helpBox.setColorOff()
        else:
            self.helpBox.flattenLight()
        if self['helpBin']:
            self.helpBox.setBin(self['helpBin'], self['helpBinSort'])



    def helpTextUpdated(self):
        if self.helpBox and self.helpBox['text'] != self['helpText']:
            self.helpBox.destroy()
            self.createHelpBox()
        elif self['helpText']:
            self.createHelpBox()



    def setHelpPos(self):
        if self.helpBox:
            self.helpTextUpdated()



    def waitShowDetails(self, event):

        try:
            self['helpDelay']
        except AttributeError:
            return None

        if not self.helpBox:
            self.createHelpBox()

        if self['helpDelay']:
            self.hideDetails()
            self.helpTaskName = 'helpInfoTask-%s' % self.getName()
            taskMgr.doMethodLater(self['helpDelay'], self.helpBox.show, self.helpTaskName, extraArgs = [])
        else:
            self.helpBox.show()


    def hideDetails(self, event = None):
        if self.helpTaskName:
            taskMgr.remove(self.helpTaskName)

        if self.helpBox and not self.helpBox.isEmpty():
            self.helpBox.hide()



    def setImage(self):
        DirectButton.setImage(self)
        if not self['baseImage']:
            self['baseImage'] = self['image']



    def setSelected(self):
        if self['selected']:
            self['image'] = self['selectedImage']
        else:
            self['image'] = self['baseImage']


    def setState(self):
        DirectButton.setState(self)
        if self.helpWatcher:
            self.helpWatcher['state'] = self['state']



    def removeNode(self):
        DirectButton.removeNode(self)
        if self.helpWatcher:
            self.helpWatcher.removeNode()



    def remove(self):
        DirectButton.remove(self)
        if self.helpWatcher:
            self.helpWatcher.remove()



    def detachNode(self):
        DirectButton.detachNode(self)
        if self.helpWatcher:
            self.helpWatcher.detachNode()



    def hide(self):
        DirectButton.hide(self)
        if self.helpWatcher:
            self.helpWatcher.hide()



    def show(self):
        DirectButton.show(self)
        if self.helpWatcher:
            self.helpWatcher.show()



    def stash(self):
        DirectButton.stash(self)
        if self.helpWatcher:
            self.helpWatcher.stash()



    def unstash(self):
        DirectButton.unstash(self)
        self.reparentTo(self.getParent(), sort = self['sortOrder'])
        if self.helpWatcher:
            self.helpWatcher.unstash()
            self.helpWatcher.reparentTo(self.helpWatcher.getParent(), sort = self.helpWatcher['sortOrder'])
예제 #4
0
class BuffIcon(DirectFrame):
    __module__ = __name__
    Background = None
    Card = None

    def __init__(self, parent, effectId, duration, attackerId, **kw):
        optiondefs = (('relief', None, None), )
        self.defineoptions(kw, optiondefs)
        DirectFrame.__init__(self, parent, **kw)
        self.initialiseoptions(BuffIcon)
        if not self.Background:
            self.Background = loader.loadModel('models/gui/lookout_gui').find(
                '**/lookout_submit')
            self.Background.setScale(0.33)
        if not self.Card:
            self.Card = loader.loadModel('models/textureCards/buff_icons')
        self.myIcon = None
        self.detailFrame = None
        self.dial = None
        self.iconScale = 0.07
        self.effectId = effectId
        self.maxDuration = duration
        self.timeLeft = duration
        self.lastTimestamp = None
        self.attackerId = attackerId
        self.setDepthWrite(0)
        self.setFogOff()
        self.setLightOff()
        self.setBin('gui-fixed', 0)
        return

    def makeIcons(self):
        self.Background.copyTo(self)
        self.dial = DialMeter(parent=self,
                              meterColor=Vec4(0.3, 0.0, 0.8, 1),
                              baseColor=Vec4(0, 0, 0, 1),
                              scale=0.17,
                              sortOrder=0)
        if self.effectId in buffTable:
            info = buffTable.get(self.effectId)
        else:
            info = buffTable.get(WeaponGlobals.C_UNKNOWN_EFFECT)
        self.myIcon = DirectButton(parent=self,
                                   relief=None,
                                   geom=self.Card.find('**/' + info[0]),
                                   geom_scale=self.iconScale,
                                   sortOrder=1)
        self.myIcon.bind(DGG.ENTER, self.showDetails)
        self.myIcon.bind(DGG.EXIT, self.hideDetails)
        self.updateIconInfo()
        return

    def makeDetails(self):
        if self.detailFrame:
            return
        normalScale = 0.973072
        parent = self.getParent()
        if parent:
            for i in range(0, 2):
                parent = parent.getParent()
                if not parent:
                    break

        if parent:
            parentScale = parent.getScale()[0]
        else:
            parentScale = normalScale
        durationStr = str(int(self.maxDuration))
        if self.effectId in buffTable:
            text = buffTable[
                self.effectId][1] + PLocalizer.BuffDuration % durationStr
        else:
            text = buffTable[WeaponGlobals.C_UNKNOWN_EFFECT][
                1] + PLocalizer.BuffDuration % durationStr
        self.detailBox = DirectLabel(
            state=DGG.DISABLED,
            relief=None,
            text=text,
            text_align=TextNode.ALeft,
            text_scale=PiratesGuiGlobals.TextScaleExtraLarge * normalScale /
            parentScale,
            text_fg=(1, 1, 1, 1),
            text_wordwrap=15,
            text_shadow=(0, 0, 0, 1),
            textMayChange=1)
        height = -(self.detailBox.getHeight() + 0.01)
        width = max(0.25, self.detailBox.getWidth() + 0.04)
        self.detailFrame = BorderFrame(parent=self.myIcon,
                                       state=DGG.DISABLED,
                                       frameSize=(-0.04, width, height, 0.07),
                                       pos=(0.05, 0, -0.05))
        self.detailBox.reparentTo(self.detailFrame)
        self.detailFrame.setBin('gui-popup', 0)
        self.detailFrame.hide()
        return

    def showDetails(self, event):
        self.makeDetails()
        self.detailFrame.show()
        self.updateIconInfo()

    def hideDetails(self, event):
        if self.detailFrame:
            self.detailFrame.hide()

    def updateIconInfo(self):
        if self.lastTimestamp == None:
            timeOffset = 0.0
        else:
            timeOffset = globalClockDelta.localElapsedTime(self.lastTimestamp)
        duration = max(0.0, self.timeLeft - timeOffset)
        self.dial.update(duration, self.maxDuration)
        if self.detailFrame:
            if not self.detailFrame.isHidden():
                if duration > 0:
                    durationStr = PLocalizer.BuffDuration % str(
                        int(duration) + 1)
                else:
                    durationStr = ''
                text = self.effectId in buffTable and buffTable[
                    self.effectId][1] + durationStr
            else:
                text = buffTable[
                    WeaponGlobals.C_UNKNOWN_EFFECT][1] + durationStr
            self.detailBox['text'] = text
        return

    def destroy(self):
        DirectFrame.destroy(self)
예제 #5
0
class TextIsland(Island):
    __module__ = __name__

    def __init__(self,
                 name,
                 islandUid,
                 modelName,
                 isTeleportIsland,
                 nodePath=NodePath(),
                 offset=0.0,
                 scale=1.0,
                 collisionIndex=17,
                 stencilId=0,
                 *args,
                 **kwargs):
        Island.__init__(self, name, islandUid, modelName, isTeleportIsland,
                        scale, collisionIndex, stencilId, *args, **kwargs)
        pencil = self.geom.find('**/pencil*')
        if not pencil.isEmpty():
            pass
        self.name = name
        self.helpBox = None
        self.helpLabel = None
        self.textScaleNode = self.attachNewNode('textScale')

        def formatName(name, lineWidth):
            tokens = name.split()
            out = ''
            count = 0
            for token in tokens:
                if count + len(token) < lineWidth:
                    count += len(token) + 1
                    out = '%s %s' % (out, token)
                else:
                    count = len(token) + 1
                    out = '%s\n%s' % (out, token)

            out.strip()
            return '\x01smallCaps\x01%s\x02' % (out, )

        formattedName = formatName(self.name, 10)
        self.text = Text(name + '-text', nodePath, offset, formattedName,
                         stencilId)
        self.text.reparentTo(self.textScaleNode)
        self.text.setBin('background', 2)
        if self.getNetTag('islandUid') == '1160614528.73sdnaik':
            mesh = self.geom
            t, T = self.text.getTightBounds()
            i, I = mesh.getTightBounds()
        else:
            mesh = self.geom.find('**/top_mesh')
            t, T = self.text.getTightBounds()
            if not mesh.isEmpty():
                i, I = mesh.getTightBounds()
            else:
                i, I = self.geom.getTightBounds()
            i *= self.geom.getScale()[0]
            I *= self.geom.getScale()[0]
        self.textScaleNode.setPos(0, (i[1] - I[1]) / 2 - T[2], 0.001)
        compassGui = loader.loadModel('models/gui/compass_gui')
        topGui = loader.loadModel('models/gui/toplevel_gui')
        icons = loader.loadModel('models/textureCards/icons')
        self.button = self.text.attachNewNode('button')
        bg = topGui.find('**/treasure_w_b_slot_empty')
        bg.setScale(0.14)
        bg.reparentTo(self.button)
        buttonPos = Point3(t[0] - 0.022, 0, (t[2] + T[2]) / 2.0)
        self.button.flattenStrong()
        self.button.setPos(buttonPos)
        self.button.setColorScaleOff()
        self.button.hide()
        self.teleportIconDisabled = compassGui.find(
            '**/compass_icon_objective_grey')
        self.teleportIconDisabled.setScale(0.14)
        self.teleportIconDisabled.reparentTo(self.button)
        self.teleportIconEnabled = compassGui.find(
            '**/compass_icon_objective_green')
        self.teleportIconEnabled.setScale(0.14)
        self.teleportIconEnabled.reparentTo(self.button)
        self.manIcon = icons.find('**/icon_stickman')
        self.manIcon.setScale(0.035)
        self.manIcon.reparentTo(self.button)
        t, T = self.text.getTightBounds()
        p0 = VBase3(t[0], 0, t[2])
        p1 = VBase3(T[0], 0, t[2])
        p2 = VBase3(T[0], 0, T[2])
        p3 = VBase3(t[0], 0, T[2])
        self.colNode = self.text.attachNewNode(CollisionNode('cNode-' + name))
        self.colNode.node().addSolid(CollisionPolygon(p0, p1, p2, p3))
        self.colNode.node().setFromCollideMask(BitMask32.allOff())
        self.colNode.node().setIntoCollideMask(BitMask32.bit(collisionIndex))
        self.createHelpBox()
        self.updateState()
        return

    def updateZoom(self, zoom):
        self.textScaleNode.setScale(1 - zoom / 1.5)

    def setAsCurrentIsland(self, isCurrent):
        Island.setAsCurrentIsland(self, isCurrent)
        self.updateState()

    def setAsReturnIsland(self, isReturn):
        Island.setAsReturnIsland(self, isReturn)
        self.updateState()

    def setAsPortOfCall(self, isPortOfCall):
        Island.setAsPortOfCall(self, isPortOfCall)
        self.updateState()

    def setHasTeleportToken(self, hasToken):
        Island.setHasTeleportToken(self, hasToken)
        self.updateState()

    def updateState(self, mouseOver=False):
        if not hasattr(self, 'button'):
            return
        self.button.hide()
        self.teleportIconEnabled.hide()
        self.teleportIconDisabled.hide()
        if self.isCurrentIsland():
            self.manIcon.show()
            self.button.show()
        if self.isTeleportIsland():
            self.button.show()
            self.manIcon.hide()
            self.teleportIconDisabled.show()
            self.teleportIconDisabled.clearColorScale()
            self.button.setColorScale(0.5, 0.5, 0.5, 1)
            self.setHelpLabel(PLocalizer.MapNeedsTeleportToken)
        if self.getCanTeleportTo():
            self.button.show()
            self.button.clearColorScale()
            self.teleportIconDisabled.hide()
            self.teleportIconEnabled.show()
            self.text.setBold(1)
            if not self.isCurrentIsland():
                self.isReturnIsland() and self.setHelpLabel(
                    PLocalizer.MapCanTeleportReturn)
            else:
                if not self.isCurrentIsland():
                    self.isPortOfCall() and self.setHelpLabel(
                        PLocalizer.MapCanTeleportPortOfCall)
                else:
                    self.setHelpLabel(PLocalizer.MapCanTeleport)
            if mouseOver:
                self.geom.setColorScale(0.5, 1, 0.5, 1)
        if self.isCurrentIsland() and not mouseOver:
            self.button.show()
            self.button.clearColorScale()
            self.button.setScale(1)
            self.text.setBold(1)
            self.teleportIconEnabled.hide()
            self.teleportIconDisabled.hide()
            self.manIcon.show()
            if not self.isTeleportIsland():
                self.setHelpLabel(PLocalizer.MapCurrentIsland)
        if self.isCurrentIsland() and mouseOver:
            self.button.show()
            self.button.clearColorScale()
            self.button.setScale(1)
            self.text.setBold(1)
            self.teleportIconEnabled.show()
            self.teleportIconDisabled.hide()
            self.manIcon.hide()
        if not self.isCurrentIsland() and not mouseOver:
            self.setHelpLabel('')
            self.text.setBold(0)
            self.manIcon.hide()

    def mouseOver(self, pos):
        self.updateState(mouseOver=True)
        self.showDetails(pos)

    def mouseLeft(self):
        self.geom.clearColorScale()
        self.hideDetails()
        self.updateState(mouseOver=False)

    def createHelpBox(self):
        if not self.helpBox:
            self.helpLabel = DirectLabel(
                parent=aspect2d,
                relief=None,
                text='',
                text_align=TextNode.ALeft,
                text_scale=PiratesGuiGlobals.TextScaleSmall,
                text_fg=PiratesGuiGlobals.TextFG2,
                text_wordwrap=12,
                text_shadow=(0, 0, 0, 1),
                textMayChange=1,
                sortOrder=91)
            height = -(self.helpLabel.getHeight() + 0.01)
            width = max(0.25, self.helpLabel.getWidth() + 0.04)
            self.helpBox = BorderFrame(parent=aspect2d,
                                       state=DGG.DISABLED,
                                       frameSize=(-0.04, width, height, 0.05),
                                       pos=(0, 0, 0),
                                       sortOrder=90)
            self.helpLabel.reparentTo(self.helpBox)
            self.helpBox.hide()
        return

    def setHelpLabel(self, text):
        self.helpLabel['text'] = text
        self.helpLabel.resetFrameSize()
        height = -(self.helpLabel.getHeight() + 0.01)
        width = max(0.25, self.helpLabel.getWidth() + 0.04)
        self.helpBox['frameSize'] = (-0.04, width, height, 0.05)
        self.helpBox.resetFrameSize()

    def showDetails(self, pos):
        if self.helpLabel['text'] != '':
            self.helpBox.setPos(pos -
                                Point3(self.helpBox['frameSize'][1] *
                                       1.25, 0, 0))
            self.helpBox.setBin('gui-popup', 0)
            self.helpBox.show()

    def hideDetails(self):
        if self.helpBox:
            self.helpBox.hide()
예제 #6
0
class TextIsland(Island):

    def __init__(self, name, islandUid, modelName, isTeleportIsland, nodePath = NodePath(), offset = 0.0, scale = 1.0, collisionIndex = 17, stencilId = 0, *args, **kwargs):
        Island.__init__(self, name, islandUid, modelName, isTeleportIsland, scale, collisionIndex, stencilId, *args, **kwargs)
        pencil = self.geom.find('**/pencil*')
        if not pencil.isEmpty():
            pass
        1
        self.name = name
        self.helpBox = None
        self.helpLabel = None
        self.textScaleNode = self.attachNewNode('textScale')

        def formatName(name, lineWidth):
            tokens = name.split()
            out = ''
            count = 0
            for token in tokens:
                if count + len(token) < lineWidth:
                    count += len(token) + 1
                    out = '%s %s' % (out, token)
                    continue
                count = len(token) + 1
                out = '%s\n%s' % (out, token)

            out.strip()
            return 'smallCaps%s' % (out,)

        formattedName = formatName(self.name, 10)
        self.text = Text(name + '-text', nodePath, offset, formattedName, stencilId)
        self.text.reparentTo(self.textScaleNode)
        self.text.setBin('background', 2)
        if self.getNetTag('islandUid') == '1160614528.73sdnaik':
            mesh = self.geom
            (t, T) = self.text.getTightBounds()
            (i, I) = mesh.getTightBounds()
        else:
            mesh = self.geom.find('**/top_mesh')
            (t, T) = self.text.getTightBounds()
            if not mesh.isEmpty():
                (i, I) = mesh.getTightBounds()
            else:
                (i, I) = self.geom.getTightBounds()
            i *= self.geom.getScale()[0]
            I *= self.geom.getScale()[0]
        self.textScaleNode.setPos(0, (i[1] - I[1]) / 2 - T[2], 0.001)
        compassGui = loader.loadModel('models/gui/compass_gui')
        topGui = loader.loadModel('models/gui/toplevel_gui')
        icons = loader.loadModel('models/textureCards/icons')
        self.button = self.text.attachNewNode('button')
        bg = topGui.find('**/treasure_w_b_slot_empty')
        bg.setScale(0.14000000000000001)
        bg.reparentTo(self.button)
        buttonPos = Point3(t[0] - 0.021999999999999999, 0, (t[2] + T[2]) / 2.0)
        self.button.flattenStrong()
        self.button.setPos(buttonPos)
        self.button.setColorScaleOff()
        self.button.hide()
        self.teleportIconDisabled = compassGui.find('**/compass_icon_objective_grey')
        self.teleportIconDisabled.setScale(0.14000000000000001)
        self.teleportIconDisabled.reparentTo(self.button)
        self.teleportIconEnabled = compassGui.find('**/compass_icon_objective_green')
        self.teleportIconEnabled.setScale(0.14000000000000001)
        self.teleportIconEnabled.reparentTo(self.button)
        self.manIcon = icons.find('**/icon_stickman')
        self.manIcon.setScale(0.035000000000000003)
        self.manIcon.reparentTo(self.button)
        (t, T) = self.text.getTightBounds()
        p0 = VBase3(t[0], 0, t[2])
        p1 = VBase3(T[0], 0, t[2])
        p2 = VBase3(T[0], 0, T[2])
        p3 = VBase3(t[0], 0, T[2])
        self.colNode = self.text.attachNewNode(CollisionNode('cNode-' + name))
        self.colNode.node().addSolid(CollisionPolygon(p0, p1, p2, p3))
        self.colNode.node().setFromCollideMask(BitMask32.allOff())
        self.colNode.node().setIntoCollideMask(BitMask32.bit(collisionIndex))
        self.createHelpBox()
        self.updateState()


    def updateZoom(self, zoom):
        self.textScaleNode.setScale(1 - zoom / 1.5)


    def setAsCurrentIsland(self, isCurrent):
        Island.setAsCurrentIsland(self, isCurrent)
        self.updateState()


    def setAsReturnIsland(self, isReturn):
        Island.setAsReturnIsland(self, isReturn)
        self.updateState()


    def setAsPortOfCall(self, isPortOfCall):
        Island.setAsPortOfCall(self, isPortOfCall)
        self.updateState()


    def setHasTeleportToken(self, hasToken):
        Island.setHasTeleportToken(self, hasToken)
        self.updateState()


    def updateState(self, mouseOver = False):
        if not hasattr(self, 'button'):
            return None

        self.button.hide()
        self.teleportIconEnabled.hide()
        self.teleportIconDisabled.hide()
        if self.isCurrentIsland():
            self.manIcon.show()
            self.button.show()

        if self.isTeleportIsland():
            self.button.show()
            self.manIcon.hide()
            self.teleportIconDisabled.show()
            self.teleportIconDisabled.clearColorScale()
            self.button.setColorScale(0.5, 0.5, 0.5, 1)
            self.setHelpLabel(PLocalizer.MapNeedsTeleportToken)

        if self.getCanTeleportTo():
            self.button.show()
            self.button.clearColorScale()
            self.teleportIconDisabled.hide()
            self.teleportIconEnabled.show()
            self.text.setBold(1)
            if not self.isCurrentIsland() and self.isReturnIsland():
                self.setHelpLabel(PLocalizer.MapCanTeleportReturn)
            elif not self.isCurrentIsland() and self.isPortOfCall():
                self.setHelpLabel(PLocalizer.MapCanTeleportPortOfCall)
            else:
                self.setHelpLabel(PLocalizer.MapCanTeleport)
            if mouseOver:
                self.geom.setColorScale(0.5, 1, 0.5, 1)


        if self.isCurrentIsland() and not mouseOver:
            self.button.show()
            self.button.clearColorScale()
            self.button.setScale(1)
            self.text.setBold(1)
            self.teleportIconEnabled.hide()
            self.teleportIconDisabled.hide()
            self.manIcon.show()
            if not self.isTeleportIsland():
                self.setHelpLabel(PLocalizer.MapCurrentIsland)


        if self.isCurrentIsland() and mouseOver:
            self.button.show()
            self.button.clearColorScale()
            self.button.setScale(1)
            self.text.setBold(1)
            self.teleportIconEnabled.show()
            self.teleportIconDisabled.hide()
            self.manIcon.hide()

        if not self.isCurrentIsland() and not mouseOver:
            self.setHelpLabel('')
            self.text.setBold(0)
            self.manIcon.hide()



    def mouseOver(self, pos):
        self.updateState(mouseOver = True)
        self.showDetails(pos)


    def mouseLeft(self):
        self.geom.clearColorScale()
        self.hideDetails()
        self.updateState(mouseOver = False)


    def createHelpBox(self):
        if not self.helpBox:
            self.helpLabel = DirectLabel(parent = aspect2d, relief = None, text = '', text_align = TextNode.ALeft, text_scale = PiratesGuiGlobals.TextScaleSmall, text_fg = PiratesGuiGlobals.TextFG2, text_wordwrap = 12, text_shadow = (0, 0, 0, 1), textMayChange = 1, sortOrder = 91)
            height = -(self.helpLabel.getHeight() + 0.01)
            width = max(0.25, self.helpLabel.getWidth() + 0.040000000000000001)
            self.helpBox = BorderFrame(parent = aspect2d, state = DGG.DISABLED, frameSize = (-0.040000000000000001, width, height, 0.050000000000000003), pos = (0, 0, 0), sortOrder = 90)
            self.helpLabel.reparentTo(self.helpBox)
            self.helpBox.hide()



    def setHelpLabel(self, text):
        self.helpLabel['text'] = text
        self.helpLabel.resetFrameSize()
        height = -(self.helpLabel.getHeight() + 0.01)
        width = max(0.25, self.helpLabel.getWidth() + 0.040000000000000001)
        self.helpBox['frameSize'] = (-0.040000000000000001, width, height, 0.050000000000000003)
        self.helpBox.resetFrameSize()


    def showDetails(self, pos):
        if self.helpLabel['text'] != '':
            self.helpBox.setPos(pos - Point3(self.helpBox['frameSize'][1] * 1.25, 0, 0))
            self.helpBox.setBin('gui-popup', 0)
            self.helpBox.show()



    def hideDetails(self):
        if self.helpBox:
            self.helpBox.hide()
예제 #7
0
class Dart(PickableModel):

    def __init__(self, name, parent, defaultPos, color = Vec4(1), offset = 0.0, *args, **kwargs):
        self.startScale = 0.074999999999999997
        self.highlightScale = 0.10000000000000001
        PickableModel.__init__(self, name, modelName = 'icon_objective_grey', scale = self.startScale, collisionIndex = 17, modelPath = 'models/gui/compass_main', *args, **kwargs)
        self.defaultPos = defaultPos
        self.edgeMode = False
        self.helpBox = None
        self.helpLabel = None
        self.normalModeNode = self.attachNewNode('normal')
        self.normalModeNode.setColorScale(color)
        self.normalModeNode.setY(-(offset + 0.0074999999999999997))
        self.geom.instanceTo(self.normalModeNode)
        self.colNode = self.normalModeNode.attachNewNode(CollisionNode('cNode'))
        self.colNode.node().addSolid(CollisionSphere(Point3(0, 0, 0), 0.25))
        self.colNode.setScale(1 / 20.0)
        self.colNode.node().setFromCollideMask(BitMask32.allOff())
        self.colNode.node().setIntoCollideMask(BitMask32.bit(17))
        self.setTag('dart', name)
        self.setPos(self.defaultPos)
        self.createHelpBox()
        questId = localAvatar.activeQuestId
        qs = localAvatar.getQuestById(questId)
        if qs:
            title = qs.getStatusText()
            self.setHelpLabel(title)



    def toggleHelpText(self):
        if self.helpBox:
            if not self.helpBox.isHidden():
                self.hideDetails()




    def createHelpBox(self):
        if not self.helpBox:
            self.helpLabel = DirectLabel(parent = aspect2d, relief = None, text = '', text_align = TextNode.ALeft, text_scale = PiratesGuiGlobals.TextScaleSmall, text_fg = PiratesGuiGlobals.TextFG2, text_wordwrap = 12, text_shadow = (0, 0, 0, 1), textMayChange = 1, sortOrder = 91)
            height = -(self.helpLabel.getHeight() + 0.01)
            width = max(0.25, self.helpLabel.getWidth() + 0.040000000000000001)
            self.helpBox = BorderFrame(parent = aspect2d, state = DGG.DISABLED, frameSize = (-0.040000000000000001, width, height, 0.050000000000000003), pos = (0, 0, 0), sortOrder = 90)
            self.helpLabel.reparentTo(self.helpBox)
            self.helpBox.hide()



    def setHelpLabel(self, text):
        self.helpLabel['text'] = text
        self.helpLabel.resetFrameSize()
        height = -(self.helpLabel.getHeight() + 0.01)
        width = max(0.25, self.helpLabel.getWidth() + 0.040000000000000001)
        self.helpBox['frameSize'] = (-0.040000000000000001, width, height, 0.050000000000000003)
        self.helpBox.resetFrameSize()


    def showDetails(self, pos):
        if self.helpLabel['text'] != '':
            self.helpBox.setPos(pos + Point3(self.helpBox['frameSize'][1] * 0.25, 0, 0))
            self.helpBox.setBin('gui-popup', 0)
            self.helpBox.show()
            self.geom.setScale(self.highlightScale)



    def hideDetails(self):
        if self.helpBox:
            self.helpBox.hide()
            self.geom.setScale(self.startScale)



    def mouseOver(self, pos):
        self.showDetails(pos)


    def mouseLeft(self):
        self.hideDetails()


    def getDefaultPos(self):
        return self.defaultPos


    def setEdgeMode(self, edgeMode):
        self.edgeMode = edgeMode
        if self.edgeMode:
            self.edgeModeNode.unstash()
        else:
            self.edgeModeNode.stash()


    def setColorScale(self, *args, **kwargs):
        self.edgeModeNode.setColorScale(*args, **kwargs)
        self.normalModeNode.setColorScale(*args, **kwargs)


    def setScale(self, *args, **kwargs):
        self.normalModeNode.setScale(*args, **kwargs)


    def setPosition(self, worldPos, *args, **kwargs):
        NodePath.setPos(self, *args, **kwargs)
        if self.edgeMode:
            self.edgeModeNode.setPos(*args, **kwargs)
예제 #8
0
class VitaeMeter(DirectFrame):
    def __init__(self, parent, **kw):
        DirectFrame.__init__(self, parent, **None)
        self.initialiseoptions(VitaeMeter)
        toplevel_gui = loader.loadModel('models/gui/toplevel_gui')
        self.vitaeDial = DialMeter(parent=self,
                                   meterColor=Vec4(0.80000000000000004,
                                                   0.20000000000000001,
                                                   0.20000000000000001, 1),
                                   baseColor=Vec4(0, 0, 0, 1),
                                   scale=0.28000000000000003)
        icon = toplevel_gui.find('**/morale_skull*')
        self.vitaeIcon = DirectFrame(parent=self,
                                     state=DGG.NORMAL,
                                     relief=None,
                                     image=icon,
                                     image_scale=0.625)
        detailLabel = DirectLabel(
            relief=None,
            state=DGG.DISABLED,
            text=PLocalizer.VitaeDesc,
            text_align=TextNode.ALeft,
            text_scale=PiratesGuiGlobals.TextScaleExtraLarge,
            text_fg=PiratesGuiGlobals.TextFG1,
            text_wordwrap=15,
            text_shadow=(0, 0, 0, 1),
            pos=(0.0, 0, -0.025000000000000001),
            textMayChange=0,
            sortOrder=91)
        height = -(detailLabel.getHeight() + 0.01)
        width = max(0.25, detailLabel.getWidth() + 0.040000000000000001)
        self.helpBox = BorderFrame(parent=self,
                                   state=DGG.DISABLED,
                                   modelName='general_frame_f',
                                   frameSize=(-0.040000000000000001, width,
                                              height, 0.050000000000000003),
                                   pos=(0.050000000000000003, 0,
                                        -0.050000000000000003),
                                   sortOrder=90)
        detailLabel.reparentTo(self.helpBox)
        self.helpBox.hide()
        self.helpBox.setClipPlaneOff()
        self.meterLabel = DirectLabel(
            parent=self.vitaeDial,
            relief=None,
            pos=(0, 0, -0.45000000000000001),
            text=PLocalizer.Vitae,
            text_scale=0.20000000000000001,
            text_align=TextNode.ACenter,
            text_fg=PiratesGuiGlobals.TextFG1,
            text_shadow=PiratesGuiGlobals.TextShadow,
            text_font=PiratesGlobals.getPirateOutlineFont(),
            textMayChange=1)
        self.vitaeIcon.bind(DGG.WITHIN, self.showDetails)
        self.vitaeIcon.bind(DGG.WITHOUT, self.hideDetails)

    def showDetails(self, event):
        self.helpBox.show()

    def hideDetails(self, event):
        self.helpBox.hide()

    def update(self, level, range, val):
        self.vitaeDial.hide()
        Range = range * 1.0009999999999999
        if level > 0:
            self.vitaeDial.update(val, Range)
            self.vitaeDial.show()
예제 #9
0
class GuiButton(DirectButton):
    notify = directNotify.newCategory('GuiButton')
    genericButton = None
    redGenericButton = None
    blueGenericButton = None

    def __init__(self, parent=None, hotkeys=(), hotkeyLabel=None, hotkeyLabelX=0.092, hotkeyArgs=True, helpText='', helpPos=(0, 0, 0), helpDelay=PiratesGuiGlobals.HelpPopupTime, helpColorOff=False, helpLeftAlign=False, helpCenterAlign=False, **kw):
        self.loadGui()
        self.helpBox = None
        self.helpWatcher = None
        self.canRepositon = False
        optiondefs = (
         (
          'relief', None, None), ('pos', (0, 0, 0), None), ('image', GuiButton.genericButton, None), ('image_scale', (0.24, 0.22, 0.22), None), ('image_pos', (0, 0, 0), None), ('pressEffect', 0, None), ('text', '', None), ('text_font', PiratesGlobals.getInterfaceFont(), None), ('text_scale', PiratesGuiGlobals.TextScaleLarge, None), ('text0_fg', PiratesGuiGlobals.TextFG2, None), ('text1_fg', PiratesGuiGlobals.TextFG2, None), ('text2_fg', PiratesGuiGlobals.TextFG2, None), ('text3_fg', PiratesGuiGlobals.TextFG3, None), ('text_shadow', PiratesGuiGlobals.TextShadow, None), ('text_pos', (0, -0.01), None), ('text_wordwrap', 8, None), ('text_align', TextNode.ACenter, None), ('textMayChange', 1, None), ('helpText', helpText, self.helpTextUpdated), ('helpPos', helpPos, self.setHelpPos), ('helpDelay', helpDelay, None), ('helpColorOff', helpColorOff, None), ('helpLeftAlign', helpLeftAlign, None), ('helpCenterAlign', helpCenterAlign, None), ('helpBin', 'gui-popup', None), ('helpBinSort', 0, None), ('helpOpaque', 0, None), ('canReposition', False, None), ('sortOrder', 100, None), ('baseImage', None, None), ('selected', False, None), ('selectedImage', GuiButton.genericButton, None), ('state', DGG.NORMAL, self.setState))
        self.defineoptions(kw, optiondefs)
        DirectButton.__init__(self, parent=NodePath(), **kw)
        self.initialiseoptions(GuiButton)
        self.hotkeys = ()
        self.setupHotkeys(hotkeys, hotkeyLabel, self['command'], self['extraArgs'], hotkeyLabelX, hotkeyArgs)
        self.reparentTo(parent or aspect2d)
        self.helpTaskName = None
        return None

    def destroy(self):
        self.hideDetails()
        self.command = None
        if self.helpWatcher:
            self.helpWatcher.command = None
            self.helpWatcher.unbind(DGG.WITHIN)
            self.helpWatcher.unbind(DGG.WITHOUT)
            self.helpWatcher.destroy()
            self.helpWatcher = None
        self.unbind(DGG.ENTER)
        self.unbind(DGG.EXIT)
        self.ignoreAll()
        DirectButton.destroy(self)
        return

    def loadGui(self):
        if GuiButton.genericButton:
            return
        gui = loader.loadModel('models/gui/toplevel_gui')
        GuiButton.genericButton = (gui.find('**/generic_button'), gui.find('**/generic_button_down'), gui.find('**/generic_button_over'), gui.find('**/generic_button_disabled'))
        GuiButton.redGenericButton = (
         gui.find('**/pir_t_gui_but_generic'), gui.find('**/pir_t_gui_but_generic_down'), gui.find('**/pir_t_gui_but_generic_over'), gui.find('**/pir_t_gui_but_generic_disabled'))
        GuiButton.blueGenericButton = (
         gui.find('**/pir_t_gui_but_generic_blue'), gui.find('**/pir_t_gui_but_generic_blue_down'), gui.find('**/pir_t_gui_but_generic_blue_over'), gui.find('**/pir_t_gui_but_generic_blue_disabled'))

    def setupHotkeys(self, hotkeys, hotkeyLabel, command, extraArgs, hotkeyLabelX=0.092, hotkeyArgs=True):
        if self.hotkeys:
            self.ignoreHotkeys()
            self.hotkeyLabel.destroy()
        self.hotkeys = hotkeys
        self.command = command
        self.extraArgs = extraArgs
        self.hotkeyLabel = hotkeyLabel
        self.hotkeyLabelX = hotkeyLabelX
        self.hotkeyArgs = hotkeyArgs
        if self.hotkeys:
            self.hotkeyLabel = DirectLabel(parent=self, relief=None, state=DGG.DISABLED, text=hotkeyLabel, text_font=PiratesGlobals.getPirateBoldOutlineFont(), text_scale=PiratesGuiGlobals.TextScaleMed, text_pos=(hotkeyLabelX, 0.01), text_fg=PiratesGuiGlobals.TextFG2, text_shadow=PiratesGuiGlobals.TextShadow, textMayChange=1)
            self.acceptHotkeys()
        return

    def ignoreHotkeys(self):
        if self.hotkeys:
            for hotkey in self.hotkeys:
                self.ignore(hotkey)

    def acceptHotkeys(self):
        if self.hotkeys:
            for hotkey in self.hotkeys:
                if self.hotkeyArgs:
                    self.accept(hotkey, self.command, self.extraArgs + [hotkey])
                else:
                    self.accept(hotkey, self.command, self.extraArgs)

    def createHelpWatcher(self):
        if self['helpOpaque']:
            self.bind(DGG.ENTER, self.waitShowDetails)
            self.bind(DGG.EXIT, self.hideDetails)
        else:
            w = self.getWidth()
            h = self.getHeight()
            pos = self.__discoverHelpWatcherPos()
            frameSize = self['frameSize'] or self.getBounds()
            self.helpWatcher = DirectFrame(parent=self, relief=base.config.GetBool('show-helpwatchers', 0), state=DGG.NORMAL, frameColor=(1,
                                                                                                                                          1,
                                                                                                                                          0,
                                                                                                                                          0.5), frameSize=frameSize, sortOrder=self['sortOrder'] - 1)
            self.helpWatcher.wrtReparentTo(self.getParent())
            self.reparentTo(self.getParent())
            self.helpWatcher.bind(DGG.WITHIN, self.waitShowDetails)
            self.helpWatcher.bind(DGG.WITHOUT, self.hideDetails)

    def __discoverHelpWatcherPos(self):
        w = self.getWidth()
        h = self.getHeight()
        bounds = self['frameSize'] or self.getBounds()
        pos = Vec3(bounds[0] + w / 2, 0, bounds[2] + h / 2)
        return pos

    def resetHelpWatcher(self):
        if self.helpWatcher:
            self.helpWatcher.setPos(self, 0, 0, 0)

    def createHelpBox(self):
        if not self.helpWatcher:
            self.createHelpWatcher()
        helpLabel = DirectLabel(relief=None, state=DGG.DISABLED, text=self['helpText'], text_align=TextNode.ACenter, text_scale=PiratesGuiGlobals.TextScaleMed, text_fg=PiratesGuiGlobals.TextFG1, text_wordwrap=12, text_shadow=(0,
                                                                                                                                                                                                                                  0,
                                                                                                                                                                                                                                  0,
                                                                                                                                                                                                                                  1), textMayChange=0, sortOrder=91)
        height = helpLabel.getHeight()
        width = helpLabel.getWidth() + 0.05
        if self['helpLeftAlign']:
            fs = [
             0.0, width, -height, 0.045]
            pos = [width / 2.0, 0, -0.01]
        else:
            if self['helpCenterAlign']:
                pos = [
                 0.0, 0.0, -0.01]
                fs = [-(width / 2 + 0.01), width / 2 + 0.01, -(height / 2 + 0.015), height / 2 + 0.015]
            else:
                fs = [
                 0.25 - width, 0.25, -height, 0.045]
                pos = [0.25 - width / 2.0, 0, -0.01]
            self.helpBox = BorderFrame(parent=self, state=DGG.DISABLED, frameSize=(fs[0], fs[1], fs[2], fs[3]), modelName='general_frame_f', pos=self['helpPos'], sortOrder=90)
            helpLabel.reparentTo(self.helpBox)
            helpLabel.setPos(pos[0], pos[1], pos[2])
            self.helpBox.hide()
            self.helpBox.setClipPlaneOff()
            pos = self.helpBox.getPos(aspect2d)
            x = min(pos[0], base.a2dRight - width)
            z = max(pos[2], base.a2dBottom - height)
            self.helpBox.setPos(aspect2d, x, 0, z)
            if self['helpColorOff']:
                self.helpBox.setColorOff()
            else:
                self.helpBox.flattenLight()
            if self['helpBin']:
                self.helpBox.setBin(self['helpBin'], self['helpBinSort'])
        return

    def helpTextUpdated(self):
        if self.helpBox and self.helpBox['text'] != self['helpText']:
            self.helpBox.destroy()
            self.createHelpBox()
        elif self['helpText']:
            self.createHelpBox()

    def setHelpPos(self):
        if self.helpBox:
            self.helpTextUpdated()

    def waitShowDetails(self, event):
        try:
            self['helpDelay']
        except AttributeError:
            return

        if not self.helpBox:
            self.createHelpBox()
        if self['helpDelay']:
            self.hideDetails()
            self.helpTaskName = 'helpInfoTask-%s' % self.getName()
            taskMgr.doMethodLater(self['helpDelay'], self.helpBox.show, self.helpTaskName, extraArgs=[])
        else:
            self.helpBox.show()

    def hideDetails(self, event=None):
        if self.helpTaskName:
            taskMgr.remove(self.helpTaskName)
        if self.helpBox and not self.helpBox.isEmpty():
            self.helpBox.hide()

    def setImage(self):
        DirectButton.setImage(self)
        if not self['baseImage']:
            self['baseImage'] = self['image']

    def setSelected(self):
        if self['selected']:
            self['image'] = self['selectedImage']
        else:
            self['image'] = self['baseImage']

    def setPos(self, *args, **kw):
        DirectButton.setPos(self, *args, **kw)

    def setX(self, *args, **kw):
        DirectButton.setX(self, *args, **kw)

    def setY(self, *args, **kw):
        DirectButton.setY(self, *args, **kw)

    def setZ(self, *args, **kw):
        DirectButton.setZ(self, *args, **kw)

    def setState(self):
        DirectButton.setState(self)
        if self.helpWatcher:
            self.helpWatcher['state'] = self['state']

    def removeNode(self):
        DirectButton.removeNode(self)
        if self.helpWatcher:
            self.helpWatcher.removeNode()

    def remove(self):
        DirectButton.remove(self)
        if self.helpWatcher:
            self.helpWatcher.remove()

    def detachNode(self):
        DirectButton.detachNode(self)
        if self.helpWatcher:
            self.helpWatcher.detachNode()

    def hide(self):
        DirectButton.hide(self)
        if self.helpWatcher:
            self.helpWatcher.hide()

    def show(self):
        DirectButton.show(self)
        if self.helpWatcher:
            self.helpWatcher.show()

    def stash(self):
        DirectButton.stash(self)
        if self.helpWatcher:
            self.helpWatcher.stash()

    def unstash(self):
        DirectButton.unstash(self)
        self.reparentTo(self.getParent(), sort=self['sortOrder'])
        if self.helpWatcher:
            self.helpWatcher.unstash()
            self.helpWatcher.reparentTo(self.helpWatcher.getParent(), sort=self.helpWatcher['sortOrder'])
예제 #10
0
 def hide(self, *args):
     BorderFrame.hide(self)
     if self.showTask:
         taskMgr.remove(self.showTask)
         self.showTask = None
예제 #11
0
 def hide(self, *args):
     BorderFrame.hide(self)
     if self.showTask:
         taskMgr.remove(self.showTask)
         self.showTask = None
예제 #12
0
class Dart(PickableModel):
    def __init__(self,
                 name,
                 parent,
                 defaultPos,
                 color=Vec4(1),
                 offset=0.0,
                 *args,
                 **kwargs):
        self.startScale = 0.074999999999999997
        self.highlightScale = 0.10000000000000001
        PickableModel.__init__(self,
                               name,
                               modelName='icon_objective_grey',
                               scale=self.startScale,
                               collisionIndex=17,
                               modelPath='models/gui/compass_main',
                               *args,
                               **args)
        self.defaultPos = defaultPos
        self.edgeMode = False
        self.helpBox = None
        self.helpLabel = None
        self.normalModeNode = self.attachNewNode('normal')
        self.normalModeNode.setColorScale(color)
        self.normalModeNode.setY(-(offset + 0.0074999999999999997))
        self.geom.instanceTo(self.normalModeNode)
        self.colNode = self.normalModeNode.attachNewNode(
            CollisionNode('cNode'))
        self.colNode.node().addSolid(CollisionSphere(Point3(0, 0, 0), 0.25))
        self.colNode.setScale(1 / 20.0)
        self.colNode.node().setFromCollideMask(BitMask32.allOff())
        self.colNode.node().setIntoCollideMask(BitMask32.bit(17))
        self.setTag('dart', name)
        self.setPos(self.defaultPos)
        self.createHelpBox()
        questId = localAvatar.activeQuestId
        qs = localAvatar.getQuestById(questId)
        if qs:
            title = qs.getStatusText()
            self.setHelpLabel(title)

    def toggleHelpText(self):
        if self.helpBox:
            if not self.helpBox.isHidden():
                self.hideDetails()

    def createHelpBox(self):
        if not self.helpBox:
            self.helpLabel = DirectLabel(
                parent=aspect2d,
                relief=None,
                text='',
                text_align=TextNode.ALeft,
                text_scale=PiratesGuiGlobals.TextScaleSmall,
                text_fg=PiratesGuiGlobals.TextFG2,
                text_wordwrap=12,
                text_shadow=(0, 0, 0, 1),
                textMayChange=1,
                sortOrder=91)
            height = -(self.helpLabel.getHeight() + 0.01)
            width = max(0.25, self.helpLabel.getWidth() + 0.040000000000000001)
            self.helpBox = BorderFrame(parent=aspect2d,
                                       state=DGG.DISABLED,
                                       frameSize=(-0.040000000000000001, width,
                                                  height,
                                                  0.050000000000000003),
                                       pos=(0, 0, 0),
                                       sortOrder=90)
            self.helpLabel.reparentTo(self.helpBox)
            self.helpBox.hide()

    def setHelpLabel(self, text):
        self.helpLabel['text'] = text
        self.helpLabel.resetFrameSize()
        height = -(self.helpLabel.getHeight() + 0.01)
        width = max(0.25, self.helpLabel.getWidth() + 0.040000000000000001)
        self.helpBox['frameSize'] = (-0.040000000000000001, width, height,
                                     0.050000000000000003)
        self.helpBox.resetFrameSize()

    def showDetails(self, pos):
        if self.helpLabel['text'] != '':
            self.helpBox.setPos(pos +
                                Point3(self.helpBox['frameSize'][1] *
                                       0.25, 0, 0))
            self.helpBox.setBin('gui-popup', 0)
            self.helpBox.show()
            self.geom.setScale(self.highlightScale)

    def hideDetails(self):
        if self.helpBox:
            self.helpBox.hide()
            self.geom.setScale(self.startScale)

    def mouseOver(self, pos):
        self.showDetails(pos)

    def mouseLeft(self):
        self.hideDetails()

    def getDefaultPos(self):
        return self.defaultPos

    def setEdgeMode(self, edgeMode):
        self.edgeMode = edgeMode
        if self.edgeMode:
            self.edgeModeNode.unstash()
        else:
            self.edgeModeNode.stash()

    def setColorScale(self, *args, **kwargs):
        self.edgeModeNode.setColorScale(*args, **args)
        self.normalModeNode.setColorScale(*args, **args)

    def setScale(self, *args, **kwargs):
        self.normalModeNode.setScale(*args, **args)

    def setPosition(self, worldPos, *args, **kwargs):
        NodePath.setPos(self, *args, **args)
        if self.edgeMode:
            self.edgeModeNode.setPos(*args, **args)