Skip to content

Commit

Permalink
Merge branch '5.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
goncasmage1 committed Jun 20, 2021
2 parents d443cef + 9315e0f commit ca895dc
Show file tree
Hide file tree
Showing 19 changed files with 107 additions and 76 deletions.
Binary file modified Content/Docs/UINavControllerDocs.uasset
Binary file not shown.
Binary file modified Content/Docs/UINavDocs.uasset
Binary file not shown.
Binary file modified Content/Docs/Updates.uasset
Binary file not shown.
Binary file modified Content/UINavPC.uasset
Binary file not shown.
8 changes: 4 additions & 4 deletions Source/UINavigation/Private/UINavComponentBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ void UUINavComponentBox::BaseConstruct()
void UUINavComponentBox::CheckLeftLimit()
{
if (bLoopOptions) return;
if (OptionIndex == 0) LeftButton->SetIsEnabled(false);
if (OptionIndex <= 0) LeftButton->SetIsEnabled(false);
}

void UUINavComponentBox::CheckRightLimit()
{
if (bLoopOptions) return;
if (OptionIndex == GetMaxOptionIndex()) RightButton->SetIsEnabled(false);
if (OptionIndex >= GetMaxOptionIndex()) RightButton->SetIsEnabled(false);
}

void UUINavComponentBox::UpdateTextToIndex(const int NewIndex)
Expand Down Expand Up @@ -102,7 +102,7 @@ void UUINavComponentBox::FinishNavigateLeft(const bool bOptionChanged)

CheckLeftLimit();
//Enable button if previously disabled
if (!RightButton->bIsEnabled) RightButton->SetIsEnabled(true);
if (!RightButton->bIsEnabled && GetMaxOptionIndex() > 0) RightButton->SetIsEnabled(true);

if (bOptionChanged)
{
Expand Down Expand Up @@ -130,7 +130,7 @@ void UUINavComponentBox::FinishNavigateRight(const bool bOptionChanged)

CheckRightLimit();
//Enable button if previously disabled
if (!LeftButton->bIsEnabled) LeftButton->SetIsEnabled(true);
if (!LeftButton->bIsEnabled && GetMaxOptionIndex() > 0) LeftButton->SetIsEnabled(true);

if (bOptionChanged)
{
Expand Down
8 changes: 5 additions & 3 deletions Source/UINavigation/Private/UINavHorizontalComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ void UUINavHorizontalComponent::NavigateRight()

void UUINavHorizontalComponent::Update()
{
int MaxOptionIndex = GetMaxOptionIndex();
const int MaxOptionIndex = GetMaxOptionIndex();
if (MaxOptionIndex < 1) return;

if (OptionIndex > MaxOptionIndex) OptionIndex = MaxOptionIndex;
else if (OptionIndex < 0) OptionIndex = 0;

Expand All @@ -36,9 +38,9 @@ void UUINavHorizontalComponent::UpdateTextToIndex(int NewIndex)
Update();
}

void UUINavHorizontalComponent::ChangeText(FText NewText)
void UUINavHorizontalComponent::ChangeText(const FText NewText)
{
NavText->SetText(NewText);
if (NavText != nullptr) NavText->SetText(NewText);
}

void UUINavHorizontalComponent::OnNavigateLeft_Implementation()
Expand Down
9 changes: 2 additions & 7 deletions Source/UINavigation/Private/UINavOptionBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,7 @@ int UUINavOptionBox::GetMaxOptionIndex() const
}
else
{
if (StringOptions.Num() > 0) return StringOptions.Num() - 1;
else
{
DISPLAYERROR(TEXT("StringOptions needs to have at least 2 options"));
return 0;
}
return StringOptions.Num() - 1;
}
}

Expand All @@ -39,6 +34,6 @@ void UUINavOptionBox::Update()

NavText->SetText(bUseNumberRange ?
FText::FromString(FString::FromInt(MinRange + OptionIndex*Interval)) :
StringOptions.Num() > OptionIndex ? StringOptions[OptionIndex] : FText());
StringOptions.IsValidIndex(OptionIndex) ? StringOptions[OptionIndex] : FText());
}

