circle_elem.gd 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. extends HBoxContainer
  2. onready var top_node=get_node("../")
  3. onready var global_v=get_tree().get_root().get_node("scene")
  4. var self_id=0
  5. var self_size=0
  6. const self_type=2
  7. var self_render=false
  8. var self_color=Color.black
  9. func get_self_type():
  10. return self_type
  11. func _ready():
  12. self_id=global_v.gid
  13. global_v.gid+=1
  14. global_v.live_circle_elem+=1
  15. self_color=get_node("ColorPickerButton").color
  16. self_size=get_node("LineEdit").text.to_int()
  17. func hit():
  18. if(global_v.inp_used)&&(global_v.gidx!=self_id):
  19. return false
  20. if(global_v.inp_used)&&(global_v.gidx==self_id):
  21. return true
  22. var a=global_v.iMouse
  23. var rect=21*top_node.rect_scale.x
  24. var b=top_node.rect_position
  25. if(abs(a.x-b.x-rect/2)<rect/2)&&(abs(a.y-b.y-rect/2)<rect/2):
  26. return true
  27. func unhit():
  28. if(global_v.inp_used)&&(global_v.gidx==self_id)&&(!Input.is_mouse_button_pressed(BUTTON_LEFT)):
  29. global_v.inp_used=false
  30. func _process(delta):
  31. unhit()
  32. if(hit()):
  33. if(Input.is_mouse_button_pressed(BUTTON_LEFT)):
  34. global_v.gidx=self_id
  35. global_v.inp_used=true
  36. var a=global_v.iMouse
  37. var rect=21*top_node.rect_scale.x
  38. top_node.rect_position=a-Vector2(rect/2-11.25,rect/2)
  39. top_node.rect_position=Vector2(int(top_node.rect_position.x/22.5)*22.5,11.25+int(top_node.rect_position.y/22.5)*22.5)
  40. top_node.rect_position.y=min(top_node.rect_position.y,720-11.25)
  41. Input.is_mouse_button_pressed(BUTTON_LEFT)
  42. func _on_Button_pressed():
  43. global_v.live_circle_elem+=-1
  44. top_node.queue_free()
  45. func _on_LineEdit_text_changed(new_text):
  46. self_size=get_node("LineEdit").text.to_int()
  47. #var a=get_node("LineEdit").text.to_int()
  48. #a=a/512.0
  49. #get_node("TextureRect/TextureRect2").rect_pivot_offset=Vector2(512,512)/2
  50. #get_node("TextureRect/TextureRect2").rect_scale=Vector2(a,a)
  51. func _on_ColorPickerButton_color_changed(color):
  52. self_color=get_node("ColorPickerButton").color
  53. func _on_CheckBox_pressed():
  54. self_render=!self_render