File size: 7,496 Bytes
4331f83 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | // Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CommonUserWidget.h"
#include "Fonts/SlateFontInfo.h"
#include "CommonPlayerInputKey.generated.h"
#define UE_API COMMONGAME_API
enum class ECommonInputType : uint8;
class APlayerController;
class FPaintArgs;
class FSlateRect;
class FSlateWindowElementList;
class FWidgetStyle;
class UCommonLocalPlayer;
class UMaterialInstanceDynamic;
class UObject;
struct FFrame;
struct FGeometry;
UENUM(BlueprintType)
enum class ECommonKeybindForcedHoldStatus : uint8
{
NoForcedHold,
ForcedHold,
NeverShowHold
};
USTRUCT()
struct FMeasuredText
{
GENERATED_BODY()
public:
FText GetText() const { return CachedText; }
void SetText(const FText& InText);
FVector2D GetTextSize() const { return CachedTextSize; }
FVector2D UpdateTextSize(const FSlateFontInfo &InFontInfo, float FontScale = 1.0f) const;
private:
FText CachedText;
mutable FVector2D CachedTextSize;
mutable bool bTextDirty = true;
};
UCLASS(MinimalAPI, Abstract, BlueprintType, Blueprintable, meta = (DisableNativeTick))
class UCommonPlayerInputKey : public UCommonUserWidget
{
GENERATED_BODY()
public:
UE_API UCommonPlayerInputKey(const FObjectInitializer& ObjectInitializer);
/** Update the key and associated display based on our current Boundaction */
UFUNCTION(BlueprintCallable, Category = "Keybind Widget")
UE_API void UpdateKeybindWidget();
/** Set the bound key for our keybind */
UFUNCTION(BlueprintCallable, Category = "Keybind Widget")
UE_API void SetBoundKey(FKey NewBoundAction);
/** Set the bound action for our keybind */
UFUNCTION(BlueprintCallable, Category = "Keybind Widget")
UE_API void SetBoundAction(FName NewBoundAction);
/** Force this keybind to be a hold keybind */
UFUNCTION(BlueprintCallable, Category = "Keybind Widget")
UE_API void SetForcedHoldKeybindStatus(ECommonKeybindForcedHoldStatus InForcedHoldKeybindStatus);
/** Force this keybind to be a hold keybind */
UFUNCTION(BlueprintCallable, Category = "Keybind Widget")
UE_API void SetShowProgressCountDown(bool bShow);
/** Set the axis scale value for this keybind */
UFUNCTION(BlueprintCallable, Category = "Keybind Widget")
void SetAxisScale(const float NewValue) { AxisScale = NewValue; }
/** Set the preset name override value for this keybind. */
UFUNCTION(BlueprintCallable, Category = "Keybind Widget")
void SetPresetNameOverride(const FName NewValue) { PresetNameOverride = NewValue; }
/** Our current BoundAction */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Keybind Widget")
FName BoundAction;
/** Scale to read when using an axis Mapping */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Keybind Widget")
float AxisScale;
/** Key this widget is bound to set directly in blueprint. Used when we want to reference a specific key instead of an action. */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Keybind Widget")
FKey BoundKeyFallback;
/** Allows us to set the input type explicitly for the keybind widget. */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Keybind Widget")
ECommonInputType InputTypeOverride;
/** Allows us to set the preset name explicitly for the keybind widget. */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Keybind Widget")
FName PresetNameOverride;
/** Setting that can show this keybind as a hold or never show it as a hold (even if it is) */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Keybind Widget")
ECommonKeybindForcedHoldStatus ForcedHoldKeybindStatus;
/** Called through a delegate when we start hold progress */
UFUNCTION()
UE_API void StartHoldProgress(FName HoldActionName, float HoldDuration);
/** Called through a delegate when we stop hold progress */
UFUNCTION()
UE_API void StopHoldProgress(FName HoldActionName, bool bCompletedSuccessfully);
/** Get whether this keybind is a hold action. */
UFUNCTION(BlueprintCallable, Category = "Keybind Widget")
bool IsHoldKeybind() const { return bIsHoldKeybind; }
UFUNCTION()
bool IsBoundKeyValid() const { return BoundKey.IsValid(); }
protected:
UE_API virtual void NativePreConstruct() override;
UE_API virtual void NativeConstruct() override;
UE_API virtual int32 NativePaint(const FPaintArgs& Args, const FGeometry& AllottedGeometry, const FSlateRect& MyCullingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled) const override;
UE_API void RecalculateDesiredSize();
/** Overridden to destroy our MID */
UE_API virtual void NativeDestruct() override;
/** Whether or not this keybind widget is currently set to be a hold keybind */
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Keybind Widget", meta=(ScriptName = "IsHoldKeybindValue"))
bool bIsHoldKeybind;
/** */
UPROPERTY(Transient)
bool bShowKeybindBorder;
UPROPERTY(Transient)
FVector2D FrameSize;
UPROPERTY(BlueprintReadOnly, Category = "Keybind Widget")
bool bShowTimeCountDown;
/** Derived Key this widget is bound to */
UPROPERTY(BlueprintReadOnly, Category = "Keybind Widget")
FKey BoundKey;
/** Material for showing Progress */
UPROPERTY(EditDefaultsOnly, Category = "Keybind Widget")
FSlateBrush HoldProgressBrush;
/** The key bind text border. */
UPROPERTY(EditDefaultsOnly, Category = "Keybind Widget")
FSlateBrush KeyBindTextBorder;
/** Should this keybinding widget display information that it is currently unbound? */
UPROPERTY(EditAnywhere, Category = "Keybind Widget")
bool bShowUnboundStatus = false;
/** The font to apply at each size */
UPROPERTY(EditDefaultsOnly, Category = "Font")
FSlateFontInfo KeyBindTextFont;
/** The font to apply at each size */
UPROPERTY(EditDefaultsOnly, Category = "Font")
FSlateFontInfo CountdownTextFont;
UPROPERTY(Transient)
FMeasuredText CountdownText;
UPROPERTY(Transient)
FMeasuredText KeybindText;
UPROPERTY(Transient)
FMargin KeybindTextPadding;
UPROPERTY(Transient)
FVector2D KeybindFrameMinimumSize;
/** The material parameter name for hold percentage in the HoldKeybindImage */
UPROPERTY(EditDefaultsOnly, Category = "Keybind Widget")
FName PercentageMaterialParameterName;
/** MID for the progress percentage */
UPROPERTY(Transient)
TObjectPtr<UMaterialInstanceDynamic> ProgressPercentageMID;
UE_API virtual void NativeOnInitialized() override;
private:
/**
* Synchronizes the hold progress to whatever is currently set in the
* owning player controller.
*/
UE_API void SyncHoldProgress();
/** Called for updating the HoldKeybindImage during a hold keybind */
UE_API void UpdateHoldProgress();
/** Called when we want to set up this keybind widget as a hold keybind */
UE_API void SetupHoldKeybind();
UE_API void ShowHoldBackPlate();
UE_API void HandlePlayerControllerSet(UCommonLocalPlayer* LocalPlayer, APlayerController* PlayerController);
/** Time when we started using a hold keybind */
float HoldKeybindStartTime = 0;
/** How long, in seconds, we will be doing a hold keybind */
float HoldKeybindDuration = 0;
bool bDrawProgress = false;
bool bDrawBrushForKey = false;
bool bDrawCountdownText = false;
bool bWaitingForPlayerController = false;
UPROPERTY(Transient)
FSlateBrush CachedKeyBrush;
};
#undef UE_API
|