summaryrefslogtreecommitdiff
path: root/ui/login/character_selection_item.gd
blob: 7ad77b68375ddffeb83dd1ae5b9d9ce226258016 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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)