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:
Julian Murgia
2021-02-11 07:15:55 +01:00
parent 6aa466d6d2
commit 52d19c34bd
19 changed files with 204 additions and 67 deletions

View 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

View File

@@ -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)

View File

@@ -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)

View File

@@ -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="."]

View File

@@ -1,3 +0,0 @@
[gd_scene format=2]
[node name="game" type="CanvasLayer"]

View File

@@ -1,55 +0,0 @@
extends RichTextLabel
# Infinitive verb
var current_action : String
# Target item/hotspot
var current_target : String
# Preposition: on, with...
var current_prep : String = "with"
# Target 2 item/hotspot
var current_target2 : String
var waiting_for_target2 = false
func _ready():
escoria.esc_runner.connect("action_changed", self, "on_action_selected")
func on_action_selected() -> void:
current_action = escoria.esc_runner.current_action
update_tooltip_text()
func set_target(target : String, needs_second_target : bool = false) -> void:
current_target = target
if needs_second_target:
waiting_for_target2 = true
update_tooltip_text()
func set_target2(target2 : String) -> void:
current_target2 = target2
update_tooltip_text()
func update_tooltip_text():
bbcode_text = "[center]"
if !current_action.empty():
bbcode_text += current_action
bbcode_text += "\t"
bbcode_text += current_target
if waiting_for_target2 and current_target2.empty():
bbcode_text += "\t"
bbcode_text += current_prep
if !current_target2.empty():
bbcode_text += "\t"
bbcode_text += current_prep
bbcode_text += "\t"
bbcode_text += current_target2
bbcode_text += "[/center]"

View File

@@ -1,26 +0,0 @@
[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]
[sub_resource type="DynamicFont" id=1]
size = 30
font_data = ExtResource( 1 )
[sub_resource type="DynamicFont" id=2]
size = 30
font_data = ExtResource( 1 )
[node name="tooltip" type="RichTextLabel"]
anchor_right = 0.526
anchor_bottom = 0.06
margin_right = -0.280029
margin_bottom = -10.0
custom_fonts/mono_font = SubResource( 1 )
custom_fonts/normal_font = SubResource( 2 )
bbcode_enabled = true
scroll_active = false
script = ExtResource( 2 )
__meta__ = {
"_edit_use_anchors_": false
}

View File

@@ -1,11 +0,0 @@
extends RichTextLabel
var current_target : String
func set_target(target : String) -> void:
current_target = target
update_tooltip_text()
func update_tooltip_text():
bbcode_text = current_target

View File

@@ -1,28 +0,0 @@
[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]
[sub_resource type="DynamicFont" id=1]
size = 30
font_data = ExtResource( 1 )
[sub_resource type="DynamicFont" id=2]
size = 30
font_data = ExtResource( 1 )
[node name="tooltip" type="RichTextLabel"]
anchor_right = 0.7
anchor_bottom = 0.06
margin_left = 1.49829
margin_right = 1.21826
margin_bottom = -10.0
custom_fonts/mono_font = SubResource( 1 )
custom_fonts/normal_font = SubResource( 2 )
bbcode_enabled = true
bbcode_text = "[center][/center]"
scroll_active = false
script = ExtResource( 2 )
__meta__ = {
"_edit_use_anchors_": false
}

View File

@@ -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

View File

@@ -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"]