// Copyright Epic Games, Inc. All Rights Reserved. #pragma once #include "CoreMinimal.h" #include "SlateFwd.h" #include "Misc/Attribute.h" #include "InputCoreTypes.h" #include "Types/SlateStructs.h" #include "Fonts/SlateFontInfo.h" #include "Widgets/DeclarativeSyntaxSupport.h" #include "Widgets/SWidget.h" #include "Widgets/SCompoundWidget.h" #include "Widgets/Input/SButton.h" #include "Widgets/Views/STableViewBase.h" #include "Widgets/Views/STableRow.h" #include "Widgets/Views/STreeView.h" #include "EditorStyleSet.h" class FKeyTreeInfo; class SComboButton; DECLARE_DELEGATE_OneParam(FOnKeyChanged, TSharedPtr) ////////////////////////////////////////////////////////////////////////// // SKeySelector typedef TSharedPtr FKeyTreeItem; typedef STreeView SKeyTreeView; /** Widget for selecting an input key */ class UNREALED_API SKeySelector: public SCompoundWidget { public: SLATE_BEGIN_ARGS(SKeySelector) : _CurrentKey(FKey()), _TreeViewWidth(300.f), _TreeViewHeight(400.f), _Font(FEditorStyle::GetFontStyle(TEXT("NormalFont"))), _FilterBlueprintBindable(true), _AllowClear(true) {} SLATE_ATTRIBUTE(TOptional, CurrentKey) SLATE_ATTRIBUTE(FOptionalSize, TreeViewWidth) SLATE_ATTRIBUTE(FOptionalSize, TreeViewHeight) SLATE_EVENT(FOnKeyChanged, OnKeyChanged) SLATE_ATTRIBUTE(FSlateFontInfo, Font) SLATE_ARGUMENT(bool, FilterBlueprintBindable) SLATE_ARGUMENT(bool, AllowClear) SLATE_END_ARGS() public: void Construct(const FArguments& InArgs); protected: /** Gets the icon for the key being manipulated */ const FSlateBrush* GetKeyIconImage() const; /** Toggles the icon's color when in listen mode */ FSlateColor GetKeyIconColor() const; /** Gets a succinct description for the key being manipulated */ FText GetKeyDescription() const; /** Gets a tooltip for the selected key */ FText GetKeyTooltip() const; /** Treeview support functions */ virtual TSharedRef GenerateKeyTreeRow(FKeyTreeItem InItem, const TSharedRef& OwnerTree); void OnKeySelectionChanged(FKeyTreeItem Selection, ESelectInfo::Type SelectInfo); void GetKeyChildren(FKeyTreeItem InItem, TArray& OutChildren); /** Gets the Menu Content, setting it up if necessary */ virtual TSharedRef GetMenuContent(); /** Key searching support */ void OnFilterTextChanged(const FText& NewText); void OnFilterTextCommitted(const FText& NewText, ETextCommit::Type CommitInfo); void GetSearchTokens(const FString& SearchString, TArray& OutTokens) const; /** Helper to generate the filtered list of keys, based on the search string matching */ bool GetChildrenMatchingSearch(const TArray& SearchTokens, const TArray& UnfilteredList, TArray& OutFilteredList); /** Start listening for the next key press */ FReply ListenForInput(); /** Assigns the heard input as the current key */ FReply ProcessHeardInput(FKey KeyHeard); virtual bool SupportsKeyboardFocus() const override { return bListenForNextInput; } /** Input listeners */ virtual FReply OnKeyDown(const FGeometry& MyGeometry, const FKeyEvent& InKeyEvent) override; virtual FReply OnMouseButtonDown(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override; virtual FReply OnMouseWheel(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override; virtual FReply OnMouseMove(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override; virtual FReply OnAnalogValueChanged(const FGeometry& MyGeometry, const FAnalogInputEvent& InAnalogInputEvent) override; /** * Determine the best icon to represent the given key. * * @param Key The key to get the icon for. * @param returns a brush that best represents the icon */ const FSlateBrush* GetIconFromKey(FKey Key) const; protected: /** Combo Button that shows current key and icon */ TSharedPtr KeyComboButton; /** Reference to the menu content that's displayed when the key button is clicked on */ TSharedPtr MenuContent; TSharedPtr FilterTextBox; TSharedPtr KeyTreeView; FText SearchText; /** The key attribute that we're modifying with this widget, or an empty optional if the key contains multiple values */ TAttribute> CurrentKey; /** Delegate that is called every time the key changes. */ FOnKeyChanged OnKeyChanged; /** Desired width of the tree view widget */ TAttribute TreeViewWidth; /** Desired height of the tree view widget */ TAttribute TreeViewHeight; /** Font used for category tree entries */ FSlateFontInfo CategoryFont; /** Font used for key tree entries */ FSlateFontInfo KeyFont; /** Array containing the unfiltered list of all values this key could possibly have */ TArray KeyTreeRoot; /** Array containing a filtered list, according to the text in the searchbox */ TArray FilteredKeyTreeRoot; bool bListenForNextInput = false; };