annotate demos/shooter/scripts/gui/guis.py @ 471:7a79dc2a0592

Adding the credits window (still needs to be written) Hopefully fixed some memory leaks. Moved the flashing code to the appropriate spot (in ShipBase).
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Thu, 15 Apr 2010 15:53:06 +0000
parents 5994e61cdebd
children ab28994820dd
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
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):
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
142 def __init__(self, world):
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
143 self._world = world
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
144 self.load()
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 def load(self):
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
147 self._widget = pychan.loadXML('gui/highscores.xml')
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
148 self._scores = list()
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
149
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
150 for i in range(1,11):
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
151 place = self._widget.findChild(name=str(i))
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
152 name = self._widget.findChild(name="%iname" % i)
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
153 score = self._widget.findChild(name="%iscore" % i)
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
154 highscore = HighScore(name.text, int(score.text))
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
155 self._scores.append(highscore)
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
156
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
157 eventMap = {
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
158 'close': self.hide,
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
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
161 self._widget.mapEvents(eventMap)
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 def isHighScore(self, score):
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
164 for highscore in self._scores:
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
165 if score > highscore._score:
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
166 return True
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
167
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
168 return False
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
169
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
170 def addHighScore(self, score):
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
171 if not self.isHighScore(score._score):
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
172 return
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
173
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
174 i = 0
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
175 element = 0
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
176 for highscore in self._scores:
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
177 if score._score > highscore._score:
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
178 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
179 print element
464
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
180 break
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
181 i += 1
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
182
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
183 self._scores.insert(element, score)
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
184 #remove last element
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
185 self._scores.pop()
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
186
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
187 self.saveHighScores()
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
188 self.load()
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
189
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
190 def startElement(self, name, attrs):
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
191 self._file.write(self._indent_level)
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
192 self._xmlout.startElementNS((None, name), name, attrs)
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
193 self._file.write('\n')
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
194 self._indent_level = self._indent_level + '\t'
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
195
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
196 def endElement(self, name):
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
197 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
198 self._file.write(self._indent_level)
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
199 self._xmlout.endElementNS((None, name), name)
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
200 self._file.write('\n')
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
201
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
202 def saveHighScores(self):
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
203 self._file = open('gui/highscores.xml', 'w')
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
204 self._xmlout = XMLGenerator(self._file, 'ascii')
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
205 self._xmlout.startDocument()
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
206
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
207 self._indent_level = ''
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 #<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
210
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
211 attr_values = {
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
212 (None, 'name'): 'HighScores',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
213 (None, 'position'): '0,0',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
214 (None, 'size'): '1024,768',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
215 (None, 'border_size'): '0',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
216 (None, 'base_color'): '0,0,0',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
217 (None, 'opaque'): '0',
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_names = {
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
220 (None, 'name'): 'name',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
221 (None, 'position'): 'position',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
222 (None, 'size'): 'size',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
223 (None, 'border_size'): 'border_size',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
224 (None, 'base_color'): 'base_color',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
225 (None, 'opaque'): 'opaque',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
226 }
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
227
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
228 container_attrs = AttributesNSImpl(attr_values, attr_names)
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
229 self.startElement('Container', container_attrs)
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
230
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
231 #<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
232
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
233 attr_values = {
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
234 (None, 'opaque'): '1',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
235 (None, 'base_color'): '188,0,0',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
236 (None, 'position'): '412,200',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
237 (None, 'name'): 'high_score',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
238 }
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
239
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
240 attr_names = {
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
241 (None, 'opaque'): 'opaque',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
242 (None, 'base_color'): 'base_color',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
243 (None, 'position'): 'position',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
244 (None, 'name'): 'name',
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
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
247 vbox_attrs = AttributesNSImpl(attr_values, attr_names)
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
248 self.startElement('VBox', vbox_attrs)
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
249
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
250 #<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
251
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
252 self.startElement('HBox', AttributesNSImpl({}, {}))
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
253 attr_values = {
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
254 (None, 'name'): 'high_scores',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
255 (None, 'text'): 'High Scores',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
256 (None, 'min_size'): '100,0',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
257 (None, 'border_size'): '0',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
258 }
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
259
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
260 attr_names = {
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
261 (None, 'name'): 'name',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
262 (None, 'text'): 'text',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
263 (None, 'min_size'): 'min_size',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
264 (None, 'border_size'): 'border_size',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
265 }
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
266 self.startElement('Label', AttributesNSImpl(attr_values, attr_names))
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
267 self.endElement('Label')
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
268
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
269 self.endElement('HBox')
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 i = 1
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
272 for score in self._scores:
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
273 self.startElement('HBox', AttributesNSImpl({}, {}))
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 plc_attr_values = {
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
276 (None, 'name'): str(i),
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
277 (None, 'text'): str(i),
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
278 (None, 'min_size'): '20,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 plc_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 name_attr_values = {
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
290 (None, 'name'): str(i) + 'name',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
291 (None, 'text'): score._name,
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
292 (None, 'min_size'): '50,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 name_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 score_attr_values = {
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
304 (None, 'name'): str(i) + 'score',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
305 (None, 'text'): str(score._score),
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
306 (None, 'min_size'): '150,0',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
307 (None, 'border_size'): '5',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
308 }
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 score_attr_names = {
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
311 (None, 'name'): 'name',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
312 (None, 'text'): 'text',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
313 (None, 'min_size'): 'min_size',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
314 (None, 'border_size'): 'border_size',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
315 }
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 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
318 self.endElement('Label')
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
319 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
320 self.endElement('Label')
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
321 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
322 self.endElement('Label')
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
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
325 self.endElement('HBox')
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
326 i += 1
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
327
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
328
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
329 #<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
330
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
331 attr_values = {
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
332 (None, 'name'): 'close',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
333 (None, 'text'): 'Close',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
334 (None, 'min_size'): '100,0',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
335 (None, 'border_size'): '0',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
336 }
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
337
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
338 attr_names = {
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
339 (None, 'name'): 'name',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
340 (None, 'text'): 'text',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
341 (None, 'min_size'): 'min_size',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
342 (None, 'border_size'): 'border_size',
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
343 }
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
344
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
345 self.startElement('Button', AttributesNSImpl(attr_values, attr_names))
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
346 self.endElement('Button')
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
347
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
348 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
349 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
350
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._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
352 self._file.close()
464
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
353
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
354 def show(self):
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
355 self._widget.show()
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
356
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
357 def hide(self):
be035dff788a Added high score window.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 457
diff changeset
358 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
359 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
360
5994e61cdebd Added a widget to be displayed after the player completes the game.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 465
diff changeset
361 def isVisible(self):
471
7a79dc2a0592 Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 469
diff changeset
362 return self._widget.isVisible()
7a79dc2a0592 Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 469
diff changeset
363
7a79dc2a0592 Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 469
diff changeset
364 class CreditsDisplay(object):
7a79dc2a0592 Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 469
diff changeset
365 def __init__(self, world):
7a79dc2a0592 Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 469
diff changeset
366 self._world = world
7a79dc2a0592 Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 469
diff changeset
367 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
368
7a79dc2a0592 Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 469
diff changeset
369 eventMap = {
7a79dc2a0592 Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 469
diff changeset
370 'close': self.hide,
7a79dc2a0592 Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 469
diff changeset
371 }
7a79dc2a0592 Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 469
diff changeset
372
7a79dc2a0592 Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 469
diff changeset
373 self._widget.mapEvents(eventMap)
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 def show(self):
7a79dc2a0592 Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 469
diff changeset
376 self._widget.show()
7a79dc2a0592 Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 469
diff changeset
377
7a79dc2a0592 Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 469
diff changeset
378 def hide(self):
7a79dc2a0592 Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 469
diff changeset
379 self._widget.hide()