some cursor states stuff

This commit is contained in:
Victor Turgeon 2023-10-11 02:21:05 -04:00
parent b59b4eb4ba
commit c05a396954
6 changed files with 59 additions and 5 deletions

View File

@ -1,9 +1,13 @@
[gd_scene load_steps=5 format=3 uid="uid://dl0d1m1gfcd4o"]
[gd_scene load_steps=6 format=3 uid="uid://dl0d1m1gfcd4o"]
[ext_resource type="PackedScene" uid="uid://f7n8gd1wlv4v" path="res://Scenes/Player/UI/spawnable_button.tscn" id="1_tvnet"]
[ext_resource type="PackedScene" uid="uid://brnx3xyyd0e71" path="res://Scenes/Spawnables/bat_spawnable.tscn" id="2_borla"]
[ext_resource type="Texture2D" uid="uid://ddvr5ltbo8ome" path="res://Assets/Bat/noBKG_BatFlight_strip.png" id="3_5io10"]
[sub_resource type="AtlasTexture" id="AtlasTexture_qf7uu"]
atlas = ExtResource("3_5io10")
region = Rect2(0, 0, 64, 64)
[sub_resource type="AtlasTexture" id="AtlasTexture_if561"]
resource_local_to_scene = true
atlas = ExtResource("3_5io10")
@ -11,6 +15,7 @@ region = Rect2(64, 0, 64, 64)
[node name="BatButton" instance=ExtResource("1_tvnet")]
spawnableScene = ExtResource("2_borla")
spawnableIcon = SubResource("AtlasTexture_qf7uu")
[node name="AnimatedTextureRect" parent="." index="0"]
texture = SubResource("AtlasTexture_if561")

View File

@ -0,0 +1,8 @@
extends Node2D
@onready var infoLabel : Label = $Info
@onready var imageTexture : Sprite2D = $Image
func set_cursor_state(info : String, image: Texture2D):
infoLabel.text = info
imageTexture.texture = image

View File

@ -0,0 +1,16 @@
[gd_scene load_steps=2 format=3 uid="uid://bj2kxv2gq5ase"]
[ext_resource type="Script" path="res://Scenes/Player/UI/cursor_state.gd" id="1_ghv1b"]
[node name="CursorState" type="Node2D"]
script = ExtResource("1_ghv1b")
[node name="Info" type="Label" parent="."]
offset_left = 11.5
offset_top = 14.0
offset_right = 81.5
offset_bottom = 40.0
[node name="Image" type="Sprite2D" parent="."]
position = Vector2(11.5, 14)
scale = Vector2(0.75, 0.75)

View File

@ -2,6 +2,7 @@ class_name SpawnableButton
extends Button
@export var spawnableScene : PackedScene = null
@export var spawnableIcon : Texture2D = null
@onready var animationPlayer : AnimationPlayer = $AnimationPlayer

View File

@ -1,9 +1,12 @@
extends Node2D
var currentSpawnableScene : PackedScene = null
var currentStateIcon : Texture2D = null
var spawnedMonsters : Array = []
@onready var menuZone : Control = $Camera2D/CanvasLayer/PlayerUI.menuZone
@onready var enemy : CharacterBody2D = $"../Enemy"
@onready var playableArea : Area2D = $"../PlayableArea"
@onready var cursorState : Node2D = $CursorState
var isInPlayableArea : bool = false
@ -14,11 +17,20 @@ func _ready():
func _process(delta):
handle_menu_inputs()
handle_spawn()
handle_cursor_state()
func add_monster(monster : TemplateSpawnable):
spawnedMonsters.append(monster)
func remove_monster(monster : TemplateSpawnable):
spawnedMonsters.erase(monster)
func entered_playable_area():
cursorState.set_cursor_state("", currentStateIcon)
isInPlayableArea = true
func exited_playable_area():
cursorState.set_cursor_state("out of bounds", null)
isInPlayableArea = false
func handle_menu_inputs():
@ -27,11 +39,18 @@ func handle_menu_inputs():
get_window().mode = Window.MODE_WINDOWED
else:
get_window().mode = Window.MODE_EXCLUSIVE_FULLSCREEN
if Input.is_action_just_pressed("quit_game"):
get_tree().quit()
func handle_spawn():
if Input.is_action_just_pressed("place_spawnable"):
spawn_current()
func handle_cursor_state():
cursorState.visible = !is_in_menu()
cursorState.global_position = get_global_mouse_position()
func spawn_current():
if !isInPlayableArea || is_in_menu() || currentSpawnableScene == null:
return
@ -46,12 +65,13 @@ func is_in_menu():
return menuZone.get_rect().has_point(get_local_mouse_position())
func _on_player_ui_button_changed(currentButton):
if currentButton == null:
currentSpawnableScene = null
currentStateIcon = null
cursorState.set_cursor_state("", null)
return
currentStateIcon = currentButton.spawnableIcon
currentSpawnableScene = currentButton.spawnableScene
cursorState.set_cursor_state("", currentStateIcon)

View File

@ -1,11 +1,15 @@
[gd_scene load_steps=3 format=3 uid="uid://0onqgygm832d"]
[gd_scene load_steps=4 format=3 uid="uid://0onqgygm832d"]
[ext_resource type="Script" path="res://Scenes/Player/player.gd" id="1_63swt"]
[ext_resource type="PackedScene" uid="uid://bj2kxv2gq5ase" path="res://Scenes/Player/UI/cursor_state.tscn" id="3_0uor3"]
[ext_resource type="PackedScene" uid="uid://dmvukn3rl6gbx" path="res://Scenes/Player/UI/player_ui.tscn" id="3_nbue7"]
[node name="Player" type="Node2D"]
script = ExtResource("1_63swt")
[node name="CursorState" parent="." instance=ExtResource("3_0uor3")]
z_index = 10
[node name="Camera2D" type="Camera2D" parent="."]
anchor_mode = 0