Source

Fat x Fast / FatxFast / scenes / menuscenes.py

The branch 'advanced-physics' does not exist.
Full commit

# This file is part of FatxFast.
#
#    FatxFast is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    FatxFast is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with FatxFast.  If not, see <http://www.gnu.org/licenses/>.

# Versioning based on: 
# http://en.wikipedia.org/wiki/Versioning#Designating_development_stage
__author__ = "dryatu (c) 2013"
__version__ = "1.2.4"


from FatxFast.scenes.basescene import Scene
import pygame
from FatxFast.scenes.sceneeditors import (ConfigSceneEditor,
                                            SaveSceneEditor,
                                            ScoreSceneEditor)
from FatxFast.resource import resource_manager
from FatxFast.gui.linkwidget import SceneLinkWidget, BackLinkWidget
from FatxFast.gui.containerwidget import ContainerWidget
import random

class MenuScene(Scene):
    
    def __init__(self, manager, **kwargs):
        super(MenuScene, self).__init__(manager, **kwargs)
        if kwargs.get("type") == "gamemenuscene":
            self.initialise_gamemenuscene(**kwargs)
            
    def initialise_gamemenuscene(self, **kwargs):
        bg_widget = self.get_widget("bg")
        bg_widget.image = kwargs.get("bg")
        if bg_widget.image:
            self.set_properties_to_links("bg", self.get_widget("bg").image, 
                self.widgets)
        if "gamescene" in kwargs:
            self.set_properties_to_links("gamescene",
                                         kwargs["gamescene"], self.widgets)

        
    def set_properties_to_links(self, property_name, value, widgets_dict):
        for widget in widgets_dict.values():
            if (isinstance(widget, SceneLinkWidget) and
                not isinstance(widget, BackLinkWidget)):
                widget.properties[property_name] = value
            if isinstance(widget, ContainerWidget):
                self.set_properties_to_links(
                    property_name, value, widget.widgets)
        
    def key_pressed(self, key, utf, mod):
        if key == pygame.K_ESCAPE:
            self.manager.pop_scene()
        else:
            super(MenuScene, self).key_pressed(key, utf, mod)
        
class IntroScene(MenuScene):

    def __init__(self, manager, **kwargs):
        manager.clear()
        super(IntroScene, self).__init__(manager, **kwargs)
        self.manager.game.audio.load_music("intro_cosmos.mp3")
        self.manager.game.audio.play_music(-1) 
    
    def key_pressed(self, key, utf, mod):
        if key == pygame.K_ESCAPE:
            self.manager.push_scene("exitscene")
        else:
            super(MenuScene, self).key_pressed(key, utf, mod)
        
class SaveScene(MenuScene):    
    
    def __init__(self, manager, **kwargs):
        super(SaveScene, self).__init__(manager, **kwargs)
        self.editor = SaveSceneEditor(self)
        self.editor.create_saveboard()

    def resume(self): 
        super(SaveScene, self).resume()
        self.editor.create_saveboard()
        
class ScoreScene(MenuScene):
    
    def __init__(self, manager, **kwargs):
        super(ScoreScene, self).__init__(manager, **kwargs)
        self.editor = ScoreSceneEditor(self)
        self.editor.create_scoreboard()

class ConfigScene(MenuScene):
    def __init__(self, manager, **kwargs):
        super(ConfigScene, self).__init__(manager, **kwargs)
        self.editor = ConfigSceneEditor(self)
        self.editor.create_widgets()
        self.editor.update_texts()
        
    def change_setting(self, setting):
        getattr(self.manager.game.config, "change_"+setting)()
        self.editor.update_texts()
    
    def resume(self): 
        super(ConfigScene, self).resume()
        self.editor.update_texts()
        
class ExitScene(MenuScene):    
    
    def __init__(self, manager, **kwargs):
        super(ExitScene, self).__init__(manager)
        resource_manager.save("config", self.manager.game.config)
        manager.game.running = False