Commit f27921b0 authored by Julia Santos's avatar Julia Santos

Can click on things and add them to the inventory, rearranged scenes so that...

Can click on things and add them to the inventory, rearranged scenes so that the UI + Moxie are on a bigger scene that contains instanced versions of each room
parent 9d7b12a1
extends Sprite
onready var inventory = get_parent().get_node("ItemList")
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
func _input(event):
if event is InputEventMouseButton:
if event.button_index == BUTTON_LEFT and event.pressed:
print("Unselected")
inventory.unselect_all()
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass
extends StaticBody2D
onready var dialogueBox = get_parent().get_node("Panel/RichTextLabel")
onready var parent = get_parent()
onready var dialogueBox #= get_tree().get_root().get_node("Dialogue Box/RichTextLabel"
onready var inventory #= get_tree().get_root().get_node("Inventory")
onready var texture = get_node("CollisionShape2D/Sprite").get_texture()
export(bool) var retrievable #editable in the Inspector, check if this item can be placed in the inventory
export(bool) var interactable
export(String) var flavorText #editable in the Inspector, the flavor text that appears in the dialogue box when picked up
# https://docs.godotengine.org/en/stable/getting_started/scripting/gdscript/gdscript_exports.html
#onready var clickLog = File.new()
# https://padamthapa.com/blog/how-to-detect-click-inside-staticbody2d-in-godot/
func _ready():
pass # Replace with function body.
pass
func passUI(inv, dia):
inventory = inv
dialogueBox = dia
print("Found " + inventory.get_name())
func _input_event(viewport, event, shape_idx):
if event is InputEventMouseButton:
if event.button_index == BUTTON_LEFT and event.pressed:
print("Clicked on " + self.get_name() + " " + flavorText)
dialogueBox.text = flavorText
print("Clicked on " + self.get_name() + " with selected " + str(inventory.is_anything_selected()))
if retrievable:
parent.get_inventory(self, texture)
dialogueBox.text = flavorText
inventory.add_item(self.get_name(), texture)
queue_free()
elif inventory.is_anything_selected():
#get_tree().set_input_as_handled()
dialogueBox.text = ("Tried to use " + inventory.get_item_text(inventory.get_selected_items()[0]) + " on " + self.get_name())
#print(inventory.get_selected_items()[0])
inventory.unselect_all()
#
#print("Clicked on " + self.get_name())
......
extends ItemList
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass
extends Node2D
onready var dialogueBox = get_node("Panel/RichTextLabel")
onready var inventory = get_node("ItemList")
onready var dialogueBox = get_parent().get_node("Dialogue Box/RichTextLabel")
onready var inventory = get_parent().get_node("Inventory")
onready var clicks
export(Array, NodePath) onready var items
#https://www.reddit.com/r/godot/comments/puiioy/exporting_node_references_in_gdscript_is_tricky/
#onready var items = [get_node("Placeholder 1"), get_node("Placeholder 2")]
# Called when the node enters the scene tree for the first time.
func _ready():
clicks = 0
#inventory.set_fixed_icon_size(Vector2(0,0))
#inventory.set_icon_scale(0.3)
#print(inventory.get_icon_scale())
#var file = File.new()
#file.open("res://log.txt",File.WRITE_READ)
#file.store_line("Test")
#file.close()
print(items.size())
for item in items:
get_node(item).passUI(inventory,dialogueBox)
print("Passed UI to " + get_node(item).get_name())
pass # Replace with function body.
func get_inventory(item, tex):
inventory.add_item(item.get_name(), tex)
func _input(event):
if event is InputEventMouseButton:
if event.button_index == BUTTON_LEFT and event.pressed:
print("Clicked")
inventory.unselect_all()
print("Clicked" + " with selected " + str(inventory.is_anything_selected()))
#inventory.unselect_all()
# Called every frame. 'delta' is the elapsed time since the previous frame.
......@@ -31,4 +27,3 @@ func _input(event):
# pass
[gd_scene load_steps=5 format=2]
[ext_resource path="res://Test room 1.tscn" type="PackedScene" id=1]
[ext_resource path="res://assets/189066690_228150108704696_3850052974465333899_n.png" type="Texture" id=2]
[ext_resource path="res://ItemList.gd" type="Script" id=3]
[ext_resource path="res://Main.gd" type="Script" id=4]
[node name="Node2D" type="Node2D"]
[node name="Bedroom" parent="." instance=ExtResource( 1 )]
script = ExtResource( 4 )
items = [ NodePath("Placeholder 1"), NodePath("Placeholder 2"), NodePath("Placeholder 3") ]
[node name="Moxie" type="Sprite" parent="."]
position = Vector2( 219.565, 314.247 )
scale = Vector2( 0.287676, 0.287676 )
texture = ExtResource( 2 )
[node name="Dialogue Box" type="Panel" parent="."]
anchor_right = 0.791
anchor_bottom = 0.14
margin_left = 459.826
margin_top = 34.6902
margin_right = 1000.83
margin_bottom = 150.69
__meta__ = {
"_edit_group_": true,
"_edit_use_anchors_": false
}
[node name="RichTextLabel" type="RichTextLabel" parent="Dialogue Box"]
margin_left = 21.4404
margin_top = 20.0
margin_right = 251.44
margin_bottom = 49.0
scroll_active = false
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Inventory" type="ItemList" parent="."]
margin_left = 16.0
margin_top = 494.0
margin_right = 612.0
margin_bottom = 587.0
rect_pivot_offset = Vector2( 5, 0 )
custom_constants/hseparation = 10
max_columns = 5
same_column_width = true
icon_mode = 0
fixed_icon_size = Vector2( 60, 60 )
script = ExtResource( 3 )
__meta__ = {
"_edit_use_anchors_": false
}
[editable path="Bedroom"]
......@@ -5,7 +5,7 @@
[ext_resource path="res://assets/189066690_228150108704696_3850052974465333899_n.png" type="Texture" id=3]
[ext_resource path="res://Item.gd" type="Script" id=4]
[ext_resource path="res://Main.gd" type="Script" id=5]
[ext_resource path="res://Placeholder 3.gd" type="Script" id=6]
[ext_resource path="res://ItemList.gd" type="Script" id=6]
[sub_resource type="RectangleShape2D" id=1]
......@@ -67,9 +67,9 @@ scale = Vector2( 0.101337, 0.101337 )
texture = ExtResource( 1 )
[node name="Placeholder 3" type="StaticBody2D" parent="."]
visible = false
position = Vector2( 65.5159, -1.25989 )
input_pickable = true
script = ExtResource( 6 )
__meta__ = {
"_edit_group_": true
}
......@@ -115,6 +115,7 @@ max_columns = 5
same_column_width = true
icon_mode = 0
fixed_icon_size = Vector2( 60, 60 )
script = ExtResource( 6 )
__meta__ = {
"_edit_use_anchors_": false
}
[gd_scene load_steps=5 format=2]
[ext_resource path="res://assets/room zoom out.png" type="Texture" id=1]
[ext_resource path="res://assets/placeholder item.png" type="Texture" id=2]
[ext_resource path="res://Item.gd" type="Script" id=3]
[sub_resource type="RectangleShape2D" id=1]
[node name="Node2D" type="Node2D"]
[node name="BG" type="Sprite" parent="."]
position = Vector2( 353.5, 274.901 )
scale = Vector2( 1.0821, 1.0737 )
texture = ExtResource( 1 )
__meta__ = {
"_edit_lock_": true
}
[node name="Placeholder 2" type="StaticBody2D" parent="."]
position = Vector2( 65.5159, -1.25989 )
input_pickable = true
script = ExtResource( 3 )
__meta__ = {
"_edit_group_": true
}
flavorText = "Woeee Can't pick me up!!!"
[node name="CollisionShape2D" type="CollisionShape2D" parent="Placeholder 2"]
position = Vector2( 669.45, 372.084 )
scale = Vector2( 5, 5 )
shape = SubResource( 1 )
[node name="Sprite" type="Sprite" parent="Placeholder 2/CollisionShape2D"]
position = Vector2( -0.158181, -0.0184715 )
scale = Vector2( 0.101337, 0.101337 )
texture = ExtResource( 2 )
[node name="Placeholder 3" type="StaticBody2D" parent="."]
position = Vector2( -12.3961, -122.623 )
input_pickable = true
script = ExtResource( 3 )
__meta__ = {
"_edit_group_": true
}
retrievable = true
interactable = true
flavorText = "Third!"
[node name="CollisionShape2D" type="CollisionShape2D" parent="Placeholder 3"]
position = Vector2( 669.45, 372.084 )
scale = Vector2( 5, 5 )
shape = SubResource( 1 )
[node name="Sprite" type="Sprite" parent="Placeholder 3/CollisionShape2D"]
position = Vector2( -0.158181, -0.0184715 )
scale = Vector2( 0.101337, 0.101337 )
texture = ExtResource( 2 )
[node name="Placeholder 1" type="StaticBody2D" parent="."]
position = Vector2( -79.375, 0 )
input_pickable = true
script = ExtResource( 3 )
__meta__ = {
"_edit_group_": true
}
retrievable = true
flavorText = "I Am Your Friend Now"
[node name="CollisionShape2D" type="CollisionShape2D" parent="Placeholder 1"]
position = Vector2( 669.45, 372.084 )
scale = Vector2( 5, 5 )
shape = SubResource( 1 )
[node name="Sprite" type="Sprite" parent="Placeholder 1/CollisionShape2D"]
position = Vector2( -0.158181, -0.0184715 )
scale = Vector2( 0.101337, 0.101337 )
texture = ExtResource( 2 )
......@@ -11,7 +11,7 @@ config_version=4
[application]
config/name="Thesis practice"
run/main_scene="res://PointnClick.tscn"
run/main_scene="res://Multi.tscn"
config/icon="res://icon.png"
[physics]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment