Added static class Settings to scripts #400

Merged
maverickdgg merged 1 commits from SP3-20-UI-System into main 2023-03-07 14:44:33 +08:00
11 changed files with 291 additions and 26 deletions

View File

@ -517,7 +517,14 @@
Canvas Height: 1080
Scale by canvas width: false
IsActive: false
Scripts: ~
Scripts:
- Type: SHADE_Scripting.UI.Options
Enabled: true
masterVolSlider: 29
sfxVolSlider: 30
bgmVolSlider: 31
fovSlider: 37
sensitivitySlider: 38
- EID: 20
Name: BackGround
IsActive: true
@ -732,6 +739,8 @@
IsActive: true
Slider Component:
Slider Value: 1
Min Value: 0
Max Value: 100
IsActive: true
UI Component:
Canvas ID: 19
@ -755,6 +764,8 @@
IsActive: true
Slider Component:
Slider Value: 1
Min Value: 0
Max Value: 100
IsActive: true
UI Component:
Canvas ID: 19
@ -778,6 +789,8 @@
IsActive: true
Slider Component:
Slider Value: 1
Min Value: 0
Max Value: 100
IsActive: true
UI Component:
Canvas ID: 19
@ -810,7 +823,7 @@
- EID: 33
Name: Camera Text Group
IsActive: true
NumberOfChildren: 2
NumberOfChildren: 4
Components:
Transform Component:
Translate: {x: -900, y: -220, z: 0}
@ -867,10 +880,54 @@
Clicked: false
IsActive: true
Scripts: ~
- EID: 449
Name: Camera Invert X Text
IsActive: false
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 0, y: -200, z: 0.100000001}
Rotate: {x: 0, y: 0, z: 0}
Scale: {x: 75, y: 75, z: 1}
IsActive: false
Text Renderer Component:
Text: "Camera Invert X:"
Font: 174412429
Color: {x: 0, y: 0, z: 0, w: 1}
Text Size: {x: 1, y: 1, z: 1}
IsActive: false
UI Component:
Canvas ID: 19
Hovered: false
Clicked: false
IsActive: false
Scripts: ~
- EID: 447
Name: Camera Invert Y Text
IsActive: false
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 800, y: -200, z: 0.100000001}
Rotate: {x: 0, y: 0, z: 0}
Scale: {x: 75, y: 75, z: 1}
IsActive: false
Text Renderer Component:
Text: "Y:"
Font: 174412429
Color: {x: 0, y: 0, z: 0, w: 1}
Text Size: {x: 1, y: 1, z: 1}
IsActive: false
UI Component:
Canvas ID: 19
Hovered: false
Clicked: false
IsActive: false
Scripts: ~
- EID: 36
Name: Camera Slider Group
IsActive: true
NumberOfChildren: 2
NumberOfChildren: 4
Components:
Transform Component:
Translate: {x: 100, y: -200, z: 0}
@ -899,6 +956,8 @@
IsActive: true
Slider Component:
Slider Value: 1
Min Value: 45
Max Value: 120
IsActive: true
UI Component:
Canvas ID: 19
@ -922,6 +981,8 @@
IsActive: true
Slider Component:
Slider Value: 1
Min Value: 0
Max Value: 100
IsActive: true
UI Component:
Canvas ID: 19
@ -929,6 +990,56 @@
Clicked: false
IsActive: true
Scripts: ~
- EID: 448
Name: Invert X Toggle Button
IsActive: false
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: -300, y: -200, z: 0}
Rotate: {x: 0, y: 0, z: 0}
Scale: {x: 75, y: 75, z: 1}
IsActive: false
Renderable Component:
Mesh: 141771688
Material: 129340704
IsActive: false
Toggle Button Component:
Non Toggled Texture: 55358401
Toggled Texture: 52333376
Value: false
IsActive: false
UI Component:
Canvas ID: 19
Hovered: false
Clicked: false
IsActive: false
Scripts: ~
- EID: 445
Name: Invert Y Toggle Button
IsActive: false
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: -50, y: -200, z: 0}
Rotate: {x: 0, y: 0, z: 0}
Scale: {x: 75, y: 75, z: 1}
IsActive: false
Renderable Component:
Mesh: 141771688
Material: 129340704
IsActive: false
Toggle Button Component:
Non Toggled Texture: 55358401
Toggled Texture: 52333376
Value: false
IsActive: false
UI Component:
Canvas ID: 19
Hovered: false
Clicked: false
IsActive: false
Scripts: ~
- EID: 39
Name: Audio Slider Text Group
IsActive: true
@ -970,8 +1081,6 @@
- Type: SHADE_Scripting.UI.SliderText
Enabled: true
sliderObj: 29
minValue: 0
maxValue: 100
- EID: 41
Name: SFX Volume Slider Text
IsActive: true
@ -997,8 +1106,6 @@
- Type: SHADE_Scripting.UI.SliderText
Enabled: true
sliderObj: 30
minValue: 0
maxValue: 100
- EID: 42
Name: BGM Volume Slider Text
IsActive: true
@ -1024,8 +1131,6 @@
- Type: SHADE_Scripting.UI.SliderText
Enabled: true
sliderObj: 31
minValue: 0
maxValue: 100
- EID: 43
Name: Camera Slider Text Group
IsActive: true
@ -1067,8 +1172,6 @@
- Type: SHADE_Scripting.UI.SliderText
Enabled: true
sliderObj: 37
minValue: 0
maxValue: 100
- EID: 45
Name: Sensitivity Slider Text
IsActive: true
@ -1094,8 +1197,6 @@
- Type: SHADE_Scripting.UI.SliderText
Enabled: true
sliderObj: 38
minValue: 0
maxValue: 100
- EID: 46
Name: Credits Canvas
IsActive: false

