Skip to content

Commit 075cc5f

Browse files
PurscheNixAJ
andauthored
Pursche/CanvasRenderer (#45)
* Rewrote UI rendering and made it Lua driven * Added support for 'require' in Lua * Better input events * Added UI Stack * Added various basic UI widgets implemented in Lua * Added Loading screen support in Lua * Updated Engine submodule Co-authored-by: NixAJ <[email protected]>
1 parent 11ba8e1 commit 075cc5f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+9006
-2471
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
*.app
3232

3333
build*/
34+
Build*/
3435
.vs/
3536
.vscode/
3637
out/

CREDITS

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
We would like to extend our gratitude to the following individuals and/or organisations for being part of the process to make Novus better in one way or another.
2+
3+
- Our Team (Pursche, Foe, Nix)
4+
- Our Contributors (Skarn, Elntemporel, ReynoldsCahoon, Deamon, Balkron, Skypjack, Minitbnn, Dmitry, Grim, Vblanco)
5+
- Eluna (https://github.com/ElunaLuaEngine/Eluna)

Source/Game-Lib/Game-Lib/Application/Application.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ bool Application::Init()
239239
ServiceLocator::SetTaskScheduler(_taskScheduler);
240240

241241
_registries.gameRegistry = new entt::registry();
242+
_registries.uiRegistry = new entt::registry();
242243
_registries.eventIncomingRegistry = new entt::registry();
243244
_registries.eventOutgoingRegistry = new entt::registry();
244245
ServiceLocator::SetEnttRegistries(&_registries);
@@ -262,7 +263,7 @@ bool Application::Init()
262263
ServiceLocator::SetEditorHandler(_editorHandler);
263264

264265
_ecsScheduler = new ECS::Scheduler();
265-
_ecsScheduler->Init(*_registries.gameRegistry);
266+
_ecsScheduler->Init(_registries);
266267

267268
ServiceLocator::SetGameConsole(new GameConsole());
268269

@@ -471,7 +472,7 @@ bool Application::Tick(f32 deltaTime)
471472
}
472473
}
473474

474-
_ecsScheduler->Update(*_registries.gameRegistry, deltaTime);
475+
_ecsScheduler->Update(_registries, deltaTime);
475476

