Advertisement
Guest User

Untitled

a guest
May 20th, 2017
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.55 KB | None | 0 0
  1. // Fill out your copyright notice in the Description page of Project Settings.
  2.  
  3. #pragma once
  4.  
  5. #include "UObject/NoExportTypes.h"
  6. #include "Base/PTickable.h"
  7. #include "Character/ProjectPlayerController.h"
  8. #include "UISystem.generated.h"
  9.  
  10. enum class ENavigationType : uint8;
  11.  
  12. UENUM(BlueprintType)
  13. enum class EUserInput : uint8
  14. {
  15.     UI          UMETA(DisplayName = "User Interface"),
  16.     GAME        UMETA(DisplayName = "Game"),
  17. };
  18.  
  19. struct FKeyScale
  20. {
  21.     FKey Key;
  22.     float Scale;
  23.  
  24.     FKeyScale(FKey _Key, float _Scale)
  25.     {
  26.         Key = _Key;
  27.         Scale = _Scale;
  28.     }
  29. };
  30.  
  31.  
  32. /**
  33.  *
  34.  */
  35. UCLASS()
  36. class PROJECT_API AUISystem : public AActor
  37. {
  38.     GENERATED_BODY()
  39.  
  40. public:
  41.     AUISystem();
  42.  
  43.     virtual void PostInitializeComponents() override;
  44.  
  45.     virtual void BeginPlay() override;
  46.     virtual void Tick(float DeltaTime) override;
  47.  
  48.     static EUserInput GetUserInput();
  49.     static void SetUserInput(EUserInput InputType);
  50.    
  51.     static int32 RegisterNavigatable(class UNavigatable* Navigatable);
  52.     static void UnregisterNavigatable(class UNavigatable* Navigatable);
  53.  
  54.     static int32 RegisterInventory(class UInventory* Inventory);
  55.     static void UnregisterInventory(class UInventory* Inventory);
  56.  
  57.     static bool IsGamepadDragging();
  58.  
  59.     template<typename UserClass>
  60.     static void BindUIInputAction(FName ActionName, EInputEvent InputEvent, UserClass* Object, typename FInputActionHandlerSignature::TUObjectMethodDelegate<UserClass>::FMethodPtr FuncPtr)
  61.     {
  62.         if (ActiveSystem)
  63.         {
  64.             if (AProjectPlayerController* ProjectPlayerCtrl = Cast<AProjectPlayerController>(ActiveSystem->GetWorld()->GetFirstPlayerController()))
  65.             {
  66.                 ProjectPlayerCtrl->BindUIInputAction<UserClass>(ActionName, InputEvent, Object, FuncPtr);
  67.             }
  68.             else
  69.             {
  70.                 P_SCREEN_ERROR_T("Failed binding " + ActionName.ToString() + " to" + Object->GetName() + "because PlayerController is unavailable", 10.0f);
  71.             }
  72.         }
  73.         else
  74.         {
  75.             P_SCREEN_ERROR_T("Failed binding " + ActionName.ToString() + " to" + Object->GetName() + " because ActiveSystem is currently nullptr", 10.0f);
  76.         }
  77.     }
  78.  
  79.     template<typename UserClass>
  80.     static void BindUIInputAxis(FName AxisName, UserClass* Object, typename FInputAxisHandlerSignature::TUObjectMethodDelegate<UserClass>::FMethodPtr FuncPtr);
  81.  
  82.  
  83.     UFUNCTION()
  84.     void ItemDragged(UDragDropOperation* Operation);
  85.  
  86.     UFUNCTION()
  87.     void ItemDragCancelled(UDragDropOperation* Operation);
  88.  
  89.     static AUISystem* GetInstance()
  90.     {
  91.         return ActiveSystem;
  92.     }
  93.  
  94.     static void InventoryItemDragEnter(UDragDropOperation*& Operation);
  95.     static void InventoryItemGamepadDragEnter(class UDragableWidget* Widget);
  96.  
  97.     static bool HandleGamepadDrop(class UDragableWidget* DWidget);
  98.  
  99.     static void Clean();
  100.  
  101.     static void SetUserFocus(class UFocusableWidget* FocusThis);
  102.     static void FocusLost(class UFocusableWidget* UnfocusThis);
  103.  
  104.     static void AddActionKeyMapping(FName ActionName, struct FKey Key);
  105.     static void AddActionKeyMapping(FName ActionName, TArray<struct FKey> Keys);
  106.  
  107.     static void AddAxisKeyMapping(FName AxisName, struct FKeyScale Key);
  108.     static void AddAxisKeyMapping(FName AxisName, TArray<struct FKeyScale> Keys);
  109.  
  110.     static void RegisterBinder(class UISystemInputBinder* Binder);
  111.     static void UnregisterBinder(class UISystemInputBinder* Binder);
  112.  
  113.     static bool FocusNavigatable(class UNavigatable* Navigatable);
  114.  
  115.     static ENavigationType LastNavigationInput() { return ActiveSystem->LastNavigation; }
  116.  
  117. protected:
  118.     void Navigate(ENavigationType Type);
  119.  
  120.     void NavigateUp();
  121.     void NavigateDown();
  122.     void NavigateRight();
  123.     void NavigateLeft();
  124.  
  125.     void UIInteraction();
  126.  
  127.     bool HandleSideOfNavigatableReached(class UNavigatable* Navigatable, ENavigationType NavigationType);
  128.  
  129.     static void RegisterBindings();
  130.  
  131. private:
  132.     class UNavigatable* DetermineBestNavigatable(const FVector2D& Position, ENavigationType Type);
  133.     void SetNewFocus(class UNavigatable* Navigatable);
  134.  
  135.  
  136.     UPROPERTY()
  137.     class UNavigatable* CurrentFocusedNavigatable;
  138.  
  139.     TArray<class UNavigatable*> NavigatableUserWidgets;
  140.     TArray<class UInventory*> CurrentActiveInventories;
  141.  
  142.     ENavigationType LastNavigation;
  143.     EUserInput CurrentInputType;
  144.  
  145.     bool bItemDragged;
  146.  
  147.  
  148.     //---------------------------------------------------------------------------------------------------------------------
  149.     //UPROPERTY()    <----- This UPROPERTY() Macro should cause the crash
  150.     class UFocusableWidget* CurrentlyFocusedWidget;
  151.     //---------------------------------------------------------------------------------------------------------------------
  152.  
  153.    
  154.     static AUISystem* ActiveSystem;
  155.     static bool bInitialized;
  156.  
  157.     static TArray<class UISystemInputBinder*> BinderArray;
  158. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement