HeavenStudioPlus/Assets/Scripts/Games/Global/Textbox.cs
minenice55 4c4d0a7a7a 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

291 lines
11 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using HeavenStudio.TextboxUtilities;
namespace HeavenStudio.Games.Global
{
public class Textbox : MonoBehaviour
{
public enum TextboxAnchor {
TopLeft,
TopMiddle,
TopRight,
Left,
Middle,
Right,
BottomLeft,
BottomMiddle,
BottomRight
}
public enum ClosedCaptionsAnchor {
Top,
Bottom,
}
private List<DynamicBeatmap.DynamicEntity> textboxEvents = new List<DynamicBeatmap.DynamicEntity>();
private List<DynamicBeatmap.DynamicEntity> openCaptionsEvents = new List<DynamicBeatmap.DynamicEntity>();
private List<DynamicBeatmap.DynamicEntity> idolEvents = new List<DynamicBeatmap.DynamicEntity>();
private List<DynamicBeatmap.DynamicEntity> closedCaptionsEvents = new List<DynamicBeatmap.DynamicEntity>();
public static Textbox instance { get; private set; }
[Header("Objects")]
public GameObject TextboxEnabler;
public TextboxObject TextboxObject;
public GameObject OpenCaptionsEnabler;
public TMP_Text OpenCaptionsLabel;
public RectTransform OpenCaptionsLabelRect;
public GameObject IdolEnabler;
public Animator IdolAnimator;
public TMP_Text IdolSongLabel;
public TMP_Text IdolArtistLabel;
public GameObject ClosedCaptionsEnabler;
public TMP_Text ClosedCaptionsLabel;
public RectTransform ClosedCaptionsLabelRect;
public RectTransform ClosedCaptionsBgRect;
float XAnchor = 1.5f;
float YAnchor = 1.75f;
Vector2 textboxSize = new Vector2(3f, 0.75f);
bool idolShown = false;
public void Awake()
{
instance = this;
}
public void Start()
{
GameManager.instance.onBeatChanged += OnBeatChanged;
TextboxEnabler.SetActive(false);
OpenCaptionsEnabler.SetActive(false);
ClosedCaptionsEnabler.SetActive(false);
UpdateTextboxDisplay();
UpdateOpenCaptionsDisplay();
UpdateClosedCaptionsDisplay();
}
public void Update()
{
UpdateTextboxDisplay();
UpdateOpenCaptionsDisplay();
UpdateIdolDisplay();
UpdateClosedCaptionsDisplay();
}
public void OnBeatChanged(float beat)
{
TextboxEnabler.SetActive(false);
OpenCaptionsEnabler.SetActive(false);
ClosedCaptionsEnabler.SetActive(false);
textboxEvents = EventCaller.GetAllInGameManagerList("vfx", new string[] { "display textbox" });
openCaptionsEvents = EventCaller.GetAllInGameManagerList("vfx", new string[] { "display open captions" });
idolEvents = EventCaller.GetAllInGameManagerList("vfx", new string[] { "display song artist" });
closedCaptionsEvents = EventCaller.GetAllInGameManagerList("vfx", new string[] { "display closed captions" });
UpdateTextboxDisplay();
UpdateOpenCaptionsDisplay();
UpdateClosedCaptionsDisplay();
UpdateIdolDisplay();
if (!idolShown)
{
IdolAnimator.Play("NoPose", -1, 0);
IdolAnimator.speed = 1;
}
}
private void UpdateTextboxDisplay()
{
foreach (var e in textboxEvents)
{
float prog = Conductor.instance.GetPositionFromBeat(e.beat, e.length);
if (prog >= 0f && prog <= 1f)
{
TextboxEnabler.SetActive(true);
TextboxObject.SetText(e["text1"]);
TextboxObject.Resize(e["valA"], e["valB"]);
// ouch
switch (e["type"])
{
case (int) TextboxAnchor.TopLeft:
TextboxEnabler.transform.localPosition = new Vector3(-XAnchor, YAnchor);
break;
case (int) TextboxAnchor.TopMiddle:
TextboxEnabler.transform.localPosition = new Vector3(0, YAnchor);
break;
case (int) TextboxAnchor.TopRight:
TextboxEnabler.transform.localPosition = new Vector3(XAnchor, YAnchor);
break;
case (int) TextboxAnchor.Left:
TextboxEnabler.transform.localPosition = new Vector3(-XAnchor, 0);
break;
case (int) TextboxAnchor.Middle:
TextboxEnabler.transform.localPosition = new Vector3(0, 0);
break;
case (int) TextboxAnchor.Right:
TextboxEnabler.transform.localPosition = new Vector3(XAnchor, 0);
break;
case (int) TextboxAnchor.BottomLeft:
TextboxEnabler.transform.localPosition = new Vector3(-XAnchor, -YAnchor);
break;
case (int) TextboxAnchor.BottomMiddle:
TextboxEnabler.transform.localPosition = new Vector3(0, -YAnchor);
break;
case (int) TextboxAnchor.BottomRight:
TextboxEnabler.transform.localPosition = new Vector3(XAnchor, -YAnchor);
break;
default:
TextboxEnabler.transform.localPosition = new Vector3(0, 0);
break;
}
return;
}
if (prog > 1f || prog < 0f)
{
TextboxEnabler.transform.localPosition = new Vector3(0, 0);
TextboxEnabler.SetActive(false);
}
}
}
private void UpdateOpenCaptionsDisplay()
{
foreach (var e in openCaptionsEvents)
{
float prog = Conductor.instance.GetPositionFromBeat(e.beat, e.length);
if (prog >= 0f && prog <= 1f)
{
OpenCaptionsEnabler.SetActive(true);
OpenCaptionsLabel.text = e["text1"];
OpenCaptionsLabelRect.sizeDelta = new Vector2(18f * e["valA"], 2.5f * e["valB"]);
// ouch
switch (e["type"])
{
case (int) TextboxAnchor.TopLeft:
OpenCaptionsEnabler.transform.localPosition = new Vector3(-XAnchor, YAnchor);
break;
case (int) TextboxAnchor.TopMiddle:
OpenCaptionsEnabler.transform.localPosition = new Vector3(0, YAnchor);
break;
case (int) TextboxAnchor.TopRight:
OpenCaptionsEnabler.transform.localPosition = new Vector3(XAnchor, YAnchor);
break;
case (int) TextboxAnchor.Left:
OpenCaptionsEnabler.transform.localPosition = new Vector3(-XAnchor, 0);
break;
case (int) TextboxAnchor.Middle:
OpenCaptionsEnabler.transform.localPosition = new Vector3(0, 0);
break;
case (int) TextboxAnchor.Right:
OpenCaptionsEnabler.transform.localPosition = new Vector3(XAnchor, 0);
break;
case (int) TextboxAnchor.BottomLeft:
OpenCaptionsEnabler.transform.localPosition = new Vector3(-XAnchor, -YAnchor);
break;
case (int) TextboxAnchor.BottomMiddle:
OpenCaptionsEnabler.transform.localPosition = new Vector3(0, -YAnchor);
break;
case (int) TextboxAnchor.BottomRight:
OpenCaptionsEnabler.transform.localPosition = new Vector3(XAnchor, -YAnchor);
break;
default:
OpenCaptionsEnabler.transform.localPosition = new Vector3(0, 0);
break;
}
return;
}
if (prog > 1f || prog < 0f)
{
OpenCaptionsEnabler.transform.localPosition = new Vector3(0, 0);
OpenCaptionsEnabler.SetActive(false);
}
}
}
private void UpdateIdolDisplay()
{
var cond = Conductor.instance;
foreach (var e in idolEvents)
{
float prog = cond.GetPositionFromBeat(e.beat, e.length);
if (prog >= 0f && prog <= 1f)
{
float inp = cond.GetPositionFromBeat(e.beat, 1);
IdolSongLabel.text = e["text1"];
IdolArtistLabel.text = e["text2"];
IdolAnimator.Play("IdolShow", -1, Mathf.Min(inp, 1));
IdolAnimator.speed = 0;
idolShown = true;
return;
}
else if (idolShown)
{
if (prog < 1f)
{
IdolAnimator.Play("NoPose", -1, 0);
IdolAnimator.speed = 1;
idolShown = false;
}
else
{
IdolAnimator.Play("IdolHide", -1, 0);
IdolAnimator.speed = (1f / cond.pitchedSecPerBeat) * 0.5f;
idolShown = false;
}
}
}
}
private void UpdateClosedCaptionsDisplay()
{
foreach (var e in closedCaptionsEvents)
{
float prog = Conductor.instance.GetPositionFromBeat(e.beat, e.length);
if (prog >= 0f && prog <= 1f)
{
ClosedCaptionsEnabler.SetActive(true);
ClosedCaptionsLabel.text = e["text1"];
ClosedCaptionsLabelRect.sizeDelta = new Vector2(9f, e["valA"]);
ClosedCaptionsBgRect.sizeDelta = new Vector2(9f, e["valA"]);
switch (e["type"])
{
case (int) ClosedCaptionsAnchor.Bottom:
ClosedCaptionsEnabler.transform.localPosition = new Vector3(0, -2.5f + e["valA"]/2);
break;
default:
ClosedCaptionsEnabler.transform.localPosition = new Vector3(0, 2.5f - e["valA"]/2);
break;
}
return;
}
if (prog > 1f || prog < 0f)
{
ClosedCaptionsEnabler.SetActive(false);
}
}
}
}
}