Exemple #1
0
	def __init__(self, name):
		beastNodePath.__init__(self, PGButton(name))
		beastSpriteOptions.__init__(self)
		DirectObject.__init__(self)
		self.setPythonTag('beastEntry', self)
		self.states = {}
		self.__focus = False
		self.getState('default') #- Install a default sprite
		self.__lastState = 'default'
		b = beast
		for ev in (b.enter, b.exit, b.within, b.without, b.leftPress, b.centerPress, b.rightPress, b.leftClick, b.centerClick, b.rightClick, b.leftRelease, b.centerRelease, b.rightRelease, b.wheelUp, b.wheelDown):
			self.bind(ev, self.__foo)
		self.setSuppressKeys(True)
		self.getCurrentState().getTextNode().setMaxRows(9)
		self.accept('keystroke-'+self.node().getId(), self.__keystroke)
    def __init__(self, name):
        beastNodePath.__init__(self, PGButton(name))
        beastSpriteOptions.__init__(self)
        DirectObject.__init__(self)
        self.setPythonTag('beastButton', self)
        self.states = {}
        self.getState('default')  #- Install a default sprite
        self.__lastState = 'default'
        #	taskMgr.add(self.__checkStateTask, '%s-checkStateTask' % hex(id(self)))

        b = beast
        for ev in (b.enter, b.exit, b.within, b.without, b.leftPress,
                   b.centerPress, b.rightPress, b.leftClick, b.centerClick,
                   b.rightClick, b.leftRelease, b.centerRelease,
                   b.rightRelease, b.wheelUp, b.wheelDown):
            self.bind(ev, self.__foo)
from direct.gui.DirectFrame import DirectFrame
from direct.gui.DirectEntry import DirectEntry
from direct.gui.DirectScrolledFrame import DirectScrolledFrame
from direct.gui.DirectButton import DirectButton
from direct.gui.DirectLabel import DirectLabel
from panda3d.core import (
    LPoint3f,
    LVecBase3f,
    LVecBase4f,
    TransparencyAttrib,
    TextNode
)


from panda3d.core import PGButton, MouseButton
DGG.MWUP = PGButton.getPressPrefix() + MouseButton.wheel_up().getName() + '-'
DGG.MWDOWN = PGButton.getPressPrefix() + MouseButton.wheel_down().getName() + '-'

class DirectFolderBrowser(DirectObject):
    def __init__(self, command, fileBrowser=False, defaultPath="~", defaultFilename="unnamed.txt", fileExtensions=[], tooltip=None):
        """
        A simple file and folder browser

        command: The command that will be called on closing the browser
        fileBrowser: If set to True the browser will show files, otherwise it will only show folders
        defaultPath: The initial path the browser will be set to show
        defaultFilename: The filename that will be set by default, only usefull if fileBrowser is True
        fileExtensions: A list of extensions. Only files with those extensions will be shown. Only usefull if fileBrowser is True
        tooltip: An instance of the Tooltip class to display tooltips for certain parts of the editor
        """
        self.tt = tooltip
Exemple #4
0
from direct.stdpy.file import open, exists
from direct.stdpy import pickle
import direct.gui.DirectGuiGlobals as DGG
from direct.gui.OnscreenText import OnscreenText
from direct.gui.DirectFrame import DirectFrame
from direct.gui.DirectButton import DirectButton
from direct.gui.DirectScrolledFrame import DirectScrolledFrame

from runtime_data import game_settings
from sogal_form import SogalForm, SogalDialog
from gui.layout import HLayout, VLayout
import gui.color_themes as color_themes
from sogal_form import ConfirmDialog
import runtime_data

WHEELUP = PGButton.getReleasePrefix() + MouseButton.wheelUp().getName() + '-'
WHEELDOWN = PGButton.getReleasePrefix() + MouseButton.wheelDown().getName(
) + '-'
WHEELLEFT = PGButton.getReleasePrefix() + MouseButton.wheelLeft().getName(
) + '-'
WHEELRIGHT = PGButton.getReleasePrefix() + MouseButton.wheelRight().getName(
) + '-'

#pos = (-0.57,0,0.67)
MAX_SAVE = 200
hspacing = 1.33
vspacing = 0.4
FRAMESIZE = (-1.35, 1.35, -0.95, 0.95)
LOAD_CANVAS_SIZE = (
    -0.05, 2.55,
    math.ceil(
Exemple #5
0
class DialogMask(DirectButton):
    '''used to generate a full-screen mask to prevent button-clicking below the focused window/dialog
    Added some tricks to make panda3d mouse events still available
    '''
    B1PRESS = PGButton.getPressPrefix() + MouseButton.one().getName() + '-'
    B2PRESS = PGButton.getPressPrefix() + MouseButton.two().getName() + '-'
    B3PRESS = PGButton.getPressPrefix() + MouseButton.three().getName() + '-'
    B4PRESS = PGButton.getPressPrefix() + MouseButton.four().getName() + '-'
    B5PRESS = PGButton.getPressPrefix() + MouseButton.five().getName() + '-'
    WHEELUP = PGButton.getReleasePrefix() + MouseButton.wheelUp().getName(
    ) + '-'
    WHEELDOWN = PGButton.getReleasePrefix() + MouseButton.wheelDown().getName(
    ) + '-'
    WHEELLEFT = PGButton.getReleasePrefix() + MouseButton.wheelLeft().getName(
    ) + '-'
    WHEELRIGHT = PGButton.getReleasePrefix() + MouseButton.wheelRight(
    ).getName() + '-'
    B1RELEASE = PGButton.getReleasePrefix() + MouseButton.one().getName() + '-'
    B2RELEASE = PGButton.getReleasePrefix() + MouseButton.two().getName() + '-'
    B3RELEASE = PGButton.getReleasePrefix() + MouseButton.three().getName(
    ) + '-'
    B4RELEASE = PGButton.getReleasePrefix() + MouseButton.four().getName(
    ) + '-'
    B5RELEASE = PGButton.getReleasePrefix() + MouseButton.five().getName(
    ) + '-'

    def __init__(self):
        DirectButton.__init__(self,
                              parent=aspect2d,
                              frameColor=(1, 1, 1, 0),
                              relief=DGG.FLAT,
                              commandButtons=[])
        self.accept('window-event', self.windowResize)
        self.windowResize(None)
        #trick: make this re-throw mouse events
        self.bind(self.B1PRESS, self.rethrowEvent, ['mouse1'])
        self.bind(self.B2PRESS, self.rethrowEvent, ['mouse2'])
        self.bind(self.B3PRESS, self.rethrowEvent, ['mouse3'])
        self.bind(self.B4PRESS, self.rethrowEvent, ['mouse4'])
        self.bind(self.B5PRESS, self.rethrowEvent, ['mouse5'])

        self.bind(self.WHEELUP, self.rethrowEvent, ['wheel_up'])
        self.bind(self.WHEELDOWN, self.rethrowEvent, ['wheel_down'])
        self.bind(self.WHEELLEFT, self.rethrowEvent, ['wheel_left'])
        self.bind(self.WHEELRIGHT, self.rethrowEvent, ['wheel_right'])

        self.bind(self.B1RELEASE, self.rethrowEvent, ['mouse1-up'])
        self.bind(self.B2RELEASE, self.rethrowEvent, ['mouse2-up'])
        self.bind(self.B3RELEASE, self.rethrowEvent, ['mouse3-up'])
        self.bind(self.B4RELEASE, self.rethrowEvent, ['mouse4-up'])
        self.bind(self.B5RELEASE, self.rethrowEvent, ['mouse5-up'])

    def windowResize(self, arg):
        #fill the screen
        aspect = base.getAspectRatio()
        if aspect > 1:
            self['frameSize'] = (-aspect, aspect, -1, 1)
        elif aspect:
            hh = 1.0 / aspect
            self['frameSize'] = (-1, 1, -hh, hh)

    def setCommandButtons(self, *args, **kwargs):
        #inherited
        pass

    def rethrowEvent(self, sevent, event):
        messenger.send(sevent)

    def destroy(self):
        self.ignoreAll()
        DirectButton.destroy(self)
Exemple #6
0
class _beastGlobals(DirectObject):
    enter = PGButton.getEnterPrefix()
    exit = PGButton.getExitPrefix()
    within = PGButton.getWithinPrefix()
    without = PGButton.getWithoutPrefix()
    leftPress = PGButton.getPressPrefix() + MouseButton.one().getName() + '-'
    centerPress = PGButton.getPressPrefix() + MouseButton.two().getName() + '-'
    rightPress = PGButton.getPressPrefix() + MouseButton.three().getName(
    ) + '-'
    leftClick = PGButton.getClickPrefix() + MouseButton.one().getName() + '-'
    centerClick = PGButton.getClickPrefix() + MouseButton.two().getName() + '-'
    rightClick = PGButton.getClickPrefix() + MouseButton.three().getName(
    ) + '-'
    leftRelease = PGButton.getReleasePrefix() + MouseButton.one().getName(
    ) + '-'
    centerRelease = PGButton.getReleasePrefix() + MouseButton.two().getName(
    ) + '-'
    rightRelease = PGButton.getReleasePrefix() + MouseButton.three().getName(
    ) + '-'
    wheelUp = PGButton.getPressPrefix() + MouseButton.wheelUp().getName() + '-'
    wheelDown = PGButton.getPressPrefix() + MouseButton.wheelDown().getName(
    ) + '-'

    def __init__(self, taskMgr, base):
        DirectObject.__init__(self)
        self.taskMgr = taskMgr
        self.base = base
        self.setupPoint2d()

        self.beastPointSize = ConfigVariableDouble('beast-point-size',
                                                   1.0).getValue()
        self.beastPointSizeAuto = ConfigVariableBool('beast-point-size-auto',
                                                     False).getValue()
        self.beastRenderBruteForce = ConfigVariableBool(
            'beast-render-brute-force', False).getValue()
        self.beastRenderDebug = ConfigVariableBool('beast-render-debug',
                                                   False).getValue()

        self.setPointSize(self.beastPointSize, update=False)
        self.setPointSizeAuto(self.beastPointSizeAuto, update=False)
        self.accept('window-event', self.windowEvent)
        self.originalResolution = (float(self.base.win.getXSize()),
                                   float(self.base.win.getYSize()))

        self.buffer = None
        #- If bruteForce == False then we will setup beast frame rendering system
        if self.beastRenderBruteForce == False:
            self._setupTextureBuffer()
            taskMgr.add(self.renderTask, 'beastRender', sort=-100000000)

        self.windowEvent()

    def _setupTextureBuffer(self):
        if self.buffer:
            self.card.remove()
            self.camera2d.remove()
            self.base.graphicsEngine.removeWindow(self.buffer)

        self.buffer = self.base.win.makeTextureBuffer("beastBuffer",
                                                      self.base.win.getXSize(),
                                                      self.base.win.getYSize())
        self.buffer.setActive(True)
        self.buffer.getTexture().setOrigFileSize(self.base.win.getXSize(),
                                                 self.base.win.getYSize())

        self.camera2d = self.base.makeCamera2d(self.buffer)
        self.camera2d.reparentTo(self.point2d.getParent())

        cm = CardMaker('beastDisplay')
        cm.setFrame(-1, 1, -1, 1)
        cm.setUvRange(self.buffer.getTexture())
        self.card = self.base.render2d.attachNewNode(cm.generate())
        self.card.setTransparency(TransparencyAttrib.MAlpha)
        self.card.setTexture(self.buffer.getTexture())

    def renderTask(self, task):
        if self.point2d.getRequiresUpdate():
            debug = self.beastRenderBruteForce == False and self.beastRenderDebug == True
            if debug:
                print ':beast::render'
            self.buffer.setActive(True)
            self.point2d.setRequiresUpdate(False)
        else:
            self.buffer.setActive(False)
        return task.cont

    def setupPoint2d(self):
        fakeRender2d = NodePath('render2d')
        fakeRender2d.setDepthTest(False)
        fakeRender2d.setDepthWrite(False)
        fakeRender2d.setMaterialOff(True)
        fakeRender2d.setTwoSided(True)

        self.point2d = beastNodePath(PGTop('point2d'))
        self.point2d.reparentTo(fakeRender2d)
        self.point2d.node().setMouseWatcher(self.base.mouseWatcherNode)

        self.p2dTopLeft = self.point2d.attachNewNode('p2dTopLeft')
        self.p2dTopRight = self.point2d.attachNewNode('p2dTopRight')
        self.p2dTopCenter = self.point2d.attachNewNode('p2dTopCenter')

        self.p2dCenterLeft = self.point2d.attachNewNode('p2dCenterLeft')
        self.p2dCenterRight = self.point2d.attachNewNode('p2dCenterRight')

        self.p2dBottomLeft = self.point2d.attachNewNode('p2dBottomLeft')
        self.p2dBottomRight = self.point2d.attachNewNode('p2dBottomRight')
        self.p2dBottomCenter = self.point2d.attachNewNode('p2dBottomCenter')

    def getMousePos(self):
        md = self.win.getPointer(0)
        x = md.getX()
        y = md.getY()
        p = self.point2d.getRelativePoint(self.pixel2d, (x, 0, -y))
        return p.getX(), p.getZ()

    def hasMouse(self):
        return self.mouseWatcherNode.hasMouse()

    def getAbsolutePointSize(self):
        fakePointSize = None
        if self.getPointSizeAuto():
            oldX, oldY = self.originalResolution
            newX, newY = float(self.win.getXSize()), float(self.win.getYSize())
            ratio = newY / oldY
            fakePointSize = ratio

        if self.getPointSizeAuto():
            ps = fakePointSize
        else:
            ps = self.getPointSize()
        return ps

    def windowEvent(self, win=None):
        ps = self.getAbsolutePointSize()
        x = self.base.win.getXSize()
        y = self.base.win.getYSize()

        xActual = (x / ps)
        yActual = (y / ps)
        self.point2d.setScale(2.0 / xActual, 1.0, 2.0 / yActual)

        #- Finish actuals
        self.p2dTopLeft.setPos(-xActual / 2.0, 1.0, yActual / 2.0)
        self.p2dTopRight.setPos(xActual / 2.0, 1.0, yActual / 2.0)
        self.p2dTopCenter.setPos(0, 1.0, yActual / 2.0)

        self.p2dCenterLeft.setPos(-xActual / 2.0, 1.0, 0.0)
        self.p2dCenterRight.setPos(xActual / 2.0, 1.0, 0.0)

        self.p2dBottomLeft.setPos(-xActual / 2.0, 1.0, -yActual / 2.0)
        self.p2dBottomRight.setPos(xActual / 2.0, 1.0, -yActual / 2.0)
        self.p2dBottomCenter.setPos(0, 1.0, -yActual / 2.0)

        if self.beastRenderBruteForce == False:
            debug = self.beastRenderBruteForce == False and self.beastRenderDebug == True
            bx = self.buffer.getTexture().getOrigFileXSize()
            by = self.buffer.getTexture().getOrigFileYSize()
            cx = self.base.win.getXSize()
            cy = self.base.win.getYSize()
            if bx != cx or by != by:
                if debug:
                    print ':beast::render::resolutionChanged from(%s, %s) to(%s, %s)' % (
                        bx, by, cx, cy)
                self._setupTextureBuffer()
        messenger.send('beast.windowEvent')

    ''' Point size '''

    def getPointSize(self):
        return self.pointSize

    def setPointSize(self, value, update=True):
        self.pointSize = float(value)
        if update:
            self.update()

    ''' Point size auto resolution '''

    def setPSAutoResolution(self, x, y):
        self.originalResolution = (float(base.win.getXSize()),
                                   float(base.win.getYSize()))

    def getPSAutoResolution(self):
        return self.originalResolution

    ''' Point size auto '''

    def setPointSizeAuto(self, value, update=True):
        self.pointSizeAuto = bool(value)
        if update:
            self.update()

    def getPointSizeAuto(self):
        return self.pointSizeAuto

    def togglePointSizeAuto(self):
        if self.getPointSizeAuto():
            self.setPointSizeAuto(False)
        else:
            self.setPointSizeAuto(True)

    ''' Data folder '''

    def getDataFolder(self):
        if sys.platform.startswith('win'):
            slash = '\\'
        else:
            slash = '/'
        point = __file__.rindex(slash)
        f = __file__[:point] + slash + 'data' + slash
        return Filename().fromOsSpecific(f).getFullpath()

    ''' Destroy beast now '''

    def destroy(self):
        self.ignoreAll()
Exemple #7
0
from direct.stdpy import pickle
import direct.gui.DirectGuiGlobals as DGG
from direct.gui.OnscreenText import OnscreenText
from direct.gui.DirectFrame import DirectFrame
from direct.gui.DirectButton import DirectButton
from direct.gui.DirectScrolledFrame import DirectScrolledFrame


from runtime_data import game_settings
from sogal_form import SogalForm,SogalDialog
from gui.layout import HLayout,VLayout
import gui.color_themes as color_themes
from sogal_form import ConfirmDialog
import runtime_data

WHEELUP = PGButton.getReleasePrefix() + MouseButton.wheelUp().getName() + '-'
WHEELDOWN = PGButton.getReleasePrefix() + MouseButton.wheelDown().getName() + '-'
WHEELLEFT = PGButton.getReleasePrefix() + MouseButton.wheelLeft().getName() + '-'
WHEELRIGHT = PGButton.getReleasePrefix() + MouseButton.wheelRight().getName() + '-'

#pos = (-0.57,0,0.67)
MAX_SAVE = 200
hspacing = 1.33
vspacing = 0.4
FRAMESIZE = (-1.35,1.35,-0.95,0.95)
LOAD_CANVAS_SIZE = (-0.05,2.55,math.ceil( -vspacing*(MAX_SAVE +runtime_data.MAX_AUTOSAVE + runtime_data.MAX_QUICKSAVE)/2.0 ) ,vspacing/2)
SAVE_CANVAS_SIZE = (-0.05,2.55,math.ceil(-vspacing*MAX_SAVE/2.0) ,vspacing/2)
LOAD_ROLL_SPEED = -LOAD_CANVAS_SIZE[2]/5100.0
SAVE_ROLL_SPEED = -SAVE_CANVAS_SIZE[2]/5100.0
AUTO_HIDE_SCROLLBARS = True