Input icon mouse support

This commit is contained in:
ToasterPanic 2025-12-02 23:56:00 -05:00
parent c2a76c206e
commit a0d7f109c5
17 changed files with 89 additions and 80 deletions

View file

@ -1,44 +0,0 @@
## Like a [TextureRect], but automatically updates as an input icon based on the provided [param action_name].
extends TextureRect
class_name InputIconTextureRect
@export var action_name = &"":
set(value):
action_name = value
_update_icon()
var known_using_gamepad = null
var known_gamepad_name = null
var time_until_next_check = 0
## Updates the current icon.
func _update_icon():
var events = InputMap.action_get_events(action_name)
for n in events:
if ("keycode" in n) and !input_icon.using_gamepad:
var keycode = n.keycode if n.keycode else n.physical_keycode
texture = load("res://addons/super_awesome_input_icons/textures/keyboard/" + OS.get_keycode_string(keycode).to_lower() + ".png")
break
elif ("button_index" in n) and input_icon.using_gamepad:
if input_icon.gamepad_type:
texture = load("res://addons/super_awesome_input_icons/textures/" + input_icon.gamepad_type + "/" + input_icon.button_dictionary[n.button_index] + ".png")
break
func _process(delta: float) -> void:
time_until_next_check -= delta
if time_until_next_check < 0:
time_until_next_check = 0.2
if known_gamepad_name != input_icon.gamepad_name:
_update_icon()
known_gamepad_name = input_icon.gamepad_name
elif known_using_gamepad != input_icon.using_gamepad:
_update_icon()
known_using_gamepad = input_icon.using_gamepad

View file

@ -0,0 +1,63 @@
## Like a [TextureRect], but automatically updates as an input icon based on the provided [param action_name].
extends TextureRect
class_name InputIconTextureRect
## The action used for the input icon.
@export var action_name: String = &"":
set(value):
action_name = value
_update_icon()
var _known_using_gamepad = null
var _known_gamepad_name = null
var _time_until_next_check = 0
## Updates the current icon.
func _update_icon():
# Loop through all events in an action:
var events = InputMap.action_get_events(action_name)
for n in events:
print(n)
# If it's a keyboard input and we're not using a gamepad, use a keyboard input icon
if n.is_class("InputEventKey") and !input_icon.using_gamepad:
var keycode = n.keycode if n.keycode else n.physical_keycode
texture = load("res://addons/super_awesome_input_icons/textures/keyboard/" + OS.get_keycode_string(keycode).to_lower() + ".png")
break
# If it's a mouse input and we're using a gamepad, use the corresponding gamepad input icon
elif n.is_class("InputEventMouseButton") and !input_icon.using_gamepad:
texture = load("res://addons/super_awesome_input_icons/textures/mouse/" + input_icon.mouse_button_dictionary[n.button_index] + ".png")
break
# If it's a gamepad input and we're using a gamepad, use the corresponding gamepad input icon
elif n.is_class("InputEventMouseButton") and input_icon.using_gamepad:
if input_icon.gamepad_type:
texture = load("res://addons/super_awesome_input_icons/textures/" + input_icon.gamepad_type + "/" + input_icon.button_dictionary[n.button_index] + ".png")
break
func _process(delta: float) -> void:
_time_until_next_check -= delta
if _time_until_next_check < 0:
_time_until_next_check = 0.2
if _known_gamepad_name != input_icon.gamepad_name:
_update_icon()
_known_gamepad_name = input_icon.gamepad_name
elif _known_using_gamepad != input_icon.using_gamepad:
_update_icon()
_known_using_gamepad = input_icon.using_gamepad

View file

