I want to make my own button class, complete with images, text, and mouse hit-detection. But I don’t want to have to do this using Slate, which is cumbersome.
If only there were someone out there who offered thorough and exhaustive tutorials at every opportunity!
This is a fully functional plug and
play HUD class of more than 800 lines
of C++ code for you to use as a
template for your UE4 projects, enjoy!
My solution does not use a button class, I use a USTRUCT() instead, because this is more streamlined given the way I setup the rest of my HUD code, and because the amount of data I store in a button is tiny.
If you choose to implement a button class to make the drawing of the title and the background of the button more connected to the actual button boundaries feel free to post your modified version
In this tutorial I am giving you a fully functional 800+ lines of sample HUD class that features
-multiple convenience functions for
=== Drawing ===
drawing textures
drawing materials
drawing lines
drawing rectangles
drawing text
The functions use the new UE4 method of using CanvasItems.
=== Centering ==
how to draw stuff centered in the screen (used by confirm dialog)
=== Rest of Game Code Integration ===
I have code in the tutorial to show you how to get a reference to your custom PC or Character class from within the HUD.
From your PC reference you can get access to your custom Game Mode and Game State classes (using the Cast<> code I show in tutorial PostInit)
=== Player Keyboard,Mouse,Controller Input ===
How to capture player key presses for ANY key,mouse,controller that you want from within the HUD
in this tutorial code,
ESC: clears the screen lock so camera will move with cursor.
F: Toggle screen lock so only the cursor moves as player moves the mouse.
H: Toggles hiding the HUD
LMB: Clicks on buttons
Y: Confirm yes if confirm dialog open
N: Cancel if confirm dialog is open
=== Text Size ==
How to measure text, accounting for scaling and font size, to size backgrounds,buttons,tooltips appropriately
=== Buttons ===
a button system and corresponding USTRUCT
=== Cursor ===
how to draw cursor that player can move in-game
how to change cursor when hovering over button
=== Tooltips ===
button tooltips
== Drawing Images/Textures/Materials ===
drawing custom button and menu backgrounds that come from textures/materials
how to stop camera from moving as player moves mouse cursor in-game