Beispiel #1
0
class TextValueLabel(object):
    def __init__(self, text_rect: pygame.rect.Rect, text, value, manager,
                 container):
        self.ui_manager = manager
        self.text_rect = text_rect
        self.container = container
        self.text = text
        self.value = value
        self.text_label = UILabel(self.text_rect,
                                  text,
                                  manager=self.ui_manager,
                                  container=self.container)
        self.value_label = UILabel(pygame.Rect(
            (self.text_rect.x, self.text_rect.y + self.text_rect.height),
            (self.text_rect.width, self.text_rect.height)),
                                   value,
                                   manager=self.ui_manager,
                                   container=self.container)

    def set_value(self, value):
        self.value = value
        self.value_label.set_text(value)

    def set_text(self, text):
        self.text = text
        self.text_label.set_text(text)
Beispiel #2
0
    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!')
Beispiel #3
0
    def __init__(self, radius, position, ui_manager, order):
        self.ui_manager = ui_manager
        self.traversal_order = order
        self.radius = radius
        self.colour = pygame.Color("#FF6464")
        self.rectangle_colour = pygame.Color("#646464")
        self.color_key = (127, 33, 33)
        self.world_position = [
            int(position[0] - self.radius),
            int(position[1] - self.radius)
        ]
        self.surface = pygame.Surface((self.radius * 2, self.radius * 2))
        self.surface.fill(self.color_key)
        self.surface.set_colorkey(self.color_key)
        pygame.draw.circle(self.surface, self.colour,
                           (self.radius, self.radius), self.radius)
        self.surface.set_alpha(100)

        self.rectangle_surface = pygame.Surface((32, 32))
        self.rectangle_surface.fill(self.color_key)
        self.rectangle_surface.set_colorkey(self.color_key)
        pygame.draw.rect(self.rectangle_surface, self.rectangle_colour,
                         pygame.Rect(0, 0, 32, 32))
        self.rectangle_surface.set_alpha(100)
        self.position = [self.world_position[0], self.world_position[1]]
        # self.id_text = fonts[6].render(str(self.traversal_order), True, pygame.Color("#FFFFFF"))

        self.id_text_label = UILabel(pygame.Rect(self.position, (32, 32)),
                                     str(self.traversal_order),
                                     manager=self.ui_manager,
                                     object_id="#small_screen_text")
Beispiel #4
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)
Beispiel #5
0
class Label(ColorElement):
    def __init__(self,
                 text,
                 layout_info,
                 container,
                 text_color=BLACK,
                 background_color=TRANSPARENT,
                 padding=None):
        super().__init__(layout_info, container, padding)
        self.text = text
        self.element = UILabel(relative_rect=self.bounds,
                               manager=self.manager,
                               text=text)
        self.text_color = text_color
        self.background_color = background_color

    def set_text(self, text):
        self.text = text
        self.element.set_text(text)

    @property
    def text_color(self):
        return self.element.text_colour

    @text_color.setter
    def text_color(self, color):
        if color is None:
            return

        self.element.text_colour = color
        self.element.rebuild()
    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, "Select Existing Game Map", self.gui,
                                                  self.ui_elements['panel'])
        # buttons
        select_rect = Rect(0, 0, 400, get_param('element_height') * 3)
        select_rect.y = scene_label_rect.bottom + get_param('element_padding')
        select_rect.centerx = panel_rect.w // 2
        self.ui_elements['map_select'] = UISelectionList(select_rect, [f"Map {n}" for n in range(20)], self.gui,
                                                         container=self.ui_elements['panel'])

        preview_rect = Rect(0, 0, 256, get_param('element_height') * 8)
        preview_rect.y = select_rect.bottom + get_param('element_padding')
        preview_rect.centerx = panel_rect.w // 2
        self.ui_elements['preview'] = UILabel(preview_rect, "PREVIEW AREA", self.gui, self.ui_elements['panel'])

        button_rect = Rect(0, 0, 200, get_param('element_height'))
        button_rect.y = preview_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'])
        button_rect.centerx = (panel_rect.w // 2) + 100
        self.ui_elements['btn_next'] = UIButton(button_rect, "Next", self.gui, self.ui_elements['panel'])
        self.ui_elements['btn_next'].disable()
Beispiel #7
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)
Beispiel #8
0
class Speaker(pygame_gui.elements.UIWindow):
    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

    def process_event(self, event):
        super().process_event(event)
        if event.type == pygame.USEREVENT and event.ui_element == self.input and event.user_type == pygame_gui.UI_TEXT_ENTRY_FINISHED and (
                self.speakthrd is None or
                not self.speakthrd.is_alive()) and self.input.get_text != "":
            self.engine.say(self.input.get_text)
            self.speakthrd = threading.Thread(target=self.engine.runAndWait,
                                              args=())
            self.speakthrd.start()
            self.label.set_text(self.input.get_text)
            self.input.set_text("")
    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)
