def __init_widgets(self, message):
        for index, line in enumerate(message.split("\n")):
            message_lbl = widgets.Label(util.Size(self.rect.width - 20, 25),
                                        color=self.COLOR,
                                        text=line,
                                        font_size=18,
                                        selectable=False)
            self.add_widget((10, index * 18 + 5), message_lbl)

        oke_button = widgets.Button(util.Size(self.rect.width / 2 - 25, 25),
                                    text="OK",
                                    font_size=25)
        oke_button.add_key_event_listener(1,
                                          self.__set_response_true,
                                          types=["unpressed"])
        self.add_widget((20, 60), oke_button)

        cancel_button = widgets.Button(util.Size(self.rect.width / 2 - 25, 25),
                                       text="CANCEL",
                                       font_size=25)
        cancel_button.add_key_event_listener(1,
                                             self._close_window,
                                             types=["unpressed"])
        self.add_widget((self.rect.width - cancel_button.rect.width - 20, 60),
                        cancel_button)
    def __init_widgets(self):
        self.input_line = widgets.MultilineTextBox(util.Size(150, 25),
                                                   lines=1,
                                                   font_size=25)
        self.add_widget((25, 5), self.input_line)

        self._incorect_lbl = widgets.Label(util.Size(self.rect.width - 50, 25),
                                           color=self.COLOR)
        self.add_widget((25, 35), self._incorect_lbl)

        oke_button = widgets.Button(util.Size(self.rect.width / 2 - 25, 25),
                                    text="OK",
                                    font_size=25)
        oke_button.add_key_event_listener(1,
                                          self._set_name_response,
                                          types=["unpressed"])
        self.add_widget((20, 60), oke_button)

        cancel_button = widgets.Button(util.Size(self.rect.width / 2 - 25, 25),
                                       text="CANCEL",
                                       font_size=25)
        cancel_button.add_key_event_listener(1,
                                             self._close_window,
                                             types=["unpressed"])
        self.add_widget((self.rect.width - cancel_button.rect.width - 20, 60),
                        cancel_button)
    def __init_widgets(self):
        button_size = util.Size(120, 40)
        y_coord = 150

        continue_button = widgets.Button(button_size,
                                         color=(100, 100, 100),
                                         text="CONTINUE",
                                         font_size=30)
        continue_button.add_key_event_listener(1,
                                               self._close_window,
                                               types=["unpressed"])
        self.add_widget(("center", y_coord), continue_button)

        y_coord += 50
        save_button = widgets.Button(button_size,
                                     color=(100, 100, 100),
                                     text="SAVE",
                                     font_size=30)
        save_button.add_key_event_listener(1, self.__save, types=["unpressed"])
        self.add_widget(("center", y_coord), save_button)

        y_coord += 50
        exit_button = widgets.Button(button_size,
                                     color=(100, 100, 100),
                                     text="EXIT",
                                     font_size=30)
        exit_button.add_key_event_listener(1,
                                           self.__back_to_main_menu,
                                           types=["unpressed"])
        self.add_widget(("center", y_coord), exit_button)
    def __init_widgets(self):
        save_label = widgets.Label(util.Size(200, 30),
                                   text="Choose a file to load:",
                                   font_size=25,
                                   color=(0, 0, 0, 0),
                                   selectable=False)
        self.add_widget(
            (int(self.rect.width / 2 - save_label.rect.width / 2), 5),
            save_label)

        file_list = widgets.ListBox(util.Size(self.rect.width - 50,
                                              self.rect.height - 100),
                                    color=self.COLOR)
        self.add_widget(("center", 45), file_list)
        self.add_border(file_list)

        for file in os.listdir(con.SAVE_DIR):
            if isfile(join(con.SAVE_DIR, file)) and file.endswith(".save"):
                file_button = widgets.Button(util.Size(file_list.rect.width,
                                                       25),
                                             text=file,
                                             font_size=25,
                                             color=self.COLOR)
                file_button.add_key_event_listener(1,
                                                   self.load_file,
                                                   values=[file],
                                                   types=["unpressed"])
                file_list.add_widget(file_button)
    def __add_top_border(self, size: util.Size, title: Union[str, None]):
        """Add the top bar of the window with the exit button"""
        top_label = widgets.Label(util.Size(
            size.width - self.EXIT_BUTTON_SIZE.width, self.TOP_SIZE.height),
                                  color=self.TOP_BAR_COLOR,
                                  selectable=False)
        # add the move listeners
        top_label.add_key_event_listener(1,
                                         self.__top_label_action,
                                         values=[True],
                                         types=["pressed"])
        top_label.add_key_event_listener(1,
                                         self.__top_label_action,
                                         values=[False],
                                         types=["unpressed"])
        self.add_widget((0, 0), top_label, adjust=False)

        if title is not None:
            top_label.set_text(title, (10, 5), self.TEXT_COLOR, font_size=25)
        button_image = image_handlers.image_sheets["general"].image_at(
            (20, 0), self.EXIT_BUTTON_SIZE)
        hover_image = image_handlers.image_sheets["general"].image_at(
            (45, 0), self.EXIT_BUTTON_SIZE)
        exit_button = widgets.Button(self.EXIT_BUTTON_SIZE,
                                     image=button_image,
                                     hover_image=hover_image,
                                     selectable=False)
        exit_button.add_key_event_listener(1,
                                           self._close_window,
                                           types=["unpressed"])
        self.add_widget((size.width - self.EXIT_BUTTON_SIZE.width, 0),
                        exit_button,
                        adjust=False)
예제 #6
0
    def __init_widgets(self):
        self.main_menu_frame = widgets.Frame((0, 0),
                                             util.Size(*self.rect.size),
                                             self.sprite_group,
                                             color=(173, 94, 29),
                                             static=False)

        button_size = util.Size(100, 40)
        y_coord = 200
        new_button = widgets.Button(button_size,
                                    color=(100, 100, 100),
                                    text="NEW",
                                    font_size=30)
        new_button.add_key_event_listener(1,
                                          self.__open_game_settings,
                                          types=["unpressed"])
        self.main_menu_frame.add_widget(("center", y_coord), new_button)

        y_coord += 50
        load_button = widgets.Button(button_size,
                                     color=(100, 100, 100),
                                     text="LOAD",
                                     font_size=30)
        load_button.add_key_event_listener(1,
                                           self.__load_game,
                                           types=["unpressed"])
        self.main_menu_frame.add_widget(("center", y_coord), load_button)

        y_coord += 50
        settings_button = widgets.Button(button_size,
                                         color=(100, 100, 100),
                                         text="SETTINGS",
                                         font_size=30)
        settings_button.add_key_event_listener(1,
                                               self.__open_settings,
                                               types=["unpressed"])
        self.main_menu_frame.add_widget(("center", y_coord), settings_button)

        y_coord += 50
        quit_button = widgets.Button(button_size,
                                     color=(100, 100, 100),
                                     text="QUIT",
                                     font_size=30)
        quit_button.add_key_event_listener(1, self.__quit, types=["unpressed"])
        self.main_menu_frame.add_widget(("center", y_coord), quit_button)
예제 #7
0
    def __init_widgets(self):
        self.loading_frame = widgets.Frame((0, 0),
                                           util.Size(*self.rect.size),
                                           self.sprite_group,
                                           color=(173, 94, 29),
                                           static=False)
        frame_rect = self.loading_frame.rect
        save_label = widgets.Label(util.Size(frame_rect.width, 30),
                                   text="Choose a file to load:",
                                   font_size=25,
                                   color=(0, 0, 0, 0),
                                   selectable=False)
        self.loading_frame.add_widget(
            (int(frame_rect.width / 2 - save_label.rect.width / 2), 5),
            save_label)

        file_list = widgets.ListBox(util.Size(frame_rect.width - 200,
                                              self.rect.height - 300),
                                    color=(173, 94, 29))
        self.loading_frame.add_widget(("center", 75), file_list)
        self.loading_frame.add_border(file_list)

        for file in os.listdir(con.SAVE_DIR):
            if isfile(join(con.SAVE_DIR, file)) and file.endswith(".save"):
                file_button = widgets.Button(util.Size(file_list.rect.width,
                                                       25),
                                             text=file,
                                             font_size=25,
                                             color=(173, 94, 29))
                file_button.add_key_event_listener(1,
                                                   self.load_file,
                                                   values=[file],
                                                   types=["unpressed"])
                file_list.add_widget(file_button)

        back_button = widgets.Button((200, 30),
                                     text="BACK",
                                     font_size=25,
                                     color=(150, 150, 150))
        back_button.add_key_event_listener(1,
                                           self.__back_to_main,
                                           types=["unpressed"])
        self.loading_frame.add_widget(("center", self.rect.height - 100),
                                      back_button)
