comparison gamelib/loadlevel.py @ 412:1e24eedbf40f

Implement non-gui parts of level loading communication
author Neil Muller <drnlmuller@gmail.com>
date Sat, 21 Nov 2009 11:34:12 +0000
parents
children c6dd21b75bf5
comparison
equal deleted inserted replaced
411:03d5cb669298 412:1e24eedbf40f
1 """Help screen."""
2
3 from pgu import gui
4 import os
5 import pygame
6 import constants
7 import level
8 import engine
9 import data
10 import imagecache
11
12 def make_load_screen(level):
13 """Create a screen for selecting the levels"""
14 load_screen = LoadScreen(level, width=600)
15
16 c = LoadContainer(align=0, valign=0)
17 c.add(load_screen, 0, 0)
18
19 return c, load_screen
20
21 class LoadContainer(gui.Container):
22 def paint(self, s):
23 pygame.display.set_caption('Load Level')
24 splash = imagecache.load_image("images/splash.png", ["lighten_most"])
25 pygame.display.get_surface().blit(splash, (0, 0))
26 gui.Container.paint(self, s)
27
28 class LoadScreen(gui.Document):
29 def __init__(self, start_level, **params):
30 self.levels = {}
31 self.cur_level = start_level
32 for name in os.listdir(data.filepath('levels/')):
33 if name.endswith('.conf'):
34 try:
35 this_level = level.Level(name)
36 except RuntimeError:
37 continue # Skip levels that fail to load
38 if os.path.exists(this_level.map):
39 # Skip level if we can't see the map
40 self.levels[this_level.level_name] = this_level
41 if not start_level.level_name in self.levels:
42 print 'Start level not found'
43
44 self.cur_level = self.levels.values()[0]
45
46 gui.Document.__init__(self, **params)
47
48 def done_pressed():
49 pygame.event.post(engine.DO_LOAD_LEVEL)
50
51 def cancel_pressed():
52 pygame.event.post(engine.GO_MAIN_MENU)
53
54 done_button = gui.Button("Load This Level")
55 done_button.connect(gui.CLICK, done_pressed)
56
57 cancel_button = gui.Button("Cancel & return to main menu")
58 cancel_button.connect(gui.CLICK, cancel_pressed)
59
60 self.add(done_button, align=0)
61 self.add(cancel_button, align=0)
62
63 def get_level(self):
64 return self.cur_level_name
65