Beispiel #10
0
    def __init__(self):

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

        self.title = UILabel(relative_rect=pygame.Rect(400 - 100, 20, 200, 50),
                             text='Charger une partie',
                             manager=self.manager,
                             object_id='#title')
        self.scrollingContainer = UIScrollingContainer(
            relative_rect=pygame.Rect(100, 100, 700, 400),
            manager=self.manager)

        self.verticalScrollBar = UIVerticalScrollBar(
            relative_rect=pygame.Rect(680, 0, 20, 400),
            manager=self.manager,
            visible_percentage=0.8,
            container=self.scrollingContainer)

        self.background = UIPanel(relative_rect=pygame.Rect(0, 0, 500, 80),
                                  starting_layer_height=0,
                                  manager=self.manager,
                                  container=self.scrollingContainer)

        self.name = UILabel(relative_rect=pygame.Rect(10, 10, 200, 20),
                            text='Charger une partie',
                            manager=self.manager,
                            object_id='#text-button',
                            container=self.background)

        self.date = UILabel(relative_rect=pygame.Rect(300, 10, 200, 20),
                            text='date de la partie',
                            manager=self.manager,
                            object_id='#text-button',
                            container=self.background)

        self.currentScore = UILabel(relative_rect=pygame.Rect(10, 40, 200, 20),
                                    text='45544',
                                    manager=self.manager,
                                    object_id='#text-button',
                                    container=self.background)

        self.maxScore = UILabel(relative_rect=pygame.Rect(300, 40, 200, 20),
                                text='1255454',
                                manager=self.manager,
                                object_id='#text-button',
                                container=self.background)

        self.buttonCreating = UIButton(relative_rect=pygame.Rect(
            0, 0, 500, 80),
                                       text='',
                                       manager=self.manager,
                                       container=self.scrollingContainer)

        self.buttonLogout = UIButton(relative_rect=pygame.Rect(
            800 - 220, 20, 200, 50),
                                     text='Déconnexion',
                                     manager=self.manager,
                                     object_id='#button-logout')
Beispiel #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, "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')
Beispiel #12
0
    def __init__(self, rect: pygame.Rect,
                 manager: 'pygame_gui.ui_manager.UIManager',
                 player_resources: PlayerResources, turret_costs: TurretCosts):
        super().__init__(rect, manager, 'hud_panel')
        self.player_resources = player_resources
        self.turret_costs = turret_costs

        # create top edge shadow
        top_edge_shadow_size = 4
        border_size = 1
        background_surface = pygame.Surface(
            (self.rect.width, self.rect.height - top_edge_shadow_size))
        background_surface.fill(pygame.Color("#808080"))
        background_surface.fill(
            pygame.Color("#646464"),
            pygame.Rect(
                (border_size, border_size),
                (self.rect.width - (border_size * 2), self.rect.height -
                 (border_size * 2) - top_edge_shadow_size)))
        shadow = self.ui_manager.get_shadow(
            (self.rect.width + 48, self.rect.height))
        self.image = pygame.Surface(self.rect.size, flags=pygame.SRCALPHA)
        self.image.blit(shadow, (0, 0),
                        area=pygame.Rect((24, 0), self.rect.size))
        self.image.blit(background_surface, (0, top_edge_shadow_size))

        self.get_container().relative_rect.width = self.rect.width
        self.get_container(
        ).relative_rect.height = self.rect.height - top_edge_shadow_size
        self.get_container().relative_rect.x = self.get_container(
        ).relative_rect.x
        self.get_container().relative_rect.y = self.get_container(
        ).relative_rect.y + top_edge_shadow_size
        self.get_container().update_containing_rect_position()

        self.health_label = UILabel(
            pygame.Rect((900, 30), (100, 40)),
            "Health: " +
            "{:,}".format(self.player_resources.current_base_health),
            manager=self.ui_manager,
            container=self.get_container(),
            object_id="#screen_text")

        self.cash_label = UILabel(
            pygame.Rect((900, 60), (100, 40)),
            "£" + "{:,}".format(self.player_resources.current_cash),
            manager=self.ui_manager,
            container=self.get_container(),
            object_id="#screen_text")

        self.clearable_hud_elements = []
