def handle_mouse_movement(self, mouse_screen_pos: Tuple[int, int]): self.mouse_screen_position = mouse_screen_pos self.is_mouse_hovering_ui = is_point_in_rect(mouse_screen_pos, self.ui_screen_area) mouse_ui_position = self._translate_screen_position_to_ui( mouse_screen_pos) simple_components = [ self.healthbar, self.manabar, self.sound_checkbox, self.save_button, self.fullscreen_checkbox ] + self.ability_icons + self.toggle_buttons for component in simple_components: if component.contains(mouse_ui_position): self._on_hover_component(component) return # TODO Unify hover handling for consumables/items for icon in self.consumable_icons + self.inventory_icons: collision_offset = icon.get_collision_offset(mouse_ui_position) if collision_offset: self._on_hover_component(icon) return # TODO Unify hover handling of window icons if self.talents_window.shown: hovered_icon = self.talents_window.get_icon_containing( mouse_ui_position) if hovered_icon: self._on_hover_component(hovered_icon) return # If something was hovered, we would have returned from the method self._set_currently_hovered_component_not_hovered()
def handle_mouse_movement_in_dialog(self, mouse_screen_pos: Tuple[int, int]): self.mouse_screen_position = mouse_screen_pos self.is_mouse_hovering_ui = is_point_in_rect(mouse_screen_pos, self.ui_screen_area) self.dialog.handle_mouse_movement(mouse_screen_pos)
def handle_mouse_movement(self, mouse_screen_pos: Tuple[int, int]): self.mouse_screen_position = mouse_screen_pos self.is_mouse_hovering_ui = is_point_in_rect(mouse_screen_pos, self.ui_screen_area) self._check_for_hovered_components()
def render( self, entities: List[MapEditorWorldEntity], placing_entity: Optional[MapEditorWorldEntity], deleting_entities: bool, deleting_decorations: bool, num_enemies: int, num_walls: int, num_decorations: int, grid_cell_size: int, mouse_screen_position: Tuple[int, int], camera_rect_ratio: Tuple[float, float, float, float], npc_positions_ratio: List[Tuple[float, float]], wall_positions_ratio: List[Tuple[float, float]] ) -> Optional[MapEditorWorldEntity]: mouse_ui_position = self._translate_screen_position_to_ui( mouse_screen_position) hovered_by_mouse: MapEditorWorldEntity = None self.screen_render.rect( COLOR_BLACK, Rect(0, 0, self.camera_size[0], self.camera_size[1]), 3) self.screen_render.rect_filled( COLOR_BLACK, Rect(0, self.camera_size[1], self.screen_size[0], self.screen_size[1] - self.camera_size[1])) icon_space = 5 y_1 = 10 y_2 = y_1 + 30 x_0 = 20 # TODO Handle all these icons as state, similarly to how the game UI is done, and the tab radio buttons self._map_editor_icon_in_ui(x_0, y_2, MAP_EDITOR_UI_ICON_SIZE, deleting_entities, 'Q', None, UiIconSprite.MAP_EDITOR_TRASHCAN) self._map_editor_icon_in_ui( x_0 + MAP_EDITOR_UI_ICON_SIZE[0] + icon_space, y_2, MAP_EDITOR_UI_ICON_SIZE, deleting_decorations, 'Z', None, UiIconSprite.MAP_EDITOR_RECYCLING) x_1 = 155 num_icons_per_row = 23 for i, entity in enumerate(entities): is_this_entity_being_placed = entity is placing_entity x = x_1 + (i % num_icons_per_row) * (MAP_EDITOR_UI_ICON_SIZE[0] + icon_space) row_index = (i // num_icons_per_row) y = y_2 + row_index * (MAP_EDITOR_UI_ICON_SIZE[1] + icon_space) if is_point_in_rect( mouse_ui_position, Rect(x, y, MAP_EDITOR_UI_ICON_SIZE[0], MAP_EDITOR_UI_ICON_SIZE[1])): hovered_by_mouse = entity self._map_editor_icon_in_ui(x, y, MAP_EDITOR_UI_ICON_SIZE, is_this_entity_being_placed, '', entity.sprite, None) self.screen_render.rect(COLOR_WHITE, self.ui_screen_area, 1) self.screen_render.rect_transparent(Rect(0, 0, 150, 80), 100, COLOR_BLACK) self.screen_render.text(self.font_debug_info, "# enemies: " + str(num_enemies), (5, 3)) self.screen_render.text(self.font_debug_info, "# walls: " + str(num_walls), (5, 20)) self.screen_render.text(self.font_debug_info, "# decorations: " + str(num_decorations), (5, 37)) self.screen_render.text(self.font_debug_info, "Cell size: " + str(grid_cell_size), (5, 54)) self._render_minimap(camera_rect_ratio, npc_positions_ratio, wall_positions_ratio) for button in self.tab_buttons.values(): button.render() for checkbox in self.checkboxes: checkbox.render() return hovered_by_mouse