Mercurial > parpg-source
comparison gui/hud.py @ 2:06145a6ee387
Fixed resource path dependencies issue that caused PARPG to crash on start.
* PARPG should now run without issue (system installation not tested).
* Utilized FIFE's VFS module to remove path dependencies from most PARPG modules.
* The new parpg.vfs module is a singleton with a single global variable, VFS, which is a reference to the global VFS instance. Although a singleton is not ideal it should be replaced once PARPG's core code is refactored.
* The parpg.vfs singleton is initialized in the parpg.applicaiton.PARPGApplication class with the absolute path to the data directory via the parpg.settings module and corresponding configuration file.
* A new DataPath entry was added to the default system configuration file template under the [parpg] section to support the new parpg.vfs module.
* Updated the parpg-assets subrepo to revision 3 to fix some dialog file format issues (for details see commit message for parpg-assets).
* Fixed a few bugs in the parpg.dialogueparsers.YAMLDialogueParser class related to exception handling.
author | M. George Hansen <technopolitica@gmail.com> |
---|---|
date | Mon, 06 Jun 2011 15:56:14 -1000 |
parents | 7a89ea5404b1 |
children | 98f26f7636d8 |
comparison
equal
deleted
inserted
replaced
1:4912a6f97c52 | 2:06145a6ee387 |
---|---|
17 import logging | 17 import logging |
18 | 18 |
19 from fife.extensions import pychan | 19 from fife.extensions import pychan |
20 from fife.extensions.pychan.tools import callbackWithArguments as cbwa | 20 from fife.extensions.pychan.tools import callbackWithArguments as cbwa |
21 | 21 |
22 from parpg import vfs | |
22 from parpg.gui.filebrowser import FileBrowser | 23 from parpg.gui.filebrowser import FileBrowser |
23 from parpg.gui.menus import ContextMenu, SettingsMenu | 24 from parpg.gui.menus import ContextMenu, SettingsMenu |
24 from parpg.gui import inventorygui | |
25 from parpg.gui.popups import ExaminePopup | 25 from parpg.gui.popups import ExaminePopup |
26 from parpg.gui.containergui import ContainerGUI | 26 from parpg.gui.containergui import ContainerGUI |
27 from parpg.gui.dialoguegui import DialogueGUI | 27 from parpg.gui.dialoguegui import DialogueGUI |
28 from parpg.gui import drag_drop_data as data_drag | 28 from parpg.gui import drag_drop_data as data_drag |
29 from parpg.gui.inventorygui import InventoryGUI | |
29 from actionsbox import ActionsBox | 30 from actionsbox import ActionsBox |
30 | 31 |
31 logger = logging.getLogger('hud') | 32 logger = logging.getLogger('hud') |
32 class Hud(object): | 33 class Hud(object): |
33 """Main Hud class""" | 34 """Main Hud class""" |
44 loadGame: called when the user clicks on Load | 45 loadGame: called when the user clicks on Load |
45 quitGame: called when the user clicks on Quit | 46 quitGame: called when the user clicks on Quit |
46 @return: None""" | 47 @return: None""" |
47 | 48 |
48 # TODO: perhaps this should not be hard-coded here | 49 # TODO: perhaps this should not be hard-coded here |
50 self.settings = settings | |
49 pychan.registerWidget(ActionsBox) | 51 pychan.registerWidget(ActionsBox) |
50 self.hud = pychan.loadXML("gui/hud.xml") | 52 |
53 xml_file = vfs.VFS.open('gui/hud.xml') | |
54 self.hud = pychan.loadXML(xml_file) | |
55 | |
51 self.controller = controller | 56 self.controller = controller |
52 self.engine = controller.engine | 57 self.engine = controller.engine |
53 self.model = controller.model | 58 self.model = controller.model |
54 self.settings = settings | |
55 self.inventory = None | 59 self.inventory = None |
56 self.character_screen = None | 60 self.character_screen = None |
57 | 61 |
58 self.save_game_callback = callbacks['saveGame'] | 62 self.save_game_callback = callbacks['saveGame'] |
59 self.load_game_callback = callbacks['loadGame'] | 63 self.load_game_callback = callbacks['loadGame'] |
150 self.enabled = False | 154 self.enabled = False |
151 | 155 |
152 def initializeInventory(self): | 156 def initializeInventory(self): |
153 """Initialize the inventory""" | 157 """Initialize the inventory""" |
154 if not self.inventory: | 158 if not self.inventory: |
155 self.inventory = inventorygui.InventoryGUI(self.controller, | 159 xml_file = vfs.VFS.open('gui/inventory.xml') |
156 None, | 160 self.inventory = InventoryGUI(self.controller, xml_file, None) |
157 None) | |
158 # inv_callbacks = { | 161 # inv_callbacks = { |
159 # 'refreshReadyImages': self.refreshReadyImages, | 162 # 'refreshReadyImages': self.refreshReadyImages, |
160 # 'toggleInventoryButton': self.toggleInventoryButton, | 163 # 'toggleInventoryButton': self.toggleInventoryButton, |
161 # } | 164 # } |
162 # self.inventory_storage = \ | 165 # self.inventory_storage = \ |
171 | 174 |
172 def initializeCharacterScreen(self): | 175 def initializeCharacterScreen(self): |
173 """Initialize the character screen.""" | 176 """Initialize the character screen.""" |
174 # TODO Technomage 2010-12-24: | 177 # TODO Technomage 2010-12-24: |
175 if not self.character_screen: | 178 if not self.character_screen: |
176 self.character_screen = pychan.loadXML('gui/character_screen.xml') | 179 xml_file = vfs.VFS.open('gui/character_screen.xml') |
177 | 180 self.character_screen = pychan.loadXML(xml_file) |
178 | 181 |
179 def initializeContextMenu(self): | 182 def initializeContextMenu(self): |
180 """Initialize the Context Menu | 183 """Initialize the Context Menu |
181 @return: None""" | 184 @return: None""" |
182 self.context_menu = ContextMenu (self.engine, [], (0, 0)) | 185 self.context_menu = ContextMenu(self.engine, [], (0, 0)) |
183 | 186 |
184 def showContextMenu(self, data, pos): | 187 def showContextMenu(self, data, pos): |
185 """Display the Context Menu with model at pos | 188 """Display the Context Menu with model at pos |
186 @type model: list | 189 @type model: list |
187 @param model: model to pass to context menu | 190 @param model: model to pass to context menu |
197 self.context_menu.hide() | 200 self.context_menu.hide() |
198 | 201 |
199 def initializeMainMenu(self): | 202 def initializeMainMenu(self): |
200 """Initalize the main menu. | 203 """Initalize the main menu. |
201 @return: None""" | 204 @return: None""" |
202 self.main_menu = pychan.loadXML("gui/hud_pause_menu.xml") | 205 |
206 xml_file = vfs.VFS.open('gui/hud_pause_menu.xml') | |
207 self.main_menu = pychan.loadXML(xml_file) | |
208 | |
203 #TODO: find more suitalbe place for onOptilonsPress implementation | 209 #TODO: find more suitalbe place for onOptilonsPress implementation |
204 self.menu_events = {"resumeButton": self.hideMenu, | 210 self.menu_events = {"resumeButton": self.hideMenu, |
205 "settingsButton": self.displaySettings, | 211 "settingsButton": self.displaySettings, |
206 "helpButton": self.displayHelp} | 212 "helpButton": self.displayHelp} |
207 self.main_menu.mapEvents(self.menu_events) | 213 self.main_menu.mapEvents(self.menu_events) |
235 self.settings_menu.show() | 241 self.settings_menu.show() |
236 | 242 |
237 def initializeHelpMenu(self): | 243 def initializeHelpMenu(self): |
238 """Initialize the help menu | 244 """Initialize the help menu |
239 @return: None""" | 245 @return: None""" |
240 self.help_dialog = pychan.loadXML("gui/help.xml") | 246 |
247 xml_file = vfs.VFS.open('gui/help.xml') | |
248 self.help_dialog = pychan.loadXML(xml_file) | |
249 | |
241 help_events = {"closeButton":self.help_dialog.hide} | 250 help_events = {"closeButton":self.help_dialog.hide} |
242 self.help_dialog.mapEvents(help_events) | 251 self.help_dialog.mapEvents(help_events) |
243 main_help_text = u"Welcome to Post-Apocalyptic RPG or PARPG![br][br]"\ | 252 main_help_text = u"Welcome to Post-Apocalyptic RPG or PARPG![br][br]"\ |
244 "This game is still in development, so please expect for there to be "\ | 253 "This game is still in development, so please expect for there to be "\ |
245 "bugs and[br]feel free to tell us about them at "\ | 254 "bugs and[br]feel free to tell us about them at "\ |
271 | 280 |
272 def saveGame(self): | 281 def saveGame(self): |
273 """ Called when the user wants to save the game. | 282 """ Called when the user wants to save the game. |
274 @return: None""" | 283 @return: None""" |
275 self.stopActions() | 284 self.stopActions() |
276 xml_path = os.path.join(self.settings.system_path, | 285 xml_path = 'gui/savebrowser.xml' |
277 self.settings.parpg.GuiPath, | |
278 'savebrowser.xml') | |
279 save_browser = FileBrowser(self.engine, | 286 save_browser = FileBrowser(self.engine, |
280 self.settings, | 287 self.settings, |
281 self.save_game_callback, | 288 self.save_game_callback, |
282 xml_path, | 289 xml_path, |
283 self.loadsave_close, | 290 self.loadsave_close, |
316 | 323 |
317 def loadGame(self): | 324 def loadGame(self): |
318 """ Called when the user wants to load a game. | 325 """ Called when the user wants to load a game. |
319 @return: None""" | 326 @return: None""" |
320 self.stopActions() | 327 self.stopActions() |
321 xml_path = os.path.join(self.settings.system_path, | 328 xml_path = 'gui/loadbrowser.xml' |
322 self.settings.parpg.GuiPath, | |
323 'loadbrowser.xml') | |
324 load_browser = FileBrowser(self.engine, | 329 load_browser = FileBrowser(self.engine, |
325 self.settings, | 330 self.settings, |
326 self.load_game_callback, | 331 self.load_game_callback, |
327 xml_path, | 332 xml_path, |
328 close_callback = self.loadsave_close, | 333 close_callback = self.loadsave_close, |
378 button.toggled = 0 | 383 button.toggled = 0 |
379 | 384 |
380 def toggleInventory(self, toggle_image=True): | 385 def toggleInventory(self, toggle_image=True): |
381 """Displays the inventory screen | 386 """Displays the inventory screen |
382 @return: None""" | 387 @return: None""" |
383 if self.inventory == None: | 388 if self.inventory is None: |
384 self.initializeInventory() | 389 self.initializeInventory() |
390 | |
385 self.inventory.toggleInventory(toggle_image) | 391 self.inventory.toggleInventory(toggle_image) |
386 | 392 |
387 def toggleCharacterScreen(self): | 393 def toggleCharacterScreen(self): |
388 if not self.character_screen: | 394 if self.characcter_screen is None: |
389 self.initializeCharacterScreen() | 395 self.initializeCharacterScreen() |
396 | |
390 if not self.character_screen.isVisible(): | 397 if not self.character_screen.isVisible(): |
391 self.character_screen.show() | 398 self.character_screen.show() |
392 else: | 399 else: |
393 self.character_screen.hide() | 400 self.character_screen.hide() |
394 | 401 |