Пример #1
0
    def show_guess(self):
        self.is_guess = True
        self._guess_button.set_text('Guess!')

        rect = self._room_menu_rect.copy()
        items = list(map(lambda i: i.pretty(), Room))
        self._room_menu.kill()
        self._room_menu = UIDropDownMenu(items, self.player.room.pretty(), rect, self.manager, container=self.panel)
        #self._room_menu.rebuild()
        self._room_menu.disable()

        self._show()
Пример #2
0
 def build_gui(self):
     super().build_gui()
     panel_rect = Rect(
         0, 0, 500,
         self.display.get_rect().height - (get_param('panel_padding') * 2))
     panel_rect.centerx = self.display.get_rect().centerx
     panel_rect.y = get_param('panel_padding')
     self.ui_elements['panel'] = UIPanel(panel_rect, 1, self.gui)
     # all other elements are relative
     scene_label_rect = Rect(0, 0, 400, get_param('element_height'))
     scene_label_rect.y = get_param('element_padding')
     scene_label_rect.centerx = panel_rect.w // 2  # midpoint of the panel
     self.ui_elements['scene_label'] = UILabel(scene_label_rect, "Settings",
                                               self.gui,
                                               self.ui_elements['panel'])
     # screen size
     label_rect = Rect(0, 0, 150, get_param('element_height'))
     label_rect.y += scene_label_rect.bottom + get_param('element_padding')
     dd_rect = Rect(0, 0, 250, get_param('element_height'))
     dd_rect.y = label_rect.y
     label_rect.centerx = 125
     dd_rect.centerx = 325
     self.ui_elements['d_size_label'] = UILabel(label_rect, "Display Size",
                                                self.gui,
                                                self.ui_elements['panel'])
     self.ui_elements['dd_d_size'] = UIDropDownMenu(
         get_param('display_sizes'), get_param('current_display_size'),
         dd_rect, self.gui, self.ui_elements['panel'])
     # full screen
     label_rect.y += get_param('element_height') + get_param(
         'element_padding')
     dd_rect.y = label_rect.y
     self.ui_elements['fs_label'] = UILabel(label_rect, "Full Screen",
                                            self.gui,
                                            self.ui_elements['panel'])
     self.ui_elements['dd_fs'] = UIDropDownMenu(
         ["On", "Off"], get_param('display_full_screen_value'), dd_rect,
         self.gui, self.ui_elements['panel'])
     # buttons
     button_rect = Rect(0, 0, 200, get_param('element_height'))
     button_rect.y = label_rect.bottom + get_param('element_padding')
     button_rect.centerx = (panel_rect.w // 2) - 100
     self.ui_elements['btn_back'] = UIButton(button_rect, "Back", self.gui,
                                             self.ui_elements['panel'])
     # the apply button always starts off disabled
     button_rect.centerx = (panel_rect.w // 2) + 100
     self.ui_elements['btn_apply'] = UIButton(button_rect, "Apply",
                                              self.gui,
                                              self.ui_elements['panel'])
     self.ui_elements['btn_apply'].disable()
     # re-assign values for our check parameters, this is to control the apply buttons state
     self._check_screen_size = get_param('current_display_size')
     self._check_full_screen = get_param('display_full_screen_value')
Пример #3
0
    def make_drop_down(self, enum: Enum, y_offset: int) -> UIDropDownMenu:
        items = list(map(lambda i: i.pretty(), enum))
        rect = pygame.Rect((int((self.width - 200) / 2), y_offset), (200, 25))

        if enum == Room:
            self._room_menu_rect = rect

        return UIDropDownMenu(items, items[0], rect, self.manager, container=self.panel)
Пример #4
0
    def _setup_ui(self) -> None:
        """
        Set up the UI components for the game.
        This helper is called inside the __init__ and creates several of the
        private instance attributes. It is called again any time the puzzle
        to be solved is changed.
        """
        self._variable_map = []
        self._variable_name = []

        n_variables = len(self._puzzle.variables)

        for vname in self._puzzle.variables:
            rect = pygame.Rect(
                (UI_WIDTH // 2, UI_ITEM_HEIGHT * len(self._variable_name)),
                (UI_WIDTH // 2, UI_ITEM_HEIGHT))
            uidrop = UIDropDownMenu([str(x) for x in range(10)],
                                    relative_rect=rect,
                                    starting_option=str(
                                        self._puzzle.variables[vname]),
                                    manager=self._manager)
            self._variable_map.append(uidrop)

            rect = pygame.Rect((0, UI_ITEM_HEIGHT * len(self._variable_name)),
                               (UI_WIDTH // 2, UI_ITEM_HEIGHT))

            label = UILabel(relative_rect=rect,
                            text=vname,
                            manager=self._manager)

            self._variable_name.append(label)

        rect = pygame.Rect((0, UI_ITEM_HEIGHT * n_variables),
                           (UI_WIDTH, UI_ITEM_HEIGHT))
        # target label
        UILabel(relative_rect=rect,
                text=f"Target: {self._puzzle.target}",
                manager=self._manager)

        rect = pygame.Rect((0, UI_ITEM_HEIGHT * (n_variables + 1)),
                           (UI_WIDTH, UI_ITEM_HEIGHT))
        tree_evaluation = self._tree.eval(self._puzzle.variables)
        self._result_label = UILabel(relative_rect=rect,
                                     text=f"Current:"
                                     f" {tree_evaluation}",
                                     manager=self._manager)

        rect = pygame.Rect((0, UI_HEIGHT // 2),
                           (UI_WIDTH // 2, UI_ITEM_HEIGHT))
        self._hint_button = UIButton(relative_rect=rect,
                                     text='HINT',
                                     manager=self._manager)

        rect = pygame.Rect((0, UI_HEIGHT // 2 + UI_ITEM_HEIGHT),
                           (UI_WIDTH // 2, UI_ITEM_HEIGHT))
        self._new_button = UIButton(relative_rect=rect,
                                    text='NEW',
                                    manager=self._manager)
Пример #5
0
 def generate_dropdown(self, rect, manager):
     x_center, y_center, w, h = rect
     centered_rect = (x_center - w // 2, y_center - h // 2, w, h)
     items = self.find_items()
     dropdown = UIDropDownMenu(items,
                               items[0],
                               relative_rect=pygame.Rect(*centered_rect),
                               manager=manager,
                               expansion_height_limit=200)
     return dropdown
Пример #6
0
    def build_gui(self):
        super().build_gui()
        panel_rect = Rect(
            0, 0, 500,
            self.display.get_rect().height - (get_param('panel_padding') * 2))
        panel_rect.centerx = self.display.get_rect().centerx
        panel_rect.y = get_param('panel_padding')
        self.ui_elements['panel'] = UIPanel(panel_rect, 1, self.gui)
        # all other elements are relative
        scene_label_rect = Rect(0, 0, 400, get_param('element_height'))
        scene_label_rect.y = get_param('element_padding')
        scene_label_rect.centerx = panel_rect.w // 2  # midpoint of the panel
        self.ui_elements['scene_label'] = UILabel(scene_label_rect,
                                                  "Start New Game", self.gui,
                                                  self.ui_elements['panel'])

        l_side_rect = Rect(0, 0, 150, get_param('element_height'))
        l_side_rect.centerx = 125
        l_side_rect.y = scene_label_rect.bottom + get_param('element_padding')
        self.ui_elements['l_dd_label'] = UILabel(l_side_rect, "Map Type",
                                                 self.gui,
                                                 self.ui_elements['panel'])
        dd_rect = Rect(0, 0, 250, get_param('element_height'))
        dd_rect.y = l_side_rect.y
        dd_rect.centerx = 325
        self.ui_elements['l_dd_game_map'] = UIDropDownMenu(
            ['Existing', 'Random'], 'Existing', dd_rect, self.gui,
            self.ui_elements['panel'])
        btn_rect = Rect(0, 0, 200, get_param('element_height'))
        btn_rect.centerx = (panel_rect.w) // 2 - 100
        btn_rect.y = dd_rect.bottom + get_param('element_padding')
        self.ui_elements['btn_back'] = UIButton(btn_rect, "Back", self.gui,
                                                self.ui_elements['panel'])
        btn_rect = Rect(0, 0, 200, get_param('element_height'))
        btn_rect.centerx = (panel_rect.w // 2) + 100
        btn_rect.y = dd_rect.bottom + get_param('element_padding')
        self.ui_elements['btn_next'] = UIButton(btn_rect, "Next", self.gui,
                                                self.ui_elements['panel'])
Пример #7
0
    def __init__(self, rect, ui_manager):
        super().__init__(rect,
                         ui_manager,
                         window_display_title='Everything Container',
                         object_id='#everything_window',
                         resizable=True)

        self.test_slider = UIHorizontalSlider(pygame.Rect(
            (int(self.rect.width / 2), int(self.rect.height * 0.70)),
            (240, 25)),
                                              50.0, (0.0, 100.0),
                                              self.ui_manager,
                                              container=self)

        self.slider_label = UILabel(
            pygame.Rect(
                (int(self.rect.width / 2) + 250, int(self.rect.height * 0.70)),
                (27, 25)),
            str(int(self.test_slider.get_current_value())),
            self.ui_manager,
            container=self)

        self.test_text_entry = UITextEntryLine(pygame.Rect(
            (int(self.rect.width / 2), int(self.rect.height * 0.50)),
            (200, -1)),
                                               self.ui_manager,
                                               container=self)
        self.test_text_entry.set_forbidden_characters('numbers')

        current_resolution_string = 'Item 1'
        self.test_drop_down_menu = UIDropDownMenu(
            [
                'Item 1', 'Item 2', 'Item 3', 'Item 4', 'Item 5', 'Item 6',
                'Item 7', 'Item 8', 'Item 9', 'Item 10', 'Item 11', 'Item 12',
                'Item 13', 'Item 14', 'Item 15', 'Item 16', 'Item 17',
                'Item 18', 'Item 19', 'Item 20', 'Item 21', 'Item 22',
                'Item 23', 'Item 24', 'Item 25', 'Item 26', 'Item 27',
                'Item 28', 'Item 29', 'Item 30'
            ],
            current_resolution_string,
            pygame.Rect(
                (int(self.rect.width / 2), int(self.rect.height * 0.3)),
                (200, 25)),
            self.ui_manager,
            container=self)

        self.health_bar = UIScreenSpaceHealthBar(pygame.Rect(
            (int(self.rect.width / 9), int(self.rect.height * 0.7)),
            (200, 20)),
                                                 self.ui_manager,
                                                 container=self)

        loaded_test_image = pygame.image.load(
            'data/images/splat.png').convert_alpha()

        self.test_image = UIImage(pygame.Rect(
            (int(self.rect.width / 9), int(self.rect.height * 0.3)),
            loaded_test_image.get_rect().size),
                                  loaded_test_image,
                                  self.ui_manager,
                                  container=self)
Пример #8
0
    def recreate_ui(self):
        self.ui_manager.set_window_resolution(self.options.resolution)
        self.ui_manager.clear_and_reset()

        self.background_surface = pygame.Surface(self.options.resolution)
        self.background_surface.fill(self.ui_manager.get_theme().get_colour(
            None, None, 'dark_bg'))

        self.test_button = UIButton(
            pygame.Rect((int(self.options.resolution[0] / 2),
                         int(self.options.resolution[1] * 0.90)), (100, 40)),
            '',
            self.ui_manager,
            tool_tip_text="<font face=fira_code color=normal_text size=2>"
            "<b><u>Test Tool Tip</u></b>"
            "<br><br>"
            "A little <i>test</i> of the "
            "<font color=#FFFFFF><b>tool tip</b></font>"
            " functionality."
            "<br><br>"
            "Unleash the Kraken!"
            "</font>",
            object_id='#hover_me_button')

        self.test_button_2 = UIButton(pygame.Rect(
            (int(self.options.resolution[0] / 3),
             int(self.options.resolution[1] * 0.90)), (100, 40)),
                                      'EVERYTHING',
                                      self.ui_manager,
                                      object_id='#everything_button')

        self.test_button_3 = UIButton(pygame.Rect(
            (int(self.options.resolution[0] / 6),
             int(self.options.resolution[1] * 0.90)), (100, 40)),
                                      'Scaling?',
                                      self.ui_manager,
                                      object_id='#scaling_button')

        self.test_slider = UIHorizontalSlider(pygame.Rect(
            (int(self.options.resolution[0] / 2),
             int(self.options.resolution[1] * 0.70)), (240, 25)),
                                              25.0, (0.0, 100.0),
                                              self.ui_manager,
                                              object_id='#cool_slider')

        self.test_text_entry = UITextEntryLine(pygame.Rect(
            (int(self.options.resolution[0] / 2),
             int(self.options.resolution[1] * 0.50)), (200, -1)),
                                               self.ui_manager,
                                               object_id='#main_text_entry')

        current_resolution_string = (str(self.options.resolution[0]) + 'x' +
                                     str(self.options.resolution[1]))
        self.test_drop_down = UIDropDownMenu(
            ['640x480', '800x600', '1024x768'], current_resolution_string,
            pygame.Rect((int(self.options.resolution[0] / 2),
                         int(self.options.resolution[1] * 0.3)),
                        (200, 25)), self.ui_manager)

        self.panel = UIPanel(pygame.Rect(50, 50, 200, 300),
                             starting_layer_height=4,
                             manager=self.ui_manager)

        UIButton(pygame.Rect(10, 10, 174, 30),
                 'Panel Button',
                 manager=self.ui_manager,
                 container=self.panel)

        UISelectionList(pygame.Rect(10, 50, 174, 200),
                        item_list=[
                            'Item 1', 'Item 2', 'Item 3', 'Item 4', 'Item 5',
                            'Item 6', 'Item 7', 'Item 8', 'Item 9', 'Item 10',
                            'Item 11', 'Item 12', 'Item 13', 'Item 14',
                            'Item 15', 'Item 16', 'Item 17', 'Item 18',
                            'Item 19', 'Item 20'
                        ],
                        manager=self.ui_manager,
                        container=self.panel,
                        allow_multi_select=True)
Пример #9
0
class GuessPanel:

    ###
    ### STATIC
    ###
    def card_from_text(dropdown: UIDropDownMenu, items: Enum, cardType: CardType) -> Card:
        text = dropdown.selected_option

        for item in items:
            if text == item.pretty():
                return Card(item, cardType)

        raise Exception("enum value not found " + text + " " + str(items))

    manager: UIManager
    panel: UIPanel
    player: HumanPlayer
    on_end_turn: Callable

    _weapon_menu: UIDropDownMenu
    _character_menu: UIDropDownMenu
    _room_menu: UIDropDownMenu
    _guess_button: UIButton
    _room_menu_rect: pygame.Rect

    guess: Solution
    is_guess: bool

    def __init__(self, manager: UIManager, screen_width: int, screen_height: int, player: HumanPlayer, \
            on_end_turn: Callable):
        self.manager = manager
        self.player = player
        self.on_end_turn = on_end_turn
        self._create_panel(manager, screen_width, screen_height)
   
    def _create_panel(self, manager: UIManager, screen_width: int, screen_height: int):
        self.width = 300
        self.height = 355

        rect = create_modal_rect(screen_width, screen_height, self.width, self.height)
        self.panel = UIPanel(rect, 0, manager, element_id='guess_panel')

        y_offset = 20

        self.make_label("Make a guess", y_offset)
        y_offset += 20 + 20

        self._character_menu = self.make_drop_down(Character, y_offset)
        y_offset += 25 + 10

        self.make_label("in the", y_offset)
        y_offset += 20 + 10

        self._room_menu = self.make_drop_down(Room, y_offset)
        y_offset += 25 + 10

        self.make_label("with the", y_offset)
        y_offset += 20 + 10

        self._weapon_menu = self.make_drop_down(Weapon, y_offset)
        y_offset += 20 + 50

        button_rect = pygame.Rect((50, y_offset), (200, 30))
        self._guess_button = UIButton(button_rect, '', manager, container=self.panel)

        self.panel.hide()

    def make_label(self, text: str, y_offset):
        rect = pygame.Rect((0, y_offset), (self.width, 20))
        UILabel(rect, text, self.manager, container=self.panel)

    def make_drop_down(self, enum: Enum, y_offset: int) -> UIDropDownMenu:
        items = list(map(lambda i: i.pretty(), enum))
        rect = pygame.Rect((int((self.width - 200) / 2), y_offset), (200, 25))

        if enum == Room:
            self._room_menu_rect = rect

        return UIDropDownMenu(items, items[0], rect, self.manager, container=self.panel)

    def show_guess(self):
        self.is_guess = True
        self._guess_button.set_text('Guess!')

        rect = self._room_menu_rect.copy()
        items = list(map(lambda i: i.pretty(), Room))
        self._room_menu.kill()
        self._room_menu = UIDropDownMenu(items, self.player.room.pretty(), rect, self.manager, container=self.panel)
        #self._room_menu.rebuild()
        self._room_menu.disable()

        self._show()

    def show_accuse(self):
        self.is_guess = False
        self._guess_button.set_text('Make Accusation!')
        self._room_menu.enable()
        self._show()

    def _show(self):
        self.guess = Solution(None, None, None)
        self._update_weapon()
        self._update_character()
        self._update_room() 

        self.panel.show()

    def process_events(self, event):
        if not self.panel.visible:
            return

        self.panel.process_event(event)

        if event.type != pygame.USEREVENT:
            return

        if event.user_type == pygame_gui.UI_DROP_DOWN_MENU_CHANGED:
            if event.ui_element == self._weapon_menu:
                self._update_weapon()
            elif event.ui_element == self._character_menu:
                self._update_character()
            elif event.ui_element == self._room_menu:
                self._update_room()                

        if event.user_type == pygame_gui.UI_BUTTON_PRESSED and event.ui_element == self._guess_button:
            print("guessing " + str(self.guess))
            self.panel.hide()

            if self.is_guess:
                self.player.make_guess(self.guess)
            else:
                self.player.accuse(self.guess)
            self.on_end_turn()

    def _update_weapon(self):
        self.guess.weapon = GuessPanel.card_from_text(self._weapon_menu, Weapon, CardType.WEAPON)

    def _update_character(self):
        self.guess.character = GuessPanel.card_from_text(self._character_menu, Character, CardType.CHARACTER)

    def _update_room(self):
        self.guess.room = GuessPanel.card_from_text(self._room_menu, Room, CardType.ROOM)
Пример #10
0
    def __init__(self):
        pygame.init()

        pygame.display.set_caption("Pathfinding Algorithms")
        self.window_surface = pygame.display.set_mode((800, 600))

        self.ui_manager = pygame_gui.UIManager(
            (800, 600), "pathfinding/data/ui_theme.json")
        self.ui_manager.preload_fonts([{
            'name': 'fira_code',
            'point_size': 14,
            'style': 'bold'
        }])

        self.background_surface = pygame.Surface((800, 600))
        self.background_surface.fill(
            self.ui_manager.get_theme().get_colour('dark_bg'))

        self.playing_pathfinder = False
        self.play_speed = 0.5
        self.play_speed_acc = 0.0

        pathfinding_algorithms = [
            'A*', "Breadth First", "Depth First", "Dijkstra's", "Uniform Cost"
        ]
        self.pathfinder_drop_down = UIDropDownMenu(
            pathfinding_algorithms, 'A*', pygame.Rect((620, 50), (150, 25)),
            self.ui_manager)

        self.pathfinder_label = pygame_gui.elements.UILabel(
            pygame.Rect((520, 50), (100, 25)), "Algorithm: ", self.ui_manager)

        map_sizes = ['20x20', "40x40", "80x80"]
        self.map_size_drop_down = UIDropDownMenu(
            map_sizes, '20x20', pygame.Rect((620, 225), (150, 25)),
            self.ui_manager)

        self.map_size_label = pygame_gui.elements.UILabel(
            pygame.Rect((520, 225), (100, 25)), "Map size: ", self.ui_manager)

        self.random_start_button = UIButton(pygame.Rect((620, 350), (150, 25)),
                                            "Random start", self.ui_manager)

        self.increment_pathfinder_button = UIButton(
            pygame.Rect((620, 385), (150, 25)), "Increment", self.ui_manager)

        self.play_button = UIButton(pygame.Rect((620, 420), (150, 25)), "Play",
                                    self.ui_manager)

        self.speed_slider = UIHorizontalSlider(
            pygame.Rect((620, 455), (150, 25)), self.play_speed, (1.0, 0.017),
            self.ui_manager)

        self.speed_slider_label = pygame_gui.elements.UILabel(
            pygame.Rect((520, 455), (100, 25)), "Play speed: ",
            self.ui_manager)

        self.tool_tip = None

        self.wall_colour = pygame.Color("#FFFFFF")

        self.available_maze_space = 450
        self.wall_size = 4
        self.maze_dimension = 20

        self.maze_square_size = int(
            self.available_maze_space / self.maze_dimension) + 1
        self.walls, self.junctions, self.entrance, self.exit = create_maze(
            top_left=(20, 20),
            square_size=self.maze_square_size,
            width=self.maze_dimension,
            height=self.maze_dimension)

        self.nav_node_graph = [
            junction.nav_node for junction in self.junctions
        ]
        self.font = pygame.font.Font(None, 12)
        self.current_finder = AStarFinder(self.entrance.nav_node,
                                          self.exit.nav_node,
                                          incremental=True)

        self.clock = pygame.time.Clock()
        self.running = True
Пример #11
0
    def build_gui(self):
        super().build_gui()
        panel_rect = Rect(
            0, 0, 500,
            self.display.get_rect().height - (get_param('panel_padding') * 2))
        panel_rect.centerx = self.display.get_rect().centerx
        panel_rect.y = get_param('panel_padding')
        self.ui_elements['panel'] = UIPanel(panel_rect, 1, self.gui)
        # all other elements are relative
        scene_label_rect = Rect(0, 0, 400, get_param('element_height'))
        scene_label_rect.y = get_param('element_padding')
        scene_label_rect.centerx = panel_rect.w // 2  # midpoint of the panel
        self.ui_elements['scene_label'] = UILabel(scene_label_rect,
                                                  "Generate Random Map",
                                                  self.gui,
                                                  self.ui_elements['panel'])
        # map size
        label_rect = Rect(0, 0, 150, get_param('element_height'))
        label_rect.y += scene_label_rect.bottom + get_param('element_padding')
        dd_rect = Rect(0, 0, 250, get_param('element_height'))
        dd_rect.y = label_rect.y
        label_rect.centerx = 125
        dd_rect.centerx = 325
        self.ui_elements['d_size_label'] = UILabel(label_rect, "Map Size",
                                                   self.gui,
                                                   self.ui_elements['panel'])
        self.ui_elements['dd_map_size'] = UIDropDownMenu(
            ['64', '128', '256'], '64', dd_rect, self.gui,
            self.ui_elements['panel'])
        # Seed
        label_rect.y += get_param('element_height') + get_param(
            'element_padding')
        ip_rect = Rect(0, 0, 180, get_param('element_height'))
        ip_rect.centerx = (panel_rect.w // 2) + 30
        ip_rect.y = label_rect.y
        s_btn_rect = Rect(0, 0, 60, get_param('element_height'))
        s_btn_rect.x = ip_rect.right + get_param('element_padding')
        s_btn_rect.y = ip_rect.y
        self.ui_elements['seed_label'] = UILabel(label_rect, 'Map Seed',
                                                 self.gui,
                                                 self.ui_elements['panel'])
        self.ui_elements['input_seed'] = UITextEntryLine(
            ip_rect, self.gui, self.ui_elements['panel'])
        self.ui_elements['btn_rnd_seed'] = UIButton(s_btn_rect, 'Random',
                                                    self.gui,
                                                    self.ui_elements['panel'])
        # I want to add two sliders, 1 for mountains and 1 for water, these would be used to control the upper
        # and lower limits of the height mapping.
        h_sl_ops = (0, 100)
        h_sl_sel = 50
        label_rect.y += get_param('element_height') + get_param(
            'element_padding')
        h_sl_rect = Rect(0, 0, 200, get_param('element_height'))
        h_sl_rect.centerx = (panel_rect.w //
                             2) + get_param('element_padding') + 30
        h_sl_rect.y = label_rect.y
        self.ui_elements['hsl_grass'] = UILabel(label_rect, 'Grass', self.gui,
                                                self.ui_elements['panel'])
        self.ui_elements['hs_grass'] = UIHorizontalSlider(
            h_sl_rect, h_sl_sel, h_sl_ops, self.gui, self.ui_elements['panel'])

        label_rect.y += get_param('element_height') + get_param(
            'element_padding')
        h_sl_rect.y = label_rect.y
        self.ui_elements['hsl_water'] = UILabel(label_rect, 'Water', self.gui,
                                                self.ui_elements['panel'])
        self.ui_elements['hs_water'] = UIHorizontalSlider(
            h_sl_rect, h_sl_sel, h_sl_ops, self.gui, self.ui_elements['panel'])

        label_rect.y += get_param('element_height') + get_param(
            'element_padding')
        h_sl_rect.y = label_rect.y
        self.ui_elements['hsl_mountain'] = UILabel(label_rect, 'Mountain',
                                                   self.gui,
                                                   self.ui_elements['panel'])
        self.ui_elements['hs_mountain'] = UIHorizontalSlider(
            h_sl_rect, h_sl_sel, h_sl_ops, self.gui, self.ui_elements['panel'])

        # buttons
        button_rect = Rect(0, 0, 200, get_param('element_height'))
        button_rect.centerx = panel_rect.w // 2
        button_rect.y = label_rect.bottom + get_param('element_padding')
        self.ui_elements['btn_preview'] = UIButton(button_rect,
                                                   "Generate Preview",
                                                   self.gui,
                                                   self.ui_elements['panel'])
        button_rect.w = 200
        button_rect.y += get_param('element_height') + get_param(
            'element_padding')
        button_rect.centerx = (panel_rect.w // 2) - 100
        self.ui_elements['btn_back'] = UIButton(button_rect, "Back", self.gui,
                                                self.ui_elements['panel'])
        # the apply button always starts off disabled
        button_rect.centerx = (panel_rect.w // 2) + 100
        self.ui_elements['btn_next'] = UIButton(button_rect, "Next", self.gui,
                                                self.ui_elements['panel'])
        pv_rect = Rect(0, 0, 300, 300)
        pv_rect.centerx = panel_rect.w // 2
        pv_rect.y = button_rect.bottom + get_param('element_padding')
        self.ui_elements['pv_image'] = UIImage(pv_rect, self.pv_img, self.gui,
                                               self.ui_elements['panel'])
    def __init__(self, rect, manager, window_surface):
        super().__init__(rect,
                         manager,
                         lang.strings['settings_window'],
                         'SettingsWindow',
                         '#settings_window',
                         resizable=True)
        self.manager = manager
        self.settings = read_json()
        self.window_surface = window_surface

        self.warning_screen = None

        self.in_fullscreen = False
        self.special_flags = self.settings['screen_mode']
        self.any_settings_changed = False
        self.setting_changed = {
            'res': False,  # resolution of screen
            'fll': False,  # screen made fullscreen 
            # i removed fll from the settings window and made fullscreen toggleable from a button on the main menu but, didn't change this because I'm too lazy to debug it afterwards
            'scr': False,  # screen mode changed (other than fullscreen)
            'lng': False,  # language changed
            'yrs': False  # year changed 
        }

        # resolution ↓↓
        resol_label_rect = pygame.Rect(
            (12, 32), ((len(lang.strings['resolution_label']) * 10) - 36, 19))
        self.resol_label = UILabel(resol_label_rect,
                                   lang.strings['resolution_label'],
                                   self.manager, self, self, '#res_menu_label')
        resol_drop_down_rect = pygame.Rect((12, 56), (94, 24))
        resol_drop_down_rect.topleft = resol_label_rect.bottomleft
        self.res_selections = [
            "600x500", "800x600", "900x650", "1000x700", "1200x700", "1240x740"
        ]
        current_res = self.settings["resolution"]
        self.resol_drop_down = UIDropDownMenu(
            self.res_selections,
            f"{current_res['width']}x{current_res['height']}",
            resol_drop_down_rect, self.manager, self, self, '#resolution_menu')

        # screen mode ↓↓
        scr_mode_label_rect = pygame.Rect(
            (200, 32),
            ((len(lang.strings['screen_mode_label']) * 10) - 19, 19))
        self.scr_mode_label = UILabel(scr_mode_label_rect,
                                      lang.strings['screen_mode_label'],
                                      self.manager, self, self,
                                      '#screen_mode_label')
        scr_mode_menu_rect = pygame.Rect((200, 56), (106, 24))
        scr_mode_menu_rect.topleft = scr_mode_label_rect.bottomleft
        self.scr_mode_selections = lang.strings['screen_mode_list']
        current_screen_mode = self.settings['screen_mode']

        if self.settings['screen_mode'] == "windowed" and self.settings[
                'language'] == "turkce":
            current_screen_mode = self.scr_mode_selections[0]

        elif self.settings['screen_mode'] == "borderless" and self.settings[
                'language'] == "turkce":
            current_screen_mode = self.scr_mode_selections[1]

        elif self.settings['screen_mode'] == "fullscreen" and self.settings[
                'language'] == "turkce":
            current_screen_mode = self.scr_mode_selections[2]

        self.scr_mode_menu = UIDropDownMenu(self.scr_mode_selections,
                                            current_screen_mode.capitalize(),
                                            scr_mode_menu_rect, self.manager,
                                            self, self, '#screen_menu')

        # sene seçme ↓↓
        year_label_rect = pygame.Rect(
            (12, 132), ((len(lang.strings['year_label']) * 10) - 19, 19))
        self.year_label = UILabel(year_label_rect, lang.strings['year_label'],
                                  self.manager, self, self, '#year_menu_label')

        year_drop_down_rect = pygame.Rect((12, 156), (84, 24))
        year_drop_down_rect.topleft = year_label_rect.bottomleft
        self.year_selections = ['2018', '2017', '2016']
        self.year_drop_down_menu = UIDropDownMenu(self.year_selections,
                                                  self.settings["year"],
                                                  year_drop_down_rect,
                                                  self.manager,
                                                  self,
                                                  self,
                                                  object_id='#year_menu')

        # dil seçme ↓↓
        lang_label_rect = pygame.Rect(
            (200, 132), ((len(lang.strings['language_label']) * 10) - 24, 19))
        self.lang_label = UILabel(lang_label_rect,
                                  lang.strings['language_label'], self.manager,
                                  self, self, '#lang_menu_label')

        lang_drop_down_rect = pygame.Rect((200, 156), (84, 24))
        lang_drop_down_rect.topleft = lang_label_rect.bottomleft
        self.lang_drop_down = UIDropDownMenu(
            GUI_LANGUAGES, self.settings["language"].capitalize(),
            lang_drop_down_rect, self.manager, self, self, '#lang_menu')

        # keep changes? ↓↓
        save_button_x_size = ((len(lang.strings['keep_changes']) * 10) - 18)
        save_button_rect = pygame.Rect((-16 - save_button_x_size, -16 - 24),
                                       (save_button_x_size, 24))
        self.save_button = UIButton(save_button_rect,
                                    lang.strings['keep_changes'],
                                    self.manager,
                                    self,
                                    lang.strings['keep_changes_hover'],
                                    parent_element=self,
                                    object_id='#keep_changes',
                                    anchors=GUI_ANCHORS_BOTTOM_RIGHT)
Пример #13
0
    def __init__(self):
        pygame.init()
        self.size = [INTRO_SCREEN_WIDTH, INTRO_SCREEN_HEIGHT]
        self.screen = pygame.display.set_mode(self.size)
        self.con_win = None
        self.game_level = 4
        self.game = None
        self.start_game = False
        self.game_nb_players = 4  # TODO The max number of players should be in function of the size of the desk
        self.game_nb_online_players = 1
        self.nb_p_c = 1
        # self.block_list
        self.player_name = "John"
        # self.player_name = "IA Show"
        self.player_type = "offline"
        self.host_address = "localhost"
        self.survival_mode = True
        self.all_sprites_list = pygame.sprite.Group()
        self.block_list = pygame.sprite.Group()
        self.clicked = False
        self.ui_manager = pygame_gui.UIManager(
            (INTRO_SCREEN_WIDTH, INTRO_SCREEN_HEIGHT))
        self.ui_manager.preload_fonts([{
            'name': 'fira_code',
            'point_size': 10,
            'style': 'bold'
        }, {
            'name': 'fira_code',
            'point_size': 10,
            'style': 'regular'
        }, {
            'name': 'fira_code',
            'point_size': 10,
            'style': 'italic'
        }, {
            'name': 'fira_code',
            'point_size': 14,
            'style': 'italic'
        }, {
            'name': 'fira_code',
            'point_size': 14,
            'style': 'bold'
        }, {
            'name': 'fira_code',
            'point_size': 14,
            'style': 'bold_italic'
        }])
        step = 40
        s = [150, 35]
        self.name_label = UILabel(pygame.rect.Rect((0, step), s),
                                  "Name",
                                  manager=self.ui_manager)
        self.name_value = UITextEntryLine(
            pygame.Rect((self.name_label.relative_rect.width,
                         self.name_label.relative_rect.y), (200, -1)),
            self.ui_manager)
        self.name_value.set_text(self.player_name)
        # The level
        self.game_level_label = UILabel(pygame.rect.Rect((0, step * 2), s),
                                        "Level",
                                        manager=self.ui_manager)
        self.game_level_drop = UIDropDownMenu(
            [str(i) for i in range(1, 5, 1)], f"{self.game_level}",
            pygame.rect.Rect(((s[0] - step) // 2, step * 3),
                             (50, 35)), self.ui_manager)
        self.nb_players_label = UILabel(pygame.rect.Rect(
            (s[0], self.game_level_label.relative_rect.y), s),
                                        "NB players",
                                        manager=self.ui_manager)
        self.nb_players_drop = UIDropDownMenu([str(i) for i in range(2, 7, 1)],
                                              f"{self.game_nb_players}",
                                              pygame.Rect(
                                                  (int(1.3 * s[0]), step * 3),
                                                  (50, 35)), self.ui_manager)

        self.nb_p_c_label = UILabel(pygame.rect.Rect(
            (2 * s[0], self.game_level_label.relative_rect.y), s),
                                    "NB playing cards",
                                    manager=self.ui_manager)

        self.nb_p_c_players_drop = UIDropDownMenu(
            [str(i) for i in range(1, 5, 1)], f"{self.nb_p_c}",
            pygame.Rect((int(2.3 * s[0]), step * 3),
                        (50, 35)), self.ui_manager)
        self.survival_label = UILabel(pygame.rect.Rect(
            (3 * s[0], self.game_level_label.relative_rect.y), s),
                                      "Survival mode",
                                      manager=self.ui_manager)

        self.survival_drop = UIDropDownMenu(
            ["yes", "no"], f"{'yes' if self.survival_mode else 'no'}",
            pygame.Rect((int(3.3 * s[0]), step * 3),
                        (60, 35)), self.ui_manager)

        self.start_game_btn = UIButton(
            pygame.Rect((INTRO_SCREEN_WIDTH - 200, INTRO_SCREEN_HEIGHT - 50),
                        (100, 40)), 'START', self.ui_manager)
        self.resume_game_btn = UIButton(
            pygame.Rect(
                (INTRO_SCREEN_WIDTH // 2 - 50, INTRO_SCREEN_HEIGHT - 50),
                (100, 40)), 'RESUME', self.ui_manager)
        self.quit_game_btn = UIButton(
            pygame.Rect((100, INTRO_SCREEN_HEIGHT - 50), (100, 40)), 'QUIT',
            self.ui_manager)
        UILabel(pygame.rect.Rect((10, int(step * 6.5 - s[1])), s),
                "On-line Settings",
                manager=self.ui_manager)
        self.online_panel = UIPanel(pygame.rect.Rect(
            (10, int(step * 6.5)), (INTRO_SCREEN_WIDTH - 20, step * 5)),
                                    starting_layer_height=4,
                                    manager=self.ui_manager)

        self.nb_online_players_label = UILabel(pygame.rect.Rect((s[0], 0), s),
                                               "Online players",
                                               manager=self.ui_manager,
                                               container=self.online_panel)

        self.nb_online_players_drop = UIDropDownMenu(
            [str(i) for i in range(1, 6, 1)],
            f"{self.game_nb_online_players}",
            pygame.Rect((int(1.3 * (s[0])), step), (55, 35)),
            self.ui_manager,
            container=self.online_panel)
        self.player_type_label = UILabel(pygame.rect.Rect((0, 0), s),
                                         "Player type",
                                         manager=self.ui_manager,
                                         container=self.online_panel)
        self.player_type_drop = UIDropDownMenu(["server", "client", "offline"],
                                               f"{self.player_type}",
                                               pygame.Rect(
                                                   (int(0.17 * s[0]), step),
                                                   (100, 35)),
                                               self.ui_manager,
                                               container=self.online_panel)
        self.host_address_label = UILabel(pygame.rect.Rect((s[0], 0), s),
                                          "Host address",
                                          manager=self.ui_manager,
                                          container=self.online_panel)
        self.host_address_entry = UITextEntryLine(pygame.Rect((s[0], step),
                                                              (150, 35)),
                                                  self.ui_manager,
                                                  container=self.online_panel)
        self.host_address_entry.set_text(self.host_address)
        if self.player_type != "client":
            # self.host_address_label.is_enabled = False
            # self.host_address_entry.is_enabled = False

            self.game_level_drop.show()
            self.game_level_label.show()
            self.nb_players_drop.show()
            self.nb_players_label.show()
            self.nb_p_c_players_drop.show()
            self.nb_p_c_label.show()
            self.survival_drop.show()
            self.survival_label.show()

            self.host_address_entry.hide()
            self.host_address_label.hide()
        else:
            # self.host_address_label.is_enabled = True
            # self.host_address_entry.is_enabled = True

            self.game_level_drop.hide()
            self.game_level_label.hide()
            self.nb_players_drop.hide()
            self.nb_players_label.hide()
            self.nb_p_c_players_drop.hide()
            self.nb_p_c_label.hide()
            self.survival_drop.hide()
            self.survival_label.hide()

            self.host_address_label.show()
            self.host_address_entry.show()

        if self.player_type != "server":
            # self.nb_online_players_drop.is_enabled = False
            self.nb_online_players_drop.hide()
            self.nb_online_players_label.hide()
        else:
            # self.nb_online_players_drop.is_enabled = True
            self.nb_online_players_drop.show()
            self.nb_online_players_label.show()
Пример #14
0
class IntroScreen(object):
    def __init__(self):
        pygame.init()
        self.size = [INTRO_SCREEN_WIDTH, INTRO_SCREEN_HEIGHT]
        self.screen = pygame.display.set_mode(self.size)
        self.con_win = None
        self.game_level = 4
        self.game = None
        self.start_game = False
        self.game_nb_players = 4  # TODO The max number of players should be in function of the size of the desk
        self.game_nb_online_players = 1
        self.nb_p_c = 1
        # self.block_list
        self.player_name = "John"
        # self.player_name = "IA Show"
        self.player_type = "offline"
        self.host_address = "localhost"
        self.survival_mode = True
        self.all_sprites_list = pygame.sprite.Group()
        self.block_list = pygame.sprite.Group()
        self.clicked = False
        self.ui_manager = pygame_gui.UIManager(
            (INTRO_SCREEN_WIDTH, INTRO_SCREEN_HEIGHT))
        self.ui_manager.preload_fonts([{
            'name': 'fira_code',
            'point_size': 10,
            'style': 'bold'
        }, {
            'name': 'fira_code',
            'point_size': 10,
            'style': 'regular'
        }, {
            'name': 'fira_code',
            'point_size': 10,
            'style': 'italic'
        }, {
            'name': 'fira_code',
            'point_size': 14,
            'style': 'italic'
        }, {
            'name': 'fira_code',
            'point_size': 14,
            'style': 'bold'
        }, {
            'name': 'fira_code',
            'point_size': 14,
            'style': 'bold_italic'
        }])
        step = 40
        s = [150, 35]
        self.name_label = UILabel(pygame.rect.Rect((0, step), s),
                                  "Name",
                                  manager=self.ui_manager)
        self.name_value = UITextEntryLine(
            pygame.Rect((self.name_label.relative_rect.width,
                         self.name_label.relative_rect.y), (200, -1)),
            self.ui_manager)
        self.name_value.set_text(self.player_name)
        # The level
        self.game_level_label = UILabel(pygame.rect.Rect((0, step * 2), s),
                                        "Level",
                                        manager=self.ui_manager)
        self.game_level_drop = UIDropDownMenu(
            [str(i) for i in range(1, 5, 1)], f"{self.game_level}",
            pygame.rect.Rect(((s[0] - step) // 2, step * 3),
                             (50, 35)), self.ui_manager)
        self.nb_players_label = UILabel(pygame.rect.Rect(
            (s[0], self.game_level_label.relative_rect.y), s),
                                        "NB players",
                                        manager=self.ui_manager)
        self.nb_players_drop = UIDropDownMenu([str(i) for i in range(2, 7, 1)],
                                              f"{self.game_nb_players}",
                                              pygame.Rect(
                                                  (int(1.3 * s[0]), step * 3),
                                                  (50, 35)), self.ui_manager)

        self.nb_p_c_label = UILabel(pygame.rect.Rect(
            (2 * s[0], self.game_level_label.relative_rect.y), s),
                                    "NB playing cards",
                                    manager=self.ui_manager)

        self.nb_p_c_players_drop = UIDropDownMenu(
            [str(i) for i in range(1, 5, 1)], f"{self.nb_p_c}",
            pygame.Rect((int(2.3 * s[0]), step * 3),
                        (50, 35)), self.ui_manager)
        self.survival_label = UILabel(pygame.rect.Rect(
            (3 * s[0], self.game_level_label.relative_rect.y), s),
                                      "Survival mode",
                                      manager=self.ui_manager)

        self.survival_drop = UIDropDownMenu(
            ["yes", "no"], f"{'yes' if self.survival_mode else 'no'}",
            pygame.Rect((int(3.3 * s[0]), step * 3),
                        (60, 35)), self.ui_manager)

        self.start_game_btn = UIButton(
            pygame.Rect((INTRO_SCREEN_WIDTH - 200, INTRO_SCREEN_HEIGHT - 50),
                        (100, 40)), 'START', self.ui_manager)
        self.resume_game_btn = UIButton(
            pygame.Rect(
                (INTRO_SCREEN_WIDTH // 2 - 50, INTRO_SCREEN_HEIGHT - 50),
                (100, 40)), 'RESUME', self.ui_manager)
        self.quit_game_btn = UIButton(
            pygame.Rect((100, INTRO_SCREEN_HEIGHT - 50), (100, 40)), 'QUIT',
            self.ui_manager)
        UILabel(pygame.rect.Rect((10, int(step * 6.5 - s[1])), s),
                "On-line Settings",
                manager=self.ui_manager)
        self.online_panel = UIPanel(pygame.rect.Rect(
            (10, int(step * 6.5)), (INTRO_SCREEN_WIDTH - 20, step * 5)),
                                    starting_layer_height=4,
                                    manager=self.ui_manager)

        self.nb_online_players_label = UILabel(pygame.rect.Rect((s[0], 0), s),
                                               "Online players",
                                               manager=self.ui_manager,
                                               container=self.online_panel)

        self.nb_online_players_drop = UIDropDownMenu(
            [str(i) for i in range(1, 6, 1)],
            f"{self.game_nb_online_players}",
            pygame.Rect((int(1.3 * (s[0])), step), (55, 35)),
            self.ui_manager,
            container=self.online_panel)
        self.player_type_label = UILabel(pygame.rect.Rect((0, 0), s),
                                         "Player type",
                                         manager=self.ui_manager,
                                         container=self.online_panel)
        self.player_type_drop = UIDropDownMenu(["server", "client", "offline"],
                                               f"{self.player_type}",
                                               pygame.Rect(
                                                   (int(0.17 * s[0]), step),
                                                   (100, 35)),
                                               self.ui_manager,
                                               container=self.online_panel)
        self.host_address_label = UILabel(pygame.rect.Rect((s[0], 0), s),
                                          "Host address",
                                          manager=self.ui_manager,
                                          container=self.online_panel)
        self.host_address_entry = UITextEntryLine(pygame.Rect((s[0], step),
                                                              (150, 35)),
                                                  self.ui_manager,
                                                  container=self.online_panel)
        self.host_address_entry.set_text(self.host_address)
        if self.player_type != "client":
            # self.host_address_label.is_enabled = False
            # self.host_address_entry.is_enabled = False

            self.game_level_drop.show()
            self.game_level_label.show()
            self.nb_players_drop.show()
            self.nb_players_label.show()
            self.nb_p_c_players_drop.show()
            self.nb_p_c_label.show()
            self.survival_drop.show()
            self.survival_label.show()

            self.host_address_entry.hide()
            self.host_address_label.hide()
        else:
            # self.host_address_label.is_enabled = True
            # self.host_address_entry.is_enabled = True

            self.game_level_drop.hide()
            self.game_level_label.hide()
            self.nb_players_drop.hide()
            self.nb_players_label.hide()
            self.nb_p_c_players_drop.hide()
            self.nb_p_c_label.hide()
            self.survival_drop.hide()
            self.survival_label.hide()

            self.host_address_label.show()
            self.host_address_entry.show()

        if self.player_type != "server":
            # self.nb_online_players_drop.is_enabled = False
            self.nb_online_players_drop.hide()
            self.nb_online_players_label.hide()
        else:
            # self.nb_online_players_drop.is_enabled = True
            self.nb_online_players_drop.show()
            self.nb_online_players_label.show()

    def run_game(self):
        done = self.game.run()
        if not done:
            pygame.mouse.set_visible(True)
            self.screen = pygame.display.set_mode(self.size)
        else:
            return True

    def process_events(self):
        """ Process all of the events. Return a "True" if we need
            to close the window. """

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                return True
            if event.type == pygame.MOUSEBUTTONDOWN:
                self.clicked = True
            if event.type == pygame.USEREVENT:
                if event.user_type == pygame_gui.UI_BUTTON_PRESSED or self.start_game:
                    if event.ui_element == self.resume_game_btn and self.game:
                        done = self.game.resume()
                        if not done:
                            pygame.mouse.set_visible(True)
                            self.screen = pygame.display.set_mode(self.size)
                        else:
                            return True

                    if event.ui_element == self.start_game_btn or self.start_game:
                        if self.player_type == "client":
                            _type = self.host_address
                        elif self.player_type == "server":
                            _type = self.player_type
                        else:
                            _type = None
                        g_args = {
                            "player_name": self.player_name,
                            "nb_players": self.game_nb_players,
                            "nb_online": self.game_nb_online_players,
                            "level": self.game_level,
                            "nb_playing_cards": self.nb_p_c,
                            "_type": _type,
                            "survival_mode": self.survival_mode,
                        }
                        if self.player_type == "server":
                            if self.con_win is None or not self.con_win.alive(
                            ):
                                self.con_win = ConnectionWindow.ConnectionWindow(
                                    g_args, self,
                                    pygame.rect.Rect(
                                        (INTRO_SCREEN_WIDTH // 4, 0),
                                        (INTRO_SCREEN_WIDTH // 2,
                                         DESK_HEIGHT)), self.ui_manager)
                        else:
                            self.game = CardsGame.CardsGame(**g_args)

                        if self.game:
                            done = self.game.run()
                            if not done:
                                pygame.mouse.set_visible(True)
                                self.screen = pygame.display.set_mode(
                                    self.size)
                            else:
                                return True

                    if event.ui_element == self.quit_game_btn:
                        return True
                if event.user_type == pygame_gui.UI_TEXT_ENTRY_CHANGED:
                    if event.ui_element == self.name_value:
                        self.player_name = event.text
                    if event.ui_element == self.host_address_entry:
                        self.host_address = event.text
                if event.user_type == pygame_gui.UI_DROP_DOWN_MENU_CHANGED:
                    if event.ui_element == self.survival_drop:
                        self.survival_mode = self.survival_drop.selected_option == "yes"
                    if event.ui_element == self.game_level_drop:
                        self.game_level = int(
                            self.game_level_drop.selected_option)
                    if event.ui_element == self.nb_players_drop:
                        self.game_nb_players = int(
                            self.nb_players_drop.selected_option)
                    if event.ui_element == self.nb_online_players_drop:
                        self.game_nb_online_players = int(
                            self.nb_online_players_drop.selected_option)
                    if event.ui_element == self.nb_p_c_players_drop:
                        self.nb_p_c = int(
                            self.nb_p_c_players_drop.selected_option)
                    if event.ui_element == self.player_type_drop:
                        self.player_type = self.player_type_drop.selected_option

                        if self.player_type != "client":
                            # self.host_address_label.is_enabled = False
                            # self.host_address_entry.is_enabled = False

                            self.game_level_drop.show()
                            self.game_level_label.show()
                            self.nb_players_drop.show()
                            self.nb_players_label.show()
                            self.nb_p_c_players_drop.show()
                            self.nb_p_c_label.show()
                            self.survival_drop.show()
                            self.survival_label.show()

                            self.host_address_entry.hide()
                            self.host_address_label.hide()
                        else:
                            # self.host_address_label.is_enabled = True
                            # self.host_address_entry.is_enabled = True

                            self.game_level_drop.hide()
                            self.game_level_label.hide()
                            self.nb_players_drop.hide()
                            self.nb_players_label.hide()
                            self.nb_p_c_players_drop.hide()
                            self.nb_p_c_label.hide()
                            self.survival_drop.hide()
                            self.survival_label.hide()

                            self.host_address_label.show()
                            self.host_address_entry.show()

                        if self.player_type != "server":
                            # self.nb_online_players_drop.is_enabled = False
                            self.nb_online_players_drop.hide()
                            self.nb_online_players_label.hide()
                        else:
                            # self.nb_online_players_drop.is_enabled = True
                            self.nb_online_players_drop.show()
                            self.nb_online_players_label.show()
            self.ui_manager.process_events(event)

        return False

    def run_logic(self):
        """
        This method is run each time through the frame. It
        updates positions and checks for collisions.
        """
        # Move all the sprites
        self.all_sprites_list.update()
        self.block_list.update()
        if self.clicked:
            col = (randint(0, 255), randint(0, 255), randint(0, 255))
            block = Block(col)
            pos = pygame.mouse.get_pos()
            x = pos[0]
            y = pos[1]
            block.rect.x = x
            block.rect.y = y
            self.block_list.add(block)
            self.all_sprites_list.add(block)
            if len(self.block_list) > 20:
                self.block_list.sprites()[0].kill()
        self.clicked = False

    def display_frame(self, time_delta, screen):
        """ Display everything to the screen for the game. """
        screen.fill(self.ui_manager.get_theme().get_colour('dark_bg'))
        if not self.game:
            self.resume_game_btn.disable()
        elif not self.resume_game_btn.is_enabled:
            self.resume_game_btn.enable()
        # if self.player_type != "server":
        #     self.host_address_label.ui_manager = None
        #     self.host_address_label.ui_container = None
        #     self.host_address_entry.ui_manager = None
        #     self.host_address_entry.ui_container = None

        self.ui_manager.update(time_delta)
        self.ui_manager.draw_ui(screen)

        self.all_sprites_list.draw(screen)
        pygame.display.flip()

    def run(self):
        """ Main program function. """
        # Initialize Pygame and set up the window
        pygame.display.set_caption("Setup")

        # Create our objects and set the data
        done = False
        clock = pygame.time.Clock()

        # intro_game = IntroScreen()

        # Main game loop
        while not done:
            time_delta = clock.tick() / 1000.0
            # Process events (keystrokes, mouse clicks, etc)
            done = self.process_events()

            if not done:
                # Update object positions, check for collisions
                # self.run_logic()
                # Draw the current frame
                self.display_frame(time_delta, self.screen)

            # Pause for the next frame
            # clock.tick(60)

        # Close window and exit
        pygame.quit()