* Replace action inputs */
| 341 | * Replace action inputs |
| 342 | */ |
| 343 | void UUnLuaManager::ReplaceActionInputs(AActor *Actor, UInputComponent *InputComponent, TSet<FName> &LuaFunctions) |
| 344 | { |
| 345 | UClass *Class = Actor->GetClass(); |
| 346 | |
| 347 | TSet<FName> ActionNames; |
| 348 | int32 NumActionBindings = InputComponent->GetNumActionBindings(); |
| 349 | for (int32 i = 0; i < NumActionBindings; ++i) |
| 350 | { |
| 351 | FInputActionBinding &IAB = InputComponent->GetActionBinding(i); |
| 352 | FName Name = GET_INPUT_ACTION_NAME(IAB); |
| 353 | FString ActionName = Name.ToString(); |
| 354 | ActionNames.Add(Name); |
| 355 | |
| 356 | FName FuncName = FName(*FString::Printf(TEXT("%s_%s"), *ActionName, SReadableInputEvent[IAB.KeyEvent])); |
| 357 | if (LuaFunctions.Find(FuncName)) |
| 358 | { |
| 359 | ULuaFunction::Override(InputActionFunc, Class, FuncName); |
| 360 | IAB.ActionDelegate.BindDelegate(Actor, FuncName); |
| 361 | } |
| 362 | |
| 363 | if (!IS_INPUT_ACTION_PAIRED(IAB)) |
| 364 | { |
| 365 | EInputEvent IE = IAB.KeyEvent == IE_Pressed ? IE_Released : IE_Pressed; |
| 366 | FuncName = FName(*FString::Printf(TEXT("%s_%s"), *ActionName, SReadableInputEvent[IE])); |
| 367 | if (LuaFunctions.Find(FuncName)) |
| 368 | { |
| 369 | ULuaFunction::Override(InputActionFunc, Class, FuncName); |
| 370 | FInputActionBinding AB(Name, IE); |
| 371 | AB.ActionDelegate.BindDelegate(Actor, FuncName); |
| 372 | InputComponent->AddActionBinding(AB); |
| 373 | } |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | EInputEvent IEs[] = { IE_Pressed, IE_Released }; |
| 378 | TSet<FName> DiffActionNames = DefaultActionNames.Difference(ActionNames); |
| 379 | for (TSet<FName>::TConstIterator It(DiffActionNames); It; ++It) |
| 380 | { |
| 381 | FName ActionName = *It; |
| 382 | for (int32 i = 0; i < 2; ++i) |
| 383 | { |
| 384 | FName FuncName = FName(*FString::Printf(TEXT("%s_%s"), *ActionName.ToString(), SReadableInputEvent[IEs[i]])); |
| 385 | if (LuaFunctions.Find(FuncName)) |
| 386 | { |
| 387 | ULuaFunction::Override(InputActionFunc, Class, FuncName); |
| 388 | FInputActionBinding AB(ActionName, IEs[i]); |
| 389 | AB.ActionDelegate.BindDelegate(Actor, FuncName); |
| 390 | InputComponent->AddActionBinding(AB); |
| 391 | } |
| 392 | } |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | /** |
| 397 | * Replace key inputs |
nothing calls this directly
no test coverage detected