comparison gamelib/gameboard.py @ 548:27c09c58d89d

Remove gameboard and dialog event flow hacks.
author Simon Cross <hodgestar@gmail.com>
date Sat, 28 Nov 2009 11:25:56 +0000
parents 84964077626a
children 11c4cebfe4c5
comparison
equal deleted inserted replaced
547:1456bf2ff02e 548:27c09c58d89d
1 import random 1 import random
2 2
3 import pygame 3 import pygame
4 from pygame.locals import MOUSEBUTTONDOWN, MOUSEMOTION, KEYDOWN, K_UP, K_DOWN, \ 4 from pygame.locals import MOUSEBUTTONDOWN, MOUSEMOTION, KEYDOWN, K_UP, K_DOWN, \
5 K_LEFT, K_RIGHT, KMOD_SHIFT, K_0, K_1, K_2, K_3, K_4, K_5, K_6, K_7, \ 5 K_LEFT, K_RIGHT, KMOD_SHIFT, K_0, K_1, K_2, K_3, K_4, K_5, K_6, K_7, \
6 K_8, K_9, KMOD_CTRL, KMOD_ALT, KEYUP 6 K_8, K_9, K_ESCAPE, K_n, K_d, KMOD_CTRL, KMOD_ALT, KEYUP
7 from pgu import gui 7 from pgu import gui
8 8
9 import tiles 9 import tiles
10 import icons 10 import icons
11 import constants 11 import constants
39 if e.type == MOUSEBUTTONDOWN: 39 if e.type == MOUSEBUTTONDOWN:
40 self.gameboard.use_tool(e) 40 self.gameboard.use_tool(e)
41 elif e.type == MOUSEMOTION and self.gameboard.sprite_cursor: 41 elif e.type == MOUSEMOTION and self.gameboard.sprite_cursor:
42 self.gameboard.update_sprite_cursor(e) 42 self.gameboard.update_sprite_cursor(e)
43 else: 43 else:
44 return self.gameboard.event(e) 44 return False
45 return True
46 45
47 46
48 class AnimalPositionCache(object): 47 class AnimalPositionCache(object):
49 def __init__(self, gameboard): 48 def __init__(self, gameboard):
50 self.gameboard = gameboard 49 self.gameboard = gameboard
190 tbl.tr() 189 tbl.tr()
191 self.toolbar = toolbar.DefaultToolBar(self, width=constants.TOOLBAR_WIDTH) 190 self.toolbar = toolbar.DefaultToolBar(self, width=constants.TOOLBAR_WIDTH)
192 tbl.td(self.toolbar, valign=-1) 191 tbl.td(self.toolbar, valign=-1)
193 self.tvw = VidWidget(self, self.tv, width=width-constants.TOOLBAR_WIDTH, height=height) 192 self.tvw = VidWidget(self, self.tv, width=width-constants.TOOLBAR_WIDTH, height=height)
194 tbl.td(self.tvw) 193 tbl.td(self.tvw)
194
195 # we should probably create a custom widget to be the top widget
196 # if we want to flow some events to the gameboard
197 def event(e):
198 if gui.Table.event(tbl, e):
199 return True
200 return self.event(e)
201 tbl.event = event
202
195 self.top_widget = tbl 203 self.top_widget = tbl
196 self.redraw_counters() 204 self.redraw_counters()
197 205
198 def change_toolbar(self, new_toolbar): 206 def change_toolbar(self, new_toolbar):
199 """Replace the toolbar""" 207 """Replace the toolbar"""
818 tbl.td(button, align=1, **kwargs) 826 tbl.td(button, align=1, **kwargs)
819 827
820 dialog = self.open_dialog(tbl, x=x, y=y) 828 dialog = self.open_dialog(tbl, x=x, y=y)
821 829
822 def event(self, e): 830 def event(self, e):
823 if e.type == KEYDOWN and e.key in [K_UP, K_DOWN, K_LEFT, K_RIGHT]: 831 if e.type == KEYDOWN and e.key == K_ESCAPE:
832 def sure(val):
833 if val:
834 import engine
835 pygame.event.post(engine.GO_GAME_OVER)
836 dialog = misc.CheckDialog(sure)
837 self.disp.open(dialog)
838 return True
839 elif e.type == KEYDOWN and e.key == K_n and self.day:
840 import engine
841 pygame.event.post(engine.START_NIGHT)
842 return True
843 elif e.type == KEYDOWN and e.key == K_d and self.night:
844 import engine
845 pygame.event.post(engine.FAST_FORWARD)
846 return True
847 elif e.type == KEYDOWN and e.key in [K_UP, K_DOWN, K_LEFT, K_RIGHT]:
824 if e.key == K_UP: 848 if e.key == K_UP:
825 self.tvw.move_view(0, -constants.TILE_DIMENSIONS[1]) 849 self.tvw.move_view(0, -constants.TILE_DIMENSIONS[1])
826 if e.key == K_DOWN: 850 if e.key == K_DOWN:
827 self.tvw.move_view(0, constants.TILE_DIMENSIONS[1]) 851 self.tvw.move_view(0, constants.TILE_DIMENSIONS[1])
828 if e.key == K_LEFT: 852 if e.key == K_LEFT: