summaryrefslogtreecommitdiff
path: root/ui/dice_configurator/dice_configurator.gd
blob: c347dd77718d9ef9cf6cd05ceabb0c3b9ea31a4b (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
58
59
60
61
62
extends Control


@export var dice_configuration: DiceConfiguration

var rotate_tween: Tween


func _ready() -> void:
	%FaceFront.texture = DiceFace.get_face_type_icon(dice_configuration.front_face.type)
	%FaceBack.texture = DiceFace.get_face_type_icon(dice_configuration.back_face.type)
	%FaceLeft.texture = DiceFace.get_face_type_icon(dice_configuration.left_face.type)
	%FaceRight.texture = DiceFace.get_face_type_icon(dice_configuration.right_face.type)
	%FaceTop.texture = DiceFace.get_face_type_icon(dice_configuration.top_face.type)
	%FaceBottom.texture = DiceFace.get_face_type_icon(dice_configuration.bottom_face.type)
	
	rotate_tween = get_tree().create_tween()
	
	%DiceConfigurationFacePreviewFront.grab_focus()


func set_face_active(face: Control) -> void:
	for node in %DiceConfigurationPreview.get_children():
		node.active = false
	
	face.active = true


func rotate_dice(target: Vector3) -> void:
	rotate_tween.stop()
	rotate_tween = get_tree().create_tween()
	rotate_tween.tween_property(%Dice, "rotation", target, 0.5)


func _on_dice_configuration_face_preview_front_focus_entered() -> void:
	rotate_dice(Vector3.ZERO)
	set_face_active(%DiceConfigurationFacePreviewFront)


func _on_dice_configuration_face_preview_back_focus_entered() -> void:
	rotate_dice(Vector3(0, deg_to_rad(180), 0))
	set_face_active(%DiceConfigurationFacePreviewBack)


func _on_dice_configuration_face_preview_left_focus_entered() -> void:
	rotate_dice(Vector3(0, deg_to_rad(90), 0))
	set_face_active(%DiceConfigurationFacePreviewLeft)


func _on_dice_configuration_face_preview_right_focus_entered() -> void:
	rotate_dice(Vector3(0, deg_to_rad(-90), 0))
	set_face_active(%DiceConfigurationFacePreviewRight)


func _on_dice_configuration_face_preview_top_focus_entered() -> void:
	rotate_dice(Vector3(deg_to_rad(90), 0, 0))
	set_face_active(%DiceConfigurationFacePreviewTop)


func _on_dice_configuration_face_preview_bottom_focus_entered() -> void:
	rotate_dice(Vector3(deg_to_rad(-90), 0, 0))
	set_face_active(%DiceConfigurationFacePreviewBottom)