Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 KB | None | 0 0
  1. tool
  2. extends Node2D
  3.  
  4.  
  5. const border_icon_texture : Texture = preload("res://elements/icons/icon_animated_border_white.svg")
  6. const border_icon_normale : Texture = preload("res://elements/icons/animated_border_nmap.png")
  7.  
  8. var border_icon : Sprite = Sprite.new()
  9. var icon : Sprite = Sprite.new()
  10.  
  11. export(Texture) var button_icon : Texture setget set_button_icon, get_button_icon
  12. export(Texture) var button_normal : Texture
  13.  
  14. var first_rand = RandomNumberGenerator.new()
  15. var mouse_on : bool = false
  16.  
  17. onready var animationPlayer : AnimationPlayer = $Anchor/AnimationPlayer
  18.  
  19.  
  20. func _enter_tree() -> void:
  21.  
  22. if not $Anchor/AnimationPlayer.is_connected("animation_finished", self, "_on_animation_finished"):
  23. $Anchor/AnimationPlayer.connect("animation_finished", self, "_on_animation_finished")
  24. if not $Timer.is_connected("timeout", self, "_on_timer_timeout"):
  25. $Timer.connect("timeout", self, "_on_timer_timeout")
  26. if not $Area2D.is_connected("input_event", self, "_on_area_input_event"):
  27. $Area2D.connect("input_event", self, "_on_area_input_event")
  28. if not $Area2D.is_connected("mouse_entered", self, "_on_mouse_entered"):
  29. $Area2D.connect("mouse_entered", self, "_on_mouse_entered")
  30. if not $Area2D.is_connected("mouse_exited", self, "_on_mouse_exited"):
  31. $Area2D.connect("mouse_exited", self, "_on_mouse_exited")
  32.  
  33. if not button_icon:
  34. button_icon = load("res://elements/icons/missing_texture.svg")
  35. button_normal = load("res://elements/icons/missing_texture_nmap.png")
  36.  
  37. if button_icon:
  38.  
  39. if border_icon_texture.get_size() > $Anchor/Sprite.get_texture().get_size() * 0.75:
  40. border_icon.set_scale(Vector2(0.75,0.75))
  41.  
  42. if button_icon.get_size() > $Anchor/Sprite.get_texture().get_size() * 0.75:
  43. icon.set_scale(Vector2(0.75,0.75))
  44.  
  45. border_icon.set_texture(border_icon_texture)
  46. border_icon.set_normal_map(border_icon_normale)
  47. border_icon.set_name("border_icon")
  48.  
  49. icon.set_texture(button_icon)
  50. if button_normal:
  51. icon.set_normal_map(button_normal)
  52. icon.set_name("icon")
  53.  
  54. if not $Anchor.has_node("border_icon"):
  55. $Anchor.add_child(border_icon)
  56. if not $Anchor.has_node("icon"):
  57. $Anchor.add_child(icon)
  58.  
  59.  
  60. func _ready() -> void:
  61. _on_animation_finished("BoutonRondl_Idle")
  62.  
  63.  
  64. func _process(delta: float) -> void:
  65. border_icon.rotate(deg2rad(3.0))
  66.  
  67.  
  68. func _on_animation_finished(anim_name : String) -> void:
  69.  
  70. match anim_name:
  71.  
  72. "BoutonRond_MouseOut":
  73. animationPlayer.play("BoutonRondl_Idle")
  74.  
  75. "BoutonRondl_Idle":
  76. if not mouse_on:
  77. $Timer.start(randf() * 2.0)
  78.  
  79. _:
  80. pass
  81.  
  82.  
  83. func _on_timer_timeout() -> void:
  84. animationPlayer.play("BoutonRondl_Idle")
  85.  
  86.  
  87. func _on_area_input_event(viewport : Node, event : InputEvent, shape_id : int) -> void:
  88. if event is InputEventMouseButton:
  89. if event.is_pressed():
  90. print("Clique sur "+get_name())
  91.  
  92.  
  93. func _on_mouse_entered() -> void:
  94. mouse_on = true
  95. animationPlayer.play("BoutonRond_MouseOn")
  96.  
  97.  
  98. func _on_mouse_exited() -> void:
  99. mouse_on = false
  100. animationPlayer.play("BoutonRond_MouseOut")
  101.  
  102.  
  103. func set_button_icon(icon : Texture) -> void:
  104. print("set")
  105.  
  106.  
  107. func get_button_icon() -> Texture:
  108. print("get")
  109. return button_icon
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement