1 | #!/usr/bin/python |
---|
2 | |
---|
3 | # This file is part of PARPG. |
---|
4 | |
---|
5 | # PARPG is free software: you can redistribute it and/or modify |
---|
6 | # it under the terms of the GNU General Public License as published by |
---|
7 | # the Free Software Foundation, either version 3 of the License, or |
---|
8 | # (at your option) any later version. |
---|
9 | |
---|
10 | # PARPG is distributed in the hope that it will be useful, |
---|
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
13 | # GNU General Public License for more details. |
---|
14 | |
---|
15 | # You should have received a copy of the GNU General Public License |
---|
16 | # along with PARPG. If not, see <http://www.gnu.org/licenses/>. |
---|
17 | |
---|
18 | import shutil, fife, pychan |
---|
19 | import pychan.widgets as widgets |
---|
20 | from pychan.tools import callbackWithArguments as cbwa |
---|
21 | from scripts.parpgfilebrowser import PARPGFileBrowser |
---|
22 | from scripts.context_menu import ContextMenu |
---|
23 | from scripts import inventory |
---|
24 | from scripts.popups import ExaminePopup, ContainerGUI |
---|
25 | from scripts.dialoguegui import DialogueGUI |
---|
26 | |
---|
27 | class Hud(object): |
---|
28 | """Main Hud class""" |
---|
29 | def __init__(self, engine, settings, inv_model, callbacks): |
---|
30 | """Initialise the instance. |
---|
31 | @type engine: fife.Engine |
---|
32 | @param engine: An instance of the fife engine |
---|
33 | @type settings: settings.Setting |
---|
34 | @param settings: The settings data |
---|
35 | @type inv_model: dict |
---|
36 | @type callbacks: dict |
---|
37 | @param callbacks: a dict of callbacks |
---|
38 | saveGame: called when the user clicks on Save |
---|
39 | loadGame: called when the user clicks on Load |
---|
40 | quitGame: called when the user clicks on Quit |
---|
41 | @return: None""" |
---|
42 | pychan.init(engine, debug = True) |
---|
43 | |
---|
44 | # TODO: perhaps this should not be hard-coded here |
---|
45 | self.hud = pychan.loadXML("gui/hud.xml") |
---|
46 | self.engine = engine |
---|
47 | self.settings = settings |
---|
48 | |
---|
49 | inv_callbacks = { |
---|
50 | 'refreshReadyImages': self.refreshReadyImages, |
---|
51 | 'toggleInventoryButton': self.toggleInventoryButton, |
---|
52 | } |
---|
53 | |
---|
54 | self.inventory = inventory.Inventory(self.engine, inv_model, inv_callbacks) |
---|
55 | self.refreshReadyImages() |
---|
56 | |
---|
57 | self.saveGameCallback = callbacks['saveGame'] |
---|
58 | self.loadGameCallback = callbacks['loadGame'] |
---|
59 | self.quitCallback = callbacks['quitGame'] |
---|
60 | |
---|
61 | self.box_container = None |
---|
62 | self.examine_box = None |
---|
63 | |
---|
64 | self.actionsBox = self.hud.findChild(name="actionsBox") |
---|
65 | self.actionsText = [] |
---|
66 | self.menu_displayed = False |
---|
67 | self.initializeHud() |
---|
68 | self.initializeMainMenu() |
---|
69 | self.initializeContextMenu() |
---|
70 | self.initializeOptionsMenu() |
---|
71 | self.initializeHelpMenu() |
---|
72 | self.initializeEvents() |
---|
73 | self.initializeQuitDialog() |
---|
74 | |
---|
75 | def initializeHud(self): |
---|
76 | """Initialize and show the main HUD |
---|
77 | @return: None""" |
---|
78 | self.events_to_map = {"menuButton":self.displayMenu,} |
---|
79 | self.hud.mapEvents(self.events_to_map) |
---|
80 | # set HUD size accoriding to screen size |
---|
81 | screen_width = int(self.settings.readSetting('ScreenWidth')) |
---|
82 | self.hud.findChild(name="mainHudWindow").size = (screen_width, 65) |
---|
83 | self.hud.findChild(name="inventoryButton").position = (screen_width-59, 7) |
---|
84 | # add ready slots |
---|
85 | ready1 = self.hud.findChild(name='hudReady1') |
---|
86 | ready2 = self.hud.findChild(name='hudReady2') |
---|
87 | ready3 = self.hud.findChild(name='hudReady3') |
---|
88 | ready4 = self.hud.findChild(name='hudReady4') |
---|
89 | actions_scroll_area = self.hud.findChild(name='actionsScrollArea') |
---|
90 | if (screen_width <=800) : |
---|
91 | gap = 0 |
---|
92 | else : |
---|
93 | gap = 40 |
---|
94 | # annoying code that is both essential and boring to enter |
---|
95 | ready1.position = (160+gap, 7) |
---|
96 | ready2.position = (220+gap, 7) |
---|
97 | ready3.position = (screen_width-180-gap, 7) |
---|
98 | ready4.position = (screen_width-120-gap, 7) |
---|
99 | actions_scroll_area.position = (280+gap, 5) |
---|
100 | actions_width = screen_width - 470 - 2*gap |
---|
101 | |
---|
102 | # and finally add an actions box |
---|
103 | self.hud.findChild(name="actionsBox").min_size = (actions_width, 0) |
---|
104 | actions_scroll_area.min_size = (actions_width, 55) |
---|
105 | actions_scroll_area.max_size = (actions_width, 55) |
---|
106 | # now it should be OK to display it all |
---|
107 | self.hud.show() |
---|
108 | |
---|
109 | def refreshActionsBox(self): |
---|
110 | """Refresh the actions box so that it displays the contents of |
---|
111 | self.actionsText |
---|
112 | @return: None""" |
---|
113 | self.actionsBox.items = self.actionsText |
---|
114 | |
---|
115 | def addAction(self, action): |
---|
116 | """Add an action to the actions box. |
---|
117 | @type action: string |
---|
118 | @param action: The text that you want to display in the actions box |
---|
119 | @return: None""" |
---|
120 | self.actionsText.insert(0, action) |
---|
121 | self.refreshActionsBox() |
---|
122 | |
---|
123 | def showHUD(self): |
---|
124 | """Show the HUD. |
---|
125 | @return: None""" |
---|
126 | self.hud.show() |
---|
127 | |
---|
128 | def hideHUD(self): |
---|
129 | """Hide the HUD. |
---|
130 | @return: None""" |
---|
131 | self.hud.hide() |
---|
132 | |
---|
133 | def initializeContextMenu(self): |
---|
134 | """Initialize the Context Menu |
---|
135 | @return: None""" |
---|
136 | self.context_menu = ContextMenu (self.engine, [], (0,0)) |
---|
137 | self.context_menu.hide() |
---|
138 | |
---|
139 | def showContextMenu(self, data, pos): |
---|
140 | """Display the Context Menu with data at pos |
---|
141 | @type data: list |
---|
142 | @param data: data to pass to context menu |
---|
143 | @type pos: tuple |
---|
144 | @param pos: tuple of x and y coordinates |
---|
145 | @return: None""" |
---|
146 | self.context_menu = ContextMenu(self.engine, data, pos) |
---|
147 | |
---|
148 | def hideContextMenu(self): |
---|
149 | """Hides the context menu |
---|
150 | @return: None""" |
---|
151 | self.context_menu.hide() |
---|
152 | |
---|
153 | def initializeMainMenu(self): |
---|
154 | """Initalize the main menu. |
---|
155 | @return: None""" |
---|
156 | self.main_menu = pychan.loadXML("gui/hud_main_menu.xml") |
---|
157 | self.menu_events = {"resumeButton":self.hideMenu, |
---|
158 | "optionsButton":self.displayOptions, |
---|
159 | "helpButton":self.displayHelp} |
---|
160 | self.main_menu.mapEvents(self.menu_events) |
---|
161 | |
---|
162 | def displayMenu(self): |
---|
163 | """Displays the main in-game menu. |
---|
164 | @return: None""" |
---|
165 | if (self.menu_displayed == False): |
---|
166 | self.main_menu.show() |
---|
167 | self.menu_displayed = True |
---|
168 | elif (self.menu_displayed == True): |
---|
169 | self.hideMenu() |
---|
170 | |
---|
171 | def hideMenu(self): |
---|
172 | """Hides the main in-game menu. |
---|
173 | @return: None""" |
---|
174 | self.main_menu.hide() |
---|
175 | self.menu_displayed = False |
---|
176 | |
---|
177 | |
---|
178 | def initializeHelpMenu(self): |
---|
179 | """Initialize the help menu |
---|
180 | @return: None""" |
---|
181 | self.help_dialog = pychan.loadXML("gui/help.xml") |
---|
182 | help_events = {"closeButton":self.help_dialog.hide} |
---|
183 | self.help_dialog.mapEvents(help_events) |
---|
184 | 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]" |
---|
192 | |
---|
193 | 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" |
---|
199 | self.help_dialog.distributeInitialData({ |
---|
200 | "MainHelpText":main_help_text, |
---|
201 | "KeybindText":k_text |
---|
202 | }) |
---|
203 | |
---|
204 | def displayHelp(self): |
---|
205 | """Display the help screen. |
---|
206 | @return: None""" |
---|
207 | self.help_dialog.show() |
---|
208 | |
---|
209 | def initializeOptionsMenu(self): |
---|
210 | """Initalize the options menu. |
---|
211 | @return: None""" |
---|
212 | self.options_menu = pychan.loadXML("gui/hud_options.xml") |
---|
213 | self.options_events = {"applyButton":self.applyOptions, |
---|
214 | "closeButton":self.options_menu.hide, |
---|
215 | "defaultsButton":self.setToDefaults, |
---|
216 | "InitialVolumeSlider":self.updateVolumeText} |
---|
217 | |
---|
218 | settings = self.engine.getSettings() |
---|
219 | current_fullscreen = settings.isFullScreen() |
---|
220 | settings.setFullScreen(True) |
---|
221 | availableResolutions = settings.getPossibleResolutions() |
---|
222 | self.Resolutions = [str(x[0])+'x'+str(x[1]) for x in availableResolutions]; |
---|
223 | settings.setFullScreen(current_fullscreen) |
---|
224 | self.RenderBackends = ['OpenGL', 'SDL'] |
---|
225 | self.renderNumber = 0 |
---|
226 | if (str(self.settings.readSetting('RenderBackend')) == "SDL"): |
---|
227 | self.renderNumber = 1 |
---|
228 | initialVolume = float(self.settings.readSetting('InitialVolume')) |
---|
229 | initialVolumeText = str('Initial Volume: %.0f%s' % |
---|
230 | (int(initialVolume*10), "%")) |
---|
231 | self.options_menu.distributeInitialData({ |
---|
232 | 'ResolutionBox': self.Resolutions, |
---|
233 | 'RenderBox': self.RenderBackends, |
---|
234 | 'InitialVolumeLabel' : initialVolumeText |
---|
235 | }) |
---|
236 | |
---|
237 | sFullscreen = self.settings.readSetting(name="FullScreen") |
---|
238 | sSounds = self.settings.readSetting(name="PlaySounds") |
---|
239 | sRender = self.renderNumber |
---|
240 | sVolume = initialVolume |
---|
241 | |
---|
242 | screen_width = self.settings.readSetting(name="ScreenWidth") |
---|
243 | screen_height = self.settings.readSetting(name="ScreenHeight") |
---|
244 | indexRes = str(screen_width + 'x' + screen_height) |
---|
245 | try: |
---|
246 | sResolution = self.Resolutions.index(indexRes) |
---|
247 | resolutionInList = True |
---|
248 | except: |
---|
249 | resolutionInList = False |
---|
250 | |
---|
251 | dataToDistribute = { |
---|
252 | 'FullscreenBox':int(sFullscreen), |
---|
253 | 'SoundsBox':int(sSounds), |
---|
254 | 'RenderBox': sRender, |
---|
255 | 'InitialVolumeSlider':sVolume |
---|
256 | } |
---|
257 | |
---|
258 | if (resolutionInList == True): |
---|
259 | dataToDistribute['ResolutionBox'] = sResolution |
---|
260 | |
---|
261 | self.options_menu.distributeData(dataToDistribute) |
---|
262 | |
---|
263 | self.options_menu.mapEvents(self.options_events) |
---|
264 | |
---|
265 | def saveGame(self): |
---|
266 | """ Called when the user wants to save the game. |
---|
267 | @return: None""" |
---|
268 | save_browser = PARPGFileBrowser(self.engine, |
---|
269 | self.saveGameCallback, |
---|
270 | savefile=True, |
---|
271 | guixmlpath="gui/savebrowser.xml", |
---|
272 | extensions = ('.dat')) |
---|
273 | save_browser.showBrowser() |
---|
274 | |
---|
275 | def newGame(self): |
---|
276 | """Called when user request to start a new game. |
---|
277 | @return: None""" |
---|
278 | print 'new game' |
---|
279 | |
---|
280 | def loadGame(self): |
---|
281 | """ Called when the user wants to load a game. |
---|
282 | @return: None""" |
---|
283 | load_browser = PARPGFileBrowser(self.engine, |
---|
284 | self.loadGameCallback, |
---|
285 | savefile=False, |
---|
286 | guixmlpath='gui/loadbrowser.xml', |
---|
287 | extensions=('.dat')) |
---|
288 | load_browser.showBrowser() |
---|
289 | |
---|
290 | def initializeQuitDialog(self): |
---|
291 | """Creates the quit confirmation dialog |
---|
292 | @return: None""" |
---|
293 | self.quitWindow = pychan.widgets.Window(title=unicode("Quit?"),min_size=(200,0)) |
---|
294 | |
---|
295 | hbox = pychan.widgets.HBox() |
---|
296 | are_you_sure = "Are you sure you want to quit?" |
---|
297 | label = pychan.widgets.Label(text=unicode(are_you_sure)) |
---|
298 | yes_button = pychan.widgets.Button(name="yes_button", |
---|
299 | text=unicode("Yes"), |
---|
300 | min_size=(90,20), |
---|
301 | max_size=(90,20)) |
---|
302 | no_button = pychan.widgets.Button(name="no_button", |
---|
303 | text=unicode("No"), |
---|
304 | min_size=(90,20), |
---|
305 | max_size=(90,20)) |
---|
306 | |
---|
307 | self.quitWindow.addChild(label) |
---|
308 | hbox.addChild(yes_button) |
---|
309 | hbox.addChild(no_button) |
---|
310 | self.quitWindow.addChild(hbox) |
---|
311 | |
---|
312 | events_to_map = { "yes_button": self.quitCallback, |
---|
313 | "no_button": self.quitWindow.hide } |
---|
314 | |
---|
315 | self.quitWindow.mapEvents(events_to_map) |
---|
316 | |
---|
317 | |
---|
318 | def quitGame(self): |
---|
319 | """Called when user requests to quit game. |
---|
320 | @return: None""" |
---|
321 | |
---|
322 | self.quitWindow.show() |
---|
323 | |
---|
324 | def toggleInventoryButton(self): |
---|
325 | """Manually toggles the inventory button. |
---|
326 | @return: None""" |
---|
327 | button = self.hud.findChild(name="inventoryButton") |
---|
328 | if button.toggled == 0: |
---|
329 | button.toggled = 1 |
---|
330 | else: |
---|
331 | button.toggled = 0 |
---|
332 | |
---|
333 | def toggleInventory(self, toggleImage=True): |
---|
334 | """Display's the inventory screen |
---|
335 | @return: None""" |
---|
336 | |
---|
337 | self.inventory.toggleInventory(toggleImage) |
---|
338 | |
---|
339 | def refreshReadyImages(self): |
---|
340 | """Make the Ready slot images on the HUD be the same as those |
---|
341 | on the inventory |
---|
342 | @return: None""" |
---|
343 | self.setImages(self.hud.findChild(name="hudReady1"), |
---|
344 | self.inventory.getImage("Ready1").up_image) |
---|
345 | |
---|
346 | self.setImages(self.hud.findChild(name="hudReady2"), |
---|
347 | self.inventory.getImage("Ready2").up_image) |
---|
348 | |
---|
349 | self.setImages(self.hud.findChild(name="hudReady3"), |
---|
350 | self.inventory.getImage("Ready3").up_image) |
---|
351 | |
---|
352 | self.setImages(self.hud.findChild(name="hudReady4"), |
---|
353 | self.inventory.getImage("Ready4").up_image) |
---|
354 | |
---|
355 | def setImages(self, widget, image): |
---|
356 | """Set the up, down, and hover images of an Imagebutton. |
---|
357 | @type widget: pychan.widget |
---|
358 | @param widget: widget to set |
---|
359 | @type image: string |
---|
360 | @param image: image to use |
---|
361 | @return: None""" |
---|
362 | widget.up_image = image |
---|
363 | widget.down_image = image |
---|
364 | widget.hover_image = image |
---|
365 | |
---|
366 | def initializeEvents(self): |
---|
367 | """Intialize Hud events |
---|
368 | @return: None""" |
---|
369 | events_to_map = {} |
---|
370 | |
---|
371 | # when we click the toggle button don't change the image |
---|
372 | events_to_map["inventoryButton"] = cbwa(self.toggleInventory, False) |
---|
373 | events_to_map["saveButton"] = self.saveGame |
---|
374 | events_to_map["loadButton"] = self.loadGame |
---|
375 | |
---|
376 | hud_ready_buttons = ["hudReady1", "hudReady2", "hudReady3", "hudReady4"] |
---|
377 | |
---|
378 | for item in hud_ready_buttons: |
---|
379 | events_to_map[item] = cbwa(self.readyAction, item) |
---|
380 | |
---|
381 | self.hud.mapEvents(events_to_map) |
---|
382 | |
---|
383 | menu_events = {} |
---|
384 | menu_events["newButton"] = self.newGame |
---|
385 | menu_events["quitButton"] = self.quitGame |
---|
386 | menu_events["saveButton"] = self.saveGame |
---|
387 | menu_events["loadButton"] = self.loadGame |
---|
388 | self.main_menu.mapEvents(menu_events) |
---|
389 | |
---|
390 | def updateVolumeText(self): |
---|
391 | """ |
---|
392 | Update the initial volume label to reflect the value of the slider |
---|
393 | """ |
---|
394 | volume = float(self.options_menu.collectData("InitialVolumeSlider")) |
---|
395 | volume_label = self.options_menu.findChild(name="InitialVolumeLabel") |
---|
396 | volume_label.text = unicode("Initial Volume: %.0f%s" % |
---|
397 | (int(volume*10), "%")) |
---|
398 | |
---|
399 | def requireRestartDialog(self): |
---|
400 | """Show a dialog asking the user to restart PARPG in order for their |
---|
401 | changes to take effect. |
---|
402 | @return: None""" |
---|
403 | require_restart_dialog = pychan.loadXML('gui/hud_require_restart.xml') |
---|
404 | require_restart_dialog.mapEvents({'okButton':require_restart_dialog.hide}) |
---|
405 | require_restart_dialog.show() |
---|
406 | |
---|
407 | def applyOptions(self): |
---|
408 | """Apply the current options. |
---|
409 | @return: None""" |
---|
410 | # At first no restart is required |
---|
411 | self.requireRestart = False |
---|
412 | |
---|
413 | # get the current values of each setting from the options menu |
---|
414 | enable_fullscreen = self.options_menu.collectData('FullscreenBox') |
---|
415 | enable_sound = self.options_menu.collectData('SoundsBox') |
---|
416 | screen_resolution = self.options_menu.collectData('ResolutionBox') |
---|
417 | partition = self.Resolutions[screen_resolution].partition('x') |
---|
418 | screen_width = partition[0] |
---|
419 | screen_height = partition[2] |
---|
420 | render_backend = self.options_menu.collectData('RenderBox') |
---|
421 | initial_volume = self.options_menu.collectData('InitialVolumeSlider') |
---|
422 | initial_volume = "%.1f" % initial_volume |
---|
423 | |
---|
424 | # get the options that are being used right now from settings.xml |
---|
425 | sFullscreen = self.settings.readSetting('FullScreen') |
---|
426 | sSound = self.settings.readSetting('PlaySounds') |
---|
427 | sRender = self.settings.readSetting('RenderBackend') |
---|
428 | sVolume = self.settings.readSetting('InitialVolume') |
---|
429 | |
---|
430 | sScreenHeight = self.settings.readSetting('ScreenHeight') |
---|
431 | sScreenWidth = self.settings.readSetting('ScreenWidth') |
---|
432 | sResolution = sScreenWidth + 'x' + sScreenHeight |
---|
433 | |
---|
434 | # On each: |
---|
435 | # - Check to see whether the option within the xml matches the |
---|
436 | # option within the options menu |
---|
437 | # - If they do not match, set the option within the xml to |
---|
438 | # to be what is within the options menu |
---|
439 | # - Require a restart |
---|
440 | |
---|
441 | if (int(enable_fullscreen) != int(sFullscreen)): |
---|
442 | self.setOption('FullScreen', int(enable_fullscreen)) |
---|
443 | self.requireRestart = True |
---|
444 | |
---|
445 | if (int(enable_sound) != int(sSound)): |
---|
446 | self.setOption('PlaySounds', int(enable_sound)) |
---|
447 | self.requireRestart = True |
---|
448 | |
---|
449 | if (screen_resolution != sResolution): |
---|
450 | self.setOption('ScreenWidth', int(screen_width)) |
---|
451 | self.setOption('ScreenHeight', int(screen_height)) |
---|
452 | self.requireRestart = True |
---|
453 | |
---|
454 | # Convert the number from the list of render backends to |
---|
455 | # the string that FIFE wants for its settings.xml |
---|
456 | if (render_backend == 0): |
---|
457 | render_backend = 'OpenGL' |
---|
458 | else: |
---|
459 | render_backend = 'SDL' |
---|
460 | |
---|
461 | if (render_backend != str(sRender)): |
---|
462 | self.setOption('RenderBackend', render_backend) |
---|
463 | self.requireRestart = True |
---|
464 | |
---|
465 | if (initial_volume != float(sVolume)): |
---|
466 | self.setOption('InitialVolume', initial_volume) |
---|
467 | self.requireRestart = True |
---|
468 | |
---|
469 | # Write all the settings to settings.xml |
---|
470 | self.settings.tree.write('settings.xml') |
---|
471 | |
---|
472 | # If the changes require a restart, popup the dialog telling |
---|
473 | # the user to do so |
---|
474 | if (self.requireRestart): |
---|
475 | self.requireRestartDialog() |
---|
476 | # Once we are done, we close the options menu |
---|
477 | self.options_menu.hide() |
---|
478 | |
---|
479 | def setOption(self, name, value): |
---|
480 | """Set an option within the xml. |
---|
481 | @type name: string |
---|
482 | @param name: The name of the option within the xml |
---|
483 | @type value: any |
---|
484 | @param value: The value that the option 'name' should be set to |
---|
485 | @return: None""" |
---|
486 | element = self.settings.root_element.find(name) |
---|
487 | if(element != None): |
---|
488 | if(value != element.text): |
---|
489 | element.text = str(value) |
---|
490 | else: |
---|
491 | print 'Setting,', name, 'does not exist!' |
---|
492 | |
---|
493 | def setToDefaults(self): |
---|
494 | """Reset all the options to the options in settings-dist.xml. |
---|
495 | @return: None""" |
---|
496 | shutil.copyfile('settings-dist.xml', 'settings.xml') |
---|
497 | self.requireRestartDialog() |
---|
498 | self.options_menu.hide() |
---|
499 | |
---|
500 | def displayOptions(self): |
---|
501 | """Display the options menu. |
---|
502 | @return: None""" |
---|
503 | self.options_menu.show() |
---|
504 | |
---|
505 | def readyAction(self, ready_button): |
---|
506 | """ Called when the user selects a ready button from the HUD """ |
---|
507 | text = "Used the item from %s" % ready_button |
---|
508 | self.addAction(text) |
---|
509 | |
---|
510 | def createBoxGUI(self, title): |
---|
511 | """Creates a window to display the contents of a box |
---|
512 | @type title: string |
---|
513 | @param title: The title for the window |
---|
514 | @return: None""" |
---|
515 | if self.box_container: |
---|
516 | # if it has already been created, just show it |
---|
517 | self.box_container.showContainer() |
---|
518 | else: |
---|
519 | # otherwise create it then show it |
---|
520 | data = ["dagger01", "empty", "empty", "empty", "empty", |
---|
521 | "empty", "empty", "empty", "empty"] |
---|
522 | self.box_container = ContainerGUI(self.engine, unicode(title), data) |
---|
523 | def close_and_delete(): |
---|
524 | self.hideContainer() |
---|
525 | events = {'takeAllButton':close_and_delete, |
---|
526 | 'closeButton':close_and_delete} |
---|
527 | self.box_container.container_gui.mapEvents(events) |
---|
528 | self.box_container.showContainer() |
---|
529 | |
---|
530 | def hideContainer(self): |
---|
531 | """Hide the container box |
---|
532 | @return: None""" |
---|
533 | if self.box_container: |
---|
534 | self.box_container.hideContainer() |
---|
535 | |
---|
536 | def createExamineBox(self, title, desc): |
---|
537 | """Create an examine box. It displays some textual description of an |
---|
538 | object |
---|
539 | @type title: string |
---|
540 | @param title: The title of the examine box |
---|
541 | @type desc: string |
---|
542 | @param desc: The main body of the examine box |
---|
543 | @return: None""" |
---|
544 | |
---|
545 | if self.examine_box: |
---|
546 | self.examine_box.closePopUp() |
---|
547 | self.examine_box = ExaminePopup(self.engine, title, desc) |
---|
548 | self.examine_box.showPopUp() |
---|
549 | |
---|
550 | def showDialogue(self, npc): |
---|
551 | """Show the NPC dialogue window |
---|
552 | @type npc: ??? |
---|
553 | @param npc: the npc that we are having a dialogue with""" |
---|
554 | dialogue = DialogueGUI(npc) |
---|
555 | dialogue.initiateDialogue() |
---|