Commit d5db428c authored by Julia Santos's avatar Julia Santos

Refactored some of the scripts and added proper arrangement/labeling, added...

Refactored some of the scripts and added proper arrangement/labeling, added energy bar UI and quest UI, tested out editing quest list by interacting with objects
parent f0705579
...@@ -3,6 +3,5 @@ extends TextureButton ...@@ -3,6 +3,5 @@ extends TextureButton
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _ready():
var funcName = "_pressed" + self.get_name() var funcName = "_pressed" + self.get_name()
print (funcName)
connect("pressed", get_parent().get_node("Movement Handler"), funcName) connect("pressed", get_parent().get_node("Movement Handler"), funcName)
pass # Replace with function body. pass # Replace with function body.
...@@ -14,14 +14,14 @@ func interaction(selected, clicked): #selected = item in inventory, clicked = it ...@@ -14,14 +14,14 @@ func interaction(selected, clicked): #selected = item in inventory, clicked = it
return "Using Placeholder 3 on 1" return "Using Placeholder 3 on 1"
"Placeholder 2": "Placeholder 2":
match clicked: match selected:
"Placeholder 1": "Placeholder 1":
return "Using Placeholder 1 on 2" return "Using Placeholder 1 on 2"
"Placeholder 3": "Placeholder 3":
return "Using Placeholder 3 on 2" return "Using Placeholder 3 on 2"
"Placeholder 3": "Placeholder 3":
match clicked: match selected:
"Placeholder 1": "Placeholder 1":
return "Using Placeholder 1 on 3" return "Using Placeholder 1 on 3"
"Placeholder 2": "Placeholder 2":
......
extends Node
#for code that we don't quite want to delete yet
#func _input(event):
#whenever something onscreen is clicked on
#if event is InputEventMouseButton:
#if event.button_index == BUTTON_LEFT and event.pressed:
# print("Clicked" + " with selected " + str(inventory.is_anything_selected()))
#inventory.unselect_all()
#onready var clickLog = File.new()
#print("Clicked on " + self.get_name())
#dialogueBox.text = "Clicked on " + self.get_name()
#clickLog.open("res://log.txt",File.WRITE_READ)
#clickLog.seek_end(0)
#clickLog.store_string("Clicked on " + self.get_name() + "\n")
#clickLog.close()
func _ready():
pass # Replace with function body.
extends StaticBody2D extends StaticBody2D
#UI stuff
onready var dialogueBox onready var dialogueBox
onready var inventory onready var inventory
onready var texture = get_node("CollisionShape2D/Sprite").get_texture() onready var quests
export(bool) var retrievable #editable in the Inspector, check if this item can be placed in the inventory
export(bool) var interactable #editable in Inspector, for environmental objects that are interactable but not retrievable #variables that are editable in the Inspector
export(String) var flavorText #editable in the Inspector, the flavor text that appears in the dialogue box when picked up export(bool) var retrievable # check if this item can be placed in the inventory
export(bool) var interactable # for environmental objects that are interactable but not retrievable
export(String) var flavorText # the flavor text that appears in the dialogue box when picked up
onready var control = get_parent().get_node("Dialogue control") onready var control = get_parent().get_node("Dialogue control")
#other variables
onready var texture = get_node("CollisionShape2D/Sprite").get_texture()
# some references
# https://docs.godotengine.org/en/stable/getting_started/scripting/gdscript/gdscript_exports.html # 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/ # https://padamthapa.com/blog/how-to-detect-click-inside-staticbody2d-in-godot/
func _ready(): func _ready():
pass pass
func passUI(inv, dia): #passes the inventory and dialogue box from the parent scene to the item in the instanced scene func passUI(inv, dia, que): #passes the inventory and dialogue box from the parent scene to the item in the instanced scene
inventory = inv inventory = inv
dialogueBox = dia dialogueBox = dia
quests = que
print("Found " + dialogueBox.get_name()) print("Found " + dialogueBox.get_name())
func _input_event(viewport, event, shape_idx): func _input_event(viewport, event, shape_idx): # executes when clicked on
if event is InputEventMouseButton: if event is InputEventMouseButton:
if event.button_index == BUTTON_LEFT and event.pressed: if event.button_index == BUTTON_LEFT and event.pressed:
var selected #print("Clicked on " + self.get_name() + " with selected " + str(inventory.is_anything_selected()))
print("Clicked on " + self.get_name() + " with selected " + str(inventory.is_anything_selected())) if inventory.is_anything_selected() and interactable: # if the player has an item selected and they use it on something interactable
if inventory.is_anything_selected() and interactable: #if the player has an item selected and they use it on something interactable objInteraction(inventory.get_selected_items()[0])
selected = inventory.get_selected_items()[0] #get index of item in inventory elif inventory.is_anything_selected() and retrievable: # use object on something retrievable
dialogueBox.text = control.interaction(inventory.get_item_text(selected), self.get_name()) objInteraction(inventory.get_selected_items()[0])
#dialogueBox.text = ("Tried to use " + inventory.get_item_text(selected) + " on " + self.get_name()) elif !inventory.is_anything_selected() and retrievable: # if they click on something retrievable w/ empty hands
inventory.unselect_all() #unselect item pickup()
elif retrievable: #if they click on something retrievable
if !inventory.is_anything_selected(): #with empty hands, pick it up
dialogueBox.text = flavorText
inventory.add_item(self.get_name(), texture)
queue_free()
else: #while holding something, do interaction
selected = inventory.get_selected_items()[0] #get index of item in inventory
dialogueBox.text = control.interaction(inventory.get_item_text(selected), self.get_name())
inventory.unselect_all()
elif interactable: #for environment things that arent retrievable, and hands are empty elif interactable: #for environment things that arent retrievable, and hands are empty
dialogueBox.text = flavorText mouseInteraction()
#print("Clicked on " + self.get_name())
#dialogueBox.text = "Clicked on " + self.get_name() func mouseInteraction(): # just clicked on it with nothing
#clickLog.open("res://log.txt",File.WRITE_READ) dialogueBox.text = flavorText
#clickLog.seek_end(0)
#clickLog.store_string("Clicked on " + self.get_name() + "\n") func pickup(): # when it's picked up
#clickLog.close() dialogueBox.text = flavorText
inventory.add_item(self.get_name(), texture)
queue_free()
# Called every frame. 'delta' is the elapsed time since the previous frame. inventory.unselect_all()
#func _process(delta):
# pass func objInteraction(selected): # when an object is used on it
var flavor = control.interaction(inventory.get_item_text(selected), self.get_name())
if typeof(flavor) != 0: #checks if there's coded flavor text for this interaction
dialogueBox.text = flavor
else:
dialogueBox.text = "No flavor text found" #can replace this later!
inventory.unselect_all() #unselect item
extends Node2D extends Node2D
onready var current = self.get_name() #name of the room Movie is currently in
#UI variables
onready var dialogueBox = get_parent().get_node("Moxie/Camera2D/Dialogue Box/RichTextLabel") onready var dialogueBox = get_parent().get_node("Moxie/Camera2D/Dialogue Box/RichTextLabel")
onready var inventory = get_parent().get_node("Moxie/Camera2D/Inventory") onready var inventory = get_parent().get_node("Moxie/Camera2D/Inventory")
onready var quests = get_parent().get_node("Moxie/Camera2D/Panel/Quests")
#variables that are editable in the Inspector
export(Array, NodePath) onready var items 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. #other variables
func _ready(): onready var current = self.get_name() #name of the room Movie is currently in
#some references
# https://www.reddit.com/r/godot/comments/puiioy/exporting_node_references_in_gdscript_is_tricky/
func _ready(): # Called when the node enters the scene tree for the first time.
print(items.size()) print(items.size())
#gives each item in a room access to the dialogue box and the inventory from the parent room #gives each item in a room access to the dialogue box and the inventory from the parent room
passUI() passUI()
func passUI(): func passUI(): # gives reference to the nodes to each item in the room
for item in items: for item in items:
get_node(item).passUI(inventory,dialogueBox) get_node(item).passUI(inventory,dialogueBox, quests)
print("Passed UI to " + get_node(item).get_name()) print("Passed UI to " + get_node(item).get_name())
#func _input(event):
#whenever something onscreen is clicked on
#if event is InputEventMouseButton:
#if event.button_index == BUTTON_LEFT and event.pressed:
# print("Clicked" + " with selected " + str(inventory.is_anything_selected()))
#inventory.unselect_all()
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass
extends Control extends Control
onready var rooms = [self.owner.get_node("Bedroom"), self.owner.get_node("Kitchen")] onready var rooms = [self.owner.get_node("Bedroom"), self.owner.get_node("Kitchen")] # array of all the screens available to Moxie at the moment
onready var current onready var current # index of the room Moxie is currently in
# Called when the node enters the scene tree for the first time. func _ready(): # Called when the node enters the scene tree for the first time.
func _ready():
current = 0 current = 0
rooms[1].hide() rooms[1].hide() #still not sure we need to do this but just in case
pass # Replace with function body.
func _pressedRight(): # hide = room is not only invisible, but is no longer rendered
print("Click") func _pressedRight(): # when right arrow is clicked, move to the next adjacent screen
rooms[current].hide() if(current != rooms.size()-1):
current += 1 rooms[current].hide()
rooms[current].show() current += 1
rooms[current].show()
func _pressedLeft(): func _pressedLeft(): # when left arrow is clicked, move to the next adjacent screen
print("Click") if(current != 0):
rooms[current].hide() rooms[current].hide()
current -= 1 current -= 1
rooms[current].show() rooms[current].show()
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass
[gd_scene load_steps=11 format=2] [gd_scene load_steps=15 format=2]
[ext_resource path="res://Test room 1.tscn" type="PackedScene" id=1] [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://assets/189066690_228150108704696_3850052974465333899_n.png" type="Texture" id=2]
...@@ -10,12 +10,22 @@ ...@@ -10,12 +10,22 @@
[ext_resource path="res://Kitchen.tscn" type="PackedScene" id=8] [ext_resource path="res://Kitchen.tscn" type="PackedScene" id=8]
[ext_resource path="res://assets/Thesis Clickables/left arrow.png" type="Texture" id=9] [ext_resource path="res://assets/Thesis Clickables/left arrow.png" type="Texture" id=9]
[ext_resource path="res://Arrows.gd" type="Script" id=10] [ext_resource path="res://Arrows.gd" type="Script" id=10]
[ext_resource path="res://Quests.gd" type="Script" id=11]
[sub_resource type="StyleBoxFlat" id=1]
bg_color = Color( 0.466667, 0.631373, 0.168627, 1 )
[sub_resource type="StyleBoxFlat" id=2]
bg_color = Color( 0.145098, 0.145098, 0.164706, 1 )
[sub_resource type="StyleBoxFlat" id=3]
bg_color = Color( 0.984314, 0.847059, 0.435294, 1 )
[node name="Node2D" type="Node2D"] [node name="Node2D" type="Node2D"]
[node name="Bedroom" parent="." instance=ExtResource( 1 )] [node name="Bedroom" parent="." instance=ExtResource( 1 )]
script = ExtResource( 4 ) script = ExtResource( 4 )
items = [ NodePath("Placeholder 1"), NodePath("Placeholder 2"), NodePath("Placeholder 3") ] items = [ NodePath("Placeholder 1"), NodePath("Placeholder 2"), NodePath("Placeholder 3"), NodePath("Placeholder 4") ]
[node name="Kitchen" parent="." instance=ExtResource( 8 )] [node name="Kitchen" parent="." instance=ExtResource( 8 )]
visible = false visible = false
...@@ -32,11 +42,24 @@ position = Vector2( 293.69, -103 ) ...@@ -32,11 +42,24 @@ position = Vector2( 293.69, -103 )
scale = Vector2( 2.86111, 2.86111 ) scale = Vector2( 2.86111, 2.86111 )
current = true current = true
[node name="ProgressBar" type="ProgressBar" parent="Moxie/Camera2D"]
margin_left = -497.761
margin_top = -283.681
margin_right = -64.7609
margin_bottom = -241.681
custom_styles/fg = SubResource( 1 )
custom_styles/bg = SubResource( 2 )
value = 35.0
percent_visible = false
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Dialogue Box" type="Panel" parent="Moxie/Camera2D"] [node name="Dialogue Box" type="Panel" parent="Moxie/Camera2D"]
margin_left = -57.7761 margin_left = -57.0
margin_top = -267.951 margin_top = -284.0
margin_right = 483.228 margin_right = 484.0
margin_bottom = -151.952 margin_bottom = -192.0
__meta__ = { __meta__ = {
"_edit_group_": true, "_edit_group_": true,
"_edit_use_anchors_": false "_edit_use_anchors_": false
...@@ -87,10 +110,10 @@ __meta__ = { ...@@ -87,10 +110,10 @@ __meta__ = {
} }
[node name="Inventory" type="ItemList" parent="Moxie/Camera2D"] [node name="Inventory" type="ItemList" parent="Moxie/Camera2D"]
margin_left = -501.602 margin_left = -502.0
margin_top = 191.358 margin_top = 212.995
margin_right = 94.3979 margin_right = 94.0
margin_bottom = 284.358 margin_bottom = 288.995
rect_pivot_offset = Vector2( 5, 0 ) rect_pivot_offset = Vector2( 5, 0 )
custom_constants/hseparation = 10 custom_constants/hseparation = 10
max_columns = 5 max_columns = 5
...@@ -113,6 +136,41 @@ __meta__ = { ...@@ -113,6 +136,41 @@ __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
} }
[node name="Panel" type="Panel" parent="Moxie/Camera2D"]
margin_left = 183.06
margin_top = 204.903
margin_right = 470.06
margin_bottom = 597.903
custom_styles/panel = SubResource( 3 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Title" type="RichTextLabel" parent="Moxie/Camera2D/Panel"]
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = 13.0
margin_top = 16.0
margin_right = -213.0
margin_bottom = -362.0
custom_colors/default_color = Color( 0, 0, 0, 1 )
text = "To Do:"
__meta__ = {
"_edit_use_anchors_": true
}
[node name="Quests" type="RichTextLabel" parent="Moxie/Camera2D/Panel"]
margin_left = 14.7614
margin_top = 39.8421
margin_right = 272.761
margin_bottom = 256.842
custom_colors/default_color = Color( 0, 0, 0, 1 )
script = ExtResource( 11 )
__meta__ = {
"_edit_use_anchors_": false
}
quests = PoolStringArray( "Do Lab", "Laundry" )
[connection signal="pressed" from="Moxie/Camera2D/Button" to="Moxie/Camera2D/Inventory" method="_on_Button_pressed"] [connection signal="pressed" from="Moxie/Camera2D/Button" to="Moxie/Camera2D/Inventory" method="_on_Button_pressed"]
[editable path="Bedroom"] [editable path="Bedroom"]
......
extends "res://Item.gd"
# 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 pickup(): # when it's picked up
.pickup()
quests.add("Wash laundry")
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass
extends RichTextLabel
# variables editable in the Inspector
export(PoolStringArray) onready var quests # array of all the current quests
func _ready(): # Called when the node enters the scene tree for the first time.
showQuests()
pass
func add(q):
quests.append(q)
showQuests()
func showQuests():
text = "- " + quests.join("\n- ") # prints all quests on the notepad
[gd_scene load_steps=6 format=2] [gd_scene load_steps=13 format=2]
[ext_resource path="res://assets/room zoom out.png" type="Texture" id=1] [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://assets/placeholder item.png" type="Texture" id=2]
[ext_resource path="res://Item.gd" type="Script" id=3] [ext_resource path="res://Item.gd" type="Script" id=3]
[ext_resource path="res://Dialogue control - Test Room 1.gd" type="Script" id=4] [ext_resource path="res://Dialogue control - Test Room 1.gd" type="Script" id=4]
[ext_resource path="res://assets/Thesis Clickables/trail 1.png" type="Texture" id=5]
[ext_resource path="res://assets/Thesis Clickables/trail 2.png" type="Texture" id=6]
[ext_resource path="res://Placeholder 4.gd" type="Script" id=7]
[ext_resource path="res://assets/Thesis Clickables/clothes pile.png" type="Texture" id=8]
[sub_resource type="RectangleShape2D" id=1] [sub_resource type="RectangleShape2D" id=1]
[sub_resource type="RectangleShape2D" id=4]
extents = Vector2( 16.0697, 9.41678 )
[sub_resource type="GDScript" id=2]
script/source = "extends StaticBody2D
onready var dialogueBox
onready var inventory
onready var quests
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 #editable in Inspector, for environmental objects that are interactable but not retrievable
export(String) var flavorText #editable in the Inspector, the flavor text that appears in the dialogue box when picked up
onready var control = get_parent().get_node(\"Dialogue control\")
# 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
func passUI(inv, dia, que): #passes the inventory and dialogue box from the parent scene to the item in the instanced scene
inventory = inv
dialogueBox = dia
quests = que
print(\"Found \" + dialogueBox.get_name())
func _input_event(viewport, event, shape_idx):
if event is InputEventMouseButton:
if event.button_index == BUTTON_LEFT and event.pressed:
var selected
print(\"Clicked on \" + self.get_name() + \" with selected \" + str(inventory.is_anything_selected()))
if inventory.is_anything_selected() and interactable: #if the player has an item selected and they use it on something interactable
selected = inventory.get_selected_items()[0] #get index of item in inventory
dialogueBox.text = control.interaction(inventory.get_item_text(selected), self.get_name())
#dialogueBox.text = (\"Tried to use \" + inventory.get_item_text(selected) + \" on \" + self.get_name())
inventory.unselect_all() #unselect item
elif retrievable: #if they click on something retrievable
if !inventory.is_anything_selected(): #with empty hands, pick it up
dialogueBox.text = flavorText
inventory.add_item(self.get_name(), texture)
queue_free()
else: #while holding something, do interaction
selected = inventory.get_selected_items()[0] #get index of item in inventory
dialogueBox.text = control.interaction(inventory.get_item_text(selected), self.get_name())
inventory.unselect_all()
elif interactable: #for environment things that arent retrievable, and hands are empty
dialogueBox.text = flavorText
#print(\"Clicked on \" + self.get_name())
#dialogueBox.text = \"Clicked on \" + self.get_name()
#clickLog.open(\"res://log.txt\",File.WRITE_READ)
#clickLog.seek_end(0)
#clickLog.store_string(\"Clicked on \" + self.get_name() + \"\\n\")
#clickLog.close()
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass
"
[sub_resource type="RectangleShape2D" id=3]
extents = Vector2( 22.5937, 13.9737 )
[node name="Node2D" type="Node2D"] [node name="Node2D" type="Node2D"]
[node name="BG" type="Sprite" parent="."] [node name="BG" type="Sprite" parent="."]
...@@ -18,7 +87,7 @@ __meta__ = { ...@@ -18,7 +87,7 @@ __meta__ = {
} }
[node name="Placeholder 2" type="StaticBody2D" parent="."] [node name="Placeholder 2" type="StaticBody2D" parent="."]
position = Vector2( 65.5159, -1.25989 ) position = Vector2( -517.196, -33.3684 )
input_pickable = true input_pickable = true
script = ExtResource( 3 ) script = ExtResource( 3 )
__meta__ = { __meta__ = {
...@@ -33,11 +102,31 @@ scale = Vector2( 5, 5 ) ...@@ -33,11 +102,31 @@ scale = Vector2( 5, 5 )
shape = SubResource( 1 ) shape = SubResource( 1 )
[node name="Sprite" type="Sprite" parent="Placeholder 2/CollisionShape2D"] [node name="Sprite" type="Sprite" parent="Placeholder 2/CollisionShape2D"]
position = Vector2( -0.158181, -0.0184715 ) position = Vector2( -0.277301, -0.137165 )
scale = Vector2( 0.101337, 0.101337 ) scale = Vector2( 0.0197574, 0.0197574 )
texture = ExtResource( 2 ) texture = ExtResource( 5 )
[node name="Placeholder 4" type="StaticBody2D" parent="."]
position = Vector2( -110.385, -61.6535 )
input_pickable = true
script = ExtResource( 7 )
__meta__ = {
"_edit_group_": true
}
retrievable = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="Placeholder 4"]
position = Vector2( 669.45, 372.084 )
scale = Vector2( 5, 5 )
shape = SubResource( 4 )
[node name="Sprite" type="Sprite" parent="Placeholder 4/CollisionShape2D"]
position = Vector2( -0.2771, -3.84143 )
scale = Vector2( 0.033227, 0.0334515 )
texture = ExtResource( 8 )
[node name="Placeholder 3" type="StaticBody2D" parent="."] [node name="Placeholder 3" type="StaticBody2D" parent="."]
visible = false
position = Vector2( -12.3961, -122.623 ) position = Vector2( -12.3961, -122.623 )
input_pickable = true input_pickable = true
script = ExtResource( 3 ) script = ExtResource( 3 )
...@@ -58,24 +147,23 @@ scale = Vector2( 0.101337, 0.101337 ) ...@@ -58,24 +147,23 @@ scale = Vector2( 0.101337, 0.101337 )
texture = ExtResource( 2 ) texture = ExtResource( 2 )
[node name="Placeholder 1" type="StaticBody2D" parent="."] [node name="Placeholder 1" type="StaticBody2D" parent="."]
position = Vector2( -79.375, 0 ) position = Vector2( -389.758, 96.3257 )
input_pickable = true input_pickable = true
script = ExtResource( 3 ) script = SubResource( 2 )
__meta__ = { __meta__ = {
"_edit_group_": true "_edit_group_": true
} }
retrievable = true retrievable = true
flavorText = "I Am Your Friend Now"
[node name="CollisionShape2D" type="CollisionShape2D" parent="Placeholder 1"] [node name="CollisionShape2D" type="CollisionShape2D" parent="Placeholder 1"]
position = Vector2( 669.45, 372.084 ) position = Vector2( 669.45, 372.084 )
scale = Vector2( 5, 5 ) scale = Vector2( 5, 5 )
shape = SubResource( 1 ) shape = SubResource( 3 )
[node name="Sprite" type="Sprite" parent="Placeholder 1/CollisionShape2D"] [node name="Sprite" type="Sprite" parent="Placeholder 1/CollisionShape2D"]
position = Vector2( -0.158181, -0.0184715 ) position = Vector2( -0.395752, -4.29968 )
scale = Vector2( 0.101337, 0.101337 ) scale = Vector2( 0.0480605, 0.0480605 )
texture = ExtResource( 2 ) texture = ExtResource( 6 )
[node name="Dialogue control" type="Control" parent="."] [node name="Dialogue control" type="Control" parent="."]
visible = false visible = false
......
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