Mercurial > fife-parpg
annotate demos/shooter/scripts/gui/guis.py @ 697:ecaa4d98f05f tip
Abstracted the GUI code and refactored the GUIChan-specific code into its own module.
* Most of the GUIChan code has been refactored into its own gui/guichan module. However, references to the GuiFont class still persist in the Engine and GuiManager code and these will need further refactoring.
* GuiManager is now an abstract base class which specific implementations (e.g. GUIChan) should subclass.
* The GUIChan GUI code is now a concrete implementation of GuiManager, most of which is in the new GuiChanGuiManager class.
* The GUI code in the Console class has been refactored out of the Console and into the GUIChan module as its own GuiChanConsoleWidget class. The rest of the Console class related to executing commands was left largely unchanged.
* Existing client code may need to downcast the GuiManager pointer received from FIFE::Engine::getGuiManager() to GuiChanGuiManager, since not all functionality is represented in the GuiManager abstract base class. Python client code can use the new GuiChanGuiManager.castTo static method for this purpose.
author | M. George Hansen <technopolitica@gmail.com> |
---|---|
date | Sat, 18 Jun 2011 00:28:40 -1000 |
parents | 987307d12235 |
children |
rev | line source |
---|---|
456
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
1 # -*- coding: utf-8 -*- |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
2 |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
3 # #################################################################### |
491
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
479
diff
changeset
|
4 # Copyright (C) 2005-2010 by the FIFE team |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
479
diff
changeset
|
5 # http://www.fifengine.net |
456
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
6 # This file is part of FIFE. |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
7 # |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
8 # FIFE is free software; you can redistribute it and/or |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
9 # modify it under the terms of the GNU Lesser General Public |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
10 # License as published by the Free Software Foundation; either |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
11 # version 2.1 of the License, or (at your option) any later version. |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
12 # |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
13 # This library is distributed in the hope that it will be useful, |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
16 # Lesser General Public License for more details. |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
17 # |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
18 # You should have received a copy of the GNU Lesser General Public |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
19 # License along with this library; if not, write to the |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
20 # Free Software Foundation, Inc., |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
22 # #################################################################### |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
23 |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
24 from fife import fife |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
25 from fife.extensions import pychan |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
26 from fife.extensions.pychan import widgets |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
27 |
464
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
28 from xml.sax.saxutils import XMLGenerator |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
29 from xml.sax.xmlreader import AttributesNSImpl |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
30 |
456
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
31 class MainMenu(object): |
496
987307d12235
Added the fife_settings.py extension. This provides a small utility class for loading and saving settings along with a dialog box for setting screen resolution and other things.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
491
diff
changeset
|
32 def __init__(self, world, setting): |
456
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
33 self._world = world |
496
987307d12235
Added the fife_settings.py extension. This provides a small utility class for loading and saving settings along with a dialog box for setting screen resolution and other things.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
491
diff
changeset
|
34 self._setting = setting |
456
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
35 self._widget = pychan.loadXML('gui/mainmenu.xml') |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
36 |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
37 self._continue = self._widget.findChild(name="continue") |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
38 self._newgame = self._widget.findChild(name="new_game") |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
39 self._credits = self._widget.findChild(name="credits") |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
40 self._highscores = self._widget.findChild(name="high_scores") |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
41 self._quit = self._widget.findChild(name="quit") |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
42 |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
43 self._widget.position = (0,0) |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
44 |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
45 eventMap = { |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
46 'continue': self._world.continueGame, |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
47 'new_game': self._world.newGame, |
496
987307d12235
Added the fife_settings.py extension. This provides a small utility class for loading and saving settings along with a dialog box for setting screen resolution and other things.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
491
diff
changeset
|
48 'settings': self._setting.onOptionsPress, |
456
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
49 'credits': self._world.showCredits, |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
50 'high_scores': self._world.showHighScores, |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
51 'quit': self._world.quit, |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
52 } |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
53 |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
54 self._widget.mapEvents(eventMap) |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
55 |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
56 self._continueMinWidth = self._continue.min_width |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
57 self._continueMinHeight = self._continue.min_height |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
58 self._continueMaxWidth = self._continue.max_width |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
59 self._continueMaxHeight = self._continue.max_height |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
60 |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
61 |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
62 def show(self, cont=False): |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
63 if cont: |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
64 self._continue.min_width = self._continueMinWidth |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
65 self._continue.min_height = self._continueMinHeight |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
66 self._continue.max_width = self._continueMaxWidth |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
67 self._continue.max_height = self._continueMaxHeight |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
68 |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
69 else: |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
70 self._continue.min_width = 0 |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
71 self._continue.min_height = 0 |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
72 self._continue.max_width = 0 |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
73 self._continue.max_height = 0 |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
74 |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
75 self._continue.adaptLayout() |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
76 self._widget.show() |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
77 |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
78 def hide(self): |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
79 self._widget.hide() |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
80 |
469
5994e61cdebd
Added a widget to be displayed after the player completes the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
81 def isVisible(self): |
5994e61cdebd
Added a widget to be displayed after the player completes the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
82 return self._widget.isVisible() |
5994e61cdebd
Added a widget to be displayed after the player completes the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
83 |
5994e61cdebd
Added a widget to be displayed after the player completes the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
84 |
456
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
85 class HeadsUpDisplay(object): |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
86 def __init__(self, world): |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
87 self._world = world |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
88 self._widget = pychan.loadXML('gui/hud.xml') |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
89 |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
90 self._fpstext = self._widget.findChild(name="fps") |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
91 self._velocitytext = self._widget.findChild(name="velocity") |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
92 self._positiontext = self._widget.findChild(name="position") |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
93 self._scoretext = self._widget.findChild(name="score") |
457
597b066d5ccb
Player now has 3 lives and will receive a game over message once they are used up.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
456
diff
changeset
|
94 self._livestext = self._widget.findChild(name="lives") |
456
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
95 self._widget.position = (0,0) |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
96 |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
97 def show(self): |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
98 self._widget.show() |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
99 |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
100 def hide(self): |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
101 self._widget.hide() |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
102 |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
103 def setFPSText(self, text): |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
104 self._fpstext.text = text |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
105 |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
106 def setPositionText(self, text): |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
107 self._positiontext.text = text |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
108 |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
109 def setVelocityText(self, text): |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
110 self._velocitytext.text = text |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
111 |
41fd97da94d1
Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
112 def setScoreText(self, text): |
457
597b066d5ccb
Player now has 3 lives and will receive a game over message once they are used up.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
456
diff
changeset
|
113 self._scoretext.text = text |
597b066d5ccb
Player now has 3 lives and will receive a game over message once they are used up.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
456
diff
changeset
|
114 |
597b066d5ccb
Player now has 3 lives and will receive a game over message once they are used up.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
456
diff
changeset
|
115 def setLivesText(self, text): |
597b066d5ccb
Player now has 3 lives and will receive a game over message once they are used up.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
456
diff
changeset
|
116 self._livestext.text = text |
597b066d5ccb
Player now has 3 lives and will receive a game over message once they are used up.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
456
diff
changeset
|
117 |
597b066d5ccb
Player now has 3 lives and will receive a game over message once they are used up.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
456
diff
changeset
|
118 class GameOverDisplay(object): |
597b066d5ccb
Player now has 3 lives and will receive a game over message once they are used up.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
456
diff
changeset
|
119 def __init__(self): |
597b066d5ccb
Player now has 3 lives and will receive a game over message once they are used up.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
456
diff
changeset
|
120 self._widget = pychan.loadXML('gui/gameover.xml') |
597b066d5ccb
Player now has 3 lives and will receive a game over message once they are used up.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
456
diff
changeset
|
121 |
597b066d5ccb
Player now has 3 lives and will receive a game over message once they are used up.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
456
diff
changeset
|
122 def show(self): |
597b066d5ccb
Player now has 3 lives and will receive a game over message once they are used up.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
456
diff
changeset
|
123 self._widget.show() |
597b066d5ccb
Player now has 3 lives and will receive a game over message once they are used up.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
456
diff
changeset
|
124 |
597b066d5ccb
Player now has 3 lives and will receive a game over message once they are used up.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
456
diff
changeset
|
125 def hide(self): |
464
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
126 self._widget.hide() |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
127 |
469
5994e61cdebd
Added a widget to be displayed after the player completes the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
128 class WinnerDisplay(object): |
5994e61cdebd
Added a widget to be displayed after the player completes the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
129 def __init__(self): |
5994e61cdebd
Added a widget to be displayed after the player completes the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
130 self._widget = pychan.loadXML('gui/winner.xml') |
5994e61cdebd
Added a widget to be displayed after the player completes the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
131 |
5994e61cdebd
Added a widget to be displayed after the player completes the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
132 def show(self): |
5994e61cdebd
Added a widget to be displayed after the player completes the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
133 self._widget.show() |
5994e61cdebd
Added a widget to be displayed after the player completes the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
134 |
5994e61cdebd
Added a widget to be displayed after the player completes the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
135 def hide(self): |
5994e61cdebd
Added a widget to be displayed after the player completes the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
136 self._widget.hide() |
5994e61cdebd
Added a widget to be displayed after the player completes the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
137 |
464
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
138 class HighScore(object): |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
139 def __init__(self, name, score): |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
140 self._name = name |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
141 self._score = int(score) |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
142 |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
143 class HighScores(object): |
491
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
479
diff
changeset
|
144 """ |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
479
diff
changeset
|
145 Handles all the high scores. It saves and loads the high score file. |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
479
diff
changeset
|
146 """ |
464
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
147 def __init__(self, world): |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
148 self._world = world |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
149 self.load() |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
150 |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
151 def load(self): |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
152 self._widget = pychan.loadXML('gui/highscores.xml') |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
153 self._scores = list() |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
154 |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
155 for i in range(1,11): |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
156 place = self._widget.findChild(name=str(i)) |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
157 name = self._widget.findChild(name="%iname" % i) |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
158 score = self._widget.findChild(name="%iscore" % i) |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
159 highscore = HighScore(name.text, int(score.text)) |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
160 self._scores.append(highscore) |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
161 |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
162 eventMap = { |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
163 'close': self.hide, |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
164 } |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
165 |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
166 self._widget.mapEvents(eventMap) |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
167 |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
168 def isHighScore(self, score): |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
169 for highscore in self._scores: |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
170 if score > highscore._score: |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
171 return True |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
172 |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
173 return False |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
174 |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
175 def addHighScore(self, score): |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
176 if not self.isHighScore(score._score): |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
177 return |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
178 |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
179 i = 0 |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
180 element = 0 |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
181 for highscore in self._scores: |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
182 if score._score > highscore._score: |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
183 element = i |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
184 break |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
185 i += 1 |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
186 |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
187 self._scores.insert(element, score) |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
188 #remove last element |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
189 self._scores.pop() |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
190 |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
191 self.saveHighScores() |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
192 self.load() |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
193 |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
194 def startElement(self, name, attrs): |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
195 self._file.write(self._indent_level) |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
196 self._xmlout.startElementNS((None, name), name, attrs) |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
197 self._file.write('\n') |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
198 self._indent_level = self._indent_level + '\t' |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
199 |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
200 def endElement(self, name): |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
201 self._indent_level = self._indent_level[0:(len(self._indent_level) - 1)] |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
202 self._file.write(self._indent_level) |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
203 self._xmlout.endElementNS((None, name), name) |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
204 self._file.write('\n') |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
205 |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
206 def saveHighScores(self): |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
207 self._file = open('gui/highscores.xml', 'w') |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
208 self._xmlout = XMLGenerator(self._file, 'ascii') |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
209 self._xmlout.startDocument() |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
210 |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
211 self._indent_level = '' |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
212 |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
213 #<Container name="HighScores" position="0,0" size="1024,768" border_size="0" base_color="0,0,0" opaque="0"> |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
214 |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
215 attr_values = { |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
216 (None, 'name'): 'HighScores', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
217 (None, 'position'): '0,0', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
218 (None, 'size'): '1024,768', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
219 (None, 'border_size'): '0', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
220 (None, 'base_color'): '0,0,0', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
221 (None, 'opaque'): '0', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
222 } |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
223 attr_names = { |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
224 (None, 'name'): 'name', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
225 (None, 'position'): 'position', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
226 (None, 'size'): 'size', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
227 (None, 'border_size'): 'border_size', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
228 (None, 'base_color'): 'base_color', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
229 (None, 'opaque'): 'opaque', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
230 } |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
231 |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
232 container_attrs = AttributesNSImpl(attr_values, attr_names) |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
233 self.startElement('Container', container_attrs) |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
234 |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
235 #<VBox opaque='1' base_color="188, 0, 0" position="412,200" name="high_score"> |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
236 |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
237 attr_values = { |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
238 (None, 'opaque'): '1', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
239 (None, 'base_color'): '188,0,0', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
240 (None, 'position'): '412,200', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
241 (None, 'name'): 'high_score', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
242 } |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
243 |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
244 attr_names = { |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
245 (None, 'opaque'): 'opaque', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
246 (None, 'base_color'): 'base_color', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
247 (None, 'position'): 'position', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
248 (None, 'name'): 'name', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
249 } |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
250 |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
251 vbox_attrs = AttributesNSImpl(attr_values, attr_names) |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
252 self.startElement('VBox', vbox_attrs) |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
253 |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
254 #<Label name="high_scores" text="High Scores" min_size="100,0" border_size="0"/> |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
255 |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
256 self.startElement('HBox', AttributesNSImpl({}, {})) |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
257 attr_values = { |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
258 (None, 'name'): 'high_scores', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
259 (None, 'text'): 'High Scores', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
260 (None, 'min_size'): '100,0', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
261 (None, 'border_size'): '0', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
262 } |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
263 |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
264 attr_names = { |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
265 (None, 'name'): 'name', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
266 (None, 'text'): 'text', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
267 (None, 'min_size'): 'min_size', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
268 (None, 'border_size'): 'border_size', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
269 } |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
270 self.startElement('Label', AttributesNSImpl(attr_values, attr_names)) |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
271 self.endElement('Label') |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
272 |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
273 self.endElement('HBox') |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
274 |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
275 i = 1 |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
276 for score in self._scores: |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
277 self.startElement('HBox', AttributesNSImpl({}, {})) |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
278 |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
279 plc_attr_values = { |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
280 (None, 'name'): str(i), |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
281 (None, 'text'): str(i), |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
282 (None, 'min_size'): '20,0', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
283 (None, 'border_size'): '5', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
284 } |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
285 |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
286 plc_attr_names = { |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
287 (None, 'name'): 'name', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
288 (None, 'text'): 'text', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
289 (None, 'min_size'): 'min_size', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
290 (None, 'border_size'): 'border_size', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
291 } |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
292 |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
293 name_attr_values = { |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
294 (None, 'name'): str(i) + 'name', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
295 (None, 'text'): score._name, |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
296 (None, 'min_size'): '50,0', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
297 (None, 'border_size'): '5', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
298 } |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
299 |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
300 name_attr_names = { |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
301 (None, 'name'): 'name', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
302 (None, 'text'): 'text', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
303 (None, 'min_size'): 'min_size', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
304 (None, 'border_size'): 'border_size', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
305 } |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
306 |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
307 score_attr_values = { |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
308 (None, 'name'): str(i) + 'score', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
309 (None, 'text'): str(score._score), |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
310 (None, 'min_size'): '150,0', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
311 (None, 'border_size'): '5', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
312 } |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
313 |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
314 score_attr_names = { |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
315 (None, 'name'): 'name', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
316 (None, 'text'): 'text', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
317 (None, 'min_size'): 'min_size', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
318 (None, 'border_size'): 'border_size', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
319 } |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
320 |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
321 self.startElement('Label', AttributesNSImpl(plc_attr_values, plc_attr_names)) |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
322 self.endElement('Label') |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
323 self.startElement('Label', AttributesNSImpl(name_attr_values, name_attr_names)) |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
324 self.endElement('Label') |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
325 self.startElement('Label', AttributesNSImpl(score_attr_values, score_attr_names)) |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
326 self.endElement('Label') |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
327 |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
328 |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
329 self.endElement('HBox') |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
330 i += 1 |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
331 |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
332 |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
333 #<Button name="close" text="Close" min_size="100,0" border_size="0"/> |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
334 |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
335 attr_values = { |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
336 (None, 'name'): 'close', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
337 (None, 'text'): 'Close', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
338 (None, 'min_size'): '100,0', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
339 (None, 'border_size'): '0', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
340 } |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
341 |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
342 attr_names = { |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
343 (None, 'name'): 'name', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
344 (None, 'text'): 'text', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
345 (None, 'min_size'): 'min_size', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
346 (None, 'border_size'): 'border_size', |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
347 } |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
348 |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
349 self.startElement('Button', AttributesNSImpl(attr_values, attr_names)) |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
350 self.endElement('Button') |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
351 |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
352 self.endElement('VBox') |
465
4e58dab2fcdc
Added the high score dialog to ask for players name (with no validation yet)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
464
diff
changeset
|
353 self.endElement('Container') |
4e58dab2fcdc
Added the high score dialog to ask for players name (with no validation yet)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
464
diff
changeset
|
354 |
4e58dab2fcdc
Added the high score dialog to ask for players name (with no validation yet)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
464
diff
changeset
|
355 self._xmlout.endDocument() |
4e58dab2fcdc
Added the high score dialog to ask for players name (with no validation yet)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
464
diff
changeset
|
356 self._file.close() |
464
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
357 |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
358 def show(self): |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
359 self._widget.show() |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
360 |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
361 def hide(self): |
be035dff788a
Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
457
diff
changeset
|
362 self.saveHighScores() |
469
5994e61cdebd
Added a widget to be displayed after the player completes the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
363 self._widget.hide() |
5994e61cdebd
Added a widget to be displayed after the player completes the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
364 |
5994e61cdebd
Added a widget to be displayed after the player completes the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
465
diff
changeset
|
365 def isVisible(self): |
471
7a79dc2a0592
Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
469
diff
changeset
|
366 return self._widget.isVisible() |
7a79dc2a0592
Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
469
diff
changeset
|
367 |
7a79dc2a0592
Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
469
diff
changeset
|
368 class CreditsDisplay(object): |
7a79dc2a0592
Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
469
diff
changeset
|
369 def __init__(self, world): |
7a79dc2a0592
Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
469
diff
changeset
|
370 self._world = world |
7a79dc2a0592
Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
469
diff
changeset
|
371 self._widget = pychan.loadXML('gui/credits.xml') |
7a79dc2a0592
Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
469
diff
changeset
|
372 |
7a79dc2a0592
Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
469
diff
changeset
|
373 eventMap = { |
7a79dc2a0592
Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
469
diff
changeset
|
374 'close': self.hide, |
7a79dc2a0592
Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
469
diff
changeset
|
375 } |
7a79dc2a0592
Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
469
diff
changeset
|
376 |
7a79dc2a0592
Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
469
diff
changeset
|
377 self._widget.mapEvents(eventMap) |
7a79dc2a0592
Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
469
diff
changeset
|
378 |
7a79dc2a0592
Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
469
diff
changeset
|
379 def show(self): |
7a79dc2a0592
Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
469
diff
changeset
|
380 self._widget.show() |
7a79dc2a0592
Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
469
diff
changeset
|
381 |
7a79dc2a0592
Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
469
diff
changeset
|
382 def hide(self): |
491
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
479
diff
changeset
|
383 self._widget.hide() |