HeavenStudio/Assets/Scripts/UI/SettingsDialog/Tabs/GameSettings.cs
minenice55 caf7d9465f
Play Mode Features Part 1 (#413)
* add pause menu assets

* layout and animation for pause

* make play mode prefab function

re-assign unused class inheritance

* remove filepath

* don't init medals twice

* remove PlayerActionObject

* initial attempt at anti-note lock

TODO: circumvent inputs clearing themselves making the functionality not work

* properly implement input lock prevention

* fix error on editor open

* functional pause menu

* bugfix

* make unpausing not reset current play statistics

* serialize initializer components in inspector instead of procedurally generating

* sanity check

* note for fade

* make flashes in the camera prefabs instead of in world space

remove / reorganize script files
address issue #411

* fix bug with perfect campaign

make minigame transitions hide the game canvas
adjust animation of the song credits textbox

* fully functional intro scene (placeholder for future title screen)

refactored entire game loading procedure
re-organized some files

* add interaction query to disclaimer text

* reword legal

* anchor section medals to section display

more tempo change placement controls

* operation order bugfix

* prep for future ratings and stats

* loading text

* autoload opening scene

* splash screen adjustments

added setting to force enable splash screen

* adjust setting entry
2023-05-07 20:33:15 +00:00

322 lines
12 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using HeavenStudio.Common;
namespace HeavenStudio.Editor
{
public class GameSettings : TabsContent
{
public static bool InPreview;
static Color ambiColour;
static bool needUpdateAmbi;
[SerializeField] Toggle editorOverlaysToggle;
[SerializeField] Toggle perfectChallengeToggle;
[SerializeField] Toggle sectionMedalsToggle;
[SerializeField] Toggle timingDispMinModeToggle;
[SerializeField] Toggle letterboxBgEnable;
[SerializeField] Toggle letterboxFxEnable;
[SerializeField] Image LytEditBg;
[SerializeField] Image LytEditBgAmbi;
[SerializeField] GameObject LytEditBgAmbiGO;
[Header("Layout Settings - Header")]
[SerializeField] TMP_Text ElementNameText;
[Header("Layout Settings - General")]
[SerializeField] Toggle ElementToggle;
[SerializeField] TMP_InputField XPosInput;
[SerializeField] TMP_InputField YPosInput;
[SerializeField] Slider XPosSlider;
[SerializeField] Slider YPosSlider;
[SerializeField] TMP_InputField RotationInput;
[SerializeField] Slider RotationSlider;
[SerializeField] TMP_InputField ScaleInput;
[SerializeField] Slider ScaleSlider;
[Header("Layout Settings - Timing Display")]
[SerializeField] GameObject TimingDispTypeContainer;
[SerializeField] TMP_Dropdown TimingDispTypeDropdown;
List<OverlaysManager.OverlayOption> lytElements = new List<OverlaysManager.OverlayOption>();
static int currentElementIdx = 0;
const string fFormat = "0.000";
bool initLyt = false;
public static void UpdatePreviewAmbient(Color col)
{
ambiColour = col;
needUpdateAmbi = true;
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (InPreview && needUpdateAmbi)
{
LytEditBgAmbi.color = ambiColour;
needUpdateAmbi = false;
}
}
void CreateDefaultLayout()
{
PersistentDataManager.gameSettings.timingDisplayComponents = new List<OverlaysManager.TimingDisplayComponent>()
{
OverlaysManager.TimingDisplayComponent.CreateDefaultDual()
};
PersistentDataManager.gameSettings.skillStarComponents = new List<OverlaysManager.SkillStarComponent>()
{
OverlaysManager.SkillStarComponent.CreateDefault()
};
PersistentDataManager.gameSettings.sectionComponents = new List<OverlaysManager.SectionComponent>()
{
OverlaysManager.SectionComponent.CreateDefault()
};
PersistentDataManager.SaveSettings();
}
public void OnEditorOverlaysToggleChanged()
{
PersistentDataManager.gameSettings.overlaysInEditor = editorOverlaysToggle.isOn;
}
public void OnPerfectChallengeToggleChanged()
{
PersistentDataManager.gameSettings.perfectChallengeType = perfectChallengeToggle.isOn ? PersistentDataManager.PerfectChallengeType.On : PersistentDataManager.PerfectChallengeType.Off;
}
public void OnSectionMedalsToggleChanged()
{
PersistentDataManager.gameSettings.isMedalOn = sectionMedalsToggle.isOn;
}
public void OnTimingDispMinModeToggleChanged()
{
PersistentDataManager.gameSettings.timingDisplayMinMode = timingDispMinModeToggle.isOn;
}
public void OnLetterboxBgToggleChanged()
{
PersistentDataManager.gameSettings.letterboxBgEnable = letterboxBgEnable.isOn;
StaticCamera.instance.ToggleLetterboxBg(PersistentDataManager.gameSettings.letterboxBgEnable);
LytEditBg.color = PersistentDataManager.gameSettings.letterboxBgEnable ? Color.white : Color.black;
}
public void OnLetterboxFxToggleChanged()
{
PersistentDataManager.gameSettings.letterboxFxEnable = letterboxFxEnable.isOn;
StaticCamera.instance.ToggleLetterboxGlow(PersistentDataManager.gameSettings.letterboxFxEnable);
LytEditBgAmbiGO.SetActive(PersistentDataManager.gameSettings.letterboxFxEnable);
}
public override void OnOpenTab()
{
TimingDispTypeDropdown.ClearOptions();
TimingDispTypeDropdown.AddOptions(Enum.GetNames(typeof(OverlaysManager.TimingDisplayComponent.TimingDisplayType)).ToList());
editorOverlaysToggle.isOn = PersistentDataManager.gameSettings.overlaysInEditor;
perfectChallengeToggle.isOn = PersistentDataManager.gameSettings.perfectChallengeType != PersistentDataManager.PerfectChallengeType.Off;
sectionMedalsToggle.isOn = PersistentDataManager.gameSettings.isMedalOn;
timingDispMinModeToggle.isOn = PersistentDataManager.gameSettings.timingDisplayMinMode;
letterboxBgEnable.isOn = PersistentDataManager.gameSettings.letterboxBgEnable;
letterboxFxEnable.isOn = PersistentDataManager.gameSettings.letterboxFxEnable;
if (PersistentDataManager.gameSettings.timingDisplayComponents.Count == 0 &&
PersistentDataManager.gameSettings.skillStarComponents.Count == 0 &&
PersistentDataManager.gameSettings.sectionComponents.Count == 0)
{
CreateDefaultLayout();
}
lytElements = new List<OverlaysManager.OverlayOption>();
foreach (var c in PersistentDataManager.gameSettings.timingDisplayComponents) { lytElements.Add(c); c.EnablePreview();}
foreach (var c in PersistentDataManager.gameSettings.skillStarComponents) { lytElements.Add(c); c.EnablePreview();}
foreach (var c in PersistentDataManager.gameSettings.sectionComponents) { lytElements.Add(c); c.EnablePreview();}
UpdateLayoutSettings();
InPreview = true;
initLyt = true;
}
public override void OnCloseTab()
{
foreach (var e in lytElements)
{
e.DisablePreview();
}
lytElements.Clear();
InPreview = false;
initLyt = false;
}
void UpdateLayoutSettings()
{
var element = lytElements[currentElementIdx];
element.EnablePreview();
ElementToggle.isOn = element.enable;
XPosInput.text = element.position.x.ToString(fFormat);
YPosInput.text = element.position.y.ToString(fFormat);
XPosSlider.value = element.position.x;
YPosSlider.value = element.position.y;
RotationInput.text = element.rotation.ToString(fFormat);
RotationSlider.value = element.rotation;
ScaleInput.text = element.scale.ToString(fFormat);
ScaleSlider.value = element.scale;
if (element is OverlaysManager.TimingDisplayComponent)
{
TimingDispTypeContainer.SetActive(true);
TimingDispTypeDropdown.value = (int)(element as OverlaysManager.TimingDisplayComponent).tdType;
ElementNameText.text = "Timing Display";
}
else
{
TimingDispTypeContainer.SetActive(false);
}
if (element is OverlaysManager.SkillStarComponent)
{
ElementNameText.text = "Skill Star";
}
if (element is OverlaysManager.SectionComponent)
{
ElementNameText.text = "Section Progress";
}
}
public void OnNextElementButtonClicked()
{
currentElementIdx = (currentElementIdx + 1) % lytElements.Count;
UpdateLayoutSettings();
}
public void OnPrevElementButtonClicked()
{
currentElementIdx = (currentElementIdx - 1 + lytElements.Count) % lytElements.Count;
UpdateLayoutSettings();
}
public void OnElementToggled()
{
if (!initLyt) return;
var element = lytElements[currentElementIdx];
element.enable = ElementToggle.isOn;
element.PositionElement();
}
public void OnXPosInputChanged()
{
if (!initLyt) return;
var element = lytElements[currentElementIdx];
XPosSlider.value = float.Parse(XPosInput.text);
element.position.x = XPosSlider.value;
element.PositionElement();
}
public void OnXPosSliderChanged()
{
if (!initLyt) return;
var element = lytElements[currentElementIdx];
XPosInput.text = XPosSlider.value.ToString(fFormat);
element.position.x = XPosSlider.value;
element.PositionElement();
}
public void OnYPosInputChanged()
{
if (!initLyt) return;
var element = lytElements[currentElementIdx];
YPosSlider.value = float.Parse(YPosInput.text);
element.position.y = YPosSlider.value;
element.PositionElement();
}
public void OnYPosSliderChanged()
{
if (!initLyt) return;
var element = lytElements[currentElementIdx];
YPosInput.text = YPosSlider.value.ToString(fFormat);
element.position.y = YPosSlider.value;
element.PositionElement();
}
public void OnRotationInputChanged()
{
if (!initLyt) return;
var element = lytElements[currentElementIdx];
RotationSlider.value = float.Parse(RotationInput.text);
element.rotation = RotationSlider.value;
element.PositionElement();
}
public void OnRotationSliderChanged()
{
if (!initLyt) return;
var element = lytElements[currentElementIdx];
RotationInput.text = RotationSlider.value.ToString(fFormat);
element.rotation = RotationSlider.value;
element.PositionElement();
}
public void OnScaleInputChanged()
{
if (!initLyt) return;
var element = lytElements[currentElementIdx];
ScaleSlider.value = float.Parse(ScaleInput.text);
element.scale = ScaleSlider.value;
element.PositionElement();
}
public void OnScaleSliderChanged()
{
if (!initLyt) return;
var element = lytElements[currentElementIdx];
ScaleInput.text = ScaleSlider.value.ToString(fFormat);
element.scale = ScaleSlider.value;
element.PositionElement();
}
public void OnTimingDispTypeDropdownChanged()
{
if (!initLyt) return;
var element = lytElements[currentElementIdx] as OverlaysManager.TimingDisplayComponent;
if (element == null) return;
element.tdType = (OverlaysManager.TimingDisplayComponent.TimingDisplayType)TimingDispTypeDropdown.value;
bool elHide = element.enable;
switch (element.tdType)
{
case OverlaysManager.TimingDisplayComponent.TimingDisplayType.Dual:
element.position = new Vector2(-0.84f, 0);
element.rotation = 0f;
break;
default:
element.position = new Vector2(0, -0.8f);
element.rotation = 90f;
break;
}
element.scale = 1f;
element.enable = elHide;
element.PositionElement();
UpdateLayoutSettings();
}
}
}