Re #752 (CEGUIDemo) Loading menu done (before the Results menu) + reworked menu instances life cycle management
git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@5114 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: 3d6c5093c2a6b4194db702feb5a8316c5934e467 Former-commit-id: ee943ac7d22df3c2f23d95ce4177cfc8f4136998
This commit is contained in:
parent
cb8321915a
commit
20487120a2
22 changed files with 404 additions and 113 deletions
|
@ -1,26 +1,27 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project CEGUIDefaultResolution="800x600" CEGUIVersion="0.7" baseDirectory="." fontsPath="datafiles/fonts" imagesetsPath="datafiles/imagesets" layoutsPath="datafiles/layouts" looknfeelsPath="datafiles/looknfeels" schemesPath="datafiles/schemes" version="CEED Project 1" xmlSchemasPath="datafiles/xml_schemas">
|
||||
<Items>
|
||||
<Item name="ImageSets" type="folder">
|
||||
<Item path="datafiles/imagesets/ceguidemolook.imageset" type="file" />
|
||||
<Item path="datafiles/imagesets/sd-logo.imageset" type="file" />
|
||||
<Item path="datafiles/imagesets/splash-carselect.imageset" type="file" />
|
||||
<Item path="datafiles/imagesets/splash-credits.imageset" type="file" />
|
||||
<Item path="datafiles/imagesets/splash-main.imageset" type="file" />
|
||||
<Item path="datafiles/imagesets/splash-options.imageset" type="file" />
|
||||
<Item path="datafiles/imagesets/splash-trackselect.imageset" type="file" />
|
||||
</Item>
|
||||
<Item name="Layouts" type="folder">
|
||||
<Item path="datafiles/layouts/dialogokcancel.layout" type="file" />
|
||||
<Item path="datafiles/layouts/menucarselect.layout" type="file" />
|
||||
<Item path="datafiles/layouts/menucredits.layout" type="file" />
|
||||
<Item path="datafiles/layouts/menumain.layout" type="file" />
|
||||
<Item path="datafiles/layouts/menuoptions.layout" type="file" />
|
||||
<Item path="datafiles/layouts/menutrackselect.layout" type="file" />
|
||||
<Item path="datafiles/layouts/menuprofiles.layout" type="file" />
|
||||
</Item>
|
||||
<Item name="Schemes" type="folder">
|
||||
<Item path="datafiles/schemes/ceguidemo.scheme" type="file" />
|
||||
</Item>
|
||||
</Items>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project CEGUIDefaultResolution="800x600" CEGUIVersion="0.7" baseDirectory="." fontsPath="datafiles/fonts" imagesetsPath="datafiles/imagesets" layoutsPath="datafiles/layouts" looknfeelsPath="datafiles/looknfeels" schemesPath="datafiles/schemes" version="CEED Project 1" xmlSchemasPath="datafiles/xml_schemas">
|
||||
<Items>
|
||||
<Item name="ImageSets" type="folder">
|
||||
<Item path="datafiles/imagesets/ceguidemolook.imageset" type="file" />
|
||||
<Item path="datafiles/imagesets/sd-logo.imageset" type="file" />
|
||||
<Item path="datafiles/imagesets/splash-carselect.imageset" type="file" />
|
||||
<Item path="datafiles/imagesets/splash-credits.imageset" type="file" />
|
||||
<Item path="datafiles/imagesets/splash-main.imageset" type="file" />
|
||||
<Item path="datafiles/imagesets/splash-options.imageset" type="file" />
|
||||
<Item path="datafiles/imagesets/splash-trackselect.imageset" type="file" />
|
||||
</Item>
|
||||
<Item name="Layouts" type="folder">
|
||||
<Item path="datafiles/layouts/dialogokcancel.layout" type="file" />
|
||||
<Item path="datafiles/layouts/menucarselect.layout" type="file" />
|
||||
<Item path="datafiles/layouts/menucredits.layout" type="file" />
|
||||
<Item path="datafiles/layouts/menumain.layout" type="file" />
|
||||
<Item path="datafiles/layouts/menuoptions.layout" type="file" />
|
||||
<Item path="datafiles/layouts/menuprofiles.layout" type="file" />
|
||||
<Item path="datafiles/layouts/menutrackselect.layout" type="file" />
|
||||
<Item path="datafiles/layouts/menuloading.layout" type="file" />
|
||||
</Item>
|
||||
<Item name="Schemes" type="folder">
|
||||
<Item path="datafiles/schemes/ceguidemo.scheme" type="file" />
|
||||
</Item>
|
||||
</Items>
|
||||
</Project>
|
|
@ -41,11 +41,10 @@
|
|||
<Image Height="6" Name="StaticBottomLeft" Width="6" XPos="74" YPos="335" />
|
||||
<Image Height="6" Name="StaticBottomRight" Width="6" XPos="96" YPos="335" />
|
||||
<Image Height="6" Name="StaticBackdrop" Width="6" XPos="85" YPos="324" />
|
||||
<Image Height="12" Name="ProgressBarLeft" Width="7" XPos="71" YPos="74" />
|
||||
<Image Height="12" Name="ProgressBarMiddle" Width="6" XPos="80" YPos="74" />
|
||||
<Image Height="12" Name="ProgressBarRight" Width="6" XPos="88" YPos="74" />
|
||||
<Image Height="12" Name="ProgressBarDimSegment" Width="8" XPos="96" YPos="74" />
|
||||
<Image Height="12" Name="ProgressBarLitSegment" Width="8" XPos="106" YPos="74" />
|
||||
<Image Height="12" Name="ProgressBarLeft" Width="8" XPos="75" YPos="355" />
|
||||
<Image Height="12" Name="ProgressBarMiddle" Width="8" XPos="83" YPos="355" />
|
||||
<Image Height="12" Name="ProgressBarRight" Width="8" XPos="91" YPos="355" />
|
||||
<Image Height="12" Name="ProgressBarLitSegment" Width="8" XPos="100" YPos="355" />
|
||||
<Image Height="18" Name="EditBoxLeft" Width="4" XPos="234" YPos="219" />
|
||||
<Image Height="18" Name="EditBoxMiddle" Width="4" XPos="240" YPos="219" />
|
||||
<Image Height="18" Name="EditBoxRight" Width="4" XPos="246" YPos="219" />
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 45 KiB After Width: | Height: | Size: 45 KiB |
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" ?>
|
||||
<Imageset Name="SplashLoading" AutoScaled="true" Imagefile="splash-loading.jpg" NativeHorzRes="800" NativeVertRes="600">
|
||||
<Image Name="everything" Height="800" Width="1280" XPos="0" YPos="0" />
|
||||
</Imageset>
|
BIN
src/tools/ceguidemo/datafiles/imagesets/splash-loading.jpg
Normal file
BIN
src/tools/ceguidemo/datafiles/imagesets/splash-loading.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 40 KiB |
47
src/tools/ceguidemo/datafiles/layouts/menuloading.layout
Normal file
47
src/tools/ceguidemo/datafiles/layouts/menuloading.layout
Normal file
|
@ -0,0 +1,47 @@
|
|||
<GUILayout>
|
||||
<Window Name="MenuLoading" Type="CEGUIDemo/StaticImage">
|
||||
<Property Name="UnifiedAreaRect" Value="{{0,0},{0,0},{1,0},{1,0}}" />
|
||||
<Property Name="Image" Value="set:SplashLoading image:everything" />
|
||||
<Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
|
||||
<Property Name="FrameEnabled" Value="False" />
|
||||
<Property Name="BackgroundEnabled" Value="False" />
|
||||
<Window Name="MenuLoading/ImgLogo" Type="CEGUIDemo/StaticImage">
|
||||
<Property Name="UnifiedAreaRect" Value="{{0,0},{0,0},{0.3,0},{0.25,0}}" />
|
||||
<Property Name="Image" Value="set:Logo image:everything" />
|
||||
<Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
|
||||
<Property Name="Tooltip" Value="What a nice logo !" />
|
||||
<Property Name="FrameEnabled" Value="False" />
|
||||
<Property Name="BackgroundEnabled" Value="False" />
|
||||
</Window>
|
||||
<Window Name="MenuLoading/TxtTitle" Type="CEGUIDemo/PageTitle">
|
||||
<Property Name="UnifiedAreaRect" Value="{{0.22,0},{0.1,0},{0.92,0},{0.2,0}}" />
|
||||
<Property Name="Font" Value="MenuTitle" />
|
||||
<Property Name="Text" Value="Loading ..." />
|
||||
<Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
|
||||
<Property Name="Tooltip" Value="Yeah, this is the title of the menu !" />
|
||||
<Property Name="FrameEnabled" Value="False" />
|
||||
</Window>
|
||||
<Window Name="MenuLoading/TxtFrameRate" Type="CEGUIDemo/StaticText">
|
||||
<Property Name="UnifiedAreaRect" Value="{{0.95,0},{0.01,0},{0.99,0},{0.04,0}}" />
|
||||
<Property Name="Font" Value="TextSmall" />
|
||||
<Property Name="Text" Value="99.9" />
|
||||
<Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
|
||||
<Property Name="TextColours" Value="tl:FFFFFFFF tr:FFC0C0C0 bl:FF808080 br:FF606060" />
|
||||
<Property Name="Tooltip" Value="Frame rate (F/s)" />
|
||||
<Property Name="FrameEnabled" Value="False" />
|
||||
<Property Name="HorzFormatting" Value="RightAligned" />
|
||||
<Property Name="VertFormatting" Value="TopAligned" />
|
||||
<Property Name="BackgroundEnabled" Value="False" />
|
||||
</Window>
|
||||
<Window Name="MenuLoading/PrbProgress" Type="CEGUIDemo/ProgressBar">
|
||||
<Property Name="UnifiedAreaRect" Value="{{0.1,0},{0.9,0},{0.9,0},{0.95,0}}" />
|
||||
<Property Name="StepSize" Value="0.01" />
|
||||
<Property Name="Tooltip" Value="Current loading work progress" />
|
||||
</Window>
|
||||
<Window Name="MenuLoading/ScpMessages" Type="CEGUIDemo/ScrollablePane">
|
||||
<Property Name="UnifiedAreaRect" Value="{{0.1,0},{0.27,0},{0.9,0},{0.87,0}}" />
|
||||
<Property Name="Font" Value="MenuMedium" />
|
||||
<Property Name="Tooltip" Value="Loading messages" />
|
||||
</Window>
|
||||
</Window>
|
||||
</GUILayout>
|
|
@ -1,4 +1,8 @@
|
|||
<?xml version="1.0" ?>
|
||||
<!--
|
||||
CEGUI demo application look & feel for checking if CEGUI could be used for Speed Dreams menus
|
||||
Note: Heavily based on Falagard's look & feel (from CEGUI 0.7.5).
|
||||
-->
|
||||
<Falagard>
|
||||
<!--
|
||||
***************************************************
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
<Imageset Filename="splash-credits.imageset" />
|
||||
<Imageset Filename="splash-options.imageset" />
|
||||
<Imageset Filename="splash-profiles.imageset" />
|
||||
<Imageset Filename="splash-loading.imageset" />
|
||||
<Imageset Filename="splash-okcancel.imageset" />
|
||||
<Font Name="MenuSmall" Filename="menu-small.font" />
|
||||
<Font Name="MenuMedium" Filename="menu-medium.font" />
|
||||
|
|
|
@ -26,7 +26,7 @@ class DialogOKCancel(object):
|
|||
|
||||
singleton = None
|
||||
|
||||
def getSingleton():
|
||||
def instance():
|
||||
|
||||
if not DialogOKCancel.singleton:
|
||||
DialogOKCancel.singleton = DialogOKCancel()
|
||||
|
@ -35,7 +35,7 @@ class DialogOKCancel(object):
|
|||
|
||||
return DialogOKCancel.singleton
|
||||
|
||||
getSingleton = staticmethod(getSingleton)
|
||||
instance = staticmethod(instance)
|
||||
|
||||
def __init__(self):
|
||||
|
||||
|
|
|
@ -17,7 +17,8 @@ import PyCEGUI
|
|||
|
||||
# Import: User
|
||||
from errors import InitializationError
|
||||
from menumain import MenuMain
|
||||
from menufactory import MenuFactory
|
||||
from menumanager import MenuManager
|
||||
|
||||
# Import: Configuration
|
||||
from configuration import TheConfig
|
||||
|
@ -74,11 +75,13 @@ class GUI(object):
|
|||
self.initializeResources()
|
||||
self.initializeDefaults()
|
||||
|
||||
MenuFactory.initialize()
|
||||
|
||||
except Exception, msg:
|
||||
|
||||
raise InitializationError(msg)
|
||||
|
||||
# Setup: Interface
|
||||
def setupInterface(self):
|
||||
|
||||
MenuMain.instance().activate()
|
||||
|
||||
MenuManager.get("Main").activate()
|
||||
|
|
|
@ -171,10 +171,6 @@ class Menu(object):
|
|||
if previous:
|
||||
self.prevMenu = previous
|
||||
|
||||
# Initialize frame rate data.
|
||||
self.nFrames = 0
|
||||
self.lastTime = glutGet(GLUT_ELAPSED_TIME)
|
||||
|
||||
# Return to the previous menu.
|
||||
def switchTo(self, menu):
|
||||
|
||||
|
@ -193,13 +189,13 @@ class Menu(object):
|
|||
# Update frame rate indicator.
|
||||
def onUpdate(self, winArgs): # Bug: Not an UpdateEventArgs, but a WindowEventArgs !
|
||||
|
||||
thisTime = glutGet(GLUT_ELAPSED_TIME)
|
||||
elapsed = (thisTime - self.lastTime) / 1000.0
|
||||
self.currTime = glutGet(GLUT_ELAPSED_TIME)
|
||||
elapsed = (self.currTime - self.lastTime) / 1000.0
|
||||
self.nFrames += 1
|
||||
if elapsed >= 1.0: # Skidding mean for each second
|
||||
self.txtFrameRate.setText("%4.1f" % (self.nFrames / elapsed))
|
||||
self.nFrames = 0
|
||||
self.lastTime = thisTime
|
||||
self.lastTime = self.currTime
|
||||
|
||||
def onKeyDown(self, keyArgs):
|
||||
|
||||
|
@ -211,7 +207,13 @@ class Menu(object):
|
|||
def onActivated(self, args):
|
||||
|
||||
print("%s.onActivated" % self.__class__.__name__)
|
||||
|
||||
#self.connectHandlers()
|
||||
|
||||
# Initialize frame rate data.
|
||||
self.nFrames = 0
|
||||
self.currTime = self.lastTime = glutGet(GLUT_ELAPSED_TIME)
|
||||
|
||||
return False
|
||||
|
||||
def onDeactivated(self, args):
|
||||
|
|
|
@ -18,15 +18,14 @@ import PyCEGUI
|
|||
from configuration import TheConfig
|
||||
|
||||
# Import: Menu
|
||||
from menustandard import MenuStandard
|
||||
from menucredits import MenuCredits
|
||||
from menuoptions import MenuOptions
|
||||
from menuprofiles import MenuProfiles
|
||||
from menuresults import MenuResults
|
||||
from menustandard import MenuStandard
|
||||
from menumanager import MenuManager
|
||||
|
||||
|
||||
# Car selection menu
|
||||
class MenuCarSelect(MenuStandard):
|
||||
|
||||
# Static cars data.
|
||||
Car = collections.namedtuple("Car", "name, topSpeed, acceleration, cornering, skins")
|
||||
|
||||
Cars = \
|
||||
|
@ -60,12 +59,24 @@ class MenuCarSelect(MenuStandard):
|
|||
}
|
||||
}
|
||||
|
||||
# Singleton pattern.
|
||||
singleton = None
|
||||
|
||||
def instance():
|
||||
|
||||
if not MenuCarSelect.singleton:
|
||||
MenuCarSelect.singleton = MenuCarSelect()
|
||||
MenuCarSelect.singleton.initialize()
|
||||
MenuCarSelect.singleton.setup()
|
||||
|
||||
return MenuCarSelect.singleton
|
||||
|
||||
instance = staticmethod(instance)
|
||||
|
||||
def __init__(self):
|
||||
|
||||
MenuStandard.__init__(self, MenuCredits, MenuOptions, MenuProfiles)
|
||||
MenuStandard.__init__(self)
|
||||
|
||||
self.menuResults = None
|
||||
|
||||
# Initialize
|
||||
def initialize(self):
|
||||
|
||||
|
@ -141,12 +152,7 @@ class MenuCarSelect(MenuStandard):
|
|||
# Handler: buttonClicked
|
||||
def onStartButtonClicked(self, args):
|
||||
|
||||
if not self.menuResults:
|
||||
self.menuResults = MenuResults()
|
||||
self.menuResults.initialize()
|
||||
self.menuResults.setup()
|
||||
|
||||
self.menuResults.activate(previous=self)
|
||||
self.switchTo(MenuManager.get("Loading"))
|
||||
|
||||
def onBackButtonClicked(self, args):
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ class MenuCredits(Menu):
|
|||
|
||||
singleton = None
|
||||
|
||||
def getSingleton():
|
||||
def instance():
|
||||
|
||||
if not MenuCredits.singleton:
|
||||
MenuCredits.singleton = MenuCredits()
|
||||
|
@ -33,7 +33,7 @@ class MenuCredits(Menu):
|
|||
|
||||
return MenuCredits.singleton
|
||||
|
||||
getSingleton = staticmethod(getSingleton)
|
||||
instance = staticmethod(instance)
|
||||
|
||||
def __init__(self):
|
||||
|
||||
|
|
38
src/tools/ceguidemo/menufactory.py
Normal file
38
src/tools/ceguidemo/menufactory.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
|
||||
"""Menu factory.
|
||||
|
||||
|
||||
"""
|
||||
|
||||
# Import: Menus manager
|
||||
from menumanager import MenuManager
|
||||
|
||||
# Import: Menus
|
||||
from menucredits import MenuCredits
|
||||
from menuoptions import MenuOptions
|
||||
from menuprofiles import MenuProfiles
|
||||
from menumain import MenuMain
|
||||
from menutrackselect import MenuTrackSelect
|
||||
from menucarselect import MenuCarSelect
|
||||
from menuloading import MenuLoading
|
||||
from menuresults import MenuResults
|
||||
|
||||
|
||||
class MenuFactory:
|
||||
|
||||
def initialize():
|
||||
|
||||
MenuManager.register("Credits", MenuCredits.instance)
|
||||
MenuManager.register("Options", MenuOptions.instance)
|
||||
MenuManager.register("Profiles", MenuProfiles.instance)
|
||||
|
||||
MenuManager.register("Main", MenuMain.instance)
|
||||
MenuManager.register("TrackSelect", MenuTrackSelect.instance)
|
||||
MenuManager.register("CarSelect", MenuCarSelect.instance)
|
||||
MenuManager.register("Loading", MenuLoading.instance)
|
||||
MenuManager.register("Results", MenuResults.instance)
|
||||
|
||||
initialize = staticmethod(initialize)
|
170
src/tools/ceguidemo/menuloading.py
Normal file
170
src/tools/ceguidemo/menuloading.py
Normal file
|
@ -0,0 +1,170 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
|
||||
"""Loading menu.
|
||||
|
||||
|
||||
"""
|
||||
|
||||
# Import: std
|
||||
import sys
|
||||
import time
|
||||
import collections
|
||||
|
||||
# Import: PyCEGUI
|
||||
import PyCEGUI
|
||||
|
||||
# Import: Configuration
|
||||
from configuration import TheConfig
|
||||
|
||||
# Import: Menu
|
||||
from menu import Menu
|
||||
from menumanager import MenuManager
|
||||
|
||||
|
||||
# Loading menu
|
||||
class MenuLoading(Menu):
|
||||
|
||||
# Static data.
|
||||
Msg = collections.namedtuple("Msg", "time, dur, txt")
|
||||
|
||||
Messages = \
|
||||
(Msg(time= 0.0, dur=0.1, txt="Loading Forza track by A. Sumner (5784m long, 11m wide)"),
|
||||
Msg(time= 0.1, dur=0.9, txt="Determining starting order"),
|
||||
Msg(time= 1.0, dur=1.0, txt="Preparing starting grid"),
|
||||
Msg(time= 2.0, dur=2.0, txt="Loading physics engine (Simu V2.1)"),
|
||||
Msg(time= 4.0, dur=1.0, txt="Loading Aarne Fisher driver (Boxer 96)"),
|
||||
Msg(time= 5.0, dur=1.0, txt="Loading Jacky Graham driver (Spirit 300)"),
|
||||
Msg(time= 6.0, dur=1.0, txt="Loading Tony Davis driver (Cavallo 360)"),
|
||||
Msg(time= 7.0, dur=2.0, txt="Loading graphics for Forza track"),
|
||||
Msg(time= 9.0, dur=1.0, txt="Running pre-start"),
|
||||
Msg(time=10.0, dur=2.0, txt="Loading graphics for all cars"),
|
||||
Msg(time=12.0, dur=1.0, txt="Loading sounds for all cars"),
|
||||
Msg(time=13.0, dur=1.0, txt="Ready"),
|
||||
Msg(time=14.0, dur=1.0, txt="Set"),
|
||||
Msg(time=15.0, dur=1.0, txt="Go"),
|
||||
Msg(time=16.0, dur=0.0, txt="Now, you should be racing"))
|
||||
|
||||
# Singleton pattern.
|
||||
singleton = None
|
||||
|
||||
def instance():
|
||||
|
||||
if not MenuLoading.singleton:
|
||||
MenuLoading.singleton = MenuLoading()
|
||||
MenuLoading.singleton.initialize()
|
||||
MenuLoading.singleton.setup()
|
||||
|
||||
return MenuLoading.singleton
|
||||
|
||||
instance = staticmethod(instance)
|
||||
|
||||
def __init__(self):
|
||||
|
||||
Menu.__init__(self)
|
||||
|
||||
# Initialize
|
||||
def initialize(self):
|
||||
|
||||
name = "MenuLoading"
|
||||
|
||||
# No code written for this menu : use mandatory layout.
|
||||
window = Menu.initialize(self, name=name, title="Loading", layout="menuloading")
|
||||
|
||||
# Retrieve window descendants created here.
|
||||
self.prbProgress = window.getChild(name + "/PrbProgress")
|
||||
self.scpMessages = window.getChild(name + "/ScpMessages")
|
||||
|
||||
# Complete widget initialization.
|
||||
|
||||
return window
|
||||
|
||||
# connectHandlers
|
||||
# - Wrapper method to define the subscription/listener relationships.
|
||||
# - If there are a lot, it may behoove the coder to encapsulate them in methods, then call those methods here.
|
||||
def connectHandlers(self):
|
||||
|
||||
# Inherited connections.
|
||||
Menu.connectHandlers(self)
|
||||
|
||||
# Specific connections.
|
||||
# None (onUpdate inherited).
|
||||
|
||||
def onActivated(self, args):
|
||||
|
||||
print("%s.onActivated" % self.__class__.__name__)
|
||||
|
||||
sts = Menu.onActivated(self, args)
|
||||
|
||||
self.actTime = self.currTime
|
||||
self.curInd = -1
|
||||
|
||||
if self.scpMessages.getContentPane().getChildCount() > 0:
|
||||
for ind in range(len(self.Messages)):
|
||||
txtChld = self.scpMessages.getContentPane().getChild("MenuLoading/ScpMessages/Msg%d" % ind)
|
||||
self.scpMessages.getContentPane().removeChildWindow(txtChld)
|
||||
txtChld.destroy()
|
||||
|
||||
self.prbProgress.setProgress(0)
|
||||
|
||||
return sts
|
||||
|
||||
def onUpdate(self, args):
|
||||
|
||||
Menu.onUpdate(self, args)
|
||||
|
||||
sinceAct = (self.currTime - self.actTime) / 1000.0
|
||||
|
||||
#print("Since=%.2f, curr=%d" % (sinceAct, self.curInd))
|
||||
|
||||
if self.curInd < 0 \
|
||||
or (sinceAct > self.Messages[self.curInd].time + self.Messages[self.curInd].dur):
|
||||
|
||||
# Next message : if none left, wait a little, and then switch to next menu.
|
||||
if self.curInd == len(self.Messages) - 1:
|
||||
|
||||
if sinceAct > self.Messages[self.curInd].time + self.Messages[self.curInd].dur + 2.0:
|
||||
self.switchTo(MenuManager.get("Results"))
|
||||
else:
|
||||
self.prbProgress.hide()
|
||||
time.sleep(0.01) # Let the CPU keep cool (no hurry).
|
||||
|
||||
# Next message : if at least one left ...
|
||||
else:
|
||||
|
||||
self.curInd = self.curInd + 1
|
||||
|
||||
# Create and add the static text for the new message.
|
||||
scpItem = PyCEGUI.WindowManager.getSingleton().createWindow("CEGUIDemo/StaticText", "MenuLoading/ScpMessages/Msg%d" % self.curInd)
|
||||
scpItem.setText(self.Messages[self.curInd].txt + " ...")
|
||||
scpItem.setProperty("FrameEnabled", "false")
|
||||
scpItem.setProperty("BackgroundEnabled", "false")
|
||||
scpItem.setXPosition(PyCEGUI.UDim(0.0, 0.0))
|
||||
scpItem.setYPosition(PyCEGUI.UDim(1.0 + self.curInd * 0.10, 0.0))
|
||||
scpItem.setWidth(PyCEGUI.UDim(1.0, 0.0))
|
||||
scpItem.setHeight(PyCEGUI.UDim(0.10, 0.0))
|
||||
self.scpMessages.addChildWindow(scpItem)
|
||||
|
||||
# Adjust alpha for all messages.
|
||||
nChildren = self.scpMessages.getContentPane().getChildCount()
|
||||
for chldInd in range(nChildren):
|
||||
txtChld = self.scpMessages.getContentPane().getChildAtIdx(chldInd)
|
||||
txtChld.setAlpha(0.85 ** (nChildren - 1 - chldInd))
|
||||
|
||||
# Scroll down to show the added static text.
|
||||
self.scpMessages.setVerticalScrollPosition(1.0)
|
||||
|
||||
# Hide any scrollbar (might get shown after every call to addChildWindow).
|
||||
self.scpMessages.getVertScrollbar().hide()
|
||||
self.scpMessages.getHorzScrollbar().hide()
|
||||
|
||||
# Reset progress-bar.
|
||||
self.prbProgress.setProgress(0)
|
||||
self.prbProgress.show()
|
||||
|
||||
else:
|
||||
|
||||
# Update progress-bar.
|
||||
progress = (sinceAct - self.Messages[self.curInd].time) / self.Messages[self.curInd].dur
|
||||
self.prbProgress.setProgress(progress)
|
|
@ -16,16 +16,14 @@ import PyCEGUI
|
|||
# Import: Configuration
|
||||
from configuration import TheConfig
|
||||
|
||||
# Import: Menu
|
||||
# Import: Menus
|
||||
from menustandard import MenuStandard
|
||||
from menucredits import MenuCredits
|
||||
from menuoptions import MenuOptions
|
||||
from menuprofiles import MenuProfiles
|
||||
from menutrackselect import MenuTrackSelect
|
||||
from menumanager import MenuManager
|
||||
|
||||
# Main menu
|
||||
class MenuMain(MenuStandard):
|
||||
|
||||
# Singleton pattern.
|
||||
singleton = None
|
||||
|
||||
def instance():
|
||||
|
@ -41,10 +39,8 @@ class MenuMain(MenuStandard):
|
|||
|
||||
def __init__(self):
|
||||
|
||||
MenuStandard.__init__(self, MenuCredits, MenuOptions, MenuProfiles)
|
||||
MenuStandard.__init__(self)
|
||||
|
||||
self.menuTrackSelect = None
|
||||
|
||||
# Initialize
|
||||
def initialize(self):
|
||||
|
||||
|
@ -142,21 +138,12 @@ class MenuMain(MenuStandard):
|
|||
# Handler: buttonClicked
|
||||
def onPracticeButtonClicked(self, args):
|
||||
|
||||
self.activateTrackSelectMenu()
|
||||
self.switchTo(MenuManager.get("TrackSelect"))
|
||||
|
||||
def onQuickRaceButtonClicked(self, args):
|
||||
|
||||
self.activateTrackSelectMenu()
|
||||
self.switchTo(MenuManager.get("TrackSelect"))
|
||||
|
||||
def onSingleEventButtonClicked(self, args):
|
||||
|
||||
self.activateTrackSelectMenu()
|
||||
|
||||
def activateTrackSelectMenu(self):
|
||||
|
||||
if not self.menuTrackSelect:
|
||||
self.menuTrackSelect = MenuTrackSelect()
|
||||
self.menuTrackSelect.initialize()
|
||||
self.menuTrackSelect.setup()
|
||||
|
||||
self.switchTo(self.menuTrackSelect)
|
||||
self.switchTo(MenuManager.get("TrackSelect"))
|
||||
|
|
24
src/tools/ceguidemo/menumanager.py
Normal file
24
src/tools/ceguidemo/menumanager.py
Normal file
|
@ -0,0 +1,24 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
|
||||
"""Menu manager.
|
||||
|
||||
A dictionary of menu instance() functions (see MenuFactory)
|
||||
"""
|
||||
|
||||
class MenuManager:
|
||||
|
||||
menus = { }
|
||||
|
||||
def register(menuName, menuFactory):
|
||||
|
||||
MenuManager.menus[menuName] = menuFactory
|
||||
|
||||
register = staticmethod(register)
|
||||
|
||||
def get(menuName):
|
||||
|
||||
return MenuManager.menus[menuName]()
|
||||
|
||||
get = staticmethod(get)
|
|
@ -24,7 +24,7 @@ class MenuOptions(Menu):
|
|||
|
||||
singleton = None
|
||||
|
||||
def getSingleton():
|
||||
def instance():
|
||||
|
||||
if not MenuOptions.singleton:
|
||||
MenuOptions.singleton = MenuOptions()
|
||||
|
@ -33,7 +33,7 @@ class MenuOptions(Menu):
|
|||
|
||||
return MenuOptions.singleton
|
||||
|
||||
getSingleton = staticmethod(getSingleton)
|
||||
instance = staticmethod(instance)
|
||||
|
||||
def __init__(self):
|
||||
|
||||
|
|
|
@ -22,9 +22,10 @@ from menu import Menu
|
|||
# Profiles menu
|
||||
class MenuProfiles(Menu):
|
||||
|
||||
# Singleton pattern.
|
||||
singleton = None
|
||||
|
||||
def getSingleton():
|
||||
def instance():
|
||||
|
||||
if not MenuProfiles.singleton:
|
||||
MenuProfiles.singleton = MenuProfiles()
|
||||
|
@ -33,7 +34,7 @@ class MenuProfiles(Menu):
|
|||
|
||||
return MenuProfiles.singleton
|
||||
|
||||
getSingleton = staticmethod(getSingleton)
|
||||
instance = staticmethod(instance)
|
||||
|
||||
def __init__(self):
|
||||
|
||||
|
|
|
@ -16,12 +16,14 @@ import PyCEGUI
|
|||
# Import: Configuration
|
||||
from configuration import TheConfig
|
||||
|
||||
# Import: Menu
|
||||
# Import: Menus
|
||||
from menu import Menu
|
||||
from menumanager import MenuManager
|
||||
|
||||
# Results menu
|
||||
class MenuResults(Menu):
|
||||
|
||||
# Static data.
|
||||
CIdRank = 0
|
||||
CIdAdvance = 1
|
||||
CIdDriver = 2
|
||||
|
@ -44,9 +46,10 @@ class MenuResults(Menu):
|
|||
(6, -4, "Don Nelson", "USR", "Lynx 220", "39:15:559", "1:20.602", 36, 285, 4500, 4),
|
||||
]
|
||||
|
||||
# Singleton pattern.
|
||||
singleton = None
|
||||
|
||||
def getSingleton():
|
||||
def instance():
|
||||
|
||||
if not MenuResults.singleton:
|
||||
MenuResults.singleton = MenuResults()
|
||||
|
@ -55,7 +58,7 @@ class MenuResults(Menu):
|
|||
|
||||
return MenuResults.singleton
|
||||
|
||||
getSingleton = staticmethod(getSingleton)
|
||||
instance = staticmethod(instance)
|
||||
|
||||
def __init__(self):
|
||||
|
||||
|
@ -119,7 +122,7 @@ class MenuResults(Menu):
|
|||
|
||||
def onContinueButtonClicked(self, args):
|
||||
|
||||
self.back()
|
||||
self.switchTo(MenuManager.get("Main"))
|
||||
|
||||
def onKeyDown(self, keyArgs):
|
||||
|
||||
|
|
|
@ -15,26 +15,21 @@ import sys
|
|||
# Import: PyCEGUI
|
||||
import PyCEGUI
|
||||
|
||||
# Import: Menu
|
||||
# Import: Menus and dialogs
|
||||
from menu import Menu
|
||||
from dialogs import DialogOKCancel
|
||||
|
||||
# Import: MenuManager
|
||||
from menumanager import MenuManager
|
||||
|
||||
|
||||
# Standard menu
|
||||
class MenuStandard(Menu):
|
||||
|
||||
def __init__(self, clsMenuCredits, clsMenuOptions, clsMenuProfiles):
|
||||
def __init__(self):
|
||||
|
||||
Menu.__init__(self)
|
||||
|
||||
self.clsMenuCredits = clsMenuCredits
|
||||
self.clsMenuOptions = clsMenuOptions
|
||||
self.clsMenuProfiles = clsMenuProfiles
|
||||
|
||||
self.menuCredits = None
|
||||
self.menuProfiles = None
|
||||
self.menuOptions = None
|
||||
|
||||
# Initialize
|
||||
def initialize(self, name, title=None, layout=None, background=None):
|
||||
|
||||
|
@ -117,19 +112,19 @@ class MenuStandard(Menu):
|
|||
# Handlers
|
||||
def onCreditsButtonClicked(self, args):
|
||||
|
||||
self.switchTo(self.clsMenuCredits.getSingleton())
|
||||
self.switchTo(MenuManager.get("Credits"))
|
||||
|
||||
def onProfilesButtonClicked(self, args):
|
||||
|
||||
self.switchTo(self.clsMenuProfiles.getSingleton())
|
||||
self.switchTo(MenuManager.get("Profiles"))
|
||||
|
||||
def onOptionsButtonClicked(self, args):
|
||||
|
||||
self.switchTo(self.clsMenuOptions.getSingleton())
|
||||
self.switchTo(MenuManager.get("Options"))
|
||||
|
||||
def onExitButtonClicked(self, args):
|
||||
|
||||
DialogOKCancel.getSingleton().show(self.window, self.onOKCancelClosed, "Really quit ?")
|
||||
DialogOKCancel.instance().show(self.window, self.onOKCancelClosed, "Really quit ?")
|
||||
|
||||
def onOKCancelClosed(self, reallyQuit=False):
|
||||
|
||||
|
|
|
@ -19,14 +19,13 @@ from configuration import TheConfig
|
|||
|
||||
# Import: Menu
|
||||
from menustandard import MenuStandard
|
||||
from menucredits import MenuCredits
|
||||
from menuoptions import MenuOptions
|
||||
from menuprofiles import MenuProfiles
|
||||
from menucarselect import MenuCarSelect
|
||||
from menumanager import MenuManager
|
||||
|
||||
|
||||
# Track selection menu
|
||||
class MenuTrackSelect(MenuStandard):
|
||||
|
||||
# Static data.
|
||||
Track = collections.namedtuple("Track", "name, description, authors, length, width, nPits, outline, preview")
|
||||
|
||||
Tracks = \
|
||||
|
@ -74,12 +73,24 @@ class MenuTrackSelect(MenuStandard):
|
|||
}
|
||||
}
|
||||
|
||||
# Singleton pattern.
|
||||
singleton = None
|
||||
|
||||
def instance():
|
||||
|
||||
if not MenuTrackSelect.singleton:
|
||||
MenuTrackSelect.singleton = MenuTrackSelect()
|
||||
MenuTrackSelect.singleton.initialize()
|
||||
MenuTrackSelect.singleton.setup()
|
||||
|
||||
return MenuTrackSelect.singleton
|
||||
|
||||
instance = staticmethod(instance)
|
||||
|
||||
def __init__(self):
|
||||
|
||||
MenuStandard.__init__(self, MenuCredits, MenuOptions, MenuProfiles)
|
||||
MenuStandard.__init__(self)
|
||||
|
||||
self.menuCarSelect = None
|
||||
|
||||
# Initialize
|
||||
def initialize(self):
|
||||
|
||||
|
@ -136,12 +147,7 @@ class MenuTrackSelect(MenuStandard):
|
|||
# Handler: buttonClicked
|
||||
def onNextButtonClicked(self, args):
|
||||
|
||||
if not self.menuCarSelect:
|
||||
self.menuCarSelect = MenuCarSelect()
|
||||
self.menuCarSelect.initialize()
|
||||
self.menuCarSelect.setup()
|
||||
|
||||
self.menuCarSelect.activate(previous=self)
|
||||
self.switchTo(MenuManager.get("CarSelect"))
|
||||
|
||||
def onBackButtonClicked(self, args):
|
||||
|
||||
|
|
Loading…
Reference in a new issue