def __init__(self, inputWatcher, window, defaultKeys = []): ''' Creates a new ControlScheme object. @param inputWatcher: The MouseWatcher object to use for tracking the mouse and keys. @param defaultKeys: is a collection of key types to be initialized by default (optional). Acceptable values are "left", "right", "up", "down", and "pause". The defaults for directional keys are the arrows, WASD, and the equivalents of WASD on common alternate keyboard layouts. The keys for "pause" are escape, p, and enter. ''' self.inputWatcher = inputWatcher self.window = window properties = window.getProperties() self.centerX = properties.getXSize() // 2 self.centerY = properties.getYSize() // 2 self.prevMouseX = self.centerX self.keyMap = dict() self.addKeys(LEFT, [KeyboardButton.left(), KeyboardButton.asciiKey('a'), KeyboardButton.asciiKey('q')]) self.addKeys(RIGHT, [KeyboardButton.right(), KeyboardButton.asciiKey('d'), KeyboardButton.asciiKey('e')]) self.addKeys(UP, [KeyboardButton.up(), KeyboardButton.asciiKey('w'), KeyboardButton.asciiKey('z'), KeyboardButton.asciiKey(',')]) self.addKeys(DOWN, [KeyboardButton.down(), KeyboardButton.asciiKey('s'), KeyboardButton.asciiKey('o')]) self.addKeys(PAUSE, [KeyboardButton.escape(), KeyboardButton.asciiKey('p'), KeyboardButton.enter()]) self.addKeys(SWITCH, [KeyboardButton.shift(), KeyboardButton.control(), KeyboardButton.asciiKey('f'), KeyboardButton.asciiKey('/'), MouseButton.two(), KeyboardButton.space()]) self.addKeys(PUSH, [MouseButton.one()]) self.addKeys(PULL, [MouseButton.three()]) self.addKeys(QUIT, [KeyboardButton.asciiKey('q')]) #in case the mouse leaves the window self.mouseX = 0 self.mouseY = 0
def finish(self, pos=(0, 0, 0), minWidth=1): """ adjust frame for uniform width with siblings adjust pos relative to parent or older sibs attach stateGraphics """ me = self.getPythonTag("extras") item = me.item scale = me.style['font-size'] kind = item['kind'] width, height, lineHeight, fram = getTextSize(item['txt'], me.style) width = max(width, minWidth) arrowhead = .5 * lineHeight padding = me.style['padding'] padding = (padding[0] * scale, padding[1] * scale, padding[2] * scale, padding[3] * scale) bevel = me.style['bevel'] * scale multiLineShim = 0 if '\n' in item['txt']: multiLineShim = .04 # might need to change this to fit font NodePath(self).setPos(pos) if kind == 'separator': sh = me.style['height'] * scale frame = (-padding[0], width + padding[1], -sh / 2, sh / 2) else: frame = (fram[0], max(fram[1], fram[0] + minWidth), fram[2], fram[3]) frame = (frame[0] - padding[0], frame[1] + padding[1], frame[2] - padding[2] - multiLineShim, frame[3] + padding[3]) stateGraphics = getBackgroundSet(self, frame, arrowhead) for state in STATES: self.clearStateDef(state) # in case we've been here befor self.instanceToStateDef(state, stateGraphics[state]) DO = DirectObject() if not self.clickAccepted: #JUSTIN'S INSERTED CODE DO.accept(self.getEnterEvent(), onEnter, [me.menuRoot.menuRootID, self]) DO.accept(self.getExitEvent(), onLeave, [me.menuRoot.menuRootID, self]) if kind in ('button', 'checkBox', 'radioBTN', 'checkAllBTN', 'unCheckAllBTN', 'titleBar', 'close'): if not self.clickAccepted: #JUSTIN'S INSERTED CODE DO.accept(self.getPressEvent(MouseButton.one()), onPress, [self]) DO.accept(self.getReleaseEvent(MouseButton.one()), onRelease, [self]) # so we can simulate 'click' with messenger.send('press'+id, ['simClk']): DO.accept('press' + item['id'], onPress, [self]) if not self.clickAccepted: #JUSTIN'S INSERTED CODE self.clickAccepted = True self.setActive(True) if kind == 'parent': # accomodate arrowheads self.setFrame(frame[0], frame[1] + arrowhead * 2 - bevel, frame[2], frame[3]) else: self.setFrame(frame)
def finish(self, pos=(0,0,0), minWidth=1): """ adjust frame for uniform width with siblings adjust pos relative to parent or older sibs attach stateGraphics """ me = self.getPythonTag("extras") item = me.item scale = me.style['font-size'] kind=item['kind'] width, height, lineHeight, fram = getTextSize(item['txt'], me.style) width = max(width,minWidth) arrowhead=.5*lineHeight padding = me.style['padding'] padding = (padding[0]*scale ,padding[1]*scale ,padding[2]*scale ,padding[3]*scale ) bevel = me.style['bevel']*scale multiLineShim = 0 if '\n' in item['txt']: multiLineShim = .04 # might need to change this to fit font NodePath(self).setPos(pos) if kind=='separator': sh = me.style['height']*scale frame=( -padding[0], width+padding[1], -sh/2, sh/2) else: frame = (fram[0],max(fram[1],fram[0]+minWidth),fram[2],fram[3]) frame=( frame[0]-padding[0], frame[1]+padding[1], frame[2]-padding[2]-multiLineShim, frame[3]+padding[3]) stateGraphics = getBackgroundSet(self, frame, arrowhead) for state in STATES: self.clearStateDef(state) # in case we've been here befor self.instanceToStateDef(state, stateGraphics[state]) DO=DirectObject() if not self.clickAccepted: #JUSTIN'S INSERTED CODE DO.accept(self.getEnterEvent(), onEnter, [me.menuRoot.menuRootID, self]) DO.accept(self.getExitEvent(), onLeave, [me.menuRoot.menuRootID, self]) if kind in ('button', 'checkBox', 'radioBTN', 'checkAllBTN', 'unCheckAllBTN', 'titleBar', 'close'): if not self.clickAccepted: #JUSTIN'S INSERTED CODE DO.accept(self.getPressEvent(MouseButton.one()), onPress, [self]) DO.accept(self.getReleaseEvent(MouseButton.one()), onRelease, [self]) # so we can simulate 'click' with messenger.send('press'+id, ['simClk']): DO.accept('press'+item['id'], onPress, [self]) if not self.clickAccepted: #JUSTIN'S INSERTED CODE self.clickAccepted=True self.setActive(True) if kind == 'parent':# accomodate arrowheads self.setFrame(frame[0], frame[1]+arrowhead*2-bevel, frame[2], frame[3]) else: self.setFrame(frame)
def enterGame(self): RepairMincroGame.enterGame(self) self.lastCompleteCount = 0 taskMgr.add(self.updateTask, 'RepairCareeningGame.updateTask') self.accept('mouse1', self.onMouseDown) self.accept('mouse1-up', self.onMouseUp) if base.mouseWatcherNode.hasMouse() and base.mouseWatcherNode.isButtonDown(MouseButton.one()): self.onMouseDown()
def enterGame(self): RepairMincroGame.enterGame(self) self.lastCompleteCount = 0 taskMgr.add(self.updateTask, 'RepairCareeningGame.updateTask-%d' % id(self)) self.accept('mouse1', self.onMouseDown) self.accept('mouse1-up', self.onMouseUp) if base.mouseWatcherNode.hasMouse() and base.mouseWatcherNode.isButtonDown(MouseButton.one()): self.onMouseDown()
def exitHookedFighting(self): self.fish.stopFightBubbleEffect() self.fish.fishStatusIconNodePath.hide() taskMgr.remove('%s_StopFighting' % self.fish.getName()) if self.getCurrentOrNextState() not in ['Offscreen', 'Flee']: if base.mouseWatcherNode.isButtonDown(MouseButton.one()): self.fish.fishManager.gameObject.fsm.request('ReelingFish') else: self.fish.fishManager.gameObject.fsm.request('FishOnHook')
def exitHookedFighting(self): self.fish.stopFightBubbleEffect() self.fish.fishStatusIconNodePath.hide() taskMgr.remove('%s_StopFighting' % self.fish.getName()) if self.getCurrentOrNextState() not in [ 'Offscreen', 'Flee']: if base.mouseWatcherNode.isButtonDown(MouseButton.one()): self.fish.fishManager.gameObject.fsm.request('ReelingFish') else: self.fish.fishManager.gameObject.fsm.request('FishOnHook')
def __init__(self, parent, **kw): optiondefs = (('clickDownCommand', None, None), ('clickUpCommand', None, None)) self.defineoptions(kw, optiondefs) DirectButton.__init__(self, parent) self.initialiseoptions(RepairSaw) self.sawingGame = parent self._initVars() self._initGUI() self._initIntervals() self.accept(self.guiItem.getEnterEvent(), self.onMouseEnter) self.accept(self.guiItem.getExitEvent(), self.onMouseExit) self.guiItem.addClickButton(MouseButton.one()) self.bind(DGG.B1PRESS, self.onMouseDown) self.bind(DGG.B1RELEASE, self.onMouseUp)
def __init__(self, parent, **kw): optiondefs = (('clickDownCommand', None, None), ('clickUpCommand', None, None)) self.defineoptions(kw, optiondefs) DirectButton.__init__(self, parent, **kw) self.initialiseoptions(RepairSaw) self.sawingGame = parent self._initVars() self._initGUI() self._initIntervals() self.accept(self.guiItem.getEnterEvent(), self.onMouseEnter) self.accept(self.guiItem.getExitEvent(), self.onMouseExit) self.guiItem.addClickButton(MouseButton.one()) self.bind(DGG.B1PRESS, self.onMouseDown) self.bind(DGG.B1RELEASE, self.onMouseUp) return
def getBackgroundSet(menuItem, frame, arrowhead): item = menuItem.item kind = item['kind'] txt = item['txt'] grphcs = [] slctrs = ['menu ' + kind] if 'class' in item: # class after kind: class has higher priority slctrs.append('.' + item['class']) if 'id' in item: # id after class: id has higher priority slctrs.append('#' + item['id']) style = getStyle(slctrs, menuItem.cssFName) if 'enter-sound' in style: loadSound(menuItem, menuItem.getEnterEvent(), style, 'enter-sound') if 'exit-sound' in style: loadSound(menuItem, menuItem.getExitEvent(), style, 'exit-sound') if 'press-sound' in style: loadSound(menuItem, menuItem.getPressEvent(MouseButton.one()), style, 'press-sound') if 'release-sound' in style: loadSound(menuItem, menuItem.getReleaseEvent(MouseButton.one()), style, 'release-sound') if 'drag-sound' in style: loadSound(menuItem, None, style, 'drag-sound') for state in STATES: slctrs = ['menu ' + kind + ' :' + stateName[state].lower()] if 'class' in item: # class after kind: class has higher priority slctrs.append('.' + item['class'] + ' :' + stateName[state].lower()) if 'id' in item: # id after class: id has higher priority slctrs.append('#' + item['id'] + ' :' + stateName[state].lower()) style = getStyle(slctrs, menuItem.cssFName) # Want to add more style properties? # Do it here: # Match style keys here to property names in .ccss fontSize = style['font-size'] bevel = style['bevel'] * fontSize font = style['font'] color = style['color'] tn = TextNode(txt) tn.setText(txt) tn.setFont(loader.loadFont(font)) tn.setSlant(style['slant']) tn.setTextColor(color) tn.setShadow(*style['shadow-offset']) tn.setShadowColor(*style['shadow-color']) NodePath(tn).setScale(fontSize) sHolder = NodePath(PandaNode('sHolder')) sHolder.attachNewNode(tn) grphcs.append(sHolder) sHolder.attachNewNode(tn) borderColor = style['border-Color'] thk = style['border-thickness'] if 'background-Color' in style and\ style['background-Color'] != 'transparent': bgColor = style['background-Color'] else: bgColor = None if kind == 'parent': if state == HOVER: ar = arrowhead * 2 else: ar = arrowhead grphcs[state].attachNewNode( bevelArrow(frame, bevel, ar, thk, color, borderColor, bgColor)) elif kind in ('horizontal', 'titleBar', 'close'): grphcs[state].attachNewNode( rectangle(frame, thk, color, borderColor, bgColor)) elif kind == 'checkBox': grphcs[state].attachNewNode( checkBox(frame, bevel, thk, color, borderColor, bgColor)) cb = grphcs[state].attachNewNode( checkedBox(frame, bevel, thk, color, borderColor, bgColor)) cb.hide() elif kind == 'radioBTN': grphcs[state].attachNewNode( radioBTN(frame, bevel, thk, color, borderColor, bgColor)) cb = grphcs[state].attachNewNode( checkedRadioBTN(frame, bevel, thk, color, borderColor, bgColor)) cb.hide() else: grphcs[state].attachNewNode( bevelBG(frame, bevel, thk, borderColor, bgColor)) return grphcs
def getBackgroundSet(menuItem, frame, arrowhead): item = menuItem.item kind = item['kind'] txt = item['txt'] grphcs = [] slctrs = ['menu '+kind] if 'class' in item: # class after kind: class has higher priority slctrs.append('.'+item['class']) if 'id' in item: # id after class: id has higher priority slctrs.append('#'+item['id']) style = getStyle(slctrs, menuItem.cssFName) if 'enter-sound' in style: loadSound(menuItem, menuItem.getEnterEvent(), style, 'enter-sound') if 'exit-sound' in style: loadSound(menuItem, menuItem.getExitEvent(), style, 'exit-sound') if 'press-sound' in style: loadSound(menuItem, menuItem.getPressEvent(MouseButton.one()), style, 'press-sound') if 'release-sound' in style: loadSound(menuItem, menuItem.getReleaseEvent(MouseButton.one()), style, 'release-sound') if 'drag-sound' in style: loadSound(menuItem, None, style, 'drag-sound') for state in STATES: slctrs = ['menu '+kind+' :'+stateName[state].lower()] if 'class' in item: # class after kind: class has higher priority slctrs.append('.'+item['class']+' :'+stateName[state].lower()) if 'id' in item: # id after class: id has higher priority slctrs.append('#'+item['id']+' :'+stateName[state].lower()) style = getStyle(slctrs, menuItem.cssFName) # Want to add more style properties? # Do it here: # Match style keys here to property names in .ccss fontSize = style['font-size'] bevel = style['bevel']*fontSize font = style['font'] color = style['color'] tn = TextNode(txt) tn.setText(txt) tn.setFont(loader.loadFont(font)) tn.setSlant(style['slant']) tn.setTextColor(color) tn.setShadow(*style['shadow-offset']) tn.setShadowColor(*style['shadow-color']) NodePath(tn).setScale(fontSize) sHolder = NodePath(PandaNode('sHolder')) sHolder.attachNewNode(tn) grphcs.append(sHolder) sHolder.attachNewNode(tn) borderColor = style['border-Color'] thk = style['border-thickness'] if 'background-Color' in style and\ style['background-Color'] != 'transparent': bgColor = style['background-Color'] else: bgColor = None if kind=='parent': if state==HOVER: ar = arrowhead*2 else: ar = arrowhead grphcs[state].attachNewNode(bevelArrow(frame, bevel, ar, thk, color, borderColor, bgColor)) elif kind in ('horizontal', 'titleBar', 'close'): grphcs[state].attachNewNode(rectangle(frame, thk, color, borderColor, bgColor)) elif kind=='checkBox': grphcs[state].attachNewNode(checkBox(frame, bevel, thk, color, borderColor, bgColor)) cb = grphcs[state].attachNewNode(checkedBox(frame, bevel, thk, color, borderColor, bgColor)) cb.hide() elif kind=='radioBTN': grphcs[state].attachNewNode(radioBTN(frame, bevel, thk, color, borderColor, bgColor)) cb = grphcs[state].attachNewNode(checkedRadioBTN(frame, bevel, thk, color, borderColor, bgColor)) cb.hide() else: grphcs[state].attachNewNode(bevelBG(frame, bevel, thk, borderColor, bgColor)) return grphcs
def setCommandButtons(self): self.guiItem.addClickButton(MouseButton.one()) self.bind(DGG.B1PRESS, self.commandFunc)