-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenu.py
More file actions
641 lines (420 loc) · 27.8 KB
/
Menu.py
File metadata and controls
641 lines (420 loc) · 27.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
#Menus
#Here, inheritance enables menus to have different functionality whilst maintaining the same interface
#These are to use as part of the game class using pygame
from Widget import *
import time#Used for blinking cursor
class Menu():
def __init__(self, width, height, font, textSize, textColour):#Here, protected variables are used rather than private variables, so that they can be accessed by the subclasses
#Link to the Game the menu will be used with
#self._Game = Game#Used to send the Game commands to draw to the screen with pyGame
self._Display = "MenuDisplay"#Used to query a dictionary from the game when drawing to the screen
#Select the middle of the screen
self._MiddleWidth = width // 2#self._Game.get_setting("Width") // 2
self._MiddleHeight = height // 2#self._Game.get_setting("Height") // 2
#Load the cursor text and dimensions
self._CursorText = '*'#This will be displayed next to the most closely matching menu option if the mouse is being moved
self._CursorSize = 15
self._CursorOffset = -100#Makes the cursor appear to the left of the menu options
self._TextSize = textSize#Size of the menu options
self._TextOffset = 20#Space between menu options
self._Font = font#Name of the font used to draw text
self._Colour = textColour#Colour of the text to be drawn
#Define a map to keep track of the correct cursor position
self._SelectedState = 0
self._MenuItems = ["State"]#Create the menu items that will be displayed as part of the menu
self._MenuPositions = [[self._MiddleWidth, self._MiddleHeight + 10 + self._TextOffset]]
#[ [x,y] ]
self._Widgets = {}#A list of widget objects that handle all rect positions within the class
def display_menu(self, keyboardState, mousePosition, mouseState, returnKeys):
"""Blits the menu to the correct display before the connected Game displays it"""
returnText = []
returnWidgets = []
returnSettings = []#Used only in menus that include widgets
returnValues = []
#Menu drawing
for x in range(len(self._MenuItems)):
#self._Game.draw_text(self._MenuItems[x],self._TextSize,self._MenuPositions[x][0],self._MenuPositions[x][1],"White")
returnText.append([self._MenuItems[x],str(self._MenuPositions[x][0]),str(self._MenuPositions[x][1]),self._Colour,self._Font,self._Display])
#Some of the inputs have been casted to strings in order to be compatible with other programming languages, where arrays must only consist of a single type
for key in self._Widgets:
returnWidget = []
for rect in self._Widgets[key].draw():
returnWidget.append(rect)
returnWidgets.append(returnWidget)
#returnWidgets.append(rect for rect in self._Widgets[key].draw())
#Draw the cursor in the correct position
#print(self._MenuPositions[self._SelectedState])
#self._Game.draw_text(self._CursorText, self._CursorSize, self._MenuPositions[self._SelectedState][0] + self._CursorOffset, self._MenuPositions[self._SelectedState][1],"White")
#Check if the cursor should be drawn
if (time.time() % 1 > 0.5) and len(self._MenuPositions)>0:
returnText.append([self._CursorText,str(self._MenuPositions[self._SelectedState][0] + self._CursorOffset),str(self._MenuPositions[self._SelectedState][1]),self._Colour,self._Font,self._Display])
return returnText, returnWidgets, returnSettings, returnValues, "Menu", False#For a default menu, the game should never be started and the menu should never be changed
class MainMenu(Menu):
def __init__(self, width, height, font, textSize, textColour):
#Initialise the shared attributes and methods of the menu class
Menu.__init__(self, width, height, font, textSize, textColour)
#self._SelectedState = 0
#Define a map to keep track of the correct cursor position
self._MenuItems = ["Start","Options","Credits"]#Create the menu items that will be displayed as part of the menu
self._MenuPositions = [[self._MiddleWidth, self._MiddleHeight + 10 + self._TextOffset],
[self._MiddleWidth, self._MiddleHeight + 10 + 2*self._TextOffset],
[self._MiddleWidth, self._MiddleHeight + 10 + 3*self._TextOffset]]
def display_menu(self, keyboardState, mousePosition, mouseState, returnKeys):
"""Blits the menu to the correct display before the connected Game displays it"""
#Menu logic
currentMenu, gameStart = self.check_input(keyboardState, mousePosition, mouseState)#This uses the key states from the attached Game rather than implementing pyGame
#Menu drawing
returnText, returnWidgets, returnSettings, returnValues = Menu.display_menu(self, keyboardState, mousePosition, mouseState, returnKeys)[0:4]#Includes position 0, 1, 2 and 3
#This also returns a third and fourth value to be consistent with the return values of the sub menus
#However, these are ignored in favour of the ones calculated locally
returnText.append(["Main Menu",str(self._MiddleWidth), str(self._MiddleHeight - 20), self._Colour, self._Font, self._Display])
#self._Game.draw_text("Main Menu", 20, self._MiddleWidth, self._MiddleHeight - 20,"White", self._Display)
#Return whether the game has started
return returnText, returnWidgets, [], [], currentMenu, gameStart
def check_input(self, keyboardState, mousePosition, mouseState):
"""keyboardState: ["MoveLeft","MoveRight","MoveUp","MoveDown","Enter","Backspace"]"""
currentMenu = "MainMenu"
#MoveUp
if keyboardState[2]:
self._SelectedState = (self._SelectedState-1)%len(self._MenuItems)
print("NEW STATE: ", self._SelectedState)
#MoveDown
if keyboardState[3]:
self._SelectedState = (self._SelectedState+1)%len(self._MenuItems)
print("NEW STATE: ", self._SelectedState)
#Enter
if keyboardState[4]:#If the key mapped to enter is pressed
#Start
if self._SelectedState == 0:
print("START PLAYING THE GAME!!!")
#"MainMenu", False
return "Ready", False#True #Example to be removed after options have been set up!!!
else:#1 = Options, 2 = Credits
currentMenu = self._MenuItems[self._SelectedState]
#self._Game.set_current_menu(self._MenuItems[self._SelectedState])
#Backspace/Escape
#N/A
return currentMenu, False#Only return true when the game should start playing
class OptionsMenu(Menu):
def __init__(self, width, height, font, textSize, textColour):
#Initialise the shared attributes and methods of the menu class
Menu.__init__(self, width, height, font, textSize, textColour)
#Define a map to keep track of the correct cursor position
self._MenuItems = ["Volume","Controls"]#Create the menu items that will be displayed as part of the menu
self._MenuPositions = [[self._MiddleWidth, self._MiddleHeight + 10 + self._TextOffset],
[self._MiddleWidth, self._MiddleHeight + 10 + 2*self._TextOffset]]
self._Widgets = {
"Go back" : Button(self._MiddleWidth- (200 // 2), self._MiddleHeight + 20 + 3*self._TextOffset, 200, 25, self._Display, "Go back", font = "8-Bit", radius = 7)
}
def display_menu(self, keyboardState, mousePosition, mouseState, returnKeys):
"""Blits the menu to the correct display before the connected Game displays it"""
#Menu logic
currentMenu, gameStart = self.check_input(keyboardState, mousePosition, mouseState)
#Menu drawing
returnText, returnWidgets, returnSettings, returnValues = Menu.display_menu(self, keyboardState, mousePosition, mouseState, returnKeys)[0:4]
returnText.append(["Options",str(self._MiddleWidth), str(self._MiddleHeight - 20), self._Colour, self._Font, self._Display])
return returnText, returnWidgets, returnSettings, returnValues, currentMenu, gameStart
def check_input(self, keyboardState, mousePosition, mouseState):
"""keyboardState: ["MoveLeft","MoveRight","MoveUp","MoveDown","Enter","Backspace"]"""
currentMenu = "Options"
#MoveUp
if keyboardState[2]:
self._SelectedState = (self._SelectedState-1)%len(self._MenuItems)
#MoveDown
if keyboardState[3]:
self._SelectedState = (self._SelectedState+1)%len(self._MenuItems)
#Enter
if keyboardState[4]:#If the key mapped to enter is pressed
currentMenu = self._MenuItems[self._SelectedState]#Handles all possible options
#Backspace
elif keyboardState[5] or keyboardState[6]:#If the key mapped to enter or backspace are pressed
currentMenu = "MainMenu"
#Go back button
else:
#If the go back button is clicked, return to the controls menu
for key in self._Widgets:
returnValue = self._Widgets[key].listen(keyboardState,mousePosition,mouseState)
if returnValue == True:#If the button is pressed
if key == "Go back":
currentMenu = "MainMenu"
return currentMenu, False
class VolumeMenu(Menu):
def __init__(self, width, height, font, textSize, textColour):
#Initialise the shared attributes and methods of the menu class
Menu.__init__(self, width, height, font, textSize, textColour)
#Define a map to keep track of the correct cursor position
#self._MenuItems = []#Create the menu items that will be displayed as part of the menu
#self._MenuPositions = []
#Define widgets to interact with the menu
self._Widgets = {
"Settings Volume" : Slider(self._MiddleWidth- (200 // 2), self._MiddleHeight - 10 + self._TextOffset, 200, 20, self._Display),
#Slider(xPos,yPos,width,height,display,min,max,step,value,colour...)
"Go back" : Button(self._MiddleWidth- (200 // 2), self._MiddleHeight + 20 + 2*self._TextOffset, 200, 25, self._Display, "Go back", font = "8-Bit", radius = 7)
}
def display_menu(self, keyboardState, mousePosition, mouseState, returnKeys):
"""Blits the menu to the correct display before the connected Game displays it"""
#Menu logic
currentMenu, gameStart = self.check_input(keyboardState, mousePosition, mouseState)
returnSettings = []
returnValues = []
#Widget logic
#for key in self._Widgets:
# returnSettings.append(key)
# returnValues.append(self._Widgets[key].listen(keyboardState,mousePosition,mouseState))
#Menu drawing
returnText, returnWidgets, returnSettings, returnValues = Menu.display_menu(self, keyboardState, mousePosition, mouseState, returnKeys)[0:4]
returnText = []
returnText.append(["Set Volume", str(self._MiddleWidth), str(self._MiddleHeight - 20), self._Colour, self._Font, self._Display])
return returnText, returnWidgets, returnSettings, returnValues, currentMenu, gameStart
def check_input(self, keyboardState, mousePosition, mouseState):
"""keyboardState: ["MoveLeft","MoveRight","MoveUp","MoveDown","Enter","Backspace"]"""
currentMenu = "Volume"
#MoveUp
if keyboardState[2]:
self._SelectedState = (self._SelectedState-1)%len(self._MenuItems)
#MoveDown
if keyboardState[3]:
self._SelectedState = (self._SelectedState+1)%len(self._MenuItems)
#Backspace
if keyboardState[5]:#If the key mapped to enter or backspace are pressed
currentMenu = "Options"
#Escape
elif keyboardState[6]:
currentMenu = "MainMenu"
#Go back button
else:
#If the go back button is clicked, return to the controls menu
for key in self._Widgets:
returnValue = self._Widgets[key].listen(keyboardState,mousePosition,mouseState)
if key == "Go back" and returnValue == True:#If the button is pressed
currentMenu = "Options"
#elif key == "Settings Volume":
#Handled in the menu super class
return currentMenu, False
class ControlsMenu(Menu):
def __init__(self, width, height, font, textSize, textColour, keymap, keyNames):
"""Precondition: The menu items size must match the menu positions size
Precondition: All items in the keymap section must have their position added separately inside this function"""
#Initialise the shared attributes and methods of the menu class
Menu.__init__(self, width, height, font, textSize, textColour)
self._CursorOffset = -105
#Define a map to keep track of the correct cursor position
self._MenuItems = []
self.__KeyNames = keyNames
for key in keymap:
self._MenuItems.append(key)#Since the text needs to be alligned to the left side of the screem, its more simple to calculate the correct positions manually
self._MenuPositions = [[(self._MiddleWidth // 2) - 40 , self._MiddleHeight + 10 + self._TextOffset],
[(self._MiddleWidth // 2) - 30, self._MiddleHeight + 10 + 2*self._TextOffset],
[(self._MiddleWidth // 2), self._MiddleHeight + 10 + 3*self._TextOffset],
[(self._MiddleWidth // 2) - 25, self._MiddleHeight + 10 + 4*self._TextOffset],
[(self._MiddleWidth // 2), self._MiddleHeight + 10 + 5*self._TextOffset],
[(self._MiddleWidth // 2) - 5, self._MiddleHeight + 10 + 6*self._TextOffset],
[(self._MiddleWidth // 2), self._MiddleHeight + 10 + 7*self._TextOffset]]
#for x in range(len(keyNames)):
# self._MenuItems.append(keyNames[x])
# self._MenuPositions.append([((self._MiddleWidth * 3) // 2), self._MiddleHeight + 10 + (x+1)*self._TextOffset])#Since the key names will be alligned centrally, the positions can be calculated automatically
self._Widgets = {
"Go back" : Button(self._MiddleWidth- (200 // 2), self._MiddleHeight + 20 + 8*self._TextOffset, 200, 25, self._Display, "Go back", font = "8-Bit", radius = 7)
}
#self._MenuItems.append("Go Back")
#self._MenuPositions.append([self._MiddleWidth, self._MiddleHeight + 10 + (len(keyNames)+2)*self._TextOffset])
def display_menu(self, keyboardState, mousePosition, mouseState, returnKeys):
"""Blits the menu to the correct display before the connected Game displays it"""
#Menu logic
currentMenu, gameStart = self.check_input(keyboardState, mousePosition, mouseState)
#Menu drawing
returnText, returnWidgets, returnSettings, returnValues = Menu.display_menu(self, keyboardState, mousePosition, mouseState, returnKeys)[0:4]
returnText.append(["Controls", str(self._MiddleWidth), str(self._MiddleHeight - 20), self._Colour, self._Font, self._Display])
length = len(self.__KeyNames)
for x in range(length):
returnText.append([self.__KeyNames[x], str((self._MiddleWidth * 3) // 2), str(self._MiddleHeight + 10 + (x+1)*self._TextOffset), self._Colour, self._Font, self._Display])
#Change cursor position to match the left allignment of the text
if time.time() % 1 > 0.5:#Check if the cursor needs to be drawn
#if self._SelectedState in range(0,(len(self._MenuItems)-1)//2):
#self._CursorOffset = -105
if self._SelectedState != len(self._MenuItems)-1:
returnText[len(returnText)-length-2][1] = (self._MiddleWidth // 2) + self._CursorOffset
#elif self._SelectedState != len(self._MenuItems)-1:
#self._CursorOffset = -100
#returnText[len(returnText)-2][1] = ((self._MiddleWidth*3) // 2) + self._CursorOffset
#else:#This case is covered by the default menu class
return returnText, returnWidgets, returnSettings, returnValues, currentMenu, gameStart
def check_input(self, keyboardState, mousePosition, mouseState):
"""keyboardState: ["MoveLeft","MoveRight","MoveUp","MoveDown","Enter","Backspace","Escape"]"""
currentMenu = "Controls"
#MoveUp
if keyboardState[2]:
self._SelectedState = (self._SelectedState-1)%len(self._MenuItems)
#MoveDown
if keyboardState[3]:
self._SelectedState = (self._SelectedState+1)%len(self._MenuItems)
#Enter
if keyboardState[4]:#If the key mapped to enter is pressed
currentMenu = self._MenuItems[self._SelectedState]#Handles all possible options
#Backspace
elif keyboardState[5]:
currentMenu = "Options"
#Escape
elif keyboardState[6]:
currentMenu = "MainMenu"
#Go back button
else:
#If the go back button is clicked, return to the controls menu
for key in self._Widgets:
returnValue = self._Widgets[key].listen(keyboardState,mousePosition,mouseState)
if returnValue == True:#If the button is pressed
if key == "Go back":
currentMenu = "Options"
return currentMenu, False
class KeyMenu(Menu):
def __init__(self, width, height, font, textSize, textColour, action, key):
"""Precondition: The menu items size must match the menu positions size
Precondition: All items in the keymap section must have their position added separately inside this function"""
#Initialise the shared attributes and methods of the menu class
Menu.__init__(self, width, height, font, textSize, textColour)
self._CursorOffset = -105
self.__Action = action#Name of the action for which a key is mapped to
self.__Key = key#Name of the key that is currently mapped to the action
self.__ChangeKey = self.__Key
#Define a map to keep track of the correct cursor position
#self._MenuItems = []
#self._MenuItems.append(key)#This is to be done elsewhere, since the menu name will be this value
#self._MenuPositions = []
#Define widgets to interact with the menu
String = "Keymap " + self.__Action
self._Widgets = {
String : Button(self._MiddleWidth - (200 // 2), self._MiddleHeight + 60 + 4*self._TextOffset, 200, 25, self._Display, "Confirm", font = "8-Bit", radius = 7),
#Slider(xPos,yPos,width,height,display,min,max,step,value,colour...)
"Return" : Button(self._MiddleWidth- (200 // 2), self._MiddleHeight +70 + 4*self._TextOffset + 25, 200, 25, self._Display, "Return", font = "8-Bit", radius = 7)
}
def display_menu(self, keyboardState, mousePosition, mouseState, returnKeys):
"""Blits the menu to the correct display before the connected Game displays it"""
#Menu logic
currentMenu, gameStart, changeKeymap = self.check_input(keyboardState, mousePosition, mouseState, returnKeys)
#Menu drawing
returnWidgets, returnSettings, returnValues = Menu.display_menu(self, keyboardState, mousePosition, mouseState, returnKeys)[1:4]
returnText = []
returnText.append([self.__Action,str(self._MiddleWidth), str(self._MiddleHeight - 20), self._Colour, self._Font, self._Display])
returnText.append(["Current",str(self._MiddleWidth // 2), str(self._MiddleHeight + 20), self._Colour, self._Font, self._Display])
returnText.append(["mapping",str(self._MiddleWidth //2), str(self._MiddleHeight + 20 + self._TextOffset), self._Colour, self._Font, self._Display])
returnText.append([self.__Key,str((self._MiddleWidth * 3) // 2), str(self._MiddleHeight + 30), self._Colour, self._Font, self._Display])
returnText.append(["New",str(self._MiddleWidth // 2), str(self._MiddleHeight + 20 + 3*self._TextOffset), self._Colour, self._Font, self._Display])
returnText.append(["mapping",str(self._MiddleWidth // 2), str(self._MiddleHeight + 20 + 4*self._TextOffset), self._Colour, self._Font, self._Display])
returnText.append([self.__ChangeKey,str((self._MiddleWidth * 3) // 2), str(self._MiddleHeight + 30 + 3*self._TextOffset), self._Colour, self._Font, self._Display])
#Button pressed logic
if changeKeymap == True:
returnSettings.append("Keymap " + self.__Action)
returnValues.append(self.__Key)
#Remove the cursor, since the only options are buttons
#returnText.pop(len(returnText)-2)#Removes the item in the specified position in the list
#Change cursor position to match the left allignment of the text
## if time.time() % 1 > 0.5:#Check if the cursor needs to be drawn
## if self._SelectedState in range(0,(len(self._MenuItems)-1)//2):
## #self._CursorOffset = -105
## returnText[len(returnText)-2][1] = (self._MiddleWidth // 2) + self._CursorOffset
## elif self._SelectedState != len(self._MenuItems)-1:
## #self._CursorOffset = -100
## returnText[len(returnText)-2][1] = ((self._MiddleWidth*3) // 2) + self._CursorOffset
## #else:#This case is covered by the default menu class
return returnText, returnWidgets, returnSettings, returnValues, currentMenu, gameStart
def check_input(self, keyboardState, mousePosition, mouseState, returnKeys):
"""keyboardState: ["MoveLeft","MoveRight","MoveUp","MoveDown","Enter","Backspace"]"""
currentMenu = self.__Action
changeKeymap = False
#Check if a different key has been entered
length = len(returnKeys)
if length > 0:
self.__ChangeKey = returnKeys[length-1]
#If the go back button is clicked, return to the controls menu
for key in self._Widgets:
returnValue = self._Widgets[key].listen(keyboardState,mousePosition,mouseState)
if returnValue == True:#If the button is pressed
if key == "Keymap " + self.__Action:
self.__Key = self.__ChangeKey
changeKeymap = True
elif key == "Return":
currentMenu = "Controls"
#if self.__Key == "Enter":
#Enter/Backspace
#if keyboardState[4] or keyboardState[5]:#If the key mapped to enter or backspace are pressed
# currentMenu = "Controls"
return currentMenu, False, changeKeymap
class CreditsMenu(Menu):
def __init__(self, width, height, font, textSize, textColour):
#Initialise the shared attributes and methods of the menu class
Menu.__init__(self, width, height, font, textSize, textColour)
#Define a map to keep track of the correct cursor position
#self._MenuItems = ["Go Back"]#Create the menu items that will be displayed as part of the menu
#self._MenuPositions = [[self._MiddleWidth, self._MiddleHeight + 10 + 5*self._TextOffset]]
self._Widgets = {
"Go back" : Button(self._MiddleWidth- (200 // 2), self._MiddleHeight +20 + 5*self._TextOffset, 200, 25, self._Display, "Go back", font = "8-Bit", radius = 7)
}
def display_menu(self, keyboardState, mousePosition, mouseState, returnKeys):
"""Blits the menu to the correct display before the connected Game displays it"""
#Menu logic
currentMenu, gameStart = self.check_input(keyboardState, mousePosition, mouseState)
#Menu drawing
returnText, returnWidgets, returnSettings, returnValues= Menu.display_menu(self, keyboardState, mousePosition, mouseState, returnKeys)[0:4]
returnText = []
returnText.append(["Credits",str(self._MiddleWidth), str(self._MiddleHeight - 20), self._Colour, self._Font, self._Display])
returnText.append(["Made by me",str(self._MiddleWidth), str(self._MiddleHeight), self._Colour, self._Font, self._Display])
return returnText, returnWidgets, [], [], currentMenu, gameStart
def check_input(self, keyboardState, mousePosition, mouseState):
"""keyboardState: ["MoveLeft","MoveRight","MoveUp","MoveDown","Enter","Backspace","Escape"]"""
#This could be used to show dev pictures etc.
currentMenu = "Credits"
#MoveUp
if keyboardState[2]:
print("SCROLL THE SCREEN UP!!!")
#MoveDown
if keyboardState[3]:
print("SCROLL THE SCREEN DOWN!!!")
#Enter
#N/A
#Backspace/Escape
if keyboardState[5] or keyboardState[6]:#If the key mapped to enter or backspace are pressed
currentMenu = "MainMenu"
#Go back button
else:
#If the go back button is clicked, return to the controls menu
for key in self._Widgets:
returnValue = self._Widgets[key].listen(keyboardState,mousePosition,mouseState)
if returnValue == True:#If the button is pressed
if key == "Go back":
currentMenu = "MainMenu"
return currentMenu, False
class ReadyMenu(Menu):
def __init__(self, width, height, font, textSize, textColour):
#Initialise the shared attributes and methods of the menu class
Menu.__init__(self, width, height, font, textSize, textColour)
self._MenuItems = []#Create the menu items that will be displayed as part of the menu
self._MenuPositions = []
self._Widgets = {
"Ready" : Button(self._MiddleWidth- (200 // 2), self._MiddleHeight + 30 - 1*self._TextOffset, 200, 25, self._Display, "Ready", font = "8-Bit", radius = 7),
"Go back" : Button(self._MiddleWidth- (200 // 2), self._MiddleHeight + 10 + 2*self._TextOffset, 200, 25, self._Display, "Go back", font = "8-Bit", radius = 7)
}
def display_menu(self, keyboardState, mousePosition, mouseState, returnKeys):
"""Blits the menu to the correct display before the connected Game displays it"""
#Menu logic
currentMenu, gameStart = self.check_input(keyboardState, mousePosition, mouseState)
#Menu drawing
returnText, returnWidgets, returnSettings, returnValues = Menu.display_menu(self, keyboardState, mousePosition, mouseState, returnKeys)[0:4]
returnText.append(["Ready Up",str(self._MiddleWidth), str(self._MiddleHeight - 20), self._Colour, self._Font, self._Display])
return returnText, returnWidgets, returnSettings, returnValues, currentMenu, gameStart
def check_input(self, keyboardState, mousePosition, mouseState):
"""keyboardState: ["MoveLeft","MoveRight","MoveUp","MoveDown","Enter","Backspace"]"""
currentMenu = "Ready"
#Backspace
if keyboardState[5] or keyboardState[6]:#If the key mapped to enter or backspace are pressed
currentMenu = "MainMenu"
#Go back button
else:
#If the go back button is clicked, return to the controls menu
for key in self._Widgets:
returnValue = self._Widgets[key].listen(keyboardState,mousePosition,mouseState)
if returnValue == True:#If the button is pressed
if key == "Ready":
return "MainMenu", True
if key == "Go back":
currentMenu = "MainMenu"
return currentMenu, False