line_elem.gd 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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=1
  7. var self_render=false
  8. var self_color=Color.black
  9. var self_rot=0
  10. func get_self_type():
  11. return self_type
  12. func _ready():
  13. self_id=global_v.gid
  14. global_v.gid+=1
  15. global_v.live_line_elem+=1
  16. self_size=get_node("LineEdit").text.to_int()
  17. self_rot=get_node("LineEdit2").text.to_int()
  18. self_color=get_node("ColorPickerButton").color
  19. _on_LineEdit_text_changed("")
  20. func hit():
  21. if(global_v.inp_used)&&(global_v.gidx!=self_id):
  22. return false
  23. if(global_v.inp_used)&&(global_v.gidx==self_id):
  24. return true
  25. var a=global_v.iMouse
  26. var rect=21*top_node.rect_scale.x
  27. var b=top_node.rect_position
  28. if(abs(a.x-b.x-rect/2)<rect/2)&&(abs(a.y-b.y-rect/2)<rect/2):
  29. return true
  30. func unhit():
  31. if(global_v.inp_used)&&(global_v.gidx==self_id)&&(!Input.is_mouse_button_pressed(BUTTON_LEFT)):
  32. global_v.inp_used=false
  33. func _process(delta):
  34. unhit()
  35. if(hit()):
  36. if(Input.is_mouse_button_pressed(BUTTON_LEFT)):
  37. global_v.gidx=self_id
  38. global_v.inp_used=true
  39. var a=global_v.iMouse
  40. var rect=21*top_node.rect_scale.x
  41. top_node.rect_position=a-Vector2(rect/2-11.25,rect/2)
  42. 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)
  43. top_node.rect_position.y=min(top_node.rect_position.y,720-11.25)
  44. Input.is_mouse_button_pressed(BUTTON_LEFT)
  45. func _on_Button_pressed():
  46. global_v.live_line_elem+=-1
  47. top_node.queue_free()
  48. func _on_LineEdit2_text_changed(new_text):
  49. var rot=get_node("LineEdit2").text.to_int()
  50. get_node("TextureRect/TextureRect2").rect_pivot_offset=Vector2(6,100)/2
  51. get_node("TextureRect/TextureRect2").rect_rotation=rot
  52. self_rot=rot
  53. func _on_LineEdit_text_changed(new_text):
  54. var a=get_node("LineEdit").text.to_int()*2
  55. a=a/100.0
  56. get_node("TextureRect/TextureRect2").rect_pivot_offset=Vector2(6,100)/2
  57. get_node("TextureRect/TextureRect2").rect_scale.y=a
  58. self_size=get_node("LineEdit").text.to_int()
  59. func _on_ColorPickerButton_color_changed(color):
  60. self_color=get_node("ColorPickerButton").color
  61. func _on_CheckBox_pressed():
  62. self_render=!self_render