Ignore:
Timestamp:
06/02/09 03:05:02 (10 years ago)
Author:
bretzel_parpg
Message:

Added lots of stuff:

-> Changed some code in the HUD so it will be easier to skin
-> Added options to change the resolution and render backend in the options menu
-> Removed the reset images button in the inventory
-> Made the close button in the inventory toggle the inventory button on the HUD

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/PARPG/scripts/hud.py

    r76 r80  
    11#!/usr/bin/python 
    2  
    3 # Make the actions append at the top instead of the bottom 
    42 
    53"""Import all necessary modules""" 
     
    2119 
    2220        self.settings = settings 
    23         self.hp = self.hud.findChild(name="HealthPoints") 
    24         self.ap = self.hud.findChild(name="ActionPoints") 
    25         self.actionsBox = self.hud.findChild(name="ActionsBox") 
     21        self.hp = self.hud.findChild(name="healthPoints") 
     22        self.ap = self.hud.findChild(name="actionPoints") 
     23        self.actionsBox = self.hud.findChild(name="actionsBox") 
    2624        self.actionsText = [] 
    2725        self.menu_displayed = False 
    28  
     26         
     27        self.initializeHud() 
     28        self.initializeMainMenu() 
     29        self.initializeOptionsMenu() 
     30 
     31    def initializeHud(self): 
    2932        """Initialize and show the main HUD""" 
    3033        self.events_to_map = {"menuButton":self.displayMenu, "saveButton":self.saveGame, 
    3134                              "loadButton":self.loadGame} 
    3235        self.hud.mapEvents(self.events_to_map)  
     36 
     37        screen_width = int(self.settings.readSetting('ScreenWidth')) 
     38        self.hud.findChild(name="mainHudWindow").size = (screen_width, 65) 
     39 
     40        self.hud.findChild(name="inventoryButton").position = (screen_width-59, 7) 
     41         
     42        actions_width = screen_width - 175  
     43        self.hud.findChild(name="actionsBox").min_size = (actions_width, 0) 
     44        self.hud.findChild(name="actionsScrollArea").size = (actions_width, 55) 
     45 
    3346        self.hud.show() 
    3447         
     48    def initializeMainMenu(self): 
    3549        """Initalize the main menu""" 
    3650        self.main_menu = pychan.loadXML("gui/hud_main_menu.xml") 
     
    4054        self.main_menu.mapEvents(self.menu_events) 
    4155 
     56 
     57    def initializeOptionsMenu(self): 
    4258        """Initalize the options menu""" 
    4359        self.options_menu = pychan.loadXML("gui/hud_options.xml") 
    44         self.options_events = {"applyButton":self.applyOptions, "closeButton":self.options_menu.hide} 
    45  
    46         self.options_menu.distributeData({'FullscreenBox':int(self.settings.readSetting(name="FullScreen")), 
    47                                           'SoundsBox':int(self.settings.readSetting(name="PlaySounds"))}) 
     60        self.options_events = {"applyButton":self.applyOptions, 
     61                               "closeButton":self.options_menu.hide} 
     62 
     63        self.Resolutions = ['640x480', '800x600', '1024x768', '1280x1024', '1440x900'] 
     64        self.RenderBackends = ['OpenGL', 'SDL'] 
     65        self.renderNumber = 0 
     66        if (str(self.settings.readSetting('RenderBackend')) == "SDL"): 
     67            self.renderNumber = 1 
     68        self.options_menu.distributeInitialData({ 
     69                'ResolutionBox': self.Resolutions, 
     70                'RenderBox': self.RenderBackends 
     71                }) 
     72        self.options_menu.distributeData({ 
     73                'FullscreenBox':int(self.settings.readSetting(name="FullScreen")),  
     74                'SoundsBox':int(self.settings.readSetting(name="PlaySounds")), 
     75                'ResolutionBox':self.Resolutions.index(str(self.settings.readSetting("ScreenWidth")) + 'x' + str(self.settings.readSetting("ScreenHeight"))), 
     76                'RenderBox': self.renderNumber 
     77                }) 
    4878         
    4979        self.options_menu.mapEvents(self.options_events) 
     
    79109        """ 
    80110        self.requireRestart = False 
    81         enable_fullscreen, enable_sound = self.options_menu.collectData('FullscreenBox', 'SoundsBox') 
     111        enable_fullscreen, enable_sound, screen_resolution, render_backend = self.options_menu.collectData('FullscreenBox', 'SoundsBox', 'ResolutionBox', 'RenderBox') 
    82112 
    83113        if (int(enable_fullscreen) != int(self.settings.readSetting('FullScreen'))): 
     
    87117        if (int(enable_sound) != int(self.settings.readSetting('PlaySounds'))): 
    88118            self.setOption('PlaySounds', int(enable_sound)) 
     119            self.requireRestart = True 
     120 
     121        if (screen_resolution != self.Resolutions.index(str(self.settings.readSetting("ScreenWidth")) + 'x' + str(self.settings.readSetting("ScreenHeight")))): 
     122            self.setOption('ScreenWidth', int(self.Resolutions[screen_resolution].partition('x')[0])) 
     123            self.setOption('ScreenHeight', int(self.Resolutions[screen_resolution].partition('x')[2])) 
     124            self.requireRestart = True 
     125         
     126        if (render_backend == 0): 
     127            render_backend = 'OpenGL' 
     128        else: 
     129            render_backend = 'SDL' 
     130 
     131        if (render_backend != str(self.settings.readSetting("RenderBackend"))): 
     132            self.setOption('RenderBackend', render_backend) 
    89133            self.requireRestart = True 
    90134 
Note: See TracChangeset for help on using the changeset viewer.