KSP-Conformal-Decals/Source/ConformalDecals/ModuleConformalText.cs

71 lines
2.8 KiB
C#
Raw Normal View History

2020-06-19 08:01:46 +00:00
using ConformalDecals.Text;
2020-07-13 03:27:19 +00:00
using ConformalDecals.UI;
using UnityEngine;
namespace ConformalDecals {
2020-07-20 04:12:48 +00:00
public class ModuleConformalText : ModuleConformalDecal {
[KSPField(isPersistant = true)] public string text = "Hello World!";
2020-07-24 21:39:35 +00:00
[KSPField(isPersistant = true)] public string fontName = "Calibri SDF";
2020-07-20 04:12:48 +00:00
[KSPField(isPersistant = true)] public int style;
[KSPField(isPersistant = true)] public bool vertical;
2020-07-23 05:37:16 +00:00
[KSPField(isPersistant = true)] public Color fillColor = Color.black;
2020-07-20 04:12:48 +00:00
[KSPField(isPersistant = true)] public Color outlineColor = Color.white;
[KSPField(isPersistant = true)] public float outlineWidth;
2020-07-24 21:39:35 +00:00
private DecalTextStyle _style;
private DecalFont _font;
2020-07-23 05:37:16 +00:00
private TextEntryController _textEntryController;
private ColorPickerController _fillColorPickerController;
private ColorPickerController _outlineColorPickerCOntroller;
public override void OnStart(StartState state) {
base.OnStart(state);
2020-07-24 21:39:35 +00:00
_font = DecalConfig.GetFont(fontName);
_style = new DecalTextStyle();
2020-07-20 04:12:48 +00:00
2020-07-24 21:39:35 +00:00
var decalText = new DecalText("Hello World!", _font, _style);
TextRenderer.Instance.RenderText(decalText, out var texture, out var window);
materialProperties.AddOrGetTextureProperty("_Decal", true).Texture = texture;
UpdateMaterials();
UpdateScale();
2020-07-20 04:12:48 +00:00
}
2020-07-24 21:39:35 +00:00
public void OnTextUpdate(string newText, DecalFont newFont, DecalTextStyle newStyle) {
text = newText;
_font = newFont;
_style = newStyle;
}
2020-07-23 05:37:16 +00:00
public void OnFillColorUpdate(Color rgb, Util.ColorHSV hsv) {
Debug.Log($"new fill color: {rgb}, {hsv}");
}
public void OnOutlineColorUpdate(Color rgb, Util.ColorHSV hsv) {
Debug.Log($"new outline color: {rgb}, {hsv}");
}
2020-07-13 03:27:19 +00:00
[KSPEvent(guiActive = false, guiActiveEditor = true, guiName = "#LOC_ConformalDecals_gui-select-flag")]
2020-07-20 04:12:48 +00:00
public void SetText() {
if (_textEntryController == null) {
2020-07-24 21:39:35 +00:00
_textEntryController = TextEntryController.Create(text, _font, _style, OnTextUpdate);
}
}
2020-07-23 05:37:16 +00:00
[KSPEvent(guiActive = false, guiActiveEditor = true, guiName = "Set Fill Color")]
public void SetFillColor() {
if (_fillColorPickerController == null) {
_fillColorPickerController = ColorPickerController.Create(fillColor, OnFillColorUpdate);
}
}
[KSPEvent(guiActive = false, guiActiveEditor = true, guiName = "Set Outline Color")]
public void SetOutlineColor() {
if (_outlineColorPickerCOntroller == null) {
_outlineColorPickerCOntroller = ColorPickerController.Create(outlineColor, OnOutlineColorUpdate);
}
}
}
}