amélioration de l'UI de l'inventaire et ajout de la récompense d'amélioration de taille d'inventaire #52
This commit is contained in:
parent
00c7e9bc4c
commit
bcd8038b3a
@ -57,8 +57,8 @@ func generate_objective_rewards(level = 0) -> Array[ObjectiveReward]:
|
||||
|
||||
var possible_objective_rewards_path : Array[ObjectiveReward] = [
|
||||
UpgradePlayerMaxEnergyReward.new(),
|
||||
RechargePlayerReward.new(randi_range(level + 1, (level + 1) * 2)),
|
||||
LootRandomSeedsReward.new(randi_range(level + 1, (level + 1) * 2))
|
||||
UpgradePlayerInventorySizeReward.new(),
|
||||
LootRandomSeedsReward.new(randi_range(4+level, 6+level))
|
||||
]
|
||||
|
||||
var objectives_reward : Array[ObjectiveReward] = []
|
||||
|
||||
1
common/icons/backpack.svg
Normal file
1
common/icons/backpack.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="#ffffff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-backpack"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M5 18v-6a6 6 0 0 1 6 -6h2a6 6 0 0 1 6 6v6a3 3 0 0 1 -3 3h-8a3 3 0 0 1 -3 -3z" /><path d="M10 6v-1a2 2 0 1 1 4 0v1" /><path d="M9 21v-4a2 2 0 0 1 2 -2h2a2 2 0 0 1 2 2v4" /><path d="M11 10h2" /></svg>
|
||||
|
After Width: | Height: | Size: 511 B |
43
common/icons/backpack.svg.import
Normal file
43
common/icons/backpack.svg.import
Normal file
@ -0,0 +1,43 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://c3f2f1w12afnu"
|
||||
path="res://.godot/imported/backpack.svg-87b1145524d28fbb61259964722c7305.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://common/icons/backpack.svg"
|
||||
dest_files=["res://.godot/imported/backpack.svg-87b1145524d28fbb61259964722c7305.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/uastc_level=0
|
||||
compress/rdo_quality_loss=0.0
|
||||
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/channel_remap/red=0
|
||||
process/channel_remap/green=1
|
||||
process/channel_remap/blue=2
|
||||
process/channel_remap/alpha=3
|
||||
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
|
||||
@ -4,10 +4,13 @@ class_name Inventory
|
||||
signal inventory_changed(inventory: Inventory)
|
||||
|
||||
@export var items: Array[Item] = []
|
||||
@export var max_items: int = 3
|
||||
@export var size: int = 3
|
||||
|
||||
var current_item_ind: int = 0
|
||||
|
||||
func _init(_inventory_size : int = 1):
|
||||
size = _inventory_size
|
||||
|
||||
func set_current_item(new_ind: int):
|
||||
if new_ind >= length():
|
||||
return
|
||||
@ -27,7 +30,7 @@ func change_current_item(ind_mod: int):
|
||||
set_current_item(new_ind)
|
||||
|
||||
func add_item(item: Item):
|
||||
if items.size() < max_items:
|
||||
if items.size() < size:
|
||||
items.append(item)
|
||||
emit_signal("inventory_changed", self)
|
||||
return true
|
||||
@ -37,13 +40,13 @@ func add_item(item: Item):
|
||||
func add_items(items_to_add: Array[Item], fillup: bool = false):
|
||||
if fillup:
|
||||
var has_changed := false
|
||||
for i in min(items_to_add.size(), max_items - items.size()):
|
||||
for i in min(items_to_add.size(), size - items.size()):
|
||||
items.append(items_to_add[i])
|
||||
has_changed = true
|
||||
if has_changed:
|
||||
emit_signal("inventory_changed", self)
|
||||
return has_changed
|
||||
elif !fillup && items.size() + items_to_add.size() < max_items:
|
||||
elif !fillup && items.size() + items_to_add.size() < size:
|
||||
items.append_array(items_to_add)
|
||||
emit_signal("inventory_changed", self)
|
||||
return true
|
||||
@ -52,7 +55,7 @@ func length() -> int:
|
||||
return len(items)
|
||||
|
||||
func set_item(item: Item, ind: int = 0) -> bool:
|
||||
if ind >= max_items:
|
||||
if ind >= size:
|
||||
return false
|
||||
while len(items) <= ind:
|
||||
items.append(null)
|
||||
|
||||
@ -0,0 +1,19 @@
|
||||
extends ObjectiveReward
|
||||
class_name UpgradePlayerMaxEnergyReward
|
||||
|
||||
@export var upgrade_amount = 1
|
||||
|
||||
func _init(_upgrade_amount : int = 1):
|
||||
upgrade_amount = _upgrade_amount
|
||||
|
||||
func reward(objective : Objective):
|
||||
objective.planet.player.upgrade_max_energy(upgrade_amount)
|
||||
|
||||
func get_icon() -> Texture:
|
||||
return preload("res://common/icons/bolt.svg")
|
||||
|
||||
func get_text() -> String:
|
||||
return "+"+str(upgrade_amount)+" max"
|
||||
|
||||
func get_description() -> String:
|
||||
return "Increase player max energy by " + str(upgrade_amount) + "."
|
||||
@ -0,0 +1 @@
|
||||
uid://qywwuv3et7oq
|
||||
@ -1,5 +1,5 @@
|
||||
extends ObjectiveReward
|
||||
class_name UpgradePlayerMaxEnergyReward
|
||||
class_name UpgradePlayerInventorySizeReward
|
||||
|
||||
@export var upgrade_amount = 1
|
||||
|
||||
@ -7,13 +7,13 @@ func _init(_upgrade_amount : int = 1):
|
||||
upgrade_amount = _upgrade_amount
|
||||
|
||||
func reward(objective : Objective):
|
||||
objective.planet.player.upgrade_max_energy(upgrade_amount)
|
||||
objective.planet.player.upgrade_inventory_size(upgrade_amount)
|
||||
|
||||
func get_icon() -> Texture:
|
||||
return preload("res://common/icons/bolt.svg")
|
||||
return preload("res://common/icons/backpack.svg")
|
||||
|
||||
func get_text() -> String:
|
||||
return "+"+str(upgrade_amount)+" max"
|
||||
|
||||
func get_description() -> String:
|
||||
return "Increase player max energy by " + str(upgrade_amount) + "."
|
||||
return "Increase player inventory size by " + str(upgrade_amount) + "."
|
||||
|
||||
@ -3,6 +3,7 @@ class_name Player
|
||||
|
||||
const MAX_REACH = 100
|
||||
const HOLDING_ITEM_SPRITE_SIZE = 20.
|
||||
const DEFAULT_INVENTORY_SIZE = 2
|
||||
|
||||
signal player_updated(player: Player)
|
||||
signal upgraded
|
||||
@ -25,7 +26,7 @@ var energy : int = max_energy :
|
||||
energy = v
|
||||
player_updated.emit(self)
|
||||
|
||||
@onready var inventory : Inventory = Inventory.new()
|
||||
@onready var inventory : Inventory = Inventory.new(DEFAULT_INVENTORY_SIZE)
|
||||
@onready var preview_zone : Area2D = null
|
||||
@onready var action_zone : Area2D = null
|
||||
|
||||
@ -123,13 +124,9 @@ func try_move(move_to : Vector2):
|
||||
instruction = MoveInstruction.new(move_to)
|
||||
|
||||
func pick_item(item : Item) -> Item:
|
||||
var itemAdded = inventory.add_item(item)
|
||||
inventory.add_item(item)
|
||||
var currentItem : Item = inventory.get_item()
|
||||
var itemSwapped : bool = false
|
||||
if itemAdded:
|
||||
inventory.set_current_item(inventory.length() - 1)
|
||||
else:
|
||||
itemSwapped = inventory.set_item(item, inventory.current_item_ind)
|
||||
play_sfx("pick")
|
||||
if !itemSwapped:
|
||||
currentItem = null
|
||||
@ -174,6 +171,11 @@ func upgrade_max_energy(amount = 1):
|
||||
upgraded.emit()
|
||||
player_updated.emit(self)
|
||||
|
||||
func upgrade_inventory_size(amount = 1):
|
||||
inventory.size += amount
|
||||
upgraded.emit()
|
||||
player_updated.emit(self)
|
||||
|
||||
func recharge(amount : int = max_energy):
|
||||
energy = energy + amount
|
||||
upgraded.emit()
|
||||
|
||||
@ -6,10 +6,8 @@ const MODULATE_INSPECTED_COLOR = Color.GRAY
|
||||
@onready var default_modulate : Color = modulate
|
||||
@onready var inspectable_signals_setuped : bool = setup_inspectable_signals()
|
||||
|
||||
var inspected : bool = false :
|
||||
set(v):
|
||||
inspected = v
|
||||
modulate = MODULATE_INSPECTED_COLOR if inspected else default_modulate
|
||||
func inspect(is_inspected : bool = true):
|
||||
modulate = MODULATE_INSPECTED_COLOR if is_inspected else default_modulate
|
||||
|
||||
func setup_inspectable_signals() -> bool:
|
||||
mouse_entered.connect(_on_mouse_entered)
|
||||
@ -17,10 +15,10 @@ func setup_inspectable_signals() -> bool:
|
||||
return true
|
||||
|
||||
func _on_mouse_entered():
|
||||
Pointer.inspect_entity(self)
|
||||
Pointer.inspect(self, inspector_info())
|
||||
|
||||
func _on_mouse_excited():
|
||||
Pointer.stop_inspect_entity(self)
|
||||
Pointer.stop_inspect(self)
|
||||
|
||||
func pointer_text():
|
||||
return ""
|
||||
@ -29,3 +27,7 @@ func inspector_info() -> Inspector.Info:
|
||||
return Inspector.Info.new(
|
||||
pointer_text()
|
||||
)
|
||||
|
||||
func _notification(what):
|
||||
if (what == NOTIFICATION_PREDELETE):
|
||||
Pointer.stop_inspect(self)
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=30 format=3 uid="uid://12nak7amd1uq"]
|
||||
[gd_scene load_steps=29 format=3 uid="uid://12nak7amd1uq"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://cqao7n800qy40" path="res://gui/game/scripts/game_gui.gd" id="1_udau0"]
|
||||
[ext_resource type="Theme" uid="uid://bgcmd213j6gk1" path="res://gui/ressources/default_theme.tres" id="2_nq5i2"]
|
||||
@ -7,9 +7,8 @@
|
||||
[ext_resource type="Texture2D" uid="uid://dcgnamu7sb3ov" path="res://common/icons/bolt.svg" id="4_k4juk"]
|
||||
[ext_resource type="LabelSettings" uid="uid://dqwayi8yjwau2" path="res://gui/ressources/title_label_settings.tres" id="4_ujg5r"]
|
||||
[ext_resource type="PackedScene" uid="uid://d3lff5fui1k0c" path="res://gui/game/inspector/inspector.tscn" id="6_dr1y2"]
|
||||
[ext_resource type="Texture2D" uid="uid://bf6nw4onkhavr" path="res://common/icons/shovel.svg" id="8_h6540"]
|
||||
[ext_resource type="Texture2D" uid="uid://b5cuxgisrsfgt" path="res://common/icons/player-pause.svg" id="9_2wykm"]
|
||||
[ext_resource type="Texture2D" uid="uid://bupl1y0cfj21q" path="res://entities/plants/assets/sprites/chardi/mature.png" id="9_id0t5"]
|
||||
[ext_resource type="PackedScene" uid="uid://clicjf8ts51h8" path="res://gui/game/inventory_gui/inventory_gui.tscn" id="9_id0t5"]
|
||||
|
||||
[sub_resource type="Gradient" id="Gradient_id0t5"]
|
||||
interpolation_mode = 1
|
||||
@ -377,33 +376,12 @@ focus_mode = 0
|
||||
mouse_filter = 1
|
||||
icon = ExtResource("9_2wykm")
|
||||
|
||||
[node name="Inventory" type="HBoxContainer" parent="MarginContainer"]
|
||||
[node name="Inventory" parent="MarginContainer" instance=ExtResource("9_id0t5")]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(48, 48)
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
size_flags_vertical = 8
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="MarginContainer/Inventory"]
|
||||
modulate = Color(1, 0, 1, 1)
|
||||
custom_minimum_size = Vector2(48, 48)
|
||||
layout_mode = 2
|
||||
texture = ExtResource("8_h6540")
|
||||
expand_mode = 3
|
||||
|
||||
[node name="TextureRect2" type="TextureRect" parent="MarginContainer/Inventory"]
|
||||
custom_minimum_size = Vector2(48, 48)
|
||||
layout_mode = 2
|
||||
texture = ExtResource("4_k4juk")
|
||||
expand_mode = 3
|
||||
|
||||
[node name="TextureRect3" type="TextureRect" parent="MarginContainer/Inventory"]
|
||||
modulate = Color(1, 0.37254903, 0.101960786, 1)
|
||||
custom_minimum_size = Vector2(48, 48)
|
||||
layout_mode = 2
|
||||
texture = ExtResource("9_id0t5")
|
||||
expand_mode = 3
|
||||
|
||||
[node name="PassDayFade" type="ColorRect" parent="."]
|
||||
physics_interpolation_mode = 0
|
||||
layout_mode = 1
|
||||
@ -415,11 +393,6 @@ grow_vertical = 2
|
||||
mouse_filter = 2
|
||||
color = Color(0.0627451, 0.0588235, 0.168627, 0)
|
||||
|
||||
[node name="GridContainer" type="GridContainer" parent="."]
|
||||
layout_mode = 0
|
||||
offset_right = 40.0
|
||||
offset_bottom = 40.0
|
||||
|
||||
[node name="Effect" type="TextureRect" parent="."]
|
||||
modulate = Color(1, 1, 1, 0)
|
||||
layout_mode = 1
|
||||
|
||||
13
gui/game/inventory_gui/inventory_gui.tscn
Normal file
13
gui/game/inventory_gui/inventory_gui.tscn
Normal file
@ -0,0 +1,13 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://clicjf8ts51h8"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://dplbbs2dlq308" path="res://gui/game/inventory_gui/scripts/inventory_gui.gd" id="1_himlj"]
|
||||
[ext_resource type="PackedScene" uid="uid://dadihouw8o3jx" path="res://gui/game/inventory_gui/inventory_item/inventory_gui_item.tscn" id="2_0vvyy"]
|
||||
|
||||
[node name="Inventory" type="HBoxContainer"]
|
||||
custom_minimum_size = Vector2(48, 48)
|
||||
offset_right = 156.0
|
||||
offset_bottom = 153.0
|
||||
size_flags_horizontal = 0
|
||||
size_flags_vertical = 0
|
||||
script = ExtResource("1_himlj")
|
||||
inventory_item_scene = ExtResource("2_0vvyy")
|
||||
107
gui/game/inventory_gui/inventory_item/inventory_gui_item.tscn
Normal file
107
gui/game/inventory_gui/inventory_item/inventory_gui_item.tscn
Normal file
@ -0,0 +1,107 @@
|
||||
[gd_scene load_steps=11 format=3 uid="uid://dadihouw8o3jx"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://c8qfny4dlg7ql" path="res://gui/game/inventory_gui/inventory_item/scripts/inventory_gui_item.gd" id="2_m0ja8"]
|
||||
[ext_resource type="Texture2D" uid="uid://bf6nw4onkhavr" path="res://common/icons/shovel.svg" id="2_xs0u7"]
|
||||
|
||||
[sub_resource type="Animation" id="Animation_046xr"]
|
||||
length = 0.001
|
||||
|
||||
[sub_resource type="Animation" id="Animation_x2pqk"]
|
||||
resource_name = "squish"
|
||||
length = 0.2
|
||||
|
||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_k17ff"]
|
||||
_data = {
|
||||
&"RESET": SubResource("Animation_046xr"),
|
||||
&"squish": SubResource("Animation_x2pqk")
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_m0ja8"]
|
||||
resource_name = "selected"
|
||||
length = 0.2
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("BottomSpace:custom_minimum_size")
|
||||
tracks/0/interp = 2
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0, 0.2),
|
||||
"transitions": PackedFloat32Array(1, 1),
|
||||
"update": 0,
|
||||
"values": [Vector2(0, 0), Vector2(0, 15)]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_k17ff"]
|
||||
length = 0.001
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("BottomSpace:custom_minimum_size")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 0,
|
||||
"values": [Vector2(0, 0)]
|
||||
}
|
||||
|
||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_2wu2x"]
|
||||
_data = {
|
||||
&"RESET": SubResource("Animation_k17ff"),
|
||||
&"selected": SubResource("Animation_m0ja8")
|
||||
}
|
||||
|
||||
[sub_resource type="Gradient" id="Gradient_fu672"]
|
||||
interpolation_mode = 1
|
||||
offsets = PackedFloat32Array(0, 0.44886363)
|
||||
colors = PackedColorArray(1, 1, 1, 1, 1, 1, 1, 0)
|
||||
|
||||
[sub_resource type="GradientTexture2D" id="GradientTexture2D_vgckh"]
|
||||
gradient = SubResource("Gradient_fu672")
|
||||
fill = 1
|
||||
fill_from = Vector2(0.48290598, 0.48290598)
|
||||
|
||||
[node name="InventoryItem" type="VBoxContainer"]
|
||||
custom_minimum_size = Vector2(48, 48)
|
||||
offset_right = 48.0
|
||||
offset_bottom = 52.0
|
||||
size_flags_horizontal = 0
|
||||
size_flags_vertical = 8
|
||||
script = ExtResource("2_m0ja8")
|
||||
|
||||
[node name="SquishAnimation" type="AnimationPlayer" parent="."]
|
||||
unique_name_in_owner = true
|
||||
libraries = {
|
||||
&"": SubResource("AnimationLibrary_k17ff")
|
||||
}
|
||||
|
||||
[node name="SelectedAnimation" type="AnimationPlayer" parent="."]
|
||||
unique_name_in_owner = true
|
||||
libraries = {
|
||||
&"": SubResource("AnimationLibrary_2wu2x")
|
||||
}
|
||||
|
||||
[node name="CenterContainer" type="CenterContainer" parent="."]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="NoItemTextureRect" type="TextureRect" parent="CenterContainer"]
|
||||
unique_name_in_owner = true
|
||||
visible = false
|
||||
custom_minimum_size = Vector2(12, 12)
|
||||
layout_mode = 2
|
||||
texture = SubResource("GradientTexture2D_vgckh")
|
||||
expand_mode = 2
|
||||
stretch_mode = 5
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="CenterContainer"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(48, 48)
|
||||
layout_mode = 2
|
||||
texture = ExtResource("2_xs0u7")
|
||||
expand_mode = 1
|
||||
stretch_mode = 5
|
||||
|
||||
[node name="BottomSpace" type="Control" parent="."]
|
||||
layout_mode = 2
|
||||
@ -0,0 +1,50 @@
|
||||
extends Control
|
||||
class_name InventoryGuiItem
|
||||
|
||||
@export var no_item_texture_path : Texture2D
|
||||
|
||||
|
||||
const MODULATE_INSPECTED_COLOR = Color.GRAY
|
||||
|
||||
var current_item : Item = null
|
||||
var was_selected : bool = false
|
||||
|
||||
func _ready():
|
||||
mouse_entered.connect(_on_mouse_entered)
|
||||
mouse_exited.connect(_on_mouse_excited)
|
||||
update(null, false)
|
||||
|
||||
func inspect(is_inspected : bool = true):
|
||||
modulate = MODULATE_INSPECTED_COLOR if is_inspected else Color.WHITE
|
||||
|
||||
func _on_mouse_entered():
|
||||
if current_item:
|
||||
Pointer.inspect(self, inspector_info())
|
||||
|
||||
func _on_mouse_excited():
|
||||
if current_item:
|
||||
Pointer.stop_inspect(self)
|
||||
|
||||
func inspector_info() -> Inspector.Info:
|
||||
return Inspector.Info.new(
|
||||
current_item.name,
|
||||
current_item.description,
|
||||
current_item.icon
|
||||
)
|
||||
|
||||
func update(item: Item, selected : bool):
|
||||
if selected and not was_selected:
|
||||
%SelectedAnimation.play("selected")
|
||||
elif not selected and was_selected:
|
||||
%SelectedAnimation.play_backwards("selected")
|
||||
|
||||
if item != current_item:
|
||||
%SquishAnimation.play("squish")
|
||||
print("squish")
|
||||
if item and item.icon:
|
||||
%TextureRect.texture = item.icon
|
||||
%TextureRect.visible = item != null
|
||||
%NoItemTextureRect.visible = item == null
|
||||
|
||||
current_item = item
|
||||
was_selected = selected
|
||||
@ -0,0 +1 @@
|
||||
uid://c8qfny4dlg7ql
|
||||
26
gui/game/inventory_gui/scripts/inventory_gui.gd
Normal file
26
gui/game/inventory_gui/scripts/inventory_gui.gd
Normal file
@ -0,0 +1,26 @@
|
||||
extends HBoxContainer
|
||||
class_name InventoryGui
|
||||
|
||||
@export var inventory_item_scene : PackedScene
|
||||
|
||||
var inventory_item_objects : Array[InventoryGuiItem]
|
||||
|
||||
func update(inventory : Inventory):
|
||||
if len(inventory_item_objects) == 0 or len(inventory_item_objects) != inventory.size:
|
||||
for o in inventory_item_objects:
|
||||
o.queue_free()
|
||||
inventory_item_objects = generate_inventory_item_objects(inventory.size)
|
||||
|
||||
for i in range(inventory.size):
|
||||
inventory_item_objects[i].update(
|
||||
inventory.get_item(i),
|
||||
i == inventory.current_item_ind and inventory.get_item(i) != null
|
||||
)
|
||||
|
||||
func generate_inventory_item_objects(nb : int = 1) -> Array[InventoryGuiItem]:
|
||||
var objects : Array[InventoryGuiItem] = []
|
||||
for i in range(nb):
|
||||
var o = inventory_item_scene.instantiate() as InventoryGuiItem
|
||||
add_child(o)
|
||||
objects.append(o)
|
||||
return objects
|
||||
1
gui/game/inventory_gui/scripts/inventory_gui.gd.uid
Normal file
1
gui/game/inventory_gui/scripts/inventory_gui.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://dplbbs2dlq308
|
||||
@ -4,29 +4,13 @@ class_name GameGui
|
||||
signal pause_asked
|
||||
|
||||
func _ready():
|
||||
Pointer.connect("inspected_entity_changed", _on_inspected_entity_changed)
|
||||
Pointer.connect("inspected_changed", _on_inspected_changed)
|
||||
|
||||
func _on_player_updated(player:Player):
|
||||
%EnergyCount.text = str(player.energy) + "/" + str(player.max_energy)
|
||||
%EnergyInfo.modulate = Color.WHITE if player.energy > 0 else Color.RED
|
||||
|
||||
for i in player.inventory.max_items:
|
||||
var item : Item = player.inventory.get_item(i)
|
||||
if item:
|
||||
if %Inventory.get_child_count() <= i:
|
||||
var texture_rect = TextureRect.new()
|
||||
texture_rect.expand_mode = TextureRect.EXPAND_FIT_WIDTH_PROPORTIONAL
|
||||
%Inventory.add_child(texture_rect)
|
||||
%Inventory.get_child(i).texture = item.icon
|
||||
%Inventory.get_child(i).visible = true
|
||||
if i == player.inventory.current_item_ind:
|
||||
%Inventory.get_child(i).modulate = Color.WHITE
|
||||
else:
|
||||
%Inventory.get_child(i).modulate = Color.DARK_GRAY
|
||||
else:
|
||||
if %Inventory.get_child_count() > i:
|
||||
%Inventory.get_child(i).visible = false
|
||||
|
||||
%Inventory.update(player.inventory)
|
||||
|
||||
update_no_energy_left_info(player.energy)
|
||||
|
||||
@ -59,10 +43,7 @@ func _on_planet_pass_day_started(planet):
|
||||
await $PassDayAnimation.animation_finished
|
||||
$PassDayAnimation.speed_scale = 1
|
||||
|
||||
func _on_inspected_entity_changed(e : InspectableEntity):
|
||||
var info : Inspector.Info = null
|
||||
if e:
|
||||
info = e.inspector_info()
|
||||
func _on_inspected_changed(info : Inspector.Info):
|
||||
%Inspector.info = info
|
||||
|
||||
func update_no_energy_left_info(energy):
|
||||
|
||||
@ -1,16 +1,14 @@
|
||||
extends Node
|
||||
|
||||
signal inspected_entity_changed(e : InspectableEntity)
|
||||
signal inspected_changed(info : Inspector.Info)
|
||||
|
||||
const DEFAULT_ACTION_COLOR = Color.WHITE
|
||||
const ENERGY_ACTION_COLOR = Color("ffff2b")
|
||||
|
||||
@export var default_cursor : Texture2D
|
||||
|
||||
var inspected_entity : InspectableEntity = null :
|
||||
set(e):
|
||||
inspected_entity = e
|
||||
inspected_entity_changed.emit(e)
|
||||
var inspected : Node = null
|
||||
var inspected_info : Inspector.Info = null
|
||||
var player : Player # renseigné par Player
|
||||
var can_interact : bool = false
|
||||
var current_selected_item : Item = null
|
||||
@ -32,7 +30,7 @@ func _input(_event):
|
||||
|
||||
if Input.is_action_just_pressed("action"):
|
||||
if can_interact:
|
||||
var interactable = inspected_entity as Interactable
|
||||
var interactable = inspected as Interactable
|
||||
player.try_interact(interactable)
|
||||
elif can_use_item:
|
||||
player.try_use_item(
|
||||
@ -45,9 +43,9 @@ func _process(_delta):
|
||||
|
||||
if player:
|
||||
can_interact = (
|
||||
inspected_entity
|
||||
and inspected_entity is Interactable
|
||||
and player.can_interact(inspected_entity)
|
||||
inspected
|
||||
and inspected is Interactable
|
||||
and player.can_interact(inspected)
|
||||
)
|
||||
|
||||
current_selected_item = player.inventory.get_item()
|
||||
@ -67,24 +65,27 @@ func _process(_delta):
|
||||
|
||||
update_inspector()
|
||||
|
||||
func inspect_entity(entity : InspectableEntity):
|
||||
if inspected_entity and inspected_entity != entity:
|
||||
inspected_entity.inspected = false
|
||||
inspected_entity = entity
|
||||
inspected_entity.inspected = true
|
||||
func inspect(node : Node, info : Inspector.Info):
|
||||
if inspected and inspected != node and inspected.has_method("inspect"):
|
||||
inspected.inspect(false)
|
||||
inspected_info = info
|
||||
inspected = node
|
||||
inspected_changed.emit(inspected_info)
|
||||
if inspected.has_method("inspect"):
|
||||
inspected.inspect(true)
|
||||
update_inspector()
|
||||
|
||||
func update_inspector():
|
||||
%InspectorText.visible = inspected_entity != null
|
||||
if inspected_entity:
|
||||
%InspectorText.text = inspected_entity.pointer_text()
|
||||
%InspectorText.visible = inspected != null
|
||||
if inspected and inspected is InspectableEntity:
|
||||
%InspectorText.text = inspected.pointer_text()
|
||||
|
||||
if player:
|
||||
if can_interact and inspected_entity and inspected_entity is Interactable:
|
||||
if can_interact and inspected and inspected is Interactable:
|
||||
%Action.visible = true
|
||||
%ActionText.text = inspected_entity.interact_text()
|
||||
%Action.modulate = DEFAULT_ACTION_COLOR if inspected_entity.interaction_cost(player) == 0 else ENERGY_ACTION_COLOR
|
||||
%ActionEnergyImage.visible = inspected_entity.interaction_cost(player) != 0
|
||||
%ActionText.text = inspected.interact_text()
|
||||
%Action.modulate = DEFAULT_ACTION_COLOR if inspected.interaction_cost(player) == 0 else ENERGY_ACTION_COLOR
|
||||
%ActionEnergyImage.visible = inspected.interaction_cost(player) != 0
|
||||
elif can_use_item and current_selected_item:
|
||||
%Action.visible = true
|
||||
%ActionText.text = current_selected_item.use_text()
|
||||
@ -96,8 +97,11 @@ func update_inspector():
|
||||
else:
|
||||
%Action.visible = false
|
||||
|
||||
func stop_inspect_entity(entity : InspectableEntity):
|
||||
entity.inspected = false
|
||||
if inspected_entity == entity:
|
||||
inspected_entity = null
|
||||
func stop_inspect(node : Node):
|
||||
if node.has_method("inspect"):
|
||||
node.inspect(false)
|
||||
if inspected == node:
|
||||
inspected = null
|
||||
inspected_info = null
|
||||
inspected_changed.emit(inspected_info)
|
||||
update_inspector()
|
||||
|
||||
@ -30,10 +30,8 @@ const OBJECTIVE_MIN_ANGLE_DIFF = PI/2
|
||||
|
||||
var background_sprite : Polygon2D
|
||||
var contamination_sprite : Polygon2D
|
||||
var decontamination_surface : float :
|
||||
set(v):
|
||||
decontamination_surface = v
|
||||
planet_updated.emit(self)
|
||||
var decontamination_surface : float
|
||||
|
||||
@onready var objective_scene : PackedScene = preload("res://entities/objectives/objective.tscn")
|
||||
|
||||
var planet_data : PlanetData
|
||||
|
||||
Loading…
Reference in New Issue
Block a user