Mercurial > parpg-core
view src/parpg/mainmenuview.py @ 6:dd4ed4945411
Ported binary launcher to Windows.
* Reorganized the parpg executable source so that it now compiles with the MSVC compiler (tested with MSVC Express 2010).
* Cleaned up the launcher source by adding a bunch of const statements and removing the superfluous NULL_TERMINATE macro.
* Fixed a few memory leaks in the launcher source by freeing malloced/calloced pointers;
* Added a new SubstfileEscape builder to the SConstruct script used to escape certain sequences when substituting a template file. This is used to escape backslashes ("\") in c strings in the bin/parpg.c.in template for Windows paths.
* Fixed the PY_LIB_DIR_DEFAULT for Windows so that it now correctly points to the default Python installation path.
* Modified the SConstruct script to support compiling the launcher executable with debugging symbols in Windows with the DEBUG flag.
author | M. George Hansen |
---|---|
date | Sun, 22 May 2011 00:53:59 -0700 |
parents | 1fd2201f5c36 |
children | d60f1dab8469 |
line wrap: on
line source
# This file is part of PARPG. # PARPG 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. # PARPG 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 PARPG. If not, see <http://www.gnu.org/licenses/ import os from fife.extensions import pychan from viewbase import ViewBase from parpg.gui.filebrowser import FileBrowser from parpg.gui.menus import SettingsMenu class MainMenuView(ViewBase): """View that is used to display the main menu""" def __init__(self, engine, model): """Constructor for MainMenuView @param engine: A fife.Engine instance @type engine: fife.Engine @param model: a script.GameModel instance @type model: script.GameModel """ ViewBase.__init__(self, engine, model) self.quit_window = None self.new_game_callback = None self.load_game_callback = None self.quit_callback = None self.main_menu = None self.character_screen = None self.gui_path = os.path.join(self.model.settings.system_path, self.model.settings.parpg.GuiPath) def showMenu(self): """"Shows the main menu""" self.main_menu_background.show() self.main_menu.show() def hideMenu(self): """"Hides the main menu""" self.main_menu.hide() self.main_menu_background.hide() def initalizeMainMenu(self, new_game, load_game, quit_game): """Initialized the main menu and sets the callbacks""" # Set a simple background to display the main screen. self.main_menu_background = pychan.loadXML(os.path.join(self.gui_path, 'main_menu_background.xml')) # Initialize the main menu screen. screen_mode = self.engine.getRenderBackend().getCurrentScreenMode() self.main_menu_background.width = screen_mode.getWidth() self.main_menu_background.height = screen_mode.getHeight() self.main_menu = pychan.loadXML(os.path.join(self.gui_path, 'main_menu.xml')) # Setup images for variables widgets self.main_menu.background_image = os.path.join(self.gui_path, 'notebook', 'notebook_background.png') quit_button = self.main_menu.findChild(name='quitButton') quit_button.up_image = os.path.join(self.gui_path, 'notebook', 'tabs', 'tab2_bg_dark_bottom.png') quit_button.hover_image = os.path.join(self.gui_path, 'notebook', 'tabs', 'tab2_bg_normal_bottom.png') quit_button.down_image = os.path.join(self.gui_path, 'notebook', 'tabs', 'tab2_bg_normal_bottom.png') self.main_menu.adaptLayout() self.new_game_callback = new_game self.load_game_callback = load_game self.quit_callback = quit_game menu_events = {} menu_events["newButton"] = self.newGame menu_events["loadButton"] = self.loadGame menu_events["settingsButton"] = self.displaySettings menu_events["quitButton"] = self.quitGame self.main_menu.mapEvents(menu_events) self.initializeQuitDialog() self.initializeSettingsMenu() def newGame(self): """Called when user request to start a new game. @return: None""" self.new_game_callback() def loadGame(self): """ Called when the user wants to load a game. @return: None""" load_browser = FileBrowser(self.engine, self.model.settings, self.load_game_callback, gui_xml_path=os.path.join(self.gui_path, 'loadbrowser.xml'), save_file=False, extensions=('.dat')) load_browser.showBrowser() def initializeQuitDialog(self): """Creates the quit confirmation dialog @return: None""" self.quit_window = pychan.widgets.Window(title=unicode("Quit?"), \ min_size=(200,0)) hbox = pychan.widgets.HBox() are_you_sure = "Are you sure you want to quit?" label = pychan.widgets.Label(text=unicode(are_you_sure)) yes_button = pychan.widgets.Button(name="yes_button", text=unicode("Yes"), min_size=(90,20), max_size=(90,20)) no_button = pychan.widgets.Button(name="no_button", text=unicode("No"), min_size=(90,20), max_size=(90,20)) self.quit_window.addChild(label) hbox.addChild(yes_button) hbox.addChild(no_button) self.quit_window.addChild(hbox) events_to_map = { "yes_button": self.quit_callback, "no_button": self.quit_window.hide } self.quit_window.mapEvents(events_to_map) def quitGame(self): """Called when user requests to quit game. @return: None""" self.quit_window.show() def initializeSettingsMenu(self): self.settings_menu = SettingsMenu(self.engine, self.model.settings) def displaySettings(self): self.settings_menu.show()