Beispiel #13
0
 def __init__(self,
              text,
              layout_info,
              container,
              text_color=BLACK,
              background_color=TRANSPARENT,
              padding=None):
     super().__init__(layout_info, container, padding)
     self.text = text
     self.element = UILabel(relative_rect=self.bounds,
                            manager=self.manager,
                            text=text)
     self.text_color = text_color
     self.background_color = background_color
Beispiel #14
0
class SpeakSpell(pygame_gui.elements.UIWindow):
    speakthrd = None

    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!')

    def speak(self, text):
        if self.speakthrd is not None and self.speakthrd.is_alive():
            return

        if text == '':
            return

        self.engine.say(text)
        self.speakthrd = threading.Thread(target=self.engine.runAndWait, args=())
        self.speakthrd.start()
        self.label.set_text(text)
        self.input.set_text('')

    def process_event(self, event):
        super().process_event(event)
        if event.type == pygame.USEREVENT and event.ui_element == self.input:
            if event.user_type == pygame_gui.UI_TEXT_ENTRY_FINISHED:
                self.speak(self.input.get_text())
Beispiel #15
0
class DrawableWaypointCircle:
    def __init__(self, radius, position, ui_manager, order):
        self.ui_manager = ui_manager
        self.traversal_order = order
        self.radius = radius
        self.colour = pygame.Color("#FF6464")
        self.rectangle_colour = pygame.Color("#646464")
        self.color_key = (127, 33, 33)
        self.world_position = [
            int(position[0] - self.radius),
            int(position[1] - self.radius)
        ]
        self.surface = pygame.Surface((self.radius * 2, self.radius * 2))
        self.surface.fill(self.color_key)
        self.surface.set_colorkey(self.color_key)
        pygame.draw.circle(self.surface, self.colour,
                           (self.radius, self.radius), self.radius)
        self.surface.set_alpha(100)

        self.rectangle_surface = pygame.Surface((32, 32))
        self.rectangle_surface.fill(self.color_key)
        self.rectangle_surface.set_colorkey(self.color_key)
        pygame.draw.rect(self.rectangle_surface, self.rectangle_colour,
                         pygame.Rect(0, 0, 32, 32))
        self.rectangle_surface.set_alpha(100)
        self.position = [self.world_position[0], self.world_position[1]]
        # self.id_text = fonts[6].render(str(self.traversal_order), True, pygame.Color("#FFFFFF"))

        self.id_text_label = UILabel(pygame.Rect(self.position, (32, 32)),
                                     str(self.traversal_order),
                                     manager=self.ui_manager,
                                     object_id="#small_screen_text")

    def kill(self):
        self.id_text_label.kill()

    def update_offset_position(self, offset):
        self.position = [
            self.world_position[0] - offset[0],
            self.world_position[1] - offset[1]
        ]
        self.id_text_label.rect.x = self.position[0] + 16
        self.id_text_label.rect.y = self.position[1] + 16

    def draw(self, screen):
        screen.blit(self.rectangle_surface,
                    [self.position[0] + 16, self.position[1] + 16])
        screen.blit(self.surface, self.position)
