From 2f57a4db064e81e32d3f5037c02ebc53dfff45ed Mon Sep 17 00:00:00 2001 From: minenice55 Date: Tue, 13 Sep 2022 17:35:54 -0400 Subject: [PATCH] creation of Chart Sections (TODO: GO REFERENCE) --- .../SpecialTmeline/SectionTimelineObj.cs | 88 +++++++++++++++++++ .../SpecialTmeline/SpecialTimeline.cs | 44 ++++++++++ 2 files changed, 132 insertions(+) create mode 100644 Assets/Scripts/LevelEditor/Timeline/SpecialTmeline/SectionTimelineObj.cs diff --git a/Assets/Scripts/LevelEditor/Timeline/SpecialTmeline/SectionTimelineObj.cs b/Assets/Scripts/LevelEditor/Timeline/SpecialTmeline/SectionTimelineObj.cs new file mode 100644 index 000000000..a774032be --- /dev/null +++ b/Assets/Scripts/LevelEditor/Timeline/SpecialTmeline/SectionTimelineObj.cs @@ -0,0 +1,88 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +using TMPro; + +using DG.Tweening; + +namespace HeavenStudio.Editor.Track +{ + public class SectionTimelineObj : SpecialTimelineObj + { + [Header("Components")] + [SerializeField] private TMP_Text sectionLabel; + [SerializeField] private GameObject chartLine; + + public DynamicBeatmap.ChartSection chartSection; + + new private void Update() + { + base.Update(); + if (hovering) + { + SpecialTimeline.hoveringTypes |= SpecialTimeline.HoveringTypes.SectionChange; + } + + UpdateLabel(); + } + + private void UpdateLabel() + { + sectionLabel.text = chartSection.sectionName; + } + + public override void Init() + { + UpdateLabel(); + } + + public override void OnLeftClick() + { + if (Timeline.instance.timelineState.currentState == Timeline.CurrentTimelineState.State.ChartSection) + StartMove(); + } + + public override void OnRightClick() + { + if (Timeline.instance.timelineState.currentState == Timeline.CurrentTimelineState.State.ChartSection) + { + GameManager.instance.Beatmap.beatmapSections.Remove(chartSection); + DeleteObj(); + } + } + + public override bool OnMove(float beat) + { + foreach (var sectionChange in GameManager.instance.Beatmap.beatmapSections) + { + if (this.chartSection == sectionChange) + continue; + if (beat > sectionChange.beat - Timeline.instance.snapInterval && beat < sectionChange.beat + Timeline.instance.snapInterval) + return false; + } + this.chartSection.beat = beat; + return true; + } + + public override void SetVisibility(Timeline.CurrentTimelineState.State state) + { + if (state == Timeline.CurrentTimelineState.State.ChartSection || state == Timeline.CurrentTimelineState.State.Selection) + { + gameObject.SetActive(true); + if (state == Timeline.CurrentTimelineState.State.ChartSection) + { + chartLine.SetActive(true); + sectionLabel.gameObject.SetActive(true); + } + else + { + chartLine.SetActive(false); + sectionLabel.gameObject.SetActive(false); + } + } + else + gameObject.SetActive(false); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/LevelEditor/Timeline/SpecialTmeline/SpecialTimeline.cs b/Assets/Scripts/LevelEditor/Timeline/SpecialTmeline/SpecialTimeline.cs index 8a5c6653c..6f5621980 100644 --- a/Assets/Scripts/LevelEditor/Timeline/SpecialTmeline/SpecialTimeline.cs +++ b/Assets/Scripts/LevelEditor/Timeline/SpecialTmeline/SpecialTimeline.cs @@ -52,6 +52,9 @@ namespace HeavenStudio.Editor.Track foreach (var volumeChange in GameManager.instance.Beatmap.volumeChanges) AddVolumeChange(false, volumeChange); + foreach (var sectionChange in GameManager.instance.Beatmap.beatmapSections) + AddChartSection(false, sectionChange); + Timeline.instance.timelineState.SetState(Timeline.CurrentTimelineState.State.Selection); FixObjectsVisibility(); } @@ -83,6 +86,10 @@ namespace HeavenStudio.Editor.Track if (!hoveringTypes.HasFlag(HoveringTypes.VolumeChange)) AddVolumeChange(true); break; + case Timeline.CurrentTimelineState.State.ChartSection: + if (!hoveringTypes.HasFlag(HoveringTypes.SectionChange)) + AddChartSection(true); + break; } } } @@ -178,5 +185,42 @@ namespace HeavenStudio.Editor.Track specialTimelineObjs.Add(volumeTimelineObj); } + + public void AddChartSection(bool create, DynamicBeatmap.ChartSection chartSection_ = null) + { + GameObject chartSection = Instantiate(RefSectionChange.gameObject, this.transform); + + chartSection.transform.GetChild(0).GetComponent().color = EditorTheme.theme.properties.SectionLayerCol.Hex2RGB(); + chartSection.transform.GetChild(1).GetComponent().color = EditorTheme.theme.properties.SectionLayerCol.Hex2RGB(); + chartSection.transform.GetChild(2).GetComponent().color = EditorTheme.theme.properties.SectionLayerCol.Hex2RGB(); + + chartSection.SetActive(true); + + SectionTimelineObj sectionTimelineObj = chartSection.GetComponent(); + + if (create == true) + { + chartSection.transform.position = new Vector3(Editor.instance.EditorCamera.ScreenToWorldPoint(Input.mousePosition).x + 0.08f, chartSection.transform.position.y); + chartSection.transform.localPosition = new Vector3(Starpelly.Mathp.Round2Nearest(chartSection.transform.localPosition.x, Timeline.SnapInterval()), chartSection.transform.localPosition.y); + + DynamicBeatmap.ChartSection sectionC = new DynamicBeatmap.ChartSection(); + sectionC.beat = chartSection.transform.localPosition.x; + sectionC.sectionName = "New Section"; + sectionC.startPerfect = false; + sectionC.isCheckpoint = false; + + sectionTimelineObj.chartSection = sectionC; + GameManager.instance.Beatmap.beatmapSections.Add(sectionC); + } + else + { + chartSection.transform.localPosition = new Vector3(chartSection_.beat, chartSection.transform.localPosition.y); + + sectionTimelineObj.chartSection = chartSection_; + } + sectionTimelineObj.SetVisibility(Timeline.instance.timelineState.currentState); + + specialTimelineObjs.Add(sectionTimelineObj); + } } }