View File

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SHADE_Scripting
{
static public class Settings
{
static public float cameraSensitivity = 100.0f;
static public float cameraFOV = 90.0f;
static public float masterVolume = 100.0f;
static public float sfxVolume = 100.0f;
static public float bgmVolume = 100.0f;
}
}

View File

@ -0,0 +1,3 @@
Name: Settings
ID: 163325256
Type: 9

View File

@ -0,0 +1,95 @@
using SHADE;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SHADE_Scripting.UI
{
public class Options:Script
{
public GameObject masterVolSlider;
public GameObject sfxVolSlider;
public GameObject bgmVolSlider;
public GameObject fovSlider;
public GameObject sensitivitySlider;
protected override void awake()
{
Slider mv = masterVolSlider.GetComponent<Slider>();
Slider sfx = sfxVolSlider.GetComponent<Slider>();
Slider bgm = bgmVolSlider.GetComponent<Slider>();
Slider fov = fovSlider.GetComponent<Slider>();
Slider sens = sensitivitySlider.GetComponent<Slider>();
if (mv != null)
{
mv.ScaledValue = Settings.masterVolume;
}
if (sfx != null)
{
sfx.ScaledValue = Settings.sfxVolume;
}
if (bgm != null)
{
bgm.ScaledValue = Settings.bgmVolume;
}
if (fov != null)
{
fov.ScaledValue = Settings.cameraFOV;
}
if (sens != null)
{
sens.ScaledValue = Settings.cameraSensitivity;
}
}
protected override void update()
{
Slider mv = masterVolSlider.GetComponent<Slider>();
Slider sfx = sfxVolSlider.GetComponent<Slider>();
Slider bgm = bgmVolSlider.GetComponent<Slider>();
Slider fov = fovSlider.GetComponent<Slider>();
Slider sens = sensitivitySlider.GetComponent<Slider>();
if(mv != null)
{
Settings.masterVolume = mv.ScaledValue;
}
if (sfx != null)
{
Settings.sfxVolume = sfx.ScaledValue;
}
if (bgm != null)
{
Settings.bgmVolume = bgm.ScaledValue;
}
if (fov != null)
{
Settings.cameraFOV = fov.ScaledValue;
}
if (sens != null)
{
Settings.cameraSensitivity = sens.ScaledValue;
}
}
}
}

View File

@ -0,0 +1,3 @@
Name: SC_Options
ID: 162565004
Type: 9

View File

@ -11,8 +11,6 @@ namespace SHADE_Scripting.UI
{
public GameObject sliderObj;
public int minValue = 0;
public int maxValue = 0;
protected override void start()
{
@ -22,7 +20,7 @@ namespace SHADE_Scripting.UI
if (slider != null && text != null)
{
text.Text = ((int)(slider.GetValue() * (maxValue - minValue) + minValue)).ToString();
text.Text = ((int)(slider.ScaledValue)).ToString();
}
}
protected override void update()
@ -32,7 +30,7 @@ namespace SHADE_Scripting.UI
if(slider != null && text != null)
{
text.Text = ((int)(slider.GetValue() * (maxValue - minValue) + minValue)).ToString();
text.Text = ((int)(slider.ScaledValue)).ToString();
}
}

View File

@ -4,7 +4,7 @@
namespace SHADE
{
SHSliderComponent::SHSliderComponent()
:value(0.0f)
:value(0.0f),minValue(0.0f), maxValue(100.0f)
{
}
@ -21,6 +21,17 @@ namespace SHADE
}
float SHSliderComponent::GetScaledValue() const noexcept
{
return value * (maxValue - minValue) + minValue;
}
void SHSliderComponent::SetScaledValue(float value) noexcept
{
this->value = (value - minValue) / (maxValue - minValue);
}
}
@ -32,7 +43,8 @@ RTTR_REGISTRATION
registration::class_<SHSliderComponent>("Slider Component")
.property("Slider Value", &SHSliderComponent::GetValue, &SHSliderComponent::SetValue)
.property("Min Value", &SHSliderComponent::minValue)
.property("Max Value", &SHSliderComponent::maxValue)
;

View File

@ -18,11 +18,16 @@ namespace SHADE
virtual ~SHSliderComponent() = default;
float minValue;
float maxValue;
float GetValue() const noexcept;
void SetValue(float value) noexcept;
float GetScaledValue() const noexcept;
void SetScaledValue(float value)noexcept;
friend class SHUISystem;
private:

View File

@ -403,7 +403,7 @@ namespace SHADE
auto uiComp = SHComponentManager::GetComponent<SHUIComponent>(comp.GetEID());
//auto canvasComp = SHComponentManager::GetComponent_s<SHCanvasComponent>(uiComp->canvasID);
float tempValue = comp.GetValue();
float tempValue = comp.value;
CheckButtonHoveredOrClicked(*uiComp);
@ -441,9 +441,9 @@ namespace SHADE
comp.value = (mousePos.x - topExtent.x) / (btmExtent.x - topExtent.x);
if (comp.GetValue() > 1.0f)
if (comp.value > 1.0f)
comp.value = 1.0f;
if (comp.GetValue() < 0.0f)
if (comp.value < 0.0f)
comp.value = 0.0f;
}
try
@ -453,11 +453,11 @@ namespace SHADE
auto material = renderable->GetModifiableMaterial();
if (renderable)
{
if (comp.GetValue() != material->GetProperty<float>("data.sliderThreshold"))
if (comp.value != material->GetProperty<float>("data.sliderThreshold"))
{
//Set shader value.
material->SetProperty("data.sliderThreshold", comp.GetValue());
material->SetProperty("data.sliderThreshold", comp.value);
}
}

View File

@ -23,4 +23,22 @@ namespace SHADE
}
void Slider::SetValue(float value)
{
return GetNativeComponent()->SetValue(value);
}
float Slider::ScaledValue::get()
{
return GetNativeComponent()->GetScaledValue();
}
void Slider::ScaledValue::set(float value)
{
return GetNativeComponent()->SetScaledValue(value);
}
}

View File

@ -42,6 +42,15 @@ namespace SHADE
public:
float GetValue();
void SetValue(float value);
property float ScaledValue
{
float get();
void set(float value);
}
};