예제 #1
0
    def __init__(self):

        self.manager = UIManager((800, 600), 'themes/signup.json')

        self.title = UILabel(relative_rect=pygame.Rect(400 - 100, 50, 200, 50),
                             text='Inscription',
                             manager=self.manager)

        self.labelPseudo = UILabel(relative_rect=pygame.Rect(400 - 210, 142, 100, 50),
                                   text='Pseudo',
                                   manager=self.manager)

        self.pseudo = UITextEntryLine(relative_rect=pygame.Rect(400 - 100, 150, 200, 50),
                                      manager=self.manager)

        self.labelPassword = UILabel(relative_rect=pygame.Rect(400 - 210, 222, 100, 50),
                                     text='Mot de passe',
                                     manager=self.manager)

        self.password = UITextEntryLine(relative_rect=pygame.Rect(400 - 100, 230, 200, 50),
                                        manager=self.manager)

        self.buttonSignup = UIButton(relative_rect=pygame.Rect(400 - 100, 320, 200, 50),
                                     text="S'inscrire",
                                     manager=self.manager)

        self.buttonLogin = UIButton(relative_rect=pygame.Rect(400 - 100, 400, 200, 50),
                                    text="Déja un compte ?",
                                    manager=self.manager)
예제 #2
0
    def __init__(self):

        self.manager = UIManager((800, 600), 'themes/theme.json')

        self.title = UILabel(relative_rect=pygame.Rect(350, 50, 100, 50),
                             text='Connexion',
                             manager=self.manager)

        self.labelPseudo = UILabel(relative_rect=pygame.Rect(
            400 - 210, 142, 100, 50),
                                   text='Pseudo',
                                   manager=self.manager)

        self.pseudo = UITextEntryLine(relative_rect=pygame.Rect(
            400 - 100, 150, 200, 50),
                                      manager=self.manager)

        self.labelPassword = UILabel(relative_rect=pygame.Rect(
            400 - 210, 222, 100, 50),
                                     text='Mot de passe',
                                     manager=self.manager)

        self.password = UITextEntryLine(relative_rect=pygame.Rect(
            400 - 100, 230, 200, 50),
                                        manager=self.manager)

        self.buttonLogin = UIButton(relative_rect=pygame.Rect(
            400 - 100, 320, 200, 50),
                                    text='Se connecter',
                                    manager=self.manager)

        self.buttonSignup = UIButton(relative_rect=pygame.Rect(
            400 - 100, 400, 200, 50),
                                     text='Pas de compte ?',
                                     manager=self.manager)
예제 #3
0
파일: speak.py 프로젝트: cclauss/snakeware
    def __init__(self, pos, manager):
        super().__init__(
            pygame.Rect(pos, (400,128)),
            manager=manager,
            window_display_title='speaknspell',
            object_id='#speaknspell'
        )

        self.label = UILabel(
            relative_rect=pygame.Rect(-20, 10, 400, 20),
            text='',
            manager=manager,
            container=self
        )

        self.input = UITextEntryLine(
            relative_rect=pygame.Rect(0, 40, 368, 30),
            manager=manager,
            container=self
        )

        self.engine = pyttsx3.init()
        self.engine.setProperty('rate', 150)
        self.speakthrd = None

        self.speak('Hello, thank you for using snakeware!')
예제 #4
0
    def __init__(
        self,
        size: tuple[int, int],
        manager: IUIManagerInterface,
        udp: UDP_P2P,
        username: str,
    ) -> None:
        # region Docstring
        """
        Creates a `Chat` object

        ### Arguments
            `size {(int, int)}`:
                `summary`: the size of the chat window
            `manager {UIManager}`:
                `summary`: the UIManager that manages this element.
            `udp {UDP_P2P}`:
                `summary`: the udp object
            `username {str}`:
                `summary`: the username of this host
        """
        # endregion
        super().__init__(relative_rect=Rect((Game.SIZE[0], 0), size),
                         manager=manager)

        # region Element creation

        self.textbox = UITextBox(
            html_text="",
            relative_rect=Rect((0, 0), (size[0], size[1] - 25)),
            manager=manager,
            container=self,
        )

        self.entryline = UITextEntryLine(
            relative_rect=Rect((0, size[1] - 28), (size[0] - 50, 20)),
            manager=manager,
            container=self,
        )
        self.entryline.set_text_length_limit(100)

        self.enterbtn = UIButton(
            text="Enter",
            relative_rect=Rect((size[0] - 50, size[1] - 28), (50, 30)),
            manager=manager,
            container=self,
        )

        # endregion

        self.record = ""
        self.size = size
        self.udp = udp
        self.username = username
