source: branches/active/character_customization/game/parpg/controllerbase.py @ 809

Revision 809, 4.0 KB checked in by aspidites, 8 years ago (diff)

Patch by Aspidites:

  • Modified settings api slightly to prepare for other changes. Settings.filenames is replaced by Settings.paths as it will be more useful, IMHO.
  • Added copyright notice to settings module
  • Renamed DataDirectory? to SystemDataDirectory? and added UserDataDirectory? to [fife] section of default config file.
  • Implemented proper command line interface for settings.py

+ If multiple system names are given, multiple settings files

are generated, with the system name prepended to the filename

+ Both system and user data directories may be specified

+ It is possible to change the filename
+ not speficying anything will assume the system to be the one that

the script was run on and a filename of system.cfg

  • saves directory is now configurable (located in user's data directory by default
  • removed hard coded paths to open and save file browsers
  • removed default argument for FileBrowser?'s gui xml since it didnt' exist
  • screenshot directory now resides in user data directory
  • updated help screen
  • screenshots directory is now created only when its needed
  • when saving of games is implemented, the same should be done for the saves directory
  • Property svn:eol-style set to native
Line 
1#   This file is part of PARPG.
2
3#   PARPG is free software: you can redistribute it and/or modify
4#   it under the terms of the GNU General Public License as published by
5#   the Free Software Foundation, either version 3 of the License, or
6#   (at your option) any later version.
7
8#   PARPG is distributed in the hope that it will be useful,
9#   but WITHOUT ANY WARRANTY; without even the implied warranty of
10#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11#   GNU General Public License for more details.
12
13#   You should have received a copy of the GNU General Public License
14#   along with PARPG.  If not, see <http://www.gnu.org/licenses/>.
15import os
16from fife import fife
17
18from parpg.common.listeners.key_listener import KeyListener
19from parpg.common.listeners.mouse_listener import MouseListener
20from parpg.common.listeners.command_listener import CommandListener
21
22class ControllerBase(KeyListener, MouseListener, CommandListener):
23    """Base of Controllers"""
24    def __init__(self, 
25                 engine, 
26                 view, 
27                 model, 
28                 application):
29        '''
30        Constructor
31        @param engine: Instance of the active fife engine
32        @type engine: fife.Engine
33        @param view: Instance of a GameSceneView
34        @param type: parpg.GameSceneView
35        @param model: The model that has the current gamestate
36        @type model: parpg.GameModel
37        @param application: The application that created this controller
38        @type application: parpg.PARPGApplication
39        @param settings: The current settings of the application
40        @type settings: fife.extensions.fife_settings.Setting
41        '''
42        KeyListener.__init__(self, application.event_listener)       
43        MouseListener.__init__(self, application.event_listener)
44        CommandListener.__init__(self, application.event_listener)
45        self.engine = engine
46        self.event_manager = engine.getEventManager()
47        self.view = view
48        self.model = model
49        self.application = application
50       
51    def pause(self, paused):
52        """Stops receiving events"""
53        if paused:
54            KeyListener.detach(self)
55            MouseListener.detach(self)
56        else:
57            KeyListener.attach(self, self.application.event_listener)
58            MouseListener.attach(self, self.application.event_listener)
59   
60    def setMouseCursor(self, image, dummy_image, mc_type="native"): 
61        """Set the mouse cursor to an image.
62           @type image: string
63           @param image: The image you want to set the cursor to
64           @type dummy_image: string
65           @param dummy_image: ???
66           @type type: string
67           @param type: ???
68           @return: None"""
69        cursor = self.engine.getCursor()
70        cursor_type = fife.CURSOR_IMAGE
71        img_pool = self.engine.getImagePool()
72        if(mc_type == "target"):
73            target_cursor_id = img_pool.addResourceFromFile(image) 
74            dummy_cursor_id = img_pool.addResourceFromFile(dummy_image)
75            cursor.set(cursor_type, dummy_cursor_id)
76            cursor.setDrag(cursor_type, target_cursor_id, -16, -16)
77        else:
78            cursor_type = fife.CURSOR_IMAGE
79            zero_cursor_id = img_pool.addResourceFromFile(image)
80            cursor.set(cursor_type, zero_cursor_id)
81            cursor.setDrag(cursor_type, zero_cursor_id)
82
83    def resetMouseCursor(self):
84        """Reset cursor to default image.
85           @return: None"""
86        image = os.path.join(self.model.settings.fife.SystemDataDirectory,
87                             self.model.settings.parpg.GuiDirectory,
88                             self.model.settings.parpg.CursorDirectory,
89                             self.model.settings.parpg.CursorDefault)
90        self.setMouseCursor(image, image)
91       
92    def onStop(self):
93        """Called when the controller is removed from the list"""
94        pass 
95               
96    def pump(self):
97        """This method gets called every frame"""
98        pass
99   
Note: See TracBrowser for help on using the repository browser.