191 lines
6.6 KiB
C#
191 lines
6.6 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using DG.Tweening;
|
|
using I2.Loc;
|
|
using Ichni.RhythmGame.Beatmap;
|
|
using Ichni.RhythmGame.ThemeBundles.Basic.Beatmap;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
|
|
namespace Ichni.RhythmGame.ThemeBundles.Basic
|
|
{
|
|
public partial class TextObject : EnvironmentObject
|
|
{
|
|
[SerializeField]
|
|
private TMP_Text textObject;
|
|
[SerializeField]
|
|
private Localize localize;
|
|
|
|
public override bool haveEmission => true;
|
|
|
|
public float width;
|
|
public float height;
|
|
|
|
public bool isLocalized;
|
|
public string content;
|
|
public string fontName;
|
|
public float size;
|
|
public HorizontalAlignmentOptions horizontalAlignment;
|
|
public VerticalAlignmentOptions verticalAlignment;
|
|
|
|
public bool isGeneratingOneByOne;
|
|
public float generateTime;
|
|
public Tweener oneByOneTweener;
|
|
|
|
public static TextObject GenerateElement(string elementName, Guid id, List<string> tags,
|
|
bool isFirstGenerated, GameElement parentElement, string themeBundleName, string objectName,
|
|
bool isStatic, float width, float height, string content, bool isLocalized, string fontName, float size,
|
|
HorizontalAlignmentOptions horizontalAlignment, VerticalAlignmentOptions verticalAlignment,
|
|
bool isGeneratingOneByOne, float generateTime)
|
|
{
|
|
TextObject text = EnvironmentObject.GenerateElement(elementName, id, tags,
|
|
isFirstGenerated, themeBundleName, objectName, parentElement, isStatic).GetComponent<TextObject>();
|
|
|
|
text.width = width;
|
|
text.height = height;
|
|
text.content = content;
|
|
text.fontName = fontName;
|
|
text.isLocalized = isLocalized;
|
|
text.size = size;
|
|
text.horizontalAlignment = horizontalAlignment;
|
|
text.verticalAlignment = verticalAlignment;
|
|
text.isGeneratingOneByOne = isGeneratingOneByOne;
|
|
text.generateTime = generateTime;
|
|
|
|
return text;
|
|
}
|
|
|
|
public override void AfterInitialize()
|
|
{
|
|
base.AfterInitialize();
|
|
|
|
timeDurationSubmodule.SetUpActions(() =>
|
|
{
|
|
if (isGeneratingOneByOne)
|
|
{
|
|
oneByOneTweener.Kill(true);
|
|
textObject.text = "";
|
|
oneByOneTweener = textObject.DOText(GetContent(), generateTime).Play();
|
|
Debug.Log($"TextObject {objectName} is generating text one by one with duration {generateTime}");
|
|
}
|
|
});
|
|
|
|
SetWidthAndHeight();
|
|
SetFont();
|
|
SetFontSize();
|
|
SetAlignment();
|
|
SetContent();
|
|
}
|
|
|
|
public override void Refresh()
|
|
{
|
|
base.Refresh();
|
|
textObject.color = colorSubmodule.currentBaseColor;
|
|
textObject.fontMaterial.SetColor("_FaceColor", colorSubmodule.GetCurrentEmissionColor());
|
|
textObject.SetAllDirty();
|
|
}
|
|
}
|
|
|
|
public partial class TextObject
|
|
{
|
|
private void SetContent()
|
|
{
|
|
if (isLocalized)
|
|
{
|
|
localize.SetTerm(content);
|
|
}
|
|
else
|
|
{
|
|
textObject.text = content;
|
|
}
|
|
}
|
|
|
|
private string GetContent()
|
|
{
|
|
if (isLocalized)
|
|
{
|
|
return LocalizationManager.GetTermTranslation(content);
|
|
}
|
|
else
|
|
{
|
|
return content;
|
|
}
|
|
}
|
|
|
|
private void SetWidthAndHeight()
|
|
{
|
|
RectTransform rectTransform = textObject.GetComponent<RectTransform>();
|
|
rectTransform.sizeDelta = new Vector2(width, height);
|
|
}
|
|
|
|
private void SetFont()
|
|
{
|
|
if (!GameManager.Instance.basePrefabs.fonts.ContainsKey(fontName))
|
|
{
|
|
fontName = "SarasaGothic";
|
|
}
|
|
|
|
textObject.font = GameManager.Instance.basePrefabs.fonts[fontName];
|
|
//textObject.fontMaterial = Instantiate(EditorManager.instance.basePrefabs.fonts[fontName].material);
|
|
}
|
|
|
|
private void SetFontSize()
|
|
{
|
|
textObject.fontSize = size;
|
|
}
|
|
|
|
private void SetAlignment()
|
|
{
|
|
textObject.alignment = (TextAlignmentOptions) ((int)horizontalAlignment | (int)verticalAlignment);
|
|
}
|
|
}
|
|
|
|
|
|
namespace Beatmap
|
|
{
|
|
public class TextObject_BM : EnvironmentObject_BM
|
|
{
|
|
public float width;
|
|
public float height;
|
|
public string content;
|
|
public bool isLocalized;
|
|
public string fontName;
|
|
public float size;
|
|
public HorizontalAlignmentOptions horizontalAlignment;
|
|
public VerticalAlignmentOptions verticalAlignment;
|
|
public bool isGeneratingOneByOne;
|
|
public float generateTime;
|
|
|
|
public TextObject_BM()
|
|
{
|
|
|
|
}
|
|
|
|
public TextObject_BM(string elementName, Guid elementGuid, List<string> tags, GameElement_BM attachedElement,
|
|
string themeBundleName, string objectName, bool isStatic, float width, float height, string content, bool isLocalized,
|
|
string fontName, float size, HorizontalAlignmentOptions horizontalAlignment, VerticalAlignmentOptions verticalAlignment,
|
|
bool isGeneratingOneByOne, float generateTime)
|
|
: base(elementName, elementGuid, tags, attachedElement, themeBundleName, objectName, isStatic)
|
|
{
|
|
this.width = width;
|
|
this.height = height;
|
|
this.content = content;
|
|
this.isLocalized = isLocalized;
|
|
this.fontName = fontName;
|
|
this.size = size;
|
|
this.horizontalAlignment = horizontalAlignment;
|
|
this.verticalAlignment = verticalAlignment;
|
|
this.isGeneratingOneByOne = isGeneratingOneByOne;
|
|
this.generateTime = generateTime;
|
|
}
|
|
|
|
public override void ExecuteBM()
|
|
{
|
|
matchedElement = TextObject.GenerateElement(elementName, elementGuid, tags, false,
|
|
GetElement(attachedElementGuid), themeBundleName, objectName, isStatic, width, height, content,
|
|
isLocalized, fontName, size, horizontalAlignment, verticalAlignment, isGeneratingOneByOne, generateTime);
|
|
}
|
|
}
|
|
}
|
|
} |