@@ -195,13 +195,9 @@ def __init__(self, max_amount, origin):
195
195
196
196
self .colour_manager = ColourPicker ()
197
197
198
- # pygame_gui.Button not designed to be moved once defined, inherited to SlotButton to allow for this.
199
- self .add_human_button = SlotButton (paths .uiMenuPath + "add-human-slot.png" ,
200
- paths .uiMenuPath + "add-human-slot-hover.png" ,
201
- self .origin [0 ], self .origin [1 ])
202
- self .add_computer_button = SlotButton (paths .uiMenuPath + "add-computer-slot.png" ,
203
- paths .uiMenuPath + "add-computer-slot-hover.png" ,
204
- self .origin [0 ] + 250 , self .origin [1 ])
198
+ # pygame_gui.Button not designed to be moved once defined, inherited to NewPlayerSlot to allow for this.
199
+ self .add_human_button = NewPlayerSlot ([self .origin [0 ], self .origin [1 ]], "human" )
200
+ self .add_computer_button = NewPlayerSlot ([self .origin [0 ] + 260 , self .origin [1 ]], "computer" )
205
201
206
202
self .slot_size = [200 , 30 ]
207
203
self .slot_padding = 40
@@ -248,8 +244,7 @@ def refresh_slots(self):
248
244
old_slots = self .players .copy ()
249
245
self .players = []
250
246
for player_slot in old_slots : # allows slots to auto move up if an above slot is deleted.
251
- self .players .append (PlayerSlot (self , self .get_slot_bottom (),
252
- player_slot .colour , player_slot .name_entry .text .text ))
247
+ self .players .append (PlayerSlot (self , self .get_slot_bottom (), player_slot .colour , player_slot .control , player_slot .name_entry .text .text ))
253
248
254
249
def handle_click (self ):
255
250
added = False
@@ -283,7 +278,7 @@ def draw(self, display):
283
278
self .add_human_button .change_position (new_position )
284
279
self .add_human_button .draw (display )
285
280
286
- computer_slot_position = [new_position [0 ] + 250 , new_position [1 ]]
281
+ computer_slot_position = [new_position [0 ] + 260 , new_position [1 ]]
287
282
self .add_computer_button .change_position (computer_slot_position )
288
283
self .add_computer_button .draw (display )
289
284
@@ -309,6 +304,9 @@ def __init__(self, player_manager, origin, colour, control, name=""):
309
304
self .delete_self = pygame_gui .Button (paths .uiPath + "cross.png" , paths .uiPath + "cross-hover.png" ,
310
305
self .origin [0 ]+ 430 , self .origin [1 ]+ 8 )
311
306
307
+ self .computer_player_indicator = pygame_gui .Image (paths .uiMenuPath + "computer-icon.png" , self .origin [0 ] + 300 , self .origin [1 ] + 10 )
308
+ self .human_player_indicator = pygame_gui .Image (paths .uiMenuPath + "human-icon.png" , self .origin [0 ] + 300 , self .origin [1 ] + 10 )
309
+
312
310
def get_dict (self ):
313
311
return {
314
312
"name" : self .name_entry .get_text (),
@@ -341,7 +339,9 @@ def draw(self, display):
341
339
pygame .draw .ellipse (display , constants .COLOURS [self .colour ], [self .origin [0 ]+ 360 , self .origin [1 ]+ 10 , 28 , 28 ])
342
340
343
341
if self .control == "computer" :
344
- pygame .draw .ellipse (display , constants .COLOURS ["white" ], [self .origin [0 ] + 300 , self .origin [1 ] + 10 , 28 , 28 ])
342
+ self .computer_player_indicator .draw (display )
343
+ else :
344
+ self .human_player_indicator .draw (display )
345
345
346
346
self .delete_self .draw (display )
347
347
@@ -422,9 +422,40 @@ def draw(self, display):
422
422
self .forward_button .draw (display )
423
423
424
424
425
- class SlotButton (pygame_gui .Button ):
426
- """ Specific to PlayerManager, button must change position depending on number of slots """
425
+ class NewPlayerSlot :
426
+ """ A individual game slot, seen on the screen. managed by FileSelector """
427
+ def __init__ (self , position , player_control ):
428
+ self .position = position
429
+ self .player_control = player_control
430
+
431
+ # GUI Setup
432
+ self .back_panel = pygame_gui .Panel ([self .position [0 ], self .position [1 ], 240 , 50 ],
433
+ 100 ,
434
+ constants .COLOURS ["panel" ])
435
+ self .back_panel_hover = pygame_gui .Panel ([self .position [0 ], self .position [1 ], 240 , 50 ],
436
+ 50 ,
437
+ constants .COLOURS ["panel" ])
438
+
439
+ self .text = pygame_gui .Text (
440
+ "Add " + player_control + " player" ,
441
+ constants .FONTS ["sizes" ]["medium" ], constants .FONTS ["colour" ], constants .FONTS ["main" ],
442
+ self .position [0 ] + 50 , self .position [1 ] + 15 )
443
+
444
+ def check_clicked (self ):
445
+ return self .mouse_over ()
446
+
447
+ def mouse_over (self ):
448
+ return self .back_panel .rect .collidepoint (pygame .mouse .get_pos ())
449
+
427
450
def change_position (self , position ):
428
- self .rect .topleft = position
429
- self .rest_image .rect .topleft = position
430
- self .hover_image .rect .topleft = position
451
+ self .back_panel .rect .topleft = position
452
+ self .back_panel_hover .rect .topleft = position
453
+ self .text .change_position (position [0 ] + 50 , position [1 ] + 15 )
454
+
455
+ def draw (self , display ):
456
+ if self .mouse_over ():
457
+ self .back_panel_hover .draw (display )
458
+ else :
459
+ self .back_panel .draw (display )
460
+
461
+ self .text .draw (display )
0 commit comments