Changeset 541 for trunk/game/scripts


Ignore:
Timestamp:
06/16/10 19:18:01 (10 years ago)
Author:
beliar
Message:
  • Change to make PARPG run with the latest FIFE revision (3373)
    • Removed argument to addCamera that FIFE no longer needs
  • Changed settings code to use the FIFE extension fife_settings
  • Additions to pylintrc
Location:
trunk/game/scripts
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/game/scripts/gui/hud.py

    r487 r541  
    6666        self.initializeMainMenu() 
    6767        self.initializeContextMenu() 
    68         self.initializeOptionsMenu() 
    6968        self.initializeHelpMenu() 
    7069        self.initializeEvents() 
     
    7776        self.hud.mapEvents(self.events_to_map)  
    7877        # set HUD size according to screen size 
    79         screen_width = int(self.settings.readSetting('ScreenWidth')) 
     78        screen_width = self.engine.getSettings().getScreenWidth() 
    8079        self.hud.findChild(name="mainHudWindow").size = (screen_width, 65) 
    8180        self.hud.findChild(name="inventoryButton").position = \ 
     
    167166        self.main_menu = pychan.loadXML("gui/hud_main_menu.xml") 
    168167        self.menu_events = {"resumeButton":self.hideMenu,  
    169                             "optionsButton":self.displayOptions, 
     168                            "optionsButton":self.settings.onOptionsPress, 
    170169                            "helpButton":self.displayHelp} 
    171170        self.main_menu.mapEvents(self.menu_events) 
     
    236235                                                     }) 
    237236         
    238     def initializeOptionsMenu(self): 
    239         """Initialize the options menu, this will generate a list of fullscreen 
    240            resolutions and a list of windowed resolutions. Next to this the  
    241            current active settings are read and also selected in the matching 
    242            widgets. 
    243            @return: None""" 
    244             
    245         self.options_menu = pychan.loadXML("gui/hud_options.xml") 
    246         self.options_events = {"applyButton":self.applyOptions, 
    247                                "closeButton":self.options_menu.hide, 
    248                                "defaultsButton":self.setToDefaults, 
    249                                "FullscreenBox": self.switchResolutions, 
    250                                "InitialVolumeSlider":self.updateVolumeText} 
    251          
    252         settings = self.engine.getSettings() 
    253         # The settings need to be set to fullscreen for the call to  
    254         # getPossibleResolutions() to function. 
    255         current_fullscreen = settings.isFullScreen() 
    256         settings.setFullScreen(True) 
    257          
    258         available_fullscreen_resolutions = settings.getPossibleResolutions() 
    259         available_windowed_resolutions = ((1920, 1200), (1920, 1080), \ 
    260                                           (1856, 1392), (1792, 1344), \ 
    261                                           (1680, 1050), (1600, 1200), \ 
    262                                           (1600, 1024), (1440,  900), \ 
    263                                           (1400, 1050), (1360,  768), \ 
    264                                           (1280, 1024), (1280,  960), \ 
    265                                           (1152,  864), (1024,  768)) 
    266         # Filter too small resolutions from the fullscreen resolutions 
    267         self.resolutions_fullscreen = [] 
    268         for x in available_fullscreen_resolutions: 
    269             if x[0] >= 1024 and x[1] >= 768: 
    270                 self.resolutions_fullscreen.append(str(x[0]) + 'x' + str(x[1])) 
    271  
    272         # Filter too large resolution from the windowed resolutions  
    273         self.resolutions_windowed = [] 
    274         for x in available_windowed_resolutions: 
    275             if x[0] <= available_fullscreen_resolutions[0][0] and \ 
    276             x[1] <= available_fullscreen_resolutions[0][1]: 
    277                 self.resolutions_windowed.append(str(x[0]) + 'x' + str(x[1]))         
    278          
    279         settings.setFullScreen(current_fullscreen) 
    280         self.render_backends = ['OpenGL', 'SDL'] 
    281         self.render_number = 0 
    282         if (str(self.settings.readSetting('RenderBackend')) == "SDL"): 
    283             self.render_number = 1 
    284         initial_volume = float(self.settings.readSetting('InitialVolume')) 
    285         initial_volume_text = str('Initial Volume: %.0f%s' % 
    286                                 (int(initial_volume*10), "%")) 
    287         initial_data_to_distribute = {     
    288                 'RenderBox'          : self.render_backends, 
    289                 'InitialVolumeLabel' : initial_volume_text 
    290                 } 
    291  
    292         s_fullscreen = self.settings.readSetting(name="FullScreen") 
    293         s_sounds = self.settings.readSetting(name="PlaySounds") 
    294         s_render = self.render_number 
    295         s_volume = initial_volume 
    296  
    297         # Find the current active resolution so we can select it  
    298         screen_width = self.settings.readSetting(name="ScreenWidth") 
    299         screen_height = self.settings.readSetting(name="ScreenHeight") 
    300         index_res = str(screen_width + 'x' + screen_height) 
    301         try: 
    302             if int(s_fullscreen) == 0: 
    303                 s_resolution = self.resolutions_windowed.index(index_res) 
    304             else: 
    305                 s_resolution = self.resolutions_fullscreen.index(index_res) 
    306             resolution_in_list = True 
    307         except: 
    308             resolution_in_list = False 
    309              
    310         data_to_distribute = { 
    311                 'FullscreenBox'      : int(s_fullscreen),  
    312                 'SoundsBox'          : int(s_sounds), 
    313                 'RenderBox'          : s_render, 
    314                 'InitialVolumeSlider': s_volume 
    315                 } 
    316  
    317         if int(s_fullscreen) == 0: 
    318             initial_data_to_distribute['ResolutionBox'] = self.resolutions_windowed 
    319         else: 
    320             initial_data_to_distribute['ResolutionBox'] = self.resolutions_fullscreen 
    321              
    322         if (resolution_in_list == True): 
    323             data_to_distribute['ResolutionBox'] = s_resolution 
    324  
    325         self.options_menu.distributeInitialData(initial_data_to_distribute) 
    326         self.options_menu.distributeData(data_to_distribute) 
    327         self.options_menu.mapEvents(self.options_events) 
     237 
    328238 
    329239    def saveGame(self): 
     
    461371                                    (int(volume*10), "%")) 
    462372 
    463     def requireRestartDialog(self): 
    464         """Show a dialog asking the user to restart PARPG in order for their 
    465            changes to take effect. 
    466            @return: None""" 
    467         require_restart_dialog = pychan.loadXML('gui/hud_require_restart.xml') 
    468         require_restart_dialog.mapEvents(\ 
    469                                 {'okButton':require_restart_dialog.hide}) 
    470         require_restart_dialog.show() 
    471  
    472     def applyOptions(self): 
    473         """Apply the current options. 
    474            @return: None""" 
    475         # At first no restart is required 
    476         self.require_restart = False 
    477  
    478         # get the current values of each setting from the options menu 
    479         enable_fullscreen = self.options_menu.collectData('FullscreenBox') 
    480         enable_sound = self.options_menu.collectData('SoundsBox') 
    481         screen_resolution = self.options_menu.collectData('ResolutionBox') 
    482         if enable_fullscreen: 
    483             partition = self.resolutions_fullscreen[screen_resolution].partition('x') 
    484         else: 
    485             partition = self.resolutions_windowed[screen_resolution].partition('x') 
    486         screen_width = partition[0] 
    487         screen_height = partition[2] 
    488         render_backend = self.options_menu.collectData('RenderBox') 
    489         initial_volume = self.options_menu.collectData('InitialVolumeSlider') 
    490         initial_volume = "%.1f" % initial_volume 
    491  
    492         # get the options that are being used right now from settings.xml 
    493         s_fullscreen = self.settings.readSetting('FullScreen') 
    494         s_sounds = self.settings.readSetting('PlaySounds') 
    495         s_render = self.settings.readSetting('RenderBackend') 
    496         s_volume = self.settings.readSetting('InitialVolume') 
    497  
    498         s_screen_height = self.settings.readSetting('ScreenHeight') 
    499         s_screen_width = self.settings.readSetting('ScreenWidth') 
    500         s_resolution = s_screen_width + 'x' + s_screen_height 
    501  
    502         # On each: 
    503         # - Check to see whether the option within the xml matches the 
    504         #   option within the options menu 
    505         # - If they do not match, set the option within the xml to 
    506         #   to be what is within the options menu 
    507         # - Require a restart 
    508  
    509         if (int(enable_fullscreen) != int(s_fullscreen)): 
    510             self.setOption('FullScreen', int(enable_fullscreen)) 
    511             self.require_restart = True 
    512              
    513         if (int(enable_sound) != int(s_sounds)): 
    514             self.setOption('PlaySounds', int(enable_sound)) 
    515             self.require_restart = True 
    516  
    517         if (screen_resolution != s_resolution): 
    518             self.setOption('ScreenWidth', int(screen_width)) 
    519             self.setOption('ScreenHeight', int(screen_height)) 
    520             self.require_restart = True 
    521  
    522         # Convert the number from the list of render backends to 
    523         # the string that FIFE wants for its settings.xml 
    524         if (render_backend == 0): 
    525             render_backend = 'OpenGL' 
    526         else: 
    527             render_backend = 'SDL' 
    528  
    529         if (render_backend != str(s_render)): 
    530             self.setOption('RenderBackend', render_backend) 
    531             self.require_restart = True 
    532  
    533         if (initial_volume != float(s_volume)): 
    534             self.setOption('InitialVolume', initial_volume) 
    535             self.require_restart = True 
    536          
    537         # Write all the settings to settings.xml 
    538         self.settings.saveSettings(); 
    539          
    540         # If the changes require a restart, popup the dialog telling 
    541         # the user to do so 
    542         if (self.require_restart): 
    543             self.requireRestartDialog() 
    544         # Once we are done, we close the options menu 
    545         self.options_menu.hide() 
    546  
    547373    def setOption(self, name, value): 
    548374        """Set an option within the xml. 
     
    565391        self.requireRestartDialog() 
    566392        self.options_menu.hide() 
    567  
    568     def displayOptions(self): 
    569         """Display the options menu. 
    570            @return: None""" 
    571         self.options_menu.show() 
    572393     
    573394    def readyAction(self, ready_button): 
  • trunk/game/scripts/map.py

    r501 r541  
    2020from local_loaders.loaders import loadMapFile 
    2121from scripts.common.eventlistenerbase import EventListenerBase 
    22 from settings import Setting 
     22from fife.extensions.fife_settings import Setting 
    2323 
    24 TDS = Setting() 
     24TDS = Setting(app_name="PARPG", 
     25              settings_file="./settings.xml",  
     26              settings_gui_xml="") 
    2527 
    2628class Map(fife.MapChangeListener): 
     
    124126        At this point we also set the viewport to the current resolution.""" 
    125127        for cam in self.map.getCameras(): 
    126             width = int(TDS.readSetting(name="ScreenWidth")) 
    127             height = int(TDS.readSetting(name="ScreenHeight")) 
     128            width = self.engine.getSettings().getScreenWidth() 
     129            height = self.engine.getSettings().getScreenHeight()  
    128130            viewport = fife.Rect(0,0,width,height) 
    129131            cam.setViewPort(viewport) 
     
    141143        text = self.engine.getGuiManager().\ 
    142144                        createFont('fonts/rpgfont.png', 0, \ 
    143                                    str(TDS.readSetting("FontGlyphs", \ 
    144                                                        strip=False))) 
     145                                   TDS.get("FIFE", "FontGlyphs")) 
    145146        rend.changeDefaultFont(text) 
    146147        rend.activateAllLayers(self.map) 
  • trunk/game/scripts/objects/actors.py

    r533 r541  
    2626__all__ = ["PlayerCharacter", "NonPlayerCharacter",] 
    2727 
    28 TDS = Setting() 
     28TDS = Setting(app_name="PARPG", 
     29              settings_file="./settings.xml",  
     30              settings_gui_xml="") 
    2931_AGENT_STATE_NONE, _AGENT_STATE_IDLE, _AGENT_STATE_APPROACH, _AGENT_STATE_RUN, _AGENT_STATE_WANDER, _AGENT_STATE_TALK = xrange(6) 
    3032 
     
    4446        self.state = _AGENT_STATE_NONE 
    4547        # TODO: rework/improve 
    46         self.speed = float(TDS.readSetting("PCSpeed"))-1 
     48        self.speed = TDS.get("PARPG", "PCSpeed")-1 
    4749         
    4850    def getX(self): 
     
    6769        self.idle_counter = 1 
    6870        # TODO: rework/improve 
    69         self.speed = float(TDS.readSetting("PCSpeed")) 
     71        self.speed = TDS.get("PARPG", "PCSpeed") 
    7072        self.nextAction = None 
    7173        self.agent = None 
  • trunk/game/scripts/objects/base.py

    r530 r541  
    5353            
    5454from fife import fife 
    55 from settings import Setting 
     55from fife.extensions.fife_settings import Setting 
    5656from random import randrange 
    5757from scripts.gui.popups import ExaminePopup, ContainerGUI 
  • trunk/game/scripts/world.py

    r527 r541  
    2727from local_loaders.loaders import loadMapFile 
    2828from sounds import SoundEngine 
    29 from settings import Setting 
     29from fife.extensions.fife_settings import Setting 
    3030from scripts.gui import hud 
    3131from scripts.gui.popups import * 
     
    3333from map import Map 
    3434 
    35 TDS = Setting() 
     35TDS = Setting(app_name="PARPG", 
     36              settings_file="./settings.xml",  
     37              settings_gui_xml="") 
    3638 
    3739# this file should be the meta-file for all FIFE-related code 
     
    7173 
    7274        # don't force restart if skipping to new section 
    73         if TDS.readSetting("PlaySounds") == "1": 
     75        if TDS.get("FIFE",  "PlaySounds"): 
    7476            if not self.sounds.music_init: 
    7577                self.sounds.playMusic(random.choice(glob.glob(os.path.join("music", "*.ogg"))))  
Note: See TracChangeset for help on using the changeset viewer.