Skip to content

Commit d63c8bf

Browse files
committed
Initial public release
Adds the following new nodes via a plugin: - ActionPrompt - JoypadButtonPrompt - JoypadMotionPrompt - KeyPrompt - MouseButtonPrompt
0 parents  commit d63c8bf

39 files changed

+1166
-0
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 John Pennycook
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Godot Input Prompts
2+
3+
This Godot plugin adds new nodes providing easy-to-use input prompts.
4+
5+
A demo of the prompts in action is available on [itch.io][1]; if you find this
6+
plugin useful, please consider supporting my work there.
7+
8+
[1]:https://pennycook.itch.io/godot-input-prompts
9+
10+
The current version supports the following icons:
11+
- Keyboard and mouse
12+
- Xbox
13+
- PlayStation
14+
- Nintendo Switch
15+
16+
Please note that the PlayStation icons must be completed manually in an editor.
17+
18+
## ActionPrompt
19+
20+
![ActionPrompt](./addons/input_prompts/ActionPrompt/screenshot.png)
21+
22+
ActionPrompt nodes display prompts based on the InputMap and an icon
23+
preference. When set to "Automatic", the prompts update to match the input
24+
device.
25+
26+
## JoypadButtonPrompt
27+
28+
![JoypadButtonPrompt](./addons/input_prompts/JoypadButtonPrompt/screenshot.png)
29+
30+
JoypadButtonPrompt nodes display prompts corresponding to a button index.
31+
32+
## JoypadMotionPrompt
33+
34+
![JoypadMotionPrompt](./addons/input_prompts/JoypadMotionPrompt/screenshot.png)
35+
36+
JoypadMotionPrompt nodes display prompts corresponding to an axis and an axis
37+
value.
38+
39+
## KeyPrompt
40+
41+
![KeyPrompt](./addons/input_prompts/KeyPrompt/screenshot.png)
42+
43+
KeyPrompt nodes display prompts corresponding to a key scancode.
44+
45+
## MousePrompt
46+
47+
![MouseButtonPrompt](./addons/input_prompts/MouseButtonPrompt/screenshot.png)
48+
49+
MouseButtonPrompt nodes display prompts corresponding to a button index.
50+
51+
# License
52+
53+
Code is licensed under the MIT license.
54+
Icons are in the [public domain][2], originally released by [Kenney][3].
55+
56+
[2]:https://creativecommons.org/publicdomain/zero/1.0/
57+
[3]:https://kenney.nl/
58+
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# Copyright (C) 2022 John Pennycook
2+
# SPDX-License-Identifier: MIT
3+
tool
4+
extends "res://addons/input_prompts/BasePrompt.gd"
5+
6+
var action = "ui_accept" setget _set_action
7+
var icon = InputPrompts.Icons.AUTOMATIC setget _set_icon
8+
var _events : Array = []
9+
10+
func _ready():
11+
self.action = action
12+
self.icon = icon
13+
_update_icon()
14+
15+
func _set_action(new_action : String):
16+
action = new_action
17+
# In the Editor, InputMap reflects Editor settings
18+
# Read the list of actions from ProjectSettings instead
19+
if Engine.editor_hint:
20+
_events = ProjectSettings.get_setting("input/" + action)["events"]
21+
else:
22+
_events = InputMap.get_action_list(action)
23+
_update_icon()
24+
25+
func _set_icon(new_icon):
26+
icon = new_icon
27+
_update_icon()
28+
29+
func _find_event(list : Array, types : Array):
30+
for candidate in list:
31+
for type in types:
32+
if candidate is type:
33+
return candidate
34+
return null
35+
36+
func _update_icon():
37+
# If icon is set to AUTOMATIC, first determine which icon to display
38+
var display_icon : int = icon
39+
if icon == InputPrompts.Icons.AUTOMATIC:
40+
display_icon = InputPrompts.get_icons()
41+
42+
# Choose the atlas and region associated with the InputEvent
43+
# If the InputMap contains multiple events, choose the first
44+
if display_icon == InputPrompts.Icons.KEYBOARD:
45+
var types = [InputEventKey, InputEventMouseButton]
46+
var ev = _find_event(_events, types)
47+
if not (ev is InputEventKey or ev is InputEventMouseButton):
48+
push_error("No Key/Mouse input for " + action + " in InputMap")
49+
if ev is InputEventKey:
50+
var scancode = ev.get_scancode()
51+
texture.atlas = InputPrompts.get_key_atlas()
52+
texture.region = InputPrompts.get_key_region(scancode)
53+
elif ev is InputEventMouseButton:
54+
var button = ev.get_button_index()
55+
texture.atlas = InputPrompts.get_mouse_atlas()
56+
texture.region = InputPrompts.get_mouse_region(button)
57+
else:
58+
var types = [InputEventJoypadButton, InputEventJoypadMotion]
59+
var ev = _find_event(_events, types)
60+
if not (ev is InputEventJoypadButton or ev is InputEventJoypadMotion):
61+
push_error("No Joypad input for " + action + " in InputMap")
62+
if ev is InputEventJoypadButton:
63+
var button = ev.get_button_index()
64+
texture.atlas = InputPrompts.get_joypad_button_atlas(display_icon)
65+
texture.region = InputPrompts.get_joypad_button_region(button)
66+
elif ev is InputEventJoypadMotion:
67+
var axis = ev.get_axis()
68+
var value = ev.get_axis_value()
69+
texture.atlas = InputPrompts.get_joypad_motion_atlas()
70+
texture.region = InputPrompts.get_joypad_motion_region(axis, value)
71+
update()
72+
73+
func _input(event : InputEvent):
74+
if not event.is_action_pressed(action):
75+
return
76+
emit_signal("pressed")
77+
78+
func _get_property_list():
79+
var properties = []
80+
properties.append({
81+
name = "ActionPrompt",
82+
type = TYPE_NIL,
83+
usage = PROPERTY_USAGE_CATEGORY | PROPERTY_USAGE_SCRIPT_VARIABLE
84+
})
85+
# In the Editor, InputMap reflects Editor settings
86+
# Read the list of actions from ProjectSettings instead
87+
var actions : String = ""
88+
for property in ProjectSettings.get_property_list():
89+
var name = property["name"]
90+
if name.begins_with("input/"):
91+
if actions != "":
92+
actions += ","
93+
actions += name.trim_prefix("input/")
94+
properties.append({
95+
name = "action",
96+
type = TYPE_STRING,
97+
hint = PROPERTY_HINT_ENUM,
98+
hint_string = actions
99+
})
100+
properties.append({
101+
name = "icon",
102+
type = TYPE_INT,
103+
hint = PROPERTY_HINT_ENUM,
104+
hint_string = "Automatic,Xbox,Sony,Nintendo,Keyboard"
105+
})
106+
return properties
301 Bytes
Loading
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
[remap]
2+
3+
importer="texture"
4+
type="StreamTexture"
5+
path="res://.import/icon.png-81530b8bad18876c36fd6be5243690a5.stex"
6+
metadata={
7+
"vram_texture": false
8+
}
9+
10+
[deps]
11+
12+
source_file="res://addons/input_prompts/ActionPrompt/icon.png"
13+
dest_files=[ "res://.import/icon.png-81530b8bad18876c36fd6be5243690a5.stex" ]
14+
15+
[params]
16+
17+
compress/mode=0
18+
compress/lossy_quality=0.7
19+
compress/hdr_mode=0
20+
compress/bptc_ldr=0
21+
compress/normal_map=0
22+
flags/repeat=0
23+
flags/filter=true
24+
flags/mipmaps=false
25+
flags/anisotropic=false
26+
flags/srgb=2
27+
process/fix_alpha_border=true
28+
process/premult_alpha=false
29+
process/HDR_as_SRGB=false
30+
process/invert_color=false
31+
process/normal_map_invert_y=false
32+
stream=false
33+
size_limit=0
34+
detect_3d=true
35+
svg/scale=1.0
5.38 KB
Loading

addons/input_prompts/BasePrompt.gd

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright (C) 2022 John Pennycook
2+
# SPDX-License-Identifier: MIT
3+
tool
4+
extends TextureRect
5+
6+
signal pressed()
7+
8+
func _is_input_prompt():
9+
return true
10+
11+
func _ready():
12+
self.texture = AtlasTexture.new()
13+
14+
func _update_icon():
15+
pass
16+
17+
func _enter_tree():
18+
InputPrompts.connect("icons_changed", self, "_update_icon")
19+
20+
func _exit_tree():
21+
InputPrompts.disconnect("icons_changed", self, "_update_icon")

0 commit comments

Comments
 (0)