annotate demos/shooter/scripts/gui/guis.py @ 491:c4168eb47a44

Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Thu, 06 May 2010 19:34:21 +0000
parents ab28994820dd
children 987307d12235
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):
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
32 def __init__(self, world):
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
33 self._world = world
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
34 self._widget = pychan.loadXML('gui/mainmenu.xml')
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
35
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
36 self._continue = self._widget.findChild(name="continue")
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
37 self._newgame = self._widget.findChild(name="new_game")
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
38 self._credits = self._widget.findChild(name="credits")
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
39 self._highscores = self._widget.findChild(name="high_scores")
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
40 self._quit = self._widget.findChild(name="quit")
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
41
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
42 self._widget.position = (0,0)
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
43
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
44 eventMap = {
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
45 'continue': self._world.continueGame,
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
46 'new_game': self._world.newGame,
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
47 'credits': self._world.showCredits,
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
48 'high_scores': self._world.showHighScores,
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
49 'quit': self._world.quit,
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
50 }
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
51
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
52 self._widget.mapEvents(eventMap)
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._continueMinWidth = self._continue.min_width
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
55 self._continueMinHeight = self._continue.min_height
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
56 self._continueMaxWidth = self._continue.max_width
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
57 self._continueMaxHeight = self._continue.max_height
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
58
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
59
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
60 def show(self, cont=False):
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
61 if cont:
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
62 self._continue.min_width = self._continueMinWidth
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
63 self._continue.min_height = self._continueMinHeight
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
64 self._continue.max_width = self._continueMaxWidth
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
65 self._continue.max_height = self._continueMaxHeight
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
66
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
67 else:
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
68 self._continue.min_width = 0
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
69 self._continue.min_height = 0
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
70 self._continue.max_width = 0
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
71 self._continue.max_height = 0
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
72
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
73 self._continue.adaptLayout()
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
74 self._widget.show()
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
75
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
76 def hide(self):
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
77 self._widget.hide()
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
78
469
5994e61cdebd Added a widget to be displayed after the player completes the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 465
diff changeset
79 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
80 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
81
5994e61cdebd Added a widget to be displayed after the player completes the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 465
diff changeset
82
456
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
83 class HeadsUpDisplay(object):
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
84 def __init__(self, world):
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
85 self._world = world
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
86 self._widget = pychan.loadXML('gui/hud.xml')
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
87
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
88 self._fpstext = self._widget.findChild(name="fps")
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
89 self._velocitytext = self._widget.findChild(name="velocity")
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
90 self._positiontext = self._widget.findChild(name="position")
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
91 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
92 self._livestext = self._widget.findChild(name="lives")
456
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
93 self._widget.position = (0,0)
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
94
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
95 def show(self):
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
96 self._widget.show()
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
97
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
98 def hide(self):
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
99 self._widget.hide()
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
100
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
101 def setFPSText(self, text):
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
102 self._fpstext.text = text
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
103
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
104 def setPositionText(self, text):
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
105 self._positiontext.text = text
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
106
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
107 def setVelocityText(self, text):
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
108 self._velocitytext.text = text
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
109
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
110 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
111 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
112
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 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
114 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
115
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 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
117 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
118 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
119
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 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
121 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
122
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 def hide(self):
464
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
124 self._widget.hide()
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
125
469
5994e61cdebd Added a widget to be displayed after the player completes the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 465
diff changeset
126 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
127 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
128 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
129
5994e61cdebd Added a widget to be displayed after the player completes the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 465
diff changeset
130 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
131 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
132
5994e61cdebd Added a widget to be displayed after the player completes the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 465
diff changeset
133 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
134 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
135
464
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
136 class HighScore(object):
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
137 def __init__(self, name, score):
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
138 self._name = name
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
139 self._score = int(score)
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
140
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
141 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
142 """
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
143 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
144 """
464
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
145 def __init__(self, world):
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
146 self._world = world
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
147 self.load()
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
148
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
149 def load(self):
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
150 self._widget = pychan.loadXML('gui/highscores.xml')
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
151 self._scores = list()
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
152
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
153 for i in range(1,11):
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
154 place = self._widget.findChild(name=str(i))
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
155 name = self._widget.findChild(name="%iname" % i)
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
156 score = self._widget.findChild(name="%iscore" % i)
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
157 highscore = HighScore(name.text, int(score.text))
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
158 self._scores.append(highscore)
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
159
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
160 eventMap = {
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
161 'close': self.hide,
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
162 }
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
163
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
164 self._widget.mapEvents(eventMap)
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 def isHighScore(self, score):
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
167 for highscore in self._scores:
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
168 if score > highscore._score:
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
169 return True
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
170
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
171 return False
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 def addHighScore(self, score):
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
174 if not self.isHighScore(score._score):
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
175 return
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
176
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
177 i = 0
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
178 element = 0
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
179 for highscore in self._scores:
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
180 if score._score > highscore._score:
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
181 element = i
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
182 break
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
183 i += 1
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
184
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
185 self._scores.insert(element, score)
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
186 #remove last element
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
187 self._scores.pop()
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
188
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
189 self.saveHighScores()
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
190 self.load()
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
191
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
192 def startElement(self, name, attrs):
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
193 self._file.write(self._indent_level)
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
194 self._xmlout.startElementNS((None, name), name, attrs)
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
195 self._file.write('\n')
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
196 self._indent_level = self._indent_level + '\t'
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
197
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
198 def endElement(self, name):
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
199 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
200 self._file.write(self._indent_level)
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
201 self._xmlout.endElementNS((None, name), name)
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
202 self._file.write('\n')
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
203
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
204 def saveHighScores(self):
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
205 self._file = open('gui/highscores.xml', 'w')
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
206 self._xmlout = XMLGenerator(self._file, 'ascii')
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
207 self._xmlout.startDocument()
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
208
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
209 self._indent_level = ''
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 #<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
212
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
213 attr_values = {
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
214 (None, 'name'): 'HighScores',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
215 (None, 'position'): '0,0',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
216 (None, 'size'): '1024,768',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
217 (None, 'border_size'): '0',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
218 (None, 'base_color'): '0,0,0',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
219 (None, 'opaque'): '0',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
220 }
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
221 attr_names = {
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
222 (None, 'name'): 'name',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
223 (None, 'position'): 'position',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
224 (None, 'size'): 'size',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
225 (None, 'border_size'): 'border_size',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
226 (None, 'base_color'): 'base_color',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
227 (None, 'opaque'): 'opaque',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
228 }
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
229
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
230 container_attrs = AttributesNSImpl(attr_values, attr_names)
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
231 self.startElement('Container', container_attrs)
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
232
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
233 #<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
234
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
235 attr_values = {
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
236 (None, 'opaque'): '1',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
237 (None, 'base_color'): '188,0,0',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
238 (None, 'position'): '412,200',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
239 (None, 'name'): 'high_score',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
240 }
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
241
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
242 attr_names = {
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
243 (None, 'opaque'): 'opaque',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
244 (None, 'base_color'): 'base_color',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
245 (None, 'position'): 'position',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
246 (None, 'name'): 'name',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
247 }
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
248
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
249 vbox_attrs = AttributesNSImpl(attr_values, attr_names)
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
250 self.startElement('VBox', vbox_attrs)
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
251
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
252 #<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
253
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
254 self.startElement('HBox', AttributesNSImpl({}, {}))
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
255 attr_values = {
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
256 (None, 'name'): 'high_scores',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
257 (None, 'text'): 'High Scores',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
258 (None, 'min_size'): '100,0',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
259 (None, 'border_size'): '0',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
260 }
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
261
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
262 attr_names = {
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
263 (None, 'name'): 'name',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
264 (None, 'text'): 'text',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
265 (None, 'min_size'): 'min_size',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
266 (None, 'border_size'): 'border_size',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
267 }
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
268 self.startElement('Label', AttributesNSImpl(attr_values, attr_names))
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
269 self.endElement('Label')
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
270
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
271 self.endElement('HBox')
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 i = 1
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
274 for score in self._scores:
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
275 self.startElement('HBox', AttributesNSImpl({}, {}))
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
276
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
277 plc_attr_values = {
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
278 (None, 'name'): str(i),
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
279 (None, 'text'): str(i),
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
280 (None, 'min_size'): '20,0',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
281 (None, 'border_size'): '5',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
282 }
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
283
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
284 plc_attr_names = {
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
285 (None, 'name'): 'name',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
286 (None, 'text'): 'text',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
287 (None, 'min_size'): 'min_size',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
288 (None, 'border_size'): 'border_size',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
289 }
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
290
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
291 name_attr_values = {
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
292 (None, 'name'): str(i) + 'name',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
293 (None, 'text'): score._name,
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
294 (None, 'min_size'): '50,0',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
295 (None, 'border_size'): '5',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
296 }
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
297
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
298 name_attr_names = {
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
299 (None, 'name'): 'name',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
300 (None, 'text'): 'text',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
301 (None, 'min_size'): 'min_size',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
302 (None, 'border_size'): 'border_size',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
303 }
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
304
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
305 score_attr_values = {
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
306 (None, 'name'): str(i) + 'score',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
307 (None, 'text'): str(score._score),
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
308 (None, 'min_size'): '150,0',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
309 (None, 'border_size'): '5',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
310 }
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
311
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
312 score_attr_names = {
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
313 (None, 'name'): 'name',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
314 (None, 'text'): 'text',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
315 (None, 'min_size'): 'min_size',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
316 (None, 'border_size'): 'border_size',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
317 }
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
318
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
319 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
320 self.endElement('Label')
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
321 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
322 self.endElement('Label')
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
323 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
324 self.endElement('Label')
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
325
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
326
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
327 self.endElement('HBox')
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
328 i += 1
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
329
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
330
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
331 #<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
332
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
333 attr_values = {
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
334 (None, 'name'): 'close',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
335 (None, 'text'): 'Close',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
336 (None, 'min_size'): '100,0',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
337 (None, 'border_size'): '0',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
338 }
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
339
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
340 attr_names = {
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
341 (None, 'name'): 'name',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
342 (None, 'text'): 'text',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
343 (None, 'min_size'): 'min_size',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
344 (None, 'border_size'): 'border_size',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
345 }
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
346
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
347 self.startElement('Button', AttributesNSImpl(attr_values, attr_names))
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
348 self.endElement('Button')
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
349
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
350 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
351 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
352
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._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
354 self._file.close()
464
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
355
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
356 def show(self):
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
357 self._widget.show()
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
358
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
359 def hide(self):
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
360 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
361 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
362
5994e61cdebd Added a widget to be displayed after the player completes the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 465
diff changeset
363 def isVisible(self):
471
7a79dc2a0592 Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 469
diff changeset
364 return self._widget.isVisible()
7a79dc2a0592 Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 469
diff changeset
365
7a79dc2a0592 Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 469
diff changeset
366 class CreditsDisplay(object):
7a79dc2a0592 Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 469
diff changeset
367 def __init__(self, world):
7a79dc2a0592 Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 469
diff changeset
368 self._world = world
7a79dc2a0592 Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 469
diff changeset
369 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
370
7a79dc2a0592 Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 469
diff changeset
371 eventMap = {
7a79dc2a0592 Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 469
diff changeset
372 'close': self.hide,
7a79dc2a0592 Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 469
diff changeset
373 }
7a79dc2a0592 Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 469
diff changeset
374
7a79dc2a0592 Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 469
diff changeset
375 self._widget.mapEvents(eventMap)
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 def show(self):
7a79dc2a0592 Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 469
diff changeset
378 self._widget.show()
7a79dc2a0592 Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 469
diff changeset
379
7a79dc2a0592 Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 469
diff changeset
380 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
381 self._widget.hide()