Quit-Rolling-Around-gmtk-ja.../UI/DiceView.gd

70 lines
1.8 KiB
GDScript3
Raw Normal View History

2022-07-16 21:33:47 +01:00
extends Control
2022-07-17 14:32:42 +01:00
signal dice_selected (dice_value)
2022-07-16 21:33:47 +01:00
const dice = preload("res://UI/Dice.tscn")
2022-07-17 13:05:20 +01:00
var selected : bool = false
var selected_dice = null
2022-07-16 21:33:47 +01:00
var current_dice = []
2022-07-17 13:05:20 +01:00
func _physics_process(delta):
# no keyboard input if not selected
if not selected:
selected_dice = null
return
# if selected dice is null, add a value
if not selected_dice:
selected_dice = 0
# TODO: maybe support actual dicrectional selection
# move the selection forward or backward the list depending on input
if (Input.is_action_just_pressed("ui_up") or
Input.is_action_just_pressed("ui_left")):
current_dice[selected_dice].selected = false
2022-07-17 13:05:20 +01:00
selected_dice += 1
if selected_dice >= len(current_dice):
2022-07-17 13:05:20 +01:00
selected_dice = 0
if (Input.is_action_just_pressed("ui_down") or
Input.is_action_just_pressed("ui_right")):
current_dice[selected_dice].selected = false
2022-07-17 13:05:20 +01:00
selected_dice -= 1
if selected_dice < 0:
2022-07-17 13:05:20 +01:00
selected_dice = len(current_dice) -1
# enable the selected shader
current_dice[selected_dice].selected = true
2022-07-17 14:32:42 +01:00
#if the enter key is pressed, remove the selected dice and emit the signal
if Input.is_action_just_pressed("ui_accept"):
emit_signal("dice_selected", current_dice[selected_dice].dice_value)
print(current_dice[selected_dice].dice_value)
print("current_dice[selected_dice].dice_value")
2022-07-17 14:32:42 +01:00
current_dice[selected_dice].queue_free()
current_dice.remove(selected_dice)
selected_dice = null
selected = false
2022-07-17 13:05:20 +01:00
2022-07-16 21:33:47 +01:00
func roll_dice(specific_value : int = 0):
# make a new dice instance and add it to the grid container
var new_dice = dice.instance()
$Margin/AutoGrid.add_child(new_dice)
# if a specifc dice choosen, make new dice that type
if specific_value in [1, 2, 3, 4, 5, 6]:
new_dice.dice_value = specific_value
# add the current dice to the list of dice
current_dice.append(new_dice)