view gamelib/mainmenu.py @ 82:b0d97d51df51

Hook up simplistic equipment screen
author Neil Muller <drnlmuller@gmail.com>
date Wed, 09 May 2012 16:51:26 +0200
parents 8d1cf0cbe5e1
children 74ce25ec2073
line wrap: on
line source

# -*- coding: utf-8 -*-
# vim:fileencoding=utf-8 ai ts=4 sts=4 et sw=4

"""The main menu"""

import pygame
from pygame import image

from gamelib import data
from gamelib.gui_base import Window
from gamelib.gui import BigButton
from gamelib.engine import AddWindow
from gamelib.gamegui import LabWindow

from gamelib.constants import WIDTH, HEIGHT


class MainMenuButton(BigButton):
    WIDTH = 276
    HEIGHT = 75
    BG_IMAGE_NORMAL = image.load(data.filepath('images/main_normal.png'))
    BG_IMAGE_DOWN = image.load(data.filepath('images/main_down.png'))


class NewGameButton(MainMenuButton):

    def __init__(self, parent):
        super(NewGameButton, self).__init__(((WIDTH - self.WIDTH) / 2,
            (HEIGHT - self.HEIGHT) / 2 - self.HEIGHT),
                'Start New Game')
        self.parent = parent

    def on_click(self):
        self.parent.start_new_game()


class ResumeGameButton(MainMenuButton):

    def __init__(self, parent):
        super(ResumeGameButton, self).__init__(((WIDTH - self.WIDTH) / 2,
            (HEIGHT - self.HEIGHT) / 2), 'Resume Game')
        self.parent = parent

    def on_click(self):
        self.parent.resume_game()


class QuitButton(MainMenuButton):

    def __init__(self):
        super(QuitButton, self).__init__(((WIDTH - self.WIDTH) / 2,
            (HEIGHT - self.HEIGHT) / 2 + self.HEIGHT), 'Quit')

    def on_click(self):
        pygame.event.post(pygame.event.Event(pygame.QUIT))


class MainMenu(Window):

    def __init__(self, screen):
        super(MainMenu, self).__init__(screen)
        self.game_window = None
        self.resume = None
        self.screen = screen
        self.background_colour = (0, 0, 0)
        self.background_image = image.load(data.filepath('images/temp.jpg'))
        button1 = NewGameButton(self)
        self.add_child(button1)
        button2 = QuitButton()
        self.add_child(button2)

    def start_new_game(self):
        self.game_window = LabWindow(self.screen)
        if not self.resume:
            # Add the resume button
            self.resume = ResumeGameButton(self)
            self.add_child(self.resume)
        AddWindow.post(self.game_window)

    def resume_game(self):
        AddWindow.post(self.game_window)