#42 ajout d'un inspecteur
This commit is contained in:
parent
52b2df8639
commit
49e16d12f8
@ -4,13 +4,13 @@ class_name Compost
|
||||
|
||||
@export var value_per_seed : float = 0.5
|
||||
|
||||
var fill_value : float = 0.
|
||||
@onready var fill_value : float = 0.
|
||||
|
||||
func _process(_delta):
|
||||
%ProgressBar.value = lerp(%ProgressBar.value, fill_value * 100, 0.5)
|
||||
|
||||
func _ready():
|
||||
fill_value = 0.
|
||||
func inspected_text():
|
||||
return "Compost"
|
||||
|
||||
func can_interact(p : Player) -> bool:
|
||||
return p.inventory.get_item() and p.inventory.get_item() is Seed
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
extends Interactable
|
||||
class_name ItemObject
|
||||
|
||||
const ITEM_AREA_WIDTH = 10
|
||||
const ITEM_AREA_WIDTH = 20
|
||||
const ITEM_SPRITE_SIZE = 40.
|
||||
const SPRITE_SCENE : PackedScene = preload("res://entities/interactables/item_object/item_object_sprite.tscn")
|
||||
|
||||
@ -19,7 +19,10 @@ func _init(_item = null):
|
||||
item = _item
|
||||
|
||||
func _ready():
|
||||
generate_collision(10)
|
||||
generate_collision(ITEM_AREA_WIDTH)
|
||||
|
||||
func inspected_text():
|
||||
return item.name + (" Seed" if item is Seed else "")
|
||||
|
||||
func interact(player : Player) -> bool:
|
||||
var swapped_item = player.inventory.get_item()
|
||||
|
||||
@ -1,11 +1,8 @@
|
||||
extends Area2D
|
||||
extends InspectableEntity
|
||||
class_name Interactable
|
||||
|
||||
var available : bool = true
|
||||
|
||||
func _ready():
|
||||
printerr("Abstract Interactable class used")
|
||||
|
||||
func can_interact(_p : Player) -> bool:
|
||||
return true
|
||||
|
||||
|
||||
@ -99,7 +99,6 @@ script = ExtResource("1_pq8o7")
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
scale = Vector2(0.15, 0.15)
|
||||
texture = ExtResource("2_hyinx")
|
||||
offset = Vector2(0, -100)
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||
libraries = {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
extends Area2D
|
||||
extends InspectableEntity
|
||||
class_name Plant
|
||||
|
||||
const PLANT_AREA_WIDTH = 10
|
||||
const PLANT_AREA_WIDTH = 20
|
||||
const HARVESTED_SEED_POSITION_RANGE = 100
|
||||
|
||||
const RANDOM_MAX_GROW_INTERVAL = 0.4
|
||||
@ -23,6 +23,11 @@ func _init(_plant_type = null, _planet = null):
|
||||
plant_type = _plant_type
|
||||
planet = _planet
|
||||
|
||||
func inspected_text():
|
||||
var state_text = "Growing"
|
||||
if state == State.MATURE: state_text = "Mature"
|
||||
return state_text + " " + plant_type.name
|
||||
|
||||
func generate_sprite() -> PlantSprite:
|
||||
var spriteObject : PlantSprite = SPRITE_SCENE.instantiate()
|
||||
|
||||
|
||||
27
entities/scripts/inspectable_entity.gd
Normal file
27
entities/scripts/inspectable_entity.gd
Normal file
@ -0,0 +1,27 @@
|
||||
extends Area2D
|
||||
class_name InspectableEntity
|
||||
|
||||
const MODULATE_INSPECTED_COLOR = Color.GRAY
|
||||
|
||||
@onready var default_modulate : Color = modulate
|
||||
@onready var mouse_signals_setuped : bool = setup_mouse_signals()
|
||||
|
||||
var inspected : bool = false :
|
||||
set(v):
|
||||
print(v)
|
||||
inspected = v
|
||||
modulate = MODULATE_INSPECTED_COLOR if inspected else default_modulate
|
||||
|
||||
func setup_mouse_signals() -> bool:
|
||||
mouse_entered.connect(_on_mouse_entered)
|
||||
mouse_exited.connect(_on_mouse_excited)
|
||||
return true
|
||||
|
||||
func _on_mouse_entered():
|
||||
Pointer.inspect_entity(self)
|
||||
|
||||
func _on_mouse_excited():
|
||||
Pointer.stop_inspect_entity(self)
|
||||
|
||||
func inspected_text():
|
||||
return ""
|
||||
1
entities/scripts/inspectable_entity.gd.uid
Normal file
1
entities/scripts/inspectable_entity.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://d3bk52402ylvl
|
||||
@ -1,7 +1,7 @@
|
||||
extends Area2D
|
||||
extends InspectableEntity
|
||||
class_name UndergroundLoot
|
||||
|
||||
const AREA_WIDTH = 10
|
||||
const AREA_WIDTH = 20
|
||||
const LOOTED_ITEM_RANDOM_RANGE = 100
|
||||
|
||||
const SPRITE_SCENE : PackedScene = preload("res://entities/underground_loot/underground_loot_sprite.tscn")
|
||||
@ -15,6 +15,9 @@ var planet : Planet # mis à jour par la classe Planet
|
||||
func _init(_planet = null):
|
||||
planet = _planet
|
||||
|
||||
func inspected_text():
|
||||
return "Buried Loot"
|
||||
|
||||
func generate_sprite() -> Node2D:
|
||||
var object = SPRITE_SCENE.instantiate()
|
||||
|
||||
|
||||
@ -257,6 +257,7 @@ grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
mouse_filter = 1
|
||||
script = ExtResource("1_udau0")
|
||||
|
||||
[node name="GameAction" type="TextureButton" parent="."]
|
||||
@ -266,6 +267,7 @@ anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
mouse_filter = 1
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="."]
|
||||
layout_mode = 1
|
||||
@ -343,6 +345,7 @@ layout_mode = 2
|
||||
size_flags_horizontal = 8
|
||||
size_flags_vertical = 8
|
||||
focus_mode = 0
|
||||
mouse_filter = 1
|
||||
theme = ExtResource("2_nq5i2")
|
||||
text = "Recharge"
|
||||
icon = ExtResource("4_k4juk")
|
||||
@ -455,6 +458,7 @@ layout_mode = 2
|
||||
size_flags_horizontal = 8
|
||||
size_flags_vertical = 0
|
||||
focus_mode = 0
|
||||
mouse_filter = 1
|
||||
icon = ExtResource("9_2wykm")
|
||||
|
||||
[node name="RechargeFade" type="ColorRect" parent="."]
|
||||
|
||||
10
gui/game/mouse/scripts/mouse.gd
Normal file
10
gui/game/mouse/scripts/mouse.gd
Normal file
@ -0,0 +1,10 @@
|
||||
extends Control
|
||||
class_name Mouse
|
||||
|
||||
@export var default_cursor : Texture2D
|
||||
|
||||
func _ready():
|
||||
Input.set_custom_mouse_cursor(default_cursor)
|
||||
|
||||
func _process(_delta):
|
||||
position = get_viewport().get_mouse_position()
|
||||
1
gui/game/mouse/scripts/mouse.gd.uid
Normal file
1
gui/game/mouse/scripts/mouse.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://dm0d2sxki2ljd
|
||||
@ -2,7 +2,6 @@ extends Control
|
||||
|
||||
var pause = false :
|
||||
set(v):
|
||||
print(pause)
|
||||
pause = v
|
||||
visible = pause
|
||||
get_tree().paused = pause
|
||||
|
||||
1
gui/pointer/assets/cursors/pointer.svg
Normal file
1
gui/pointer/assets/cursors/pointer.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="#ffffff" class="icon icon-tabler icons-tabler-filled icon-tabler-pointer"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M3.039 4.277l3.904 13.563c.185 .837 .92 1.516 1.831 1.642l.17 .016a2.2 2.2 0 0 0 1.982 -1.006l.045 -.078l1.4 -2.072l4.05 4.05a2.067 2.067 0 0 0 2.924 0l1.047 -1.047c.388 -.388 .606 -.913 .606 -1.461l-.008 -.182a2.067 2.067 0 0 0 -.598 -1.28l-4.047 -4.048l2.103 -1.412c.726 -.385 1.18 -1.278 1.053 -2.189a2.2 2.2 0 0 0 -1.701 -1.845l-13.524 -3.89a1 1 0 0 0 -1.236 1.24z" /></svg>
|
||||
|
After Width: | Height: | Size: 607 B |
37
gui/pointer/assets/cursors/pointer.svg.import
Normal file
37
gui/pointer/assets/cursors/pointer.svg.import
Normal file
@ -0,0 +1,37 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://bspffyprdywgc"
|
||||
path="res://.godot/imported/pointer.svg-7e9852b8fc87e59d7ede00033ef3f170.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://gui/pointer/assets/cursors/pointer.svg"
|
||||
dest_files=["res://.godot/imported/pointer.svg-7e9852b8fc87e59d7ede00033ef3f170.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
svg/scale=1.0
|
||||
editor/scale_with_editor_scale=false
|
||||
editor/convert_colors_with_editor_theme=false
|
||||
30
gui/pointer/pointer.tscn
Normal file
30
gui/pointer/pointer.tscn
Normal file
@ -0,0 +1,30 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://0yr6b2jtuttm"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://vhumsfntpqcl" path="res://gui/pointer/scripts/pointer.gd" id="1_1pe2k"]
|
||||
[ext_resource type="Texture2D" uid="uid://bspffyprdywgc" path="res://gui/pointer/assets/cursors/pointer.svg" id="2_q4bvb"]
|
||||
|
||||
[node name="Pointer" type="Node"]
|
||||
process_mode = 3
|
||||
script = ExtResource("1_1pe2k")
|
||||
default_cursor = ExtResource("2_q4bvb")
|
||||
|
||||
[node name="CanvasLayer" type="CanvasLayer" parent="."]
|
||||
layer = 128
|
||||
|
||||
[node name="Inspector" type="Control" parent="CanvasLayer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 3
|
||||
anchors_preset = 0
|
||||
offset_right = 40.0
|
||||
offset_bottom = 40.0
|
||||
size_flags_horizontal = 0
|
||||
size_flags_vertical = 0
|
||||
mouse_filter = 2
|
||||
|
||||
[node name="InspectorText" type="Label" parent="CanvasLayer/Inspector"]
|
||||
unique_name_in_owner = true
|
||||
z_index = 1
|
||||
layout_mode = 1
|
||||
offset_left = 26.0
|
||||
offset_right = 66.0
|
||||
offset_bottom = 23.0
|
||||
26
gui/pointer/scripts/pointer.gd
Normal file
26
gui/pointer/scripts/pointer.gd
Normal file
@ -0,0 +1,26 @@
|
||||
extends Node
|
||||
|
||||
@export var default_cursor : Texture2D
|
||||
|
||||
var inspected_entity : InspectableEntity = null
|
||||
|
||||
func _ready():
|
||||
Input.set_custom_mouse_cursor(default_cursor)
|
||||
|
||||
func _process(_delta):
|
||||
%Inspector.position = get_viewport().get_mouse_position()
|
||||
|
||||
func inspect_entity(entity : InspectableEntity):
|
||||
if inspected_entity and inspected_entity != entity:
|
||||
inspected_entity.inspected = false
|
||||
%InspectorText.text = entity.inspected_text()
|
||||
%InspectorText.visible = true
|
||||
inspected_entity = entity
|
||||
inspected_entity.inspected = true
|
||||
|
||||
func stop_inspect_entity(entity : InspectableEntity):
|
||||
entity.inspected = false
|
||||
if inspected_entity == entity:
|
||||
%InspectorText.visible = false
|
||||
inspected_entity = null
|
||||
|
||||
1
gui/pointer/scripts/pointer.gd.uid
Normal file
1
gui/pointer/scripts/pointer.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://vhumsfntpqcl
|
||||
@ -17,6 +17,10 @@ run/main_scene="uid://c5bruelvqbm1k"
|
||||
config/features=PackedStringArray("4.4", "Forward Plus")
|
||||
config/icon="uid://df0y0s666ui4h"
|
||||
|
||||
[autoload]
|
||||
|
||||
Pointer="*res://gui/pointer/pointer.tscn"
|
||||
|
||||
[input]
|
||||
|
||||
move_right={
|
||||
|
||||
@ -15,6 +15,7 @@ start_scene_path = "uid://d28cp7a21kwou"
|
||||
[node name="CanvasLayer" type="CanvasLayer" parent="."]
|
||||
|
||||
[node name="Background1" type="TextureRect" parent="CanvasLayer"]
|
||||
z_index = -1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
@ -25,6 +26,7 @@ expand_mode = 2
|
||||
stretch_mode = 6
|
||||
|
||||
[node name="Background2" type="TextureRect" parent="CanvasLayer"]
|
||||
z_index = -1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
|
||||
Loading…
Reference in New Issue
Block a user