diff --git a/Characters/Character.gd b/Characters/Character.gd index 89a32f9..7cb5035 100644 --- a/Characters/Character.gd +++ b/Characters/Character.gd @@ -12,6 +12,8 @@ onready var target_position : Vector2 = position var moving : bool = false var cards = [] setget ,get_cards +var dice = [] + func get_cards(): for child in get_children(): diff --git a/UI/Dice.gd b/UI/Dice.gd deleted file mode 100644 index 5f32cab..0000000 --- a/UI/Dice.gd +++ /dev/null @@ -1,31 +0,0 @@ -tool -extends Control - -const dice_image_string = "res://Assets/Dice/Dice%s.png" -const selected_shader = preload("res://UI/RainbowOutline.tres") - -export (int, 0, 6) var dice_value : int = 0 -export var selected : bool setget _set_selected - - -func _set_selected(new_value): - selected = new_value - if selected: - self.material = selected_shader - else: - self.material = null - - -func _physics_process(delta): - self.texture = load(dice_image_string % dice_value) - - -func _ready(): - randomize() - - if dice_value == 0: - self.dice_value = int(round(rand_range(0.5, 6.49999999))) - - _physics_process(0) - - diff --git a/UI/Dice.tscn b/UI/Dice.tscn deleted file mode 100644 index b95c2e2..0000000 --- a/UI/Dice.tscn +++ /dev/null @@ -1,14 +0,0 @@ -[gd_scene load_steps=3 format=2] - -[ext_resource path="res://Assets/Dice/Dice6.png" type="Texture" id=1] -[ext_resource path="res://UI/Dice.gd" type="Script" id=2] - -[node name="Dice" type="TextureRect"] -margin_right = 100.0 -margin_bottom = 100.0 -size_flags_horizontal = 3 -size_flags_vertical = 3 -texture = ExtResource( 1 ) -expand = true -stretch_mode = 6 -script = ExtResource( 2 ) diff --git a/UI/DiceContainer.tscn b/UI/DiceContainer.tscn new file mode 100644 index 0000000..5230ea5 --- /dev/null +++ b/UI/DiceContainer.tscn @@ -0,0 +1,26 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://AutoGridContainer - Full Version/AutoGridContainer.tscn" type="PackedScene" id=1] +[ext_resource path="res://UI/ItemContainer.gd" type="Script" id=2] +[ext_resource path="res://UI/DiceView.tscn" type="PackedScene" id=3] + +[node name="DiceContainer" type="Control"] +anchor_right = 1.0 +anchor_bottom = 1.0 +script = ExtResource( 2 ) +item_view_scene = ExtResource( 3 ) +child_holder = NodePath("Margin/AutoGrid") +character_property = "dice" +view_property = "dice_value" + +[node name="Margin" type="MarginContainer" parent="."] +anchor_right = 1.0 +anchor_bottom = 1.0 +margin_left = 30.0 +margin_top = 30.0 +margin_right = -30.0 +margin_bottom = -30.0 + +[node name="AutoGrid" parent="Margin" instance=ExtResource( 1 )] +margin_right = 1220.0 +margin_bottom = 660.0 diff --git a/UI/DiceView.gd b/UI/DiceView.gd index f2fa098..9cd9b73 100644 --- a/UI/DiceView.gd +++ b/UI/DiceView.gd @@ -1,76 +1,22 @@ +tool extends Control -signal dice_selected (dice_value) -signal scene_finished -signal scene_failed +const dice_image_string = "res://Assets/Dice/Dice%s.png" +const selected_shader = preload("res://UI/RainbowOutline.tres") -var active : bool = false - -const dice = preload("res://UI/Dice.tscn") - -var selected : bool = false -var selected_dice = null - -var current_dice = [] +export (int, 0, 6) var dice_value : int = 0 +export var selected : bool setget set_selected -func _physics_process(delta): - - # no keyboard input if not selected - if not selected: - selected_dice = null - return - - # skip turn if the list is empty - if len(current_dice) == 0: - selected = false - 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 - - selected_dice += 1 - if selected_dice >= len(current_dice): - 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 - - selected_dice -= 1 - if selected_dice < 0: - selected_dice = len(current_dice) -1 - - # enable the selected shader - current_dice[selected_dice].selected = true - - #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) - - current_dice[selected_dice].queue_free() - current_dice.remove(selected_dice) - selected_dice = null - selected = false +func set_selected(new_value): + selected = new_value + if selected: + self.material = selected_shader + else: + self.material = null + + +func _physics_process(_delta): + self.texture = load(dice_image_string % dice_value) -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) diff --git a/UI/DiceView.tscn b/UI/DiceView.tscn index 880c24e..62c9dfa 100644 --- a/UI/DiceView.tscn +++ b/UI/DiceView.tscn @@ -1,21 +1,15 @@ [gd_scene load_steps=3 format=2] -[ext_resource path="res://AutoGridContainer - Full Version/AutoGridContainer.tscn" type="PackedScene" id=1] +[ext_resource path="res://Assets/Dice/Dice6.png" type="Texture" id=1] [ext_resource path="res://UI/DiceView.gd" type="Script" id=2] -[node name="DiceView" type="Control"] -anchor_right = 1.0 -anchor_bottom = 1.0 +[node name="DiceView" type="TextureRect"] +margin_right = 100.0 +margin_bottom = 100.0 +size_flags_horizontal = 3 +size_flags_vertical = 3 +texture = ExtResource( 1 ) +expand = true +stretch_mode = 6 script = ExtResource( 2 ) - -[node name="Margin" type="MarginContainer" parent="."] -anchor_right = 1.0 -anchor_bottom = 1.0 -margin_left = 30.0 -margin_top = 30.0 -margin_right = -30.0 -margin_bottom = -30.0 - -[node name="AutoGrid" parent="Margin" instance=ExtResource( 1 )] -margin_right = 1220.0 -margin_bottom = 660.0 +dice_value = 6