Initial commit of Escoria-Reloaded. Still a lot of missing stuff.
This commit is contained in:
11
addons/escoria-core/game/scenes/camera_player/camera.tscn
Normal file
11
addons/escoria-core/game/scenes/camera_player/camera.tscn
Normal file
@@ -0,0 +1,11 @@
|
||||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://addons/escoria-core/game/scenes/camera_player/esccamera.gd" type="Script" id=1]
|
||||
|
||||
[node name="camera" type="Camera2D"]
|
||||
current = true
|
||||
drag_margin_h_enabled = true
|
||||
drag_margin_v_enabled = true
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="tween" type="Tween" parent="."]
|
||||
166
addons/escoria-core/game/scenes/camera_player/esccamera.gd
Normal file
166
addons/escoria-core/game/scenes/camera_player/esccamera.gd
Normal file
@@ -0,0 +1,166 @@
|
||||
extends Camera2D
|
||||
class_name ESCCamera
|
||||
|
||||
onready var tween = $"tween"
|
||||
|
||||
var default_limits = {} # This does not change once set
|
||||
|
||||
var speed = 0.0
|
||||
var target
|
||||
var target_pos
|
||||
|
||||
var zoom_time
|
||||
var zoom_target
|
||||
|
||||
# This is needed to adjust dialog positions and such, see dialog_instance.gd
|
||||
var zoom_transform
|
||||
|
||||
func set_limits(kwargs=null):
|
||||
if not kwargs:
|
||||
kwargs = {
|
||||
"limit_left": -10000,
|
||||
"limit_right": 10000,
|
||||
"limit_top": -10000,
|
||||
"limit_bottom": 10000,
|
||||
"set_default": false,
|
||||
}
|
||||
print_stack()
|
||||
|
||||
self.limit_left = kwargs["limit_left"]
|
||||
self.limit_right = kwargs["limit_right"]
|
||||
self.limit_top = kwargs["limit_top"]
|
||||
self.limit_bottom = kwargs["limit_bottom"]
|
||||
|
||||
if "set_default" in kwargs and kwargs["set_default"] and not default_limits:
|
||||
default_limits = kwargs
|
||||
|
||||
func resolve_target_pos():
|
||||
if typeof(target) == TYPE_VECTOR2:
|
||||
target_pos = target
|
||||
elif typeof(target) == TYPE_ARRAY:
|
||||
var count = 0
|
||||
|
||||
for obj in target:
|
||||
target_pos += obj.get_camera_pos()
|
||||
count += 1
|
||||
|
||||
# Let the error in if an empty array was passed (divzero)
|
||||
target_pos = target_pos / count
|
||||
else:
|
||||
target_pos = target.get_camera_pos()
|
||||
|
||||
return target_pos
|
||||
|
||||
func set_drag_margin_enabled(p_dm_h_enabled, p_dm_v_enabled):
|
||||
self.drag_margin_h_enabled = p_dm_h_enabled
|
||||
self.drag_margin_v_enabled = p_dm_v_enabled
|
||||
|
||||
func set_target(p_target, p_speed : float = 0.0):
|
||||
speed = p_speed
|
||||
target = p_target
|
||||
|
||||
resolve_target_pos()
|
||||
|
||||
if speed == 0.0:
|
||||
self.global_position = target_pos
|
||||
else:
|
||||
var time = self.global_position.distance_to(target_pos) / speed
|
||||
|
||||
if tween.is_active():
|
||||
var tweenstat = String(tween.tell()) + "/" + String(tween.get_runtime())
|
||||
escoria.report_warnings("camera.gd:set_target()", ["Tween still active running camera_set_target: " + tweenstat])
|
||||
tween.emit_signal("tween_completed")
|
||||
|
||||
tween.interpolate_property(self, "global_position", self.global_position, target_pos, time, Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)
|
||||
|
||||
tween.start()
|
||||
|
||||
func set_camera_zoom(p_zoom_level, p_time):
|
||||
if p_zoom_level <= 0.0:
|
||||
escoria.report_errors("camera.gd:set_camera_zoom()", ["Tried to set negative or zero zoom level"])
|
||||
|
||||
zoom_time = p_time
|
||||
zoom_target = Vector2(1, 1) * p_zoom_level
|
||||
|
||||
if zoom_time == 0:
|
||||
self.zoom = zoom_target
|
||||
else:
|
||||
if tween.is_active():
|
||||
var tweenstat = String(tween.tell()) + "/" + String(tween.get_runtime())
|
||||
escoria.report_warnings("camera", ["Tween still active running camera_set_zoom: " + tweenstat])
|
||||
tween.emit_signal("tween_completed")
|
||||
|
||||
tween.interpolate_property(self, "zoom", self.zoom, zoom_target, zoom_time, Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)
|
||||
|
||||
tween.start()
|
||||
|
||||
func push(p_target, p_time, p_type):
|
||||
var time = float(p_time)
|
||||
var type = "TRANS_" + p_type
|
||||
|
||||
target = p_target
|
||||
|
||||
var camera_pos
|
||||
var camera_pos_coords
|
||||
if target.has_node("camera_pos"):
|
||||
camera_pos = target.get_node("camera_pos")
|
||||
camera_pos_coords = camera_pos.global_position
|
||||
else:
|
||||
camera_pos_coords = target.global_position
|
||||
|
||||
if time == 0:
|
||||
self.global_position = camera_pos_coords
|
||||
|
||||
if camera_pos and camera_pos is Camera2D:
|
||||
self.zoom = camera_pos.zoom
|
||||
else:
|
||||
if tween.is_active():
|
||||
var tweenstat = String(tween.tell()) + "/" + String(tween.get_runtime())
|
||||
escoria.report_warnings("camera", ["Tween still active running camera_push: " + tweenstat])
|
||||
tween.emit_signal("tween_completed")
|
||||
|
||||
if camera_pos and camera_pos is Camera2D:
|
||||
tween.interpolate_property(self, "zoom", self.zoom, camera_pos.zoom, time, tween.get(type), Tween.EASE_IN_OUT)
|
||||
|
||||
tween.interpolate_property(self, "global_position", self.global_position, camera_pos_coords, time, tween.get(type), Tween.EASE_IN_OUT)
|
||||
|
||||
tween.start()
|
||||
|
||||
func shift(p_x, p_y, p_time, p_type):
|
||||
var x = int(p_x)
|
||||
var y = int(p_y)
|
||||
var time = float(p_time)
|
||||
var type = "TRANS_" + p_type
|
||||
|
||||
var new_pos = self.global_position + Vector2(x, y)
|
||||
|
||||
target = new_pos
|
||||
|
||||
if tween.is_active():
|
||||
var tweenstat = String(tween.tell()) + "/" + String(tween.get_runtime())
|
||||
escoria.report_warnings("camera", ["Tween still active running camera_shift: " + tweenstat])
|
||||
tween.emit_signal("tween_completed")
|
||||
|
||||
tween.interpolate_property(self, "global_position", self.global_position, new_pos, time, tween.get(type), Tween.EASE_IN_OUT)
|
||||
|
||||
tween.start()
|
||||
|
||||
func target_reached(_obj=null, _key=null):
|
||||
tween.stop_all()
|
||||
|
||||
func _process(_delta):
|
||||
zoom_transform = self.get_canvas_transform()
|
||||
|
||||
if target and not tween.is_active():
|
||||
if typeof(target) == TYPE_VECTOR2 or typeof(target) == TYPE_ARRAY:
|
||||
self.global_position = resolve_target_pos()
|
||||
elif "moved" in target and target.moved:
|
||||
self.global_position = resolve_target_pos()
|
||||
|
||||
func _ready():
|
||||
if not target:
|
||||
target = Vector2(0, 0)
|
||||
|
||||
tween.connect("tween_completed", self, "target_reached")
|
||||
escoria.register_object(self)
|
||||
|
||||
74
addons/escoria-core/game/scenes/dialogs/dialog_player.gd
Normal file
74
addons/escoria-core/game/scenes/dialogs/dialog_player.gd
Normal file
@@ -0,0 +1,74 @@
|
||||
tool
|
||||
extends ResourcePreloader
|
||||
class_name ESCDialogsPlayer
|
||||
|
||||
func get_class():
|
||||
return "ESCDialogsPlayer"
|
||||
|
||||
# This scene is in charge of ALL dialogs management :
|
||||
# - characters sayings
|
||||
# - player dialog options panel display/hiding and choices
|
||||
|
||||
var path_to_dialog_scenes : String
|
||||
|
||||
var is_speaking = false
|
||||
var dialog_ui = null
|
||||
var dialog_chooser_ui = null
|
||||
|
||||
func _ready():
|
||||
if !Engine.is_editor_hint():
|
||||
escoria.register_object(self)
|
||||
preload_resources(ProjectSettings.get_setting("escoria/ui/dialogs_folder"))
|
||||
|
||||
func preload_resources(path : String):
|
||||
path_to_dialog_scenes = path
|
||||
|
||||
var dialog_folder := Directory.new()
|
||||
if !path_to_dialog_scenes.empty() and dialog_folder.open(path_to_dialog_scenes) == OK:
|
||||
dialog_folder.list_dir_begin()
|
||||
var file_name = dialog_folder.get_next()
|
||||
while file_name != "":
|
||||
if !dialog_folder.current_is_dir() and file_name.get_extension() == "tscn":
|
||||
var extension = "." + file_name.get_extension()
|
||||
var basename = file_name.replace(extension, "")
|
||||
|
||||
if !has_resource(basename):
|
||||
var file_path = dialog_folder.get_current_dir() + "/" + file_name
|
||||
var dialog_scene = load(file_path)
|
||||
|
||||
if dialog_scene != null:
|
||||
add_resource(basename, dialog_scene)
|
||||
file_name = dialog_folder.get_next()
|
||||
else:
|
||||
escoria.report_errors("dialog_player.gd:preload_resources()", ["An error occurred when trying to access the path: {_}.".format(path)])
|
||||
|
||||
|
||||
func say(character : String, params : Dictionary):
|
||||
is_speaking = true
|
||||
dialog_ui = get_resource(params.ui).instance()
|
||||
get_parent().add_child(dialog_ui)
|
||||
dialog_ui.say(character, params)
|
||||
|
||||
func finish_fast():
|
||||
dialog_ui.finish_fast()
|
||||
|
||||
# Options:
|
||||
# type: (default value "default") the type of dialog menu to use. All types are in the "dd_player" scene.
|
||||
# avatar: (default value "default") the avatar to use in the dialog ui.
|
||||
# timeout: (default value 0) timeout to select an option. After the time has passed, the "timeout_option" will be selected automatically. If the value is 0, there's no timeout.
|
||||
# timeout_option: (default value 0) option selected when timeout is reached.
|
||||
func start_dialog_choices(answers : Array, options : Array):
|
||||
if answers.empty():
|
||||
escoria.report_errors("dialog_player.gd:start_dialog_choices()", ["Received answers array was empty."])
|
||||
dialog_chooser_ui = get_resource("text_dialog_choice").instance()
|
||||
get_parent().add_child(dialog_chooser_ui)
|
||||
dialog_chooser_ui.set_answers(answers)
|
||||
|
||||
func play_dialog_option_chosen(level_to_run : Array):
|
||||
# escoria.esc_runner.finished(context)
|
||||
var ev_level = level_to_run
|
||||
var ev = esctypes.ESCEvent.new("dialog_choice_done", ev_level, [])
|
||||
escoria.esc_runner.add_level(ev, false)
|
||||
dialog_chooser_ui.hide()
|
||||
# stop()
|
||||
|
||||
10
addons/escoria-core/game/scenes/dialogs/dialog_player.tscn
Normal file
10
addons/escoria-core/game/scenes/dialogs/dialog_player.tscn
Normal file
@@ -0,0 +1,10 @@
|
||||
[gd_scene load_steps=5 format=2]
|
||||
|
||||
[ext_resource path="res://game/ui/commons/dialogs/dialog_label.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://game/ui/commons/dialogs/text_dialog_choice.tscn" type="PackedScene" id=2]
|
||||
[ext_resource path="res://addons/escoria-core/game/scenes/dialogs/dialog_player.gd" type="Script" id=3]
|
||||
[ext_resource path="res://game/ui/commons/dialogs/dialog_box_inset.tscn" type="PackedScene" id=4]
|
||||
|
||||
[node name="dialog_player" type="ResourcePreloader"]
|
||||
resources = [ PoolStringArray( "dialog_box_inset", "dialog_label", "text_dialog_choice" ), [ ExtResource( 4 ), ExtResource( 1 ), ExtResource( 2 ) ] ]
|
||||
script = ExtResource( 3 )
|
||||
@@ -0,0 +1,40 @@
|
||||
extends WindowDialog
|
||||
|
||||
onready var past_actions = $VBoxContainer/past_actions
|
||||
onready var command = $VBoxContainer/command
|
||||
|
||||
var last_event_done := true
|
||||
|
||||
func _on_command_text_entered(p_command_str : String):
|
||||
if p_command_str.empty():
|
||||
return
|
||||
|
||||
last_event_done = false
|
||||
command.text = ""
|
||||
past_actions.text += "\n"
|
||||
past_actions.text += "# " + p_command_str
|
||||
past_actions.text += "\n"
|
||||
|
||||
var actual_command = ":debug\n" + p_command_str + "\n"
|
||||
|
||||
var errors = []
|
||||
var events = escoria.esc_compiler.compile_str(actual_command, errors)
|
||||
|
||||
if errors.empty():
|
||||
#past_actions.text += str(events)
|
||||
var ret = escoria.esc_runner.run_event(events["debug"])
|
||||
if ret != null:
|
||||
past_actions.text += str(ret)
|
||||
else:
|
||||
# Display first error only
|
||||
past_actions.text += str(errors[0].split(":")[1].strip_edges())
|
||||
|
||||
|
||||
func _on_event_done(event_name : String):
|
||||
if event_name == "debug" and !last_event_done:
|
||||
last_event_done = true
|
||||
# past_actions.text += "\nDone.\n"
|
||||
|
||||
|
||||
func _on_esc_prompt_popup_about_to_show():
|
||||
command.grab_focus()
|
||||
@@ -0,0 +1,42 @@
|
||||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://addons/escoria-core/game/scenes/esc_prompt/esc_prompt_popup.gd" type="Script" id=1]
|
||||
|
||||
[node name="esc_prompt_popup" type="WindowDialog"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
margin_left = 64.0
|
||||
margin_top = 68.0
|
||||
margin_right = -617.0
|
||||
margin_bottom = -456.0
|
||||
window_title = "ESC debug prompt"
|
||||
script = ExtResource( 1 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="."]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="past_actions" type="TextEdit" parent="VBoxContainer"]
|
||||
margin_right = 599.0
|
||||
margin_bottom = 240.0
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="HSeparator" type="HSeparator" parent="VBoxContainer"]
|
||||
margin_top = 244.0
|
||||
margin_right = 599.0
|
||||
margin_bottom = 248.0
|
||||
|
||||
[node name="command" type="LineEdit" parent="VBoxContainer"]
|
||||
margin_top = 252.0
|
||||
margin_right = 599.0
|
||||
margin_bottom = 276.0
|
||||
caret_blink = true
|
||||
|
||||
[connection signal="about_to_show" from="." to="." method="_on_esc_prompt_popup_about_to_show"]
|
||||
[connection signal="text_entered" from="VBoxContainer/command" to="." method="_on_command_text_entered"]
|
||||
101
addons/escoria-core/game/scenes/inventory/inventory_ui.gd
Normal file
101
addons/escoria-core/game/scenes/inventory/inventory_ui.gd
Normal file
@@ -0,0 +1,101 @@
|
||||
extends Control
|
||||
class_name ESCInventory
|
||||
|
||||
func get_class():
|
||||
return "ESCInventory"
|
||||
|
||||
# Define the actual container node to add items as children of. Should be a Container.
|
||||
export(NodePath) var items_container
|
||||
onready var all_items = $all_items
|
||||
|
||||
# Methods available for selecting an item
|
||||
enum ITEM_SELECTION_METHODS {
|
||||
VERB_ACTION, # Use a verb action, such as use or give, on inventory item
|
||||
ONE_CLICK, # One click on inventory item selects it (eventually put it on cursor)
|
||||
DRAG_N_DROP # (Useful for mobile) Drag n drop item on another or on background to use/give it
|
||||
}
|
||||
export(ITEM_SELECTION_METHODS) var selection_method
|
||||
|
||||
var items_ids_in_inventory : Dictionary = {} # { item_id : TextureButton}
|
||||
|
||||
func _ready():
|
||||
# # For debugging scene only. These 2 lines should remain commented on normal run.
|
||||
# if !Engine.is_editor_hint():
|
||||
# return
|
||||
|
||||
for item_id in escoria.esc_runner.items_in_inventory():
|
||||
call_deferred("add_new_item_by_id", item_id)
|
||||
|
||||
escoria.register_object(self)
|
||||
|
||||
if items_container == null or items_container.is_empty():
|
||||
escoria.report_errors(self.get_path(), ["Items container is empty."])
|
||||
return
|
||||
for c in get_node(items_container).get_items():
|
||||
items_ids_in_inventory[c.item_id] = c
|
||||
# c.connect("pressed", escoria.inputs_manager, "_on_inventory_item_pressed", [c.item_id])
|
||||
|
||||
escoria.esc_runner.connect("global_changed", self, "_on_escoria_global_changed")
|
||||
|
||||
|
||||
# add item to Inventory UI using its id set in its scene
|
||||
func add_new_item_by_id(item_id : String) -> void:
|
||||
if item_id.begins_with("i/"):
|
||||
item_id = item_id.rsplit("i/", false)[0]
|
||||
if !items_ids_in_inventory.has(item_id):
|
||||
var item_inventory_button = all_items.get_inventory_item(item_id).duplicate()
|
||||
items_ids_in_inventory[item_id] = item_inventory_button
|
||||
get_node(items_container).add_item(item_inventory_button)
|
||||
|
||||
# Add the item to inventory
|
||||
if !escoria.esc_runner.objects.has(item_id):
|
||||
escoria.esc_runner.register_object(item_id, item_inventory_button)
|
||||
item_inventory_button.visible = true
|
||||
|
||||
# connect this new item TextureButton's signals to our inventory UI
|
||||
item_inventory_button.connect("mouse_left_inventory_item",
|
||||
escoria.inputs_manager, "_on_mouse_left_click_inventory_item")
|
||||
item_inventory_button.connect("mouse_double_left_inventory_item",
|
||||
escoria.inputs_manager, "_on_mouse_double_left_click_inventory_item")
|
||||
item_inventory_button.connect("mouse_right_inventory_item",
|
||||
escoria.inputs_manager, "_on_mouse_right_click_inventory_item")
|
||||
|
||||
item_inventory_button.connect("inventory_item_focused",
|
||||
escoria.inputs_manager, "_on_mouse_entered_inventory_item")
|
||||
item_inventory_button.connect("inventory_item_unfocused",
|
||||
escoria.inputs_manager, "_on_mouse_exited_inventory_item")
|
||||
|
||||
# remove item fromInventory UI using its id set in its scene
|
||||
func remove_item_by_id(item_id : String) -> void:
|
||||
if items_ids_in_inventory.has(item_id):
|
||||
var item_inventory_button = items_ids_in_inventory[item_id]
|
||||
|
||||
item_inventory_button.disconnect("mouse_left_inventory_item",
|
||||
escoria.inputs_manager, "_on_mouse_left_click_inventory_item")
|
||||
item_inventory_button.disconnect("mouse_double_left_inventory_item",
|
||||
escoria.inputs_manager, "_on_mouse_double_left_click_inventory_item")
|
||||
item_inventory_button.disconnect("mouse_right_inventory_item",
|
||||
escoria.inputs_manager, "_on_mouse_right_click_inventory_item")
|
||||
item_inventory_button.disconnect("inventory_item_focused",
|
||||
escoria.inputs_manager, "_on_mouse_entered_inventory_item")
|
||||
item_inventory_button.disconnect("inventory_item_unfocused",
|
||||
escoria.inputs_manager, "_on_mouse_exited_inventory_item")
|
||||
|
||||
get_node(items_container).remove_item(item_inventory_button)
|
||||
item_inventory_button.queue_free()
|
||||
items_ids_in_inventory.erase(item_id)
|
||||
|
||||
func _on_escoria_global_changed(global : String) -> void:
|
||||
if !global.begins_with("i/"):
|
||||
return
|
||||
var item = global.rsplit("i/", false)
|
||||
if item.size() == 1:
|
||||
if escoria.esc_runner.globals[global] == "true":
|
||||
add_new_item_by_id(item[0])
|
||||
elif escoria.esc_runner.globals[global] == "false":
|
||||
remove_item_by_id(item[0])
|
||||
else:
|
||||
escoria.report_warnings("inventory_ui.gd:_on_escoria_global_changed()", \
|
||||
["Inventory global " + global + " is neither 'true' nor 'false' (was " + escoria.esc_runner.globals[global] + "). "])
|
||||
else:
|
||||
escoria.report_errors("inventory_ui.gd:_on_escoria_global_changed()", ["Global must contain 1 item name.", "(received: " + global + ")"])
|
||||
Reference in New Issue
Block a user