Created ESCGame class to force game.tscn scene to have empty functions by inheritance.
Also continued some tests about tooltip following mouse. Fixed project settings wrongly set.
This commit is contained in:
108
addons/escoria-core/game/core-scripts/escgame.gd
Normal file
108
addons/escoria-core/game/core-scripts/escgame.gd
Normal file
@@ -0,0 +1,108 @@
|
||||
tool
|
||||
extends Node2D
|
||||
class_name ESCGame
|
||||
|
||||
func get_class():
|
||||
return "ESCGame"
|
||||
|
||||
|
||||
export(float) var mouse_tooltip_margin = 50.0
|
||||
|
||||
### EDITOR TOOLS ###
|
||||
enum EDITOR_GAME_DEBUG_DISPLAY {
|
||||
NONE,
|
||||
MOUSE_TOOLTIP_LIMITS
|
||||
}
|
||||
export(EDITOR_GAME_DEBUG_DISPLAY) var editor_debug_mode = EDITOR_GAME_DEBUG_DISPLAY.NONE setget set_editor_debug_mode
|
||||
|
||||
|
||||
|
||||
func set_editor_debug_mode(p_editor_debug_mode : int) -> void:
|
||||
editor_debug_mode = p_editor_debug_mode
|
||||
update()
|
||||
|
||||
func _draw():
|
||||
if !Engine.is_editor_hint():
|
||||
return
|
||||
if editor_debug_mode == EDITOR_GAME_DEBUG_DISPLAY.NONE:
|
||||
return
|
||||
|
||||
if editor_debug_mode == EDITOR_GAME_DEBUG_DISPLAY.MOUSE_TOOLTIP_LIMITS:
|
||||
var mouse_limits : Rect2 = get_viewport_rect().grow(-mouse_tooltip_margin)
|
||||
print(mouse_limits)
|
||||
|
||||
# Draw lines for tooltip limits
|
||||
draw_rect(mouse_limits, ColorN("red"), false, 10.0)
|
||||
return
|
||||
|
||||
|
||||
## BACKGROUND ##
|
||||
func left_click_on_bg(position : Vector2) -> void:
|
||||
pass
|
||||
|
||||
func right_click_on_bg(position : Vector2) -> void:
|
||||
pass
|
||||
|
||||
func left_double_click_on_bg(position : Vector2) -> void:
|
||||
pass
|
||||
|
||||
## ITEM/HOTSPOT FOCUS ##
|
||||
func element_focused(element_id : String) -> void:
|
||||
pass
|
||||
|
||||
func element_unfocused() -> void:
|
||||
pass
|
||||
|
||||
|
||||
## ITEMS ##
|
||||
func left_click_on_item(item_global_id : String, event : InputEvent) -> void:
|
||||
pass
|
||||
|
||||
func right_click_on_item(item_global_id : String, event : InputEvent) -> void:
|
||||
pass
|
||||
|
||||
func left_double_click_on_item(item_global_id : String, event : InputEvent) -> void:
|
||||
pass
|
||||
|
||||
|
||||
## INVENTORY ##
|
||||
func left_click_on_inventory_item(inventory_item_global_id : String, event : InputEvent) -> void:
|
||||
pass
|
||||
|
||||
func right_click_on_inventory_item(inventory_item_global_id : String, event : InputEvent) -> void:
|
||||
pass
|
||||
|
||||
func left_double_click_on_inventory_item(inventory_item_global_id : String, event : InputEvent) -> void:
|
||||
pass
|
||||
|
||||
func inventory_item_focused(inventory_item_global_id : String) -> void:
|
||||
pass
|
||||
|
||||
func inventory_item_unfocused() -> void:
|
||||
pass
|
||||
|
||||
func open_inventory():
|
||||
pass
|
||||
|
||||
func close_inventory():
|
||||
pass
|
||||
|
||||
## MOUSEWHEEL ACTION ##
|
||||
func mousewheel_action(direction : int):
|
||||
pass
|
||||
|
||||
|
||||
## UI SPECIFICS
|
||||
func hide_ui():
|
||||
pass
|
||||
|
||||
func show_ui():
|
||||
pass
|
||||
|
||||
|
||||
## EVENTS
|
||||
func _on_event_done(event_name: String):
|
||||
pass
|
||||
|
||||
func _on_tooltip_position_update_required(p_position : Vector2):
|
||||
pass
|
||||
@@ -12,6 +12,11 @@ func _ready():
|
||||
func _input(event):
|
||||
if event.is_action_pressed("esc_show_debug_prompt"):
|
||||
escoria.main.get_node("layers/debug_layer/esc_prompt_popup").popup()
|
||||
|
||||
if ProjectSettings.get_setting("escoria/ui/tooltip_follows_mouse"):
|
||||
if !hotspot_focused.empty():
|
||||
if event is InputEventMouseMotion:
|
||||
escoria.main.current_scene.game.update_tooltip_position(event.position)
|
||||
|
||||
###################################################################################
|
||||
|
||||
@@ -79,7 +84,7 @@ func _on_mouse_entered_item(item : ESCItem) -> void:
|
||||
|
||||
func _on_mouse_exited_item(item : ESCItem) -> void:
|
||||
escoria.logger.info("Item unfocused : ", [item.global_id])
|
||||
hover_stack.erase(item)
|
||||
hover_stack_pop(item)
|
||||
if hover_stack.empty():
|
||||
hotspot_focused = ""
|
||||
escoria.main.current_scene.game.element_unfocused()
|
||||
@@ -116,3 +121,6 @@ func clean_hover_stack():
|
||||
for e in hover_stack:
|
||||
if e == null or !is_instance_valid(e):
|
||||
hover_stack.erase(e)
|
||||
|
||||
func hover_stack_pop(item):
|
||||
hover_stack.erase(item)
|
||||
|
||||
@@ -4,7 +4,7 @@ extends Node
|
||||
# This scene sets up the main menu scene to load.
|
||||
|
||||
func _ready():
|
||||
var main_menu_path = ProjectSettings.get_setting("escoria/main/main_menu_scene")
|
||||
var main_menu_path = ProjectSettings.get_setting("escoria/ui/main_menu_scene")
|
||||
var main_menu_scene = load(main_menu_path).instance()
|
||||
get_tree().get_root().call_deferred("add_child", main_menu_scene)
|
||||
escoria.set_main_menu(main_menu_scene)
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://addons/escoria-core/game/core-scripts/esccharacter.gd" type="Script" id=1]
|
||||
|
||||
|
||||
[sub_resource type="CapsuleShape2D" id=1]
|
||||
|
||||
[node name="character" type="KinematicBody2D"]
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="AnimatedSprite" type="AnimatedSprite" parent="."]
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource( 1 )
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||
@@ -1,3 +0,0 @@
|
||||
[gd_scene format=2]
|
||||
|
||||
[node name="game" type="CanvasLayer"]
|
||||
@@ -10,6 +10,8 @@ signal text_selected(text)
|
||||
export(NodePath) var path_to_richtextlabel
|
||||
const ONE_LINE_HEIGHT = 16
|
||||
export(int) var max_width = 200
|
||||
const MIN_HEIGHT = 30
|
||||
const MAX_HEIGHT = 500
|
||||
|
||||
func _ready():
|
||||
assert(!path_to_richtextlabel.is_empty())
|
||||
@@ -139,28 +141,28 @@ func update_size():
|
||||
# var nblines = float(rtl_node.get_content_height()) / float(ONE_LINE_HEIGHT)
|
||||
var nblines = nb_visible_lines
|
||||
if nblines >= 1:
|
||||
# reset size
|
||||
#get_parent().rect_size.x = 10
|
||||
#get_parent().rect_size.y = ONE_LINE_HEIGHT
|
||||
|
||||
yield(get_tree(), "idle_frame")
|
||||
yield(get_tree(), "idle_frame")
|
||||
var text_height = rtl_node.get_content_height()
|
||||
if text_height > MAX_HEIGHT:
|
||||
text_height = MAX_HEIGHT
|
||||
if text_height <= MIN_HEIGHT:
|
||||
text_height = MIN_HEIGHT
|
||||
|
||||
var parent_width = rtl_node.rect_size.x
|
||||
|
||||
# first, try to increase width until it goes above max_width
|
||||
while parent_width < max_width && float(text_height) / float(ONE_LINE_HEIGHT) > 1.0:
|
||||
rtl_node.rect_size.x += 1
|
||||
parent_width = rtl_node.rect_size.x
|
||||
yield(get_tree(), "idle_frame")
|
||||
yield(get_tree(), "idle_frame")
|
||||
# text_height = get_parent().rect_size.y
|
||||
|
||||
|
||||
rtl_node.rect_size.y = text_height
|
||||
|
||||
if rtl_node.rect_size.x >= max_width:
|
||||
rtl_node.rect_size.x = max_width
|
||||
|
||||
|
||||
|
||||
## END RECT_SIZE ##
|
||||
rtl_node.anchor_top = 0.0
|
||||
rtl_node.anchor_right = 0.0
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://addons/escoria-core/testing/rtl_screen_offset_testing.gd" type="Script" id=1]
|
||||
[ext_resource path="res://addons/escoria-core/template_scenes/label/target_tooltip.tscn" type="PackedScene" id=2]
|
||||
[ext_resource path="res://game/ui/ui_mouse_icons/tooltip/target_tooltip.tscn" type="PackedScene" id=2]
|
||||
|
||||
[sub_resource type="ButtonGroup" id=1]
|
||||
|
||||
@@ -72,7 +72,7 @@ margin_top = 56.0
|
||||
margin_right = 624.0
|
||||
margin_bottom = 80.0
|
||||
group = SubResource( 1 )
|
||||
text = "Une phrase extremement<br>longue pour tester<br>le comportement de ce RichTextLabel..."
|
||||
text = "A super extremely long sentence to test<br>the behaviour of that RichTextLabel node..."
|
||||
|
||||
[node name="tooltip" parent="." instance=ExtResource( 2 )]
|
||||
margin_left = 238.815
|
||||
@@ -81,7 +81,8 @@ margin_right = 638.815
|
||||
margin_bottom = 231.18
|
||||
rect_min_size = Vector2( 400, 0 )
|
||||
bbcode_text = "Tooltip content"
|
||||
fit_content_height = true
|
||||
text = "Tooltip content"
|
||||
|
||||
[connection signal="mouse_moved" from="." to="." method="_on_Control_mouse_moved"]
|
||||
[connection signal="text_selected" from="." to="." method="_on_Control_text_selected"]
|
||||
[connection signal="text_changed" from="VBoxContainer/HBoxContainer/clamp_distance" to="." method="_on_clamp_distance_text_changed"]
|
||||
|
||||
@@ -53,6 +53,7 @@ global_id = "r1_r_exit"
|
||||
esc_script = "res://game/rooms/room1/esc/right_exit.esc"
|
||||
is_exit = true
|
||||
tooltip_name = "Exit"
|
||||
default_action = "walk"
|
||||
dialog_color = Color( 1, 1, 1, 1 )
|
||||
interact_positions = {
|
||||
"default": Vector2( 1225.47, 353.99 )
|
||||
|
||||
@@ -54,6 +54,7 @@ global_id = "r2_r_exit"
|
||||
esc_script = "res://game/rooms/room2/esc/right_exit.esc"
|
||||
is_exit = true
|
||||
tooltip_name = "Right exit"
|
||||
default_action = "walk"
|
||||
dialog_color = Color( 1, 1, 1, 1 )
|
||||
interact_positions = {
|
||||
"default": Vector2( 1225.47, 353.99 )
|
||||
@@ -71,6 +72,7 @@ global_id = "r2_l_exit"
|
||||
esc_script = "res://game/rooms/room2/esc/left_exit.esc"
|
||||
is_exit = true
|
||||
tooltip_name = "Left exit"
|
||||
default_action = "walk"
|
||||
dialog_color = Color( 1, 1, 1, 1 )
|
||||
interact_positions = {
|
||||
"default": Vector2( 52.1462, 384.691 )
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
extends Node
|
||||
tool
|
||||
extends ESCGame
|
||||
|
||||
"""
|
||||
Implement methods to react to inputs.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[gd_scene load_steps=9 format=2]
|
||||
|
||||
[ext_resource path="res://addons/escoria-core/template_scenes/label/action_target_tooltip.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://game/ui/ui_9verbs/tooltip/action_target_tooltip.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://game/ui/ui_9verbs/inventory/inventory_ui.tscn" type="PackedScene" id=2]
|
||||
[ext_resource path="res://game/ui/ui_9verbs/verbs_menu.tscn" type="PackedScene" id=3]
|
||||
[ext_resource path="res://addons/escoria-core/game/scenes/dialogs/dialog_player.tscn" type="PackedScene" id=4]
|
||||
@@ -11,7 +11,7 @@
|
||||
[sub_resource type="StyleBoxFlat" id=1]
|
||||
bg_color = Color( 0.6, 0.6, 0.6, 0.5 )
|
||||
|
||||
[node name="game" type="Node"]
|
||||
[node name="game" type="Node2D"]
|
||||
script = ExtResource( 5 )
|
||||
|
||||
[node name="ui" type="CanvasLayer" parent="."]
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[gd_scene load_steps=5 format=2]
|
||||
|
||||
[ext_resource path="res://addons/escoria-core/game/assets/fonts/onesize/ONESIZE_.TTF" type="DynamicFontData" id=1]
|
||||
[ext_resource path="res://addons/escoria-core/template_scenes/label/action_target_tooltip.gd" type="Script" id=2]
|
||||
[ext_resource path="res://game/ui/ui_9verbs/tooltip/action_target_tooltip.gd" type="Script" id=2]
|
||||
|
||||
[sub_resource type="DynamicFont" id=1]
|
||||
size = 30
|
||||
@@ -1,4 +1,5 @@
|
||||
extends Node
|
||||
tool
|
||||
extends ESCGame
|
||||
|
||||
"""
|
||||
Implement methods to react to inputs.
|
||||
@@ -17,43 +18,49 @@ Implement methods to react to inputs.
|
||||
- left_click_on_item(item_global_id : String, event : InputEvent)
|
||||
- right_click_on_item(item_global_id : String, event : InputEvent)
|
||||
- left_double_click_on_item(item_global_id : String, event : InputEvent)
|
||||
|
||||
- inventory_item_focused(inventory_item_global_id : String) -> void
|
||||
- inventory_item_unfocused() -> void
|
||||
|
||||
- open_inventory()
|
||||
- close_inventory()
|
||||
|
||||
- mousewheel_action(direction : int)
|
||||
|
||||
- hide_ui()
|
||||
- show_ui()
|
||||
|
||||
- _on_event_done(event_name: String)
|
||||
- update_tooltip_position(p_position : Vector2)
|
||||
|
||||
"""
|
||||
|
||||
signal element_focused(element_global_id)
|
||||
|
||||
|
||||
#func _input(event):
|
||||
# if event.is_action_pressed("switch_action_verb"):
|
||||
# if event.button_index == BUTTON_WHEEL_UP:
|
||||
# $ui/verbs_layer/verbs_menu.iterate_actions_cursor(-1)
|
||||
# elif event.button_index == BUTTON_WHEEL_DOWN:
|
||||
# $ui/verbs_layer/verbs_menu.iterate_actions_cursor(1)
|
||||
|
||||
## BACKGROUND ##
|
||||
|
||||
func left_click_on_bg(position : Vector2) -> void:
|
||||
escoria.do("walk", ["player", position])
|
||||
$ui/verbs_layer/verbs_menu.set_by_name("walk")
|
||||
|
||||
func right_click_on_bg(position : Vector2) -> void:
|
||||
escoria.do("walk", ["player", position])
|
||||
$ui/verbs_layer/verbs_menu.set_by_name("walk")
|
||||
|
||||
func left_double_click_on_bg(position : Vector2) -> void:
|
||||
escoria.do("walk", ["player", position, true])
|
||||
|
||||
$ui/verbs_layer/verbs_menu.set_by_name("walk")
|
||||
|
||||
## ITEM/HOTSPOT FOCUS ##
|
||||
|
||||
func element_focused(element_id : String) -> void:
|
||||
#emit_signal("element_focused", element_id)
|
||||
var target_obj = escoria.esc_runner.get_object(element_id)
|
||||
$ui/tooltip_layer/tooltip.text = target_obj.tooltip_name
|
||||
|
||||
if escoria.esc_runner.current_action != "use" && escoria.esc_runner.current_tool == null:
|
||||
if target_obj is ESCItem or target_obj is ESCHotspot:
|
||||
if target_obj is ESCItem:
|
||||
$ui/verbs_layer/verbs_menu.set_by_name(target_obj.default_action)
|
||||
|
||||
func element_unfocused() -> void:
|
||||
#emit_signal("element_focused", "")
|
||||
#$ui/verbs_layer/verbs_menu.set_by_name("walk")
|
||||
pass
|
||||
$ui/tooltip_layer/tooltip.text = ""
|
||||
|
||||
|
||||
## ITEMS ##
|
||||
@@ -86,10 +93,10 @@ func left_double_click_on_inventory_item(inventory_item_global_id : String, even
|
||||
pass
|
||||
|
||||
func inventory_item_focused(inventory_item_global_id : String) -> void:
|
||||
emit_signal("element_focused", inventory_item_global_id)
|
||||
$ui/tooltip_layer/tooltip.set_target(escoria.esc_runner.get_object(inventory_item_global_id).tooltip_name)
|
||||
|
||||
func inventory_item_unfocused() -> void:
|
||||
emit_signal("element_focused", "")
|
||||
$ui/tooltip_layer/tooltip.set_target("")
|
||||
|
||||
|
||||
func open_inventory():
|
||||
@@ -101,3 +108,17 @@ func close_inventory():
|
||||
|
||||
func mousewheel_action(direction : int):
|
||||
$ui/verbs_layer/verbs_menu.iterate_actions_cursor(direction)
|
||||
|
||||
func hide_ui():
|
||||
$ui/inventory_layer/inventory_ui.hide()
|
||||
|
||||
func show_ui():
|
||||
$ui/inventory_layer/inventory_ui.show()
|
||||
|
||||
func _on_event_done(event_name: String):
|
||||
escoria.esc_runner.clear_current_action()
|
||||
|
||||
|
||||
func update_tooltip_position(p_position : Vector2):
|
||||
# + Vector2(-200,-50)
|
||||
$ui/tooltip_layer/tooltip.global_position = p_position
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
[gd_scene load_steps=6 format=2]
|
||||
[gd_scene load_steps=7 format=2]
|
||||
|
||||
[ext_resource path="res://game/ui/ui_mouse_icons/inventory/inventory_ui.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://addons/escoria-core/game/scenes/dialogs/dialog_player.tscn" type="PackedScene" id=2]
|
||||
[ext_resource path="res://addons/escoria-core/game/scenes/camera_player/camera.tscn" type="PackedScene" id=3]
|
||||
[ext_resource path="res://game/ui/ui_mouse_icons/verbs_mouseicons.tscn" type="PackedScene" id=4]
|
||||
[ext_resource path="res://game/ui/ui_mouse_icons/game.gd" type="Script" id=5]
|
||||
[ext_resource path="res://game/ui/ui_mouse_icons/tooltip/target_tooltip.tscn" type="PackedScene" id=6]
|
||||
|
||||
[node name="game" type="Node"]
|
||||
[node name="game" type="Node2D"]
|
||||
script = ExtResource( 5 )
|
||||
|
||||
[node name="ui" type="CanvasLayer" parent="."]
|
||||
@@ -32,6 +33,9 @@ margin_bottom = -583.507
|
||||
[node name="tooltip_layer" type="CanvasLayer" parent="ui"]
|
||||
layer = 2
|
||||
|
||||
[node name="tooltip" parent="ui/tooltip_layer" instance=ExtResource( 6 )]
|
||||
mouse_filter = 2
|
||||
|
||||
[node name="dialog_layer" type="CanvasLayer" parent="ui"]
|
||||
layer = 3
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ extends RichTextLabel
|
||||
|
||||
var current_target : String
|
||||
|
||||
|
||||
func set_target(target : String) -> void:
|
||||
current_target = target
|
||||
update_tooltip_text()
|
||||
@@ -1,7 +1,7 @@
|
||||
[gd_scene load_steps=5 format=2]
|
||||
|
||||
[ext_resource path="res://addons/escoria-core/game/assets/fonts/onesize/ONESIZE_.TTF" type="DynamicFontData" id=1]
|
||||
[ext_resource path="res://addons/escoria-core/template_scenes/label/target_tooltip.gd" type="Script" id=2]
|
||||
[ext_resource path="res://game/ui/ui_mouse_icons/tooltip/target_tooltip.gd" type="Script" id=2]
|
||||
|
||||
[sub_resource type="DynamicFont" id=1]
|
||||
size = 30
|
||||
@@ -53,6 +53,10 @@ margin_bottom = 132.0
|
||||
texture = ExtResource( 4 )
|
||||
|
||||
[node name="mouse_position" type="Control" parent="."]
|
||||
margin_left = 323.435
|
||||
margin_top = 57.9191
|
||||
margin_right = 323.435
|
||||
margin_bottom = 57.9191
|
||||
mouse_filter = 2
|
||||
|
||||
[node name="tool" type="TextureRect" parent="mouse_position"]
|
||||
|
||||
@@ -29,6 +29,11 @@ _global_script_classes=[ {
|
||||
"language": "GDScript",
|
||||
"path": "res://addons/escoria-core/game/scenes/dialogs/dialog_player.gd"
|
||||
}, {
|
||||
"base": "Node2D",
|
||||
"class": "ESCGame",
|
||||
"language": "GDScript",
|
||||
"path": "res://addons/escoria-core/game/core-scripts/escgame.gd"
|
||||
}, {
|
||||
"base": "Control",
|
||||
"class": "ESCInventory",
|
||||
"language": "GDScript",
|
||||
@@ -69,6 +74,7 @@ _global_script_class_icons={
|
||||
"ESCCamera": "",
|
||||
"ESCCharacter": "",
|
||||
"ESCDialogsPlayer": "",
|
||||
"ESCGame": "",
|
||||
"ESCInventory": "",
|
||||
"ESCInventoryItem": "",
|
||||
"ESCItem": "",
|
||||
@@ -108,18 +114,17 @@ enabled=PoolStringArray( "escoria-core" )
|
||||
|
||||
[escoria]
|
||||
|
||||
debug/terminate_on_errors=true
|
||||
main/game_start_script="res://game/start_game.esc"
|
||||
main/main_menu_scene="res://game/ui/commons/main_menu.tscn"
|
||||
debug/terminate_on_warnings=false
|
||||
main/force_quit=true
|
||||
internals/save_data=""
|
||||
debug/terminate_on_warnings=false
|
||||
debug/terminate_on_errors=true
|
||||
debug/development_lang="en"
|
||||
ui/tooltip_follows_mouse=true
|
||||
ui/game_scene="res://game/ui/ui_9verbs/game.tscn"
|
||||
ui/main_menu_scene="res://game/ui/commons/main_menu.tscn"
|
||||
ui/default_dialog_scene="res://game/ui/commons/dialogs/dialog_label.tscn"
|
||||
ui/tooltip_follows_mouse=false
|
||||
ui/dialogs_folder="res://game/ui/commons/dialogs"
|
||||
ui/default_dialog_scene="res://game/ui/commons/dialogs/dialog_label.tscn"
|
||||
ui/main_menu_scene="res://game/ui/commons/main_menu.tscn"
|
||||
ui/game_scene="res://game/ui/ui_9verbs/game.tscn"
|
||||
internals/save_data=""
|
||||
|
||||
[input]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user