예제 #5
0
    def __init__(self):

        self.manager = UIManager((800, 600), 'themes/createParty.json')

        self.labelParty = UILabel(relative_rect=pygame.Rect(10, 92, 150, 50),
                                  text='Nom de la partie',
                                  manager=self.manager)

        self.party = UITextEntryLine(relative_rect=pygame.Rect(
            330, 100, 150, 50),
                                     manager=self.manager)

        self.buttonCreate = UIButton(relative_rect=pygame.Rect(
            330, 200, 150, 50),
                                     text='Creer une partie',
                                     manager=self.manager)
예제 #6
0
    def __init__(self, pos, manager):
        super().__init__(
            pygame.Rect(pos, (400, 200)),
            manager=manager,
            window_display_title="speaknspell",
            object_id="#speaknspell",
            resizable=True,
        )

        self.box = UITextBox(
            "",
            relative_rect=pygame.Rect(0, 0, 368, 100),
            manager=manager,
            container=self,
            anchors={
                "left": "left",
                "right": "right",
                "top": "top",
                "bottom": "bottom",
            },
        )

        self.input = UITextEntryLine(
            relative_rect=pygame.Rect(0, -35, 368, 30),
            manager=manager,
            container=self,
            anchors={
                "left": "left",
                "right": "right",
                "top": "bottom",
                "bottom": "bottom",
            },
        )

        self.engine = pyttsx3.init()
        self.engine.setProperty("rate", 150)
        self.speakthrd = None

        self.speak("Hello, thank you for using snakeware!")
        self.input.focus()

        # history attributes
        self.histsize = 100
        self.histindex = -1
        self.history = ["Hello, thank you for using snakeware!"]
        self.cached_command = ""
예제 #7
0
 def __init__(self, pos, manager):
     super().__init__(
         pygame.Rect(pos, (400, 128)),
         manager=manager,
         window_display_title="speaker",
         object_id="#speaker",
     )
     self.label = UILabel(
         relative_rect=pygame.Rect(-20, 10, 400, 20),
         text="",
         manager=manager,
         container=self,
     )
     self.input = UITextEntryLine(relative_rect=pygame.Rect(0, 40, 368, 30),
                                  manager=manager,
                                  container=self)
     self.engine = pyttsx3.init()
     self.engine.setProperty("rate", 150)
     self.speakthrd = None
예제 #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)

        if self.start_up == True:
            self.image = UIImage(pygame.Rect((0, 0), self.options.resolution), title_screen_image, self.ui_manager)
        elif self.enter_mines == True:
            self.image = UIImage(pygame.Rect((0, 0), self.options.resolution), mines_image, self.ui_manager)
        elif self.enter_busstop == True:
            self.image = UIImage(pygame.Rect((0, 0), self.options.resolution), busstop_image, self.ui_manager)
        elif self.enter_uptown == True:
            self.image = UIImage(pygame.Rect((0, 0), self.options.resolution), uptown_image, self.ui_manager)
        else: 
            self.background_surface.fill(self.ui_manager.get_theme().get_colour('dark_bg'))
            self.background_surface.blit(pygame.image.load("media/images/background.png"), (0, 0))
            
            global response_history
            response = response_history
            response_history = response
            self.text_entry = UITextEntryLine(pygame.Rect((50, 550), (700, 50)), self.ui_manager, object_id = "#text_entry")
            self.text_block = UITextBox(response, pygame.Rect((50, 25), (700, 500)), self.ui_manager, object_id = "#text_block")
