|
|
|
@ -24,6 +24,9 @@ namespace ConformalDecals {
|
|
|
|
|
if (_textEntryController == null) {
|
|
|
|
|
_textEntryController = TextEntryController.Create(text, _font, _style, OnTextUpdate);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
_textEntryController.OnClose();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// FILL
|
|
|
|
@ -39,6 +42,9 @@ namespace ConformalDecals {
|
|
|
|
|
if (_fillColorPickerController == null) {
|
|
|
|
|
_fillColorPickerController = ColorPickerController.Create(fillColor, OnFillColorUpdate);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
_fillColorPickerController.OnClose();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// OUTLINE
|
|
|
|
@ -56,8 +62,11 @@ namespace ConformalDecals {
|
|
|
|
|
[KSPEvent(guiName = "#LOC_ConformalDecals_gui-set-outline-color", groupName = "decal-outline", groupDisplayName = "#LOC_ConformalDecals_gui-group-outline",
|
|
|
|
|
guiActive = false, guiActiveEditor = true)]
|
|
|
|
|
public void SetOutlineColor() {
|
|
|
|
|
if (_outlineColorPickerCOntroller == null) {
|
|
|
|
|
_outlineColorPickerCOntroller = ColorPickerController.Create(outlineColor, OnOutlineColorUpdate);
|
|
|
|
|
if (_outlineColorPickerController == null) {
|
|
|
|
|
_outlineColorPickerController = ColorPickerController.Create(outlineColor, OnOutlineColorUpdate);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
_outlineColorPickerController.OnClose();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -66,7 +75,17 @@ namespace ConformalDecals {
|
|
|
|
|
|
|
|
|
|
private TextEntryController _textEntryController;
|
|
|
|
|
private ColorPickerController _fillColorPickerController;
|
|
|
|
|
private ColorPickerController _outlineColorPickerCOntroller;
|
|
|
|
|
private ColorPickerController _outlineColorPickerController;
|
|
|
|
|
|
|
|
|
|
private MaterialTextureProperty _decalTextureProperty;
|
|
|
|
|
private MaterialFloatProperty _decalTextWeightProperty;
|
|
|
|
|
|
|
|
|
|
private MaterialKeywordProperty _fillEnabledProperty;
|
|
|
|
|
private MaterialColorProperty _fillColorProperty;
|
|
|
|
|
|
|
|
|
|
private MaterialKeywordProperty _outlineEnabledProperty;
|
|
|
|
|
private MaterialColorProperty _outlineColorProperty;
|
|
|
|
|
private MaterialFloatProperty _outlineWidthProperty;
|
|
|
|
|
|
|
|
|
|
private TextRenderJob _currentJob;
|
|
|
|
|
private DecalText _currentText;
|
|
|
|
@ -74,6 +93,8 @@ namespace ConformalDecals {
|
|
|
|
|
public override void OnLoad(ConfigNode node) {
|
|
|
|
|
base.OnLoad(node);
|
|
|
|
|
OnAfterDeserialize();
|
|
|
|
|
|
|
|
|
|
UpdateTextRecursive();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnSave(ConfigNode node) {
|
|
|
|
@ -83,10 +104,24 @@ namespace ConformalDecals {
|
|
|
|
|
|
|
|
|
|
public override void OnStart(StartState state) {
|
|
|
|
|
base.OnStart(state);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UpdateTextRecursive();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnAwake() {
|
|
|
|
|
base.OnAwake();
|
|
|
|
|
|
|
|
|
|
_decalTextureProperty = materialProperties.AddOrGetTextureProperty("_Decal", true);
|
|
|
|
|
_decalTextWeightProperty = materialProperties.AddOrGetProperty<MaterialFloatProperty>("_Weight");
|
|
|
|
|
|
|
|
|
|
_fillEnabledProperty = materialProperties.AddOrGetProperty<MaterialKeywordProperty>("DECAL_FILL");
|
|
|
|
|
_fillColorProperty = materialProperties.AddOrGetProperty<MaterialColorProperty>("_DecalColor");
|
|
|
|
|
|
|
|
|
|
_outlineEnabledProperty = materialProperties.AddOrGetProperty<MaterialKeywordProperty>("DECAL_OUTLINE");
|
|
|
|
|
_outlineColorProperty = materialProperties.AddOrGetProperty<MaterialColorProperty>("_OutlineColor");
|
|
|
|
|
_outlineWidthProperty = materialProperties.AddOrGetProperty<MaterialFloatProperty>("_OutlineWidth");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnTextUpdate(string newText, DecalFont newFont, DecalTextStyle newStyle) {
|
|
|
|
|
text = newText;
|
|
|
|
|
_font = newFont;
|
|
|
|
@ -96,25 +131,63 @@ namespace ConformalDecals {
|
|
|
|
|
|
|
|
|
|
public void OnFillColorUpdate(Color rgb, Util.ColorHSV hsv) {
|
|
|
|
|
fillColor = rgb;
|
|
|
|
|
Debug.Log($"new fill color: {rgb}, {hsv}");
|
|
|
|
|
UpdateMaterials();
|
|
|
|
|
|
|
|
|
|
foreach (var counterpart in part.symmetryCounterparts) {
|
|
|
|
|
var decal = counterpart.GetComponent<ModuleConformalText>();
|
|
|
|
|
decal.fillColor = fillColor;
|
|
|
|
|
decal.UpdateMaterials();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnOutlineColorUpdate(Color rgb, Util.ColorHSV hsv) {
|
|
|
|
|
outlineColor = rgb;
|
|
|
|
|
Debug.Log($"new outline color: {rgb}, {hsv}");
|
|
|
|
|
UpdateMaterials();
|
|
|
|
|
|
|
|
|
|
foreach (var counterpart in part.symmetryCounterparts) {
|
|
|
|
|
var decal = counterpart.GetComponent<ModuleConformalText>();
|
|
|
|
|
decal.outlineColor = outlineColor;
|
|
|
|
|
decal.UpdateMaterials();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnFillToggle() {
|
|
|
|
|
public void OnFillToggle(BaseField field, object obj) {
|
|
|
|
|
if (!fillEnabled && !outlineEnabled) {
|
|
|
|
|
outlineEnabled = true;
|
|
|
|
|
OnOutlineToggle();
|
|
|
|
|
OnOutlineToggle(field, obj);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UpdateTweakables();
|
|
|
|
|
|
|
|
|
|
foreach (var counterpart in part.symmetryCounterparts) {
|
|
|
|
|
var decal = counterpart.GetComponent<ModuleConformalText>();
|
|
|
|
|
decal.fillEnabled = fillEnabled;
|
|
|
|
|
decal.UpdateTweakables();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnOutlineToggle() {
|
|
|
|
|
public void OnOutlineToggle(BaseField field, object obj) {
|
|
|
|
|
if (!fillEnabled && !outlineEnabled) {
|
|
|
|
|
fillEnabled = true;
|
|
|
|
|
OnFillToggle();
|
|
|
|
|
OnFillToggle(field, obj);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UpdateTweakables();
|
|
|
|
|
|
|
|
|
|
foreach (var counterpart in part.symmetryCounterparts) {
|
|
|
|
|
var decal = counterpart.GetComponent<ModuleConformalText>();
|
|
|
|
|
decal.outlineEnabled = outlineEnabled;
|
|
|
|
|
decal.UpdateTweakables();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnOutlineWidthUpdate(BaseField field, object obj) {
|
|
|
|
|
UpdateMaterials();
|
|
|
|
|
|
|
|
|
|
foreach (var counterpart in part.symmetryCounterparts) {
|
|
|
|
|
var decal = counterpart.GetComponent<ModuleConformalText>();
|
|
|
|
|
decal.outlineWidth = outlineWidth;
|
|
|
|
|
decal.UpdateMaterials();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -132,10 +205,20 @@ namespace ConformalDecals {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnDestroy() {
|
|
|
|
|
TextRenderer.UnregisterText(_currentText);
|
|
|
|
|
if (_currentText != null) TextRenderer.UnregisterText(_currentText);
|
|
|
|
|
|
|
|
|
|
base.OnDestroy();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnDetach() {
|
|
|
|
|
// close all UIs
|
|
|
|
|
if (_textEntryController != null) _textEntryController.OnClose();
|
|
|
|
|
if (_fillColorPickerController != null) _fillColorPickerController.OnClose();
|
|
|
|
|
if (_outlineColorPickerController != null) _outlineColorPickerController.OnClose();
|
|
|
|
|
|
|
|
|
|
base.OnDetach();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateTextRecursive() {
|
|
|
|
|
UpdateText();
|
|
|
|
|
|
|
|
|
@ -152,14 +235,13 @@ namespace ConformalDecals {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateText() {
|
|
|
|
|
|
|
|
|
|
// Render text
|
|
|
|
|
var newText = new DecalText(text, _font, _style);
|
|
|
|
|
var output = TextRenderer.UpdateTextNow(_currentText, newText);
|
|
|
|
|
_currentText = newText;
|
|
|
|
|
|
|
|
|
|
UpdateTexture(output);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: ASYNC RENDERING
|
|
|
|
|
// var newText = new DecalText(text, _font, _style);
|
|
|
|
|
// _currentJob = TextRenderer.UpdateText(_currentText, newText, UpdateTexture);
|
|
|
|
@ -167,25 +249,49 @@ namespace ConformalDecals {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UpdateTexture(TextRenderOutput output) {
|
|
|
|
|
var textureProperty = materialProperties.AddOrGetTextureProperty("_Decal", true);
|
|
|
|
|
textureProperty.Texture = output.Texture;
|
|
|
|
|
textureProperty.SetTile(output.Window);
|
|
|
|
|
_decalTextureProperty.Texture = output.Texture;
|
|
|
|
|
_decalTextureProperty.SetTile(output.Window);
|
|
|
|
|
_decalTextWeightProperty.value = output.Weight;
|
|
|
|
|
|
|
|
|
|
UpdateMaterials();
|
|
|
|
|
UpdateScale();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void UpdateMaterials() {
|
|
|
|
|
materialProperties.AddOrGetProperty<MaterialKeywordProperty>("DECAL_FILL").value = fillEnabled;
|
|
|
|
|
materialProperties.AddOrGetProperty<MaterialKeywordProperty>("DECAL_OUTLINE").value = outlineEnabled;
|
|
|
|
|
if (fillEnabled) {
|
|
|
|
|
materialProperties.AddOrGetProperty<MaterialColorProperty>("_DecalColor").color = fillColor;
|
|
|
|
|
}
|
|
|
|
|
_fillEnabledProperty.value = fillEnabled;
|
|
|
|
|
_fillColorProperty.color = fillColor;
|
|
|
|
|
|
|
|
|
|
if (outlineEnabled) {
|
|
|
|
|
materialProperties.AddOrGetProperty<MaterialColorProperty>("_OutlineColor").color = outlineColor;
|
|
|
|
|
materialProperties.AddOrGetProperty<MaterialFloatProperty>("_OutlineWidth").value = outlineWidth;
|
|
|
|
|
}
|
|
|
|
|
_outlineEnabledProperty.value = outlineEnabled;
|
|
|
|
|
_outlineColorProperty.color = outlineColor;
|
|
|
|
|
_outlineWidthProperty.value = outlineWidth;
|
|
|
|
|
|
|
|
|
|
base.UpdateMaterials();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void UpdateTweakables() {
|
|
|
|
|
Debug.Log($"Fields is null: {Fields == null}");
|
|
|
|
|
Debug.Log($"Actions is null: {Actions == null}");
|
|
|
|
|
var fillEnabledField = Fields[nameof(fillEnabled)];
|
|
|
|
|
var fillColorAction = Actions["SetFillColor"];
|
|
|
|
|
|
|
|
|
|
var outlineEnabledField = Fields[nameof(outlineEnabled)];
|
|
|
|
|
var outlineWidthField = Fields[nameof(outlineWidth)];
|
|
|
|
|
var outlineColorAction = Actions["SetOutlineColor"];
|
|
|
|
|
|
|
|
|
|
Debug.Log($"outlineColorAction is null: {outlineColorAction == null}");
|
|
|
|
|
|
|
|
|
|
// fillColorAction.activeEditor = fillEnabled;
|
|
|
|
|
// outlineWidthField.guiActiveEditor = outlineEnabled;
|
|
|
|
|
// outlineColorAction.activeEditor = outlineEnabled;
|
|
|
|
|
|
|
|
|
|
Debug.Log("Fart");
|
|
|
|
|
((UI_Toggle) fillEnabledField.uiControlEditor).onFieldChanged = OnFillToggle;
|
|
|
|
|
((UI_Toggle) outlineEnabledField.uiControlEditor).onFieldChanged = OnOutlineToggle;
|
|
|
|
|
((UI_FloatRange) outlineWidthField.uiControlEditor).onFieldChanged = OnOutlineWidthUpdate;
|
|
|
|
|
|
|
|
|
|
base.UpdateTweakables();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void UpdateCachedProperties() { }
|
|
|
|
|
}
|
|
|
|
|
}
|