2 Created on 12 nov. 2009
4 @author: Samuel Benveniste
6 from logging
.FamiliarizerLog
import FamiliarizerLog
16 from pygame
.locals import *
20 from StaticFamiliarizer
import StaticFamiliarizer
21 from SongFamiliarizer
import SongFamiliarizer
22 from instruments
.Instrument
import Instrument
23 from cursor
.WarpingCursor
import *
24 from controllers
.Wiimote
import Wiimote
25 from logging
.FamiliarizerLog
import FamiliarizerLog
26 from songs
.Song
import Song
27 from constants
import *
28 from SongPlayingScreen
import SongPlayingScreen
29 from DummyInstrumentChoice
import DummyInstrumentChoice
31 class FamiliarizerPGUConfiguration(gui
.Desktop
):
37 def __init__(self
,window
,defaultParams
= False):
41 gui
.Desktop
.__init
__(self
)
44 self
.scale
= scaleDict
["majorScale"]
45 self
.fileName
= fileName
47 self
.activeWiimotes
= [False for i
in range(4)]
51 self
.titleFont
= pygame
.font
.Font(None,100)
52 self
.font
= pygame
.font
.Font(None,70)
53 self
.spaceSize
= (100,100)
55 self
.goButton
= gui
.Button(self
.createLabel("Go"))
56 self
.goButton
.connect(gui
.CLICK
,self
.goButtonClicked
,None)
58 self
.quitButton
= gui
.Button(self
.createLabel("Fin"))
59 self
.quitButton
.connect(gui
.CLICK
,self
.quitButtonClicked
,None)
61 self
.levelSelect
= gui
.Select()
63 self
.levelSelect
.add(self
.createLabel(str(i
+1)),i
)
64 self
.levelSelect
.connect(gui
.CHANGE
,self
.levelSelectChanged
,None)
66 self
.activeWiimoteSwitches
= [gui
.Switch(False) for i
in range(4)]
67 for i
in range(len(self
.activeWiimoteSwitches
)) :
68 self
.activeWiimoteSwitches
[i
].connect(gui
.CHANGE
,self
.activeWiimoteSwitchesChanged
,i
)
70 self
.connect(gui
.QUIT
,self
.quit
,None)
74 ##The table code is entered much like HTML.
76 mainContainer
= gui
.Table()
81 # c.td(self.createLabel("MINWii",self.titleFont),colspan = 4)
84 c
.td(gui
.Spacer(*self
.spaceSize
))
87 c
.td(self
.createLabel("Niveau :"))
88 c
.td(self
.levelSelect
,colspan
=3)
91 c
.td(gui
.Spacer(*self
.spaceSize
))
94 c
.td(self
.createLabel("Joueurs :", self
.font
))
95 playerTable
= gui
.Table()
96 for i
in range(len(self
.activeWiimoteSwitches
)):
97 playerTable
.td(self
.createLabel(" " + str(i
+1)+" ", self
.font
))
98 playerTable
.td(self
.activeWiimoteSwitches
[i
])
99 c
.td(playerTable
,colspan
= 3)
102 c
.td(gui
.Spacer(*self
.spaceSize
))
106 c
.td(self
.quitButton
,colspan
=3)
109 c
.td(gui
.Spacer(500,500))
111 mainContainer
.add(c
,0,0)
114 self
.goButtonClicked()
116 self
.run(mainContainer
)
118 def open_file_browser(self
,data
=None):
120 d
.connect(gui
.CHANGE
, self
.handle_file_browser_closed
, d
)
124 def handle_file_browser_closed(self
,dlg
):
126 self
.file = dlg
.value
128 def createLabel(self
,text
,font
= None):
131 w
,h
= self
.font
.size(text
)
132 label
= gui
.Label(text
,width
=w
,height
=h
,font
= font
)
135 def levelSelectChanged(self
,data
=None):
136 self
.level
= self
.levelSelect
.value
138 def quitButtonClicked(self
,data
= None):
142 def activeWiimoteSwitchesChanged(self
,data
= None):
143 if self
.activeWiimoteSwitches
[data
].value
:
144 for i
in range(len(self
.activeWiimoteSwitches
)) :
145 if self
.activeWiimoteSwitches
[i
].value
and data
!= i
:
146 self
.activeWiimoteSwitches
[i
].click()
147 for i
in range(len(self
.activeWiimoteSwitches
)) :
148 self
.activeWiimotes
[i
] = self
.activeWiimoteSwitches
[i
].value
150 def hasActiveWiimote(self
):
152 for active
in self
.activeWiimotes
:
161 def goButtonClicked(self
,data
= None):
164 instruments
= [Instrument(self
.scale
, i
+ 1, "".join(["../instruments/instrumentImages/", instrumentImagePathList
[i
], ".jpg"]), octaves
[i
]) for i
in range(9)]
166 joys
= [[id,pygame
.joystick
.Joystick(id).get_name()] for id in range(pygame
.joystick
.get_count())]
168 if joy
[1] in joyNames
:
169 pygame
.joystick
.Joystick(joy
[0]).init()
171 ports
= [pygame
.midi
.get_device_info(id)[1] for id in range(pygame
.midi
.get_count())]
172 portOffset
= ports
.index(portNames
[0])
175 screen
= pygame
.display
.get_surface()
176 clock
= pygame
.time
.Clock()
177 cursorImages
=[['../cursor/cursorImages/black/10.png'],['../cursor/cursorImages/red/10.png'],['../cursor/cursorImages/blue/10.png'],['../cursor/cursorImages/green/10.png']]
178 durations
= [75 for i
in range(len(cursorImages
))]
184 song
= Song(scaleDict
["majorScale"],[3,9,6,4,1,8,5,7,2,10],True)
188 cursors
= [WarpingCursor(None, cursorImages
[i
], durations
, (300 * i
, 300 * i
),'../cursor/cursorImages/black/flash.png') for i
in range(wiimoteCount
)]
189 wiimotes
= [Wiimote(i
, i
+ portOffset
, None, instruments
[0], cursors
[i
]) for i
in range(wiimoteCount
)]
190 dummyInstrumentChoice
= DummyInstrumentChoice(wiimotes
, self
.window
, screen
, clock
, joys
, portOffset
, self
.activeWiimotes
)
191 if not self
.hasActiveWiimote():
192 self
.activeWiimotes
[0] = True
194 familiarize
= StaticFamiliarizer(wiimotes
, self
.window
, screen
, clock
, joys
, portOffset
,self
.activeWiimotes
,level
= self
.level
)
195 elif familiarize
.nextLevel
== 2 :
196 familiarize
= SongFamiliarizer(wiimotes
, self
.window
, screen
, clock
, joys
, portOffset
,song
,self
.activeWiimotes
,casc
,extsc
,easyMode
)
198 familiarize
= SongPlayingScreen(dummyInstrumentChoice
,songDict
["clairdelalune"],easyMode
= True)
200 while familiarize
.nextLevel
!= None :
201 if familiarize
.nextLevel
< 2 :
202 familiarize
= StaticFamiliarizer(wiimotes
, self
.window
, screen
, clock
, joys
, portOffset
,self
.activeWiimotes
,level
= familiarize
.nextLevel
,eventLog
= familiarize
.eventLog
)
203 elif familiarize
.nextLevel
== 2 :
204 familiarize
= SongFamiliarizer(wiimotes
, self
.window
, screen
, clock
, joys
, portOffset
,song
,self
.activeWiimotes
,casc
,extsc
,easyMode
,eventLog
= familiarize
.eventLog
)
206 familiarize
= SongPlayingScreen(dummyInstrumentChoice
,songDict
["clairdelalune"],easyMode
= True,eventLog
= familiarize
.eventLog
)
208 for wiimote
in wiimotes
:
214 filePath
= "".join([self
.fileName
,str(i
),".fmwi"])
215 while os
.path
.exists(filePath
):
217 filePath
= "".join([self
.fileName
,str(i
),".fmwi"])
219 f
= file(filePath
, 'w')
220 self
.log
= FamiliarizerLog(familiarize
.eventLog
,self
.level
,self
.activeWiimotes
)
221 pickler
= pickle
.Pickler(f
)
222 pickler
.dump(self
.log
)
228 if __name__
== "__main__" :
230 modeResolution
= (1024,768)
231 window
= pygame
.display
.set_mode(modeResolution
,pygame
.FULLSCREEN
)
232 familiarizer
= FamiliarizerPGUConfiguration(window
)