From e52716c79306ae82fb6d7a6ea5deb00440e92eb8 Mon Sep 17 00:00:00 2001 From: CactiChameleon9 Date: Sat, 16 Jul 2022 21:33:47 +0100 Subject: [PATCH] Add dice and diceview --- UI/Dice.gd | 16 ++++++++++++++++ UI/Dice.tscn | 12 ++++++++++++ UI/DiceView.gd | 17 +++++++++++++++++ UI/DiceView.tscn | 40 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 85 insertions(+) create mode 100644 UI/Dice.gd create mode 100644 UI/Dice.tscn create mode 100644 UI/DiceView.gd create mode 100644 UI/DiceView.tscn diff --git a/UI/Dice.gd b/UI/Dice.gd new file mode 100644 index 0000000..3ff0b7b --- /dev/null +++ b/UI/Dice.gd @@ -0,0 +1,16 @@ +tool +extends Control + +const dice_image_string = "res://Assets/Dice/Dice%s.png" + +export (int, 1, 6) var dice_value : int setget _set_dice_value + +func _set_dice_value(new_value): + dice_value = new_value + self.texture = load(dice_image_string % new_value) + + +func _ready(): + randomize() + + self.dice_value = round(rand_range(0.5, 6.49999999)) diff --git a/UI/Dice.tscn b/UI/Dice.tscn new file mode 100644 index 0000000..a3550b8 --- /dev/null +++ b/UI/Dice.tscn @@ -0,0 +1,12 @@ +[gd_scene load_steps=2 format=2] + +[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 +expand = true +stretch_mode = 6 +script = ExtResource( 2 ) diff --git a/UI/DiceView.gd b/UI/DiceView.gd new file mode 100644 index 0000000..a786673 --- /dev/null +++ b/UI/DiceView.gd @@ -0,0 +1,17 @@ +extends Control + +const dice = preload("res://UI/Dice.tscn") + +var current_dice = [] + +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 new file mode 100644 index 0000000..bb2ded9 --- /dev/null +++ b/UI/DiceView.tscn @@ -0,0 +1,40 @@ +[gd_scene load_steps=6 format=2] + +[ext_resource path="res://AutoGridContainer - Full Version/AutoGridContainer.tscn" type="PackedScene" id=1] +[ext_resource path="res://UI/DiceView.gd" type="Script" id=2] +[ext_resource path="res://UI/Dice.tscn" type="PackedScene" id=3] +[ext_resource path="res://Assets/Dice/Dice6.png" type="Texture" id=4] +[ext_resource path="res://Assets/Dice/Dice1.png" type="Texture" id=5] + +[node name="DiceView" type="Control"] +anchor_right = 1.0 +anchor_bottom = 1.0 +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 + +[node name="Dice" parent="Margin/AutoGrid" instance=ExtResource( 3 )] +texture = ExtResource( 5 ) +dice_value = 1 + +[node name="Dice2" parent="Margin/AutoGrid" instance=ExtResource( 3 )] +texture = ExtResource( 5 ) +dice_value = 1 + +[node name="Dice3" parent="Margin/AutoGrid" instance=ExtResource( 3 )] +texture = ExtResource( 5 ) +dice_value = 1 + +[node name="Dice4" parent="Margin/AutoGrid" instance=ExtResource( 3 )] +texture = ExtResource( 4 ) +dice_value = 6