changeset 456:41fd97da94d1

Moved guis to their own file. Added a continue button to the main menu.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Wed, 07 Apr 2010 21:26:26 +0000
parents e686b82d93d0
children 597b066d5ccb
files demos/shooter/gui/hud.xml demos/shooter/gui/mainmenu.xml demos/shooter/gui/mainwindow.xml demos/shooter/scripts/gui/__init__.py demos/shooter/scripts/gui/guis.py demos/shooter/scripts/world.py
diffstat 5 files changed, 132 insertions(+), 83 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/demos/shooter/gui/hud.xml	Wed Apr 07 21:26:26 2010 +0000
@@ -0,0 +1,18 @@
+<VBox opaque='0'>
+	<HBox opaque='0'>
+			<Label text = "FPS: "/>
+			<Label name="fps" text="000"/>
+	</HBox>
+	<HBox opaque='0'>
+			<Label text = "Player Position: "/>
+			<Label name="position" text="x,y                           "/>
+	</HBox>
+	<HBox opaque='0'>
+			<Label text = "Player Velocity: "/>
+			<Label name="velocity" text="x,y                           "/>
+	</HBox>
+	<HBox opaque='0'>
+			<Label text = "SCORE: "/>
+			<Label name="score" text="0                             "/>
+	</HBox>
+</VBox>
\ No newline at end of file
--- a/demos/shooter/gui/mainmenu.xml	Wed Apr 07 19:37:42 2010 +0000
+++ b/demos/shooter/gui/mainmenu.xml	Wed Apr 07 21:26:26 2010 +0000
@@ -1,4 +1,4 @@
-<Container name="Main" position="0,0" size="1024,768" border_size="0" base_color="0,0,0" opaque="1">
+<Container name="Main" position="0,0" size="1024,768" border_size="0" base_color="0,0,0" opaque="0">
 
 <!--
 	<Icon image="gui/backgrounds/800_main_bg.png" position="0,0" size="1024,768" name="main_background_icon"/>
@@ -6,7 +6,7 @@
 
 	<VBox opaque='0' base_color="188, 0, 0" position="412,200" name="main_menu">
 		<HBox>
-			<VBox name="menu">
+			<VBox>
 				<Button name="continue" text="Continue" min_size="200,0" border_size="0"/>
 				<Button name="new_game" text="New Game" min_size="200,0" border_size="0"/>
 				<Button name="high_scores" text="High Scores" min_size="200,0" border_size="0"/>
--- a/demos/shooter/gui/mainwindow.xml	Wed Apr 07 19:37:42 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,18 +0,0 @@
-<VBox opaque='0'>
-	<HBox opaque='0'>
-			<Label text = "FPS: "/>
-			<Label name="fps" text="000"/>
-	</HBox>
-	<HBox opaque='0'>
-			<Label text = "Player Position: "/>
-			<Label name="position" text="x,y                           "/>
-	</HBox>
-	<HBox opaque='0'>
-			<Label text = "Player Velocity: "/>
-			<Label name="velocity" text="x,y                           "/>
-	</HBox>
-	<HBox opaque='0'>
-			<Label text = "SCORE: "/>
-			<Label name="score" text="0                             "/>
-	</HBox>
-</VBox>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/demos/shooter/scripts/gui/guis.py	Wed Apr 07 21:26:26 2010 +0000
@@ -0,0 +1,103 @@
+# -*- coding: utf-8 -*-
+
+# ####################################################################
+#  Copyright (C) 2005-2009 by the FIFE team
+#  http://www.fifengine.de
+#  This file is part of FIFE.
+#
+#  FIFE is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU Lesser General Public
+#  License as published by the Free Software Foundation; either
+#  version 2.1 of the License, or (at your option) any later version.
+#
+#  This library is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+#  Lesser General Public License for more details.
+#
+#  You should have received a copy of the GNU Lesser General Public
+#  License along with this library; if not, write to the
+#  Free Software Foundation, Inc.,
+#  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+# ####################################################################
+
+from fife import fife
+from fife.extensions import pychan
+from fife.extensions.pychan import widgets
+
+class MainMenu(object):
+	def __init__(self, world):
+		self._world = world
+		self._widget = pychan.loadXML('gui/mainmenu.xml')
+
+		self._continue = self._widget.findChild(name="continue")
+		self._newgame = self._widget.findChild(name="new_game")
+		self._credits = self._widget.findChild(name="credits")
+		self._highscores = self._widget.findChild(name="high_scores")
+		self._quit = self._widget.findChild(name="quit")
+		
+		self._widget.position = (0,0)
+
+		eventMap = {
+			'continue': self._world.continueGame,
+			'new_game': self._world.newGame,
+			'credits': self._world.showCredits,
+			'high_scores': self._world.showHighScores,
+			'quit': self._world.quit,
+		}
+
+		self._widget.mapEvents(eventMap)		
+		
+		self._continueMinWidth = self._continue.min_width
+		self._continueMinHeight = self._continue.min_height
+		self._continueMaxWidth = self._continue.max_width
+		self._continueMaxHeight = self._continue.max_height	
+
+		
+	def show(self, cont=False):
+		if cont:
+			self._continue.min_width = self._continueMinWidth
+			self._continue.min_height = self._continueMinHeight
+			self._continue.max_width = self._continueMaxWidth
+			self._continue.max_height = self._continueMaxHeight
+			
+		else:
+			self._continue.min_width = 0
+			self._continue.min_height = 0
+			self._continue.max_width = 0
+			self._continue.max_height = 0
+
+		self._continue.adaptLayout()
+		self._widget.show()
+		
+	def hide(self):
+		self._widget.hide()
+		
+class HeadsUpDisplay(object):
+	def __init__(self, world):
+		self._world = world
+		self._widget = pychan.loadXML('gui/hud.xml')
+		
+		self._fpstext = self._widget.findChild(name="fps")
+		self._velocitytext = self._widget.findChild(name="velocity")
+		self._positiontext = self._widget.findChild(name="position")
+		self._scoretext = self._widget.findChild(name="score")
+		self._widget.position = (0,0)
+		
+	def show(self):
+		self._widget.show()
+		
+	def hide(self):
+		self._widget.hide()
+		
+	def setFPSText(self, text):
+		self._fpstext.text = text
+		
+	def setPositionText(self, text):
+		self._positiontext.text = text
+		
+	def setVelocityText(self, text):
+		self._velocitytext.text = text
+		
+	def setScoreText(self, text):
+		self._scoretext.text = text
\ No newline at end of file
--- a/demos/shooter/scripts/world.py	Wed Apr 07 19:37:42 2010 +0000
+++ b/demos/shooter/scripts/world.py	Wed Apr 07 21:26:26 2010 +0000
@@ -30,59 +30,12 @@
 from scripts.common.helpers import normalize
 from fife.extensions.loaders import loadMapFile
 
+from scripts.gui.guis import *
+
 from scripts.ships.shipbase import Ship
 from scripts.ships.player import Player
 from scripts.scene import Scene
 
-class MainMenu(object):
-	def __init__(self, world):
-		self._world = world
-		self._widget = pychan.loadXML('gui/mainmenu.xml')
-
-		self._continue = self._widget.findChild(name="continue")
-		self._newgame = self._widget.findChild(name="new_game")
-		self._credits = self._widget.findChild(name="credits")
-		self._highscores = self._widget.findChild(name="high_scores")
-		self._quit = self._widget.findChild(name="quit")
-		
-		self._widget.position = (0,0)
-
-		eventMap = {
-			'continue': self._world.continueGame,
-			'new_game': self._world.newGame,
-			'credits': self._world.showCredits,
-			'high_scores': self._world.showHighScores,
-			'quit': self._world.quit,
-		}
-
-		self._widget.mapEvents(eventMap)		
-		
-		self._continueMinWidth = self._continue.min_width
-		self._continueMinHeight = self._continue.min_height
-		self._continueMaxWidth = self._continue.max_width
-		self._continueMaxHeight = self._continue.max_height	
-
-		
-	def show(self, cont=False):
-		if cont:
-			self._continue.min_width = self._continueMinWidth
-			self._continue.min_height = self._continueMinHeight
-			self._continue.max_width = self._continueMaxWidth
-			self._continue.max_height = self._continueMaxHeight
-			
-		else:
-			self._continue.min_width = 0
-			self._continue.min_height = 0
-			self._continue.max_width = 0
-			self._continue.max_height = 0
-
-		self._continue.adaptLayout()
-		self._widget.show()
-		
-	def hide(self):
-		self._widget.hide()
-		
-
 class World(EventListenerBase):
 	"""
 	The world!
@@ -114,7 +67,8 @@
 		self._mainmenu = MainMenu(self)
 		self.showMainMenu()
 		
-		self._hudwindow = None
+		self._hudwindow = HeadsUpDisplay(self)
+		self._hudwindow.hide()
 
 	
 	def showMainMenu(self):
@@ -154,16 +108,8 @@
 		self.map = loadMapFile(self.filename, self.engine)
 
 		self.scene = Scene(self.engine, self.map.getLayer('objects'))
-		
-		if not self._hudwindow:
-			self._hudwindow = pychan.loadXML('gui/mainwindow.xml')
-			self.fpstext = self._hudwindow.findChild(name="fps")
-			self.velocitytext = self._hudwindow.findChild(name="velocity")
-			self.positiontext = self._hudwindow.findChild(name="position")
-			self.scoretext = self._hudwindow.findChild(name="score")
-			self._hudwindow.position = (0,0)
-		
 		self.scene.initScene(self.map)
+
 		self.initCameras()
 
 		self._hudwindow.show()
@@ -267,18 +213,18 @@
 			else:
 				fps = 0
 			fpstxt = "%3.2f" % fps
-			self.fpstext.text = unicode(fpstxt)
+			self._hudwindow.setFPSText(unicode(fpstxt))
 		
 			player = self.scene.player
 			exactcoords = player.location.getExactLayerCoordinates()
 			pos = "%1.2f" % exactcoords.x + ", %1.2f" % exactcoords.y
-			self.positiontext.text = unicode(pos)
+			self._hudwindow.setPositionText(unicode(pos))
 		
 			vel = "%1.2f" % player.velocity.x + ", %1.2f" % player.velocity.y
-			self.velocitytext.text = unicode(vel)
+			self._hudwindow.setVelocityText(unicode(vel))
 		
 			score = unicode(str(player.score))
-			self.scoretext.text = score
+			self._hudwindow.setScoreText(score)
 			
 		else:
 			if not self.scene.paused: