annotate demos/shooter/scripts/gui/guis.py @ 465:4e58dab2fcdc

Added the high score dialog to ask for players name (with no validation yet) Enabled modal execution. Fixed a small bug where the scene tries to remove a projectile that it already removed from the scene.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Tue, 13 Apr 2010 20:23:13 +0000
parents be035dff788a
children 5994e61cdebd
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 # ####################################################################
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
4 # Copyright (C) 2005-2009 by the FIFE team
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
5 # http://www.fifengine.de
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
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
79 class HeadsUpDisplay(object):
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
80 def __init__(self, world):
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
81 self._world = world
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
82 self._widget = pychan.loadXML('gui/hud.xml')
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
83
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
84 self._fpstext = self._widget.findChild(name="fps")
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
85 self._velocitytext = self._widget.findChild(name="velocity")
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
86 self._positiontext = self._widget.findChild(name="position")
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
87 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
88 self._livestext = self._widget.findChild(name="lives")
456
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
89 self._widget.position = (0,0)
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
90
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
91 def show(self):
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
92 self._widget.show()
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
93
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
94 def hide(self):
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
95 self._widget.hide()
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 setFPSText(self, text):
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
98 self._fpstext.text = text
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 setPositionText(self, text):
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
101 self._positiontext.text = text
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 setVelocityText(self, text):
41fd97da94d1 Moved guis to their own file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
104 self._velocitytext.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 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
107 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
108
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
109 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
110 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
111
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 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
113 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
114 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
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 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
117 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
118
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 hide(self):
464
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
120 self._widget.hide()
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
121
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
122 class HighScore(object):
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
123 def __init__(self, name, score):
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
124 self._name = name
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
125 self._score = int(score)
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
126
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
127 class HighScores(object):
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
128 def __init__(self, world):
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
129 self._world = world
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
130 self.load()
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
131
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
132 def load(self):
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
133 self._widget = pychan.loadXML('gui/highscores.xml')
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
134 self._scores = list()
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
135
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
136 for i in range(1,11):
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
137 place = self._widget.findChild(name=str(i))
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
138 name = self._widget.findChild(name="%iname" % i)
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
139 score = self._widget.findChild(name="%iscore" % i)
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
140 highscore = HighScore(name.text, int(score.text))
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
141 self._scores.append(highscore)
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 eventMap = {
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
144 'close': self.hide,
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
145 }
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
146
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
147 self._widget.mapEvents(eventMap)
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 isHighScore(self, score):
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
150 for highscore in self._scores:
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
151 if score > highscore._score:
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
152 return True
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
153
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
154 return False
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
155
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
156 def addHighScore(self, score):
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
157 if not self.isHighScore(score._score):
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
158 return
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 i = 0
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
161 element = 0
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
162 for highscore in self._scores:
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
163 if score._score > highscore._score:
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
164 element = i
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
165 print element
464
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
166 break
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
167 i += 1
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
168
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
169 self._scores.insert(element, score)
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
170 #remove last element
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
171 self._scores.pop()
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 self.saveHighScores()
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
174 self.load()
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
175
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
176 def startElement(self, name, attrs):
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
177 self._file.write(self._indent_level)
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
178 self._xmlout.startElementNS((None, name), name, attrs)
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
179 self._file.write('\n')
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
180 self._indent_level = self._indent_level + '\t'
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
181
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
182 def endElement(self, name):
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
183 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
184 self._file.write(self._indent_level)
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
185 self._xmlout.endElementNS((None, name), name)
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
186 self._file.write('\n')
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
187
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
188 def saveHighScores(self):
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
189 self._file = open('gui/highscores.xml', 'w')
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
190 self._xmlout = XMLGenerator(self._file, 'ascii')
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
191 self._xmlout.startDocument()
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
192
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
193 self._indent_level = ''
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
194
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
195 #<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
196
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
197 attr_values = {
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
198 (None, 'name'): 'HighScores',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
199 (None, 'position'): '0,0',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
200 (None, 'size'): '1024,768',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
201 (None, 'border_size'): '0',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
202 (None, 'base_color'): '0,0,0',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
203 (None, 'opaque'): '0',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
204 }
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
205 attr_names = {
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
206 (None, 'name'): 'name',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
207 (None, 'position'): 'position',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
208 (None, 'size'): 'size',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
209 (None, 'border_size'): 'border_size',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
210 (None, 'base_color'): 'base_color',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
211 (None, 'opaque'): 'opaque',
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
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
214 container_attrs = AttributesNSImpl(attr_values, attr_names)
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
215 self.startElement('Container', container_attrs)
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
216
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
217 #<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
218
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
219 attr_values = {
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
220 (None, 'opaque'): '1',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
221 (None, 'base_color'): '188,0,0',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
222 (None, 'position'): '412,200',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
223 (None, 'name'): 'high_score',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
224 }
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
225
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
226 attr_names = {
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 (None, 'base_color'): 'base_color',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
229 (None, 'position'): 'position',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
230 (None, 'name'): 'name',
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
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
233 vbox_attrs = AttributesNSImpl(attr_values, attr_names)
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
234 self.startElement('VBox', vbox_attrs)
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
235
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
236 #<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
237
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
238 self.startElement('HBox', AttributesNSImpl({}, {}))
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
239 attr_values = {
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
240 (None, 'name'): 'high_scores',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
241 (None, 'text'): 'High Scores',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
242 (None, 'min_size'): '100,0',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
243 (None, 'border_size'): '0',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
244 }
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
245
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
246 attr_names = {
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
247 (None, 'name'): 'name',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
248 (None, 'text'): 'text',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
249 (None, 'min_size'): 'min_size',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
250 (None, 'border_size'): 'border_size',
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 self.startElement('Label', AttributesNSImpl(attr_values, attr_names))
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
253 self.endElement('Label')
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
254
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
255 self.endElement('HBox')
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
256
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
257 i = 1
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
258 for score in self._scores:
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
259 self.startElement('HBox', AttributesNSImpl({}, {}))
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 plc_attr_values = {
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
262 (None, 'name'): str(i),
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
263 (None, 'text'): str(i),
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
264 (None, 'min_size'): '20,0',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
265 (None, 'border_size'): '5',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
266 }
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 plc_attr_names = {
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
269 (None, 'name'): 'name',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
270 (None, 'text'): 'text',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
271 (None, 'min_size'): 'min_size',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
272 (None, 'border_size'): 'border_size',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
273 }
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 name_attr_values = {
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
276 (None, 'name'): str(i) + 'name',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
277 (None, 'text'): score._name,
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
278 (None, 'min_size'): '50,0',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
279 (None, 'border_size'): '5',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
280 }
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
281
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
282 name_attr_names = {
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
283 (None, 'name'): 'name',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
284 (None, 'text'): 'text',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
285 (None, 'min_size'): 'min_size',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
286 (None, 'border_size'): 'border_size',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
287 }
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
288
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
289 score_attr_values = {
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
290 (None, 'name'): str(i) + 'score',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
291 (None, 'text'): str(score._score),
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
292 (None, 'min_size'): '150,0',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
293 (None, 'border_size'): '5',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
294 }
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
295
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
296 score_attr_names = {
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
297 (None, 'name'): 'name',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
298 (None, 'text'): 'text',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
299 (None, 'min_size'): 'min_size',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
300 (None, 'border_size'): 'border_size',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
301 }
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
302
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
303 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
304 self.endElement('Label')
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
305 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
306 self.endElement('Label')
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
307 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
308 self.endElement('Label')
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
309
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 self.endElement('HBox')
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
312 i += 1
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
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
315 #<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
316
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
317 attr_values = {
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
318 (None, 'name'): 'close',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
319 (None, 'text'): 'Close',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
320 (None, 'min_size'): '100,0',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
321 (None, 'border_size'): '0',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
322 }
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
323
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
324 attr_names = {
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
325 (None, 'name'): 'name',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
326 (None, 'text'): 'text',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
327 (None, 'min_size'): 'min_size',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
328 (None, 'border_size'): 'border_size',
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 self.startElement('Button', AttributesNSImpl(attr_values, attr_names))
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
332 self.endElement('Button')
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
333
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
334 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
335 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
336
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
337 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
338 self._file.close()
464
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 def show(self):
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
341 self._widget.show()
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
342
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
343 def hide(self):
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
344 self.saveHighScores()
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
345 self._widget.hide()