@ -24,6 +24,14 @@ static var button_dictionary = {
JOY_BUTTON_PADDLE1: "left_shoulder",
}
static var mouse_button_dictionary = {
MOUSE_BUTTON_LEFT: "left",
MOUSE_BUTTON_MIDDLE: "left",
MOUSE_BUTTON_RIGHT: "left",
MOUSE_BUTTON_WHEEL_DOWN: "scroll_down",
MOUSE_BUTTON_WHEEL_UP: "scroll_up",
}
## A dictionary where each JoyAxis key corresponds to a string pair. Used for textures.
static var axis_dictionary = {
JOY_AXIS_TRIGGER_LEFT: "left_trigger",

View file

@ -1,17 +0,0 @@
## This is a Sprite3D that takes an action name and automatically loads the proper icon
class_name InputIconSprite3D extends Sprite3D
## The name of the action in your InputMap, it has to be an existing action
@export var action_name: StringName = &"":
set(value):
action_name = value
_update()
## The Index of the event, if you have more than one event in the same action.
## You can use negative numbers but not a number bigger than the number of events
@export var event_index: int = 0:
set(value):
event_index = value
_update()
func _update():
texture = InputIcon.get_icon(action_name, event_index)

View file

@ -1 +0,0 @@
uid://bb0jpw478pdd0

View file

Before

Width:  |  Height:  |  Size: 751 B

After

Width:  |  Height:  |  Size: 751 B

View file

@ -3,15 +3,15 @@
importer="texture"
type="CompressedTexture2D"
uid="uid://cy711ee2m3eq0"
path="res://.godot/imported/mouse_left.png-e3230d4e53ec25138f4d43c7842dc825.ctex"
path="res://.godot/imported/left.png-d85e45f831a06d2ba5c83824c36b51bf.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://addons/super_awesome_input_icons/textures/mouse/mouse_left.png"
dest_files=["res://.godot/imported/mouse_left.png-e3230d4e53ec25138f4d43c7842dc825.ctex"]
source_file="res://addons/super_awesome_input_icons/textures/mouse/left.png"
dest_files=["res://.godot/imported/left.png-d85e45f831a06d2ba5c83824c36b51bf.ctex"]
[params]

View file

Before

Width:  |  Height:  |  Size: 749 B

After

Width:  |  Height:  |  Size: 749 B

View file

@ -3,15 +3,15 @@
importer="texture"
type="CompressedTexture2D"
uid="uid://be0ek7arnv0ri"
path="res://.godot/imported/mouse_scroll.png-a425582d277f4ff22967a9c86711da56.ctex"
path="res://.godot/imported/middle.png-0d1dccd65dfca3ee7bb71c11b38bc297.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://addons/super_awesome_input_icons/textures/mouse/mouse_scroll.png"
dest_files=["res://.godot/imported/mouse_scroll.png-a425582d277f4ff22967a9c86711da56.ctex"]
source_file="res://addons/super_awesome_input_icons/textures/mouse/middle.png"
dest_files=["res://.godot/imported/middle.png-0d1dccd65dfca3ee7bb71c11b38bc297.ctex"]
[params]

View file

Before

Width:  |  Height:  |  Size: 753 B

After

Width:  |  Height:  |  Size: 753 B

View file

@ -3,15 +3,15 @@
importer="texture"
type="CompressedTexture2D"
uid="uid://c0ds7retiljhr"
path="res://.godot/imported/mouse_right.png-43ec3200245560770baa71c0e562af8c.ctex"
path="res://.godot/imported/right.png-9a5e70b6547aea9d5aa704648da23df5.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://addons/super_awesome_input_icons/textures/mouse/mouse_right.png"
dest_files=["res://.godot/imported/mouse_right.png-43ec3200245560770baa71c0e562af8c.ctex"]
source_file="res://addons/super_awesome_input_icons/textures/mouse/right.png"
dest_files=["res://.godot/imported/right.png-9a5e70b6547aea9d5aa704648da23df5.ctex"]
[params]

View file

Before

Width:  |  Height:  |  Size: 838 B

After

Width:  |  Height:  |  Size: 838 B

View file

@ -3,15 +3,15 @@
importer="texture"
type="CompressedTexture2D"
uid="uid://c0hxhuywr30wn"
path="res://.godot/imported/mouse_scroll_down.png-839a2e0c0dcf822e8f49943054050b87.ctex"
path="res://.godot/imported/scroll_down.png-56f571acb78a8d4c70c4a7fa97c3e2a8.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://addons/super_awesome_input_icons/textures/mouse/mouse_scroll_down.png"
dest_files=["res://.godot/imported/mouse_scroll_down.png-839a2e0c0dcf822e8f49943054050b87.ctex"]
source_file="res://addons/super_awesome_input_icons/textures/mouse/scroll_down.png"
dest_files=["res://.godot/imported/scroll_down.png-56f571acb78a8d4c70c4a7fa97c3e2a8.ctex"]
[params]

View file

Before

Width:  |  Height:  |  Size: 839 B

After

Width:  |  Height:  |  Size: 839 B

View file

@ -3,15 +3,15 @@
importer="texture"
type="CompressedTexture2D"
uid="uid://gkojfej7jdhl"
path="res://.godot/imported/mouse_scroll_up.png-d3eb669687c8d8b150a86c0dd0d2d82c.ctex"
path="res://.godot/imported/scroll_up.png-7e850decbbb4ef2ea13641229b3fbfbf.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://addons/super_awesome_input_icons/textures/mouse/mouse_scroll_up.png"
dest_files=["res://.godot/imported/mouse_scroll_up.png-d3eb669687c8d8b150a86c0dd0d2d82c.ctex"]
source_file="res://addons/super_awesome_input_icons/textures/mouse/scroll_up.png"
dest_files=["res://.godot/imported/scroll_up.png-7e850decbbb4ef2ea13641229b3fbfbf.ctex"]
[params]

View file

@ -17,7 +17,7 @@
[ext_resource type="Script" uid="uid://khas1kkt2t3k" path="res://scripts/exit_ship.gd" id="14_257nh"]
[ext_resource type="Texture2D" uid="uid://b047lku56vtve" path="res://textures/galacta_counter.png" id="15_vuhkc"]
[ext_resource type="Texture2D" uid="uid://dauoebs801ngm" path="res://addons/super_awesome_input_icons/textures/keyboard/question.png" id="16_e3s4u"]
[ext_resource type="Script" uid="uid://b2maxk5g6yb0i" path="res://addons/super_awesome_input_icons/classes/InputIconTextureRect.gd" id="16_hby33"]
[ext_resource type="Script" uid="uid://b2maxk5g6yb0i" path="res://addons/super_awesome_input_icons/classes/input_icon_texture_rect.gd" id="16_hby33"]
[sub_resource type="CanvasItemMaterial" id="CanvasItemMaterial_gysiw"]
light_mode = 1
@ -322,14 +322,14 @@ layout_mode = 2
text = "PRESS"
label_settings = SubResource("LabelSettings_c2suo")
[node name="InputIcon2" type="TextureRect" parent="UI/Control/Interact"]
[node name="InputIcon" type="TextureRect" parent="UI/Control/Interact"]
material = SubResource("ShaderMaterial_jo68p")
custom_minimum_size = Vector2(64, 64)
layout_mode = 2
texture = ExtResource("16_e3s4u")
expand_mode = 2
script = ExtResource("16_hby33")
action_name = &"interact"
action_name = "interact"
[node name="End" type="Label" parent="UI/Control/Interact"]
layout_mode = 2