예제 #9
0
    def __init__(self,
                 rect: pygame.Rect,
                 manager: IUIManagerInterface,
                 window_title: str = 'File Dialog',
                 initial_file_path: Union[str, None] = None,
                 object_id: Union[ObjectID,
                                  str] = ObjectID('#file_dialog', None),
                 allow_existing_files_only: bool = False,
                 allow_picking_directories: bool = False,
                 visible: int = 1):

        super().__init__(rect,
                         manager,
                         window_display_title=window_title,
                         object_id=object_id,
                         resizable=True,
                         visible=visible)

        minimum_dimensions = (260, 300)
        if rect.width < minimum_dimensions[
                0] or rect.height < minimum_dimensions[1]:
            warn_string = ("Initial size: " + str(rect.size) +
                           " is less than minimum dimensions: " +
                           str(minimum_dimensions))
            warnings.warn(warn_string, UserWarning)
        self.set_minimum_dimensions(minimum_dimensions)

        self.allow_existing_files_only = allow_existing_files_only
        self.allow_picking_directories = allow_picking_directories

        self.delete_confirmation_dialog = None  # type: Union[UIConfirmationDialog, None]
        self.current_file_path = None  # type: Union[Path, None]

        if initial_file_path is not None:
            pathed_initial_file_path = Path(initial_file_path)
            if pathed_initial_file_path.exists(
            ) and not pathed_initial_file_path.is_file():
                self.current_directory_path = str(
                    pathed_initial_file_path.resolve())
                if self.allow_picking_directories:
                    self.current_file_path = self.current_directory_path
            elif pathed_initial_file_path.exists(
            ) and pathed_initial_file_path.is_file():
                self.current_file_path = pathed_initial_file_path.resolve()
                self.current_directory_path = str(
                    pathed_initial_file_path.parent.resolve())
            elif pathed_initial_file_path.parent.exists():
                self.current_directory_path = str(
                    pathed_initial_file_path.parent.resolve())
                self.current_file_path = (
                    Path(initial_file_path).parent.resolve() /
                    Path(initial_file_path).name)
        else:
            self.current_directory_path = str(Path('.').resolve())

        self.last_valid_directory_path = self.current_directory_path

        self.current_file_list = None  # type: Union[List[str], None]
        self.update_current_file_list()

        self.ok_button = UIButton(relative_rect=pygame.Rect(
            -220, -40, 100, 30),
                                  text='OK',
                                  manager=self.ui_manager,
                                  container=self,
                                  object_id='#ok_button',
                                  anchors={
                                      'left': 'right',
                                      'right': 'right',
                                      'top': 'bottom',
                                      'bottom': 'bottom'
                                  })
        if not self._validate_file_path(self.current_file_path):
            self.ok_button.disable()

        self.cancel_button = UIButton(relative_rect=pygame.Rect(
            -110, -40, 100, 30),
                                      text='Cancel',
                                      manager=self.ui_manager,
                                      container=self,
                                      object_id='#cancel_button',
                                      anchors={
                                          'left': 'right',
                                          'right': 'right',
                                          'top': 'bottom',
                                          'bottom': 'bottom'
                                      })

        self.home_button = UIButton(relative_rect=pygame.Rect(10, 10, 20, 20),
                                    text='⌂',
                                    tool_tip_text='Home Directory',
                                    manager=self.ui_manager,
                                    container=self,
                                    object_id='#home_icon_button',
                                    anchors={
                                        'left': 'left',
                                        'right': 'left',
                                        'top': 'top',
                                        'bottom': 'top'
                                    })

        self.delete_button = UIButton(relative_rect=pygame.Rect(
            32, 10, 20, 20),
                                      text='⌧',
                                      tool_tip_text='Delete',
                                      manager=self.ui_manager,
                                      container=self,
                                      object_id='#delete_icon_button',
                                      anchors={
                                          'left': 'left',
                                          'right': 'left',
                                          'top': 'top',
                                          'bottom': 'top'
                                      })
        if not self._validate_path_exists_and_of_allowed_type(
                self.current_file_path, allow_directories=False):
            self.delete_button.disable()

        self.parent_directory_button = UIButton(
            relative_rect=pygame.Rect(54, 10, 20, 20),
            text='↑',
            tool_tip_text='Parent Directory',
            manager=self.ui_manager,
            container=self,
            object_id='#parent_icon_button',
            anchors={
                'left': 'left',
                'right': 'left',
                'top': 'top',
                'bottom': 'top'
            })

        self.refresh_button = UIButton(relative_rect=pygame.Rect(
            76, 10, 20, 20),
                                       text='⇪',
                                       tool_tip_text='Refresh Directory',
                                       manager=self.ui_manager,
                                       container=self,
                                       object_id='#refresh_icon_button',
                                       anchors={
                                           'left': 'left',
                                           'right': 'left',
                                           'top': 'top',
                                           'bottom': 'top'
                                       })

        text_line_rect = pygame.Rect(10, 40,
                                     self.get_container().get_size()[0] - 20,
                                     25)
        self.file_path_text_line = UITextEntryLine(
            relative_rect=text_line_rect,
            manager=self.ui_manager,
            container=self,
            object_id='#file_path_text_line',
            anchors={
                'left': 'left',
                'right': 'right',
                'top': 'top',
                'bottom': 'top'
            })
        if self.current_file_path is not None:
            self.file_path_text_line.set_text(str(self.current_file_path))
            self._highlight_file_name_for_editing()
        else:
            self.file_path_text_line.set_text(str(self.current_directory_path))

        file_selection_rect = pygame.Rect(
            10, 80,
            self.get_container().get_size()[0] - 20,
            self.get_container().get_size()[1] - 130)
        self.file_selection_list = UISelectionList(
            relative_rect=file_selection_rect,
            item_list=self.current_file_list,
            manager=self.ui_manager,
            container=self,
            object_id='#file_display_list',
            anchors={
                'left': 'left',
                'right': 'right',
                'top': 'top',
                'bottom': 'bottom'
            })
    def __init__(self,
                 relative_rect: pygame.Rect,
                 manager: IUIManagerInterface,
                 name: str,
                 channel_index: int,
                 value_range: Tuple[int, int],
                 initial_value: int,
                 container: Union[IContainerLikeInterface, None] = None,
                 parent_element: UIElement = None,
                 object_id: Union[ObjectID, str, None] = None,
                 anchors: Dict[str, str] = None,
                 visible: int = 1):

        super().__init__(relative_rect,
                         manager,
                         container,
                         starting_height=1,
                         layer_thickness=1,
                         anchors=anchors,
                         visible=visible)

        self._create_valid_ids(container=container,
                               parent_element=parent_element,
                               object_id=object_id,
                               element_id='colour_channel_editor')

        self.range = value_range
        self.current_value = initial_value
        self.channel_index = channel_index

        self.set_image(self.ui_manager.get_universal_empty_surface())

        self.element_container = UIContainer(relative_rect,
                                             self.ui_manager,
                                             container=self.ui_container,
                                             parent_element=self,
                                             anchors=anchors,
                                             visible=self.visible)

        default_sizes = {
            'space_between': 3,
            'label_width': 17,
            'entry_width': 43,
            'line_height': 29,
            'slider_height': 21,
            'slider_vert_space': 4
        }

        self.label = UILabel(pygame.Rect(0, 0, -1,
                                         default_sizes['line_height']),
                             text=name,
                             manager=self.ui_manager,
                             container=self.element_container,
                             parent_element=self,
                             anchors={
                                 'left': 'left',
                                 'right': 'left',
                                 'top': 'top',
                                 'bottom': 'bottom'
                             })

        self.entry = UITextEntryLine(pygame.Rect(-default_sizes['entry_width'],
                                                 0,
                                                 default_sizes['entry_width'],
                                                 default_sizes['line_height']),
                                     manager=self.ui_manager,
                                     container=self.element_container,
                                     parent_element=self,
                                     anchors={
                                         'left': 'right',
                                         'right': 'right',
                                         'top': 'top',
                                         'bottom': 'bottom'
                                     })

        slider_width = (self.entry.rect.left - self.label.rect.right) - (
            2 * default_sizes['space_between'])

        self.slider = UIHorizontalSlider(pygame.Rect(
            (self.label.get_abs_rect().width + default_sizes['space_between']),
            default_sizes['slider_vert_space'], slider_width,
            default_sizes['slider_height']),
                                         start_value=initial_value,
                                         value_range=value_range,
                                         manager=self.ui_manager,
                                         container=self.element_container,
                                         parent_element=self,
                                         anchors={
                                             'left': 'left',
                                             'right': 'right',
                                             'top': 'top',
                                             'bottom': 'bottom'
                                         })

        self.entry.set_allowed_characters('numbers')
        self.entry.set_text(str(initial_value))
        self.entry.set_text_length_limit(3)
예제 #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'])
예제 #12
0
    def __init__(self,
                 rect: pygame.Rect,
                 manager: IUIManagerInterface,
                 window_title: str = 'File Dialog',
                 initial_file_path: Union[str, None] = None,
                 object_id: str = '#file_dialog'):

        super().__init__(rect,
                         manager,
                         window_display_title=window_title,
                         object_id=object_id,
                         resizable=True)

        minimum_dimensions = (260, 300)
        if rect.width < minimum_dimensions[
                0] or rect.height < minimum_dimensions[1]:
            warn_string = ("Initial size: " + str(rect.size) +
                           " is less than minimum dimensions: " +
                           str(minimum_dimensions))
            warnings.warn(warn_string, UserWarning)
        self.set_minimum_dimensions(minimum_dimensions)

        self.delete_confirmation_dialog = None  # type: Union[None, UIConfirmationDialog]

        if initial_file_path is not None:
            if exists(initial_file_path):
                self.current_directory_path = abspath(initial_file_path)
        else:
            self.current_directory_path = abspath('.')

        self.last_valid_path = None

        self.selected_file_path = None

        self.current_file_list = None  # type: Union[None, List[str]]
        self.update_current_file_list()

        self.ok_button = UIButton(relative_rect=pygame.Rect(
            -220, -40, 100, 30),
                                  text='OK',
                                  manager=self.ui_manager,
                                  container=self,
                                  object_id='#ok_button',
                                  anchors={
                                      'left': 'right',
                                      'right': 'right',
                                      'top': 'bottom',
                                      'bottom': 'bottom'
                                  })
        self.ok_button.disable()

        self.cancel_button = UIButton(relative_rect=pygame.Rect(
            -110, -40, 100, 30),
                                      text='Cancel',
                                      manager=self.ui_manager,
                                      container=self,
                                      object_id='#cancel_button',
                                      anchors={
                                          'left': 'right',
                                          'right': 'right',
                                          'top': 'bottom',
                                          'bottom': 'bottom'
                                      })

        self.home_button = UIButton(relative_rect=pygame.Rect(10, 10, 20, 20),
                                    text='⌂',
                                    tool_tip_text='Home Directory',
                                    manager=self.ui_manager,
                                    container=self,
                                    object_id='#home_icon_button',
                                    anchors={
                                        'left': 'left',
                                        'right': 'left',
                                        'top': 'top',
                                        'bottom': 'top'
                                    })

        self.delete_button = UIButton(relative_rect=pygame.Rect(
            32, 10, 20, 20),
                                      text='⌧',
                                      tool_tip_text='Delete',
                                      manager=self.ui_manager,
                                      container=self,
                                      object_id='#delete_icon_button',
                                      anchors={
                                          'left': 'left',
                                          'right': 'left',
                                          'top': 'top',
                                          'bottom': 'top'
                                      })
        self.delete_button.disable()

        self.parent_directory_button = UIButton(
            relative_rect=pygame.Rect(54, 10, 20, 20),
            text='↑',
            tool_tip_text='Parent Directory',
            manager=self.ui_manager,
            container=self,
            object_id='#parent_icon_button',
            anchors={
                'left': 'left',
                'right': 'left',
                'top': 'top',
                'bottom': 'top'
            })

        self.refresh_button = UIButton(relative_rect=pygame.Rect(
            76, 10, 20, 20),
                                       text='⇪',
                                       tool_tip_text='Refresh Directory',
                                       manager=self.ui_manager,
                                       container=self,
                                       object_id='#refresh_icon_button',
                                       anchors={
                                           'left': 'left',
                                           'right': 'left',
                                           'top': 'top',
                                           'bottom': 'top'
                                       })

        text_line_rect = pygame.Rect(
            10, 40,
            self.get_container().relative_rect.width - 20, 25)
        self.file_path_text_line = UITextEntryLine(
            relative_rect=text_line_rect,
            manager=self.ui_manager,
            container=self,
            object_id='#file_path_text_line',
            anchors={
                'left': 'left',
                'right': 'right',
                'top': 'top',
                'bottom': 'top'
            })
        self.file_path_text_line.set_text(self.current_directory_path)

        file_selection_rect = pygame.Rect(
            10, 80,
            self.get_container().relative_rect.width - 20,
            self.get_container().relative_rect.height - 130)
        self.file_selection_list = UISelectionList(
            relative_rect=file_selection_rect,
            item_list=self.current_file_list,
            manager=self.ui_manager,
            container=self,
            object_id='#file_display_list',
            anchors={
                'left': 'left',
                'right': 'right',
                'top': 'top',
                'bottom': 'bottom'
            })
