From c8541742e2d75ee26b36b8de3e9b17b26130c851 Mon Sep 17 00:00:00 2001 From: Keelhauled <10797970+Keelhauled@users.noreply.github.com> Date: Sun, 16 Jun 2024 16:01:05 +0300 Subject: [PATCH] [ME] Color prop background and enable reset button when changed --- src/MaterialEditor.Base/UI/UI.ListEntry.cs | 110 +++++++++------------ src/MaterialEditor.Base/UI/UI.cs | 1 + 2 files changed, 50 insertions(+), 61 deletions(-) diff --git a/src/MaterialEditor.Base/UI/UI.ListEntry.cs b/src/MaterialEditor.Base/UI/UI.ListEntry.cs index 04a28d0f..ce6dd86a 100644 --- a/src/MaterialEditor.Base/UI/UI.ListEntry.cs +++ b/src/MaterialEditor.Base/UI/UI.ListEntry.cs @@ -124,7 +124,7 @@ public void SetItem(ItemInfo item, bool force) { case ItemInfo.RowItemType.Renderer: ShowRenderer(); - SetLabelText(RendererLabel, item.LabelText); + SetLabelText(RendererLabel, item.LabelText, false, null, RendererPanel); ExportUVButton.onClick.RemoveAllListeners(); ExportUVButton.onClick.AddListener(() => item.ExportUVOnClick()); ExportObjButton.onClick.RemoveAllListeners(); @@ -135,7 +135,7 @@ public void SetItem(ItemInfo item, bool force) break; case ItemInfo.RowItemType.RendererEnabled: ShowRendererEnabled(); - SetLabelText(RendererEnabledLabel, item.LabelText, item.RendererEnabled != item.RendererEnabledOriginal); + SetLabelText(RendererEnabledLabel, item.LabelText, item.RendererEnabled != item.RendererEnabledOriginal, RendererEnabledResetButton, RendererEnabledPanel); RendererEnabledToggle.onValueChanged.RemoveAllListeners(); RendererEnabledToggle.isOn = item.RendererEnabled; RendererEnabledToggle.onValueChanged.AddListener(value => @@ -145,7 +145,7 @@ public void SetItem(ItemInfo item, bool force) item.RendererEnabledOnChange(value); else item.RendererEnabledOnReset(); - SetLabelText(RendererEnabledLabel, item.LabelText, item.RendererEnabled != item.RendererEnabledOriginal); + SetLabelText(RendererEnabledLabel, item.LabelText, item.RendererEnabled != item.RendererEnabledOriginal, RendererEnabledResetButton, RendererEnabledPanel); }); RendererEnabledResetButton.onClick.RemoveAllListeners(); @@ -154,7 +154,7 @@ public void SetItem(ItemInfo item, bool force) break; case ItemInfo.RowItemType.RendererShadowCastingMode: ShowRendererShadowCastingMode(); - SetLabelText(RendererShadowCastingModeLabel, item.LabelText, item.RendererShadowCastingMode != item.RendererShadowCastingModeOriginal); + SetLabelText(RendererShadowCastingModeLabel, item.LabelText, item.RendererShadowCastingMode != item.RendererShadowCastingModeOriginal, RendererShadowCastingModeResetButton, RendererShadowCastingModePanel); RendererShadowCastingModeDropdown.onValueChanged.RemoveAllListeners(); RendererShadowCastingModeDropdown.value = item.RendererShadowCastingMode; RendererShadowCastingModeDropdown.onValueChanged.AddListener(value => @@ -164,7 +164,7 @@ public void SetItem(ItemInfo item, bool force) item.RendererShadowCastingModeOnChange(value); else item.RendererShadowCastingModeOnReset(); - SetLabelText(RendererShadowCastingModeLabel, item.LabelText, item.RendererShadowCastingMode != item.RendererShadowCastingModeOriginal); + SetLabelText(RendererShadowCastingModeLabel, item.LabelText, item.RendererShadowCastingMode != item.RendererShadowCastingModeOriginal, RendererShadowCastingModeResetButton, RendererShadowCastingModePanel); }); RendererShadowCastingModeResetButton.onClick.RemoveAllListeners(); @@ -173,7 +173,7 @@ public void SetItem(ItemInfo item, bool force) break; case ItemInfo.RowItemType.RendererReceiveShadows: ShowRendererReceiveShadows(); - SetLabelText(RendererReceiveShadowsLabel, item.LabelText, item.RendererReceiveShadows != item.RendererReceiveShadowsOriginal); + SetLabelText(RendererReceiveShadowsLabel, item.LabelText, item.RendererReceiveShadows != item.RendererReceiveShadowsOriginal, RendererReceiveShadowsResetButton, RendererReceiveShadowsPanel); RendererReceiveShadowsToggle.onValueChanged.RemoveAllListeners(); RendererReceiveShadowsToggle.isOn = item.RendererReceiveShadows; RendererReceiveShadowsToggle.onValueChanged.AddListener(value => @@ -183,7 +183,7 @@ public void SetItem(ItemInfo item, bool force) item.RendererReceiveShadowsOnChange(value); else item.RendererReceiveShadowsOnReset(); - SetLabelText(RendererReceiveShadowsLabel, item.LabelText, item.RendererReceiveShadows != item.RendererReceiveShadowsOriginal); + SetLabelText(RendererReceiveShadowsLabel, item.LabelText, item.RendererReceiveShadows != item.RendererReceiveShadowsOriginal, RendererReceiveShadowsResetButton, RendererReceiveShadowsPanel); }); RendererReceiveShadowsResetButton.onClick.RemoveAllListeners(); @@ -192,7 +192,7 @@ public void SetItem(ItemInfo item, bool force) break; case ItemInfo.RowItemType.RendererUpdateWhenOffscreen: ShowRendererUpdateWhenOffscreen(); - SetLabelText(RendererUpdateWhenOffscreenLabel, item.LabelText, item.RendererUpdateWhenOffscreen != item.RendererUpdateWhenOffscreenOriginal); + SetLabelText(RendererUpdateWhenOffscreenLabel, item.LabelText, item.RendererUpdateWhenOffscreen != item.RendererUpdateWhenOffscreenOriginal, RendererUpdateWhenOffscreenResetButton, RendererUpdateWhenOffscreenPanel); RendererUpdateWhenOffscreenToggle.onValueChanged.RemoveAllListeners(); RendererUpdateWhenOffscreenToggle.isOn = item.RendererUpdateWhenOffscreen; RendererUpdateWhenOffscreenToggle.onValueChanged.AddListener(value => @@ -202,7 +202,7 @@ public void SetItem(ItemInfo item, bool force) item.RendererUpdateWhenOffscreenOnChange(value); else item.RendererUpdateWhenOffscreenOnReset(); - SetLabelText(RendererUpdateWhenOffscreenLabel, item.LabelText, item.RendererUpdateWhenOffscreen != item.RendererUpdateWhenOffscreenOriginal); + SetLabelText(RendererUpdateWhenOffscreenLabel, item.LabelText, item.RendererUpdateWhenOffscreen != item.RendererUpdateWhenOffscreenOriginal, RendererUpdateWhenOffscreenResetButton, RendererUpdateWhenOffscreenPanel); }); RendererUpdateWhenOffscreenResetButton.onClick.RemoveAllListeners(); @@ -211,7 +211,7 @@ public void SetItem(ItemInfo item, bool force) break; case ItemInfo.RowItemType.RendererRecalculateNormals: ShowRendererRecalculateNormals(); - SetLabelText(RendererRecalculateNormalsLabel, item.LabelText, item.RendererRecalculateNormals != item.RendererRecalculateNormalsOriginal); + SetLabelText(RendererRecalculateNormalsLabel, item.LabelText, item.RendererRecalculateNormals != item.RendererRecalculateNormalsOriginal, RendererRecalculateNormalsResetButton, RendererRecalculateNormalsPanel); RendererRecalculateNormalsToggle.onValueChanged.RemoveAllListeners(); RendererRecalculateNormalsToggle.isOn = item.RendererRecalculateNormals; RendererRecalculateNormalsToggle.onValueChanged.AddListener(value => @@ -221,7 +221,7 @@ public void SetItem(ItemInfo item, bool force) item.RendererRecalculateNormalsOnChange(value); else item.RendererRecalculateNormalsOnReset(); - SetLabelText(RendererRecalculateNormalsLabel, item.LabelText, item.RendererRecalculateNormals != item.RendererRecalculateNormalsOriginal); + SetLabelText(RendererRecalculateNormalsLabel, item.LabelText, item.RendererRecalculateNormals != item.RendererRecalculateNormalsOriginal, RendererRecalculateNormalsResetButton, RendererRecalculateNormalsPanel); }); RendererRecalculateNormalsResetButton.onClick.RemoveAllListeners(); @@ -230,7 +230,7 @@ public void SetItem(ItemInfo item, bool force) break; case ItemInfo.RowItemType.Material: ShowMaterial(); - SetLabelText(MaterialLabel, item.LabelText); + SetLabelText(MaterialLabel, item.LabelText, false, null, MaterialPanel); MaterialText.text = item.MaterialName; MaterialCopyButton.onClick.RemoveAllListeners(); MaterialCopyButton.onClick.AddListener(() => item.MaterialOnCopy.Invoke()); @@ -270,7 +270,7 @@ public void SetItem(ItemInfo item, bool force) break; case ItemInfo.RowItemType.Shader: ShowShader(); - SetLabelText(ShaderLabel, item.LabelText, item.ShaderName != item.ShaderNameOriginal); + SetLabelText(ShaderLabel, item.LabelText, item.ShaderName != item.ShaderNameOriginal, ShaderResetButton, ShaderPanel); ShaderDropdown.onValueChanged.RemoveAllListeners(); ShaderDropdown.value = ShaderDropdown.OptionIndex(item.ShaderName); ShaderDropdown.captionText.text = item.ShaderName; @@ -285,7 +285,7 @@ public void SetItem(ItemInfo item, bool force) item.ShaderNameOnChange(item.ShaderName); else item.ShaderNameOnReset(); - SetLabelText(ShaderLabel, item.LabelText, item.ShaderName != item.ShaderNameOriginal); + SetLabelText(ShaderLabel, item.LabelText, item.ShaderName != item.ShaderNameOriginal, ShaderResetButton, ShaderPanel); }); ShaderResetButton.onClick.RemoveAllListeners(); @@ -299,7 +299,7 @@ public void SetItem(ItemInfo item, bool force) break; case ItemInfo.RowItemType.ShaderRenderQueue: ShowShaderRenderQueue(); - SetLabelText(ShaderRenderQueueLabel, item.LabelText, item.ShaderRenderQueue != item.ShaderRenderQueueOriginal); + SetLabelText(ShaderRenderQueueLabel, item.LabelText, item.ShaderRenderQueue != item.ShaderRenderQueueOriginal, ShaderRenderQueueResetButton, ShaderRenderQueuePanel); ShaderRenderQueueInput.onEndEdit.RemoveAllListeners(); ShaderRenderQueueInput.text = item.ShaderRenderQueue.ToString(); ShaderRenderQueueInput.onEndEdit.AddListener(value => @@ -317,7 +317,7 @@ public void SetItem(ItemInfo item, bool force) item.ShaderRenderQueueOnChange(item.ShaderRenderQueue); else item.ShaderRenderQueueOnReset(); - SetLabelText(ShaderRenderQueueLabel, item.LabelText, item.ShaderRenderQueue != item.ShaderRenderQueueOriginal); + SetLabelText(ShaderRenderQueueLabel, item.LabelText, item.ShaderRenderQueue != item.ShaderRenderQueueOriginal, ShaderRenderQueueResetButton, ShaderRenderQueuePanel); }); ShaderRenderQueueResetButton.onClick.RemoveAllListeners(); @@ -326,13 +326,13 @@ public void SetItem(ItemInfo item, bool force) ShaderRenderQueueInput.text = item.ShaderRenderQueueOriginal.ToString(); item.ShaderRenderQueue = item.ShaderRenderQueueOriginal; item.ShaderRenderQueueOnReset(); - SetLabelText(ShaderRenderQueueLabel, item.LabelText, item.ShaderRenderQueue != item.ShaderRenderQueueOriginal); + SetLabelText(ShaderRenderQueueLabel, item.LabelText, item.ShaderRenderQueue != item.ShaderRenderQueueOriginal, ShaderRenderQueueResetButton, ShaderRenderQueuePanel); }); break; case ItemInfo.RowItemType.TextureProperty: ShowTexture(); - SetLabelText(TextureLabel, item.LabelText, item.TextureChanged); + SetLabelText(TextureLabel, item.LabelText, item.TextureChanged, TextureResetButton, TexturePanel); ConfigureExportButton(); void ConfigureExportButton() @@ -362,7 +362,7 @@ void ConfigureExportButton() item.TextureExists = true; item.TextureOnImport(); ConfigureExportButton(); - SetLabelText(TextureLabel, item.LabelText, item.TextureChanged); + SetLabelText(TextureLabel, item.LabelText, item.TextureChanged, TextureResetButton, TexturePanel); }); TextureResetButton.onClick.RemoveAllListeners(); @@ -370,14 +370,14 @@ void ConfigureExportButton() { item.TextureChanged = false; item.TextureOnReset(); - SetLabelText(TextureLabel, item.LabelText, item.TextureChanged); + SetLabelText(TextureLabel, item.LabelText, item.TextureChanged, TextureResetButton, TexturePanel); }); SelectInterpolableTextureButton.onClick.RemoveAllListeners(); SelectInterpolableTextureButton.onClick.AddListener(() => item.SelectInterpolableButtonTextureOnClick()); break; case ItemInfo.RowItemType.TextureOffsetScale: ShowOffsetScale(); - SetLabelText(OffsetScaleLabel, item.LabelText, item.Offset != item.OffsetOriginal || item.Scale != item.ScaleOriginal); + SetLabelText(OffsetScaleLabel, item.LabelText, item.Offset != item.OffsetOriginal || item.Scale != item.ScaleOriginal, OffsetScaleResetButton, OffsetScalePanel); OffsetXInput.onEndEdit.RemoveAllListeners(); OffsetYInput.onEndEdit.RemoveAllListeners(); @@ -405,7 +405,7 @@ void ConfigureExportButton() else item.OffsetOnChange(item.Offset); - SetLabelText(OffsetScaleLabel, item.LabelText, item.Offset != item.OffsetOriginal || item.Scale != item.ScaleOriginal); + SetLabelText(OffsetScaleLabel, item.LabelText, item.Offset != item.OffsetOriginal || item.Scale != item.ScaleOriginal, OffsetScaleResetButton, OffsetScalePanel); }); OffsetYInput.onEndEdit.AddListener(value => @@ -424,7 +424,7 @@ void ConfigureExportButton() else item.OffsetOnChange(item.Offset); - SetLabelText(OffsetScaleLabel, item.LabelText, item.Offset != item.OffsetOriginal || item.Scale != item.ScaleOriginal); + SetLabelText(OffsetScaleLabel, item.LabelText, item.Offset != item.OffsetOriginal || item.Scale != item.ScaleOriginal, OffsetScaleResetButton, OffsetScalePanel); }); ScaleXInput.onEndEdit.AddListener(value => @@ -443,7 +443,7 @@ void ConfigureExportButton() else item.ScaleOnChange(item.Scale); - SetLabelText(OffsetScaleLabel, item.LabelText, item.Offset != item.OffsetOriginal || item.Scale != item.ScaleOriginal); + SetLabelText(OffsetScaleLabel, item.LabelText, item.Offset != item.OffsetOriginal || item.Scale != item.ScaleOriginal, OffsetScaleResetButton, OffsetScalePanel); }); ScaleYInput.onEndEdit.AddListener(value => @@ -462,7 +462,7 @@ void ConfigureExportButton() else item.ScaleOnChange(item.Scale); - SetLabelText(OffsetScaleLabel, item.LabelText, item.Offset != item.OffsetOriginal || item.Scale != item.ScaleOriginal); + SetLabelText(OffsetScaleLabel, item.LabelText, item.Offset != item.OffsetOriginal || item.Scale != item.ScaleOriginal, OffsetScaleResetButton, OffsetScalePanel); }); OffsetScaleResetButton.onClick.RemoveAllListeners(); @@ -478,13 +478,13 @@ void ConfigureExportButton() item.OffsetOnReset(); item.ScaleOnReset(); - SetLabelText(OffsetScaleLabel, item.LabelText, item.Offset != item.OffsetOriginal || item.Scale != item.ScaleOriginal); + SetLabelText(OffsetScaleLabel, item.LabelText, item.Offset != item.OffsetOriginal || item.Scale != item.ScaleOriginal, OffsetScaleResetButton, OffsetScalePanel); }); break; case ItemInfo.RowItemType.ColorProperty: ShowColor(); - SetLabelText(ColorLabel, item.LabelText, item.ColorValue != item.ColorValueOriginal); + SetLabelText(ColorLabel, item.LabelText, item.ColorValue != item.ColorValueOriginal, ColorResetButton, ColorPanel); ColorRInput.onEndEdit.RemoveAllListeners(); ColorGInput.onEndEdit.RemoveAllListeners(); @@ -517,7 +517,7 @@ void ConfigureExportButton() ColorEditButton.image.color = item.ColorValue; item.ColorValueSetToPalette(item.LabelText, item.ColorValue); - SetLabelText(ColorLabel, item.LabelText, item.ColorValue != item.ColorValueOriginal); + SetLabelText(ColorLabel, item.LabelText, item.ColorValue != item.ColorValueOriginal, ColorResetButton, ColorPanel); }); ColorGInput.onEndEdit.AddListener(value => @@ -539,7 +539,7 @@ void ConfigureExportButton() ColorEditButton.image.color = item.ColorValue; item.ColorValueSetToPalette(item.LabelText, item.ColorValue); - SetLabelText(ColorLabel, item.LabelText, item.ColorValue != item.ColorValueOriginal); + SetLabelText(ColorLabel, item.LabelText, item.ColorValue != item.ColorValueOriginal, ColorResetButton, ColorPanel); }); ColorBInput.onEndEdit.AddListener(value => @@ -561,7 +561,7 @@ void ConfigureExportButton() ColorEditButton.image.color = item.ColorValue; item.ColorValueSetToPalette(item.LabelText, item.ColorValue); - SetLabelText(ColorLabel, item.LabelText, item.ColorValue != item.ColorValueOriginal); + SetLabelText(ColorLabel, item.LabelText, item.ColorValue != item.ColorValueOriginal, ColorResetButton, ColorPanel); }); ColorAInput.onEndEdit.AddListener(value => @@ -583,7 +583,7 @@ void ConfigureExportButton() ColorEditButton.image.color = item.ColorValue; item.ColorValueSetToPalette(item.LabelText, item.ColorValue); - SetLabelText(ColorLabel, item.LabelText, item.ColorValue != item.ColorValueOriginal); + SetLabelText(ColorLabel, item.LabelText, item.ColorValue != item.ColorValueOriginal, ColorResetButton, ColorPanel); }); ColorResetButton.onClick.RemoveAllListeners(); @@ -600,7 +600,7 @@ void ConfigureExportButton() item.ColorValueSetToPalette(item.LabelText, item.ColorValue); item.ColorValueOnReset(); - SetLabelText(ColorLabel, item.LabelText, item.ColorValue != item.ColorValueOriginal); + SetLabelText(ColorLabel, item.LabelText, item.ColorValue != item.ColorValueOriginal, ColorResetButton, ColorPanel); }); ColorEditButton.onClick.RemoveAllListeners(); @@ -623,7 +623,7 @@ void onChanged(Color c) else item.ColorValueOnChange(item.ColorValue); - SetLabelText(ColorLabel, item.LabelText, item.ColorValue != item.ColorValueOriginal); + SetLabelText(ColorLabel, item.LabelText, item.ColorValue != item.ColorValueOriginal, ColorResetButton, ColorPanel); } }); SelectInterpolableColorButton.onClick.RemoveAllListeners(); @@ -632,7 +632,7 @@ void onChanged(Color c) break; case ItemInfo.RowItemType.FloatProperty: ShowFloat(); - SetLabelText(FloatLabel, item.LabelText, item.FloatValue != item.FloatValueOriginal); + SetLabelText(FloatLabel, item.LabelText, item.FloatValue != item.FloatValueOriginal, FloatResetButton, FloatPanel); FloatSlider.onValueChanged.RemoveAllListeners(); FloatInputField.onEndEdit.RemoveAllListeners(); @@ -664,7 +664,7 @@ void onChanged(Color c) else item.FloatValueOnChange(item.FloatValue); - SetLabelText(FloatLabel, item.LabelText, item.FloatValue != item.FloatValueOriginal); + SetLabelText(FloatLabel, item.LabelText, item.FloatValue != item.FloatValueOriginal, FloatResetButton, FloatPanel); }); FloatResetButton.onClick.RemoveAllListeners(); @@ -676,14 +676,14 @@ void onChanged(Color c) FloatInputField.text = item.FloatValue.ToString(); item.FloatValueOnReset(); - SetLabelText(FloatLabel, item.LabelText, item.FloatValue != item.FloatValueOriginal); + SetLabelText(FloatLabel, item.LabelText, item.FloatValue != item.FloatValueOriginal, FloatResetButton, FloatPanel); }); SelectInterpolableFloatButton.onClick.RemoveAllListeners(); SelectInterpolableFloatButton.onClick.AddListener(() => item.SelectInterpolableButtonFloatOnClick()); break; case ItemInfo.RowItemType.KeywordProperty: ShowKeyword(); - SetLabelText(KeywordLabel, item.LabelText, item.KeywordValue != item.KeywordValueOriginal); + SetLabelText(KeywordLabel, item.LabelText, item.KeywordValue != item.KeywordValueOriginal, KeywordResetButton, KeywordPanel); KeywordToggle.onValueChanged.RemoveAllListeners(); KeywordToggle.isOn = item.KeywordValue; @@ -696,7 +696,7 @@ void onChanged(Color c) else item.KeywordValueOnChange(item.KeywordValue); - SetLabelText(KeywordLabel, item.LabelText, item.KeywordValue != item.KeywordValueOriginal); + SetLabelText(KeywordLabel, item.LabelText, item.KeywordValue != item.KeywordValueOriginal, KeywordResetButton, KeywordPanel); }); KeywordResetButton.onClick.RemoveAllListeners(); @@ -707,7 +707,7 @@ void onChanged(Color c) KeywordToggle.Set(item.KeywordValue); item.KeywordValueOnReset(); - SetLabelText(KeywordLabel, item.LabelText, item.KeywordValue != item.KeywordValueOriginal); + SetLabelText(KeywordLabel, item.LabelText, item.KeywordValue != item.KeywordValueOriginal, KeywordResetButton, KeywordPanel); }); break; } @@ -720,33 +720,21 @@ public void SetVisible(bool visible) gameObject.SetActive(visible); } - private static void SetLabelText(Text label, string text, bool valueChanged = false) + private static void SetLabelText(Text label, string text, bool valueChanged, Button resetBtn, CanvasGroup panel) { - if (text.IsNullOrEmpty()) + label.text = text ?? ""; + + if (valueChanged) { - if (valueChanged) - { - label.text = "*"; - label.fontStyle = FontStyle.Bold; - } - else - { - label.text = ""; - label.fontStyle = FontStyle.Normal; - } + panel.gameObject.GetComponent().color = MaterialEditorUI.ItemColorChanged; + if (resetBtn) + resetBtn.interactable = true; } else { - if (valueChanged) - { - label.text = text + ":*"; - label.fontStyle = FontStyle.Bold; - } - else - { - label.text = text + ":"; - label.fontStyle = FontStyle.Normal; - } + panel.gameObject.GetComponent().color = MaterialEditorUI.ItemColor; + if (resetBtn) + resetBtn.interactable = false; } } private void HideAll() diff --git a/src/MaterialEditor.Base/UI/UI.cs b/src/MaterialEditor.Base/UI/UI.cs index 9986d6e3..49e5239e 100644 --- a/src/MaterialEditor.Base/UI/UI.cs +++ b/src/MaterialEditor.Base/UI/UI.cs @@ -63,6 +63,7 @@ public abstract class MaterialEditorUI : BaseUnityPlugin internal static RectOffset Padding; internal static readonly Color RowColor = new Color(1f, 1f, 1f, 0.6f); internal static readonly Color ItemColor = new Color(1f, 1f, 1f, 0f); + internal static readonly Color ItemColorChanged = new Color(0f, 0f, 0f, 0.3f); internal static readonly Color SeparatorItemColor = new Color(0.9f, 0.9f, 0.9f, 0.55f); private protected IMaterialEditorColorPalette ColorPalette;