예제 #8
0
    def __init_widgets(self):
        self.settings_menu_frame = widgets.Frame((0, 0),
                                                 util.Size(*self.rect.size),
                                                 self.sprite_group,
                                                 color=(173, 94, 29),
                                                 static=False)
        frame_rect = self.settings_menu_frame.rect

        widget_size = util.Size(100, 40)
        color = (173, 94, 29)
        y_coord = 100

        # GENERAL OPTIONS
        generel_options_pane = widgets.Pane((frame_rect.width - 100, 100),
                                            border=True,
                                            border_width=4,
                                            color=color)
        self.settings_menu_frame.add_widget(("center", y_coord),
                                            generel_options_pane)
        local_y = 10
        local_x = int((generel_options_pane.rect.width / 2) + 5)
        self.__game_name_textbox = widgets.MultilineTextBox(
            (200, con.FONTS[22].get_linesize() + 6), font_size=22, lines=1)
        generel_options_pane.add_widget((local_x, local_y),
                                        self.__game_name_textbox)

        local_x = int((generel_options_pane.rect.width / 2) - 135)
        game_name_label = widgets.Label((140, con.FONTS[22].get_linesize()),
                                        color=color,
                                        text="Name:",
                                        font_size=22,
                                        text_pos=("W", "C"),
                                        selectable=False)
        generel_options_pane.add_widget((local_x, local_y), game_name_label)

        # GENERATION OPTIONS
        y_coord += generel_options_pane.rect.height + 10
        generation_values_pane = widgets.Pane((frame_rect.width - 100, 300),
                                              border=True,
                                              border_width=4,
                                              color=color)
        self.settings_menu_frame.add_widget(("center", y_coord),
                                            generation_values_pane)

        # Biome size selection
        local_y = 10
        local_x = int((generation_values_pane.rect.width / 2) + 5)
        self.__biome_size_selection_list =\
            widgets.SelectionList(self.sprite_group, color=(150, 150, 150),
                                  options=list(generation.BoardGenerator.BIOME_SIZES.keys()))
        self.__biome_size_selection_list.select_option("normal")
        generation_values_pane.add_widget((local_x, local_y),
                                          self.__biome_size_selection_list)

        biome_size_label = widgets.Label(
            (100, self.__biome_size_selection_list.LINE_HEIGHT),
            color=color,
            text="Biome Size:",
            font_size=22,
            text_pos=("W", "C"),
            selectable=False)
        biome_size_tooltip = widgets.Tooltip(self.sprite_group,
                                             color=(150, 150, 150),
                                             text="Average size of biomes")
        biome_size_label.add_tooltip(biome_size_tooltip)
        local_x = int((generation_values_pane.rect.width / 2) - 135)
        generation_values_pane.add_widget((local_x, local_y), biome_size_label)

        # Biome blend selection
        local_y += self.__biome_size_selection_list.LINE_HEIGHT + 10
        local_x = int((generation_values_pane.rect.width / 2) + 5)
        self.__biome_blend_selection_list = \
            widgets.SelectionList(self.sprite_group, color=(150, 150, 150),
                                  options=list(generation.BoardGenerator.BIOME_BLEND.keys()))
        self.__biome_blend_selection_list.select_option("normal")
        generation_values_pane.add_widget((local_x, local_y),
                                          self.__biome_blend_selection_list)

        biome_blend_label = widgets.Label(
            (100, self.__biome_blend_selection_list.LINE_HEIGHT),
            color=color,
            text="Biome Blend:",
            font_size=22,
            text_pos=("W", "C"),
            selectable=False)
        biome_blend_tooltip = widgets.Tooltip(
            self.sprite_group,
            color=(150, 150, 150),
            text="The level to which biomes\ncan blend trough one another")
        biome_blend_label.add_tooltip(biome_blend_tooltip)
        local_x = int((generation_values_pane.rect.width / 2) - 135)
        generation_values_pane.add_widget((local_x, local_y),
                                          biome_blend_label)

        # Max Caves selection
        local_y += self.__biome_blend_selection_list.LINE_HEIGHT + 10
        local_x = int((generation_values_pane.rect.width / 2) + 5)
        self.__max_caves_selection_list = \
            widgets.SelectionList(self.sprite_group, color=(150, 150, 150),
                                  options=list(generation.BoardGenerator.MAX_CAVES.keys()))
        self.__max_caves_selection_list.select_option("normal")
        generation_values_pane.add_widget((local_x, local_y),
                                          self.__max_caves_selection_list)

        max_caves_label = widgets.Label(
            (140, self.__max_caves_selection_list.LINE_HEIGHT),
            color=color,
            text="Number of Caves:",
            font_size=22,
            text_pos=("W", "C"),
            selectable=False)
        max_caves_tooltip = widgets.Tooltip(
            self.sprite_group,
            color=(150, 150, 150),
            text="The amount of caves present on the map")
        max_caves_label.add_tooltip(max_caves_tooltip)
        local_x = int((generation_values_pane.rect.width / 2) - 135)
        generation_values_pane.add_widget((local_x, local_y), max_caves_label)

        # Cave length selection
        local_y += self.__max_caves_selection_list.LINE_HEIGHT + 10
        local_x = int((generation_values_pane.rect.width / 2) + 5)
        self.__cave_length_selection_list =\
            widgets.SelectionList(self.sprite_group, color=(150, 150, 150),
                                  options=list(generation.BoardGenerator.CAVE_LENGTH.keys()))
        self.__cave_length_selection_list.select_option("normal")
        generation_values_pane.add_widget((local_x, local_y),
                                          self.__cave_length_selection_list)

        cave_length_label = widgets.Label(
            (140, self.__cave_length_selection_list.LINE_HEIGHT),
            color=color,
            text="Length of Caves:",
            font_size=22,
            text_pos=("W", "C"),
            selectable=False)
        cave_length_tooltip = widgets.Tooltip(self.sprite_group,
                                              color=(150, 150, 150),
                                              text="The lenght of the caves")
        cave_length_label.add_tooltip(cave_length_tooltip)
        local_x = int((generation_values_pane.rect.width / 2) - 135)
        generation_values_pane.add_widget((local_x, local_y),
                                          cave_length_label)

        # Cave width selection
        local_y += self.__max_caves_selection_list.LINE_HEIGHT + 10
        local_x = int((generation_values_pane.rect.width / 2) + 5)
        self.__cave_width_selection_list = \
            widgets.SelectionList(self.sprite_group, color=(150, 150, 150),
                                  options=list(generation.BoardGenerator.CAVE_STOP_SPREAD_CHANCE.keys()))
        self.__cave_width_selection_list.select_option("normal")
        generation_values_pane.add_widget((local_x, local_y),
                                          self.__cave_width_selection_list)

        cave_width_label = widgets.Label(
            (140, self.__cave_width_selection_list.LINE_HEIGHT),
            color=color,
            text="Width of Caves:",
            font_size=22,
            text_pos=("W", "C"),
            selectable=False)
        cave_width_tooltip = widgets.Tooltip(self.sprite_group,
                                             color=(150, 150, 150),
                                             text="How wide a cave is")
        cave_width_label.add_tooltip(cave_width_tooltip)
        local_x = int((generation_values_pane.rect.width / 2) - 135)
        generation_values_pane.add_widget((local_x, local_y), cave_width_label)

        # general buttons
        y_coord += generation_values_pane.rect.height + 20
        x_coord = (frame_rect.width / 2) - widget_size.width - 5
        start_game_btn = widgets.Button(widget_size,
                                        color=(100, 100, 100),
                                        text="START",
                                        font_size=30)
        start_game_btn.add_key_event_listener(1, self.__start_game)
        self.settings_menu_frame.add_widget((x_coord, y_coord), start_game_btn)

        x_coord = int((frame_rect.width / 2) + 5)
        back_btn = widgets.Button(widget_size,
                                  color=(100, 100, 100),
                                  text="BACK",
                                  font_size=30)
        back_btn.add_key_event_listener(1, self.__back_to_main)
        self.settings_menu_frame.add_widget((x_coord, y_coord), back_btn)