From: Stefano Rivera Date: Sun, 11 May 2014 17:11:30 +0000 (+0200) Subject: A menu that works (but doesn't show the selection) X-Git-Tag: 0.1~399 X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=baa600e7e8557e51c6deddff16988a5e1779f379;p=naja.git A menu that works (but doesn't show the selection) --- diff --git a/naja/scenes/game.py b/naja/scenes/game.py index e37b63e..9d8b290 100644 --- a/naja/scenes/game.py +++ b/naja/scenes/game.py @@ -4,16 +4,13 @@ Gameboard scene. import pygame.locals as pgl -from .scene import Scene -from .menu import MenuScene - +from naja.events import SceneChangeEvent +from naja.scenes.scene import Scene from naja.widgets.board import BoardWidget from naja.widgets.player_bits import PlayerBitsWidget from naja.widgets.game_bits import GameBitsWidget from naja.widgets.info_area import InfoAreaWidget -from naja.events import SceneChangeEvent - class GameScene(Scene): """ @@ -28,6 +25,7 @@ class GameScene(Scene): self.widgets.append(InfoAreaWidget((480, 0))) def handle_event(self, ev): + from naja.scenes.menu import MenuScene if ev.type == pgl.KEYUP and ev.key in (pgl.K_q, pgl.K_ESCAPE): SceneChangeEvent.post(MenuScene) return diff --git a/naja/scenes/menu.py b/naja/scenes/menu.py index 9a0fe71..a73c2ec 100644 --- a/naja/scenes/menu.py +++ b/naja/scenes/menu.py @@ -8,6 +8,7 @@ from naja.scenes.scene import Scene from naja.widgets.text import TextWidget from naja.events import QuitGameEvent from naja.scenes.credits import CreditsScene +from naja.scenes.game import GameScene from naja.events import SceneChangeEvent @@ -21,11 +22,23 @@ class MenuScene(Scene): colour='white')) self.widgets.append(TextWidget((10, 70), 'Quit', fontsize=32, colour='white')) + self.pos = 0 def handle_event(self, ev): - if ev.type == pgl.KEYDOWN and ev.key in (pgl.K_q, pgl.K_ESCAPE): - QuitGameEvent.post() - return - if ev.type == pgl.KEYDOWN and ev.key is pgl.K_RETURN: - SceneChangeEvent.post(CreditsScene) - return + if ev.type == pgl.KEYDOWN: + if ev.key in (pgl.K_q, pgl.K_ESCAPE): + QuitGameEvent.post() + return + if ev.key == pgl.K_DOWN: + self.pos = (self.pos + 1) % 3 + elif ev.key == pgl.K_UP: + self.pos = (self.pos - 1) % 3 + elif ev.key == pgl.K_RETURN: + if self.pos == 2: + QuitGameEvent.post() + return + elif self.pos == 0: + scene = GameScene + elif self.pos == 1: + scene = CreditsScene + SceneChangeEvent.post(scene)