mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-06 22:45:53 +00:00
Keymapping menu
This commit is contained in:
parent
9e8c2220b2
commit
b76427e3ca
14 changed files with 137 additions and 34 deletions
|
|
@ -1,15 +1,30 @@
|
|||
using Godot;
|
||||
using System;
|
||||
using Cirno.Scripts.UI;
|
||||
using Godot.Collections;
|
||||
|
||||
public partial class KeyRemapping : Container
|
||||
{
|
||||
[Export] public Dictionary<StringName, StringName> KeysDict { get; private set; } = new();
|
||||
|
||||
[Export] public Container KeysContainer { get; private set; }
|
||||
|
||||
[Export] public PackedScene ItemPrefab { get; private set; }
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
var remap = GetNode("/root/Remap");
|
||||
//var remap = GetNode("/root/Remap");
|
||||
//InputEvent.
|
||||
|
||||
foreach (var element in KeysDict)
|
||||
{
|
||||
var item = ItemPrefab.Instantiate<KeyRemappingItem>();
|
||||
|
||||
item.KeyId = element.Key;
|
||||
item.KeyName = element.Value;
|
||||
|
||||
KeysContainer.AddChild(item);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
43
Scripts/UI/KeyRemappingItem.cs
Normal file
43
Scripts/UI/KeyRemappingItem.cs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
using System.Linq;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.UI;
|
||||
|
||||
public partial class KeyRemappingItem : HBoxContainer
|
||||
{
|
||||
public StringName KeyId { get; set; }
|
||||
public StringName KeyName { get; set; }
|
||||
|
||||
[Export] public Label NameLabel { get; private set; }
|
||||
[Export] public Label InputLabel { get; private set; }
|
||||
|
||||
private bool _active = false;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
NameLabel.Text = KeyName;
|
||||
var actions = InputMap.GetActions();
|
||||
|
||||
var action = actions.FirstOrDefault(x => x == KeyId);
|
||||
var events = InputMap.ActionGetEvents(action);
|
||||
|
||||
InputLabel.Text = string.Join(",", events.Select(x => x.AsText()));
|
||||
}
|
||||
|
||||
public void StartRemap()
|
||||
{
|
||||
_active = true;
|
||||
}
|
||||
|
||||
public override void _Input(InputEvent e)
|
||||
{
|
||||
if (!_active) return;
|
||||
|
||||
if (e is InputEventKey keyEvent && keyEvent.Pressed)
|
||||
{
|
||||
GD.Print(keyEvent.Keycode);
|
||||
InputLabel.Text = keyEvent.Keycode.ToString();
|
||||
_active = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
1
Scripts/UI/KeyRemappingItem.cs.uid
Normal file
1
Scripts/UI/KeyRemappingItem.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dn52llyqx84e0
|
||||
Loading…
Add table
Add a link
Reference in a new issue