Cursor example
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
class_name BattleScene extends Node3D
|
class_name BattleScene extends Node3D
|
||||||
|
|
||||||
@export var actionBox:ActionBox = null
|
@export var actionBox:ActionBox = null
|
||||||
|
@export var battleCursor:BattleCursor = null
|
||||||
|
@export var battleFighterScenes:Node
|
||||||
|
|
||||||
signal neverEmitted
|
signal neverEmitted
|
||||||
|
|
||||||
@@ -35,7 +37,8 @@ func getBattleDecisions(fighters:Array[BattleFighter]) -> Array[BattleDecision]:
|
|||||||
elif action == ActionBox.Action.ATTACK:
|
elif action == ActionBox.Action.ATTACK:
|
||||||
var targets = await _getTargets(fighter, fighter.movePrimary)
|
var targets = await _getTargets(fighter, fighter.movePrimary)
|
||||||
|
|
||||||
actionBox.visible = false
|
# Get cursor
|
||||||
|
|
||||||
|
|
||||||
if decision != null:
|
if decision != null:
|
||||||
decisions.append(decision)
|
decisions.append(decision)
|
||||||
@@ -45,5 +48,20 @@ func getBattleDecisions(fighters:Array[BattleFighter]) -> Array[BattleDecision]:
|
|||||||
|
|
||||||
func _getTargets(fighter:BattleFighter, move:BattleAction) -> Array[BattleFighter]:
|
func _getTargets(fighter:BattleFighter, move:BattleAction) -> Array[BattleFighter]:
|
||||||
print("Determining target")
|
print("Determining target")
|
||||||
|
|
||||||
|
battleCursor.visible = true
|
||||||
|
var positions:Array[BattleSingleton.BattlePosition] = []
|
||||||
|
for pos in BATTLE.BattlePosition.values():
|
||||||
|
positions.append(pos)
|
||||||
|
battleCursor.setCursors(self, positions)
|
||||||
|
|
||||||
await neverEmitted
|
await neverEmitted
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
func getFighterSceneAtPosition(pos:BattleSingleton.BattlePosition) -> BattleFighterScene:
|
||||||
|
for fighterScene in battleFighterScenes.get_children():
|
||||||
|
if !(fighterScene is BattleFighterScene):
|
||||||
|
continue
|
||||||
|
if fighterScene.battlePosition == pos:
|
||||||
|
return fighterScene
|
||||||
|
return null
|
||||||
|
|||||||
@@ -5,9 +5,11 @@
|
|||||||
[ext_resource type="PackedScene" uid="uid://ktmvnapibv2q" path="res://battle/ui/ActionBox.tscn" id="2_c3ndu"]
|
[ext_resource type="PackedScene" uid="uid://ktmvnapibv2q" path="res://battle/ui/ActionBox.tscn" id="2_c3ndu"]
|
||||||
[ext_resource type="PackedScene" uid="uid://c4knowtushjly" path="res://battle/ui/BattleCursor.tscn" id="3_7s6t6"]
|
[ext_resource type="PackedScene" uid="uid://c4knowtushjly" path="res://battle/ui/BattleCursor.tscn" id="3_7s6t6"]
|
||||||
|
|
||||||
[node name="BattleScene" type="Node3D" node_paths=PackedStringArray("actionBox")]
|
[node name="BattleScene" type="Node3D" node_paths=PackedStringArray("actionBox", "battleCursor", "battleFighterScenes")]
|
||||||
script = ExtResource("1_acaen")
|
script = ExtResource("1_acaen")
|
||||||
actionBox = NodePath("UI/ActionBox")
|
actionBox = NodePath("UI/ActionBox")
|
||||||
|
battleCursor = NodePath("UI/BattleCursor")
|
||||||
|
battleFighterScenes = NodePath("Fighters")
|
||||||
metadata/_custom_type_script = "uid://dihfp05x6pktn"
|
metadata/_custom_type_script = "uid://dihfp05x6pktn"
|
||||||
|
|
||||||
[node name="UI" type="Control" parent="."]
|
[node name="UI" type="Control" parent="."]
|
||||||
@@ -29,6 +31,7 @@ text = "Battle"
|
|||||||
|
|
||||||
[node name="BattleCursor" parent="UI" instance=ExtResource("3_7s6t6")]
|
[node name="BattleCursor" parent="UI" instance=ExtResource("3_7s6t6")]
|
||||||
layout_mode = 0
|
layout_mode = 0
|
||||||
|
anchors_preset = 0
|
||||||
|
|
||||||
[node name="Fighters" type="Node" parent="."]
|
[node name="Fighters" type="Node" parent="."]
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,21 @@ class_name BattleCursor extends Control
|
|||||||
|
|
||||||
@export var cursor:PackedScene
|
@export var cursor:PackedScene
|
||||||
|
|
||||||
func setCursors(targets:Array[BattleSingleton.BattlePosition]) -> void:
|
func setCursors(battleScene:BattleScene, targets:Array[BattleSingleton.BattlePosition]) -> void:
|
||||||
clearCursors()
|
clearCursors()
|
||||||
|
|
||||||
|
for target in targets:
|
||||||
|
var fighterScene = battleScene.getFighterSceneAtPosition(target)
|
||||||
|
if fighterScene == null:
|
||||||
|
continue
|
||||||
|
|
||||||
|
var cursorInstance = cursor.instantiate()
|
||||||
|
add_child(cursorInstance)
|
||||||
|
|
||||||
|
# Convert world position to screen space
|
||||||
|
var screenPos = battleScene.get_viewport().get_camera_3d().unproject_position(fighterScene.global_transform.origin)
|
||||||
|
cursorInstance.position = screenPos
|
||||||
|
|
||||||
func clearCursors() -> void:
|
func clearCursors() -> void:
|
||||||
# Clear all children (cursors).
|
# Clear all children (cursors).
|
||||||
for child in get_children():
|
for child in get_children():
|
||||||
|
|||||||
@@ -5,8 +5,7 @@
|
|||||||
|
|
||||||
[node name="BattleCursor" type="Control"]
|
[node name="BattleCursor" type="Control"]
|
||||||
layout_mode = 3
|
layout_mode = 3
|
||||||
anchors_preset = 0
|
size_flags_horizontal = 0
|
||||||
offset_right = 11.0
|
size_flags_vertical = 0
|
||||||
offset_bottom = 11.0
|
|
||||||
script = ExtResource("1_wsiei")
|
script = ExtResource("1_wsiei")
|
||||||
cursor = ExtResource("2_6yv4v")
|
cursor = ExtResource("2_6yv4v")
|
||||||
|
|||||||
@@ -1,6 +1,15 @@
|
|||||||
[gd_scene format=3 uid="uid://br2rs8skcn72l"]
|
[gd_scene format=3 uid="uid://br2rs8skcn72l"]
|
||||||
|
|
||||||
[node name="Control" type="ColorRect"]
|
[node name="Control" type="ColorRect"]
|
||||||
offset_right = 8.0
|
anchors_preset = 8
|
||||||
offset_bottom = 8.0
|
anchor_left = 0.5
|
||||||
|
anchor_top = 0.5
|
||||||
|
anchor_right = 0.5
|
||||||
|
anchor_bottom = 0.5
|
||||||
|
offset_left = -4.0
|
||||||
|
offset_top = -4.0
|
||||||
|
offset_right = 4.0
|
||||||
|
offset_bottom = 4.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 2
|
||||||
color = Color(1, 0.478431, 1, 1)
|
color = Color(1, 0.478431, 1, 1)
|
||||||
|
|||||||
Reference in New Issue
Block a user