Beispiel #16
0
    def __init__(self):

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

        self.title = UILabel(relative_rect=pygame.Rect(400 - 100, 20, 200, 50),
                             text='Instruction',
                             manager=self.manager,
                             object_id='#title')

        self.text = UITextBox(
            relative_rect=pygame.Rect(100, 100, 800 - 200, 600 - 100),
            html_text=
            "<body><b>Touche</b><br>Espace -> Tirer<br>Entrer -> Magasin<br>Echap -> Menu de sauvegarde<br>Flèche droite et gauche -> Se déplacer<br><br><b>Système de Niveau</b><br>Niveau 1 -> 0 à 5000 points<br>Niveau 2 -> 5000 à 10000 points<br>Niveau 3 -> 10000 à 15000 points<br>Niveau 4 -> plus de 15000 points<br><br><b>Système du jeu</b><br>Le Joueur commence avec 3 vies, lorsque un monstre touche le joueur celui-ci perd une vie et le monstre meurt.<br>Un monstre rapporte 100 points et 1 credit lorsque le joueur le tue et retire 50 points lorsque le monstre touche le sol<br>Le Joueur a un pourcentage de chance d'obtenir un bonus lorsqu'il tue un monstre<br><br><b>Les Bonus</b><br>Double attaque -> Double les dégats du missile du joueur<br>3 missiles -> Tire 3 missiles au lieu de 1<br>Double score -> Double le score du joueur<br>Temps d'apparition -> Le temps d'apparition est augmenté de 2s</body>",
            manager=self.manager)

        self.buttonReturn = UIButton(relative_rect=pygame.Rect(
            20, 20, 200, 50),
                                     text='Retour',
                                     manager=self.manager)

        self.buttonLogout = UIButton(relative_rect=pygame.Rect(
            800 - 220, 20, 200, 50),
                                     text='Déconnexion',
                                     manager=self.manager,
                                     object_id='#button-logout')
Beispiel #17
0
    def __init__(self, args: dict, int_sec, rect, ui_manager):
        self.game_args = args
        self.int_sec = int_sec
        super().__init__(rect,
                         ui_manager,
                         window_display_title='Waiting for connections',
                         object_id='#connection_window',
                         resizable=True)
        self.enable_close_button = False
        self.close_window_button = None
        size = [150, 35]
        self.nb_online = self.game_args["nb_online"]
        self.socket = socket.socket()
        HOST = socket.gethostbyname(socket.gethostname())
        print(HOST, PORT)
        self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        self.socket.bind((HOST, PORT))
        self.socket.listen(self.nb_online)
        self.socket_list = []
        self.socket_list.append((self.int_sec.player_name, self.socket))
        self.thread = ListeningThread(self)
        self.thread.setDaemon(True)
        self.thread.start()
        UILabel(pygame.Rect((0, 0), size),
                f"Connected players",
                self.ui_manager,
                container=self)

        self.new_game_btn = UIButton(
            pygame.Rect((self.relative_rect.width - 160,
                         self.relative_rect.height - 140), (100, 40)),
            'GO',
            self.ui_manager,
            container=self,
        )
Beispiel #18
0
    def construct_gen_explore(self):
        #self.gen_explore_bg_surface = pygame.Surface(self.opt.resolution)
        #self.gen_explore_bg_surface.fill(self.ui_manager.get_theme().get_colour('dark_bg'))
        self.pnl_gen_explore = UIPanel(self.main_area,
                                       starting_layer_height=0,
                                       manager=self.ui_manager)

        self.gen_explore_label = UILabel(
            pygame.Rect(5, 5, 350, 35),
            'Explore generators',
            self.ui_manager,
            container=self.pnl_gen_explore,
        )
        self.gen_list = UISelectionList(
            relative_rect=pygame.Rect(5, 75, 350, self.opt.H - 95),
            item_list=self.gen_state.get_current_gen_list(),
            manager=self.ui_manager,
            container=self.pnl_gen_explore,
            allow_multi_select=False,
            object_id='#gen_list',
        )
        self.btn_gen_explore_save_as_png = None
        self.gen_explore_map_image = None
        self.gen_explore_image = None
        self.file_dialog_gen_explore_save_as_png = None
        self.pnl_gen_explore.hide()
    def _create_panel(self, screen_width: int, screen_height: int):
        self.width = 300
        self.height = 275

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

        UILabel(pygame.Rect((0, 10), (self.width, 20)), 
                "Your Turn", 
                self.manager, 
                container=self.panel,
                object_id="windowTitle")

        y_offset = 10 + 10

        roll_button_rect = pygame.Rect((50, y_offset + 25), (200, 50))
        self._roll_button = UIButton(roll_button_rect, 'Roll', self.manager, container=self.panel)

        y_offset += 25 + 50

        self._guess_rect = pygame.Rect((50, y_offset + 25), (200, 50))
        self._make_guess_button()

        y_offset += 25 + 50

        rect = pygame.Rect((50, y_offset + 25), (200, 50))
        self._accuse_button = UIButton(rect, 'Accuse', self.manager, container=self.panel)

        self.hide()
