From 6e2deea3d1b2fb4d79dac02a0d4310936c7f317c Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Tue, 24 Dec 2024 00:36:06 +0100 Subject: next commit --- ui/login/character_selection_item.gd | 57 ++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 ui/login/character_selection_item.gd (limited to 'ui/login/character_selection_item.gd') diff --git a/ui/login/character_selection_item.gd b/ui/login/character_selection_item.gd new file mode 100644 index 0000000..7ad77b6 --- /dev/null +++ b/ui/login/character_selection_item.gd @@ -0,0 +1,57 @@ +class_name CharacterSelectionItem +extends PanelContainer + + +signal selected + +static var selected_item: CharacterSelectionItem: + set(value): + var previous_item = selected_item + selected_item = value + if previous_item: + previous_item.draw_highlight(false) + +var is_hovered := false + + +func initialize_with_info(info: CharacterInformation): + %Head.texture = load( + "%s/%s/000.png" % [ + "res://client_data/data/sprite", + Constants.FilePaths.get_player_head(info.gender, info.head), + ] + ) + + %Body.texture = load( + "%s/%s/000.png" % [ + "res://client_data/data/sprite", + Constants.FilePaths.get_player_body(info.gender, info.job), + ] + ) + + %Name.text = info.name + + +func draw_highlight(is_highlighted: bool): + if selected_item == self: + is_highlighted = true + + var style_box: StyleBoxFlat = get_theme_stylebox("panel").duplicate() + style_box.draw_center = is_highlighted + add_theme_stylebox_override("panel", style_box) + + +func _on_gui_input(event: InputEvent) -> void: + if event.is_pressed(): + selected_item = self + draw_highlight(true) + selected.emit() + + +func _on_mouse_entered() -> void: + is_hovered = true + draw_highlight(is_hovered) + +func _on_mouse_exited() -> void: + is_hovered = false + draw_highlight(is_hovered) -- cgit v1.2.3