예제 #13
0
    def __init__(self,
                 rect: pygame.Rect,
                 manager: IUIManagerInterface,
                 window_title: str = 'pygame-gui.console_title_bar',
                 object_id: Union[ObjectID,
                                  str] = ObjectID('#console_window', None),
                 visible: int = 1,
                 preload_bold_log_font: bool = True):
        super().__init__(rect,
                         manager,
                         window_display_title=window_title,
                         object_id=object_id,
                         resizable=True,
                         visible=visible)

        self.default_log_prefix = '> '
        self.log_prefix = self.default_log_prefix

        self.should_logged_commands_escape_html = True

        self.logged_commands_above = []
        self.current_logged_command = None
        self.logged_commands_below = []

        self.command_entry = UITextEntryLine(relative_rect=pygame.rect.Rect(
            (2, -32), (self.get_container().get_size()[0] - 4, 30)),
                                             manager=self.ui_manager,
                                             container=self,
                                             object_id='#command_entry',
                                             anchors={
                                                 'left': 'left',
                                                 'right': 'right',
                                                 'top': 'bottom',
                                                 'bottom': 'bottom'
                                             })

        self.log = UITextBox(html_text="",
                             relative_rect=pygame.rect.Rect(
                                 (2, 2),
                                 (self.get_container().get_size()[0] - 4,
                                  self.get_container().get_size()[1] - 36)),
                             manager=manager,
                             container=self,
                             object_id='#log',
                             anchors={
                                 'left': 'left',
                                 'right': 'right',
                                 'top': 'top',
                                 'bottom': 'bottom'
                             })

        if preload_bold_log_font:
            # Would be better to load this font during UIManager setup, but this is probably
            # second best place. We can't know if someone will use the console window in advance
            # but if they do and use the default bold output setup for it, it would be a good idea
            # to load the bold font at th the same time th other UI stuff is loaded.

            log_font_info = self.ui_theme.get_font_info(
                self.log.combined_element_ids)
            font_dict = self.ui_manager.get_theme().get_font_dictionary()
            bold_font_id = font_dict.create_font_id(log_font_info['size'],
                                                    log_font_info['name'],
                                                    bold=True,
                                                    italic=False)
            if not font_dict.check_font_preloaded(bold_font_id):
                font_dict.preload_font(log_font_info['size'],
                                       log_font_info['name'],
                                       bold=True)
