text_elem.gd 2.0 KB

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