Beispiel #20
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,
                                               "Map Editor Menu", self.gui,
                                               self.ui_elements['panel'])
     # buttons
     button_rect = Rect(0, 100, 400, get_param('element_height'))
     button_rect.centerx = panel_rect.w // 2
     self.ui_elements['btn_new'] = UIButton(button_rect, "New Map",
                                            self.gui,
                                            self.ui_elements['panel'])
     button_rect.y += get_param('element_height') + get_param(
         'element_padding')
     self.ui_elements['btn_load'] = UIButton(button_rect, "Load Map",
                                             self.gui,
                                             self.ui_elements['panel'])
     button_rect.y += get_param('element_height') + get_param(
         'element_padding')
     self.ui_elements['btn_back'] = UIButton(button_rect, "Back", self.gui,
                                             self.ui_elements['panel'])
    def _create_panel(self, manager: UIManager, screen_width: int, screen_height: int):
        self.width = 300
        self.height = 275

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

        UILabel(pygame.Rect((0, 10), (self.width, 20)), 
                "Pick a card to show", 
                manager, 
                container=self.panel)

        y_offset = 10 + 10

        self._weapon_button_rect = pygame.Rect((50, y_offset + 25), (200, 50))        
        self._make_weapon_button('')

        y_offset += 25 + 50

        self._character_button_rect = pygame.Rect((50, y_offset + 25), (200, 50))
        self._make_character_button('')

        y_offset += 25 + 50

        self._room_button_rect = pygame.Rect((50, y_offset + 25), (200, 50))
        self._make_room_button('')

        self.panel.hide()