예제 #14
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)
예제 #15
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)
예제 #16
0
    def user_interface(self):
        WINDOW_WIDTH = 300
        WINDOW_HEIGHT = 200

        Colors = {
            'Red': (127, 0, 0),
            'Cyan': (0, 255, 255),
            'Orange': (255, 106, 0),
            'Blue': (0, 38, 255),
            'Green': (0, 153, 15),
            'Pink': (255, 0, 110),
            'Yellow': (255, 216, 0)
        }

        pygame.init()

        pygame.display.set_caption('Startup Menu')
        center = (WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2)
        window = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
        manager = pygame_gui.UIManager((WINDOW_WIDTH, WINDOW_HEIGHT),
                                       './themes/button_theme.json')
        clock = pygame.time.Clock()

        background_color = (61, 120, 180)
        background = pygame.Surface((WINDOW_WIDTH, WINDOW_HEIGHT))
        background.fill(background_color)

        # color button dimensions
        button_center = [center[0], center[1] + 50]
        button_size = [30, 30]
        padding = 5
        num_buttons = 7

        colors = list(Colors.keys())

        color_buttons = []

        for index in range(-3, 4):
            position = (int(button_center[0] + index *
                            (padding + button_size[0]) - button_size[0] / 2),
                        int(button_center[1] - padding - 75 - 3))
            pygame_gui.elements.UIButton(relative_rect=pygame.Rect(
                position, button_size),
                                         text='',
                                         manager=manager,
                                         object_id='#' + colors[index + 3])

        # button dimensions
        button_width = 240
        button_height = 40
        padding = 10

        # text box dimensions
        entry_width = 240
        entry_height = 40
        padding = 10

        position = (int(center[0] - button_width / 2),
                    int(center[1] + padding / 2 + 25))
        client_button = pygame_gui.elements.UIButton(
            relative_rect=pygame.Rect(position, (button_width, button_height)),
            text='Connect',
            manager=manager,
            object_id='#standard_button')

        position = (int(center[0] - button_width / 2),
                    int(center[1] - padding / 2 - entry_height / 2 + 25))

        ip_entry = UITextEntryLine(relative_rect=pygame.Rect(
            position, (button_width - 80, button_height)),
                                   manager=manager,
                                   object_id='#text_entry')
        ip_entry.set_text('127.0.0.1')

        position = (int(center[0] - button_width / 2 + button_width - 80 +
                        padding),
                    int(center[1] - padding / 2 - entry_height / 2 + 25))

        port_entry = UITextEntryLine(relative_rect=pygame.Rect(
            position, (80 - padding, button_height)),
                                     manager=manager,
                                     object_id='#text_entry')
        port_entry.set_text('1233')

        position = (int(center[0] - button_width / 2 + 3),
                    int(center[1] - padding / 2 - entry_height / 2 + 25 - 65 +
                        3))

        name_label = pygame_gui.elements.ui_label.UILabel(
            relative_rect=pygame.Rect(position, (50, button_height - 17)),
            text='Name:',
            manager=manager,
            object_id='#text_entry')

        position = (int(center[0] - button_width / 2 + 55 + padding),
                    int(center[1] - padding / 2 - entry_height / 2 + 25 - 65))

        name_entry = UITextEntryLine(relative_rect=pygame.Rect(
            position, (button_width - 55 - padding, button_height)),
                                     manager=manager,
                                     object_id='#text_entry')

        # update screen
        pygame.display.flip()

        running = True
        client_flag = False
        server_flag = False

        while running:
            time_delta = clock.tick(60) / 1000.0
            for event in pygame.event.get():
                # close if X is clicked
                if event.type == pygame.QUIT:
                    running = False

                # close if ESC is pressed
                if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
                    running = False

                if event.type == pygame.USEREVENT:
                    if event.user_type == pygame_gui.UI_BUTTON_PRESSED:
                        # action if client is pressed
                        if event.ui_element == client_button:
                            client_flag = True
                            # print('Client created')

                manager.process_events(event)

            manager.update(time_delta)

            window.blit(background, (0, 0))
            manager.draw_ui(window)

            pygame.display.update()

            if client_flag:
                running = False
                client_flag = False
                # self.children.append(subprocess.Popen([sys.executable, './ClientMain.py']))
                pygame.quit()
                start_instance = client(ip_entry.text, port_entry.text,
                                        name_entry.text)
예제 #17
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()