-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds the following new nodes via a plugin: - ActionPrompt - JoypadButtonPrompt - JoypadMotionPrompt - KeyPrompt - MouseButtonPrompt
- Loading branch information
0 parents
commit d63c8bf
Showing
39 changed files
with
1,166 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 John Pennycook | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Godot Input Prompts | ||
|
||
This Godot plugin adds new nodes providing easy-to-use input prompts. | ||
|
||
A demo of the prompts in action is available on [itch.io][1]; if you find this | ||
plugin useful, please consider supporting my work there. | ||
|
||
[1]:https://pennycook.itch.io/godot-input-prompts | ||
|
||
The current version supports the following icons: | ||
- Keyboard and mouse | ||
- Xbox | ||
- PlayStation | ||
- Nintendo Switch | ||
|
||
Please note that the PlayStation icons must be completed manually in an editor. | ||
|
||
## ActionPrompt | ||
|
||
![ActionPrompt](./addons/input_prompts/ActionPrompt/screenshot.png) | ||
|
||
ActionPrompt nodes display prompts based on the InputMap and an icon | ||
preference. When set to "Automatic", the prompts update to match the input | ||
device. | ||
|
||
## JoypadButtonPrompt | ||
|
||
![JoypadButtonPrompt](./addons/input_prompts/JoypadButtonPrompt/screenshot.png) | ||
|
||
JoypadButtonPrompt nodes display prompts corresponding to a button index. | ||
|
||
## JoypadMotionPrompt | ||
|
||
![JoypadMotionPrompt](./addons/input_prompts/JoypadMotionPrompt/screenshot.png) | ||
|
||
JoypadMotionPrompt nodes display prompts corresponding to an axis and an axis | ||
value. | ||
|
||
## KeyPrompt | ||
|
||
![KeyPrompt](./addons/input_prompts/KeyPrompt/screenshot.png) | ||
|
||
KeyPrompt nodes display prompts corresponding to a key scancode. | ||
|
||
## MousePrompt | ||
|
||
![MouseButtonPrompt](./addons/input_prompts/MouseButtonPrompt/screenshot.png) | ||
|
||
MouseButtonPrompt nodes display prompts corresponding to a button index. | ||
|
||
# License | ||
|
||
Code is licensed under the MIT license. | ||
Icons are in the [public domain][2], originally released by [Kenney][3]. | ||
|
||
[2]:https://creativecommons.org/publicdomain/zero/1.0/ | ||
[3]:https://kenney.nl/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
# Copyright (C) 2022 John Pennycook | ||
# SPDX-License-Identifier: MIT | ||
tool | ||
extends "res://addons/input_prompts/BasePrompt.gd" | ||
|
||
var action = "ui_accept" setget _set_action | ||
var icon = InputPrompts.Icons.AUTOMATIC setget _set_icon | ||
var _events : Array = [] | ||
|
||
func _ready(): | ||
self.action = action | ||
self.icon = icon | ||
_update_icon() | ||
|
||
func _set_action(new_action : String): | ||
action = new_action | ||
# In the Editor, InputMap reflects Editor settings | ||
# Read the list of actions from ProjectSettings instead | ||
if Engine.editor_hint: | ||
_events = ProjectSettings.get_setting("input/" + action)["events"] | ||
else: | ||
_events = InputMap.get_action_list(action) | ||
_update_icon() | ||
|
||
func _set_icon(new_icon): | ||
icon = new_icon | ||
_update_icon() | ||
|
||
func _find_event(list : Array, types : Array): | ||
for candidate in list: | ||
for type in types: | ||
if candidate is type: | ||
return candidate | ||
return null | ||
|
||
func _update_icon(): | ||
# If icon is set to AUTOMATIC, first determine which icon to display | ||
var display_icon : int = icon | ||
if icon == InputPrompts.Icons.AUTOMATIC: | ||
display_icon = InputPrompts.get_icons() | ||
|
||
# Choose the atlas and region associated with the InputEvent | ||
# If the InputMap contains multiple events, choose the first | ||
if display_icon == InputPrompts.Icons.KEYBOARD: | ||
var types = [InputEventKey, InputEventMouseButton] | ||
var ev = _find_event(_events, types) | ||
if not (ev is InputEventKey or ev is InputEventMouseButton): | ||
push_error("No Key/Mouse input for " + action + " in InputMap") | ||
if ev is InputEventKey: | ||
var scancode = ev.get_scancode() | ||
texture.atlas = InputPrompts.get_key_atlas() | ||
texture.region = InputPrompts.get_key_region(scancode) | ||
elif ev is InputEventMouseButton: | ||
var button = ev.get_button_index() | ||
texture.atlas = InputPrompts.get_mouse_atlas() | ||
texture.region = InputPrompts.get_mouse_region(button) | ||
else: | ||
var types = [InputEventJoypadButton, InputEventJoypadMotion] | ||
var ev = _find_event(_events, types) | ||
if not (ev is InputEventJoypadButton or ev is InputEventJoypadMotion): | ||
push_error("No Joypad input for " + action + " in InputMap") | ||
if ev is InputEventJoypadButton: | ||
var button = ev.get_button_index() | ||
texture.atlas = InputPrompts.get_joypad_button_atlas(display_icon) | ||
texture.region = InputPrompts.get_joypad_button_region(button) | ||
elif ev is InputEventJoypadMotion: | ||
var axis = ev.get_axis() | ||
var value = ev.get_axis_value() | ||
texture.atlas = InputPrompts.get_joypad_motion_atlas() | ||
texture.region = InputPrompts.get_joypad_motion_region(axis, value) | ||
update() | ||
|
||
func _input(event : InputEvent): | ||
if not event.is_action_pressed(action): | ||
return | ||
emit_signal("pressed") | ||
|
||
func _get_property_list(): | ||
var properties = [] | ||
properties.append({ | ||
name = "ActionPrompt", | ||
type = TYPE_NIL, | ||
usage = PROPERTY_USAGE_CATEGORY | PROPERTY_USAGE_SCRIPT_VARIABLE | ||
}) | ||
# In the Editor, InputMap reflects Editor settings | ||
# Read the list of actions from ProjectSettings instead | ||
var actions : String = "" | ||
for property in ProjectSettings.get_property_list(): | ||
var name = property["name"] | ||
if name.begins_with("input/"): | ||
if actions != "": | ||
actions += "," | ||
actions += name.trim_prefix("input/") | ||
properties.append({ | ||
name = "action", | ||
type = TYPE_STRING, | ||
hint = PROPERTY_HINT_ENUM, | ||
hint_string = actions | ||
}) | ||
properties.append({ | ||
name = "icon", | ||
type = TYPE_INT, | ||
hint = PROPERTY_HINT_ENUM, | ||
hint_string = "Automatic,Xbox,Sony,Nintendo,Keyboard" | ||
}) | ||
return properties |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
[remap] | ||
|
||
importer="texture" | ||
type="StreamTexture" | ||
path="res://.import/icon.png-81530b8bad18876c36fd6be5243690a5.stex" | ||
metadata={ | ||
"vram_texture": false | ||
} | ||
|
||
[deps] | ||
|
||
source_file="res://addons/input_prompts/ActionPrompt/icon.png" | ||
dest_files=[ "res://.import/icon.png-81530b8bad18876c36fd6be5243690a5.stex" ] | ||
|
||
[params] | ||
|
||
compress/mode=0 | ||
compress/lossy_quality=0.7 | ||
compress/hdr_mode=0 | ||
compress/bptc_ldr=0 | ||
compress/normal_map=0 | ||
flags/repeat=0 | ||
flags/filter=true | ||
flags/mipmaps=false | ||
flags/anisotropic=false | ||
flags/srgb=2 | ||
process/fix_alpha_border=true | ||
process/premult_alpha=false | ||
process/HDR_as_SRGB=false | ||
process/invert_color=false | ||
process/normal_map_invert_y=false | ||
stream=false | ||
size_limit=0 | ||
detect_3d=true | ||
svg/scale=1.0 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Copyright (C) 2022 John Pennycook | ||
# SPDX-License-Identifier: MIT | ||
tool | ||
extends TextureRect | ||
|
||
signal pressed() | ||
|
||
func _is_input_prompt(): | ||
return true | ||
|
||
func _ready(): | ||
self.texture = AtlasTexture.new() | ||
|
||
func _update_icon(): | ||
pass | ||
|
||
func _enter_tree(): | ||
InputPrompts.connect("icons_changed", self, "_update_icon") | ||
|
||
func _exit_tree(): | ||
InputPrompts.disconnect("icons_changed", self, "_update_icon") |
Oops, something went wrong.