Initial commit of Escoria-Reloaded. Still a lot of missing stuff.
This commit is contained in:
BIN
addons/escoria-core/testing/NotoSans-Regular.ttf
Normal file
BIN
addons/escoria-core/testing/NotoSans-Regular.ttf
Normal file
Binary file not shown.
8
addons/escoria-core/testing/README
Normal file
8
addons/escoria-core/testing/README
Normal file
@@ -0,0 +1,8 @@
|
||||
In this folder, you can find various scenes and tools to test some of the scenes of your actual game project.
|
||||
|
||||
These scenes are not intended to be shipped with your game, you may want to use them only for testing purposes, such as:
|
||||
|
||||
- RichTextLabels screen clamping (rtl_screen_clamping.tscn)
|
||||
This scene helps you test the RichTextLabels used in your game, such as labels used when pointing an item or NPC or dialogs.
|
||||
To use this testing scene, simply add your actual label scene as a child of the root node and set the path to this node in it.
|
||||
You can then run the scene, move your mouse around the edges of the screen and see if the label reacts properly.
|
||||
231
addons/escoria-core/testing/player_angles_finder.gd
Normal file
231
addons/escoria-core/testing/player_angles_finder.gd
Normal file
@@ -0,0 +1,231 @@
|
||||
extends Node2D
|
||||
|
||||
# This scenes purpose is to help determining the angles between X and Y axis
|
||||
# when clicking somewhere on the screen.
|
||||
# Let us consider that player position is always 0,0.
|
||||
# Clicking right above his head is angle 0.
|
||||
# Clicking on the right is angle 90.
|
||||
# Clicking under his feet is angle 180.
|
||||
# etc.
|
||||
|
||||
var number_of_directions : int
|
||||
var angle_horizontal_axes : float
|
||||
var angle_vertical_axes : float
|
||||
var angle_diagonal_axes : float
|
||||
const POLYGON_DISTANCE = 400
|
||||
|
||||
enum Directions {
|
||||
NORTH, # 0
|
||||
NORTHEAST, # 1
|
||||
EAST, # 2
|
||||
SOUTHEAST, # 3
|
||||
SOUTH, # 4
|
||||
SOUTHWEST, # 5
|
||||
WEST, # 6
|
||||
NORTHWEST # 7
|
||||
}
|
||||
|
||||
const starting_angles = [
|
||||
0, # 0 NORTH
|
||||
PI/4, # 1 NORTHEAST
|
||||
PI/2, # 2 EAST
|
||||
3*PI/4, # 3 SOUTHEAST
|
||||
PI, # 4 SOUTH
|
||||
5*PI/4, # 5 SOUTHWEST
|
||||
3*PI/2, # 6 WEST
|
||||
7*PI/4, # 7 NORTHWEST
|
||||
]
|
||||
|
||||
var colors = [
|
||||
ColorN("red"), # 0 NORTH
|
||||
ColorN("green"), # 1 NORTHEAST
|
||||
ColorN("blue"), # 2 EAST
|
||||
ColorN("black"), # 3 SOUTHEAST
|
||||
ColorN("yellow"), # 4 SOUTH
|
||||
ColorN("cyan"), # 5 SOUTHWEST
|
||||
ColorN("white"), # 6 WEST
|
||||
ColorN("purple") # 7 NORTHWEST
|
||||
]
|
||||
|
||||
var result_angles = []
|
||||
|
||||
#onready var result_angles_anim = {
|
||||
# "angle_offset_rad" : PI/2,
|
||||
# Directions.NORTH : {
|
||||
# "direction_base_angle_rad" : 0,
|
||||
# "angle_start_deg" : 0,
|
||||
# "angle_area_deg" : 0,
|
||||
# "animations" : {}
|
||||
# },
|
||||
# Directions.NORTHEAST : {
|
||||
# "direction_base_angle_rad" : PI/4,
|
||||
# "angle_start_deg" : 0,
|
||||
# "angle_area_deg" : 0,
|
||||
# "animation" : ""
|
||||
# },
|
||||
# Directions.EAST : {
|
||||
# "direction_base_angle_rad" : PI/2,
|
||||
# "angle_start_deg" : 0,
|
||||
# "angle_area_deg" : 0,
|
||||
# "animation" : ""
|
||||
# },
|
||||
# Directions.SOUTHEAST : {
|
||||
# "direction_base_angle_rad" : 3*PI/4,
|
||||
# "angle_start_deg" : 0,
|
||||
# "angle_area_deg" : 0,
|
||||
# "animation" : ""
|
||||
# },
|
||||
# Directions.SOUTH : {
|
||||
# "direction_base_angle_rad" : PI,
|
||||
# "angle_start_deg" : 0,
|
||||
# "angle_area_deg" : 0,
|
||||
# "animation" : ""
|
||||
#
|
||||
# },
|
||||
# Directions.SOUTHWEST : {
|
||||
# "direction_base_angle_rad" : 5*PI/4,
|
||||
# "angle_start_deg" : 0,
|
||||
# "angle_area_deg" : 0,
|
||||
# "animation" : ""
|
||||
# },
|
||||
# Directions.WEST : {
|
||||
# "direction_base_angle_rad" : 3*PI/2,
|
||||
# "angle_start_deg" : 0,
|
||||
# "angle_area_deg" : 0,
|
||||
# "animation" : ""
|
||||
# },
|
||||
# Directions.NORTHWEST : {
|
||||
# "direction_base_angle_rad" : 7*PI/4,
|
||||
# "angle_start_deg" : 0,
|
||||
# "angle_area_deg" : 0,
|
||||
# "animation" : ""
|
||||
# }
|
||||
# }
|
||||
|
||||
|
||||
|
||||
func _ready():
|
||||
# Find player animations
|
||||
$player_animations.add_item("")
|
||||
for anim_name in $player.get_animations_list():
|
||||
$player_animations.add_item(anim_name)
|
||||
|
||||
# Set initial angles
|
||||
var initial_angle : float = 360.0 / 8.0
|
||||
$VBoxContainer/angle_x/angle_horiz.text = str(40)
|
||||
$VBoxContainer/angle_y/angle_vert.text = str(40)
|
||||
$VBoxContainer/angle_diag/angle_diag.text = str(50)
|
||||
angle_horizontal_axes = 40
|
||||
angle_vertical_axes = 40
|
||||
angle_diagonal_axes = 50
|
||||
|
||||
calculate_areas()
|
||||
|
||||
|
||||
func _on_number_of_directions_text_changed(new_text : String):
|
||||
if !new_text.is_valid_integer():
|
||||
return
|
||||
number_of_directions = int(new_text)
|
||||
calculate_areas(number_of_directions)
|
||||
|
||||
|
||||
func clear_areas_node():
|
||||
for n in $areas.get_children():
|
||||
n.queue_free()
|
||||
|
||||
|
||||
func calculate_areas(nb_directions : int = 8):
|
||||
clear_areas_node()
|
||||
var angles = []
|
||||
for i in range(nb_directions):
|
||||
var angle_area : float = 0.0
|
||||
var start_angle : float = 0.0
|
||||
# MANUAL
|
||||
match i:
|
||||
Directions.EAST,Directions.WEST:
|
||||
angle_area = deg2rad(angle_horizontal_axes)
|
||||
Directions.NORTH,Directions.SOUTH:
|
||||
angle_area = deg2rad(angle_vertical_axes)
|
||||
Directions.NORTHEAST,Directions.NORTHWEST,Directions.SOUTHEAST,Directions.SOUTHWEST:
|
||||
angle_area = deg2rad(angle_diagonal_axes)
|
||||
|
||||
# Since angles start from EAST, offset by -PI/2 (= -90°) to start on up direction
|
||||
# Then minus angle_area/2 to align on direction
|
||||
start_angle = PI/2 + angle_area / 2
|
||||
|
||||
var angle_start = starting_angles[i] - start_angle
|
||||
var angle_end = angle_start + angle_area
|
||||
angles.push_back([angle_start, angle_end])
|
||||
|
||||
result_angles.push_back([clamp360(rad2deg(angle_start) + rad2deg(PI/2)),clamp360(rad2deg(angle_area))])
|
||||
|
||||
$VBoxContainer/VBoxContainer/angles/angle_array.text = str(result_angles)
|
||||
construct_scene_nodes(angles)
|
||||
|
||||
func construct_scene_nodes(angles):
|
||||
|
||||
var areas_nodes = []
|
||||
for i in angles.size():
|
||||
var polygon_node = Polygon2D.new()
|
||||
polygon_node.color = colors[i]
|
||||
var area_node = Area2D.new()
|
||||
area_node.name = Directions.keys()[i]
|
||||
area_node.connect("input_event", self, "_on_area_click", [area_node.name])
|
||||
polygon_node.add_child(area_node)
|
||||
|
||||
var collision = CollisionShape2D.new()
|
||||
var collision_shape = ConvexPolygonShape2D.new()
|
||||
|
||||
var p_points = []
|
||||
p_points.push_back($player.position)
|
||||
p_points.push_back(polar2cartesian(POLYGON_DISTANCE, angles[i][0]) + $player.position)
|
||||
p_points.push_back(polar2cartesian(POLYGON_DISTANCE, angles[i][1]) + $player.position)
|
||||
polygon_node.polygon = p_points
|
||||
collision_shape.points = p_points
|
||||
collision.set_shape(collision_shape)
|
||||
area_node.add_child(collision)
|
||||
|
||||
$areas.add_child(polygon_node)
|
||||
|
||||
|
||||
func _on_angle_horiz_text_changed(new_text : String):
|
||||
if !new_text.is_valid_float():
|
||||
return
|
||||
angle_horizontal_axes = float(new_text)
|
||||
# result_angles_anim.Directions.EAST.angle_area_deg = clamp360(angle_horizontal_axes)
|
||||
# result_angles_anim.Directions.WEST.angle_area_deg = clamp360(angle_horizontal_axes)
|
||||
calculate_areas()
|
||||
|
||||
|
||||
func _on_angle_vert_text_changed(new_text : String):
|
||||
if !new_text.is_valid_float():
|
||||
return
|
||||
angle_vertical_axes = float(new_text)
|
||||
# result_angles_anim.Directions.NORTH.angle_area_deg = clamp360(angle_vertical_axes)
|
||||
# result_angles_anim.Directions.SOUTH.angle_area_deg = clamp360(angle_vertical_axes)
|
||||
calculate_areas()
|
||||
|
||||
|
||||
func _on_angle_diag_text_changed(new_text : String):
|
||||
if !new_text.is_valid_float():
|
||||
return
|
||||
angle_diagonal_axes = float(new_text)
|
||||
# result_angles_anim.Directions.NORTHEAST.angle_area_deg = clamp360(angle_diagonal_axes)
|
||||
# result_angles_anim.Directions.SOUTHEAST.angle_area_deg = clamp360(angle_diagonal_axes)
|
||||
# result_angles_anim.Directions.NORTHWEST.angle_area_deg = clamp360(angle_diagonal_axes)
|
||||
# result_angles_anim.Directions.SOUTHWEST.angle_area_deg = clamp360(angle_diagonal_axes)
|
||||
calculate_areas()
|
||||
|
||||
|
||||
func _on_area_click(viewport: Object, event: InputEvent, shape_idx: int, area_name : String):
|
||||
if event is InputEventMouseButton and event.is_pressed():
|
||||
pass
|
||||
|
||||
func clamp360(angle : float):
|
||||
if angle < 0.0:
|
||||
while angle < 0.0:
|
||||
angle += 360.0
|
||||
elif angle >= 360.0:
|
||||
while angle >= 360.0:
|
||||
angle -= 360.0
|
||||
return angle
|
||||
219
addons/escoria-core/testing/player_angles_finder.tscn
Normal file
219
addons/escoria-core/testing/player_angles_finder.tscn
Normal file
@@ -0,0 +1,219 @@
|
||||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://game/characters/guybrush/guybrush.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://addons/escoria-core/testing/player_angles_finder.gd" type="Script" id=2]
|
||||
|
||||
[node name="player_angles_finder" type="Node2D"]
|
||||
script = ExtResource( 2 )
|
||||
|
||||
[node name="areas" type="Node2D" parent="."]
|
||||
|
||||
[node name="player" parent="." instance=ExtResource( 1 )]
|
||||
position = Vector2( 640, 480 )
|
||||
dialog_position_node = NodePath("../../player_angles_finder/player/dialog_position")
|
||||
|
||||
[node name="x_axis" type="Line2D" parent="."]
|
||||
points = PoolVector2Array( -10, 480, 1300, 480 )
|
||||
width = 2.0
|
||||
default_color = Color( 0.980392, 0.00392157, 0.00392157, 1 )
|
||||
|
||||
[node name="y_axis" type="Line2D" parent="."]
|
||||
points = PoolVector2Array( 640, -20, 640, 810 )
|
||||
width = 2.0
|
||||
default_color = Color( 0.156863, 0.0117647, 0.984314, 1 )
|
||||
|
||||
[node name="three" type="Node2D" parent="."]
|
||||
visible = false
|
||||
|
||||
[node name="Line2D" type="Line2D" parent="three"]
|
||||
points = PoolVector2Array( 160, 0, 1120, 960 )
|
||||
width = 2.0
|
||||
default_color = Color( 1, 1, 1, 1 )
|
||||
|
||||
[node name="Line2D2" type="Line2D" parent="three"]
|
||||
points = PoolVector2Array( 160, 960, 1120, 0 )
|
||||
width = 2.0
|
||||
default_color = Color( 1, 1, 1, 1 )
|
||||
|
||||
[node name="six" type="Node2D" parent="."]
|
||||
visible = false
|
||||
|
||||
[node name="Line2D" type="Line2D" parent="six"]
|
||||
points = PoolVector2Array( 0, 210, 640, 480 )
|
||||
width = 2.0
|
||||
default_color = Color( 1, 1, 1, 1 )
|
||||
|
||||
[node name="Line2D4" type="Line2D" parent="six"]
|
||||
points = PoolVector2Array( 320, 0, 640, 480 )
|
||||
width = 2.0
|
||||
default_color = Color( 1, 1, 1, 1 )
|
||||
|
||||
[node name="Line2D2" type="Line2D" parent="six"]
|
||||
points = PoolVector2Array( 640, 480, 1280, 210 )
|
||||
width = 2.0
|
||||
default_color = Color( 1, 1, 1, 1 )
|
||||
|
||||
[node name="Line2D3" type="Line2D" parent="six"]
|
||||
points = PoolVector2Array( 640, 480, 960, 0 )
|
||||
width = 2.0
|
||||
default_color = Color( 1, 1, 1, 1 )
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="."]
|
||||
margin_right = 40.0
|
||||
margin_bottom = 40.0
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
|
||||
visible = false
|
||||
margin_right = 420.0
|
||||
margin_bottom = 24.0
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Label" type="Label" parent="VBoxContainer/HBoxContainer"]
|
||||
margin_top = 5.0
|
||||
margin_right = 136.0
|
||||
margin_bottom = 19.0
|
||||
text = "Number of directions"
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="number_of_directions" type="LineEdit" parent="VBoxContainer/HBoxContainer"]
|
||||
margin_left = 140.0
|
||||
margin_right = 198.0
|
||||
margin_bottom = 24.0
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="angle_x" type="HBoxContainer" parent="VBoxContainer"]
|
||||
margin_right = 235.0
|
||||
margin_bottom = 24.0
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Label" type="Label" parent="VBoxContainer/angle_x"]
|
||||
margin_top = 5.0
|
||||
margin_right = 173.0
|
||||
margin_bottom = 19.0
|
||||
text = "Angle on horizontal axis (X)"
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="angle_horiz" type="LineEdit" parent="VBoxContainer/angle_x"]
|
||||
margin_left = 177.0
|
||||
margin_right = 235.0
|
||||
margin_bottom = 24.0
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="angle_y" type="HBoxContainer" parent="VBoxContainer"]
|
||||
margin_top = 28.0
|
||||
margin_right = 235.0
|
||||
margin_bottom = 52.0
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Label" type="Label" parent="VBoxContainer/angle_y"]
|
||||
margin_top = 5.0
|
||||
margin_right = 155.0
|
||||
margin_bottom = 19.0
|
||||
text = "Angle on vertical axis (Y)"
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="angle_vert" type="LineEdit" parent="VBoxContainer/angle_y"]
|
||||
margin_left = 159.0
|
||||
margin_right = 217.0
|
||||
margin_bottom = 24.0
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="angle_diag" type="HBoxContainer" parent="VBoxContainer"]
|
||||
margin_top = 56.0
|
||||
margin_right = 235.0
|
||||
margin_bottom = 80.0
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Label" type="Label" parent="VBoxContainer/angle_diag"]
|
||||
margin_top = 5.0
|
||||
margin_right = 146.0
|
||||
margin_bottom = 19.0
|
||||
text = "Angle on diagonal axes"
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="angle_diag" type="LineEdit" parent="VBoxContainer/angle_diag"]
|
||||
margin_left = 150.0
|
||||
margin_right = 208.0
|
||||
margin_bottom = 24.0
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="HSeparator" type="HSeparator" parent="VBoxContainer"]
|
||||
margin_top = 84.0
|
||||
margin_right = 235.0
|
||||
margin_bottom = 88.0
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="VBoxContainer"]
|
||||
margin_top = 92.0
|
||||
margin_right = 235.0
|
||||
margin_bottom = 116.0
|
||||
__meta__ = {
|
||||
"_editor_description_": ""
|
||||
}
|
||||
|
||||
[node name="angles" type="HBoxContainer" parent="VBoxContainer/VBoxContainer"]
|
||||
margin_right = 235.0
|
||||
margin_bottom = 24.0
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Label" type="Label" parent="VBoxContainer/VBoxContainer/angles"]
|
||||
margin_top = 5.0
|
||||
margin_right = 78.0
|
||||
margin_bottom = 19.0
|
||||
text = "Angles array"
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="angle_array" type="LineEdit" parent="VBoxContainer/VBoxContainer/angles"]
|
||||
margin_left = 82.0
|
||||
margin_right = 235.0
|
||||
margin_bottom = 24.0
|
||||
size_flags_horizontal = 3
|
||||
editable = false
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="player_animations" type="OptionButton" parent="."]
|
||||
visible = false
|
||||
margin_left = 470.0
|
||||
margin_top = 10.0
|
||||
margin_right = 638.0
|
||||
margin_bottom = 33.0
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
[connection signal="text_changed" from="VBoxContainer/HBoxContainer/number_of_directions" to="." method="_on_number_of_directions_text_changed"]
|
||||
[connection signal="text_changed" from="VBoxContainer/angle_x/angle_horiz" to="." method="_on_angle_horiz_text_changed"]
|
||||
[connection signal="text_changed" from="VBoxContainer/angle_y/angle_vert" to="." method="_on_angle_vert_text_changed"]
|
||||
[connection signal="text_changed" from="VBoxContainer/angle_diag/angle_diag" to="." method="_on_angle_diag_text_changed"]
|
||||
[connection signal="text_changed" from="VBoxContainer/VBoxContainer/angles/angle_array" to="." method="_on_angle_diag_text_changed"]
|
||||
169
addons/escoria-core/testing/rtl_screen_offset_testing.gd
Normal file
169
addons/escoria-core/testing/rtl_screen_offset_testing.gd
Normal file
@@ -0,0 +1,169 @@
|
||||
extends Control
|
||||
|
||||
onready var screen_width = get_tree().get_root().get_viewport().size.x
|
||||
onready var screen_height = get_tree().get_root().get_viewport().size.y
|
||||
var global_distance_to_clamp = 40 setget set_global_dist_clamp,get_global_dist_clamp
|
||||
|
||||
signal mouse_moved(position)
|
||||
signal text_selected(text)
|
||||
|
||||
export(NodePath) var path_to_richtextlabel
|
||||
const ONE_LINE_HEIGHT = 16
|
||||
export(int) var max_width = 200
|
||||
|
||||
func _ready():
|
||||
assert(!path_to_richtextlabel.is_empty())
|
||||
$VBoxContainer/HBoxContainer/clamp_distance.text = str(global_distance_to_clamp)
|
||||
|
||||
# Add a white TextureRect behind the RTL to see its actual size
|
||||
var texturerect_node = TextureRect.new()
|
||||
get_node(path_to_richtextlabel).add_child(texturerect_node)
|
||||
texturerect_node.texture = load("res://addons/escoria-core/testing/white.png")
|
||||
texturerect_node.expand = true
|
||||
texturerect_node.stretch_mode = TextureRect.STRETCH_TILE
|
||||
texturerect_node.size_flags_horizontal = SIZE_EXPAND_FILL
|
||||
texturerect_node.size_flags_vertical = SIZE_EXPAND_FILL
|
||||
texturerect_node.show_behind_parent = true
|
||||
texturerect_node.anchor_right = 1.0
|
||||
texturerect_node.anchor_bottom = 1.0
|
||||
move_child(get_node(path_to_richtextlabel), 1)
|
||||
|
||||
update_line2d()
|
||||
_on_new_text_pressed()
|
||||
set_process_input(true)
|
||||
|
||||
func set_path_to_richtextlabel(path):
|
||||
path_to_richtextlabel = path
|
||||
|
||||
|
||||
func _input(event):
|
||||
if event is InputEventMouseMotion:
|
||||
emit_signal("mouse_moved", event.position)
|
||||
|
||||
func set_global_dist_clamp(d):
|
||||
global_distance_to_clamp = d
|
||||
update_line2d()
|
||||
|
||||
func get_global_dist_clamp():
|
||||
return global_distance_to_clamp
|
||||
|
||||
func update_line2d():
|
||||
$Line2D.clear_points()
|
||||
$Line2D.add_point(Vector2(global_distance_to_clamp, global_distance_to_clamp))
|
||||
$Line2D.add_point(Vector2(global_distance_to_clamp, screen_height - global_distance_to_clamp))
|
||||
$Line2D.add_point(Vector2(screen_width - global_distance_to_clamp, screen_height - global_distance_to_clamp))
|
||||
$Line2D.add_point(Vector2(screen_width - global_distance_to_clamp, global_distance_to_clamp))
|
||||
$Line2D.add_point(Vector2(global_distance_to_clamp, global_distance_to_clamp))
|
||||
|
||||
|
||||
func _on_new_text_pressed():
|
||||
var pressed_button = $HBoxContainer2/foo.group.get_pressed_button()
|
||||
printt(pressed_button.name, pressed_button.text)
|
||||
emit_signal("text_selected", pressed_button.text)
|
||||
|
||||
|
||||
func tooltip_distance_to_edge_top(position_y):
|
||||
return position_y
|
||||
|
||||
func tooltip_distance_to_edge_bottom(position_y):
|
||||
return screen_height - position_y
|
||||
|
||||
func tooltip_distance_to_edge_left(position_x):
|
||||
return position_x
|
||||
|
||||
func tooltip_distance_to_edge_right(position_x):
|
||||
return screen_width - position_x
|
||||
|
||||
func _on_Control_mouse_moved(mouse_pos):
|
||||
# printt("mousepos", mouse_pos)
|
||||
# printt("label_container_pos", rect_position)
|
||||
|
||||
#var corrected_position = _offset(new_pos)
|
||||
var corrected_position = mouse_pos
|
||||
|
||||
# clamp TOP
|
||||
if tooltip_distance_to_edge_top(mouse_pos.y) <= global_distance_to_clamp:
|
||||
corrected_position.y = global_distance_to_clamp
|
||||
|
||||
# clamp BOTTOM
|
||||
if tooltip_distance_to_edge_bottom(mouse_pos.y + get_node(path_to_richtextlabel).rect_size.y) <= global_distance_to_clamp:
|
||||
corrected_position.y = screen_height - global_distance_to_clamp - get_node(path_to_richtextlabel).rect_size.y
|
||||
|
||||
# clamp LEFT
|
||||
if tooltip_distance_to_edge_left(mouse_pos.x - get_node(path_to_richtextlabel).rect_size.x/2) <= global_distance_to_clamp:
|
||||
corrected_position.x = global_distance_to_clamp
|
||||
|
||||
# clamp RIGHT
|
||||
if tooltip_distance_to_edge_right(mouse_pos.x + get_node(path_to_richtextlabel).rect_size.x/2) <= global_distance_to_clamp:
|
||||
corrected_position.x = screen_width - global_distance_to_clamp - get_node(path_to_richtextlabel).rect_size.x
|
||||
|
||||
get_node(path_to_richtextlabel).anchor_right = 0.2
|
||||
get_node(path_to_richtextlabel).rect_position = corrected_position
|
||||
|
||||
|
||||
func _on_Control_text_selected(text):
|
||||
get_node(path_to_richtextlabel).bbcode_text = "[color=red]" + text.replace("<br>", "\n") + "[/color]"
|
||||
update_size()
|
||||
|
||||
func _on_clamp_distance_text_changed(new_text):
|
||||
global_distance_to_clamp = int(new_text)
|
||||
update_line2d()
|
||||
|
||||
func _on_rtl_sizex_text_changed(text):
|
||||
pass
|
||||
get_node(path_to_richtextlabel).rect_size.x = float(text)
|
||||
update_size()
|
||||
|
||||
|
||||
func _offset(position):
|
||||
var center_offset_x = rect_size.x / 2
|
||||
var offset_y = 5
|
||||
|
||||
position.x -= center_offset_x
|
||||
position.y += offset_y
|
||||
return position
|
||||
|
||||
|
||||
func update_size():
|
||||
## RECT_SIZE ##
|
||||
var rtl_node = get_node(path_to_richtextlabel)
|
||||
var rtl_width = rtl_node.rect_size.x
|
||||
var rtl_height = rtl_node.rect_size.y
|
||||
var content_height = rtl_node.get_content_height()
|
||||
var nb_visible_characters = rtl_node.visible_characters
|
||||
var nb_visible_lines = rtl_node.get_visible_line_count()
|
||||
|
||||
printt("BEFORE", "text_height", content_height, "rtl_height", rtl_node.rect_size.y)
|
||||
|
||||
# if text is too long and is wrapped
|
||||
# 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
|
||||
|
||||
var text_height = rtl_node.get_content_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
|
||||
rtl_node.anchor_bottom = 0.0
|
||||
rtl_node.anchor_left = 0.0
|
||||
printt("AFTER", "text_height", get_node(path_to_richtextlabel).get_content_height(), "rtl_height", rtl_node.rect_size.y)
|
||||
90
addons/escoria-core/testing/rtl_screen_offset_testing.tscn
Normal file
90
addons/escoria-core/testing/rtl_screen_offset_testing.tscn
Normal file
@@ -0,0 +1,90 @@
|
||||
[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]
|
||||
|
||||
[sub_resource type="ButtonGroup" id=1]
|
||||
|
||||
[node name="rtl_screen_offset" type="Control"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
margin_right = -1280.0
|
||||
margin_bottom = -800.0
|
||||
script = ExtResource( 1 )
|
||||
__meta__ = {
|
||||
"_edit_lock_": true
|
||||
}
|
||||
path_to_richtextlabel = NodePath("tooltip")
|
||||
|
||||
[node name="Line2D" type="Line2D" parent="."]
|
||||
points = PoolVector2Array( 40, 40, 40, 976, 1808, 976, 1808, 40, 40, 40 )
|
||||
width = 2.51
|
||||
texture_mode = 116
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="."]
|
||||
margin_left = 315.72
|
||||
margin_top = 269.104
|
||||
margin_right = 475.72
|
||||
margin_bottom = 321.104
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
|
||||
margin_right = 160.0
|
||||
margin_bottom = 24.0
|
||||
|
||||
[node name="Label" type="Label" parent="VBoxContainer/HBoxContainer"]
|
||||
margin_top = 5.0
|
||||
margin_right = 98.0
|
||||
margin_bottom = 19.0
|
||||
text = "Clamp distance"
|
||||
|
||||
[node name="clamp_distance" type="LineEdit" parent="VBoxContainer/HBoxContainer"]
|
||||
margin_left = 102.0
|
||||
margin_right = 160.0
|
||||
margin_bottom = 24.0
|
||||
text = "40"
|
||||
max_length = 4
|
||||
|
||||
[node name="HBoxContainer2" type="VBoxContainer" parent="."]
|
||||
margin_left = 310.0
|
||||
margin_top = 340.0
|
||||
margin_right = 470.0
|
||||
margin_bottom = 380.0
|
||||
|
||||
[node name="foo" type="CheckBox" parent="HBoxContainer2"]
|
||||
margin_right = 624.0
|
||||
margin_bottom = 24.0
|
||||
pressed = true
|
||||
group = SubResource( 1 )
|
||||
text = "Foo"
|
||||
|
||||
[node name="foobar" type="CheckBox" parent="HBoxContainer2"]
|
||||
margin_top = 28.0
|
||||
margin_right = 624.0
|
||||
margin_bottom = 52.0
|
||||
group = SubResource( 1 )
|
||||
text = "Foo bar"
|
||||
|
||||
[node name="whatisit" type="CheckBox" parent="HBoxContainer2"]
|
||||
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..."
|
||||
|
||||
[node name="tooltip" parent="." instance=ExtResource( 2 )]
|
||||
margin_left = 238.815
|
||||
margin_top = 131.18
|
||||
margin_right = 638.815
|
||||
margin_bottom = 231.18
|
||||
rect_min_size = Vector2( 400, 0 )
|
||||
bbcode_text = "Tooltip content"
|
||||
fit_content_height = true
|
||||
[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"]
|
||||
[connection signal="pressed" from="HBoxContainer2/foo" to="." method="_on_new_text_pressed"]
|
||||
[connection signal="pressed" from="HBoxContainer2/foobar" to="." method="_on_new_text_pressed"]
|
||||
[connection signal="pressed" from="HBoxContainer2/whatisit" to="." method="_on_new_text_pressed"]
|
||||
BIN
addons/escoria-core/testing/white.png
Normal file
BIN
addons/escoria-core/testing/white.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 174 B |
34
addons/escoria-core/testing/white.png.import
Normal file
34
addons/escoria-core/testing/white.png.import
Normal file
@@ -0,0 +1,34 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="StreamTexture"
|
||||
path="res://.import/white.png-e746adb12fed1043fc3bcc319345fecb.stex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/escoria-core/testing/white.png"
|
||||
dest_files=[ "res://.import/white.png-e746adb12fed1043fc3bcc319345fecb.stex" ]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_mode=0
|
||||
compress/bptc_ldr=0
|
||||
compress/normal_map=0
|
||||
flags/repeat=0
|
||||
flags/filter=true
|
||||
flags/mipmaps=false
|
||||
flags/anisotropic=false
|
||||
flags/srgb=2
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/HDR_as_SRGB=false
|
||||
process/invert_color=false
|
||||
stream=false
|
||||
size_limit=0
|
||||
detect_3d=true
|
||||
svg/scale=1.0
|
||||
Reference in New Issue
Block a user