Mercurial > rinkhals
changeset 6:c0abad23a055
Add start, quit and toggle fullscreen buttons to menu.
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Sun, 30 Aug 2009 13:25:04 +0000 |
parents | 67b79658b047 |
children | 99c4f2226314 |
files | gamelib/constants.py gamelib/main.py gamelib/mainmenu.py |
diffstat | 3 files changed, 32 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/gamelib/constants.py Sun Aug 30 13:04:24 2009 +0000 +++ b/gamelib/constants.py Sun Aug 30 13:25:04 2009 +0000 @@ -1,12 +1,17 @@ """Operation Fox Assault constants.""" +# Project metadata + NAME = "Operation Fox Assault" -SCREEN = (800, 600) - AUTHORS = [ ("Adrianna Pinska", "adrianna.pinska@gmail.com"), ("Jeremy Thurgood", ""), ("Neil Muller", ""), ("Simon Cross", "hodgestar+rinkhals@gmail.com"), ] + +# GUI constants + +SCREEN = (800, 600) +FG_COLOR = (255, 255, 255)
--- a/gamelib/main.py Sun Aug 30 13:04:24 2009 +0000 +++ b/gamelib/main.py Sun Aug 30 13:25:04 2009 +0000 @@ -8,7 +8,7 @@ import pygame from pgu import gui -from pygame.locals import SWSURFACE, QUIT, KEYDOWN, K_ESCAPE +from pygame.locals import SWSURFACE, QUIT, KEYDOWN, K_ESCAPE, USEREVENT from mainmenu import MainMenu import constants @@ -23,6 +23,8 @@ done = True elif e.type is KEYDOWN and e.key == K_ESCAPE: done = True + elif e.type is USEREVENT: + print e.event else: app.event(e)
--- a/gamelib/mainmenu.py Sun Aug 30 13:04:24 2009 +0000 +++ b/gamelib/mainmenu.py Sun Aug 30 13:25:04 2009 +0000 @@ -5,26 +5,35 @@ import constants class MainMenu(gui.Table): - def __init__(self,**params): - gui.Table.__init__(self,**params) + def __init__(self, **params): + gui.Table.__init__(self, **params) - def fullscreen_changed(btn): + def fullscreen_toggled(): pygame.display.toggle_fullscreen() - fg = (255,255,255) + def quit_pressed(): + pygame.event.post(pygame.event.Event(pygame.QUIT)) + + def start_pressed(): + pygame.event.post(pygame.event.Event(pygame.USEREVENT, event="<Our Start Event Class>")) - self.tr() - self.td(gui.Label(constants.NAME, color=fg), colspan=2) + start_button = gui.Button("Start") + start_button.connect(gui.CLICK, start_pressed) + + quit_button = gui.Button("Quit") + quit_button.connect(gui.CLICK, quit_pressed) + + fullscreen_toggle = gui.Button("Toggle Fullscreen") + fullscreen_toggle.connect(gui.CLICK, fullscreen_toggled) self.tr() - self.td(gui.Label("Start", color=fg), align=1) - - btn = gui.Switch(value=False,name='fullscreen') - btn.connect(gui.CHANGE, fullscreen_changed, btn) + self.td(gui.Label(constants.NAME, color=constants.FG_COLOR), colspan=2) self.tr() - self.td(gui.Label("Full Screen: ",color=fg),align=1) - self.td(btn) + self.td(start_button, align=0) self.tr() - self.td(gui.Label("Quit", color=fg), align=1) + self.td(fullscreen_toggle, align=0) + + self.tr() + self.td(quit_button, align=0)