Changeset 80 for trunk/PARPG/scripts


Ignore:
Timestamp:
06/02/09 03:05:02 (11 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

Location:
trunk/PARPG/scripts
Files:
3 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 
  • trunk/PARPG/scripts/inventory.py

    r74 r80  
    2121 
    2222        self.inventory = pychan.loadXML("gui/inventory.xml") 
    23         events_to_map = {'close_button':self.inventory.hide, 
    24                          'reset_button':self.resetImages} 
     23        self.events_to_map = {} 
    2524 
    2625        # the images that should be used for the buttons when they are "empty" 
     
    7877        for button in self.buttons: 
    7978            # make every button's callback be self.dragDrop 
    80             events_to_map[button] = cbwa(self.dragDrop, button) 
     79            self.events_to_map[button] = cbwa(self.dragDrop, button) 
    8180            ch = self.inventory.findChild(name = button) 
    8281            # make every slot's item be empty 
    8382            ch.item = "" 
    8483 
    85         self.inventory.mapEvents(events_to_map)    
     84        self.inventory.mapEvents(self.events_to_map)    
    8685        self.resetMouseCursor() 
    8786        self.inventory.show() 
     
    9493        """Show the inventory""" 
    9594        self.inventory.show() 
    96  
    97     def resetImages(self): 
    98         """Reset all images in the program to the way they were when the  
    99            program was first launched 
    100            TODO: should be taken out on release (WHY?)""" 
    101         for image in self.empty_images: 
    102             child = self.inventory.findChild(name = image) 
    103             original_image = self.empty_images[image] 
    104             child._setUpImage(original_image) 
    105             child._setDownImage(original_image) 
    106             child._setHoverImage(original_image) 
    10795 
    10896    def setMouseCursor(self, image, dummy_image, type = "native"):  
  • trunk/PARPG/scripts/world.py

    r79 r80  
    149149            self.obj_hash[obj].say(str(text), 3500) 
    150150 
     151    def closeInventoryAndToggle(self): 
     152        self.inventory.closeInventory() 
     153        self.hud.toggleInventory() 
     154        self.inventoryShown = False 
     155 
    151156    def displayInventory(self, callFromHud): 
    152157        """Pause the game and enter the inventory screen 
     
    157162        if(self.firstInventory == True): 
    158163            self.inventory = inventory.Inventory(self.engine) 
     164            self.inventory.events_to_map['close_button'] = self.closeInventoryAndToggle 
     165            self.inventory.inventory.mapEvents(self.inventory.events_to_map) 
    159166            self.firstInventory = False 
    160167            self.inventoryShown = True 
Note: See TracChangeset for help on using the changeset viewer.