├── .gitignore
├── README.md
└── SlateTutorials
├── Build
└── Receipts
│ └── SlateTutorialsEditor-Win64-Development.target.xml
├── Config
├── DefaultEditor.ini
├── DefaultEngine.ini
└── DefaultGame.ini
├── Content
└── UI
│ ├── Font
│ └── Roboto-Regular.uasset
│ └── Styles
│ ├── Global.uasset
│ ├── NewSlateWidgetStyleAsset.uasset
│ ├── buttonLong_blue.uasset
│ ├── buttonLong_brown.uasset
│ └── buttonLong_grey.uasset
├── SlateTutorials.uproject
└── Source
├── SlateTutorials.Target.cs
├── SlateTutorials
├── GlobalMenuStyle.cpp
├── GlobalMenuStyle.h
├── MainMenuHUD.cpp
├── MainMenuHUD.h
├── MainMenuUI.cpp
├── MainMenuUI.h
├── MenuStyles.cpp
├── MenuStyles.h
├── SlateTutorials.Build.cs
├── SlateTutorials.cpp
├── SlateTutorials.h
├── TutGameMode.cpp
├── TutGameMode.h
├── TutorialCharacter.cpp
├── TutorialCharacter.h
├── TutorialGameHUD.cpp
├── TutorialGameHUD.h
├── TutorialGameHUDUI.cpp
├── TutorialGameHUDUI.h
├── WidgetGameMode.cpp
└── WidgetGameMode.h
└── SlateTutorialsEditor.Target.cs
/.gitignore:
--------------------------------------------------------------------------------
1 | #
2 | # This file tells Git about engine files that never really belong in source control. They are usually build products, log
3 | # files and intermediate files generated from a compiler or the engine runtime.
4 | #
5 | #
6 | # NOTE:
7 | # Paths that start with / match paths relative to the root (where the .gitignore file is)
8 | # Paths that end with / will match a folder and all files under it (but not a regular file with no extension)
9 | # Use * for wildcards. Wildcards stop at path separators
10 | # Use ** for a wildcard that spans path separators
11 | # Paths in this file should use forward slash characters, not back slashes
12 | # Use \ to escape special characters like ! and #
13 | # Use ! to negate a previous pattern. But it doesn't work if the parent sub-folder was masked out already.
14 | #
15 |
16 |
17 | # Ignore project files in the root
18 | /*.sln
19 | /*.xcodeproj
20 | /*/*.sln
21 | /*/*.xcodeproj
22 |
23 | # Ignore local user Visual Studio files in any folder
24 | *.suo
25 | *.opensdf
26 | *.sdf
27 | *.opendb
28 |
29 | # Standard binary files
30 | *.lib
31 | *.idb
32 | *.a
33 | *.dll
34 | *.exe
35 | *.png
36 | *.bz2
37 | *.psd
38 | *.gif
39 | *.zip
40 | *.tga
41 | *.dylib
42 | *.gz
43 | *.so
44 | *.jar
45 | *.mp4
46 | *.pak
47 | *.bmp
48 | *.obj
49 | *.pdb
50 | **/*.framework/**
51 |
52 | # Derived data cache is never checked in
53 | /*/DerivedDataCache/**
54 |
55 | # Engine intermediates
56 | /*/Intermediate/**
57 | /*/Plugins/**/Intermediate/**
58 |
59 | /*/Binaries/**
60 | /*/Plugins/**/Binaries/**
61 |
62 | # Ignore any saved local files
63 | /*/Saved/**
64 |
65 | # Other binaries
66 | /SlateTutorials/.vs/**
67 | /SlateTutorials/Binaries/**
68 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SlateTutorials
2 | A simple Unreal Engine 4 Slate UI tutorials.
3 |
4 | [Part 1: Introduction & Basic Menu](https://wiki.unrealengine.com/Slate_Introduction_%E2%80%92_Basic_Menu_Part_1)
5 |
6 | [Part 2: Style Sets](https://wiki.unrealengine.com/Slate_Style_Sets_Part_2)
7 |
8 | [Part 3: Data Binding](https://wiki.unrealengine.com/Slate_Data_Binding_Part_3)
9 |
--------------------------------------------------------------------------------
/SlateTutorials/Build/Receipts/SlateTutorialsEditor-Win64-Development.target.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | true
17 |
--------------------------------------------------------------------------------
/SlateTutorials/Config/DefaultEditor.ini:
--------------------------------------------------------------------------------
1 | [EditoronlyBP]
2 | bAllowClassAndBlueprintPinMatching=true
3 | bReplaceBlueprintWithClass=true
4 | bDontLoadBlueprintOutsideEditor=true
5 | bBlueprintIsNotBlueprintType=true
6 |
--------------------------------------------------------------------------------
/SlateTutorials/Config/DefaultEngine.ini:
--------------------------------------------------------------------------------
1 | [URL]
2 | [/Script/Engine.UserInterfaceSettings]
3 | RenderFocusRule=NavigationOnly
4 | DefaultCursor=None
5 | TextEditBeamCursor=None
6 | CrosshairsCursor=None
7 | GrabHandCursor=None
8 | GrabHandClosedCursor=None
9 | SlashedCircleCursor=None
10 | ApplicationScale=1.000000
11 | UIScaleRule=ShortestSide
12 | CustomScalingRuleClass=None
13 | UIScaleCurve=(EditorCurveData=(PreInfinityExtrap=RCCE_Constant,PostInfinityExtrap=RCCE_Constant,Keys=((Time=480.000000,Value=0.444000),(Time=720.000000,Value=0.666000),(Time=1080.000000,Value=1.000000),(Time=8640.000000,Value=8.000000)),DefaultValue=340282346638528859811704183484516925440.000000),ExternalCurve=None)
14 |
15 | [/Script/Engine.RendererSettings]
16 | r.MobileHDR=True
17 | r.MobileNumDynamicPointLights=4
18 | r.MobileDynamicPointLightsUseStaticBranch=True
19 | r.AllowOcclusionQueries=True
20 | r.MinScreenRadiusForLights=0.030000
21 | r.MinScreenRadiusForDepthPrepass=0.030000
22 | r.PrecomputedVisibilityWarning=False
23 | r.TextureStreaming=True
24 | Compat.UseDXT5NormalMaps=False
25 | r.AllowStaticLighting=True
26 | r.NormalMapsForStaticLighting=False
27 | r.GenerateMeshDistanceFields=False
28 | r.GenerateLandscapeGIData=True
29 | r.TessellationAdaptivePixelsPerTriangle=48.000000
30 | r.SeparateTranslucency=True
31 | r.TranslucentSortPolicy=0
32 | TranslucentSortAxis=(X=0.000000,Y=-1.000000,Z=0.000000)
33 | r.CustomDepth=1
34 | r.DefaultFeature.Bloom=True
35 | r.DefaultFeature.AmbientOcclusion=True
36 | r.DefaultFeature.AmbientOcclusionStaticFraction=True
37 | r.DefaultFeature.AutoExposure=False
38 | r.DefaultFeature.MotionBlur=False
39 | r.DefaultFeature.LensFlare=True
40 | r.DefaultFeature.AntiAliasing=0
41 | r.EarlyZPass=3
42 | r.EarlyZPassMovable=False
43 | r.DBuffer=False
44 | r.ClearSceneMethod=1
45 | r.BasePassOutputsVelocity=False
46 | r.WireframeCullThreshold=5.000000
47 | UIScaleRule=ShortestSide
48 | UIScaleCurve=(EditorCurveData=(PreInfinityExtrap=RCCE_Constant,PostInfinityExtrap=RCCE_Constant,Keys=,DefaultValue=340282346638528859811704183484516925440.000000),ExternalCurve=None)
49 |
50 | [/Script/HardwareTargeting.HardwareTargetingSettings]
51 | TargetedHardwareClass=Desktop
52 | AppliedTargetedHardwareClass=Desktop
53 | DefaultGraphicsPerformance=Scalable
54 | AppliedDefaultGraphicsPerformance=Scalable
55 |
56 | [/Script/EngineSettings.GameMapsSettings]
57 | GlobalDefaultGameMode=/Script/SlateTutorials.TutGameMode
58 |
59 |
--------------------------------------------------------------------------------
/SlateTutorials/Config/DefaultGame.ini:
--------------------------------------------------------------------------------
1 | [/Script/EngineSettings.GeneralProjectSettings]
2 | ProjectID=61B698FE4C79C04B4581759E20ED4A76
3 |
--------------------------------------------------------------------------------
/SlateTutorials/Content/UI/Font/Roboto-Regular.uasset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/henrya2/SlateTutorials/abd5e86f0e8e717eb33d6e2e12151756dfb4e281/SlateTutorials/Content/UI/Font/Roboto-Regular.uasset
--------------------------------------------------------------------------------
/SlateTutorials/Content/UI/Styles/Global.uasset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/henrya2/SlateTutorials/abd5e86f0e8e717eb33d6e2e12151756dfb4e281/SlateTutorials/Content/UI/Styles/Global.uasset
--------------------------------------------------------------------------------
/SlateTutorials/Content/UI/Styles/NewSlateWidgetStyleAsset.uasset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/henrya2/SlateTutorials/abd5e86f0e8e717eb33d6e2e12151756dfb4e281/SlateTutorials/Content/UI/Styles/NewSlateWidgetStyleAsset.uasset
--------------------------------------------------------------------------------
/SlateTutorials/Content/UI/Styles/buttonLong_blue.uasset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/henrya2/SlateTutorials/abd5e86f0e8e717eb33d6e2e12151756dfb4e281/SlateTutorials/Content/UI/Styles/buttonLong_blue.uasset
--------------------------------------------------------------------------------
/SlateTutorials/Content/UI/Styles/buttonLong_brown.uasset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/henrya2/SlateTutorials/abd5e86f0e8e717eb33d6e2e12151756dfb4e281/SlateTutorials/Content/UI/Styles/buttonLong_brown.uasset
--------------------------------------------------------------------------------
/SlateTutorials/Content/UI/Styles/buttonLong_grey.uasset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/henrya2/SlateTutorials/abd5e86f0e8e717eb33d6e2e12151756dfb4e281/SlateTutorials/Content/UI/Styles/buttonLong_grey.uasset
--------------------------------------------------------------------------------
/SlateTutorials/SlateTutorials.uproject:
--------------------------------------------------------------------------------
1 | {
2 | "FileVersion": 3,
3 | "EngineAssociation": "4.10",
4 | "Category": "",
5 | "Description": "",
6 | "Modules": [
7 | {
8 | "Name": "SlateTutorials",
9 | "Type": "Runtime",
10 | "LoadingPhase": "Default"
11 | }
12 | ]
13 | }
--------------------------------------------------------------------------------
/SlateTutorials/Source/SlateTutorials.Target.cs:
--------------------------------------------------------------------------------
1 | // Fill out your copyright notice in the Description page of Project Settings.
2 |
3 | using UnrealBuildTool;
4 | using System.Collections.Generic;
5 |
6 | public class SlateTutorialsTarget : TargetRules
7 | {
8 | public SlateTutorialsTarget(TargetInfo Target)
9 | {
10 | Type = TargetType.Game;
11 | }
12 |
13 | //
14 | // TargetRules interface.
15 | //
16 |
17 | public override void SetupBinaries(
18 | TargetInfo Target,
19 | ref List OutBuildBinaryConfigurations,
20 | ref List OutExtraModuleNames
21 | )
22 | {
23 | OutExtraModuleNames.AddRange( new string[] { "SlateTutorials" } );
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/SlateTutorials/Source/SlateTutorials/GlobalMenuStyle.cpp:
--------------------------------------------------------------------------------
1 | #include "SlateTutorials.h"
2 | #include "GlobalMenuStyle.h"
3 |
4 | void FGlobalStyle::GetResources(TArray & OutBrushes) const
5 | {
6 |
7 | }
8 |
9 | const FName FGlobalStyle::TypeName = TEXT("FGlobalStyle");
10 |
11 | const FName FGlobalStyle::GetTypeName() const
12 | {
13 | return TypeName;
14 | }
15 |
16 | const FGlobalStyle& FGlobalStyle::GetDefault()
17 | {
18 | static FGlobalStyle Default;
19 | return Default;
20 | }
21 |
--------------------------------------------------------------------------------
/SlateTutorials/Source/SlateTutorials/GlobalMenuStyle.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "SlateWidgetStyleContainerBase.h"
4 | #include "SlateWidgetStyle.h"
5 | #include "SlateBasics.h"
6 | #include "GlobalMenuStyle.generated.h"
7 |
8 | // Provide a group of global style settings for our game menus!
9 | USTRUCT(Blueprintable, BlueprintType)
10 | struct FGlobalStyle : public FSlateWidgetStyle
11 | {
12 | GENERATED_BODY()
13 | public:
14 | // Stores a list of Brushes we are using (we aren't using any) into OutBrushes.
15 | virtual void GetResources(TArray & OutBrushes) const override;
16 |
17 | // Stores the TypeName for our widget style.
18 | static const FName TypeName;
19 |
20 | // Retrieves the type name for our global style, which will be used by our Style Set to load the right file.
21 | virtual const FName GetTypeName() const override;
22 |
23 | // Allows us to set default values for our various styles.
24 | static const FGlobalStyle& GetDefault();
25 |
26 | // Style that define the appearance of all menu buttons
27 | UPROPERTY(EditAnywhere, Category = Appearance)
28 | FButtonStyle MenuButtonStyle;
29 |
30 | // Style that defines the text on all of our menu buttons.
31 | UPROPERTY(EditAnywhere, Category = Appearance)
32 | FTextBlockStyle MenuButtonTextStyle;
33 |
34 | // Style that defines the text for our menu title.
35 | UPROPERTY(EditAnywhere, Category = Appearance)
36 | FTextBlockStyle MenuTitleStyle;
37 | };
38 |
39 | UCLASS(HideCategories = Object, MinimalAPI)
40 | class UGlobalMenuStyle : public USlateWidgetStyleContainerBase
41 | {
42 | GENERATED_BODY()
43 | public:
44 | // This is our actual Style object.
45 | UPROPERTY(EditAnywhere, Category = Appearance, meta = (ShowOnlyInnerProperties))
46 | FGlobalStyle MenuStyle;
47 |
48 | // Retrieve the style that this container manages.
49 | virtual const struct FSlateWidgetStyle* const GetStyle() const override
50 | {
51 | return &MenuStyle;
52 | }
53 | };
--------------------------------------------------------------------------------
/SlateTutorials/Source/SlateTutorials/MainMenuHUD.cpp:
--------------------------------------------------------------------------------
1 | #include "SlateTutorials.h"
2 | #include "MainMenuHUD.h"
3 | #include "MainMenuUI.h"
4 |
5 | AMainMenuHUD::AMainMenuHUD()
6 | : Super(FObjectInitializer::Get())
7 | {
8 |
9 | }
10 |
11 | void AMainMenuHUD::PostInitializeComponents()
12 | {
13 | Super::PostInitializeComponents();
14 |
15 | SAssignNew(MainMenuUI, SMainMenuUI).MainMenuHUD(this);
16 |
17 | if (GetOwningPlayerController())
18 | {
19 | GetOwningPlayerController()->GetLocalPlayer()->ViewportClient->AddViewportWidgetContent(MainMenuUI->AsShared());
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/SlateTutorials/Source/SlateTutorials/MainMenuHUD.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "GameFramework/HUD.h"
4 | #include "MainMenuHUD.generated.h"
5 |
6 | UCLASS(Blueprintable)
7 | class SLATETUTORIALS_API AMainMenuHUD : public AHUD
8 | {
9 | GENERATED_BODY()
10 | public:
11 | AMainMenuHUD();
12 | // Initializes the Slate UI and adds it as widget content to the game viewport
13 | virtual void PostInitializeComponents() override;
14 |
15 | // Called by SMainMenu whenever the Play Game! button has been clicked.
16 | UFUNCTION(BlueprintImplementableEvent, Category = "Menus|Main Menu")
17 | void PlayGameClicked();
18 |
19 | // Called by SMainMenu whever the Quit Game! button has been clicked.
20 | UFUNCTION(BlueprintImplementableEvent, Category = "Menus|Main Menu")
21 | void QuitGameClicked();
22 |
23 | TSharedPtr MainMenuUI;
24 | };
--------------------------------------------------------------------------------
/SlateTutorials/Source/SlateTutorials/MainMenuUI.cpp:
--------------------------------------------------------------------------------
1 | #include "SlateTutorials.h"
2 | #include "MainMenuHUD.h"
3 | #include "MainMenuUI.h"
4 | #include "MenuStyles.h"
5 | #include "GlobalMenuStyle.h"
6 |
7 | BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION
8 | void SMainMenuUI::Construct(const FArguments& InArgs)
9 | {
10 | MainMenuHUD = InArgs._MainMenuHUD;
11 | MenuStyle = &FMenuStyles::Get()->GetWidgetStyle(TEXT("Global"));
12 |
13 | ChildSlot
14 | [
15 | SNew(SOverlay)
16 | +SOverlay::Slot()
17 | .HAlign(HAlign_Center)
18 | .VAlign(VAlign_Top)
19 | [
20 | SNew(STextBlock)
21 | .TextStyle(&MenuStyle->MenuTitleStyle)
22 | .Text(FText::FromString(TEXT("Main Menu")))
23 | ]
24 | +SOverlay::Slot()
25 | .HAlign(HAlign_Right)
26 | .VAlign(VAlign_Bottom)
27 | [
28 | SNew(SVerticalBox)
29 | +SVerticalBox::Slot()
30 | [
31 | SNew(SButton)
32 | .ButtonStyle(&MenuStyle->MenuButtonStyle)
33 | .TextStyle(&MenuStyle->MenuButtonTextStyle)
34 | .Text(FText::FromString(TEXT("Play Game!")))
35 | .OnClicked(this, &SMainMenuUI::PlayGameClicked)
36 | ]
37 | +SVerticalBox::Slot()
38 | [
39 | SNew(SButton)
40 | .ButtonStyle(&MenuStyle->MenuButtonStyle)
41 | .TextStyle(&MenuStyle->MenuButtonTextStyle)
42 | .Text(FText::FromString(TEXT("Quit Game!")))
43 | .OnClicked(this, &SMainMenuUI::QuitGameClicked)
44 | ]
45 | ]
46 | ];
47 | }
48 | END_SLATE_FUNCTION_BUILD_OPTIMIZATION
49 |
50 | FReply SMainMenuUI::PlayGameClicked()
51 | {
52 | if (MainMenuHUD.IsValid())
53 | {
54 | MainMenuHUD->PlayGameClicked();
55 | }
56 | return FReply::Handled();
57 | }
58 |
59 | FReply SMainMenuUI::QuitGameClicked()
60 | {
61 | if (MainMenuHUD.IsValid())
62 | {
63 | MainMenuHUD->QuitGameClicked();
64 | }
65 | return FReply::Handled();
66 | }
67 |
--------------------------------------------------------------------------------
/SlateTutorials/Source/SlateTutorials/MainMenuUI.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/henrya2/SlateTutorials/abd5e86f0e8e717eb33d6e2e12151756dfb4e281/SlateTutorials/Source/SlateTutorials/MainMenuUI.h
--------------------------------------------------------------------------------
/SlateTutorials/Source/SlateTutorials/MenuStyles.cpp:
--------------------------------------------------------------------------------
1 | #include "SlateTutorials.h"
2 | #include "MenuStyles.h"
3 | #include "SlateGameResources.h"
4 |
5 | TSharedPtr FMenuStyles::MenuStyleInstance = nullptr;
6 |
7 | void FMenuStyles::Initialize()
8 | {
9 | if (!MenuStyleInstance.IsValid())
10 | {
11 | MenuStyleInstance = Create();
12 | FSlateStyleRegistry::RegisterSlateStyle(*MenuStyleInstance);
13 | }
14 | }
15 |
16 | void FMenuStyles::Shutdown()
17 | {
18 | FSlateStyleRegistry::UnRegisterSlateStyle(*MenuStyleInstance);
19 | ensure(MenuStyleInstance.IsUnique());
20 | MenuStyleInstance.Reset();
21 | }
22 |
23 | TSharedPtr FMenuStyles::Get()
24 | {
25 | return MenuStyleInstance;
26 | }
27 |
28 | FName FMenuStyles::GetStyleSetName()
29 | {
30 | static FName StyleSetName(TEXT("MenuStyles"));
31 | return StyleSetName;
32 | }
33 |
34 | TSharedRef FMenuStyles::Create()
35 | {
36 | TSharedRef StyleRef = FSlateGameResources::New(FMenuStyles::GetStyleSetName(), TEXT("/Game/UI/Styles"), TEXT("/Game/UI/Styles"));
37 | return StyleRef;
38 | }
39 |
--------------------------------------------------------------------------------
/SlateTutorials/Source/SlateTutorials/MenuStyles.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "SlateBasics.h"
4 |
5 | class FMenuStyles
6 | {
7 | public:
8 | // Initializes the value of MenuStyleInstance and registers it with the Slate Style Registry.
9 | static void Initialize();
10 |
11 | // Unregisters the Slate Style Set and then resets the MenuStyleInstance pointer.
12 | static void Shutdown();
13 |
14 | // Retrieves a reference to the Slate Style pointed to by MenuStyleInstance.
15 | static TSharedPtr Get();
16 |
17 | // Retrieves the name of the Style Set.
18 | static FName GetStyleSetName();
19 |
20 | private:
21 | // Creates the Style Set.
22 | static TSharedRef Create();
23 |
24 | // Singleton instance used for our Style Set.
25 | static TSharedPtr MenuStyleInstance;
26 | };
27 |
--------------------------------------------------------------------------------
/SlateTutorials/Source/SlateTutorials/SlateTutorials.Build.cs:
--------------------------------------------------------------------------------
1 | // Fill out your copyright notice in the Description page of Project Settings.
2 |
3 | using UnrealBuildTool;
4 |
5 | public class SlateTutorials : ModuleRules
6 | {
7 | public SlateTutorials(TargetInfo Target)
8 | {
9 | PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" });
10 |
11 | PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });
12 |
13 | // Uncomment if you are using online features
14 | // PrivateDependencyModuleNames.Add("OnlineSubsystem");
15 | // if ((Target.Platform == UnrealTargetPlatform.Win32) || (Target.Platform == UnrealTargetPlatform.Win64))
16 | // {
17 | // if (UEBuildConfiguration.bCompileSteamOSS == true)
18 | // {
19 | // DynamicallyLoadedModuleNames.Add("OnlineSubsystemSteam");
20 | // }
21 | // }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/SlateTutorials/Source/SlateTutorials/SlateTutorials.cpp:
--------------------------------------------------------------------------------
1 | // Fill out your copyright notice in the Description page of Project Settings.
2 |
3 | #include "SlateTutorials.h"
4 | #include "MenuStyles.h"
5 |
6 |
7 | // Custom implementation of the Default Game Module.
8 | class FSlateTutorialsGameModule : public FDefaultGameModuleImpl
9 | {
10 | // Called whenever the module is starting up. In here, we unregister any style sets
11 | // (which may have been added by other modules) sharing our
12 | // style set's name, then initialize our style set.
13 | virtual void StartupModule() override
14 | {
15 | //Hot reload hack
16 | FSlateStyleRegistry::UnRegisterSlateStyle(FMenuStyles::GetStyleSetName());
17 | FMenuStyles::Initialize();
18 | }
19 |
20 | // Called whenever the module is shutting down. Here, we simply tell our MenuStyles to shut down.
21 | virtual void ShutdownModule() override
22 | {
23 | FMenuStyles::Shutdown();
24 | }
25 | };
26 |
27 | IMPLEMENT_PRIMARY_GAME_MODULE(FSlateTutorialsGameModule, SlateTutorials, "SlateTutorials");
28 |
--------------------------------------------------------------------------------
/SlateTutorials/Source/SlateTutorials/SlateTutorials.h:
--------------------------------------------------------------------------------
1 | // Fill out your copyright notice in the Description page of Project Settings.
2 |
3 | #pragma once
4 |
5 | #include "Engine.h"
6 |
7 |
--------------------------------------------------------------------------------
/SlateTutorials/Source/SlateTutorials/TutGameMode.cpp:
--------------------------------------------------------------------------------
1 | #include "SlateTutorials.h"
2 | #include "TutGameMode.h"
3 | #include "TutorialGameHUD.h"
4 | #include "TutorialCharacter.h"
5 |
6 | ATutGameMode::ATutGameMode()
7 | : Super(FObjectInitializer::Get())
8 | , CurrentScore(0)
9 | {
10 | HUDClass = ATutorialGameHUD::StaticClass();
11 | DefaultPawnClass = ATutorialCharacter::StaticClass();
12 | }
13 |
14 | int32 ATutGameMode::GetScore()
15 | {
16 | return CurrentScore;
17 | }
18 |
19 | void ATutGameMode::AddPoints(int32 value)
20 | {
21 | if (value > 0)
22 | CurrentScore += value;
23 | }
24 |
25 | void ATutGameMode::DeductPoints(int32 value)
26 | {
27 | if (value > 0)
28 | CurrentScore = FMath::Max(CurrentScore - value, 0);
29 | }
30 |
--------------------------------------------------------------------------------
/SlateTutorials/Source/SlateTutorials/TutGameMode.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "GameFramework/GameMode.h"
4 | #include "TutGameMode.generated.h"
5 |
6 | /**
7 | * A simple game mode providing a means of retrieving and adjusting a single Score value.
8 | **/
9 | UCLASS()
10 | class ATutGameMode : public AGameMode
11 | {
12 | GENERATED_BODY()
13 |
14 | public:
15 | ATutGameMode();
16 | /**
17 | * Retrieves the current Score from the game mode.
18 | **/
19 | UFUNCTION(BlueprintPure, BlueprintCallable, Category = "Score")
20 | int32 GetScore();
21 |
22 | /**
23 | * Adds to the game score.
24 | **/
25 | UFUNCTION(BlueprintCallable, Category = "Score")
26 | void AddPoints(int32 value);
27 |
28 | /**
29 | * Removes from the game score.
30 | **/
31 | UFUNCTION(BlueprintCallable, Category = "Score")
32 | void DeductPoints(int32 value);
33 |
34 | private:
35 | /**
36 | * Stores the current score.
37 | **/
38 | int32 CurrentScore;
39 | };
40 |
--------------------------------------------------------------------------------
/SlateTutorials/Source/SlateTutorials/TutorialCharacter.cpp:
--------------------------------------------------------------------------------
1 | // Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
2 |
3 | #include "SlateTutorials.h"
4 | #include "TutorialCharacter.h"
5 |
6 | ATutorialCharacter::ATutorialCharacter()
7 | : Super(FObjectInitializer::Get())
8 | {
9 | Health = 100;
10 | }
11 |
--------------------------------------------------------------------------------
/SlateTutorials/Source/SlateTutorials/TutorialCharacter.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "GameFramework/Character.h"
4 | #include "TutorialCharacter.generated.h"
5 |
6 | /**
7 | * A simple character providing a means of retrieving and manipulating health.
8 | **/
9 | UCLASS()
10 | class ATutorialCharacter : public ACharacter
11 | {
12 | GENERATED_BODY()
13 |
14 | public:
15 | ATutorialCharacter();
16 | /**
17 | * Stores the character's current health.
18 | **/
19 | UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Combat")
20 | int32 Health;
21 | };
22 |
--------------------------------------------------------------------------------
/SlateTutorials/Source/SlateTutorials/TutorialGameHUD.cpp:
--------------------------------------------------------------------------------
1 | #include "SlateTutorials.h"
2 |
3 | #include "TutorialGameHUD.h"
4 | #include "TutorialGameHUDUI.h"
5 |
6 | ATutorialGameHUD::ATutorialGameHUD()
7 | : Super(FObjectInitializer::Get())
8 | {
9 | }
10 |
11 | void ATutorialGameHUD::PostInitializeComponents()
12 | {
13 | Super::PostInitializeComponents();
14 |
15 | if (GEngine && GEngine->GameViewport)
16 | {
17 | UGameViewportClient* Viewport = GEngine->GameViewport;
18 |
19 | SAssignNew(GameHUD, STutorialGameHUDUI)
20 | .OwnerHUD(TWeakObjectPtr(this));
21 |
22 | Viewport->AddViewportWidgetContent(
23 | SNew(SWeakWidget).PossiblyNullContent(GameHUD.ToSharedRef())
24 | );
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/SlateTutorials/Source/SlateTutorials/TutorialGameHUD.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "GameFramework/HUD.h"
4 |
5 | #include "TutorialGameHUD.generated.h"
6 |
7 | /**
8 | * Provides an implementation of the game's in-game HUD, which will display the player's current health and score.
9 | **/
10 | UCLASS()
11 | class ATutorialGameHUD : public AHUD
12 | {
13 | GENERATED_BODY()
14 |
15 | public:
16 | ATutorialGameHUD();
17 | /**
18 | * Initializes the Slate UI and adds it as a widget to the game viewport.
19 | **/
20 | virtual void PostInitializeComponents() override;
21 |
22 | private:
23 | /**
24 | * Reference to the Game HUD UI.
25 | **/
26 | TSharedPtr GameHUD;
27 | };
28 |
--------------------------------------------------------------------------------
/SlateTutorials/Source/SlateTutorials/TutorialGameHUDUI.cpp:
--------------------------------------------------------------------------------
1 | #include "SlateTutorials.h"
2 |
3 | #include "TutorialGameHUD.h"
4 | #include "TutorialGameHUDUI.h"
5 |
6 | #include "GlobalMenuStyle.h"
7 | #include "MenuStyles.h"
8 | #include "TutGameMode.h"
9 | #include "TutorialCharacter.h"
10 |
11 | void STutorialGameHUDUI::Construct(const FArguments& args)
12 | {
13 | Score.Bind(this, &STutorialGameHUDUI::GetScore);
14 | Health.Bind(this, &STutorialGameHUDUI::GetHealth);
15 |
16 | OwnerHUD = args._OwnerHUD;
17 |
18 | HUDStyle = &FMenuStyles::Get()->GetWidgetStyle("Global");
19 |
20 | ChildSlot
21 | [
22 | SNew(SOverlay)
23 | + SOverlay::Slot()
24 | .HAlign(HAlign_Right)
25 | .VAlign(VAlign_Top)
26 | [
27 | SNew(STextBlock)
28 | .TextStyle(&HUDStyle->MenuTitleStyle)
29 | .Text(Score)
30 | ]
31 | + SOverlay::Slot()
32 | .HAlign(HAlign_Left)
33 | .VAlign(VAlign_Top)
34 | [
35 | SNew(STextBlock)
36 | .TextStyle(&HUDStyle->MenuTitleStyle)
37 | .Text(Health)
38 | ]
39 | ];
40 | }
41 |
42 | FText STutorialGameHUDUI::GetScore() const
43 | {
44 | // NOTE: THIS IS A TERRIBLE WAY TO DO THIS. DO NOT DO IT. IT ONLY WORKS ON SERVERS. USE GAME STATES INSTEAD!
45 | ATutGameMode* GameMode = Cast(OwnerHUD->GetWorldSettings()->GetWorld()->GetAuthGameMode());
46 |
47 | if (GameMode == nullptr)
48 | return FText::FromString(TEXT("SCORE: --"));
49 |
50 | FString score = TEXT("SCORE: ");
51 | score.AppendInt(GameMode->GetScore());
52 |
53 | return FText::FromString(score);
54 | }
55 |
56 | FText STutorialGameHUDUI::GetHealth() const
57 | {
58 | ATutorialCharacter* Character = Cast(OwnerHUD->PlayerOwner->GetCharacter());
59 |
60 | if (Character == nullptr)
61 | return FText::FromString(TEXT("HEALTH: --"));
62 |
63 | FString health = TEXT("HEALTH: ");
64 | health.AppendInt(Character->Health);
65 |
66 | return FText::FromString(health);
67 | }
68 |
--------------------------------------------------------------------------------
/SlateTutorials/Source/SlateTutorials/TutorialGameHUDUI.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "SlateBasics.h"
4 |
5 | // Lays out and controls the Tutorial HUD UI.
6 |
7 | class STutorialGameHUDUI : public SCompoundWidget
8 | {
9 | SLATE_BEGIN_ARGS(STutorialGameHUDUI)
10 | : _OwnerHUD()
11 | {
12 | }
13 |
14 | SLATE_ARGUMENT(TWeakObjectPtr, OwnerHUD);
15 |
16 | SLATE_END_ARGS()
17 |
18 | public:
19 | /**
20 | * Constructs and lays out the Tutorial HUD UI Widget.
21 | *
22 | * \args Arguments structure that contains widget-specific setup information.
23 | **/
24 | void Construct(const FArguments& args);
25 |
26 | private:
27 | /**
28 | * Stores a weak reference to the HUD owning this widget.
29 | **/
30 | TWeakObjectPtr OwnerHUD;
31 |
32 | /**
33 | * A reference to the Slate Style used for this HUD's widgets.
34 | **/
35 | const struct FGlobalStyle* HUDStyle;
36 |
37 | private:
38 | /**
39 | * Attribute storing the binding for the player's score.
40 | **/
41 | TAttribute Score;
42 |
43 | /**
44 | * Attribute storing the binding for the player's health.
45 | **/
46 | TAttribute Health;
47 |
48 | /**
49 | * Our Score will be bound to this function, which will retrieve the appropriate data and convert it into an FText.
50 | **/
51 | FText GetScore() const;
52 |
53 | /**
54 | * Our Health will be bound to this function, which will retrieve the appropriate data and convert it into an FText.
55 | **/
56 | FText GetHealth() const;
57 | };
58 |
--------------------------------------------------------------------------------
/SlateTutorials/Source/SlateTutorials/WidgetGameMode.cpp:
--------------------------------------------------------------------------------
1 | #include "SlateTutorials.h"
2 | #include "WidgetGameMode.h"
3 | #include "MainMenuHUD.h"
4 |
5 | AWidgetGameMode::AWidgetGameMode()
6 | : Super(FObjectInitializer::Get())
7 | {
8 | HUDClass = AMainMenuHUD::StaticClass();
9 | }
10 |
11 |
--------------------------------------------------------------------------------
/SlateTutorials/Source/SlateTutorials/WidgetGameMode.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "GameFramework/GameMode.h"
4 | #include "WidgetGameMode.generated.h"
5 |
6 | UCLASS(Blueprintable)
7 | class SLATETUTORIALS_API AWidgetGameMode : public AGameMode
8 | {
9 | GENERATED_BODY()
10 |
11 | public:
12 | AWidgetGameMode();
13 | };
14 |
--------------------------------------------------------------------------------
/SlateTutorials/Source/SlateTutorialsEditor.Target.cs:
--------------------------------------------------------------------------------
1 | // Fill out your copyright notice in the Description page of Project Settings.
2 |
3 | using UnrealBuildTool;
4 | using System.Collections.Generic;
5 |
6 | public class SlateTutorialsEditorTarget : TargetRules
7 | {
8 | public SlateTutorialsEditorTarget(TargetInfo Target)
9 | {
10 | Type = TargetType.Editor;
11 | }
12 |
13 | //
14 | // TargetRules interface.
15 | //
16 |
17 | public override void SetupBinaries(
18 | TargetInfo Target,
19 | ref List OutBuildBinaryConfigurations,
20 | ref List OutExtraModuleNames
21 | )
22 | {
23 | OutExtraModuleNames.AddRange( new string[] { "SlateTutorials" } );
24 | }
25 | }
26 |
--------------------------------------------------------------------------------