Add barrier-based catch and chase mechanic
This commit is contained in:
parent
ad848f9431
commit
ae2f724fe2
12 changed files with 631 additions and 68 deletions
111
ui/game_ui.gd
111
ui/game_ui.gd
|
|
@ -6,13 +6,18 @@ const FishingSpotType = preload("res://fishing/fishing_spot.gd")
|
|||
|
||||
@onready var _status_label: Label = %StatusLabel
|
||||
@onready var _bluegill_count_label: Label = %BluegillCountLabel
|
||||
@onready var _reel_progress: ProgressBar = %ReelProgress
|
||||
@onready var _catch_track: Control = %CatchTrack
|
||||
@onready var _green_catch_progress: ProgressBar = %GreenCatchProgress
|
||||
@onready var _red_chase_progress: ProgressBar = %RedChaseProgress
|
||||
@onready var _barrier_markers: Control = %BarrierMarkers
|
||||
@onready var _barrier_summary: Label = %BarrierSummary
|
||||
@onready var _barrier_health: Label = %BarrierHealth
|
||||
|
||||
|
||||
func setup(inventory: FishInventoryType, fishing_spot: FishingSpotType) -> void:
|
||||
inventory.contents_changed.connect(_on_inventory_contents_changed)
|
||||
fishing_spot.status_changed.connect(_on_fishing_status_changed)
|
||||
fishing_spot.reel_progress_changed.connect(_on_reel_progress_changed)
|
||||
fishing_spot.catch_display_changed.connect(_on_catch_display_changed)
|
||||
_update_bluegill_count(inventory.get_count(&"bluegill"))
|
||||
|
||||
|
||||
|
|
@ -26,9 +31,105 @@ func _on_fishing_status_changed(status: String) -> void:
|
|||
_status_label.visible = not status.is_empty()
|
||||
|
||||
|
||||
func _on_reel_progress_changed(progress: float, visible: bool) -> void:
|
||||
_reel_progress.value = progress * 100.0
|
||||
_reel_progress.visible = visible
|
||||
func _on_catch_display_changed(
|
||||
progress: float,
|
||||
chase_progress: float,
|
||||
barrier_positions: PackedFloat32Array,
|
||||
barrier_health: PackedInt32Array,
|
||||
barrier_max_health: PackedInt32Array,
|
||||
active_barrier_index: int,
|
||||
visible: bool,
|
||||
) -> void:
|
||||
_green_catch_progress.value = progress * 100.0
|
||||
_red_chase_progress.value = maxf(chase_progress, 0.0) * 100.0
|
||||
_catch_track.visible = visible
|
||||
_barrier_summary.visible = visible
|
||||
if not visible:
|
||||
_barrier_health.visible = false
|
||||
_clear_barrier_markers()
|
||||
_barrier_summary.text = ""
|
||||
_barrier_health.text = ""
|
||||
return
|
||||
|
||||
_update_barrier_markers(
|
||||
barrier_positions,
|
||||
barrier_health,
|
||||
active_barrier_index
|
||||
)
|
||||
var barrier_labels: PackedStringArray = []
|
||||
for barrier_index: int in range(barrier_positions.size()):
|
||||
var defeated: bool = (
|
||||
barrier_index < barrier_health.size()
|
||||
and barrier_health[barrier_index] <= 0
|
||||
)
|
||||
var marker: String = "✓" if defeated else "●"
|
||||
if barrier_index == active_barrier_index:
|
||||
marker = "[%s]" % marker
|
||||
barrier_labels.append(
|
||||
"%d%% %s"
|
||||
% [roundi(barrier_positions[barrier_index] * 100.0), marker]
|
||||
)
|
||||
_barrier_summary.text = "Barriers: %s" % " ".join(barrier_labels)
|
||||
|
||||
if (
|
||||
active_barrier_index >= 0
|
||||
and active_barrier_index < barrier_health.size()
|
||||
and active_barrier_index < barrier_max_health.size()
|
||||
):
|
||||
_barrier_health.text = (
|
||||
"Barrier: %d / %d"
|
||||
% [
|
||||
barrier_health[active_barrier_index],
|
||||
barrier_max_health[active_barrier_index],
|
||||
]
|
||||
)
|
||||
else:
|
||||
_barrier_health.text = ""
|
||||
|
||||
var chase_gap: float = progress - chase_progress
|
||||
if chase_gap <= 0.05:
|
||||
_barrier_health.text = (
|
||||
"%s%s"
|
||||
% [
|
||||
_barrier_health.text,
|
||||
"\nRed is closing in!",
|
||||
]
|
||||
).strip_edges()
|
||||
_barrier_health.visible = (
|
||||
visible
|
||||
and (active_barrier_index >= 0 or chase_gap <= 0.05)
|
||||
)
|
||||
|
||||
|
||||
func _update_barrier_markers(
|
||||
positions: PackedFloat32Array,
|
||||
health: PackedInt32Array,
|
||||
active_index: int,
|
||||
) -> void:
|
||||
_clear_barrier_markers()
|
||||
for barrier_index: int in range(positions.size()):
|
||||
var marker := ColorRect.new()
|
||||
var defeated: bool = (
|
||||
barrier_index < health.size()
|
||||
and health[barrier_index] <= 0
|
||||
)
|
||||
marker.color = Color(0.35, 0.38, 0.42, 0.8) if defeated else Color(1.0, 0.82, 0.2, 1.0)
|
||||
if barrier_index == active_index:
|
||||
marker.color = Color(1.0, 1.0, 1.0, 1.0)
|
||||
marker.set_anchors_preset(Control.PRESET_TOP_LEFT)
|
||||
marker.anchor_left = positions[barrier_index]
|
||||
marker.anchor_right = positions[barrier_index]
|
||||
marker.offset_left = -2.0
|
||||
marker.offset_right = 2.0
|
||||
marker.offset_top = 0.0
|
||||
marker.offset_bottom = 18.0
|
||||
marker.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
_barrier_markers.add_child(marker)
|
||||
|
||||
|
||||
func _clear_barrier_markers() -> void:
|
||||
for marker: Node in _barrier_markers.get_children():
|
||||
marker.queue_free()
|
||||
|
||||
|
||||
func _update_bluegill_count(count: int) -> void:
|
||||
|
|
|
|||
|
|
@ -1,7 +1,19 @@
|
|||
[gd_scene load_steps=2 format=3]
|
||||
[gd_scene load_steps=6 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://ui/game_ui.gd" id="1_ui"]
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBox_chase_background"]
|
||||
bg_color = Color(0.08, 0.08, 0.1, 0.9)
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBox_chase_fill"]
|
||||
bg_color = Color(0.85, 0.12, 0.12, 0.95)
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBox_catch_fill"]
|
||||
bg_color = Color(0.16, 0.82, 0.28, 0.9)
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBox_transparent"]
|
||||
bg_color = Color(0, 0, 0, 0)
|
||||
|
||||
[node name="GameUI" type="CanvasLayer"]
|
||||
script = ExtResource("1_ui")
|
||||
|
||||
|
|
@ -49,9 +61,55 @@ visible = false
|
|||
text = ""
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="ReelProgress" type="ProgressBar" parent="FishingPanel/MarginContainer/VBoxContainer"]
|
||||
[node name="CatchTrack" type="Control" parent="FishingPanel/MarginContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
visible = false
|
||||
custom_minimum_size = Vector2(0, 18)
|
||||
|
||||
[node name="GreenCatchProgress" type="ProgressBar" parent="FishingPanel/MarginContainer/VBoxContainer/CatchTrack"]
|
||||
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
|
||||
mouse_filter = 2
|
||||
theme_override_styles/background = SubResource("StyleBox_chase_background")
|
||||
theme_override_styles/fill = SubResource("StyleBox_catch_fill")
|
||||
value = 0.0
|
||||
show_percentage = false
|
||||
|
||||
[node name="RedChaseProgress" type="ProgressBar" parent="FishingPanel/MarginContainer/VBoxContainer/CatchTrack"]
|
||||
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
|
||||
mouse_filter = 2
|
||||
theme_override_styles/background = SubResource("StyleBox_transparent")
|
||||
theme_override_styles/fill = SubResource("StyleBox_chase_fill")
|
||||
value = 0.0
|
||||
show_percentage = false
|
||||
|
||||
[node name="BarrierMarkers" type="Control" parent="FishingPanel/MarginContainer/VBoxContainer/CatchTrack"]
|
||||
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
|
||||
mouse_filter = 2
|
||||
|
||||
[node name="BarrierSummary" type="Label" parent="FishingPanel/MarginContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
visible = false
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="BarrierHealth" type="Label" parent="FishingPanel/MarginContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
visible = false
|
||||
horizontal_alignment = 1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue