summaryrefslogtreecommitdiff
path: root/ui/login/character_selection_item.gd
diff options
context:
space:
mode:
authorDaniel Weipert <git@mail.dweipert.de>2024-12-24 00:36:06 +0100
committerDaniel Weipert <git@mail.dweipert.de>2024-12-24 00:36:06 +0100
commit6e2deea3d1b2fb4d79dac02a0d4310936c7f317c (patch)
tree05590a7d9f7cecde037aad7a5487ff2c62176932 /ui/login/character_selection_item.gd
parent7b3f386449aeab124d84d2aff4c273e646e68763 (diff)
next commit
Diffstat (limited to 'ui/login/character_selection_item.gd')
-rw-r--r--ui/login/character_selection_item.gd57
1 files changed, 57 insertions, 0 deletions
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)