2020-08-04 15:22:30 +02:00
|
|
|
tool
|
2020-05-14 02:36:45 +02:00
|
|
|
extends Control
|
|
|
|
class_name Point
|
|
|
|
|
|
|
|
const OFFSET : Vector2 = Vector2(13,13)
|
|
|
|
var point_value : Array setget set_value,get_value
|
|
|
|
var point_position : Vector2
|
2020-05-14 13:55:30 +02:00
|
|
|
var color : Color setget set_color_point, get_color_point
|
2020-05-14 02:36:45 +02:00
|
|
|
var color_outline : Color
|
2020-05-14 13:55:30 +02:00
|
|
|
var function : String setget set_function, get_function
|
2020-05-14 02:36:45 +02:00
|
|
|
|
|
|
|
var mouse_entered : bool = false
|
|
|
|
|
2020-05-20 17:28:10 +02:00
|
|
|
enum SHAPES {
|
2020-12-21 18:13:04 +01:00
|
|
|
Dot, Triangle, Square, Cross
|
2020-05-20 17:28:10 +02:00
|
|
|
}
|
2020-05-14 02:36:45 +02:00
|
|
|
|
2020-05-20 17:28:10 +02:00
|
|
|
var shape : int = 0 setget set_shape, get_shape
|
|
|
|
|
|
|
|
signal _mouse_entered(point)
|
2020-05-14 02:36:45 +02:00
|
|
|
signal _mouse_exited()
|
|
|
|
signal _point_pressed(point)
|
|
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
|
|
func _ready():
|
2020-11-06 19:32:11 +01:00
|
|
|
pass # Replace with function body.
|
2020-05-14 02:36:45 +02:00
|
|
|
|
|
|
|
func _draw():
|
2020-11-06 19:32:11 +01:00
|
|
|
if mouse_entered:
|
|
|
|
draw_point(7,color_outline)
|
|
|
|
draw_point(5,color)
|
2020-05-20 17:28:10 +02:00
|
|
|
|
|
|
|
func draw_point(size : float, color : Color):
|
2020-12-21 18:13:04 +01:00
|
|
|
var factor : float
|
2020-11-06 19:32:11 +01:00
|
|
|
match shape:
|
2020-12-21 18:13:04 +01:00
|
|
|
SHAPES.Dot:
|
2020-11-06 19:32:11 +01:00
|
|
|
draw_circle(OFFSET, size, color)
|
2020-12-21 18:13:04 +01:00
|
|
|
SHAPES.Triangle:
|
2020-11-06 19:32:11 +01:00
|
|
|
size+=6
|
2020-12-21 18:13:04 +01:00
|
|
|
factor = 2
|
2020-11-06 19:32:11 +01:00
|
|
|
draw_colored_polygon([
|
2020-12-21 18:13:04 +01:00
|
|
|
OFFSET-Vector2(0,size/factor), OFFSET+Vector2(1,1)*size/factor, OFFSET-Vector2(1,-1)*size/factor
|
2020-11-06 19:32:11 +01:00
|
|
|
], color,[],null,null,false)
|
2020-12-21 18:13:04 +01:00
|
|
|
SHAPES.Square:
|
2020-11-06 19:32:11 +01:00
|
|
|
size+=4
|
2020-12-21 18:13:04 +01:00
|
|
|
factor = 2
|
2020-11-06 19:32:11 +01:00
|
|
|
draw_colored_polygon([
|
2020-12-21 18:13:04 +01:00
|
|
|
OFFSET-Vector2(1,1)*size/factor, OFFSET-Vector2(-1,1)*size/factor, OFFSET+Vector2(1,1)*size/factor, OFFSET-Vector2(1,-1)*size/factor
|
2020-11-06 19:32:11 +01:00
|
|
|
], color,[],null,null,false)
|
2020-12-21 18:13:04 +01:00
|
|
|
SHAPES.Cross:
|
2020-11-06 19:32:11 +01:00
|
|
|
size+=2
|
|
|
|
draw_line(OFFSET-Vector2(size,0), OFFSET+Vector2(size,0), color, size-5, true)
|
|
|
|
draw_line(OFFSET-Vector2(0,size), OFFSET+Vector2(0,size), color, size-5, true)
|
2020-05-20 17:28:10 +02:00
|
|
|
|
|
|
|
func create_point(shape : int, color : Color, color_outline : Color, position : Vector2, value : Array, function : String):
|
2020-11-06 19:32:11 +01:00
|
|
|
self.shape = shape
|
|
|
|
self.color = color
|
|
|
|
self.color_outline = color_outline
|
|
|
|
self.point_position = position
|
|
|
|
self.rect_position = point_position - OFFSET
|
|
|
|
self.point_value = value
|
|
|
|
self.function = function
|
2020-05-14 02:36:45 +02:00
|
|
|
|
2020-05-20 17:28:10 +02:00
|
|
|
|
2020-05-14 02:36:45 +02:00
|
|
|
func _on_Point_mouse_entered():
|
2020-11-06 19:32:11 +01:00
|
|
|
mouse_entered = true
|
|
|
|
emit_signal("_mouse_entered",self)
|
|
|
|
update()
|
2020-05-14 02:36:45 +02:00
|
|
|
|
|
|
|
func _on_Point_mouse_exited():
|
2020-11-06 19:32:11 +01:00
|
|
|
mouse_entered = false
|
|
|
|
emit_signal("_mouse_exited")
|
|
|
|
update()
|
2020-05-14 02:36:45 +02:00
|
|
|
|
2020-05-30 01:42:58 +02:00
|
|
|
func _on_Point_gui_input(event):
|
2020-11-06 19:32:11 +01:00
|
|
|
if event is InputEventMouseButton:
|
|
|
|
if event.is_pressed():
|
|
|
|
if event.button_index == 1:
|
|
|
|
emit_signal("_point_pressed",self)
|
2020-05-30 01:42:58 +02:00
|
|
|
|
2020-05-14 02:36:45 +02:00
|
|
|
func format_value(v : Array, format_x : bool, format_y : bool):
|
2020-11-06 19:32:11 +01:00
|
|
|
var x : String = str(v[0])
|
|
|
|
var y : String = str(v[1])
|
|
|
|
|
|
|
|
if format_x:
|
|
|
|
x = format(v[1])
|
|
|
|
if format_y:
|
|
|
|
y = format(v[1])
|
|
|
|
|
|
|
|
return [x,y]
|
2020-05-14 02:36:45 +02:00
|
|
|
|
|
|
|
func format(n):
|
2020-11-06 19:32:11 +01:00
|
|
|
n = str(n)
|
|
|
|
var size = n.length()
|
|
|
|
var s
|
|
|
|
for i in range(size):
|
|
|
|
if((size - i) % 3 == 0 and i > 0):
|
|
|
|
s = str(s,",", n[i])
|
|
|
|
else:
|
|
|
|
s = str(s,n[i])
|
|
|
|
|
|
|
|
return s.replace("Null","")
|
2020-05-14 02:36:45 +02:00
|
|
|
|
|
|
|
func set_value( v : Array = [] ) :
|
2020-11-06 19:32:11 +01:00
|
|
|
point_value = v
|
2020-05-14 02:36:45 +02:00
|
|
|
|
2020-05-14 13:55:30 +02:00
|
|
|
func set_color_point( c : Color ):
|
2020-11-06 19:32:11 +01:00
|
|
|
color = c
|
2020-05-14 13:55:30 +02:00
|
|
|
|
|
|
|
func set_function( f : String ):
|
2020-11-06 19:32:11 +01:00
|
|
|
function = f
|
2020-05-14 13:55:30 +02:00
|
|
|
|
2020-05-20 17:28:10 +02:00
|
|
|
func set_shape(s : int):
|
2020-11-06 19:32:11 +01:00
|
|
|
shape = s
|
2020-05-20 17:28:10 +02:00
|
|
|
|
2020-05-30 01:42:58 +02:00
|
|
|
# Public Getters
|
|
|
|
func get_value() -> Array:
|
2020-11-06 19:32:11 +01:00
|
|
|
return point_value
|
2020-05-30 01:42:58 +02:00
|
|
|
|
|
|
|
func get_color_point() -> Color:
|
2020-11-06 19:32:11 +01:00
|
|
|
return color
|
2020-05-30 01:42:58 +02:00
|
|
|
|
|
|
|
func get_function() -> String:
|
2020-11-06 19:32:11 +01:00
|
|
|
return function
|
2020-05-30 01:42:58 +02:00
|
|
|
|
2020-05-20 17:28:10 +02:00
|
|
|
func get_shape() -> int:
|
2020-11-06 19:32:11 +01:00
|
|
|
return shape
|