Beispiel #22
0
 def __init__(self, text_rect: pygame.rect.Rect, text, value, manager,
              container):
     self.ui_manager = manager
     self.text_rect = text_rect
     self.container = container
     self.text = text
     self.value = value
     self.text_label = UILabel(self.text_rect,
                               text,
                               manager=self.ui_manager,
                               container=self.container)
     self.value_label = UILabel(pygame.Rect(
         (self.text_rect.x, self.text_rect.y + self.text_rect.height),
         (self.text_rect.width, self.text_rect.height)),
                                value,
                                manager=self.ui_manager,
                                container=self.container)
    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._buttons = []

        for i in range(N):
            row = []
            for j in range(N):
                rect = pygame.Rect(
                    (UI_ITEM_WIDTH * j + 2, UI_ITEM_HEIGHT * i + 2),
                    (UI_ITEM_WIDTH - 2, UI_ITEM_HEIGHT - 2))

                tip = str(self._puzzle.get_possible(i, j))
                if self._grid[i][j] == self._solution_grid[i][j]:
                    tip = None

                label = UIButton(relative_rect=rect,
                                 text=self._grid[i][j],
                                 tool_tip_text=tip,
                                 manager=self._manager)
                if self._grid[i][j] != EMPTY_CELL:
                    label.disable()

                row.append(label)
            self._buttons.append(row)

        rect = pygame.Rect((0, UI_ITEM_HEIGHT * N),
                           ((UI_ITEM_WIDTH * N) // 2, UI_ITEM_HEIGHT))
        self._hint_button = UIButton(relative_rect=rect,
                                     text='CHECK',
                                     manager=self._manager)

        rect = pygame.Rect(((UI_ITEM_WIDTH * N) // 2, UI_ITEM_HEIGHT * N),
                           ((UI_ITEM_WIDTH * N) // 2, UI_ITEM_HEIGHT))
        self._hint_toggle = UIButton(relative_rect=rect,
                                     text='HINTS ON',
                                     manager=self._manager)
        self._hints_on = True

        rect = pygame.Rect((0, UI_ITEM_HEIGHT * (N + 1)),
                           (UI_ITEM_WIDTH * N, UI_ITEM_HEIGHT))
        self._new_button = UIButton(relative_rect=rect,
                                    text='NEW',
                                    manager=self._manager)

        # solved label
        rect = pygame.Rect(
            (UI_ITEM_WIDTH * (N / 2) - UI_ITEM_WIDTH, UI_ITEM_HEIGHT *
             (N / 2) - UI_ITEM_HEIGHT / 2),
            (UI_ITEM_WIDTH * 2, UI_ITEM_HEIGHT))
        self._solved_label = UILabel(rect,
                                     "SOLVED!",
                                     manager=self._manager,
                                     visible=0)
Beispiel #24
0
 def generate_label(manager, rect, text):
     x_center, y_center, w, h = rect
     corrected_w = int(0.7 * w)
     new_y_center = y_center - 3 * h // 2
     label_rect = (x_center - corrected_w // 2, new_y_center, corrected_w,
                   h)
     label_item = UILabel(relative_rect=pygame.Rect(*label_rect),
                          text=text,
                          manager=manager)
     return label_item
Beispiel #25
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
Beispiel #26
0
 def run(self) -> None:
     step = 40
     size = [400, 35]
     for i in range(self.con_win.nb_online):
         con, add = self.socket.accept()
         name = con.recv(64).decode().split("$")[-1]
         self.con_win.socket_list.append((name, con))
         UILabel(pygame.Rect((0, step * (i + 1)), size),
                 f"{i + 1}. {name} connected from {add[0]}",
                 self.con_win.ui_manager,
                 container=self.con_win)
Beispiel #27
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'])
Beispiel #28
0
    def display_upgrade_hud(self, upgrade_turret):

        for element in self.clearable_hud_elements:
            element.kill()

        self.clearable_hud_elements.clear()

        self.clearable_hud_elements.append(
            UIButton(pygame.Rect(32, 32, 66, 66),
                     "",
                     manager=self.ui_manager,
                     container=self.get_container(),
                     object_id="#upgrade_button",
                     tool_tip_text="<font size=2><b>Upgrade Turret</b><br><br>"
                     "Upgrades the selected turret to the next level."
                     " Turrets have three levels.</font>"))
        self.clearable_hud_elements.append(
            UIButton(
                pygame.Rect(128, 32, 66, 66),
                "",
                manager=self.ui_manager,
                container=self.get_container(),
                object_id="#sell_button",
                tool_tip_text="<font size=2><b>Sell Turret</b><br><br>"
                "Sells the selected turret for half of the cost of building it.</font>"
            ))
        self.clearable_hud_elements.append(
            UILabel(pygame.Rect((32, 96), (64, 32)),
                    "£ " + str(upgrade_turret.get_upgrade_cost()),
                    manager=self.ui_manager,
                    container=self.get_container(),
                    object_id="#small_screen_text"))
        self.clearable_hud_elements.append(
            UILabel(pygame.Rect((128, 96), (64, 32)),
                    "£ " + str(upgrade_turret.get_sell_value()),
                    manager=self.ui_manager,
                    container=self.get_container(),
                    object_id="#small_screen_text"))
Beispiel #29
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)
Beispiel #30
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,
                                               "Main Menu", self.gui,
                                               self.ui_elements['panel'])
     # buttons
     button_rect = Rect(0, 0, 400, get_param('element_height'))
     button_rect.y = scene_label_rect.bottom + get_param('element_padding')
     button_rect.centerx = panel_rect.w // 2
     self.ui_elements['btn_new'] = UIButton(button_rect, "New Game",
                                            self.gui,
                                            self.ui_elements['panel'])
     button_rect.y += get_param('element_height') + get_param(
         'element_padding')
     self.ui_elements['btn_load'] = UIButton(button_rect, "Load Game",
                                             self.gui,
                                             self.ui_elements['panel'])
     button_rect.y += get_param('element_height') + get_param(
         'element_padding')
     self.ui_elements['btn_editor'] = UIButton(button_rect, "Map Editor",
                                               self.gui,
                                               self.ui_elements['panel'])
     button_rect.y += get_param('element_height') + get_param(
         'element_padding')
     self.ui_elements['btn_settings'] = UIButton(button_rect, "Settings",
                                                 self.gui,
                                                 self.ui_elements['panel'])
     button_rect.y += get_param('element_height') + get_param(
         'element_padding')
     self.ui_elements['btn_quit'] = UIButton(button_rect, "Quit Game",
                                             self.gui,
                                             self.ui_elements['panel'])