def __init__(self, screen, settings:Settings, sub_title_text:str = ""): super().__init__(screen, settings) #Fields initialization self.__exit_button:Button = Button(self.get_screen(), self.get_settings(), "Exit", button_color = settings.button_color_red) self._guess_button:Button = Button(self.get_screen(), self.get_settings(), "Guess") self._clear_button:Button = Button(self.get_screen(), self.get_settings(), "Clear") self._buttons_to_draw:[Button] = [self.__exit_button, self._guess_button, self._clear_button] self._guess_button_pressed:boolean = False self.__colored_pixels = set(()) self.__sub_title_label:Label = Label(sub_title_text) self._draw_sub_title_label:bool = False #Configure button placements screen_rect = self.get_screen().get_rect() #Sub title self.__sub_title_label.get_rect().top = screen_rect.top + 20 self.__sub_title_label.get_rect().centerx = screen_rect.centerx #Exit button self.get_exit_button().get_rect().left = screen_rect.left + 20 self.get_exit_button().get_rect().centery = screen_rect.bottom - self.get_exit_button().get_height() self.get_exit_button().prep_msg(self.get_exit_button().get_text()) #Guess button self.get_guess_button().get_rect().centery = screen_rect.bottom - self.get_guess_button().get_height() self.get_guess_button().prep_msg(self.get_guess_button().get_text()) #Clear button self.get_clear_button().get_rect().right =screen_rect.right - 20 self.get_clear_button().get_rect().centery = screen_rect.bottom - self.get_clear_button().get_height() self.get_clear_button().prep_msg(self.get_clear_button().get_text())
def __init__(self, screen, settings: Settings): """ screen: the pygame screen settings: the Settings object """ super().__init__(screen, settings, background_img_path="gamemode.png") #Initialize fields padding: int = 20 self.__console: ImagePanel = ImagePanel( constants.path_img_gamemode_welc_console) self.__funhouse_button: Button = Button( screen, settings, "Fun House", width=(settings.screen_width // 2) - padding * 2) self.__random_chaos_button: Button = Button( screen, settings, "Random Chaos", width=(settings.screen_width // 2) - padding * 2) self.__back_button: Button = Button( screen, settings, "Back", button_color=settings.button_color_red) self.__sub_title_font = settings.sub_title_font self.__sub_title_label = Label("Select Game Mode", font=self.__sub_title_font, bold=True, width=settings.screen_width) #Configure component placements screen_rect: Rect = self.get_screen().get_rect() #Funhouse button self.get_funhouse_button().get_rect( ).centerx = screen_rect.centerx // 2 self.get_funhouse_button().get_rect( ).centery = 4 * screen_rect.centery // 5 self.get_funhouse_button().prep_msg( self.get_funhouse_button().get_text()) #Random chaos button self.get_random_chaos_button().get_rect( ).centerx = screen_rect.centerx // 2 self.get_random_chaos_button().prep_msg( self.get_random_chaos_button().get_text()) #Back Button self.get_back_button().get_rect().centerx = screen_rect.centerx // 2 self.get_back_button().get_rect( ).centery = screen_rect.centery + screen_rect.centery // 2 self.get_back_button().prep_msg(self.get_back_button().get_text()) #Sub title text self.get_sub_title_label().get_rect().top = screen_rect.top + 20 # txt_width, _ = self.get_sub_title_label().get_font().size(self.get_sub_title_label().get_text()) # self.get_sub_title_label().get_rect().left = screen_rect.centerx - txt_width//2 #Fake center of text self.get_sub_title_label().get_rect().centerx = screen_rect.centerx #ImagePanel image console_rect = self.get_console().get_rect() console_rect.centerx = screen_rect.centerx + screen_rect.centerx // 2 console_rect.centery = screen_rect.centery
def __init__(self, screen, settings: Settings): super().__init__(screen, settings, background_img_path="monitor.png") #Initialize components self.__sub_title_label: Button = Button(screen, settings, "", button_color=None) self.__ori_image: ImagePanel = ImagePanel() self.__is_label: Button = Button(screen, settings, "is", button_color=None) self.__guess_label: Button = Button(screen, settings, "", button_color=None, font=settings.large_font) self.__finish_button: Button = Button(screen, settings, "Finish") self.__prepared: bool = False self.__punishment_labels: [] = [] #Initialize the punishment labels self.__punishment_labels.append( Button(screen, settings, "Was the guess correct?", button_color=None)) self.__punishment_labels.append( Button(screen, settings, "If not, give punishment to the player. Otherwise, give", button_color=None, padding=1)) self.__punishment_labels.append( Button(screen, settings, "punishment to everyone else. Punishment can be truth or", button_color=None, padding=1)) self.__punishment_labels.append( Button(screen, settings, "dare, push-ups, sing, etc.", button_color=None, padding=1)) #Configure component positioning screen_rect: Rect = screen.get_rect() #Finish button self.__finish_button.get_rect().right = screen_rect.right - 20 self.__finish_button.get_rect( ).centery = screen_rect.bottom - self.__finish_button.get_height() self.__finish_button.prep_msg(self.__finish_button.get_text())
def __init__(self, screen, settings:Settings): super().__init__(screen, settings, background_img_path="instructions.png") self.__ok_button:Button = Button(screen, settings, "Ok") #Component placement configuration screen_rect:Rect = screen.get_rect() #Ok Button self.__ok_button.get_rect().centery = screen_rect.bottom - self.__ok_button.get_height() self.__ok_button.prep_msg(self.__ok_button.get_text())
def __init__(self, screen, settings: Settings): super().__init__(screen, settings, background_img_path="choose_ai.png") #Initialize components self.__sub_title_label = Label("Choose your AI") self.__choose_button = Button(screen, settings, "Choose") self.__ai_buttons: [] = [] self.__back_button: Button = Button( self.get_screen(), self.get_settings(), "Back", button_color=settings.button_color_red) self.__selected_button: AIButton = None self.__ai_details_screen: AIInfoDisplay = AIInfoDisplay() self.__active_ai_image = None #Properties self.__choose_button.set_enabled(False) #Configure component placement screen_rect: Rect = screen.get_rect() #Sub title self.__sub_title_label.get_rect().top = screen_rect.top + 20 self.__sub_title_label.get_rect().centerx = screen_rect.centerx #AI Details Display Screen details_screen_rect: Rect = self.__ai_details_screen.get_rect() details_screen_rect.left = screen_rect.centerx + screen_rect.centerx // 3 details_screen_rect.centery = screen_rect.centery #Choose Button self.__choose_button.get_rect().centery = self.get_screen().get_rect( ).bottom - self.__choose_button.get_height() self.__choose_button.prep_msg(self.__choose_button.get_text()) #Back Button self.__back_button.get_rect( ).left = self.get_screen().get_rect().left + 20 self.__back_button.get_rect().centery = self.get_screen().get_rect( ).bottom - self.__back_button.get_height() self.__back_button.prep_msg(self.__back_button.get_text()) self._init_ai_buttons()
def __init__(self, screen, settings: Settings, neural_network: NeuralNetwork = None): super().__init__(screen, settings) #Fields initialization self.__exit_button: Button = Button(self.get_screen(), self.get_settings(), "Exit", button_color=constants.color_red) self.__guess_button: Button = Button(self.get_screen(), self.get_settings(), "Guess") self.__clear_button: Button = Button(self.get_screen(), self.get_settings(), "Clear") self.__buttons_to_draw: [Button] = [ self.__exit_button, self.__guess_button, self.__clear_button ] self.__guess_button_pressed: boolean = False self.__colored_pixels = set(()) self.__neural_network = neural_network #Configure button placements #Exit button self.get_exit_button().get_rect( ).left = self.get_screen().get_rect().left + 20 self.get_exit_button().get_rect().centery = self.get_screen().get_rect( ).bottom - self.get_exit_button().get_height() self.get_exit_button().prep_msg(self.get_exit_button().get_text()) #Guess button self.get_guess_button().get_rect().centery = self.get_screen( ).get_rect().bottom - self.get_guess_button().get_height() self.get_guess_button().prep_msg(self.get_guess_button().get_text()) #Clear button self.get_clear_button().get_rect( ).right = self.get_screen().get_rect().right - 20 self.get_clear_button().get_rect().centery = self.get_screen( ).get_rect().bottom - self.get_clear_button().get_height() self.get_clear_button().prep_msg(self.get_clear_button().get_text())
class ChooseAIPanel(Panel): #Constructor def __init__(self, screen, settings: Settings): super().__init__(screen, settings, background_img_path="choose_ai.png") #Initialize components self.__sub_title_label = Label("Choose your AI") self.__choose_button = Button(screen, settings, "Choose") self.__ai_buttons: [] = [] self.__back_button: Button = Button( self.get_screen(), self.get_settings(), "Back", button_color=settings.button_color_red) self.__selected_button: AIButton = None self.__ai_details_screen: AIInfoDisplay = AIInfoDisplay() self.__active_ai_image = None #Properties self.__choose_button.set_enabled(False) #Configure component placement screen_rect: Rect = screen.get_rect() #Sub title self.__sub_title_label.get_rect().top = screen_rect.top + 20 self.__sub_title_label.get_rect().centerx = screen_rect.centerx #AI Details Display Screen details_screen_rect: Rect = self.__ai_details_screen.get_rect() details_screen_rect.left = screen_rect.centerx + screen_rect.centerx // 3 details_screen_rect.centery = screen_rect.centery #Choose Button self.__choose_button.get_rect().centery = self.get_screen().get_rect( ).bottom - self.__choose_button.get_height() self.__choose_button.prep_msg(self.__choose_button.get_text()) #Back Button self.__back_button.get_rect( ).left = self.get_screen().get_rect().left + 20 self.__back_button.get_rect().centery = self.get_screen().get_rect( ).bottom - self.__back_button.get_height() self.__back_button.prep_msg(self.__back_button.get_text()) self._init_ai_buttons() #Other init methods def _init_ai_buttons(self): """Method to initialize the AIButton objects and configure their placements""" #Append AIs padding = 10 self.__ai_buttons.append( AIButton(self.get_screen(), self.get_settings(), AI("Cintra - 01000010", "ai_files/cintra/"), padding=padding)) self.__ai_buttons.append( AIButton(self.get_screen(), self.get_settings(), AI("Echo - 01100001", "ai_files/echo/"), padding=padding)) self.__ai_buttons.append( AIButton(self.get_screen(), self.get_settings(), AI("Glados - 01100111", "ai_files/glados/"), padding=padding)) self.__ai_buttons.append( AIButton(self.get_screen(), self.get_settings(), AI("House - 01110101", "ai_files/house/"), padding=padding)) self.__ai_buttons.append( AIButton(self.get_screen(), self.get_settings(), AI("Talos - 01110011", "ai_files/talos/"), padding=padding)) #Calculate total height and max width tot_height: int = 0 width_max: int = 0 for button in self.__ai_buttons: tot_height += button.get_rect( ).height #Add total height of the buttons width = button.get_rect().width if width > width_max: width_max = width #Update width of all buttons to be the same for button in self.__ai_buttons: button.get_rect().width = width_max #Placement configuration rect: Rect = Rect(0, 0, self.__ai_buttons[0].get_rect().width, tot_height) rect.centery = self.get_screen().get_rect().centery rect.centerx = self.get_screen().get_rect().centerx // 3 #Configure first button padding: int = 5 self.__ai_buttons[0].get_rect().top = rect.top - padding self.__ai_buttons[0].get_rect().left = rect.left self.__ai_buttons[0].prep_msg(self.__ai_buttons[0].get_text()) #Configure remaining buttons for i in range(1, len(self.__ai_buttons)): self.__ai_buttons[i].get_rect( ).top = self.__ai_buttons[i - 1].get_rect().bottom + padding self.__ai_buttons[i].get_rect().left = rect.left self.__ai_buttons[i].prep_msg(self.__ai_buttons[i].get_text()) self.__ai_buttons[i].prep_surface() #Setters and Getters def get_ai_buttons(self) -> [AIButton]: return self.__ai_buttons def get_ai_details_display_screen(self) -> AIInfoDisplay: return self.__ai_details_screen def get_active_ai_image(self): return self.__active_ai_image def get_back_button(self): return self.__back_button def get_choose_button(self): return self.__choose_button def get_selected_button(self) -> AIButton: return self.__selected_button #Other Methods def check_ai_button_selection(self, button: AIButton, mouse_pos: ()): """Method to check for AI selection, when one of the AI buttons are pressed""" if button != None and game_functions.mouse_on_button( button, mouse_pos): self.__selected_button = button updated_selection: bool = not self.__selected_button.is_selected() self.__selected_button.set_selected(updated_selection) if updated_selection: #If button is selected, disable every other button for button in self.__ai_buttons: if button != self.__selected_button: button.set_selected(False) self.get_ai_details_display_screen().set_image( self.__selected_button.get_ai().get_image_info_screen_path()) self.prep_ai_idle_image( self.__selected_button.get_ai().get_image()) self.__choose_button.set_enabled(updated_selection) if updated_selection == False: self.__selected_button = None else: self.__selected_button.get_ai().get_image_idle_rect( ).center = self.get_screen().get_rect().center def check_back_button(self, mouse_pos: ()): """Method to check when the back button is pressed""" if gf.mouse_on_button(self.__back_button, mouse_pos): globals.panel_index -= 1 def check_choose_button(self, mouse_pos: ()): """Method to check when the choose button is pressed""" if gf.mouse_on_button(self.__choose_button, mouse_pos) and self.__choose_button.is_enabled(): globals.active_ai = self.__selected_button.get_ai() globals.panel_index += 1 def prep_ai_idle_image(self, image): """Method to prepare the ai idle image for display""" self.__active_ai_image = image self.__active_ai_image.get_rect().center = self.get_screen().get_rect( ).center #Overridden Methods def check_events(self, event: Event): super().check_events(event) x, y = gf.get_mouse_position() #Check for mouse over actions hover: bool = False selected_button: AIButton = None for ai_button in self.__ai_buttons: hover = gf.mouse_in_area(ai_button.get_rect(), (x, y)) if hover: selected_button = ai_button break if self.__selected_button == None: if (hover): # self.get_ai_details_display_screen().set_model_sum_text(selected_button.get_ai().get_model_structure()) self.get_ai_details_display_screen().set_image( selected_button.get_ai().get_image_info_screen_path()) self.prep_ai_idle_image(selected_button.get_ai().get_image()) else: self.get_ai_details_display_screen().set_image( constants.path_img_ai_info_empty) self.__active_ai_image = None # self.get_ai_details_display_screen().set_model_sum_text("") #Check for mouse button presses if event.type == pygame.MOUSEBUTTONDOWN: if event.button == 1: #1 is left mouse button self.check_ai_button_selection(selected_button, (x, y)) self.check_back_button((x, y)) self.check_choose_button((x, y)) def draw_components(self): super().draw_components() self.__sub_title_label.draw(self.get_screen()) self.__back_button.draw() self.__choose_button.draw() self.get_ai_details_display_screen().draw(self.get_screen()) if self.__active_ai_image != None: rect: Rect = Rect(0, 0, self.__active_ai_image.get_rect().width, self.__active_ai_image.get_rect().height) rect.center = self.get_screen().get_rect().center self.get_screen().blit(self.__active_ai_image, rect) for ai_button in self.get_ai_buttons(): ai_button.draw() pygame.display.flip() def reset_defaults(self): super().reset_defaults() self.__choose_button.set_enabled(False) #If there's an existing selection, turn it off and set the selection to None if (self.__selected_button != None): self.__selected_button.set_selected(False) self.__selected_button = None
def __init__(self, screen, settings: Settings): """ screen: the pygame screen settings: the Settings object """ super().__init__(screen, settings, background_img_path="mainmenu.png") #Fields initialization self.__start_button = Button(screen, settings, "Start") self.__instructions_button = Button(screen, settings, "Instructions") self.__exit_button = Button(screen, settings, "Exit", button_color=settings.button_color_red) self.__title_label: Button = Button( screen, settings, "AI Roulette", font=settings.title_font ) #It's a label but will be using Button class for the background color #Configure components self.__title_label.set_button_color((177, 226, 236, 204)) self.__title_label.set_text_color((0, 0, 0)) #Configure Buttons self.get_start_button().set_width( 3 * self.get_settings().screen_width // 5) self.get_instructions_button().set_width( 3 * self.get_settings().screen_width // 5) #Configure component placements padding: int = 10 screen_rect: Rect = self.get_screen().get_rect() #Title label self.__title_label.get_rect().centerx = screen_rect.centerx self.__title_label.get_rect().centery = screen_rect.top + 100 self.__title_label.prep_msg(self.__title_label.get_text()) #Start button self.get_start_button().get_rect( ).left = screen_rect.left + settings.screen_width // 5 self.get_start_button().get_rect( ).right = screen_rect.right - settings.screen_width // 5 self.get_start_button().get_rect( ).centery = screen_rect.centery - self.get_start_button().get_height( ) // 2 - padding self.get_start_button().get_rect().centerx = self.get_screen( ).get_rect().centerx self.get_start_button().prep_msg(self.get_start_button().get_text()) #Instructions button self.get_instructions_button().get_rect( ).left = screen_rect.left + settings.screen_width // 5 self.get_instructions_button().get_rect( ).right = screen_rect.right - settings.screen_width // 5 self.get_instructions_button().get_rect( ).centery = screen_rect.centery + self.get_instructions_button( ).get_height() // 2 + padding self.get_instructions_button().get_rect().centerx = self.get_screen( ).get_rect().centerx self.get_instructions_button().prep_msg( self.get_instructions_button().get_text()) #Exit button self.get_exit_button().get_rect( ).left = screen_rect.left + settings.screen_width // 5 self.get_exit_button().get_rect( ).right = screen_rect.right - settings.screen_width // 5 self.get_exit_button().get_rect( ).top = self.get_instructions_button().get_rect().bottom + padding * 2 self.get_exit_button().get_rect().centerx = self.get_screen().get_rect( ).centerx self.get_exit_button().prep_msg(self.get_exit_button().get_text())
def mouse_on_button(button: Button, mouse_pos: ()): """Check if the mouse pointer is on a button""" return mouse_in_area(button.get_rect(), mouse_pos)