Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Fill out your copyright notice in the Description page of Project Settings.
- #pragma once
- #include "UObject/NoExportTypes.h"
- #include "Base/PTickable.h"
- #include "Character/ProjectPlayerController.h"
- #include "UISystem.generated.h"
- enum class ENavigationType : uint8;
- UENUM(BlueprintType)
- enum class EUserInput : uint8
- {
- UI UMETA(DisplayName = "User Interface"),
- GAME UMETA(DisplayName = "Game"),
- };
- struct FKeyScale
- {
- FKey Key;
- float Scale;
- FKeyScale(FKey _Key, float _Scale)
- {
- Key = _Key;
- Scale = _Scale;
- }
- };
- /**
- *
- */
- UCLASS()
- class PROJECT_API AUISystem : public AActor
- {
- GENERATED_BODY()
- public:
- AUISystem();
- virtual void PostInitializeComponents() override;
- virtual void BeginPlay() override;
- virtual void Tick(float DeltaTime) override;
- static EUserInput GetUserInput();
- static void SetUserInput(EUserInput InputType);
- static int32 RegisterNavigatable(class UNavigatable* Navigatable);
- static void UnregisterNavigatable(class UNavigatable* Navigatable);
- static int32 RegisterInventory(class UInventory* Inventory);
- static void UnregisterInventory(class UInventory* Inventory);
- static bool IsGamepadDragging();
- template<typename UserClass>
- static void BindUIInputAction(FName ActionName, EInputEvent InputEvent, UserClass* Object, typename FInputActionHandlerSignature::TUObjectMethodDelegate<UserClass>::FMethodPtr FuncPtr)
- {
- if (ActiveSystem)
- {
- if (AProjectPlayerController* ProjectPlayerCtrl = Cast<AProjectPlayerController>(ActiveSystem->GetWorld()->GetFirstPlayerController()))
- {
- ProjectPlayerCtrl->BindUIInputAction<UserClass>(ActionName, InputEvent, Object, FuncPtr);
- }
- else
- {
- P_SCREEN_ERROR_T("Failed binding " + ActionName.ToString() + " to" + Object->GetName() + "because PlayerController is unavailable", 10.0f);
- }
- }
- else
- {
- P_SCREEN_ERROR_T("Failed binding " + ActionName.ToString() + " to" + Object->GetName() + " because ActiveSystem is currently nullptr", 10.0f);
- }
- }
- template<typename UserClass>
- static void BindUIInputAxis(FName AxisName, UserClass* Object, typename FInputAxisHandlerSignature::TUObjectMethodDelegate<UserClass>::FMethodPtr FuncPtr);
- UFUNCTION()
- void ItemDragged(UDragDropOperation* Operation);
- UFUNCTION()
- void ItemDragCancelled(UDragDropOperation* Operation);
- static AUISystem* GetInstance()
- {
- return ActiveSystem;
- }
- static void InventoryItemDragEnter(UDragDropOperation*& Operation);
- static void InventoryItemGamepadDragEnter(class UDragableWidget* Widget);
- static bool HandleGamepadDrop(class UDragableWidget* DWidget);
- static void Clean();
- static void SetUserFocus(class UFocusableWidget* FocusThis);
- static void FocusLost(class UFocusableWidget* UnfocusThis);
- static void AddActionKeyMapping(FName ActionName, struct FKey Key);
- static void AddActionKeyMapping(FName ActionName, TArray<struct FKey> Keys);
- static void AddAxisKeyMapping(FName AxisName, struct FKeyScale Key);
- static void AddAxisKeyMapping(FName AxisName, TArray<struct FKeyScale> Keys);
- static void RegisterBinder(class UISystemInputBinder* Binder);
- static void UnregisterBinder(class UISystemInputBinder* Binder);
- static bool FocusNavigatable(class UNavigatable* Navigatable);
- static ENavigationType LastNavigationInput() { return ActiveSystem->LastNavigation; }
- protected:
- void Navigate(ENavigationType Type);
- void NavigateUp();
- void NavigateDown();
- void NavigateRight();
- void NavigateLeft();
- void UIInteraction();
- bool HandleSideOfNavigatableReached(class UNavigatable* Navigatable, ENavigationType NavigationType);
- static void RegisterBindings();
- private:
- class UNavigatable* DetermineBestNavigatable(const FVector2D& Position, ENavigationType Type);
- void SetNewFocus(class UNavigatable* Navigatable);
- UPROPERTY()
- class UNavigatable* CurrentFocusedNavigatable;
- TArray<class UNavigatable*> NavigatableUserWidgets;
- TArray<class UInventory*> CurrentActiveInventories;
- ENavigationType LastNavigation;
- EUserInput CurrentInputType;
- bool bItemDragged;
- //---------------------------------------------------------------------------------------------------------------------
- //UPROPERTY() <----- This UPROPERTY() Macro should cause the crash
- class UFocusableWidget* CurrentlyFocusedWidget;
- //---------------------------------------------------------------------------------------------------------------------
- static AUISystem* ActiveSystem;
- static bool bInitialized;
- static TArray<class UISystemInputBinder*> BinderArray;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement