Added Sliders. Added Level Select, How To Play,. Credits Options Canvases layout for in main menu. Added Tweening Manager(Script) #369
|
@ -0,0 +1,12 @@
|
|||
- VertexShader: 46580970
|
||||
FragmentShader: 48832081
|
||||
SubPass: UI
|
||||
Properties:
|
||||
data.color: {x: 1, y: 1, z: 1, w: 1}
|
||||
data.textureIndex: 64651793
|
||||
data.alpha: 0
|
||||
data.beta: {x: 1, y: 1, z: 1}
|
||||
data.sliderThreshold: 1
|
||||
data.sliderStartColor: {x: 0, y: 1, z: 0, w: 1}
|
||||
data.sliderEndColor: {x: 1, y: 0, z: 0, w: 1}
|
||||
data.sliderBarColor: {x: 1, y: 1, z: 1, w: 1}
|
|
@ -0,0 +1,3 @@
|
|||
Name: UIMat_Slider
|
||||
ID: 128676209
|
||||
Type: 7
|
|
@ -1,7 +1,7 @@
|
|||
- EID: 0
|
||||
Name: Canvas
|
||||
Name: MainMenu Canvas
|
||||
IsActive: true
|
||||
NumberOfChildren: 3
|
||||
NumberOfChildren: 4
|
||||
Components:
|
||||
Canvas Component:
|
||||
Canvas Width: 1920
|
||||
|
@ -15,7 +15,7 @@
|
|||
NumberOfChildren: 0
|
||||
Components:
|
||||
Transform Component:
|
||||
Translate: {x: 0, y: 0, z: 0.5}
|
||||
Translate: {x: 0, y: 5, z: 0.5}
|
||||
Rotate: {x: 0, y: 0, z: 0}
|
||||
Scale: {x: 1920, y: 1080, z: 1}
|
||||
IsActive: true
|
||||
|
@ -84,6 +84,29 @@
|
|||
Scripts:
|
||||
- Type: QuitButton
|
||||
Enabled: true
|
||||
- EID: 7
|
||||
Name: Slider
|
||||
IsActive: false
|
||||
NumberOfChildren: 0
|
||||
Components:
|
||||
Transform Component:
|
||||
Translate: {x: 0, y: -56, z: 0}
|
||||
Rotate: {x: 0, y: 0, z: 0}
|
||||
Scale: {x: 500, y: 100, z: 1}
|
||||
IsActive: false
|
||||
Renderable Component:
|
||||
Mesh: 141771688
|
||||
Material: 128676209
|
||||
IsActive: false
|
||||
Slider Component:
|
||||
Slider Value: 0
|
||||
IsActive: false
|
||||
UI Component:
|
||||
Canvas ID: 0
|
||||
Hovered: false
|
||||
Clicked: false
|
||||
IsActive: false
|
||||
Scripts: ~
|
||||
- EID: 2
|
||||
Name: Light
|
||||
IsActive: true
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
#version 450
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
#extension GL_ARB_shading_language_420pack : enable
|
||||
#extension GL_EXT_nonuniform_qualifier : require
|
||||
|
||||
struct MatPropData
|
||||
{
|
||||
int textureIndex;
|
||||
float alpha;
|
||||
float sliderThreshold;
|
||||
vec4 sliderStartColor;
|
||||
vec4 sliderEndColor;
|
||||
vec4 sliderBarColor;
|
||||
};
|
||||
|
||||
layout(location = 0) in struct
|
||||
{
|
||||
vec4 vertPos; // location 0
|
||||
vec2 uv; // location = 1
|
||||
vec4 normal; // location = 2
|
||||
|
||||
} In;
|
||||
|
||||
// material stuff
|
||||
layout(location = 3) flat in struct
|
||||
{
|
||||
int materialIndex;
|
||||
uint eid;
|
||||
uint lightLayerIndex;
|
||||
|
||||
} In2;
|
||||
|
||||
layout (set = 0, binding = 1) uniform sampler2D textures[]; // for textures (global)
|
||||
layout (std430, set = 2, binding = 0) buffer MaterialProperties // For materials
|
||||
{
|
||||
MatPropData data[];
|
||||
} MatProp;
|
||||
|
||||
layout(location = 0) out vec4 fragColor;
|
||||
layout(location = 1) out uint outEntityID;
|
||||
|
||||
void main()
|
||||
{
|
||||
//fragColor = texture(textures[nonuniformEXT(MatProp.data[In2.materialIndex].textureIndex)], In.uv);
|
||||
if (fragColor.a < 0.01f)
|
||||
{
|
||||
discard;
|
||||
}
|
||||
if (In.uv.x > MatProp.data[In2.materialIndex].sliderThreshold)
|
||||
fragColor = MatProp.data[In2.materialIndex].sliderBarColor;
|
||||
else
|
||||
fragColor = (1.0f - In.uv.x) * MatProp.data[In2.materialIndex].sliderStartColor + In.uv.x * MatProp.data[In2.materialIndex].sliderEndColor;
|
||||
//fragColor = texture(textures[nonuniformEXT(MatProp.data[In2.materialIndex].textureIndex)], In.uv);
|
||||
|
||||
|
||||
fragColor.a = MatProp.data[In2.materialIndex].alpha;
|
||||
|
||||
// fragColor.a = 1.0f;
|
||||
outEntityID = In2.eid;
|
||||
}
|
Binary file not shown.
|
@ -0,0 +1,3 @@
|
|||
Name: UI_Slider_FS
|
||||
ID: 48832081
|
||||
Type: 2
|
|
@ -22,6 +22,7 @@
|
|||
#include "UI/SHCanvasComponent.h"
|
||||
#include "UI/SHButtonComponent.h"
|
||||
#include "UI/SHToggleButtonComponent.h"
|
||||
#include "UI/SHSliderComponent.h"
|
||||
#include "SHEditorComponentView.h"
|
||||
#include "AudioSystem/SHAudioListenerComponent.h"
|
||||
#include "Graphics/MiddleEnd/TextRendering/SHTextRenderableComponent.h"
|
||||
|
@ -170,6 +171,9 @@ namespace SHADE
|
|||
if (auto toggleButton = SHComponentManager::GetComponent_s<SHToggleButtonComponent>(eid))
|
||||
{
|
||||
DrawComponent(toggleButton);
|
||||
}if (auto slider = SHComponentManager::GetComponent_s<SHSliderComponent>(eid))
|
||||
{
|
||||
DrawComponent(slider);
|
||||
}
|
||||
ImGui::Separator();
|
||||
// Render Scripts
|
||||
|
@ -185,6 +189,7 @@ namespace SHADE
|
|||
DrawAddComponentButton<SHCanvasComponent>(eid);
|
||||
DrawAddComponentButton<SHButtonComponent>(eid);
|
||||
DrawAddComponentButton<SHToggleButtonComponent>(eid);
|
||||
DrawAddComponentButton<SHSliderComponent>(eid);
|
||||
|
||||
// Components that require Transforms
|
||||
|
||||
|
|
|
@ -209,6 +209,7 @@ namespace SHADE
|
|||
AddComponentToComponentNode<SHCanvasComponent>(components, eid);
|
||||
AddComponentToComponentNode<SHButtonComponent>(components, eid);
|
||||
AddComponentToComponentNode<SHToggleButtonComponent>(components, eid);
|
||||
AddComponentToComponentNode<SHSliderComponent>(components, eid);
|
||||
|
||||
AddComponentToComponentNode<SHTextRenderableComponent>(components, eid);
|
||||
AddComponentToComponentNode<SHAnimatorComponent>(components, eid);
|
||||
|
@ -269,6 +270,7 @@ namespace SHADE
|
|||
AddComponentID<SHCanvasComponent>(componentIDList, componentsNode);
|
||||
AddComponentID<SHButtonComponent>(componentIDList, componentsNode);
|
||||
AddComponentID<SHToggleButtonComponent>(componentIDList, componentsNode);
|
||||
AddComponentID<SHSliderComponent>(componentIDList, componentsNode);
|
||||
AddComponentID<SHTextRenderableComponent>(componentIDList, componentsNode);
|
||||
AddComponentID<SHAnimatorComponent>(componentIDList, componentsNode);
|
||||
AddComponentID<SHUIComponent>(componentIDList, componentsNode);
|
||||
|
@ -353,6 +355,7 @@ namespace SHADE
|
|||
SHSerializationHelper::InitializeComponentFromNode<SHCanvasComponent>(componentsNode, eid);
|
||||
SHSerializationHelper::InitializeComponentFromNode<SHButtonComponent>(componentsNode, eid);
|
||||
SHSerializationHelper::InitializeComponentFromNode<SHToggleButtonComponent>(componentsNode, eid);
|
||||
SHSerializationHelper::InitializeComponentFromNode<SHSliderComponent>(componentsNode, eid);
|
||||
SHSerializationHelper::InitializeComponentFromNode<SHTextRenderableComponent>(componentsNode, eid);
|
||||
SHSerializationHelper::InitializeComponentFromNode<SHLightComponent>(componentsNode, eid);
|
||||
SHSerializationHelper::InitializeComponentFromNode<SHAnimatorComponent>(componentsNode, eid);
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
namespace SHADE
|
||||
{
|
||||
SHSliderComponent::SHSliderComponent()
|
||||
:size(1.0f), isHovered(false), isClicked(false), value(0.0f)
|
||||
:value(0.0f)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -17,8 +17,6 @@ namespace SHADE
|
|||
SHSliderComponent();
|
||||
virtual ~SHSliderComponent() = default;
|
||||
|
||||
SHVec2 size;
|
||||
|
||||
|
||||
float GetValue() const noexcept;
|
||||
|
||||
|
@ -29,8 +27,7 @@ namespace SHADE
|
|||
friend class SHUISystem;
|
||||
private:
|
||||
|
||||
bool isHovered;
|
||||
bool isClicked;
|
||||
|
||||
|
||||
float value;
|
||||
|
||||
|
|
|
@ -377,6 +377,77 @@ namespace SHADE
|
|||
}
|
||||
|
||||
|
||||
void SHUISystem::UpdateSliderComponent(SHSliderComponent& comp) noexcept
|
||||
{
|
||||
|
||||
|
||||
if (!SHComponentManager::HasComponent<SHUIComponent>(comp.GetEID()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
auto cameraSystem = SHSystemManager::GetSystem<SHCameraSystem>();
|
||||
auto uiComp = SHComponentManager::GetComponent<SHUIComponent>(comp.GetEID());
|
||||
//auto canvasComp = SHComponentManager::GetComponent_s<SHCanvasComponent>(uiComp->canvasID);
|
||||
|
||||
float tempValue = comp.GetValue();
|
||||
|
||||
CheckButtonHoveredOrClicked(*uiComp);
|
||||
|
||||
if (uiComp->GetIsClicked() == true)
|
||||
{
|
||||
SHVec4 topExtent4 = SHMatrix::Translate(-uiComp->size.x * 0.5f, uiComp->size.y * 0.5f, 0.0f) * uiComp->GetMatrix() * SHVec4(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
SHVec4 btmExtent4 = SHMatrix::Translate(uiComp->size.x * 0.5f, -uiComp->size.y * 0.5f, 0.0f) * uiComp->GetMatrix() * SHVec4(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
|
||||
|
||||
SHVec2 topExtent{ topExtent4.x,topExtent4.y };
|
||||
SHVec2 btmExtent{ btmExtent4.x,btmExtent4.y };
|
||||
auto cameraSystem = SHSystemManager::GetSystem<SHCameraSystem>();
|
||||
SHVec2 mousePos;
|
||||
SHVec2 windowSize;
|
||||
#ifdef SHEDITOR
|
||||
windowSize = SHEditorWindowManager::GetEditorWindow<SHEditorViewport>()->beginContentRegionAvailable;
|
||||
mousePos = SHEditorWindowManager::GetEditorWindow<SHEditorViewport>()->viewportMousePos;
|
||||
mousePos /= windowSize;
|
||||
#else
|
||||
int x, y;
|
||||
SHInputManager::GetMouseScreenPosition(&x, &y);
|
||||
mousePos.x = x;
|
||||
mousePos.y = y;
|
||||
auto ws = SHSystemManager::GetSystem<SHGraphicsSystem>()->GetWindow()->GetWindowSize();
|
||||
windowSize = { static_cast<float>(ws.first), static_cast<float>(ws.second) };
|
||||
mousePos /= windowSize;
|
||||
#endif
|
||||
|
||||
SHVec2 camSize{ cameraSystem->GetCameraWidthHeight(0) };
|
||||
//SHLOG_INFO("TopExtent: {}, {}", topExtent.x, topExtent.y)
|
||||
|
||||
topExtent = CanvasToScreenPoint(topExtent, true);
|
||||
btmExtent = CanvasToScreenPoint(btmExtent, true);
|
||||
|
||||
|
||||
comp.value = (mousePos.x - topExtent.x) / (btmExtent.x - topExtent.x);
|
||||
|
||||
if (comp.GetValue() > 1.0f)
|
||||
comp.value = 1.0f;
|
||||
if (comp.GetValue() < 0.0f)
|
||||
comp.value = 0.0f;
|
||||
}
|
||||
|
||||
if (comp.GetValue() != tempValue)
|
||||
{
|
||||
//Set shader value.
|
||||
|
||||
auto renderable = SHComponentManager::GetComponent_s<SHRenderable>(comp.GetEID());
|
||||
//auto texture = SHResourceManager::Get<SHTexture>(comp.GetDefaultTexture());
|
||||
auto material = renderable->GetModifiableMaterial();
|
||||
|
||||
material->SetProperty("data.sliderThreshold", comp.GetValue());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void SHUISystem::UpdateButtonsRoutine::Execute(double dt) noexcept
|
||||
{
|
||||
SHUISystem* system = (SHUISystem*)GetSystem();
|
||||
|
@ -395,6 +466,13 @@ namespace SHADE
|
|||
if (SHSceneManager::CheckNodeAndComponentsActive<SHToggleButtonComponent>(comp.GetEID()))
|
||||
system->UpdateToggleButtonComponent(comp);
|
||||
}
|
||||
|
||||
auto& sliderDense = SHComponentManager::GetDense<SHSliderComponent>();
|
||||
for (auto& comp : sliderDense)
|
||||
{
|
||||
if (SHSceneManager::CheckNodeAndComponentsActive<SHSliderComponent>(comp.GetEID()))
|
||||
system->UpdateSliderComponent(comp);
|
||||
}
|
||||
}
|
||||
|
||||
SHVec2 SHUISystem::CanvasToScreenPoint(SHVec2& const canvasPoint, bool normalized) noexcept
|
||||
|
|
|
@ -74,7 +74,7 @@ namespace SHADE
|
|||
void UpdateButtonComponent(SHButtonComponent& comp) noexcept;
|
||||
void UpdateToggleButtonComponent(SHToggleButtonComponent& comp) noexcept;
|
||||
void UpdateCanvasComponent(SHCanvasComponent& comp) noexcept;
|
||||
|
||||
void UpdateSliderComponent(SHSliderComponent& comp) noexcept;
|
||||
//returns true on button release.
|
||||
bool CheckButtonHoveredOrClicked(SHUIComponent& comp) noexcept;
|
||||
|
||||
|
|
Loading…
Reference in New Issue