Ejemplo n.º 1
0
void UInputBlueprintLibrary::K2_RemoveAxisKeyBinding(FValorAxisInputBinding BindingToRemove)
{
	UInputSettings* Settings = GetMutableDefault<UInputSettings>();
	if (!Settings)
	{
		return;
	}

	TArray<FInputAxisKeyMapping>& AxisMappings = Settings->AxisMappings;

	bool bFound = false;
	for (int32 Index = 0; Index < AxisMappings.Num(); ++Index)
	{
		if (AxisMappings[Index].Key == BindingToRemove.Key)
		{
			bFound = true;
			AxisMappings.RemoveAt(Index);
			Index = 0;
		}
	}

	if (bFound)
	{
		Settings->SaveKeyMappings();

		for (TObjectIterator<UPlayerInput> It; It; ++It)
		{
			It->ForceRebuildingKeyMaps(true);
		}
	}
}
Ejemplo n.º 2
0
void FAxisMappingsNodeBuilder::AddAxisMappingToGroupButton_OnClick(const FMappingSet MappingSet)
{
	const FScopedTransaction Transaction(LOCTEXT("AddAxisMappingToGroup_Transaction", "Add Axis Mapping To Group"));

	TArray<UObject*> OuterObjects;
	AxisMappingsPropertyHandle->GetOuterObjects(OuterObjects);

	if (OuterObjects.Num() == 1)
	{
		UInputSettings* InputSettings = CastChecked<UInputSettings>(OuterObjects[0]);
		InputSettings->Modify();
		AxisMappingsPropertyHandle->NotifyPreChange();

		FInputAxisKeyMapping NewMapping(MappingSet.SharedName);
		InputSettings->AxisMappings.Add(NewMapping);

		AxisMappingsPropertyHandle->NotifyPostChange();
	}
}
void FActionMappingsNodeBuilder::AddActionMappingToGroupButton_OnClick(const FMappingSet MappingSet)
{
	const FScopedTransaction Transaction(LOCTEXT("AddActionMappingToGroup_Transaction", "Add Action Mapping To Group"));

	TArray<UObject*> OuterObjects;
	ActionMappingsPropertyHandle->GetOuterObjects(OuterObjects);

	if (OuterObjects.Num() == 1)
	{
		UInputSettings* InputSettings = CastChecked<UInputSettings>(OuterObjects[0]);
		InputSettings->Modify();
		ActionMappingsPropertyHandle->NotifyPreChange();

		DelayedGroupExpansionStates.Add(TPairInitializer<FName, bool>(MappingSet.SharedName, true));
		FInputActionKeyMapping NewMapping(MappingSet.SharedName);
		InputSettings->ActionMappings.Add(NewMapping);

		ActionMappingsPropertyHandle->NotifyPostChange();
	}
}
void FAxisMappingsNodeBuilder::AddAxisMappingButton_OnClick()
{
	static const FName BaseAxisMappingName(*LOCTEXT("NewAxisMappingName", "NewAxisMapping").ToString());
	static int32 NewMappingCount = 0;
	const FScopedTransaction Transaction(LOCTEXT("AddAxisMapping_Transaction", "Add Axis Mapping"));

	TArray<UObject*> OuterObjects;
	AxisMappingsPropertyHandle->GetOuterObjects(OuterObjects);

	if (OuterObjects.Num() == 1)
	{
		UInputSettings* InputSettings = CastChecked<UInputSettings>(OuterObjects[0]);
		InputSettings->Modify();
		AxisMappingsPropertyHandle->NotifyPreChange();

		FName NewAxisMappingName;
		bool bFoundUniqueName;
		do
		{
			// Create a numbered name and check whether it's already been used
			NewAxisMappingName = FName(BaseAxisMappingName, ++NewMappingCount);
			bFoundUniqueName = true;
			for (int32 Index = 0; Index < InputSettings->AxisMappings.Num(); ++Index)
			{
				if (InputSettings->AxisMappings[Index].AxisName == NewAxisMappingName)
				{
					bFoundUniqueName = false;
					break;
				}
			}
		}
		while (!bFoundUniqueName);

		DelayedGroupExpansionStates.Add(TPairInitializer<FName, bool>(NewAxisMappingName, true));
		FInputAxisKeyMapping NewMapping(NewAxisMappingName);
		InputSettings->AxisMappings.Add(NewMapping);

		AxisMappingsPropertyHandle->NotifyPostChange();
	}
}