476477
// Handle Double Buffered Event Swap
477478
{

Source/Game-Lib/Game-Lib/Application/EnttRegistries.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
struct EnttRegistries
55
{
6-
entt::registry* gameRegistry;
7-
entt::registry* eventIncomingRegistry;
8-
entt::registry* eventOutgoingRegistry;
6+
entt::registry* gameRegistry;
7+
entt::registry* uiRegistry;
8+
entt::registry* eventIncomingRegistry;
9+
entt::registry* eventOutgoingRegistry;
910
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#pragma once
2+
#include <Base/Types.h>
3+
4+
namespace ECS::Components::UI
5+
{
6+
struct BoundingRect
7+
{
8+
public:
9+
vec2 min;
10+
vec2 max;
11+
};
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#pragma once
2+
#include <Base/Types.h>
3+
4+
namespace ECS::Components::UI
5+
{
6+
struct Canvas
7+
{
8+
public:
9+
10+
};
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#pragma once
2+
#include <Base/Types.h>
3+
4+
namespace ECS::Components::UI
5+
{
6+
struct EventInputInfo
7+
{
8+
public:
9+
bool isHovered = false;
10+
bool isClicked = false;
11+
bool isInteractable = true;
12+
13+
// Templates
14+
u32 onClickTemplateHash = 0;
15+
u32 onHoverTemplateHash = 0;
16+
u32 onUninteractableTemplateHash = 0;
17+
18+
// Lua Event Refs
19+
i32 onMouseDownEvent = -1;
20+
i32 onMouseUpEvent = -1;
21+
i32 onMouseHeldEvent = -1;
22+
23+
i32 onHoverBeginEvent = -1;
24+
i32 onHoverEndEvent = -1;
25+
i32 onHoverHeldEvent = -1;
26+
27+
i32 onFocusBeginEvent = -1;
28+
i32 onFocusEndEvent = -1;
29+
i32 onFocusHeldEvent = -1;
30+
31+
i32 onKeyboardEvent = -1;
32+
};
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#pragma once
2+
#include <Base/Types.h>
3+
4+
namespace ECS::Components::UI
5+
{
6+
struct Panel
7+
{
8+
public:
9+
u32 layer;
10+
11+
u32 templateIndex;
12+
13+
i32 gpuVertexIndex = -1;
14+
i32 gpuDataIndex = -1;
15+
};
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#pragma once
2+
#include "Game-Lib/UI/Box.h"
3+
4+
#include <Base/Math/Color.h>
5+
#include <Base/Types.h>
6+
7+
#include <optional>
8+
9+
namespace ECS::Components::UI
10+
{
11+
struct PanelTemplate
12+
{
13+
public:
14+
struct SetFlags
15+
{
16+
u8 background : 1 = 0;
17+
u8 foreground : 1 = 0;
18+
u8 color : 1 = 0;
19+
u8 cornerRadius : 1 = 0;
20+
u8 texCoords : 1 = 0;
21+
u8 nineSliceCoords : 1 = 0;
22+
};
23+
SetFlags setFlags;
24+
25+
std::string background;
26+
std::string foreground;
27+
Color color;
28+
f32 cornerRadius;
29+
::UI::Box texCoords;
30+
::UI::Box nineSliceCoords;
31+
32+
std::string onClickTemplate;
33+
std::string onHoverTemplate;
34+
std::string onUninteractableTemplate;
35+
36+
i32 onMouseDownEvent = -1;
37+
i32 onMouseUpEvent = -1;
38+
i32 onMouseHeldEvent = -1;
39+
40+
i32 onHoverBeginEvent = -1;
41+
i32 onHoverEndEvent = -1;
42+
i32 onHoverHeldEvent = -1;
43+
44+
i32 onFocusBeginEvent = -1;
45+
i32 onFocusEndEvent = -1;
46+
i32 onFocusHeldEvent = -1;
47+
};
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#pragma once
2+
#include <Base/Types.h>
3+
4+
namespace ECS::Components::UI
5+
{
6+
struct Text
7+
{
8+
public:
9+
std::string text;
10+
u32 layer;
11+
12+
u32 templateIndex;
13+
14+
i32 gpuVertexIndex = -1;
15+
i32 gpuDataIndex = -1;
16+
17+
i32 numCharsNonWhitespace = -1;
18+
19+
bool hasGrown = false;
20+
bool sizeChanged = true;
21+
};
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#pragma once
2+
#include "Game-Lib/UI/Box.h"
3+
4+
#include <Base/Math/Color.h>
5+
#include <Base/Types.h>
6+
7+
namespace ECS::Components::UI
8+
{
9+
struct TextTemplate
10+
{
11+
public:
12+
struct SetFlags
13+
{
14+
u8 font : 1 = 0;
15+
u8 size : 1 = 0;
16+
u8 color : 1 = 0;
17+
u8 borderSize : 1 = 0;
18+
u8 borderColor : 1 = 0;
19+
};
20+
SetFlags setFlags;
21+
22+
std::string font;
23+
f32 size;
24+
Color color;
25+
f32 borderSize;
26+
Color borderColor;
27+
28+
std::string onClickTemplate;
29+
std::string onHoverTemplate;
30+
std::string onUninteractableTemplate;
31+
32+
i32 onMouseDownEvent = -1;
33+
i32 onMouseUpEvent = -1;
34+
i32 onMouseHeldEvent = -1;
35+
36+
i32 onHoverBeginEvent = -1;
37+
i32 onHoverEndEvent = -1;
38+
i32 onHoverHeldEvent = -1;
39+
40+
i32 onFocusBeginEvent = -1;
41+
i32 onFocusEndEvent = -1;
42+
i32 onFocusHeldEvent = -1;
43+
};
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#pragma once
2+
#include <Base/Types.h>
3+
4+
namespace Scripting::UI
5+
{
6+
struct Widget;
7+
}
8+
9+
namespace ECS::Components::UI
10+
{
11+
enum class WidgetType : u8
12+
{
13+
Canvas,
14+
Panel,
15+
Text,
16+
Widget,
17+
18+
None
19+
};
20+
21+
enum class WidgetFlags : u8
22+
{
23+
None = 0,
24+
25+
Enabled = 1 << 0,
26+
Visible = 1 << 1,
27+
Interactable = 1 << 2,
28+
Focusable = 1 << 3,
29+
Resizable = 1 << 4,
30+
31+
Default = Enabled | Visible | Interactable,
32+
};
33+
DECLARE_GENERIC_BITWISE_OPERATORS(WidgetFlags);
34+
35+
struct Widget
36+
{
37+
public:
38+
WidgetType type;
39+
WidgetFlags flags = WidgetFlags::Default;
40+
Scripting::UI::Widget* scriptWidget = nullptr;
41+
42+
// Non mutable helper functions
43+
inline bool IsEnabled() const { return (flags & WidgetFlags::Enabled) == WidgetFlags::Enabled; }
44+
inline bool IsVisible() const { return IsEnabled() && (flags & WidgetFlags::Visible) == WidgetFlags::Visible; }
45+
inline bool IsInteractable() const { return IsVisible() && (flags & WidgetFlags::Interactable) == WidgetFlags::Interactable; }
46+
inline bool IsFocusable() const { return IsInteractable() && (flags & WidgetFlags::Focusable) == WidgetFlags::Focusable; }
47+
inline bool IsResizable() const { return IsInteractable() && (flags & WidgetFlags::Resizable) == WidgetFlags::Resizable; }
48+
};
49+
50+
struct WidgetRoot {};
51+
struct DirtyWidgetTransform {};
52+
struct DirtyWidgetData {};
53+
struct DirtyWidgetFlags {};
54+
}

0 commit comments

Comments
 (0)