mouse_button_prompt.gd 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # Copyright (C) 2022-2023 John Pennycook
  2. # SPDX-License-Identifier: MIT
  3. @tool
  4. @icon("res://addons/input_prompts/mouse_button_prompt/icon.svg")
  5. class_name MouseButtonPrompt
  6. extends "res://addons/input_prompts/input_prompt.gd"
  7. ## Displays a prompt based on a mouse button index.
  8. ##
  9. ## Displays a prompt based on a mouse button index.
  10. ## The texture used for the prompt is determined automatically.
  11. ## [br][br]
  12. ## [b]Note[/b]: A [MouseButtonPrompt] will never show joypad or keyboard
  13. ## prompts. To automatically reflect the most recent input device, use
  14. ## [ActionPrompt] instead.
  15. ## A mouse button index, such as [constant @GlobalScope.MOUSE_BUTTON_LEFT].
  16. var button := 1:
  17. set = _set_button
  18. func _ready():
  19. _update_icon()
  20. func _set_button(index: int):
  21. button = index
  22. var event := InputEventMouseButton.new()
  23. event.button_index = button
  24. events = [event]
  25. _update_icon()
  26. func _update_icon():
  27. var textures := PromptManager.get_mouse_textures()
  28. texture = textures.get_texture(events[0])
  29. queue_redraw()
  30. func _get_property_list():
  31. var properties = []
  32. properties.append(
  33. {
  34. name = "MouseButtonPrompt",
  35. type = TYPE_NIL,
  36. usage = PROPERTY_USAGE_CATEGORY | PROPERTY_USAGE_SCRIPT_VARIABLE
  37. }
  38. )
  39. properties.append(
  40. {
  41. name = "button",
  42. type = TYPE_INT,
  43. hint = PROPERTY_HINT_ENUM,
  44. hint_string =
  45. "Left:1,Right:2,Middle:3,Wheel Up:4,Wheel Down:5,Wheel Left:6,Wheel Right:7"
  46. }
  47. )
  48. return properties