Mercurial > parpg-core
annotate src/parpg/application.py @ 119:3564a46544bc
Added Base component, which has a saveable_fields property. It is supposed to be derived from, thus it is not in the components list.
author | KarstenBock@gmx.net |
---|---|
date | Tue, 27 Sep 2011 14:58:03 +0200 |
parents | 0443ab9533ce |
children | 59c9ce2b8351 |
rev | line source |
---|---|
0
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
1 # This program is free software: you can redistribute it and/or modify |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
2 # it under the terms of the GNU General Public License as published by |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
3 # the Free Software Foundation, either version 3 of the License, or |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
4 # (at your option) any later version. |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
5 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
6 # This program is distributed in the hope that it will be useful, |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
7 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
8 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
9 # GNU General Public License for more details. |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
10 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
11 # You should have received a copy of the GNU General Public License |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
12 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
13 """This module contains the main Application class |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
14 and the basic Listener for PARPG """ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
15 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
16 import os |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
17 import sys |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
18 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
19 from fife import fife |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
20 from fife.extensions import pychan |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
21 from fife.extensions.serializers.xmlanimation import XMLAnimationLoader |
39
8b3890f17f94
FifeManager no longer subclasses ApplicationBase
KarstenBock@gmx.net
parents:
30
diff
changeset
|
22 from fife.extensions.basicapplication import ApplicationBase |
0
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
23 |
12
d60f1dab8469
Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents:
0
diff
changeset
|
24 from parpg import console, vfs |
0
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
25 from parpg.font import PARPGFont |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
26 from parpg.gamemodel import GameModel |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
27 from parpg.mainmenuview import MainMenuView |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
28 from parpg.mainmenucontroller import MainMenuController |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
29 from parpg.common.listeners.event_listener import EventListener |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
30 from parpg.common.listeners.key_listener import KeyListener |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
31 from parpg.common.listeners.mouse_listener import MouseListener |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
32 from parpg.common.listeners.command_listener import CommandListener |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
33 from parpg.common.listeners.console_executor import ConsoleExecuter |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
34 from parpg.common.listeners.widget_listener import WidgetListener |
30
94cb5843dcbb
Modifications to use the grease manager and modes
KarstenBock@gmx.net
parents:
12
diff
changeset
|
35 from parpg.mode import FifeManager |
0
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
36 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
37 class KeyFilter(fife.IKeyFilter): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
38 """ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
39 This is the implementation of the fife.IKeyFilter class. |
45 | 40 |
0
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
41 Prevents any filtered keys from being consumed by guichan. |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
42 """ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
43 def __init__(self, keys): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
44 fife.IKeyFilter.__init__(self) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
45 self._keys = keys |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
46 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
47 def isFiltered(self, event): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
48 """Checks if an key is filtered""" |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
49 return event.getKey().getValue() in self._keys |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
50 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
51 class ApplicationListener(KeyListener, |
45 | 52 MouseListener, |
53 ConsoleExecuter, | |
54 CommandListener, | |
55 WidgetListener): | |
0
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
56 """Basic listener for PARPG""" |
45 | 57 |
0
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
58 def __init__(self, event_listener, engine, view, model): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
59 """Initialize the instance. |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
60 @type engine: fife.engine |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
61 @param engine: ??? |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
62 @type view: viewbase.ViewBase |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
63 @param view: View that draws the current state |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
64 @type model: GameModel |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
65 @param model: The game model""" |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
66 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
67 KeyListener.__init__(self, event_listener) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
68 MouseListener.__init__(self, event_listener) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
69 ConsoleExecuter.__init__(self, event_listener) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
70 CommandListener.__init__(self, event_listener) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
71 WidgetListener.__init__(self, event_listener) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
72 self.engine = engine |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
73 self.view = view |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
74 self.model = model |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
75 keyfilter = KeyFilter([fife.Key.ESCAPE]) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
76 keyfilter.__disown__() |
45 | 77 |
0
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
78 engine.getEventManager().setKeyFilter(keyfilter) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
79 self.quit = False |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
80 self.about_window = None |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
81 self.console = console.Console(self) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
82 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
83 def quitGame(self): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
84 """Forces a quit game on next cycle. |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
85 @return: None""" |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
86 self.quit = True |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
87 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
88 def onConsoleCommand(self, command): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
89 """ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
90 Called on every console comand, delegates calls to the a console |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
91 object, implementing the callbacks |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
92 @type command: string |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
93 @param command: the command to run |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
94 @return: result |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
95 """ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
96 return self.console.handleConsoleCommand(command) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
97 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
98 def onCommand(self, command): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
99 """Enables the game to be closed via the 'X' button on the window frame |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
100 @type command: fife.Command |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
101 @param command: The command to read. |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
102 @return: None""" |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
103 if(command.getCommandType() == fife.CMD_QUIT_GAME): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
104 self.quit = True |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
105 command.consume() |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
106 |
39
8b3890f17f94
FifeManager no longer subclasses ApplicationBase
KarstenBock@gmx.net
parents:
30
diff
changeset
|
107 class PARPGApplication(ApplicationBase): |
0
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
108 """Main Application class |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
109 We use an MVC model model |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
110 self.gamesceneview is our view,self.model is our model |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
111 self.controller is the controller""" |
45 | 112 |
0
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
113 def __init__(self, setting): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
114 """Initialise the instance. |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
115 @return: None""" |
45 | 116 self._setting = setting |
117 self.manager = FifeManager() | |
0
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
118 self.engine = fife.Engine() |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
119 self.loadSettings() |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
120 self.engine.init() |
12
d60f1dab8469
Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents:
0
diff
changeset
|
121 # KLUDGE M. George Hansen 2011-06-04: See parpg/vfs.py. |
d60f1dab8469
Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents:
0
diff
changeset
|
122 vfs.VFS = self.engine.getVFS() |
d60f1dab8469
Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents:
0
diff
changeset
|
123 vfs.VFS.addNewSource(setting.parpg.DataPath) |
0
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
124 self._animationloader = XMLAnimationLoader(self.engine.getImagePool(), |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
125 self.engine.getVFS()) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
126 self.engine.getAnimationPool().addResourceLoader(self._animationloader) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
127 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
128 pychan.init(self.engine, debug = True) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
129 pychan.setupModalExecution(self.mainLoop,self.breakFromMainLoop) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
130 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
131 self.quitRequested = False |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
132 self.breakRequested = False |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
133 self.returnValues = [] |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
134 #self.engine.getModel(self) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
135 self.model = GameModel(self.engine, setting) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
136 self.model.readMapFiles() |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
137 self.model.readObjectDB() |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
138 self.model.getAgentImportFiles() |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
139 self.model.readAllAgents() |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
140 self.model.getDialogues() |
12
d60f1dab8469
Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents:
0
diff
changeset
|
141 # KLUDGE M. George Hansen 2011-06-04: Hack to allow loaded PyChan XML |
d60f1dab8469
Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents:
0
diff
changeset
|
142 # scripts to locate their resources. |
d60f1dab8469
Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents:
0
diff
changeset
|
143 os.chdir(setting.parpg.DataPath) |
0
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
144 self.view = MainMenuView(self.engine, self.model) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
145 self.loadFonts() |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
146 self.event_listener = EventListener(self.engine) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
147 controller = MainMenuController(self.engine, self.view, self.model, |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
148 self) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
149 #controller.initHud() |
39
8b3890f17f94
FifeManager no longer subclasses ApplicationBase
KarstenBock@gmx.net
parents:
30
diff
changeset
|
150 self.manager.push_mode(controller) |
0
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
151 self.listener = ApplicationListener(self.event_listener, |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
152 self.engine, |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
153 self.view, |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
154 self.model) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
155 #start_map = self._setting.fife.get("PARPG", "Map") |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
156 #self.model.changeMap(start_map) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
157 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
158 def loadFonts(self): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
159 # add the fonts path to the system path to import font definitons |
12
d60f1dab8469
Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents:
0
diff
changeset
|
160 sys.path.insert(0, os.path.join(self._setting.parpg.DataPath, 'fonts')) |
0
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
161 from oldtypewriter import fontdefs |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
162 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
163 for fontdef in fontdefs: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
164 pychan.internal.get_manager().addFont(PARPGFont(fontdef, |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
165 self._setting)) |
45 | 166 |
0
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
167 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
168 def loadSettings(self): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
169 """ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
170 Load the settings from a python file and load them into the engine. |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
171 Called in the ApplicationBase constructor. |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
172 """ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
173 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
174 engineSetting = self.engine.getSettings() |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
175 engineSetting.setDefaultFontGlyphs(self._setting.fife.FontGlyphs) |
12
d60f1dab8469
Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents:
0
diff
changeset
|
176 engineSetting.setDefaultFontPath( |
d60f1dab8469
Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents:
0
diff
changeset
|
177 '{0}/fonts/{1}'.format(self._setting.parpg.DataPath, |
d60f1dab8469
Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents:
0
diff
changeset
|
178 self._setting.fife.Font) |
d60f1dab8469
Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents:
0
diff
changeset
|
179 ) |
0
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
180 engineSetting.setDefaultFontSize(self._setting.fife.DefaultFontSize) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
181 engineSetting.setBitsPerPixel(self._setting.fife.BitsPerPixel) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
182 engineSetting.setInitialVolume(self._setting.fife.InitialVolume) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
183 engineSetting.setSDLRemoveFakeAlpha(self._setting.fife.SDLRemoveFakeAlpha) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
184 engineSetting.setScreenWidth(self._setting.fife.ScreenWidth) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
185 engineSetting.setScreenHeight(self._setting.fife.ScreenHeight) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
186 engineSetting.setRenderBackend(self._setting.fife.RenderBackend) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
187 engineSetting.setFullScreen(self._setting.fife.FullScreen) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
188 engineSetting.setVideoDriver(self._setting.fife.VideoDriver) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
189 engineSetting.setLightingModel(self._setting.fife.Lighting) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
190 engineSetting.setColorKeyEnabled(self._setting.fife.ColorKeyEnabled) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
191 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
192 engineSetting.setColorKey(*[int(digit) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
193 for digit in self._setting.fife.ColorKey]) |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
194 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
195 engineSetting.setWindowTitle(self._setting.fife.WindowTitle) |
12
d60f1dab8469
Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents:
0
diff
changeset
|
196 engineSetting.setWindowIcon( |
d60f1dab8469
Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents:
0
diff
changeset
|
197 '/'.join(['gui/icons', self._setting.fife.WindowIcon]) |
d60f1dab8469
Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents:
0
diff
changeset
|
198 ) |
0
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
199 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
200 def createListener(self): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
201 """ __init__ takes care of creating an event listener, so |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
202 basicapplication's createListener is harmful. Without |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
203 overriding it, the program quit's on esc press, rather than |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
204 invoking the main menu |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
205 """ |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
206 pass |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
207 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
208 def _pump(self): |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
209 """Main game loop. |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
210 There are in fact 2 main loops, this one and the one in GameSceneView. |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
211 @return: None""" |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
212 if self.listener.quit: |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
213 self.breakRequested = True #pylint: disable-msg=C0103 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
214 else: |
45 | 215 self.manager._pump() |