Vulkan Schnee 0.0.1 (22840dc8)
High-performance rendering engine
Loading...
Searching...
No Matches
WidgetComponent.h
1#pragma once
2
3#include "Engine/Component/LogicComponent.h"
4#include "Engine/Asset/AssetHandles.h"
5
6#include <array>
7#include <cstdint>
8#include <glm/vec3.hpp>
9#include <limits>
10#include <optional>
11#include <string>
12#include <unordered_map>
13#include <vector>
14
15namespace Engine::Components
16{
22 class WidgetComponent : public Logic
23 {
24 public:
29 {
30 uint32_t width = 1024;
31 uint32_t height = 512;
32 };
33
35 {
36 float rounding = 0.0f;
37 float borderSize = 0.0f;
38 std::array<float, 4> backgroundColor{ 0.02f, 0.02f, 0.025f, 1.0f };
39 std::array<float, 4> borderColor{ 1.0f };
40 };
41
42 static constexpr bool IsUnique = false;
43
47 explicit WidgetComponent( Entities::Scene * scene );
48
49 void beginPlay() override;
50 void endPlay() override;
51
52 [[nodiscard]] std::string getComponentName() const override;
53
57 [[nodiscard]] Resolution getRequestedResolution() const;
58
62 void setRequestedResolution( uint32_t width, uint32_t height );
63
67 void setPixelsPerMeter( float pixelsPerMeter );
68
72 [[nodiscard]] glm::vec3 getPlaneScale() const;
73
77 [[nodiscard]] bool isWorldUiActive() const;
78
82 void setWorldUiActive( bool active );
83
87 [[nodiscard]] uint32_t getWorldUiDescriptorIndex() const;
88
92 void setWorldUiDescriptorIndex( uint32_t descriptorIndex );
93
98
100 [[nodiscard]] const std::optional<WorldUiWindowStyle> & getWorldUiWindowStyle() const;
101
105 virtual void drawRuntimeImGui();
106
111
115 [[nodiscard]] uint64_t getWorldUiTextureId( Assets::Texture2DHandle handle ) const;
116
117 [[nodiscard]] const std::vector<Assets::Texture2DHandle> & getRequestedWorldUiTextures() const;
118 void setWorldUiTextureId( Assets::Texture2DHandle handle, uint64_t textureId );
119
124
129
134
135 private:
137 float pixelsPerMeter_ = 750.0f;
138 bool active_ = true;
139 uint32_t descriptorIndex_ = std::numeric_limits<uint32_t>::max();
140 std::optional<WorldUiWindowStyle> worldUiWindowStyle_;
141 std::vector<Assets::Texture2DHandle> requestedTextures_;
142 std::unordered_map<uint32_t, uint64_t> worldUiTextureIds_;
143
145 int credits_ = 120;
147 };
148} // namespace Engine::Components
Logic(Entities::Scene *owningScene)
Constructs a logic component owned by a scene.
void setWorldUiTextureId(Assets::Texture2DHandle handle, uint64_t textureId)
uint32_t getWorldUiDescriptorIndex() const
Returns the texture descriptor index assigned to this widget.
void setWorldUiDescriptorIndex(uint32_t descriptorIndex)
Stores the texture descriptor index assigned by the world UI renderer.
void setPixelsPerMeter(float pixelsPerMeter)
Sets the density used to map widget pixels onto a 1m x 1m plane.
void buySelectedUpgrade()
Attempts to purchase the currently selected demo upgrade.
void selectPreviousUpgrade()
Selects the previous upgrade entry in the demo widget state.
void selectNextUpgrade()
Selects the next upgrade entry in the demo widget state.
const std::vector< Assets::Texture2DHandle > & getRequestedWorldUiTextures() const
void setWorldUiActive(bool active)
Enables or disables world UI rendering for this widget.
Resolution getRequestedResolution() const
Returns the requested offscreen render target resolution.
virtual void drawRuntimeImGui()
Draws this widget's runtime ImGui content into the active ImGui context.
void endPlay() override
Called when the component is removed or the game ends.
WidgetComponent(Entities::Scene *scene)
Creates a widget component attached to a scene.
void clearWorldUiDescriptorIndex()
Clears the assigned world UI texture descriptor index.
static constexpr bool IsUnique
Widget components are allowed to have multiple instances per entity.
std::string getComponentName() const override
Gets the component type name for debugging/UI.
void requestWorldUiTexture(Assets::Texture2DHandle handle)
Makes a loaded engine texture available to this widget's ImGui draw calls.
uint64_t getWorldUiTextureId(Assets::Texture2DHandle handle) const
Returns the ImGui texture ID assigned by the world UI renderer, or zero while loading.
std::optional< WorldUiWindowStyle > worldUiWindowStyle_
void setRequestedResolution(uint32_t width, uint32_t height)
Sets the requested offscreen render target resolution.
const std::optional< WorldUiWindowStyle > & getWorldUiWindowStyle() const
std::vector< Assets::Texture2DHandle > requestedTextures_
std::unordered_map< uint32_t, uint64_t > worldUiTextureIds_
bool isWorldUiActive() const
Returns whether this widget should be rendered into world UI.
glm::vec3 getPlaneScale() const
Returns the scale for a unit XZ plane at the requested resolution and pixel density.
void beginPlay() override
Called when the component is added to the scene or the game starts.
void setWorldUiWindowStyle(WorldUiWindowStyle style)
Owns scene entities, actor lifetime, and the scene graph root.
Definition Scene.h:84
AssetHandle< Texture2DHandleTag > Texture2DHandle
Handle to a file-backed sampled 2D texture.
Requested render-target size for the widget texture.
uint32_t width
Requested texture width in pixels.
uint32_t height
Requested texture height in pixels.