Cursor work

This commit is contained in:
2026-01-18 00:25:42 -06:00
parent 8e0ab72185
commit 6f3f613f56
11 changed files with 317 additions and 54 deletions

View File

@@ -0,0 +1,38 @@
class_name ActionBox extends GridContainer
enum Action {
ATTACK,
MAGIC,
ITEM,
BACK
}
@export var btnAttack:Button
@export var btnMagic:Button
@export var btnItem:Button
@export var btnBack:Button
signal action(action:Action)
func _ready() -> void:
btnAttack.pressed.connect(func():
action.emit(Action.ATTACK)
)
btnMagic.pressed.connect(func():
action.emit(Action.MAGIC)
)
btnItem.pressed.connect(func():
action.emit(Action.ITEM)
)
btnBack.pressed.connect(func():
action.emit(Action.BACK)
)
self.visible = false
func getAction(fighter:BattleFighter) -> Action:
btnAttack.disabled = fighter.movePrimary == null || !fighter.movePrimary.canFighterUse(fighter)
btnMagic.disabled = fighter.movesMagical.size() == 0
btnItem.disabled = false # TODO: check if items available?
var act = await action
return act

View File

@@ -0,0 +1 @@
uid://27274005hbgh

View File

@@ -0,0 +1,37 @@
[gd_scene load_steps=2 format=3 uid="uid://ktmvnapibv2q"]
[ext_resource type="Script" uid="uid://27274005hbgh" path="res://battle/ui/action/ActionBox.gd" id="1_w5s71"]
[node name="ActionBox" type="GridContainer" node_paths=PackedStringArray("btnAttack", "btnMagic", "btnItem", "btnBack")]
anchors_preset = 3
anchor_left = 1.0
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = -86.0
offset_top = -44.0
grow_horizontal = 0
grow_vertical = 0
columns = 2
script = ExtResource("1_w5s71")
btnAttack = NodePath("Attack")
btnMagic = NodePath("Magic")
btnItem = NodePath("Items")
btnBack = NodePath("Back")
metadata/_custom_type_script = "uid://27274005hbgh"
[node name="Attack" type="Button" parent="."]
layout_mode = 2
text = "Attack"
[node name="Magic" type="Button" parent="."]
layout_mode = 2
text = "Magic"
[node name="Items" type="Button" parent="."]
layout_mode = 2
text = "Items"
[node name="Back" type="Button" parent="."]
layout_mode = 2
text = "Back"

View File

@@ -0,0 +1,56 @@
class_name BattleCursorIcon extends ColorRect
# How often to blink in milliseconds.
const BLINK_RATE := 100
enum Mode {
INACTIVE,
ACTIVE,
BLINKING
}
@export var battlePosition:BattleSingleton.BattlePosition = BattleSingleton.BattlePosition.LEFT_TOP_BACK:
get():
return battlePosition
set(value):
battlePosition = value
_updatePosition()
@export var mode:Mode = Mode.INACTIVE
func _ready() -> void:
_updatePosition()
func _process(delta: float) -> void:
if mode == Mode.INACTIVE:
self.visible = false
return
elif mode == Mode.ACTIVE:
self.visible = true
elif mode == Mode.BLINKING:
self.visible = Time.get_ticks_msec() % (BLINK_RATE * 2) < BLINK_RATE
func _updatePosition() -> void:
# Walk up the tree until BattleScene is found.
var battleScene:BattleScene = null
var currentNode:Node = self
while currentNode != null:
if currentNode is BattleScene:
battleScene = currentNode
break
currentNode = currentNode.get_parent()
if battleScene == null:
push_error("BattleCursorIcon could not find BattleScene in parent nodes.")
return
var targetFighter:BattleFighterScene = battleScene.getFighterSceneAtPosition(battlePosition)
if targetFighter == null:
push_error("No BattleFighter found at battlePosition %s" % str(battlePosition))
return
# Convert the target fighter's global position to screen space position.
var viewport:Viewport = get_viewport()
var screenPos:Vector2 = viewport.get_camera_3d().unproject_position(targetFighter.global_transform.origin)
self.position = screenPos

View File

@@ -0,0 +1 @@
uid://c2lye3hasxnkj

View File

@@ -0,0 +1,18 @@
[gd_scene load_steps=2 format=3 uid="uid://br2rs8skcn72l"]
[ext_resource type="Script" uid="uid://c2lye3hasxnkj" path="res://battle/ui/action/BattleCursorIcon.gd" id="1_cpfvx"]
[node name="Control" type="ColorRect"]
anchors_preset = -1
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)
script = ExtResource("1_cpfvx")