Ignore:
Timestamp:
10/10/09 21:45:49 (10 years ago)
Author:
Kaydeth_parpg
Message:

Ticket #2: Patch by Kaydeth. Updated the rest of the classes in the scripts directory to correct some obvious discrepancies with our coding standard. Still need to go through the common and objects sub directories. comment[s:trac, t:2]

File:
1 edited

Legend:

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

    r304 r313  
    1616#   along with PARPG.  If not, see <http://www.gnu.org/licenses/>. 
    1717 
    18 import shutil, fife, pychan 
     18import shutil 
     19import fife 
     20import pychan 
    1921import pychan.widgets as widgets 
    2022from pychan.tools import callbackWithArguments as cbwa 
     
    5254        } 
    5355 
    54         self.inventory = inventory.Inventory(self.engine, inv_model, inv_callbacks) 
     56        self.inventory = inventory.Inventory(self.engine, \ 
     57                                             inv_model, inv_callbacks) 
    5558        self.refreshReadyImages() 
    5659 
    57         self.saveGameCallback = callbacks['saveGame'] 
    58         self.loadGameCallback = callbacks['loadGame'] 
    59         self.quitCallback     = callbacks['quitGame'] 
     60        self.save_game_callback = callbacks['saveGame'] 
     61        self.load_game_callback = callbacks['loadGame'] 
     62        self.quit_callback     = callbacks['quitGame'] 
    6063 
    6164        self.box_container = None 
    6265        self.examine_box = None 
    6366 
    64         self.actionsBox = self.hud.findChild(name="actionsBox") 
    65         self.actionsText = [] 
     67        self.actions_box = self.hud.findChild(name="actionsBox") 
     68        self.actions_text = [] 
    6669        self.menu_displayed = False 
    6770        self.initializeHud() 
     
    8184        screen_width = int(self.settings.readSetting('ScreenWidth')) 
    8285        self.hud.findChild(name="mainHudWindow").size = (screen_width, 65) 
    83         self.hud.findChild(name="inventoryButton").position = (screen_width-59, 7) 
     86        self.hud.findChild(name="inventoryButton").position = \ 
     87                                                    (screen_width-59, 7) 
    8488        # add ready slots 
    8589        ready1 = self.hud.findChild(name='hudReady1') 
     
    109113    def refreshActionsBox(self): 
    110114        """Refresh the actions box so that it displays the contents of 
    111            self.actionsText 
    112            @return: None""" 
    113         self.actionsBox.items = self.actionsText 
     115           self.actions_text 
     116           @return: None""" 
     117        self.actions_box.items = self.actions_text 
    114118 
    115119    def addAction(self, action): 
     
    118122           @param action: The text that you want to display in the actions box 
    119123           @return: None""" 
    120         self.actionsText.insert(0, action) 
     124        self.actions_text.insert(0, action) 
    121125        self.refreshActionsBox() 
    122126 
     
    183187        self.help_dialog.mapEvents(help_events) 
    184188        main_help_text = u"Welcome to Post-Apocalyptic RPG or PARPG![br][br]"\ 
    185         "This game is still in development, so please expect for there to be bugs"\ 
    186         " and[br]feel free to tell us about them at http://www.forums.parpg.net.[br]"\ 
    187         "This game uses a \"Point 'N' Click\" interface, which means that to move around,[br]"\ 
    188         "just click where you would like to go and your character will move there.[br]"\ 
    189         "PARPG also utilizes a context menu. To access this, just right click "\ 
    190         "anywhere[br]on the screen and a menu will come up. This menu will change"\ 
    191         " depending on[br]what you have clicked on, hence it's name \"context menu\".[br][br]" 
     189        "This game is still in development, so please expect for there to be "\ 
     190        "bugs and[br]feel free to tell us about them at "\ 
     191        "http://www.forums.parpg.net.[br]This game uses a "\ 
     192        "\"Point 'N' Click\" interface, which means that to move around,[br]"\ 
     193        "just click where you would like to go and your character will move "\ 
     194        "there.[br]PARPG also utilizes a context menu. To access this, just "\ 
     195        "right click anywhere[br]on the screen and a menu will come up. This "\ 
     196        "menu will change depending on[br]what you have clicked on, hence "\ 
     197        "it's name \"context menu\".[br][br]" 
    192198         
    193199        k_text = u" Keybindings"  
    194         k_text+="[br] A : Add a test action to the actions display" 
    195         k_text+="[br] I : Toggle the inventory screen" 
    196         k_text+="[br] F5 : Take a screenshot" 
    197         k_text+="[br]      (saves to <parpg>/screenshots/)" 
    198         k_text+="[br] Q : Quit the game" 
     200        k_text += "[br] A : Add a test action to the actions display" 
     201        k_text += "[br] I : Toggle the inventory screen" 
     202        k_text += "[br] F5 : Take a screenshot" 
     203        k_text += "[br]      (saves to <parpg>/screenshots/)" 
     204        k_text += "[br] Q : Quit the game" 
    199205        self.help_dialog.distributeInitialData({ 
    200206                "MainHelpText":main_help_text, 
     
    219225        current_fullscreen = settings.isFullScreen() 
    220226        settings.setFullScreen(True) 
    221         availableResolutions = settings.getPossibleResolutions() 
     227        available_resolutions = settings.getPossibleResolutions() 
    222228 
    223229        # Filter too small resolutions 
    224         self.Resolutions=[] 
    225         for x in availableResolutions: 
     230        self.resolutions=[] 
     231        for x in available_resolutions: 
    226232            if x[0]>=1024 and x[1]>=768: 
    227                 self.Resolutions.append(str(x[0])+'x'+str(x[1])) 
     233                self.resolutions.append(str(x[0])+'x'+str(x[1])) 
    228234 
    229235        settings.setFullScreen(current_fullscreen) 
    230         self.RenderBackends = ['OpenGL', 'SDL'] 
    231         self.renderNumber = 0 
     236        self.render_backends = ['OpenGL', 'SDL'] 
     237        self.render_number = 0 
    232238        if (str(self.settings.readSetting('RenderBackend')) == "SDL"): 
    233             self.renderNumber = 1 
    234         initialVolume = float(self.settings.readSetting('InitialVolume')) 
    235         initialVolumeText = str('Initial Volume: %.0f%s' % 
    236                                 (int(initialVolume*10), "%")) 
     239            self.render_number = 1 
     240        initial_volume = float(self.settings.readSetting('InitialVolume')) 
     241        initial_volume_text = str('Initial Volume: %.0f%s' % 
     242                                (int(initial_volume*10), "%")) 
    237243        self.options_menu.distributeInitialData({ 
    238                 'ResolutionBox': self.Resolutions, 
    239                 'RenderBox': self.RenderBackends, 
    240                 'InitialVolumeLabel' : initialVolumeText 
     244                'ResolutionBox': self.resolutions, 
     245                'RenderBox': self.render_backends, 
     246                'InitialVolumeLabel' : initial_volume_text 
    241247                }) 
    242248 
    243         sFullscreen = self.settings.readSetting(name="FullScreen") 
    244         sSounds = self.settings.readSetting(name="PlaySounds") 
    245         sRender = self.renderNumber 
    246         sVolume = initialVolume 
     249        s_fullscreen = self.settings.readSetting(name="FullScreen") 
     250        s_sounds = self.settings.readSetting(name="PlaySounds") 
     251        s_render = self.render_number 
     252        s_volume = initial_volume 
    247253 
    248254        screen_width = self.settings.readSetting(name="ScreenWidth") 
    249255        screen_height = self.settings.readSetting(name="ScreenHeight") 
    250         indexRes = str(screen_width + 'x' + screen_height) 
     256        index_res = str(screen_width + 'x' + screen_height) 
    251257        try: 
    252             sResolution = self.Resolutions.index(indexRes) 
    253             resolutionInList = True 
     258            s_resolution = self.resolutions.index(index_res) 
     259            resolution_in_list = True 
    254260        except: 
    255             resolutionInList = False 
    256  
    257         dataToDistribute = { 
    258                 'FullscreenBox':int(sFullscreen),  
    259                 'SoundsBox':int(sSounds), 
    260                 'RenderBox': sRender, 
    261                 'InitialVolumeSlider':sVolume 
     261            resolution_in_list = False 
     262 
     263        data_to_distribute = { 
     264                'FullscreenBox':int(s_fullscreen),  
     265                'SoundsBox':int(s_sounds), 
     266                'RenderBox': s_render, 
     267                'InitialVolumeSlider':s_volume 
    262268                } 
    263269 
    264         if (resolutionInList == True): 
    265             dataToDistribute['ResolutionBox'] = sResolution 
    266  
    267         self.options_menu.distributeData(dataToDistribute) 
     270        if (resolution_in_list == True): 
     271            data_to_distribute['ResolutionBox'] = s_resolution 
     272 
     273        self.options_menu.distributeData(data_to_distribute) 
    268274 
    269275        self.options_menu.mapEvents(self.options_events) 
     
    273279            @return: None""" 
    274280        save_browser = FileBrowser(self.engine, 
    275                                    self.saveGameCallback, 
    276                                    savefile=True, 
    277                                    guixmlpath="gui/savebrowser.xml", 
     281                                   self.save_game_callback, 
     282                                   save_file=True, 
     283                                   gui_xml_path="gui/savebrowser.xml", 
    278284                                   extensions = ('.dat')) 
    279285        save_browser.showBrowser() 
     
    288294            @return: None""" 
    289295        load_browser = FileBrowser(self.engine, 
    290                                    self.loadGameCallback, 
    291                                    savefile=False, 
    292                                    guixmlpath='gui/loadbrowser.xml', 
     296                                   self.load_game_callback, 
     297                                   save_file=False, 
     298                                   gui_xml_path='gui/loadbrowser.xml', 
    293299                                   extensions=('.dat')) 
    294300        load_browser.showBrowser() 
     
    297303        """Creates the quit confirmation dialog 
    298304           @return: None""" 
    299         self.quitWindow = pychan.widgets.Window(title=unicode("Quit?"),min_size=(200,0)) 
     305        self.quit_window = pychan.widgets.Window(title=unicode("Quit?"), \ 
     306                                                 min_size=(200,0)) 
    300307 
    301308        hbox = pychan.widgets.HBox() 
     
    311318                                          max_size=(90,20)) 
    312319 
    313         self.quitWindow.addChild(label) 
     320        self.quit_window.addChild(label) 
    314321        hbox.addChild(yes_button) 
    315322        hbox.addChild(no_button) 
    316         self.quitWindow.addChild(hbox) 
    317  
    318         events_to_map = { "yes_button": self.quitCallback, 
    319                           "no_button":  self.quitWindow.hide } 
     323        self.quit_window.addChild(hbox) 
     324 
     325        events_to_map = { "yes_button": self.quit_callback, 
     326                          "no_button":  self.quit_window.hide } 
    320327         
    321         self.quitWindow.mapEvents(events_to_map) 
     328        self.quit_window.mapEvents(events_to_map) 
    322329 
    323330 
     
    326333           @return: None""" 
    327334 
    328         self.quitWindow.show() 
     335        self.quit_window.show() 
    329336 
    330337    def toggleInventoryButton(self): 
     
    377384        # when we click the toggle button don't change the image 
    378385        events_to_map["inventoryButton"] = cbwa(self.toggleInventory, False) 
    379         events_to_map["saveButton"] = self.saveGame 
    380         events_to_map["loadButton"] = self.loadGame 
    381  
    382         hud_ready_buttons = ["hudReady1", "hudReady2", "hudReady3", "hudReady4"] 
     386        events_to_map["saveButton"] = self.save_game_callback 
     387        events_to_map["loadButton"] = self.load_game_callback 
     388 
     389        hud_ready_buttons = ["hudReady1", "hudReady2", \ 
     390                             "hudReady3", "hudReady4"] 
    383391 
    384392        for item in hud_ready_buttons: 
     
    390398        menu_events["newButton"] = self.newGame 
    391399        menu_events["quitButton"] = self.quitGame 
    392         menu_events["saveButton"] = self.saveGame 
    393         menu_events["loadButton"] = self.loadGame 
     400        menu_events["saveButton"] = self.save_game_callback 
     401        menu_events["loadButton"] = self.load_game_callback 
    394402        self.main_menu.mapEvents(menu_events) 
    395403 
     
    408416           @return: None""" 
    409417        require_restart_dialog = pychan.loadXML('gui/hud_require_restart.xml') 
    410         require_restart_dialog.mapEvents({'okButton':require_restart_dialog.hide}) 
     418        require_restart_dialog.mapEvents(\ 
     419                                {'okButton':require_restart_dialog.hide}) 
    411420        require_restart_dialog.show() 
    412421 
     
    415424           @return: None""" 
    416425        # At first no restart is required 
    417         self.requireRestart = False 
     426        self.require_restart = False 
    418427 
    419428        # get the current values of each setting from the options menu 
     
    421430        enable_sound = self.options_menu.collectData('SoundsBox') 
    422431        screen_resolution = self.options_menu.collectData('ResolutionBox') 
    423         partition = self.Resolutions[screen_resolution].partition('x') 
     432        partition = self.resolutions[screen_resolution].partition('x') 
    424433        screen_width = partition[0] 
    425434        screen_height = partition[2] 
     
    429438 
    430439        # get the options that are being used right now from settings.xml 
    431         sFullscreen = self.settings.readSetting('FullScreen') 
    432         sSound = self.settings.readSetting('PlaySounds') 
    433         sRender = self.settings.readSetting('RenderBackend') 
    434         sVolume = self.settings.readSetting('InitialVolume') 
    435  
    436         sScreenHeight = self.settings.readSetting('ScreenHeight') 
    437         sScreenWidth = self.settings.readSetting('ScreenWidth') 
    438         sResolution = sScreenWidth + 'x' + sScreenHeight 
     440        s_fullscreen = self.settings.readSetting('FullScreen') 
     441        s_sounds = self.settings.readSetting('PlaySounds') 
     442        s_render = self.settings.readSetting('RenderBackend') 
     443        s_volume = self.settings.readSetting('InitialVolume') 
     444 
     445        s_screen_height = self.settings.readSetting('ScreenHeight') 
     446        s_screen_width = self.settings.readSetting('ScreenWidth') 
     447        s_resolution = s_screen_width + 'x' + s_screen_height 
    439448 
    440449        # On each: 
     
    445454        # - Require a restart 
    446455 
    447         if (int(enable_fullscreen) != int(sFullscreen)): 
     456        if (int(enable_fullscreen) != int(s_fullscreen)): 
    448457            self.setOption('FullScreen', int(enable_fullscreen)) 
    449             self.requireRestart = True 
     458            self.require_restart = True 
    450459             
    451         if (int(enable_sound) != int(sSound)): 
     460        if (int(enable_sound) != int(s_sounds)): 
    452461            self.setOption('PlaySounds', int(enable_sound)) 
    453             self.requireRestart = True 
    454  
    455         if (screen_resolution != sResolution): 
     462            self.require_restart = True 
     463 
     464        if (screen_resolution != s_resolution): 
    456465            self.setOption('ScreenWidth', int(screen_width)) 
    457466            self.setOption('ScreenHeight', int(screen_height)) 
    458             self.requireRestart = True 
     467            self.require_restart = True 
    459468 
    460469        # Convert the number from the list of render backends to 
     
    465474            render_backend = 'SDL' 
    466475 
    467         if (render_backend != str(sRender)): 
     476        if (render_backend != str(s_render)): 
    468477            self.setOption('RenderBackend', render_backend) 
    469             self.requireRestart = True 
    470  
    471         if (initial_volume != float(sVolume)): 
     478            self.require_restart = True 
     479 
     480        if (initial_volume != float(s_volume)): 
    472481            self.setOption('InitialVolume', initial_volume) 
    473             self.requireRestart = True 
     482            self.require_restart = True 
    474483         
    475484        # Write all the settings to settings.xml 
     
    478487        # If the changes require a restart, popup the dialog telling 
    479488        # the user to do so 
    480         if (self.requireRestart): 
     489        if (self.require_restart): 
    481490            self.requireRestartDialog() 
    482491        # Once we are done, we close the options menu 
     
    526535            data = ["dagger01", "empty", "empty", "empty", "empty", 
    527536                    "empty", "empty", "empty", "empty"] 
    528             self.box_container = ContainerGUI(self.engine, unicode(title), data) 
    529             def close_and_delete(): 
     537            self.box_container = ContainerGUI(self.engine, \ 
     538                                              unicode(title), data) 
     539            def closeAndDelete(): 
    530540                self.hideContainer() 
    531             events = {'takeAllButton':close_and_delete, 
    532                       'closeButton':close_and_delete} 
     541            events = {'takeAllButton':closeAndDelete, 
     542                      'closeButton':closeAndDelete} 
    533543            self.box_container.container_gui.mapEvents(events) 
    534544            self.box_container.showContainer() 
     
    549559           @return: None""" 
    550560 
    551         if self.examine_box: 
     561        if self.examine_box is not None: 
    552562            self.examine_box.closePopUp() 
    553563        self.examine_box = ExaminePopup(self.engine, title, desc) 
Note: See TracChangeset for help on using the changeset viewer.