box_elem.gd 2.0 KB

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