From 1a622ff3b1e0bae39d90a143744d2009720eabcb Mon Sep 17 00:00:00 2001 From: Rob Kelly Date: Thu, 21 Nov 2024 16:20:51 -0700 Subject: [PATCH] Added cool curve bar --- src/ui/decorations/arc.gd | 36 +++++- .../shot_hud/club_selector/club_selector.tscn | 2 +- src/ui/shot_hud/curve_bar/curve_bar.gd | 26 +++++ src/ui/shot_hud/curve_bar/curve_bar.tscn | 103 ++++++++++++++++++ .../curve_bar/one_sided_gradient.tres | 6 + .../shot_hud/curve_bar/standard_gradient.tres | 6 + src/ui/shot_hud/shot_hud.gd | 6 +- src/ui/shot_hud/shot_hud.tscn | 15 +-- 8 files changed, 178 insertions(+), 22 deletions(-) create mode 100644 src/ui/shot_hud/curve_bar/curve_bar.gd create mode 100644 src/ui/shot_hud/curve_bar/curve_bar.tscn create mode 100644 src/ui/shot_hud/curve_bar/one_sided_gradient.tres create mode 100644 src/ui/shot_hud/curve_bar/standard_gradient.tres diff --git a/src/ui/decorations/arc.gd b/src/ui/decorations/arc.gd index c488a24..757838d 100644 --- a/src/ui/decorations/arc.gd +++ b/src/ui/decorations/arc.gd @@ -3,15 +3,39 @@ class_name Arc extends Control const BASE_POINTS := 64 -@export var gap_angle := 0.1 -@export var width := 1.0 -@export var antialiased := true -@export var color: Color +@export_range(-360, 360, 0.001, "radians") var arc_start := 0.1: + set(value): + arc_start = value + queue_redraw() +@export_range(-360, 360, 0.001, "radians") var arc_end := TAU: + set(value): + arc_end = value + queue_redraw() +@export var width := 1.0: + set(value): + width = value + queue_redraw() +@export var antialiased := true: + set(value): + antialiased = value + queue_redraw() +@export var color: Color: + set(value): + color = value + queue_redraw() func _draw() -> void: var radius: float = minf(size.x, size.y) / 2.0 - var point_count: int = int(BASE_POINTS * (TAU - gap_angle) / TAU) + var width_buffer: float = floor(width / 2.0) + var point_count: int = int(BASE_POINTS * (arc_end - arc_start) / TAU) draw_arc( - Vector2(radius, radius), radius, gap_angle, TAU, point_count, color, width, antialiased + Vector2(radius, radius), + radius - width_buffer, + arc_start, + arc_end, + point_count, + color, + width, + antialiased ) diff --git a/src/ui/shot_hud/club_selector/club_selector.tscn b/src/ui/shot_hud/club_selector/club_selector.tscn index 6a49964..74f3450 100644 --- a/src/ui/shot_hud/club_selector/club_selector.tscn +++ b/src/ui/shot_hud/club_selector/club_selector.tscn @@ -68,7 +68,7 @@ grow_horizontal = 2 grow_vertical = 2 pivot_offset = Vector2(300, 300) script = ExtResource("2_vijl7") -gap_angle = 0.6 +arc_start = 0.610865 width = 36.0 color = Color(0, 0, 0, 0.392157) diff --git a/src/ui/shot_hud/curve_bar/curve_bar.gd b/src/ui/shot_hud/curve_bar/curve_bar.gd new file mode 100644 index 0000000..9db9674 --- /dev/null +++ b/src/ui/shot_hud/curve_bar/curve_bar.gd @@ -0,0 +1,26 @@ +@tool +class_name CurveBar extends Control +## Swinging arc used to set the curve of a shot. + +const PIVOT_SCALE := -PI / 4 + +@export var gradient: Gradient: + set(value): + if gradient_tex: + gradient_tex.gradient = value + gradient = value + +@export var value: float: + set(v): + if pivot: + pivot.rotation = v * PIVOT_SCALE + get: + return pivot.rotation / PIVOT_SCALE if pivot else 0 + +@onready var pivot: Control = %Pivot +@onready var gradient_fill: TextureRect = %GradientFill +@onready var gradient_tex: GradientTexture2D = gradient_fill.texture + + +func _ready() -> void: + gradient = gradient diff --git a/src/ui/shot_hud/curve_bar/curve_bar.tscn b/src/ui/shot_hud/curve_bar/curve_bar.tscn new file mode 100644 index 0000000..c64207a --- /dev/null +++ b/src/ui/shot_hud/curve_bar/curve_bar.tscn @@ -0,0 +1,103 @@ +[gd_scene load_steps=6 format=3 uid="uid://mm02j126jo1h"] + +[ext_resource type="Script" path="res://src/ui/shot_hud/curve_bar/curve_bar.gd" id="1_aqvdi"] +[ext_resource type="Gradient" uid="uid://k7867gxaxx57" path="res://src/ui/shot_hud/curve_bar/one_sided_gradient.tres" id="2_f3fom"] +[ext_resource type="Texture2D" uid="uid://du3vk5nnksohs" path="res://assets/sprites/particles/sparkle.png" id="3_2tv33"] +[ext_resource type="Script" path="res://src/ui/decorations/arc.gd" id="4_s2bpl"] + +[sub_resource type="GradientTexture2D" id="GradientTexture2D_o88ik"] +gradient = ExtResource("2_f3fom") +width = 128 +height = 128 +fill = 1 +fill_from = Vector2(0.5, 0.02) +fill_to = Vector2(0.5, 0.37) +metadata/_snap_enabled = true + +[node name="CurveBar" type="Control"] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1_aqvdi") +gradient = ExtResource("2_f3fom") + +[node name="Reticle" type="TextureRect" parent="."] +texture_filter = 1 +layout_mode = 1 +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = -20.0 +offset_top = -20.0 +offset_right = 20.0 +offset_bottom = 20.0 +grow_horizontal = 2 +grow_vertical = 2 +texture = ExtResource("3_2tv33") + +[node name="Pivot" type="Control" parent="Reticle"] +unique_name_in_owner = true +show_behind_parent = true +texture_filter = 6 +custom_minimum_size = Vector2(600, 600) +layout_mode = 1 +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = -300.0 +offset_top = -32.0 +offset_right = 300.0 +offset_bottom = 568.0 +grow_horizontal = 2 +grow_vertical = 2 +pivot_offset = Vector2(300, 300) + +[node name="ArcBG" type="Control" parent="Reticle/Pivot"] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("4_s2bpl") +arc_start = -2.35619 +arc_end = -0.785398 +width = 32.0 +color = Color(0.0352941, 0.0784314, 0.160784, 0.784314) + +[node name="MarginContainer" type="MarginContainer" parent="Reticle/Pivot"] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +theme_override_constants/margin_left = 3 +theme_override_constants/margin_top = 3 +theme_override_constants/margin_right = 3 +theme_override_constants/margin_bottom = 3 + +[node name="ArcFill" type="Control" parent="Reticle/Pivot/MarginContainer"] +clip_children = 1 +layout_mode = 2 +script = ExtResource("4_s2bpl") +arc_start = -2.35619 +arc_end = -0.785398 +width = 26.0 + +[node name="GradientFill" type="TextureRect" parent="Reticle/Pivot/MarginContainer/ArcFill"] +unique_name_in_owner = true +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +texture = SubResource("GradientTexture2D_o88ik") diff --git a/src/ui/shot_hud/curve_bar/one_sided_gradient.tres b/src/ui/shot_hud/curve_bar/one_sided_gradient.tres new file mode 100644 index 0000000..5201793 --- /dev/null +++ b/src/ui/shot_hud/curve_bar/one_sided_gradient.tres @@ -0,0 +1,6 @@ +[gd_resource type="Gradient" format=3 uid="uid://k7867gxaxx57"] + +[resource] +interpolation_color_space = 2 +offsets = PackedFloat32Array(0, 0.25, 0.5, 0.75, 1) +colors = PackedColorArray(1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0) diff --git a/src/ui/shot_hud/curve_bar/standard_gradient.tres b/src/ui/shot_hud/curve_bar/standard_gradient.tres new file mode 100644 index 0000000..88d53d0 --- /dev/null +++ b/src/ui/shot_hud/curve_bar/standard_gradient.tres @@ -0,0 +1,6 @@ +[gd_resource type="Gradient" format=3 uid="uid://3achrua4vnny"] + +[resource] +interpolation_color_space = 2 +offsets = PackedFloat32Array(0, 0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875, 1) +colors = PackedColorArray(1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0) diff --git a/src/ui/shot_hud/shot_hud.gd b/src/ui/shot_hud/shot_hud.gd index 4098c8e..d818970 100644 --- a/src/ui/shot_hud/shot_hud.gd +++ b/src/ui/shot_hud/shot_hud.gd @@ -9,7 +9,7 @@ const LIFE_BAR_DAMAGE_RUMBLE_TIME := 0.2 var player: WorldPlayer @onready var power_bar: TextureProgressBar = %PowerBar -@onready var curve_bar: ProgressBar = %CurveBar +@onready var curve_bar: CurveBar = %CurveBar @onready var life_bar: TextureProgressBar = %LifeBar @onready var club_selector: ClubSelector = %ClubSelector @@ -111,8 +111,8 @@ func set_life_value(new_value: float) -> void: life_bar.value = new_value -static func create(player: WorldPlayer) -> ShotHUD: +static func create(_player: WorldPlayer) -> ShotHUD: var instance: ShotHUD = scene.instantiate() - instance.player = player + instance.player = _player return instance diff --git a/src/ui/shot_hud/shot_hud.tscn b/src/ui/shot_hud/shot_hud.tscn index e8490e6..d5b9506 100644 --- a/src/ui/shot_hud/shot_hud.tscn +++ b/src/ui/shot_hud/shot_hud.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=34 format=3 uid="uid://c4ifdiohng830"] +[gd_scene load_steps=35 format=3 uid="uid://c4ifdiohng830"] [ext_resource type="Script" path="res://src/ui/shot_hud/shot_hud.gd" id="1_x5b4c"] [ext_resource type="Shader" path="res://src/shaders/canvas_retro.gdshader" id="1_ybxxp"] @@ -7,6 +7,7 @@ [ext_resource type="Texture2D" uid="uid://b5812y3pmmgg5" path="res://assets/ui/gauge_patch.png" id="4_5kcpe"] [ext_resource type="Texture2D" uid="uid://76fjx2ukavqe" path="res://assets/ui/power_gauge_fill.png" id="5_3i1yq"] [ext_resource type="Texture2D" uid="uid://4a8tvjgwegv3" path="res://assets/ui/power_gauge_tab.png" id="6_sw48q"] +[ext_resource type="PackedScene" uid="uid://mm02j126jo1h" path="res://src/ui/shot_hud/curve_bar/curve_bar.tscn" id="7_kqi7w"] [ext_resource type="PackedScene" uid="uid://b0yr0w0xv8cm5" path="res://src/ui/shot_hud/ball_selector/ball_selector.tscn" id="8_b2302"] [ext_resource type="FontFile" uid="uid://dsa0oh7c0h4pu" path="res://assets/fonts/Racing_Sans_One/RacingSansOne-Regular.ttf" id="8_bejx4"] [ext_resource type="Texture2D" uid="uid://tancoet1lih5" path="res://assets/ui/ball_icons/basic_icon.png" id="8_tt8i3"] @@ -718,19 +719,9 @@ grow_horizontal = 2 grow_vertical = 2 mouse_filter = 1 -[node name="CurveBar" type="ProgressBar" parent="ShotGauges/CurveGauge"] +[node name="CurveBar" parent="ShotGauges/CurveGauge" instance=ExtResource("7_kqi7w")] unique_name_in_owner = true -visible = false layout_mode = 1 -anchors_preset = 15 -anchor_right = 1.0 -anchor_bottom = 1.0 -offset_top = -13.5 -offset_bottom = 13.5 -grow_horizontal = 2 -grow_vertical = 2 -min_value = -1.0 -max_value = 1.0 [node name="CurveAnimation" type="AnimationPlayer" parent="ShotGauges/CurveGauge"] unique_name_in_owner = true