11 changes: 11 additions & 0 deletions Source/UINavigation/Private/UINavPCComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ void UUINavPCComponent::BeginPlay()

VerifyDefaultInputs();
FetchUINavActionKeys();
if (!FCoreDelegates::OnControllerConnectionChange.IsBoundToObject(this))
{
FCoreDelegates::OnControllerConnectionChange.AddUObject(this, &UUINavPCComponent::OnControllerConnectionChanged);
}
}
}

Expand All @@ -58,6 +62,8 @@ void UUINavPCComponent::EndPlay(const EEndPlayReason::Type EndPlayReason)
{
FSlateApplication::Get().UnregisterInputPreProcessor(SharedInputProcessor);
}

FCoreDelegates::OnControllerConnectionChange.RemoveAll(this);

Super::EndPlay(EndPlayReason);
}
Expand Down Expand Up @@ -203,6 +209,11 @@ void UUINavPCComponent::CallCustomInput(const FName ActionName, const bool bPres
}
}

void UUINavPCComponent::OnControllerConnectionChanged(bool bConnected, int32 UserId, int32 UserIndex)
{
IUINavPCReceiver::Execute_OnControllerConnectionChanged(GetOwner(), bConnected, UserId, UserIndex);
}

void UUINavPCComponent::VerifyDefaultInputs()
{
UUINavSettings *MySettings = GetMutableDefault<UUINavSettings>();
Expand Down
7 changes: 5 additions & 2 deletions Source/UINavigation/Private/UINavPCReceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ void IUINavPCReceiver::OnInputChanged_Implementation(EInputType From, EInputType
{
}

void IUINavPCReceiver::OnActiveWidgetChanged_Implementation(UUINavWidget* OldActiveWidget,
UUINavWidget* NewActiveWidget)
void IUINavPCReceiver::OnControllerConnectionChanged_Implementation(bool bConnected, int32 UserId, int32 UserIndex)
{
}

void IUINavPCReceiver::OnActiveWidgetChanged_Implementation(UUINavWidget* OldActiveWidget, UUINavWidget* NewActiveWidget)
{
}

Expand Down
6 changes: 0 additions & 6 deletions Source/UINavigation/Private/UINavSlider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ void UUINavSlider::Update()
if (NavText != nullptr) NavText->SetText(ValueText);
if (NavSpinBox != nullptr)
{
bIgnoreSpinBoxCommit = true;
NavSpinBox->SetValue(Value);
}
}
Expand Down Expand Up @@ -144,11 +143,6 @@ void UUINavSlider::HandleOnMouseCaptureEnd()

void UUINavSlider::HandleOnSpinBoxValueChanged(float InValue, ETextCommit::Type CommitMethod)
{
if (bIgnoreSpinBoxCommit)
{
bIgnoreSpinBoxCommit = false;
return;
}
OptionIndex = IndexFromValue(InValue);
Update();
}
Expand Down
84 changes: 49 additions & 35 deletions Source/UINavigation/Private/UINavWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "UINavPCComponent.h"
#include "UINavPCReceiver.h"
#include "UINavPromptWidget.h"
#include "UINavSettings.h"
#include "UINavWidgetComponent.h"
#include "UINavBlueprintFunctionLibrary.h"
#include "UINavMacros.h"
Expand Down Expand Up @@ -134,8 +135,6 @@ void UUINavWidget::InitialSetup(const bool bRebuilding)
if (!IsSelectorValid())
{
UINavSetup();
bShouldTick = false;
return;
}
else
{
Expand All @@ -153,16 +152,12 @@ void UUINavWidget::ReconfigureSetup()
if (!IsSelectorValid())
{
UINavSetup();
return;
}
else
{
SetupSelector();
}

bShouldTick = true;
WaitForTick = 0;

for (UUINavWidget* ChildUINavWidget : ChildUINavWidgets)
{
ChildUINavWidget->ReconfigureSetup();
Expand Down Expand Up @@ -514,9 +509,7 @@ void UUINavWidget::RebuildNavigation(const int NewButtonIndex)
bMovingSelector = false;
bIgnoreMouseEvent = false;
bReturning = false;
bShouldTick = true;
ReceiveInputType = EReceiveInputType::None;
WaitForTick = 0;
HaltedIndex = -1;
SelectedButtonIndex = -1;
SelectCount = 0;
Expand Down Expand Up @@ -552,6 +545,9 @@ void UUINavWidget::SetupSelector()

SelectorSlot->SetAlignment(FVector2D(0.5f, 0.5f));
SelectorSlot->SetPosition(FVector2D(0.f, 0.f));

UINavSetupWaitForTick=0;
bShouldTickUINavSetup = true;
}

void UUINavWidget::UINavSetup()
Expand All @@ -574,7 +570,7 @@ void UUINavWidget::UINavSetup()
{
SetEnableUINavButtons(true, true);
}

bCompletedSetup = true;

if (OuterUINavWidget == nullptr)
Expand Down Expand Up @@ -720,24 +716,41 @@ void UUINavWidget::NativeTick(const FGeometry & MyGeometry, float DeltaTime)
{
Super::NativeTick(MyGeometry, DeltaTime);

if (!IsSelectorValid() || !bSetupStarted) return;

if (bMovingSelector)
{
HandleSelectorMovement(DeltaTime);
}
else
if (IsSelectorValid())
{
if (!bShouldTick) return;

if (WaitForTick == 1)
if (bShouldTickUINavSetup)
{
UINavSetup();
bShouldTick = false;
return;
if (UINavSetupWaitForTick >= 1)
{
UINavSetup();
bShouldTickUINavSetup = false;
}
else
{
UINavSetupWaitForTick++;
}
}
else
{
if (bShouldTickUpdateSelector)
{
if (UpdateSelectorWaitForTick >= 1)
{
if (MoveCurve != nullptr) BeginSelectorMovement(UpdateSelectorPrevButtonIndex, UpdateSelectorNextButtonIndex);
else UpdateSelectorLocation(UpdateSelectorNextButtonIndex);
bShouldTickUpdateSelector = false;
}
else
{
UpdateSelectorWaitForTick++;
}
}

WaitForTick++;
if (bMovingSelector)
{
HandleSelectorMovement(DeltaTime);
}
}
}
}

Expand Down Expand Up @@ -1263,20 +1276,19 @@ void UUINavWidget::ReplaceButtonInNavigationGrid(UUINavButton * ButtonToReplace,

void UUINavWidget::UpdateCurrentButton(UUINavButton * NewCurrentButton)
{
ButtonIndex = NewCurrentButton->ButtonIndex;
if (IsSelectorValid())
{
if (MoveCurve != nullptr) BeginSelectorMovement(NewCurrentButton->ButtonIndex);
else UpdateSelectorLocation(NewCurrentButton->ButtonIndex);
UpdateSelectorWaitForTick = 0;
UpdateSelectorPrevButtonIndex = ButtonIndex;
UpdateSelectorNextButtonIndex = NewCurrentButton->ButtonIndex;
bShouldTickUpdateSelector = true;
}

ButtonIndex = NewCurrentButton->ButtonIndex;

for (UScrollBox* ScrollBox : ScrollBoxes)
{
if (NewCurrentButton->IsChildOf(ScrollBox))
{
ScrollBox->ScrollWidgetIntoView(NewCurrentButton, bAnimateScrollBoxes);
break;
}
}
}

Expand Down Expand Up @@ -2410,8 +2422,10 @@ void UUINavWidget::DispatchNavigation(const int Index)

if (Index > -1 && IsSelectorValid())
{
if (MoveCurve != nullptr) BeginSelectorMovement(Index);
else UpdateSelectorLocation(Index);
UpdateSelectorWaitForTick = 0;
UpdateSelectorPrevButtonIndex = ButtonIndex;
UpdateSelectorNextButtonIndex = Index;
bShouldTickUpdateSelector = true;
}

if (bUseTextColor) UpdateTextColor(Index);
Expand All @@ -2424,12 +2438,12 @@ void UUINavWidget::DispatchNavigation(const int Index)
if (UINavAnimations.Num() > 0) ExecuteAnimations(ButtonIndex, Index);
}

void UUINavWidget::BeginSelectorMovement(const int Index)
void UUINavWidget::BeginSelectorMovement(const int PrevButtonIndex, const int NextButtonIndex)
{
if (MoveCurve == nullptr) return;

SelectorOrigin = bMovingSelector ? TheSelector->RenderTransform.Translation : GetButtonLocation(ButtonIndex);
SelectorDestination = GetButtonLocation(Index);
SelectorOrigin = bMovingSelector ? TheSelector->RenderTransform.Translation : GetButtonLocation(PrevButtonIndex);
SelectorDestination = GetButtonLocation(NextButtonIndex);
Distance = SelectorDestination - SelectorOrigin;

float MinTime, MaxTime;
Expand Down
2 changes: 1 addition & 1 deletion Source/UINavigation/Public/UINavButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class UINAVIGATION_API UUINavButton : public UButton
UPROPERTY(BlueprintReadOnly, Category = UINavButton)
int IndexInGrid = - 1;

UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = UINavButton)
UPROPERTY(BlueprintReadOnly, Category = UINavButton)
UUINavComponent* NavComp = nullptr;

EButtonStyle CurrentStyle = EButtonStyle::Normal;
Expand Down
2 changes: 1 addition & 1 deletion Source/UINavigation/Public/UINavHorizontalComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class UINAVIGATION_API UUINavHorizontalComponent : public UUINavComponent
virtual void UpdateTextToIndex(int NewIndex);
//Changes the text displayed in the NavText element
UFUNCTION(BlueprintCallable, Category = UINavComponentBox)
void ChangeText(FText NewText);
void ChangeText(const FText NewText);

UFUNCTION(BlueprintCallable, Category = UINavComponentBox)
virtual FORCEINLINE int GetMaxOptionIndex() const { return 0; }
Expand Down
2 changes: 1 addition & 1 deletion Source/UINavigation/Public/UINavOptionBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ class UINAVIGATION_API UUINavOptionBox : public UUINavComponentBox
TArray<FText> StringOptions;

UFUNCTION(BlueprintCallable, BlueprintPure, Category = UINavOptionBox)
FORCEINLINE FText GetCurrentString() const { return StringOptions[OptionIndex]; }
FORCEINLINE FText GetCurrentString() const { return StringOptions.IsValidIndex(OptionIndex) ? StringOptions[OptionIndex] : FText(); }

};
2 changes: 2 additions & 0 deletions Source/UINavigation/Public/UINavPCComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ class UINAVIGATION_API UUINavPCComponent : public UActorComponent

void CallCustomInput(const FName ActionName, const bool bPressed);

UFUNCTION()
void OnControllerConnectionChanged(bool bConnected, int32 UserId, int32 UserIndex);

public:

Expand Down
7 changes: 7 additions & 0 deletions Source/UINavigation/Public/UINavPCReceiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ class UINAVIGATION_API IUINavPCReceiver
void OnInputChanged(EInputType From, EInputType To);
virtual void OnInputChanged_Implementation(EInputType From, EInputType To);

/**
* Called when a controller is connected and disconnected
*/
UFUNCTION(BlueprintNativeEvent, Category = UINavController)
void OnControllerConnectionChanged(bool bConnected, int32 UserId, int32 UserIndex);
virtual void OnControllerConnectionChanged_Implementation(bool bConnected, int32 UserId, int32 UserIndex);

/**
* Called when the active widget changes
*
Expand Down
4 changes: 1 addition & 3 deletions Source/UINavigation/Public/UINavSlider.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019 Gonçalo Marques - All Rights Reserved
// Copyright (C) 2019 Gonçalo Marques - All Rights Reserved

#pragma once

Expand All @@ -21,8 +21,6 @@ class UINAVIGATION_API UUINavSlider : public UUINavHorizontalComponent
UPROPERTY(BlueprintReadWrite, Category = UINavSlider, meta = (BindWidget, OptionalWidget = true))
class USpinBox* NavSpinBox;

bool bIgnoreSpinBoxCommit = false;

UFUNCTION()
void HandleOnSliderValueChanged(const float InValue);
UFUNCTION()
Expand Down
Loading

0 comments on commit ca895dc

Please sign in to comment.