Changeset 159


Ignore:
Timestamp:
06/22/09 01:48:25 (10 years ago)
Author:
bretzel_parpg
Message:

Fixed some resolution/options menu errors. Fixed some terrible line
lengths. Added some comments.

File:
1 edited

Legend:

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

    r152 r159  
    178178                               "defaultsButton":self.setToDefaults, 
    179179                               "InitialVolumeSlider":self.updateVolumeText} 
     180 
    180181        self.Resolutions = ['640x480', '800x600', 
    181182                            '1024x768', '1280x1024', '1440x900'] 
     
    192193                'InitialVolumeLabel' : initialVolumeText 
    193194                }) 
    194         # TODO: fix bad line length here 
    195         self.options_menu.distributeData({ 
    196                 'FullscreenBox':int(self.settings.readSetting(name="FullScreen")),  
    197                 'SoundsBox':int(self.settings.readSetting(name="PlaySounds")), 
    198                 'ResolutionBox':self.Resolutions.index(str(self.settings.readSetting("ScreenWidth")) + 'x' + str(self.settings.readSetting("ScreenHeight"))), 
    199                 'RenderBox': self.renderNumber, 
    200                 'InitialVolumeSlider':initialVolume 
    201                 }) 
     195 
     196        sFullscreen = self.settings.readSetting(name="FullScreen") 
     197        sSounds = self.settings.readSetting(name="PlaySounds") 
     198        sRender = self.renderNumber 
     199        sVolume = initialVolume 
     200 
     201        screen_width = self.settings.readSetting(name="ScreenWidth") 
     202        screen_height = self.settings.readSetting(name="ScreenHeight") 
     203        indexRes = str(screen_width + 'x' + screen_height) 
     204        try: 
     205            sResolution = self.Resolutions.index(indexRes) 
     206            resolutionInList = True 
     207        except: 
     208            resolutionInList = False 
     209 
     210        dataToDistribute = { 
     211                'FullscreenBox':int(sFullscreen),  
     212                'SoundsBox':int(sSounds), 
     213                'RenderBox': sRender, 
     214                'InitialVolumeSlider':sVolume 
     215                } 
     216 
     217        if (resolutionInList == True): 
     218            dataToDistribute['ResolutionBox'] = sResolution 
     219 
     220        self.options_menu.distributeData(dataToDistribute) 
     221 
    202222        self.options_menu.mapEvents(self.options_events) 
    203223 
     
    222242        """Apply the current options. 
    223243           @return: None""" 
    224         # TODO: line lengths here are horrible 
    225         # TODO: add comments 
     244        # At first no restart is required 
    226245        self.requireRestart = False 
    227         enable_fullscreen, enable_sound, screen_resolution, render_backend, initial_volume = self.options_menu.collectData('FullscreenBox', 'SoundsBox', 'ResolutionBox', 'RenderBox', 'InitialVolumeSlider') 
     246 
     247        # get the current values of each setting from the options menu 
     248        enable_fullscreen = self.options_menu.collectData('FullscreenBox') 
     249        enable_sound = self.options_menu.collectData('SoundsBox') 
     250        screen_resolution = self.options_menu.collectData('ResolutionBox') 
     251        partition = self.Resolutions[screen_resolution].partition('x') 
     252        screen_width = partition[0] 
     253        screen_height = partition[2] 
     254        render_backend = self.options_menu.collectData('RenderBox') 
     255        initial_volume = self.options_menu.collectData('InitialVolumeSlider') 
    228256        initial_volume = "%.1f" % initial_volume 
    229257 
    230         if (int(enable_fullscreen) != int(self.settings.readSetting('FullScreen'))): 
     258        # get the options that are being used right now from settings.xml 
     259        sFullscreen = self.settings.readSetting('FullScreen') 
     260        sSound = self.settings.readSetting('PlaySounds') 
     261        sRender = self.settings.readSetting('RenderBackend') 
     262        sVolume = self.settings.readSetting('InitialVolume') 
     263 
     264        sScreenHeight = self.settings.readSetting('ScreenHeight') 
     265        sScreenWidth = self.settings.readSetting('ScreenWidth') 
     266        sResolution = sScreenWidth + 'x' + sScreenHeight 
     267 
     268        # On each: 
     269        # - Check to see whether the option within the xml matches the 
     270        #   option within the options menu 
     271        # - If they do not match, set the option within the xml to 
     272        #   to be what is within the options menu 
     273        # - Require a restart 
     274 
     275        if (int(enable_fullscreen) != int(sFullscreen)): 
    231276            self.setOption('FullScreen', int(enable_fullscreen)) 
    232277            self.requireRestart = True 
    233278             
    234         if (int(enable_sound) != int(self.settings.readSetting('PlaySounds'))): 
     279        if (int(enable_sound) != int(sSound)): 
    235280            self.setOption('PlaySounds', int(enable_sound)) 
    236281            self.requireRestart = True 
    237282 
    238         if (screen_resolution != self.Resolutions.index(str(self.settings.readSetting("ScreenWidth")) + 'x' + str(self.settings.readSetting("ScreenHeight")))): 
    239             self.setOption('ScreenWidth', int(self.Resolutions[screen_resolution].partition('x')[0])) 
    240             self.setOption('ScreenHeight', int(self.Resolutions[screen_resolution].partition('x')[2])) 
    241             self.requireRestart = True 
    242          
     283        if (screen_resolution != sResolution): 
     284            self.setOption('ScreenWidth', int(screen_width)) 
     285            self.setOption('ScreenHeight', int(screen_height)) 
     286            self.requireRestart = True 
     287 
     288        # Convert the number from the list of render backends to 
     289        # the string that FIFE wants for its settings.xml 
    243290        if (render_backend == 0): 
    244291            render_backend = 'OpenGL' 
     
    246293            render_backend = 'SDL' 
    247294 
    248         if (render_backend != str(self.settings.readSetting("RenderBackend"))): 
     295        if (render_backend != str(sRender)): 
    249296            self.setOption('RenderBackend', render_backend) 
    250297            self.requireRestart = True 
    251298 
    252         if (initial_volume != float(self.settings.readSetting("InitialVolume"))): 
     299        if (initial_volume != float(sVolume)): 
    253300            self.setOption('InitialVolume', initial_volume) 
    254301            self.requireRestart = True 
    255  
     302         
     303        # Write all the settings to settings.xml 
    256304        self.settings.tree.write('settings.xml') 
     305         
     306        # If the changes require a restart, popup the dialog telling 
     307        # the user to do so 
    257308        if (self.requireRestart): 
    258309            self.requireRestartDialog() 
     310        # Once we are done, we close the options menu 
    259311        self.options_menu.hide() 
    260312 
    261313    def setOption(self, name, value): 
    262314        """Set an option within the xml. 
    263            @type name: ??? 
    264            @param name: The name? 
    265            @type value: ??? 
    266            @param value: The value? 
     315           @type name: string 
     316           @param name: The name of the option within the xml 
     317           @type value: any 
     318           @param value: The value that the option 'name' should be set to 
    267319           @return: None""" 
    268320        element = self.settings.root_element.find(name) 
Note: See TracChangeset for help on using the changeset viewer.