From: Stefano Rivera Date: Sat, 17 May 2014 19:31:39 +0000 (+0200) Subject: Hook the introduction into the menus X-Git-Tag: 0.1~34^2~5 X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=51be7c66a7b60369a7165f3130f13951c21e53fa;p=naja.git Hook the introduction into the menus --- diff --git a/naja/scenes/howto.py b/naja/scenes/howto.py index cf6f354..4d34178 100644 --- a/naja/scenes/howto.py +++ b/naja/scenes/howto.py @@ -62,7 +62,7 @@ class HowtoScene(Scene): box_width=740, view_port=(780, 540))) def handle_scene_event(self, ev): - from naja.scenes.menu import MenuScene + from naja.scenes.introduction import IntroductionScene if ev.type == pgl.KEYDOWN and ev.key in KEYS.QUIT: - SceneChangeEvent.post(MenuScene) + SceneChangeEvent.post(IntroductionScene) return diff --git a/naja/scenes/introduction.py b/naja/scenes/introduction.py new file mode 100644 index 0000000..95defaa --- /dev/null +++ b/naja/scenes/introduction.py @@ -0,0 +1,68 @@ +""" +Load and save scenes. +""" + +import pygame.locals as pgl + +from naja.constants import KEYS +from naja.events import SceneChangeEvent, LoadGameEvent +from naja.gamestate import GameState +from naja.scenes.scene import Scene +from naja.scenes.howto import HowtoScene +from naja.widgets.image_box import ImageBox +from naja.widgets.selector import SelectorWidget +from naja.widgets.text import TextWidget + + +class IntroductionScene(Scene): + def __init__(self, state): + super(IntroductionScene, self).__init__(state) + + background = ImageBox( + (0, 0), "screens/splash.png") + self.add(background) + + selector = SelectorWidget() + self.add(selector) + + y_offset, y_diff = 270, 40 + x_offset = 400 + + y_offset += y_diff + title = TextWidget( + (x_offset, y_offset), 'Getting started', colour='white', + centre=True) + self.add(title) + + y_offset += y_diff + howto = TextWidget( + (x_offset, y_offset), 'How to play', colour='white', centre=True) + howto.add_callback('click', self.howto_scene) + selector.add(howto) + + y_offset += y_diff + intro = TextWidget( + (x_offset, y_offset), 'Introductory Level', colour='white', + centre=True) + intro.add_callback('click', self.introduction_level) + selector.add(intro) + + y_offset += 2*y_diff + back = TextWidget( + (x_offset, y_offset), 'Press ESC to return to the main menu.', + colour='white', centre=True) + self.add(back) + + def howto_scene(self, event): + SceneChangeEvent.post(HowtoScene) + + def introduction_level(self, event): + from naja.scenes.game import GameScene + LoadGameEvent.post(state=GameState.new(deck='introduction')) + SceneChangeEvent.post(GameScene) + + def handle_scene_event(self, ev): + if ev.type == pgl.KEYDOWN and ev.key in KEYS.QUIT: + from naja.scenes.menu import MenuScene + SceneChangeEvent.post(MenuScene) + return diff --git a/naja/scenes/menu.py b/naja/scenes/menu.py index 84911c3..2431e07 100644 --- a/naja/scenes/menu.py +++ b/naja/scenes/menu.py @@ -10,7 +10,7 @@ from naja.options import options from naja.scenes.scene import Scene from naja.scenes.credits import CreditsScene from naja.scenes.game import GameScene -from naja.scenes.howto import HowtoScene +from naja.scenes.introduction import IntroductionScene from naja.scenes.load_save import LoadGameScene, SaveGameScene from naja.scenes.new_game import NewGameScene from naja.scenes.puzzlelist import PuzzleListScene @@ -33,6 +33,13 @@ class MenuScene(Scene): y_offset, y_diff = 270, 36 x_offset = 400 + y_offset += y_diff + intro = TextWidget( + (x_offset, y_offset), 'Introduction', colour=PALETTE.WHITE, + centre=True) + intro.add_callback('click', self.scene_callback(IntroductionScene)) + selector.add(intro) + y_offset += y_diff resume = TextWidget( (x_offset, y_offset), 'Resume Game', colour=PALETTE.WHITE, @@ -41,6 +48,11 @@ class MenuScene(Scene): resume.set_selectable_callback(lambda: state is not None) selector.add(resume) + if state is None: + selector.position = 2 + else: + selector.position = 1 + y_offset += y_diff new = TextWidget( (x_offset, y_offset), 'New Random Game', colour=PALETTE.WHITE, @@ -70,13 +82,6 @@ class MenuScene(Scene): save.set_selectable_callback(lambda: state is not None) selector.add(save) - y_offset += y_diff - howto = TextWidget( - (x_offset, y_offset), 'How To Play', colour=PALETTE.WHITE, - centre=True) - howto.add_callback('click', self.scene_callback(HowtoScene)) - selector.add(howto) - y_offset += y_diff credits = TextWidget( (x_offset, y_offset), 'Credits', colour=PALETTE.WHITE,