@@ -201,7 +201,7 @@ class Text(Slide):
201201 '''
202202 def __init__ (self , text_arg , coords , window , will_slide = True , screen = None ):
203203 image = text_arg .render ()
204- super ().__init__ (image , coords , (0 , 0 ), window , 800 , will_slide , screen )
204+ super ().__init__ (image , coords , (0 , 0 ), window , 400 , will_slide , screen )
205205
206206# TODO: There is a double where a click registers as a double click
207207class Button (ButtonConfig , Slide ):
@@ -249,10 +249,10 @@ def __init__(self, text_arg, coords, function, window, will_slide = True, screen
249249 image1 = pygame .image .load ("Button/button.png" ).convert_alpha ()
250250 image2 = pygame .image .load ("Button/button_hovering.png" ).convert_alpha ()
251251 ButtonConfig .__init__ (self , [image1 , image2 ], coords , function , window )
252- Slide .__init__ (self , image1 , coords , (self .width , self .height ), window , 200 , will_slide , screen )
252+ Slide .__init__ (self , image1 , coords , (self .width , self .height ), window , 400 , will_slide , screen )
253253
254254 if will_slide :
255- self .textRect = self .text .get_rect (center = (window .window .get_size ()[0 ] + 200 , coords [1 ]))
255+ self .textRect = self .text .get_rect (center = (window .window .get_size ()[0 ] + 400 , coords [1 ]))
256256 else :
257257 self .textRect = self .text .get_rect (center = coords )
258258
@@ -289,7 +289,7 @@ class ScrollBar():
289289 self.shift = how much the buttons should shift because of scroll
290290
291291 '''
292- def __init__ (self , buttons , coords , dim , scroll_group , window , default_text , max_height = 200 ):
292+ def __init__ (self , buttons , coords , dim , scroll_group , window , default_text , will_slide = False , max_height = 200 ):
293293 self .coords = coords
294294 self .dim = dim
295295 self .scroll_group = scroll_group
@@ -306,17 +306,15 @@ def __init__(self, buttons, coords, dim, scroll_group, window, default_text, max
306306 triangle_button_1 = pygame .transform .scale (triangle_button_1 , (TRIANGLE_BUTTON_WIDTH , self .TRIANGLE_BUTTON_HEIGHT ))
307307 triangle_button_2 = pygame .image .load ('Button/triangle_button_hovering.png' ).convert_alpha ()
308308 triangle_button_2 = pygame .transform .scale (triangle_button_2 , (TRIANGLE_BUTTON_WIDTH , self .TRIANGLE_BUTTON_HEIGHT ))
309- self .scroll_button = Button ((triangle_button_1 , triangle_button_2 ), (coords [0 ]+ dim [0 ]/ 2 + TRIANGLE_BUTTON_WIDTH / 2 , coords [1 ]), self .toggle , window , True )
309+ self .scroll_button = Button ((triangle_button_1 , triangle_button_2 ), (coords [0 ]+ dim [0 ]/ 2 + TRIANGLE_BUTTON_WIDTH / 2 , coords [1 ]), self .toggle , window , will_slide )
310310 scroll_group .add (self .scroll_button )
311311
312312 self .scroll_back = Background ((coords [0 ]+ dim [0 ]/ 2 + TRIANGLE_BUTTON_WIDTH / 2 , coords [1 ] + self .TRIANGLE_BUTTON_HEIGHT / 2 + max_height / 2 ), (TRIANGLE_BUTTON_WIDTH , max_height ), Colors .BACKGROUND_SCROLL_COLOR , window , False )
313313 #print("Max Height", max_height)
314314 self .scroll_bar_height = (max_height * max_height / (dim [1 ] * (len (buttons ) - 1 )))
315315 self .scroll_bar = Background ((coords [0 ]+ dim [0 ]/ 2 + TRIANGLE_BUTTON_WIDTH / 2 , coords [1 ] + self .TRIANGLE_BUTTON_HEIGHT / 2 + self .scroll_bar_height / 2 ), (TRIANGLE_BUTTON_WIDTH , self .scroll_bar_height ), Colors .SCROLLBAR_COLOR , window , False )
316316
317- self .selected = ScrollButton (DefaultText .text (default_text , FontSizes .BUTTON_SIZE ), None , window )
318- self .selected .setCoords (coords )
319- self .selected .setDim (dim )
317+ self .selected = ScrollButton (DefaultText .text (default_text , FontSizes .BUTTON_SIZE ), None , window , will_slide , None , coords , dim )
320318 for button in buttons :
321319 button .setDim (dim )
322320 scroll_group .add (self .selected )
@@ -343,7 +341,7 @@ def button_checks(self):
343341 self .selected .kill ()
344342 sprite .is_chosen = False
345343 self .selected = sprite .copy ()
346- self .selected .setCoords (self .coords )
344+ # self.selected.setCoords(self.coords)
347345 self .selected .setDim (self .dim )
348346 self .selected .is_chosen = True
349347 time .sleep (0.3 ) # TODO : Fix bug to not click buttons behind it
@@ -456,13 +454,13 @@ class ScrollButton(pygame.sprite.Sprite):
456454 @window = the Window class object
457455 @is_chosen - if the button is selected
458456 '''
459- def __init__ (self , text_arg , function , window ):
457+ def __init__ (self , text_arg , function , window , will_slide = False , screen = None , coords = ( 0 , 0 ), dim = ( 0 , 0 ) ):
460458 super ().__init__ ()
461459 self .text = text_arg .render ()
462460 self .copy_text = text_arg # Used for duplicating purposes
463- self .dim = ()
464- self .coords = ()
465- self .image = pygame .Surface (( 0 , 0 ) )
461+ self .dim = dim
462+ self .coords = coords
463+ self .image = pygame .Surface (dim )
466464 self .rect = self .image .get_rect ()
467465 self .function = function
468466 self .screen = window .screen
@@ -473,6 +471,36 @@ def __init__(self, text_arg, function, window):
473471 self .can_press = True
474472 self .can_press_timer = 0
475473 self .timer_is_handled = True
474+
475+ if will_slide :
476+ self .rect = self .image .get_rect (center = (window .window .get_size ()[0 ] + 400 , self .coords [1 ]))
477+ self .textRect = self .text .get_rect (center = (window .window .get_size ()[0 ] + 400 , self .coords [1 ]))
478+ else :
479+ self .rect = self .image .get_rect (center = self .coords )
480+ self .textRect = self .text .get_rect (center = coords )
481+ # Will automatically set screen to whatever screen it is currently on
482+ if screen == None :
483+ self .screen = window .screen
484+ else :
485+ self .screen = screen
486+
487+ self .accel = 0
488+ self .will_slide = will_slide
489+
490+ def destroy (self ):
491+ if (self .rect .x <= - 200 ):
492+ self .kill ()
493+
494+ def slide (self ):
495+ print (self .coords [0 ], self .coords [1 ])
496+ if ((self .screen != self .window .screen ) or self .rect .x + self .dim [0 ]/ 2 > self .coords [0 ]):
497+ self .accel += - 1
498+ self .rect .x += self .accel
499+ self .textRect .x += self .accel
500+ else :
501+ self .accel = 0
502+ self .rect = self .image .get_rect (center = self .coords )
503+ self .textRect = self .text .get_rect (center = self .coords )
476504
477505 def copy (self ):
478506 copy = ScrollButton (self .copy_text , self .function , self .window )
@@ -499,13 +527,6 @@ def player_input(self):
499527 else :
500528 self .image .fill ("#415A77" )
501529
502- # If its in options, advanced tools, etc where a window would pop up, the button shouldn't be pressed
503- def check_overlap (self ):
504- if (self .window .screen == Screen .NONE and self .screen != Screen .NONE ):
505- self .set_unpressable ()
506- else :
507- self .set_pressable ()
508-
509530 def set_pressable (self ):
510531 if (not self .can_press and self .timer_is_handled ):
511532 self .can_press_timer = 0.0001
@@ -520,10 +541,9 @@ def change_func(self, func):
520541 def update (self ):
521542 #self.window.window.blit(self.text, (self.rect.x + self.width/2, self.rect.y + self.height/2))
522543 self .image = pygame .Surface (self .dim )
523- self .rect = self .image .get_rect (center = self .coords )
524- self .textRect = self .text .get_rect (center = self .coords )
544+ # self.rect = self.image.get_rect(center = self.coords)
545+ # self.textRect = self.text.get_rect(center = self.coords)
525546 self .window .window .blit (self .text , self .textRect )
526- self .check_overlap ()
527547 self .player_input ()
528548
529549 if (self .can_press_timer != 0 ):
@@ -532,6 +552,10 @@ def update(self):
532552 self .can_press = True
533553 self .timer_is_handled = True
534554 self .can_press_timer = 0
555+
556+ if self .will_slide :
557+ self .slide ()
558+ self .destroy ()
535559
536560class Background (Slide ):
537561 '''Creates a background (also used as an array element)
0 commit comments