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 __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 load_images(): """ Loads all the available image_sheets into memory and saves them by a descriptive name in a dictionary """ global image_sheets image_sheets["buildings"] = Spritesheet("building_materials.bmp", util.Size(10, 10)) image_sheets["general"] = Spritesheet("general.bmp", util.Size(10, 10)) image_sheets["materials"] = Spritesheet("materials.bmp", util.Size(10, 10))
class TerminalMaterial(Building, base_materials.Indestructable, base_materials.MultiImageMaterial): _BASE_TRANSPARANT_GROUP: ClassVar[int] = 2 _BLOCK_TYPE: ClassVar[blocks.Block] = blocks.InterfaceBlock FULL_SURFACE: ClassVar[utility.image_handling.ImageDefinition] =\ utility.image_handling.ImageDefinition("buildings", (0, 0), size=util.Size(20, 20)) IMAGE_DEFINITIONS: ClassVar[Dict[int, List[utility.image_handling.ImageDefinition]]] = \ {1: utility.image_handling.ImageDefinition("buildings", (0, 0)), 2: utility.image_handling.ImageDefinition("buildings", (10, 0)), 3: utility.image_handling.ImageDefinition("buildings", (0, 10)), 4: utility.image_handling.ImageDefinition("buildings", (10, 10))} TRANSPORT_IMAGE_DEFINITION: ClassVar[utility.image_handling.ImageDefinition] = \ utility.image_handling.ImageDefinition("buildings", (0, 0), size=util.Size(20, 20), image_size=con.TRANSPORT_BLOCK_SIZE)
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 __find_no_task_rectangle( self, blocks: List[List["Block"]], dissallowed_block_types: List[str]) -> util.Size: """Find in a given matrix of blocks the submatrix that contains blocks that the task of the selected mode is not allowed for. The 0,0 cooridinate is guaranteed to be a block that does not allow the task.""" # find how far the x-coordinate extends containing blocks that cannot have the selected task assigned x_size = 0 for block in blocks[0][1:]: if block.is_task_allowded(self._mode.name) and\ (block.name() not in dissallowed_block_types and block.light_level > 0): break x_size += 1 matrix_size = util.Size(x_size, 0) # skip the first row since this was checked already in the previous loop block = None for n_row, row in enumerate(blocks[1:]): for n_col, block in enumerate(row[:x_size + 1]): if block.is_task_allowded( self._mode.name) and (block.name() not in dissallowed_block_types): break if block is None or block.is_task_allowded(self._mode.name) and\ (block.name() not in dissallowed_block_types): break matrix_size.height += 1 return matrix_size
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)
class InventoryWindow(base_interface.Window): """Interface for inventory buildings""" SIZE = util.Size(300, 200) COLOR = (173, 94, 29) __inventory: "inventories.Inventory" __prev_no_items: int _inventory_pane: Union[widgets.ScrollPane, None] def __init__(self, rect: pygame.Rect, inventory: "inventories.Inventory", sprite_group: "sprite_groups.CameraAwareLayeredUpdates", title: str = ""): self.__inventory = inventory super().__init__(rect.topleft, self.SIZE, sprite_group, layer=con.INTERFACE_LAYER, title=title, allowed_events=[1, 4, 5, con.K_ESCAPE], static=True) self.__prev_no_items = 0 self._inventory_pane = None self._init_widgets() def _init_widgets(self): self._inventory_pane = widgets.ScrollPane(self.SIZE - (20, 20), color=self.COLOR) self.add_widget((10, 10), self._inventory_pane) self.add_border(self._inventory_pane) def update(self, *args): """Entity update method, add labels to the scroll pane when needed.""" super().update(*args) if self.__prev_no_items < self.__inventory.number_of_items: self.__prev_no_items = self.__inventory.number_of_items self.__add_item_labels() def __add_item_labels(self): """When more different items are encountered then previously in the inventory a new label is added for an item. The labels are added to the scrollpane First it is figured out what items are new and then a label for each is constructed""" # should always be a ItemDisplay covered_items = [ widget.item.name() for widget in self._inventory_pane.widgets ] # noqa for item in self.__inventory.items: if item.name() not in covered_items: tooltip = widgets.Tooltip(self.groups()[0], text=item.tooltip_text()) lbl = widgets.ItemDisplay((42, 42), item, color=self.COLOR, tooltip=tooltip) self._inventory_pane.add_widget(lbl)
def _create_recipe_grid(self): grid = base_recipes.RecipeGrid(util.Size(2, 2)) row1 = [ground_materials.Titanium, ground_materials.Titanium] row2 = [base_materials.Air, base_materials.Air] grid.add_all_rows(row1, row2) return grid
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)
def _create_recipe_grid(self): grid = base_recipes.RecipeGrid(util.Size(3, 3)) top = [ ground_materials.Stone, ground_materials.Stone, ground_materials.Stone ] middle = [base_materials.Air, base_materials.Air, base_materials.Air] grid.add_all_rows(top, middle, top) return grid
def __init__(self, width: int): super().__init__(util.Size(width, con.FONTS[22].get_linesize() + 6), lines=1, font_size=22) self.add_key_event_listener(con.K_RETURN, action_function=self.handle_return, types=["pressed"]) self.remove_key_event_listener(con.K_TAB) self.process_line = None
def __determine_cave_quadrant_size(self, caves_nr: int) -> util.Size: total_blocks = (con.ORIGINAL_BOARD_SIZE.width / con.BLOCK_SIZE.width) *\ (con.ORIGINAL_BOARD_SIZE.height / con.BLOCK_SIZE.height) total_caves = (total_blocks / 100_000) * caves_nr # Me brother : ) cave_quadrant_side = int( sqrt((con.ORIGINAL_BOARD_SIZE.width * con.ORIGINAL_BOARD_SIZE.height) / total_caves)) return util.Size(cave_quadrant_side, cave_quadrant_side)
def __init__(self, pos: Union[List[int], Tuple[int, int]], size: Union[util.Size, List[int], Tuple[int, int]], mouse_pos: Union[Tuple[int, int], List[int]], *groups: "CameraAwareLayeredUpdates", **kwargs): super().__init__(pos, size, pausable=False, *groups, **kwargs) self.__start_pos = list(pos) self.__prev_screen_pos = list(mouse_pos) self.__size = util.Size(*size) self.__update_image()
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) self.__progress_label = widgets.Label((500, 20), (173, 94, 29)) self.__loading_frame.add_widget(("center", "center"), self.__progress_label)
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)
class PauseWindow(base_interface.Window): """Pause window when in the game that is called from within the game""" WINDOW_SIZE = util.Size(400, 500) WINDOW_POS = (int((con.SCREEN_SIZE.width - WINDOW_SIZE.width) / 2), int((con.SCREEN_SIZE.height - WINDOW_SIZE.height) / 2)) def __init__(self, sprite_group): super().__init__(self.WINDOW_POS, self.WINDOW_SIZE, sprite_group, title="PAUSED", movable=False) self.__init_widgets() 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 __back_to_main_menu(self): scenes.scenes.set_active_scene("MainMenu") def __save(self): from interfaces.managers import game_window_manager explorer = \ file_explorer_interface.SaveFileWindow((self.rect.width / 2 - file_explorer_interface.SaveFileWindow.SIZE.width / 2 + self.rect.left, self.rect.height / 2 - file_explorer_interface.SaveFileWindow.SIZE.height / 2 + self.rect.top), self.groups()[0]) game_window_manager.add(explorer)
class UserUI(widgets.Frame): SIZE: Union[util.Size, Tuple[int, int], List[int]] = util.Size(150, 150) COLOR: Union[Tuple[int, int, int, int], Tuple[int, int, int], List[int]] = (173, 94, 29) def __init__(self, pos: Union[Tuple[int, int], List[int]], rotate: List[int], sprite_group: pygame.sprite.AbstractGroup, **kwargs): super().__init__(pos, self.SIZE, sprite_group, static=False, visible=True, layer=con.TOOLTIP_LAYER - 1, color=con.INVISIBLE_COLOR, **kwargs) self.__rotate = rotate self.__previous_rotate = self.__rotate[0] self.mode_label = None self.item_label = None self.__current_material = None self.__init_widgets() def __init_widgets(self): self.mode_label = widgets.Label((self.rect.width - 10, 30), color=(150, 150, 150), border=True) self.add_widget((5, 5), self.mode_label) self.item_label = widgets.ItemDisplay( (self.rect.width - 50, self.rect.height - 50), color=self.COLOR) self.add_widget((25, 45), self.item_label) def update(self, *args): super().update() item = small_interface.get_selected_item() if item is not None: material = item.material if self.__current_material is None or material.name() != self.__current_material.name() or \ self.__rotate[0] != self.__previous_rotate: if isinstance(material, building_materials.RotatbleBuildingMaterial): material.rotate(self.__rotate[0]) self.__current_material = material self.set_build_item(material) def change_mode(self, mode): self.mode_label.set_text(text=mode, font_size=25) def set_build_item(self, material): item = inventories.Item(material) self.item_label.add_item(item) def is_showing(self) -> bool: return True
class FactoryMaterial(Building, BuildingMaterial, base_materials.MultiImageMaterial): TEXT_COLOR: ClassVar[Tuple[int, int, int]] = (255, 255, 255) _BASE_TRANSPARANT_GROUP: ClassVar[int] = 4 _BLOCK_TYPE: ClassVar[blocks.Block] = blocks.InterfaceBlock FULL_SURFACE: ClassVar[utility.image_handling.ImageDefinition] = \ utility.image_handling.ImageDefinition("buildings", (40, 0), size=util.Size(20, 20)) IMAGE_DEFINITIONS: ClassVar[Dict[int, List[utility.image_handling.ImageDefinition]]] = \ {1: utility.image_handling.ImageDefinition("buildings", (40, 20)), 2: utility.image_handling.ImageDefinition("buildings", (50, 20)), 3: utility.image_handling.ImageDefinition("buildings", (40, 30)), 4: utility.image_handling.ImageDefinition("buildings", (50, 30))} ACTIVE_IMAGE_DEFINITIONS: ClassVar[Dict[int, List[utility.image_handling.ImageDefinition]]] = \ {1: utility.image_handling.ImageDefinition("buildings", (40, 0)), 2: utility.image_handling.ImageDefinition("buildings", (50, 0)), 3: utility.image_handling.ImageDefinition("buildings", (40, 10)), 4: utility.image_handling.ImageDefinition("buildings", (50, 10))} TRANSPORT_IMAGE_DEFINITION: ClassVar[utility.image_handling.ImageDefinition] = \ utility.image_handling.ImageDefinition("buildings", (40, 0), size=util.Size(20, 20), image_size=con.TRANSPORT_BLOCK_SIZE)
def __check_tasks(self): if len(self._worker.task_queue) != self._previous_number_tasks: self._previous_number_tasks = len(self._worker.task_queue) for widget in self._task_information_pane.widgets: print(widget) self._task_information_pane.remove_widget(widget) for task in self._worker.task_queue.tasks: task_label = widgets.Label(util.Size(130, 10), text=str(task), text_pos=["west", "center"], selectable=False) self._task_information_pane.add_widget(task_label)
def __init__(self, sheet_name: str, image_location: Tuple[int, int], color_key: Tuple[int, int, int] = con.INVISIBLE_COLOR, flip: Tuple[bool, bool] = (False, False), image_size: util.Size = con.BLOCK_SIZE, size: util.Size = util.Size(10, 10)): self.__sheet_name = sheet_name self.__image_location = image_location self.__color_key = color_key self.__flip = flip self.__size = size self.__image_size = image_size self.__images = []
def _create_recipe_grid(self): grid = base_recipes.RecipeGrid(util.Size(3, 3)) row1 = [ ground_materials.Stone, ground_materials.Stone, ground_materials.Stone ] row2 = [ ground_materials.Stone, ground_materials.Coal, ground_materials.Stone ] grid.add_all_rows(row1, row2, row1) return grid
class LoadFileWindow(base_interface.Window): # not in use currently but can come in handy when loading from within the game SIZE: util.Size = util.Size(350, 400) COLOR: Union[Tuple[int, int, int, int], Tuple[int, int, int], List[int]] = (173, 94, 29) def __init__(self, pos, sprite_group): super().__init__(pos, self.SIZE, sprite_group, title="CHOOSE A FILE", static=False, color=self.COLOR, movable=False, top_window=True) self.__init_widgets() 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 load_file(self, file_name): screen = scenes.scenes["Game"].screen scenes.Game.load_game(file_name, screen)
class Popup(base_interface.Window, ABC): SIZE: util.Size = util.Size(200, 100) COLOR: Union[Tuple[int, int, int, int], Tuple[int, int, int], List[int]] = (150, 150, 150) def __init__(self, pos, sprite_group, **kwargs): super().__init__(pos, self.SIZE, sprite_group, static=False, color=self.COLOR, movable=False, top_window=True, **kwargs) self.response = False
def __init__(self, pos: Union[Tuple[int, int], List[int]], size: Union[util.Size, Tuple[int, int], List[int]], *groups: "sprite_groups.CameraAwareLayeredUpdates", color=COLOR, title: Union[str, None] = None, static: bool = False, movable: bool = True, top_window: bool = False, **kwargs): super().__init__(pos, size + self.TOP_SIZE, *groups, color=color, static=static, pausable=False, **kwargs) if not isinstance(size, util.Size): size = util.Size(*size) # values for moving static windows self._is_window_moving = False self.__previous_board_pos = None self._movable = movable self.is_top_window = top_window self._is_window_showing = False self._is_window_focussed = False self.id = "window {}".format(self.ID) Window.ID += 1 # make closable with escape self.add_key_event_listener(K_ESCAPE, self._close_window, types=["unpressed"]) self.__add_top_border(size, title)
def _create_recipe_grid(self) -> RecipeGrid: return RecipeGrid(util.Size(0, 0))
class SaveFileWindow(base_interface.Window): SIZE: util.Size = util.Size(350, 400) COLOR: Union[Tuple[int, int, int, int], Tuple[int, int, int], List[int]] = (173, 94, 29) def __init__(self, pos, sprite_group): super().__init__(pos, self.SIZE, sprite_group, title="CHOOSE A FILE", static=False, color=self.COLOR, movable=False, top_window=True) self.__init_widgets() self.__create_name_popup = None self.__overwrite_file_popup = None def __init_widgets(self): save_label = widgets.Label(util.Size(200, 30), text="Choose a save file:", 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) new_button = widgets.Button(util.Size(file_list.rect.width, 25), text="New...", font_size=25, color=self.COLOR) new_button.add_key_event_listener(1, self.create_new_file_window, types=["unpressed"]) file_list.add_widget(new_button) 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.confirm_overwrite_window, values=[file], types=["unpressed"]) file_list.add_widget(file_button) def update(self, *args): super().update(*args) self.check_popups() def check_popups(self): if self.__create_name_popup is not None and not self.__create_name_popup.is_showing( ): response = self.__create_name_popup.response self.__create_name_popup = None if response is not False: self.save_game(response) if self.__overwrite_file_popup is not None and not self.__overwrite_file_popup.is_showing( ): response = self.__overwrite_file_popup.response self.__overwrite_file_popup = None if response is not False: self.save_game(response) def save_game(self, file_name): # since dots are not allowed to be in file names this should be savem file_name = file_name.replace(".save", "") scenes.scenes["Game"].save(file_name) self._close_window() def create_new_file_window(self): from interfaces.managers import game_window_manager self.__create_name_popup = GiveNamePopup( (self.rect.width / 2 - GiveNamePopup.SIZE.width / 2 + self.rect.left, self.rect.height / 2 - GiveNamePopup.SIZE.height / 2 + self.rect.top), self.groups()[0]) game_window_manager.add(self.__create_name_popup) def confirm_overwrite_window(self, file_name): from interfaces.managers import game_window_manager self.__overwrite_file_popup = \ ConfirmPopup((self.rect.width / 2 - GiveNamePopup.SIZE.width / 2 + self.rect.left, self.rect.height / 2 - GiveNamePopup.SIZE.height / 2 + self.rect.top), f"WARNING: '{file_name}'\n will be overwritten", file_name, self.groups()[0]) game_window_manager.add(self.__overwrite_file_popup)
def _create_recipe_grid(self): grid = base_recipes.RecipeGrid(util.Size(2, 2)) row = [ground_materials.Stone, ground_materials.Stone] grid.add_all_rows(row, row) return grid
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)