@frigid solar When you first load your UI scene, you have to set the keys to the dictionary values. Usually with parce input event. I did a custom UI scene for a game of mine. I also showed my code in another post on here to help someone else with it. I'm currently away from the com, but I will try to look up the post or repost my code for an example.
#Trouble trying to convert Strings to InputEventKey from dictionary
11 messages · Page 1 of 1 (latest)
Actually, I think all you are asking is this part...
$ButtonNode.text = OS.get_keycode_string(yourEventDict["ui_input"])
Looks neat to do the print out like that. Great job, never knew Godot had that....
I can show you my full code, but that's how I set it and eveything else in our code is the same.
Sure, give me sec and I'll put it together for you.
I'll try to keep the points that are relevant to yours.
var changingEventKeys: bool = false
var eventActionInt: int = 0
var eventActionKey: String
var originalActionKeyArray: Array = [KEY_W, KEY_S, KEY_A, KEY_D, KEY_ESCAPE, KEY_TAB, KEY_SPACE, KEY_U]
var eventChangedDict: Dictionary = {}# Save
func _init_dict(savedDict: Dictionary):
if !savedDict.is_empty():
eventChangedDict = savedDict["EventActionKeys"]
musicVolume = savedDict["MusicVolume"]
soundVolume = savedDict["SoundVolume"]
musicOn = savedDict["MusicOn"]
soundOn = savedDict["SoundOn"]
$OptionsControl/ComputerControls/UpGrid/Key_Up.text = OS.get_keycode_string(eventChangedDict["ui_up"])
$OptionsControl/ComputerControls/DownGrid/Key_Down.text = OS.get_keycode_string(eventChangedDict["ui_down"])
$OptionsControl/ComputerControls/LeftGrid/Key_Left.text = OS.get_keycode_string(eventChangedDict["ui_left"])
$OptionsControl/ComputerControls/RightGrid/Key_Right.text = OS.get_keycode_string(eventChangedDict["ui_right"])
$OptionsControl/ComputerControls/SettingsGrid/Key_Settings.text = OS.get_keycode_string(eventChangedDict["ui_settings"])
$OptionsControl/ComputerControls/BuildGrid/Key_Build.text = OS.get_keycode_string(eventChangedDict["ui_build"])
$OptionsControl/ComputerControls/DrillGrid/Key_Drill.text = OS.get_keycode_string(eventChangedDict["ui_drill"])
$OptionsControl/ComputerControls/UpgradeGrid/Key_Upgrade.text = OS.get_keycode_string(eventChangedDict["ui_upgrade"])
var eventKeyList: Array = eventChangedDict.keys()
for i in eventChangedDict.size():
var parseInputKey: InputEventKey = InputEventKey.new()
parseInputKey.keycode = eventChangedDict[eventKeyList[i]]
InputMap.action_erase_events(eventKeyList[i])
InputMap.action_add_event(eventKeyList[i], parseInputKey)
This is all I do to handle the change.
func _unhandled_input(event):
if scenePaused:
return
if changingEventKeys:
if event is InputEventKey and event.pressed:
var setEvent: InputEventKey = event
for i in eventChangedDict.keys():
if eventChangedDict.get(i) == setEvent.keycode:
changingEventKeys = false
return
eventChangedDict[eventActionKey] = setEvent.keycode
InputMap.action_erase_events(eventActionKey)
InputMap.action_add_event(eventActionKey, setEvent)
changingEventKeys = false
$OptionsControl/ComputerControls.get_child(eventActionInt).get_child(0).text = OS.get_keycode_string(setEvent.key_label)
return
I forgot this, it's from the button press to say which event it is relevant to the dictionary.
func _on_key_up_button_up():
changingEventKeys = true
eventActionKey = "ui_up"
eventActionInt = 0
My reset....
func _on_reset_buttons_button_pressed():
eventChangedDict = {
"ui_up": originalActionKeyArray[0],
"ui_down": originalActionKeyArray[1],
"ui_left": originalActionKeyArray[2],
"ui_right": originalActionKeyArray[3],
"ui_settings": originalActionKeyArray[4],
"ui_build": originalActionKeyArray[5],
"ui_drill": originalActionKeyArray[6],
"ui_upgrade": originalActionKeyArray[7],
}
$OptionsControl/ComputerControls/UpGrid/Key_Up.text = OS.get_keycode_string(eventChangedDict["ui_up"])
$OptionsControl/ComputerControls/DownGrid/Key_Down.text = OS.get_keycode_string(eventChangedDict["ui_down"])
$OptionsControl/ComputerControls/LeftGrid/Key_Left.text = OS.get_keycode_string(eventChangedDict["ui_left"])
$OptionsControl/ComputerControls/RightGrid/Key_Right.text = OS.get_keycode_string(eventChangedDict["ui_right"])
$OptionsControl/ComputerControls/SettingsGrid/Key_Settings.text = OS.get_keycode_string(eventChangedDict["ui_settings"])
$OptionsControl/ComputerControls/BuildGrid/Key_Build.text = OS.get_keycode_string(eventChangedDict["ui_build"])
$OptionsControl/ComputerControls/DrillGrid/Key_Drill.text = OS.get_keycode_string(eventChangedDict["ui_drill"])
$OptionsControl/ComputerControls/UpgradeGrid/Key_Upgrade.text = OS.get_keycode_string(eventChangedDict["ui_upgrade"])