HeavenStudioPlus/Assets/Scripts/LevelEditor/SettingsDialog/Tabs/GameSettings.cs

273 lines
9.8 KiB
C#
Raw Normal View History

Game Overlays (#280) * add accuracy display * temp BG for show * separate overlays prefab make proper shader for star effects * aim shakiness display * implement testing skill star * fully functional skill star * separate section display from editor * fully separate chart section display from timeline * add section to overlays * fix nullreference issues * start game layout settings * add game settings script * fix nonfunctioning scoring * invert y position logic on timing bar * add perfect challenge functionality * fix section not showing up in editor add perfect challenge option * add timing display minimal mode * Update PerfectAndPractice.png * show gismo for minigame bounds in editor * add ability to disable overlays in editor * prepare medals add new timing display graphic * hide screen preview * per-axis camera control added per request * section medals basic functionality * add medal get animations * fix bug with perfect icons * visual enhancements * adjust look of timing display minmode address audio ducking issues(?) * prepare overlay lyt editor add viewport pan, rotate, scale adjust audio setting * add layout editor UI elements * dynamic overlay creation * fix default single timing disp * set up overlay settings controls * start UI events * runtime uuid for component reference * layout editor affects overlay elements * show overlay element previews while editing * advanced audio settings * fix bug in drop-down creation * fallback defaults for the new stuff * fix textbox & overlay visibility bugs
2023-03-11 04:51:22 +00:00
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;
[SerializeField] Toggle editorOverlaysToggle;
[SerializeField] Toggle perfectChallengeToggle;
[SerializeField] Toggle sectionMedalsToggle;
[SerializeField] Toggle timingDispMinModeToggle;
[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";
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
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 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;
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;
}
public override void OnCloseTab()
{
foreach (var e in lytElements)
{
e.DisablePreview();
}
lytElements.Clear();
InPreview = 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()
{
var element = lytElements[currentElementIdx];
element.enable = ElementToggle.isOn;
element.PositionElement();
}
public void OnXPosInputChanged()
{
var element = lytElements[currentElementIdx];
XPosSlider.value = float.Parse(XPosInput.text);
element.position.x = XPosSlider.value;
element.PositionElement();
}
public void OnXPosSliderChanged()
{
var element = lytElements[currentElementIdx];
XPosInput.text = XPosSlider.value.ToString(fFormat);
element.position.x = XPosSlider.value;
element.PositionElement();
}
public void OnYPosInputChanged()
{
var element = lytElements[currentElementIdx];
YPosSlider.value = float.Parse(YPosInput.text);
element.position.y = YPosSlider.value;
element.PositionElement();
}
public void OnYPosSliderChanged()
{
var element = lytElements[currentElementIdx];
YPosInput.text = YPosSlider.value.ToString(fFormat);
element.position.y = YPosSlider.value;
element.PositionElement();
}
public void OnRotationInputChanged()
{
var element = lytElements[currentElementIdx];
RotationSlider.value = float.Parse(RotationInput.text);
element.rotation = RotationSlider.value;
element.PositionElement();
}
public void OnRotationSliderChanged()
{
var element = lytElements[currentElementIdx];
RotationInput.text = RotationSlider.value.ToString(fFormat);
element.rotation = RotationSlider.value;
element.PositionElement();
}
public void OnScaleInputChanged()
{
var element = lytElements[currentElementIdx];
ScaleSlider.value = float.Parse(ScaleInput.text);
element.scale = ScaleSlider.value;
element.PositionElement();
}
public void OnScaleSliderChanged()
{
var element = lytElements[currentElementIdx];
ScaleInput.text = ScaleSlider.value.ToString(fFormat);
element.scale = ScaleSlider.value;
element.PositionElement();
}
public void OnTimingDispTypeDropdownChanged()
{
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();
}
}
}