Add dice and diceview

This commit is contained in:
CactiChameleon9 2022-07-16 21:33:47 +01:00
parent 70c4ba38e2
commit e52716c793
4 changed files with 85 additions and 0 deletions

16
UI/Dice.gd Normal file
View File

@ -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))

12
UI/Dice.tscn Normal file
View File

@ -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 )

17
UI/DiceView.gd Normal file
View File

@ -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)

40
UI/DiceView.tscn Normal file
View File

@ -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