// Copyright Epic Games, Inc. All Rights Reserved. #pragma once #include "Containers/Array.h" #include "CoreMinimal.h" #include "Delegates/Delegate.h" #include "HAL/Platform.h" #include "Internationalization/Text.h" #include "Templates/SharedPointer.h" class SGameMenuItemWidget; namespace EGameMenuItemType { enum Type { Root, Standard, MultiChoice, CustomWidget, }; }; class FGameMenuItem : public TSharedFromThis { public: /** confirm menu item delegate */ DECLARE_DELEGATE(FOnConfirmMenuItem); /** multi-choice option changed, parameters are menu item itself and new multi-choice index */ DECLARE_DELEGATE_TwoParams(FOnOptionChanged, TSharedPtr, int32); /** delegate, which is executed by SSimpleMenuWidget if user confirms this menu item */ FOnConfirmMenuItem OnConfirmMenuItem; /** multi-choice option changed, parameters are menu item itself and new multi-choice index */ FOnOptionChanged OnOptionChanged; /** menu item type */ EGameMenuItemType::Type MenuItemType; /** menu item text */ FText Text; /** sub menu if present */ TSharedPtr SubMenu; /** shared pointer to actual slate widget representing the menu item */ TSharedPtr Widget; /** shared pointer to actual slate widget representing the custom menu item, ie whole options screen */ TSharedPtr CustomWidget; /** texts for multiple choice menu item (like INF AMMO ON/OFF or difficulty/resolution etc) */ TArray MultiChoice; /** set to other value than -1 to limit the options range */ int32 MinMultiChoiceIndex; /** set to other value than -1 to limit the options range */ int32 MaxMultiChoiceIndex; /** selected multi-choice index for this menu item */ int32 SelectedMultiChoice; /** true if this item is active */ bool bInactive; /** constructor accepting menu item text */ FGameMenuItem(FText _text) { Text = _text; MenuItemType = EGameMenuItemType::Standard; MinMultiChoiceIndex = MaxMultiChoiceIndex = SelectedMultiChoice = 0; bInactive = false; } /** custom widgets cannot contain sub menus, all functionality must be handled by custom widget itself */ FGameMenuItem(TSharedPtr InWidget) { MenuItemType = EGameMenuItemType::CustomWidget; CustomWidget = InWidget; MinMultiChoiceIndex = MaxMultiChoiceIndex = SelectedMultiChoice = 0; bInactive = false; } /** constructor for multi-choice item */ FGameMenuItem(FText InText, TArray InOptions, int32 InDefaultIndex=0) { Text = InText; MenuItemType = EGameMenuItemType::MultiChoice; MultiChoice = InOptions; MinMultiChoiceIndex = MaxMultiChoiceIndex = -1; SelectedMultiChoice = InDefaultIndex; bInactive = false; } bool ConfirmPressed() { bool bHandled = false; if ( (bInactive == false ) && (OnConfirmMenuItem.IsBound() == true ) ) { OnConfirmMenuItem.Execute(); bHandled = true; } return bHandled; } /** create special root item */ static TSharedRef CreateRoot() { return MakeShareable(new FGameMenuItem()); } private: FGameMenuItem() { MenuItemType = EGameMenuItemType::Root; } };