3 import pygame.locals as pgl
6 from .base import BaseScene
7 from ..events import QuitEvent, SceneChangeEvent
8 from ..loader import loader
9 from ..utils import save_file_exists, get_save_data
10 from ..widgets import ImageButton
11 from ..transforms import Overlay
13 class SplashButton(ImageButton):
14 def __init__(self, name, pos):
15 super(SplashButton, self).__init__("splash", "%s.png" % name, name=name,
16 pos=pos, disabled_colour=(50, 50, 50))
17 w, h = self._img.get_size()
18 img = pygame.surface.Surface((w+8, h+4), pgl.SWSURFACE).convert_alpha()
19 img.fill((0, 0, 0, 0))
20 img.blit(self._img, (8, 4), None)
21 img.fill((0, 0, 0, 255), None, pgl.BLEND_RGBA_MULT)
22 img.blit(self._img, (0, 0), None)
26 class MenuScene(BaseScene):
28 BRIGHTNESS = Overlay(colour=(255, 255, 255, 50))
30 def enter(self, gamestate):
31 if gamestate.station is None:
32 print "Loading Station Alpha ..."
33 gamestate.set_station(loader.load_station("station-alpha.json"))
35 self._cont_but = SplashButton("continue_retry", (500, 210))
36 if not save_file_exists():
37 self._cont_but.disable()
39 SplashButton("new_game", (600, 150)),
41 SplashButton("help", (700, 270)),
42 SplashButton("quit", (800, 330)),
46 self._soil = loader.load_image(
47 "textures", "soil.png", transform=self.BRIGHTNESS).convert_alpha()
48 splash = loader.load_image("splash", "splash.png").convert_alpha()
49 self._soil.blit(splash, (0, 0), None)
51 def render(self, surface, gamestate):
52 surface.blit(self._soil, (0, 0), None)
54 for item in self._menu:
57 def _get_pressed(self, ev):
58 for button in self._menu:
59 if button.pressed(ev):
63 def _do_load_save(self, gamestate):
64 gamestate.load_from_json(get_save_data())
65 from .day import DayScene
66 SceneChangeEvent.post(scene=DayScene())
68 def _start_new_game(self):
69 from .load_level import LoadLevelScene
70 SceneChangeEvent.post(scene=LoadLevelScene())
73 from .help import HelpScene
74 SceneChangeEvent.post(scene=HelpScene())
76 def event(self, ev, gamestate):
77 if ev.type == pgl.KEYDOWN:
78 if ev.key in (pgl.K_q, pgl.K_ESCAPE):
80 elif ev.key == pgl.K_n:
81 from .night import NightScene
82 SceneChangeEvent.post(scene=NightScene())
83 elif ev.key == pgl.K_d:
85 elif ev.key == pgl.K_l:
86 self._start_new_game()
87 elif ev.key == pgl.K_h:
89 elif ev.type == pgl.MOUSEBUTTONDOWN:
90 pressed = self._get_pressed(ev)
91 if pressed == 'new_game':
92 self._start_new_game()
93 elif pressed == 'continue_retry':
94 self._do_load_save(gamestate)
95 elif pressed == 'help':
97 elif pressed == 'quit':
100 print 'Pressed', pressed