Initial commit
This commit is contained in:
BIN
addons/InputMapperPresetLoader/InputMapperPlugin.gif
Normal file
BIN
addons/InputMapperPresetLoader/InputMapperPlugin.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 64 KiB |
96
addons/InputMapperPresetLoader/InputMapperPresets.gd
Normal file
96
addons/InputMapperPresetLoader/InputMapperPresets.gd
Normal file
@@ -0,0 +1,96 @@
|
||||
@tool
|
||||
extends Control
|
||||
|
||||
@onready var btn_save_preset = %BtnSavePreset
|
||||
@onready var btn_load_preset = %BtnLoadPreset
|
||||
@onready var lin_ed_preset_name = %LinEdPresetName
|
||||
@onready var dropdown = %Dropdown
|
||||
@onready var btn_import = %BtnImport
|
||||
@onready var confirmation_dialog = $ConfirmationDialog
|
||||
|
||||
|
||||
@onready var file_dialog = $FileDialog
|
||||
|
||||
|
||||
var folder_path : String
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
btn_load_preset.pressed.connect(on_btn_pressed_load)
|
||||
btn_save_preset.pressed.connect(on_btn_pressed_save)
|
||||
btn_import.pressed.connect(on_btn_pressed_import)
|
||||
confirmation_dialog.confirmed.connect(on_confirmed_restart)
|
||||
|
||||
file_dialog.dialog_hide_on_ok = true
|
||||
file_dialog.access = 2
|
||||
file_dialog.dir_selected.connect(on_folder_selected)
|
||||
btn_import.disabled = true
|
||||
|
||||
|
||||
func on_folder_selected(path):
|
||||
folder_path = path
|
||||
btn_import.disabled = false
|
||||
dir_contents(path)
|
||||
|
||||
|
||||
func on_confirmed_restart():
|
||||
EditorPlugin.new().get_editor_interface().restart_editor()
|
||||
|
||||
|
||||
func on_btn_pressed_import():
|
||||
var file_path = folder_path.path_join(dropdown.get_item_text(dropdown.selected))
|
||||
var config = ConfigFile.new()
|
||||
var err = config.load(file_path)
|
||||
|
||||
if err != OK:
|
||||
return
|
||||
|
||||
for input_name in config.get_section_keys("input"):
|
||||
var action_obj = config.get_value("input", input_name)
|
||||
ProjectSettings.set_setting("input/" + input_name, action_obj)
|
||||
ProjectSettings.save()
|
||||
confirmation_dialog.popup_centered()
|
||||
|
||||
func on_btn_pressed_load():
|
||||
file_dialog.popup_centered()
|
||||
|
||||
|
||||
func on_btn_pressed_save():
|
||||
if lin_ed_preset_name.text != null:
|
||||
save_test_file()
|
||||
|
||||
|
||||
func save_test_file():
|
||||
InputMap.load_from_project_settings()
|
||||
var config = ConfigFile.new()
|
||||
var Actions = InputMap.get_actions()
|
||||
|
||||
for action in Actions:
|
||||
if not action.begins_with("ui"):
|
||||
var input_object = {
|
||||
"deadzone": InputMap.action_get_deadzone(action),
|
||||
"events": InputMap.action_get_events(action)
|
||||
}
|
||||
config.set_value("input", action, input_object)
|
||||
|
||||
# Save it to a file (overwrite if already exists).
|
||||
config.save(folder_path.path_join(lin_ed_preset_name.text + ".godot"))
|
||||
|
||||
|
||||
func dir_contents(path):
|
||||
dropdown.clear()
|
||||
var dir = DirAccess.open(path)
|
||||
if dir:
|
||||
dir.list_dir_begin()
|
||||
var file_name = dir.get_next()
|
||||
while file_name != "":
|
||||
if dir.current_is_dir():
|
||||
print("Found directory: " + file_name)
|
||||
else:
|
||||
if file_name.ends_with(".godot"):
|
||||
dropdown.add_item(file_name)
|
||||
file_name = dir.get_next()
|
||||
|
||||
else:
|
||||
print("An error occurred when trying to access the path.")
|
||||
78
addons/InputMapperPresetLoader/InputMapperPresets.tscn
Normal file
78
addons/InputMapperPresetLoader/InputMapperPresets.tscn
Normal file
@@ -0,0 +1,78 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://cpunnqo5npx7a"]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/inputmapperpresetloader/InputMapperPresets.gd" id="1_m65gv"]
|
||||
|
||||
[node name="InputMapperPresets" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_m65gv")
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="HBoxContainer2" type="VBoxContainer" parent="MarginContainer"]
|
||||
custom_minimum_size = Vector2(200, 0)
|
||||
layout_mode = 2
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer/HBoxContainer2"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="BtnSavePreset" type="Button" parent="MarginContainer/HBoxContainer2/HBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
tooltip_text = "Saves the projects current input map using name given to the right of this button and it ends with `.godot`
|
||||
|
||||
Will ignore default values (anything that starts with `ui`"
|
||||
text = "Save"
|
||||
|
||||
[node name="LinEdPresetName" type="LineEdit" parent="MarginContainer/HBoxContainer2/HBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(200, 0)
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
tooltip_text = "The name the config file will have and it ends with a `.godot`"
|
||||
|
||||
[node name="TxtExtention" type="Label" parent="MarginContainer/HBoxContainer2/HBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 8
|
||||
text = ".godot"
|
||||
|
||||
[node name="BtnLoadPreset" type="Button" parent="MarginContainer/HBoxContainer2/HBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
tooltip_text = "Select the folder that has your saved config files"
|
||||
text = "Select Folder"
|
||||
|
||||
[node name="Dropdown" type="OptionButton" parent="MarginContainer/HBoxContainer2"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
allow_reselect = true
|
||||
|
||||
[node name="BtnImport" type="Button" parent="MarginContainer/HBoxContainer2"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
disabled = true
|
||||
text = "Import"
|
||||
|
||||
[node name="FileDialog" type="FileDialog" parent="."]
|
||||
title = "Open a Directory"
|
||||
size = Vector2i(480, 240)
|
||||
min_size = Vector2i(480, 240)
|
||||
ok_button_text = "Select Current Folder"
|
||||
dialog_hide_on_ok = true
|
||||
file_mode = 2
|
||||
access = 2
|
||||
root_subfolder = "C:\\Users\\Light\\AppData\\Roaming\\Godot"
|
||||
|
||||
[node name="ConfirmationDialog" type="AcceptDialog" parent="."]
|
||||
dialog_text = "Restart Project Now?"
|
||||
17
addons/InputMapperPresetLoader/inputmapperpresetloader.gd
Normal file
17
addons/InputMapperPresetLoader/inputmapperpresetloader.gd
Normal file
@@ -0,0 +1,17 @@
|
||||
@tool
|
||||
extends EditorPlugin
|
||||
|
||||
const editorAddon = preload("res://addons/inputmapperpresetloader/InputMapperPresets.tscn")
|
||||
var InputMapperPresetsScene
|
||||
|
||||
|
||||
func _enter_tree():
|
||||
InputMap.load_from_project_settings()
|
||||
|
||||
InputMapperPresetsScene = editorAddon.instantiate()
|
||||
add_control_to_dock(EditorPlugin.DOCK_SLOT_RIGHT_UL, InputMapperPresetsScene)
|
||||
|
||||
|
||||
func _exit_tree():
|
||||
remove_control_from_docks(InputMapperPresetsScene)
|
||||
InputMapperPresetsScene.free()
|
||||
7
addons/InputMapperPresetLoader/plugin.cfg
Normal file
7
addons/InputMapperPresetLoader/plugin.cfg
Normal file
@@ -0,0 +1,7 @@
|
||||
[plugin]
|
||||
|
||||
name="InputMapperPresetLoader"
|
||||
description="This plugin works by letting users save/import pre-defined Input Maps"
|
||||
author="Light1c3"
|
||||
version="1.0.0"
|
||||
script="inputmapperpresetloader.gd"
|
||||
Reference in New Issue
Block a user