{"id":521,"date":"2014-08-12T15:19:56","date_gmt":"2014-08-12T13:19:56","guid":{"rendered":"http:\/\/www.michalorzelek.com\/blog\/?p=521"},"modified":"2014-08-14T15:24:56","modified_gmt":"2014-08-14T13:24:56","slug":"521","status":"publish","type":"post","link":"https:\/\/www.michalorzelek.com\/blog\/521\/","title":{"rendered":"Tutorial: Custom GUI with Slate Styles"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-463\" src=\"https:\/\/www.michalorzelek.com\/blog\/wp-content\/uploads\/2014\/08\/techPanel-512x71.png\" alt=\"techPanel\" width=\"812\" height=\"103\" \/><\/p>\n<h2>Introduction<\/h2>\n<p>During game development many tasks can be done simultaneously as long as the team is big enough. Things can get more difficult when you will try to make a game with a handful of friends or on your own.<\/p>\n<p>Gameplay design, animations rigging, AI scripting, physics coding, UI creation &#8211; these are the tasks that you will have to face if you decide to become a one man army. Most of you wont have time or just wont be able to focus on all of these subjects, so you will most likely get basic animations rolling and create some gameplay around it. You will use provided physics engine and move on to AI scripting, create basic materials and use them to put together level\u00a0prototypes.<br \/>\nUnreal Engine 4 provides variety of tools that will allow you to do just that. However, the UI creation tool &#8211; Unreal Motion Graphics (UMG) &#8211; is still on the way.<\/p>\n<p>So while we&#8217;re all waiting, I decided to shed some light on Slate mysterious syntax by creating widget library that will allow you to prototype some basic game UI without much effort.<\/p>\n<p><!--more--><\/p>\n<p>You may ask &#8222;why should I bother with Slate in C++ if I will be able to create UI much easier using UMG very soon?&#8221;. Well, the same reason people prefer to keep most of the gameplay logic in C++ rather than Blueprints. It&#8217;s much easier to maintain few large files of code rather than few blueprints with a lot of nodes in it (code is much more flexible). Blueprints are still a way to go when you want to quickly get some simple features running but if you would like to create more advanced class hierarchy or base your entire game on blueprints, sooner or later you will find out that not everything can be done in Epic&#8217;s visual scripting tool.<br \/>\nSame goes for User Interface &#8211; I&#8217;m sure that guys from Epic will do their best to make UMG a tool for simple and advanced visuals. But if you&#8217;re looking for some complex UI functionality &#8211; in my opinion, code always will be the answer. Besides, after you get the idea behind Slate syntax and basic widget designs it becomes really easy and fun to use.<\/p>\n<p>In this tutorial I won&#8217;t focus much on Slate basics like, how to create a widget or add it to game viewport but you will see how to properly use Slate in code, create\/bind delegates and attributes.<\/p>\n<p>So just as a quick overview: I have\u00a0put together two basic UI elements that most of action games has &#8211; resource bars (like health or mana) and skill\/ability buttons. It will still require some coding (C++ &amp; basic Slate Syntax), so for those of you scared of C++ &#8211; keep scrolling, maybe you&#8217;ll see something that will make you want to learn it :D.<\/p>\n<p><\/p>\n<h2>Set-up<\/h2>\n<p>Ok, lets get started! First, most difficult part, will be to set things up:<\/p>\n<ol style=\"margin-left: 30px;\">\n<li> Download GUITutorial contents <strong><a href=\"https:\/\/www.michalorzelek.com\/blog\/wp-content\/uploads\/2014\/08\/4.3.rar\"> for UE 4.3<\/a><\/strong> or <strong><a href=\"https:\/\/www.michalorzelek.com\/blog\/wp-content\/uploads\/2014\/08\/4.4_preview.rar\">for UE 4.4 (preview)<\/strong><\/a><\/li>\n<li> Extract .rar file from above. You should be able to get two folders: GUILibrary and UI.<\/li>\n<li> Put GUILibrary folder inside your UE Runtime folder ( i.e. UnrealEngine-4.4\\Engine\\Source\\Runtime ).<\/li>\n<li> Generate UE project files using GenerateProjectFiles.bat<\/li>\n<li> Create a new project or choose existing one. For this tutorial I created a new one called CodeTD using Code Top Down template.<\/li>\n<li> Put UI folder from 2. into your game content folder (for me it was CodeTD\\Content)<\/li>\n<li> Open your project solution.<\/li>\n<li> Open CodeTD.Build.cs and add private dependencies to GUILibrary like this:\n<p>Note that you also must include dependencies for Slate and SlateCore if you haven&#8217;t already!<\/p>\n[cpp]\nPrivateDependencyModuleNames.AddRange(<br \/>\n            new string[] {<br \/>\n                &quot;SlateCore&quot;,<br \/>\n                &quot;Slate&quot;,<br \/>\n\t\t\t\t&quot;GUILibrary&quot;,<br \/>\n\t\t\t}<br \/>\n        );<br \/>\n[\/cpp] <\/li>\n<li> Close Visual Studio and GenerateProjectFiles again to refresh intellisense. (You can generate project files for you project only)<\/li>\n<li> Initialize GUILibrary style called <em>FGUIStyle<\/em>. To do that go to <a href=\"https:\/\/www.michalorzelek.com\/blog\/wp-content\/uploads\/2014\/08\/CodeTD.h\">CodeTD.h<\/a> file and paste below code:<br \/>\n! Remember to replace CodeTD with your project name !<br \/>\n[cpp]\n#include &quot;GUILibrary.h&quot;<\/p>\n<p>class FCodeTDGameModule : public FDefaultGameModuleImpl<br \/>\n{<br \/>\n\tvirtual void StartupModule() override<br \/>\n\t{<br \/>\n\t\t\/\/Hot reload hack<br \/>\n\t\tFSlateStyleRegistry::UnRegisterSlateStyle(FGUIStyle::GetStyleSetName());<br \/>\n\t\tFGUIStyle::Initialize();<br \/>\n\t}<\/p>\n<p>\tvirtual void ShutdownModule() override<br \/>\n\t{<br \/>\n\t\tFGUIStyle::Shutdown();<br \/>\n\t}<br \/>\n};<br \/>\n[\/cpp] <\/li>\n<li> Go to CodeTD.cpp and change IMPLEMENT_PRIMARY_GAME_MODULE macro first parameter to <em>FCodeTDGameModule <\/em>so it looks like this:<br \/>\n[cpp]\nIMPLEMENT_PRIMARY_GAME_MODULE(FCodeTDGameModule, CodeTD, &quot;CodeTD&quot;);<br \/>\n[\/cpp] <\/li>\n<li> You are ready to go!<\/li>\n<\/ol>\n<p><\/p>\n<h2>Classes description<\/h2>\n<p>Now, when the hardest part is behind you, time for some details about Library content:<\/p>\n<p>My very first version of widgets library contains useful widgets for game UI prototyping. It will allow you to create quite valueable widgets with just few lines of code. Library includes 3 basic widgets:<\/p>\n<li><strong><a href=\"https:\/\/www.michalorzelek.com\/blog\/wp-content\/uploads\/2014\/08\/SResourceBar.h\">SResourceBar<\/a> <\/strong>&#8211; displays float type resource like health, mana, stamina, etc. It requires 2 attributes to be set: Value (i.e. Current health) and MaxValue (i.e. Max health). Resource bars can also display text label in format &#8222;CurrentValue \/ MaxValue&#8221;. You can see it on examples below.<\/li>\n<li><strong><a href=\"https:\/\/www.michalorzelek.com\/blog\/wp-content\/uploads\/2014\/08\/SSkillButton.h\">SSkillButton<\/a> <\/strong>&#8211; represents a button that can easily be bound to an action using FSimpleDelegate, FUIAction, FUICommandInfo (the last one is still WIP). Buttons can also display a key binding text.<\/li>\n<li><strong><a href=\"https:\/\/www.michalorzelek.com\/blog\/wp-content\/uploads\/2014\/08\/SSkillsPanel.h\">SSkillsPanel<\/a> <\/strong>&#8211; container for SSkillsButtons. You can use AddSkillbutton(..) function to add buttons to it.<\/li>\n<p>Each one of this widget is using corresponding Slate Style classes: <a href=\"https:\/\/www.michalorzelek.com\/blog\/wp-content\/uploads\/2014\/08\/ResourceBarStyle.h\"><strong>ResourceBarStyle<\/strong><\/a>, <a href=\"https:\/\/www.michalorzelek.com\/blog\/wp-content\/uploads\/2014\/08\/SkillButtonStyle.h\"><strong>SkillButtonStyle<\/strong><\/a>, <a href=\"https:\/\/www.michalorzelek.com\/blog\/wp-content\/uploads\/2014\/08\/SkillsPanelStyle.h\"><strong>SkillsPanelStyle<\/strong><\/a>. Thanks to these assets you can control the look of your widgets.<br \/>\nThis Library comes with some default styles included (inside UI folder you put in your game project content folder).<\/p>\n<p><\/p>\n<h2>Resources bar examples<\/h2>\n<p><b>Creating a health bar<\/b><\/p>\n<p>First up lets create a health bar. To do this you will need variable that represents Current Health value and Maximum Health value. Most likely you will declare those in you character class like this:<br \/>\n[cpp]\nUPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Resources)<br \/>\nfloat Health;<\/p>\n<p>UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Resources)<br \/>\nfloat MaxHealth;<br \/>\n[\/cpp]\n<p><\/p>\n<p>You could create your health bar already, like this:<br \/>\n[cpp]\nSNew(SResourceBar)<br \/>\n.Value(Health)<br \/>\n.MaxValue(MaxHealth)<br \/>\n[\/cpp]\n<p><\/p>\n<p>But it will just make a static container, since Health and MaxHealth are passed to SResourceBar once &#8211; at the construction time. To make the health bar dynamic, so it automatically reads value of both &#8211; Health and MaxHealth, you will have to create an Attribute. Attributes can be bound to a single value or to a getter function to this value that will be called every frame for an update. Since we&#8217;re in UObject we have to do the following:<br \/>\n[cpp]\n\/\/ Create attributes as different variables so they can be referenced later on in code<br \/>\nTAttribute&lt;float&gt; Value = TAttribute&lt;float&gt;::Create(TAttribute&lt;float&gt;::FGetter::CreateUObject(this, &amp;ACodeTDCharacter::GetCurrentHealth));<br \/>\nTAttribute&lt;float&gt; MaxValue = TAttribute&lt;float&gt;::Create(TAttribute&lt;float&gt;::FGetter::CreateUObject(this, &amp;ACodeTDCharacter::GetMaxHealth));<br \/>\n[\/cpp]\n<br \/>\nNow all you have to do is add newly created bar to game viewport:<br \/>\n[cpp]\nGEngine-&gt;GameViewport-&gt;AddViewportWidgetContent(<br \/>\nSNew(SResourceBar)<br \/>\n.Value(Value)<br \/>\n.MaxValue(MaxValue)<br \/>\n);<br \/>\n[\/cpp]\n<p>\nExecuting above code will add bar widget to viewport but the widget will get greedy and take all allocated space. So to prevent that, lets say you want to add a your bar to top left corner and make it horizontal (it grows from left to right). First you will have to create a container for it. In this case it will be a SVerticalBox (a box that aligns its slots from top to bottom, for more on Slate Widgets click <a title=\"Slate widgets overview\" href=\"https:\/\/docs.unrealengine.com\/latest\/INT\/Programming\/Slate\/Widgets\/index.html\" target=\"_blank\">here<\/a>)<br \/>\n[cpp]\n\tGEngine-&gt;GameViewport-&gt;AddViewportWidgetContent(<br \/>\n\t\t\/\/ Create VerticalBox container<br \/>\n\t\tSNew(SVerticalBox)<br \/>\n\t\t\/\/ Add slot to it<br \/>\n\t\t+ SVerticalBox::Slot()<br \/>\n\t\t\/\/ Note that following settings are relevant ONLY for this slot content!<br \/>\n\t\t\/\/ Set slot to AutoHeight &#8211; this slot will adjust its height to it&#8217;s content height.<br \/>\n\t\t.AutoHeight()<br \/>\n\t\t\/\/ We want the content to be aligned to the left<br \/>\n\t\t.HAlign(HAlign_Left)<br \/>\n\t\t\/\/ set some padding so we dont end up to close to window border<br \/>\n\t\t.Padding(15)<br \/>\n\t\t[<br \/>\n\t\t\tSNew(SResourceBar)<br \/>\n\t\t\t.Value(Value)<br \/>\n\t\t\t.MaxValue(MaxValue)<br \/>\n\t\t\t\/\/ by default SResourceBar is vertical (it grows from bottom to top) so lets make it horizontal<br \/>\n\t\t\t.Orientation(EOrientation::Orient_Horizontal)<br \/>\n\t\t]\n\t);<br \/>\n[\/cpp]\n<p>\nYou should end up with a bar like this in top left corner of your screen (note that by default, I set Health to 75 and MaxHealth to 100):<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-459\" src=\"https:\/\/www.michalorzelek.com\/blog\/wp-content\/uploads\/2014\/08\/bar_h_wide_320x20.png\" alt=\"bar_h_wide_320x20\" width=\"334\" height=\"29\" \/><\/p>\n<p><\/p>\n<p>You can of course (since UE 4.3) use unlit materials on Slate widgets to achieve more advanced visual look. On image below you can see two bars (health and mana) displayed by the same style (using materials) and same variables (ideally you would have separate Attributes for health and mana). Note that you can control bar&#8217;s color via code to quickly create different instances of the same resource bar.<\/p>\n<div class=\"su-custom-gallery su-custom-gallery-align-left su-custom-gallery-title-hover su-lightbox-gallery\"><div class=\"su-custom-gallery-slide\" style=\"width:650px;height:400px\"><a href=\"https:\/\/www.michalorzelek.com\/blog\/wp-content\/uploads\/2014\/08\/twoBars_w_code.png\" title=\"twoBars_w_code\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.michalorzelek.com\/blog\/wp-content\/uploads\/2014\/08\/twoBars_w_code-650x400.png\" alt=\"twoBars_w_code\" width=\"650\" height=\"400\" \/><span class=\"su-custom-gallery-title\">twoBars_w_code<\/span><\/a><\/div><div class=\"su-clear\"><\/div><\/div>\n<p><\/p>\n<p>There is a bunch of other parameters you can check out in code and\/or style asset.<\/p>\n<p><strong>Resource bars examples with code that creates them<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.michalorzelek.com\/blog\/wp-content\/uploads\/2014\/08\/bar_v_wide_w_code.png\" alt=\"bar_v_wide_w_code\" width=\"277\" height=\"180\" class=\"alignnone size-full wp-image-584\" \/><br \/>\n<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.michalorzelek.com\/blog\/wp-content\/uploads\/2014\/08\/bar_h_wide_320x20_w_code.png\" alt=\"bar_h_wide_320x20_w_code\" width=\"337\" height=\"224\" class=\"alignnone size-full wp-image-581\" \/><\/p>\n<div class=\"su-custom-gallery su-custom-gallery-align-left su-custom-gallery-title-hover su-lightbox-gallery\"><div class=\"su-custom-gallery-slide\" style=\"width:650px;height:300px\"><a href=\"https:\/\/www.michalorzelek.com\/blog\/wp-content\/uploads\/2014\/08\/bar_v_circular_w_code.png\" title=\"bar_v_circular_w_code\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.michalorzelek.com\/blog\/wp-content\/uploads\/2014\/08\/bar_v_circular_w_code-650x300.png\" alt=\"bar_v_circular_w_code\" width=\"650\" height=\"300\" \/><span class=\"su-custom-gallery-title\">bar_v_circular_w_code<\/span><\/a><\/div><div class=\"su-clear\"><\/div><\/div>\n<p>Among all other brushes that define look of your resource bar, you will find Decorator brush, which will be drawn on top of everything. This way you can add some interesting decorations like on the image below.<\/p>\n<p><\/p>\n<div class=\"su-custom-gallery su-custom-gallery-align-left su-custom-gallery-title-hover su-lightbox-gallery\"><div class=\"su-custom-gallery-slide\" style=\"width:650px;height:120px\"><a href=\"https:\/\/www.michalorzelek.com\/blog\/wp-content\/uploads\/2014\/08\/bar_v_circular_plus_decorator.png\" title=\"bar_v_circular_plus_decorator\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.michalorzelek.com\/blog\/wp-content\/uploads\/2014\/08\/bar_v_circular_plus_decorator-650x120.png\" alt=\"bar_v_circular_plus_decorator\" width=\"650\" height=\"120\" \/><span class=\"su-custom-gallery-title\">bar_v_circular_plus_decorator<\/span><\/a><\/div><div class=\"su-clear\"><\/div><\/div>\n<p><em>Resource bar + Decorator brush<\/p>\n<p><\/em><\/p>\n<p><\/p>\n<h2>Skills Panel and Buttons<\/h2>\n<p>As mentioned before <em>SSkillsPanel<\/em> (Panel) is a container for <em>SSkillButton<\/em> (Button). Panel can contain any number of buttons and it&#8217;s style is defined by <em>FSkillsPanelWidgetStyle<\/em> class where you can set things like buttons padding, minimal button size or default style of the button.<br \/>\nNote that buttons will be added to <em>SUniformGridPanel<\/em>. That means all buttons will have same size and this size will be specified by BIGGEST button!<br \/>\nSo you are not able to have one 32&#215;32 button while the rest remains 64&#215;64 (all buttons will be 64&#215;64 and smaller buttons will be stretched to 64&#215;64).<\/p>\n<p>To add button to a Panel you will have to use one of the <em>AddSkillButton<\/em> functions. The most common would be<br \/>\n[cpp]\nvoid SSkillsPanel::AddSkillButton(FSimpleDelegate OnButtonClick)<br \/>\n[\/cpp]\n<br \/>\nThe one and only parameter of this function is a delegate that will be called after the button is clicked. <em>FSimpleDelegate<\/em> represents a function that does not reutrn anything and does not take any parameters. So to create a SimpleDelegate you will have to have a function similar to this:<br \/>\n[cpp]\nUFUNCTION(BlueprintImplementableEvent)<br \/>\nvoid UseAbility1();<br \/>\n[\/cpp] <\/p>\n<p>Now you can create delegate from it. So lets assume you&#8217;re creating your UI inside character class and you added <em>UseAbility1<\/em>() function to it. To create a delegate that contains this function do the following:<br \/>\n[cpp]\nFSimpleDelegate::CreateUObject(this, &amp;ACodeTDCharacter::UseAbility1);<br \/>\n[\/cpp]\n<br \/>\nNote that you can use different Create functions! More on Unreal delegates can be found <a title=\"Unreal Delegates Documentation\" href=\"https:\/\/docs.unrealengine.com\/latest\/INT\/Programming\/UnrealArchitecture\/Delegates\/index.html\" target=\"_blank\">here<\/a>.<br \/>\nSo the proper initialization of skill panel with one button inside <em>ACodeTDCharacter<\/em> class will look like this:<\/p>\n[cpp]\nTSharedPtr&lt;SSkillsPanel&gt; SkillsPanel = SNew(SSkillsPanel);<\/p>\n<p>SkillsPanel-&gt;AddSkillButton(FSimpleDelegate::CreateUObject(this, &amp;ACodeTDCharacter::UseAbility1));<br \/>\n[\/cpp]\n<p><\/p>\n<p>Using above code and few tweaks in Style assets you will achieve something like this:<\/p>\n<div style=\"width: 500px; margin: 0 auto; text-align: center; height: 150px\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.michalorzelek.com\/blog\/wp-content\/uploads\/2014\/08\/skillsPanel_oneButton.png\" alt=\"skillsPanel_oneButton\" width=\"66\" height=\"74\" class=\"\" \/><\/p>\n<p><em>Simple button inside Skills Panel<\/em><\/div>\n<p>\nButtons can also display <em>Hotkey text<\/em> (a key that given button is bound to). To set <em>Hotkey text<\/em> for a button you would have to use another <em>AddSkillButton<\/em> function, like this:<br \/>\n[cpp]\nSkillsPanel-&gt;AddSkillButton(FSimpleDelegate::CreateUObject(this, &amp;ACodeTDCharacter::UseAbility1), &quot;1&quot;);<br \/>\n[\/cpp]\n<p><\/p>\n<div style=\"width: 500px; margin: 0 auto; text-align: center; height: 150px\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.michalorzelek.com\/blog\/wp-content\/uploads\/2014\/08\/skillsPanel_oneButton_TextOutside.png\" alt=\"skillsPanel_oneButton_TextOutside\" width=\"67\" height=\"83\" \/><\/p>\n<p><em>Button with hotkey text below it<\/em><\/div>\n<p>You can also make buttons to display their text inside them and control if it should be visible only on hover.<\/p>\n<p><\/p>\n<div style=\"width: 500px; margin: 0 auto; text-align: center; height: 150px\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.michalorzelek.com\/blog\/wp-content\/uploads\/2014\/08\/skillsPanel_oneButton_TextInside.png\" alt=\"skillsPanel_oneButton_TextInside\" width=\"66\" height=\"67\" \/><\/p>\n<p><em>Button that displays Hotkey text inside itself and only on hover.<\/em><\/div>\n<p>Just like resource bars, Panels can be aligned horizontally (default) or vertically by setting Orientation parameter during construction.<\/p>\n<div style=\"width: 500px; margin: 0 auto; text-align: center; height: 420px\">\n<br \/><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.michalorzelek.com\/blog\/wp-content\/uploads\/2014\/08\/skillsPanel2-e1407921472594.png\" alt=\"skillsPanel2\" width=\"260\" height=\"66\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.michalorzelek.com\/blog\/wp-content\/uploads\/2014\/08\/skillsPanel_vertical_Icons-e1407921482686.png\" alt=\"skillsPanel_vertical_Icons\" width=\"71\" height=\"262\"\/><\/p>\n<\/div>\n<p>Other convenient version of <em>AddSkillButton<\/em> function would be<br \/>\n[cpp]\nvoid SSkillsPanel::AddSkillButton(FUIAction InAction)<br \/>\n[\/cpp]\n<p><em>FUIAction<\/em> is a structure commonly used in editor widgets. It contains action that should be executed when <em>Execute<\/em>() is called but also a function to test if this action is available &#8211; <em>CanExecute<\/em>(). More on FUIAction can be found <a href=\"https:\/\/docs.unrealengine.com\/latest\/INT\/API\/Runtime\/Slate\/Framework\/Commands\/FUIAction\/index.html\" target=\"_blank\">here<\/a>.<\/p>\n<p>In this case InAction is an action that will be executed when button is pressed. Button will also check if action can by executed (<em>CanExecute<\/em> function) to determine if it should be disabled or not. Using this function you can for example imitate cooldown for an ability that given button represents.<\/p>\n[cpp]\n\t\/\/ create local struct with static members that we will use for this example<br \/>\n\tstruct Local<br \/>\n\t{<br \/>\n\t\t\/\/ will be called to check if we can execute given action<br \/>\n\t\tstatic bool CanExecute()<br \/>\n\t\t{<br \/>\n\t\t\treturn false;<br \/>\n\t\t}<br \/>\n\t\t\/\/ called on execute (on button click)<br \/>\n\t\tstatic void ExecuteAction()<br \/>\n\t\t{<\/p>\n<p>\t\t}<br \/>\n\t};<\/p>\n<p>\tFUIAction Action = FUIAction(<br \/>\n\t\t\/\/ For this example we&#8217;re using static struct members to define an action<br \/>\n\t\t\/\/ However, you most likely will use your character and\/or skill manager class &#8211; you would then use CreateUObject instead CreateStatic<br \/>\n\t\tFExecuteAction::CreateStatic(&amp;Local::ExecuteAction),<br \/>\n\t\tFCanExecuteAction::CreateStatic(&amp;Local::CanExecute)<br \/>\n\t\t);<\/p>\n<p>\t\/\/ Add button to a panel<br \/>\n\tSkillPanel-&gt;AddSkillButton(Action);<br \/>\n[\/cpp]\n<p><strong>Skills Panel Style<\/strong><\/p>\n<p>In Skills Panel style you can set some basic parameters like: minimum slot height and width, content padding, background brush etc. You can also specify default look of Button Style (<em>ButtonStyle<\/em> variable). <em>ButtonStyle<\/em> will be applied to any button that has no style defined through code. So if you want all buttons in the panel to look the same but only display different hotkey text you would have to do nothing but adding buttons to your Panel.<\/p>\n<p>But most likely, above example wont be useful for anything else than prototyping. You will want to have panel where each button has different icon (representing different skill\/option). To achieve this you can use Skill Buttons Styles array declared in Panel&#8217;s Style. This array will allow you to specify different button Style for each button that will be put inside this panel.<\/p>\n<p>For example: you want to create panel with four buttons and you have created style for each button already. Ability1\/2\/3\/4 are assets names of SkillButtonWidgetStyle.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.michalorzelek.com\/blog\/wp-content\/uploads\/2014\/08\/ButtonStyles.png\" alt=\"ButtonStyles\" width=\"180\" height=\"214\" class=\"alignnone size-full wp-image-553\" \/><\/p>\n<p>Now all you have to do is add those Button styles to mentioned array in panel&#8217;s style.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.michalorzelek.com\/blog\/wp-content\/uploads\/2014\/08\/panelStyle_buttonsStyles.png\" alt=\"panelStyle_buttonsStyles\" width=\"415\" height=\"188\" class=\"alignnone size-full wp-image-552\" \/><\/p>\n<p>So if, in code, you will now call<br \/>\n[cpp]\n\/\/ Will use Ability1 Style<br \/>\nSkillsPanel-&gt;AddSkillButton(FSimpleDelegate::CreateUObject(this, &amp;ACodeTDCharacter::UseAbility1), &quot;1&quot;);<br \/>\n\/\/ Will use Ability2 Style<br \/>\nSkillsPanel-&gt;AddSkillButton(FSimpleDelegate::CreateUObject(this, &amp;ACodeTDCharacter::UseAbility2), &quot;2&quot;);<br \/>\n\/\/ Will use Ability3 Style<br \/>\nSkillsPanel-&gt;AddSkillButton(FSimpleDelegate::CreateUObject(this, &amp;ACodeTDCharacter::UseAbility3), &quot;3&quot;);<br \/>\n\/\/ Will use Ability4 Style<br \/>\nSkillsPanel-&gt;AddSkillButton(FSimpleDelegate::CreateUObject(this, &amp;ACodeTDCharacter::UseAbility4), &quot;4&quot;);<br \/>\n[\/cpp]\n<p>\nFirst button will use first style in Skill Button Styles array in SkillsPanel style. Second button will use second style in Skill Button Styles array in SkillsPanel style. Third button will use third&#8230; you get the idea.<\/p>\n<p>Note that if you have only 3 styles added to the array and you add 4 buttons to the Panel, the fourth button will use default Button Style defined by SkillsPanel Style. <\/p>\n<h2>Example usage<\/h2>\n<p>With help of our graphics designer I was able to create example character panel in a few minutes (I spent most of the time tweaking style parameters of the widgets inside editor). This panel is also created using <em>FUICommands <\/em>that are not fully supported yet so I wont describe it right now.<\/p>\n<p>It&#8217;s a very typical panel where you have two resource bars &#8211; one on the left and right (Armor and Energy). These bars sourrounds two buttons panels &#8211; first, with square buttons and labels represents Abilities, second one (rectangle buttons) is for some options and\/or inventory.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-463\" src=\"https:\/\/www.michalorzelek.com\/blog\/wp-content\/uploads\/2014\/08\/techPanel-512x71.png\" alt=\"techPanel\" width=\"812\" height=\"103\" \/><br \/>\nFrom the left we&#8217;ve got: <em>SResourceBar<\/em>, <em>SkillsPanel<\/em>, <em>SSkillsPanel<\/em> and another <em>SResourceBar<\/em>. All with different styles.<\/p>\n<p>And here you can get a code snippet that generates similar panel:<\/p>\n<div class=\"su-custom-gallery su-custom-gallery-align-left su-custom-gallery-title-hover su-lightbox-gallery\"><div class=\"su-custom-gallery-slide\" style=\"width:650px;height:400px\"><a href=\"https:\/\/www.michalorzelek.com\/blog\/wp-content\/uploads\/2014\/08\/samplePanel.png\" title=\"samplePanel\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.michalorzelek.com\/blog\/wp-content\/uploads\/2014\/08\/samplePanel-650x400.png\" alt=\"samplePanel\" width=\"650\" height=\"400\" \/><span class=\"su-custom-gallery-title\">samplePanel<\/span><\/a><\/div><div class=\"su-clear\"><\/div><\/div>\n[cpp]\n\tTAttribute&lt;float&gt; Value = TAttribute&lt;float&gt;::Create(TAttribute&lt;float&gt;::FGetter::CreateUObject(this, \/** YOUR GETTER FUNCTION HERE *\/ ));<br \/>\n\tTAttribute&lt;float&gt; MaxValue = TAttribute&lt;float&gt;::Create(TAttribute&lt;float&gt;::FGetter::CreateUObject(this, \/** YOUR GETTER FUNCTION HERE *\/ ));<\/p>\n<p>\t\/\/ Create Skill panel<br \/>\n\tTSharedPtr&lt;SSkillsPanel&gt; SkillsPanel = SNew(SSkillsPanel);<\/p>\n<p>\t\/\/ And add some buttons to it<br \/>\n\tSkillsPanel-&gt;AddSkillButton(FSimpleDelegate());<br \/>\n\tSkillsPanel-&gt;AddSkillButton(FSimpleDelegate());<br \/>\n\tSkillsPanel-&gt;AddSkillButton(FSimpleDelegate());<br \/>\n\tSkillsPanel-&gt;AddSkillButton(FSimpleDelegate());<\/p>\n<p>\tGEngine-&gt;GameViewport-&gt;AddViewportWidgetContent(<br \/>\n\t\tSNew(SVerticalBox)<br \/>\n\t\t+ SVerticalBox::Slot()<br \/>\n\t\t.VAlign(VAlign_Bottom)<br \/>\n\t\t.HAlign(HAlign_Center)<br \/>\n\t\t.Padding(15)<br \/>\n\t\t[<br \/>\n\t\t\tSNew(SHorizontalBox)<br \/>\n\t\t\t+ SHorizontalBox::Slot()<br \/>\n\t\t\t.HAlign(HAlign_Right)<br \/>\n\t\t\t.VAlign(VAlign_Bottom)<br \/>\n\t\t\t[<br \/>\n\t\t\t\t\/\/ Add health bar<br \/>\n\t\t\t\tSNew(SResourceBar)<br \/>\n\t\t\t\t.ResourceBarStyle(&amp;FGUIStyle::Get().GetWidgetStyle&lt;FResourceBarWidgetStyle&gt;(&quot;ResourceBar_Sphere&quot;))<br \/>\n\t\t\t\t.Value(Value)<br \/>\n\t\t\t\t.MaxValue(MaxValue)<br \/>\n\t\t\t]\n\t\t\t+ SHorizontalBox::Slot()<br \/>\n\t\t\t\t.AutoWidth()<br \/>\n\t\t\t\t.VAlign(VAlign_Bottom)<br \/>\n\t\t\t\t[<br \/>\n\t\t\t\t\t\/\/ Add skill panel<br \/>\n\t\t\t\t\tSkillsPanel.ToSharedRef()<br \/>\n\t\t\t\t]\n\t\t\t+ SHorizontalBox::Slot()<br \/>\n\t\t\t\t.HAlign(HAlign_Left)<br \/>\n\t\t\t\t.VAlign(VAlign_Bottom)<br \/>\n\t\t\t\t[<br \/>\n\t\t\t\t\t\/\/ Add mana bar<br \/>\n\t\t\t\t\tSNew(SResourceBar)<br \/>\n\t\t\t\t\t.ResourceBarStyle(&amp;FGUIStyle::Get().GetWidgetStyle&lt;FResourceBarWidgetStyle&gt;(&quot;ResourceBar_Sphere&quot;))<br \/>\n\t\t\t\t\t.BarColor(FLinearColor::Blue)<br \/>\n\t\t\t\t\t.Value(Value)<br \/>\n\t\t\t\t\t.MaxValue(MaxValue)<br \/>\n\t\t\t\t]\n<p>\t\t]\n\t);<br \/>\n[\/cpp]\n<p><\/p>\n<h2>Final notes:<\/h2>\n<p><\/p>\n<li>\nThis is still WIP!<\/li>\n<p><\/p>\n<li>\nIn the future I&#8217;m planning to add features like:<br \/>\n\t&#8211; support for <em>FUICommands <\/em>in skills buttons<br \/>\n\t&#8211; connect buttons with bound action so when user pushes a key on a keyboard, button will change it&#8217;s state<br \/>\n\t&#8211; circular resource bars based on parametric materials<br \/>\n\t&#8211; drag&#038;drop support for buttons on skill panel<br \/>\n\t&#8211; many improvements!\n<\/li>\n<p><\/p>\n<li>I didn&#8217;t described all the parameters of all classes in this tutorial, but they are commented quite well in code so you shouldnt have problems with understanding it. <\/li>\n<p><\/p>\n<li>\nAll styles you create and you want to reference through code, using [cpp]FGUIStyle::Get().GetWidgetStyle&lt;&#8230;&gt;(&quot;StyleName&quot;)[\/cpp], must be put inside Content\/UI folder. If for some reason you would like to reference style assets from different directory you will have to create your own SlateStyle class OR feel free to modify lookup path for <em>FGUIStyle <\/em>inside <em>GUIStyle<\/em>.cpp file<\/li>\n<p><\/p>\n<p><em><\/p>\n<p style=\"font-size:10px;\"> All &#8222;skills&#8221; icons used comes from Diablo 3, copyrighted by Blizzard Entertainment.<\/p>\n<p><\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction During game development many tasks can be done simultaneously as long as the team is big enough. Things can get more difficult when you will try to make a game with a handful of friends or on your own. Gameplay design, animations rigging, AI scripting, physics coding, UI creation &#8211; these are the tasks &hellip; <a href=\"https:\/\/www.michalorzelek.com\/blog\/521\/\" class=\"more-link\">Czytaj dalej <span class=\"screen-reader-text\">Tutorial: Custom GUI with Slate Styles<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-521","post","type-post","status-publish","format-standard","hentry","category-tutorials"],"_links":{"self":[{"href":"https:\/\/www.michalorzelek.com\/blog\/wp-json\/wp\/v2\/posts\/521","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.michalorzelek.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.michalorzelek.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.michalorzelek.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.michalorzelek.com\/blog\/wp-json\/wp\/v2\/comments?post=521"}],"version-history":[{"count":53,"href":"https:\/\/www.michalorzelek.com\/blog\/wp-json\/wp\/v2\/posts\/521\/revisions"}],"predecessor-version":[{"id":605,"href":"https:\/\/www.michalorzelek.com\/blog\/wp-json\/wp\/v2\/posts\/521\/revisions\/605"}],"wp:attachment":[{"href":"https:\/\/www.michalorzelek.com\/blog\/wp-json\/wp\/v2\/media?parent=521"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.michalorzelek.com\/blog\/wp-json\/wp\/v2\/categories?post=521"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.michalorzelek.com\/blog\/wp-json\/wp\/v2\/tags?post=521"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}