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

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

Patch by Aspidites

  • Removed SystemDataDirectory? and UserDataDirectory?
    • it is the the settings module's job to keep track of this sort of thing, not fife or PARPG's
    • consequently, setting.py's command line interface became simple
    • this will also prevent those "I generated a settings file but PARPG doesnt run" complaints
    • I think I'm going to have some helper methods to generate platform-specific paths at run-time
  • User data directory is now properly created
  • added platform_paths(system) which returns the platform-specific paths for the given system
  • if no system is given, it gives the paths for the system that the script was run on
  • changed logic of settings.py so that it is not required to pass a path.
  • not passing a path invokes paltform_paths
  • 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.paths['system'],
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.