* Replace key inputs */
| 397 | * Replace key inputs |
| 398 | */ |
| 399 | void UUnLuaManager::ReplaceKeyInputs(AActor *Actor, UInputComponent *InputComponent, TSet<FName> &LuaFunctions) |
| 400 | { |
| 401 | UClass *Class = Actor->GetClass(); |
| 402 | |
| 403 | TArray<FKey> Keys; |
| 404 | TArray<bool> PairedKeys; |
| 405 | TArray<EInputEvent> InputEvents; |
| 406 | for (FInputKeyBinding &IKB : InputComponent->KeyBindings) |
| 407 | { |
| 408 | int32 Index = Keys.Find(IKB.Chord.Key); |
| 409 | if (Index == INDEX_NONE) |
| 410 | { |
| 411 | Keys.Add(IKB.Chord.Key); |
| 412 | PairedKeys.Add(false); |
| 413 | InputEvents.Add(IKB.KeyEvent); |
| 414 | } |
| 415 | else |
| 416 | { |
| 417 | PairedKeys[Index] = true; |
| 418 | } |
| 419 | |
| 420 | FName FuncName = FName(*FString::Printf(TEXT("%s_%s"), *IKB.Chord.Key.ToString(), SReadableInputEvent[IKB.KeyEvent])); |
| 421 | if (LuaFunctions.Find(FuncName)) |
| 422 | { |
| 423 | ULuaFunction::Override(InputActionFunc, Class, FuncName); |
| 424 | IKB.KeyDelegate.BindDelegate(Actor, FuncName); |
| 425 | } |
| 426 | } |
| 427 | |
| 428 | for (int32 i = 0; i< Keys.Num(); ++i) |
| 429 | { |
| 430 | if (!PairedKeys[i]) |
| 431 | { |
| 432 | EInputEvent IE = InputEvents[i] == IE_Pressed ? IE_Released : IE_Pressed; |
| 433 | FName FuncName = FName(*FString::Printf(TEXT("%s_%s"), *Keys[i].ToString(), SReadableInputEvent[IE])); |
| 434 | if (LuaFunctions.Find(FuncName)) |
| 435 | { |
| 436 | ULuaFunction::Override(InputActionFunc, Class, FuncName); |
| 437 | FInputKeyBinding IKB(FInputChord(Keys[i]), IE); |
| 438 | IKB.KeyDelegate.BindDelegate(Actor, FuncName); |
| 439 | InputComponent->KeyBindings.Add(IKB); |
| 440 | } |
| 441 | } |
| 442 | } |
| 443 | |
| 444 | EInputEvent IEs[] = { IE_Pressed, IE_Released }; |
| 445 | for (const FKey &Key : AllKeys) |
| 446 | { |
| 447 | if (Keys.Find(Key) != INDEX_NONE) |
| 448 | { |
| 449 | continue; |
| 450 | } |
| 451 | for (int32 i = 0; i < 2; ++i) |
| 452 | { |
| 453 | FName FuncName = FName(*FString::Printf(TEXT("%s_%s"), *Key.ToString(), SReadableInputEvent[IEs[i]])); |
| 454 | if (LuaFunctions.Find(FuncName)) |
| 455 | { |
| 456 | ULuaFunction::Override(InputActionFunc, Class, FuncName); |