From 952f20fda529c80203c88ea4aa8408667af9227d Mon Sep 17 00:00:00 2001 From: DMagic Date: Tue, 21 Feb 2017 11:32:26 -0500 Subject: [PATCH] Color management window --- SCANsat.Unity/Interfaces/ISCAN_Color.cs | 116 ++++ SCANsat.Unity/SCAN_ColorPicker.cs | 91 +++ SCANsat.Unity/Unity/SCAN_ColorAltimetry.cs | 671 +++++++++++++++++++++ SCANsat.Unity/Unity/SCAN_ColorBiome.cs | 179 ++++++ SCANsat.Unity/Unity/SCAN_ColorControl.cs | 195 ++++++ SCANsat.Unity/Unity/SCAN_ColorResource.cs | 455 ++++++++++++++ SCANsat.Unity/Unity/SCAN_ColorSlope.cs | 119 ++++ SCANsat.Unity/Unity/SCAN_PaletteButton.cs | 33 + SCANsat/SCAN_Unity/SCAN_UI_Color.cs | 670 ++++++++++++++++++++ 9 files changed, 2529 insertions(+) create mode 100644 SCANsat.Unity/Interfaces/ISCAN_Color.cs create mode 100644 SCANsat.Unity/SCAN_ColorPicker.cs create mode 100644 SCANsat.Unity/Unity/SCAN_ColorAltimetry.cs create mode 100644 SCANsat.Unity/Unity/SCAN_ColorBiome.cs create mode 100644 SCANsat.Unity/Unity/SCAN_ColorControl.cs create mode 100644 SCANsat.Unity/Unity/SCAN_ColorResource.cs create mode 100644 SCANsat.Unity/Unity/SCAN_ColorSlope.cs create mode 100644 SCANsat.Unity/Unity/SCAN_PaletteButton.cs create mode 100644 SCANsat/SCAN_Unity/SCAN_UI_Color.cs diff --git a/SCANsat.Unity/Interfaces/ISCAN_Color.cs b/SCANsat.Unity/Interfaces/ISCAN_Color.cs new file mode 100644 index 000000000..4c683d2c3 --- /dev/null +++ b/SCANsat.Unity/Interfaces/ISCAN_Color.cs @@ -0,0 +1,116 @@ +using System; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; + +namespace SCANsat.Unity.Interfaces +{ + public interface ISCAN_Color + { + string ResourcePlanet { get; set; } + + string ResourceCurrent { get; set; } + + string TerrainPlanet { get; set; } + + string TerrainPalette { get; set; } + + string TerrainPaletteStyle { get; set; } + + bool BiomeBigMapStockColor { get; set; } + + bool BiomeBigMapWhiteBoder { get; set; } + + bool BiomeSmallMapStockColor { get; set; } + + bool BiomeSmallMapWhiteBorder { get; set; } + + bool TerrainClampOn { get; set; } + + bool TerrainReverse { get; set; } + + bool TerrainDiscrete { get; set; } + + bool TerrainHasSize { get; } + + float BiomeTransparency { get; set; } + + float SlopeCutoff { get; set; } + + float ResourceMin { get; set; } + + float ResourceMax { get; set; } + + float ResourceTransparency { get; set; } + + float TerrainCurrentMin { get; set; } + + float TerrainGlobalMin { get; } + + float TerrainCurrentMax { get; set; } + + float TerrainGlobalMax { get; } + + float TerrainClamp { get; set; } + + int TerrainSize { get; set; } + + int TerrainSizeMin { get; } + + int TerrainSizeMax { get; } + + Color BiomeColorOne { get; } + + Color BiomeColorTwo { get; } + + Color SlopeColorOneLo { get; } + + Color SlopeColorOneHi { get; } + + Color SlopeColorTwoLo { get; } + + Color SlopeColorTwoHi { get; } + + Color ResourceColorOne { get; } + + Color ResourceColorTwo { get; } + + Texture2D TerrainPaletteOld { get; } + + Texture2D TerrainPaletteNew { get; } + + IList> TerrainPalettes { get; } + + IList Resources { get; } + + IList CelestialBodies { get; } + + IList PaletteStyleNames { get; } + + void BiomeApply(Color one, Color two); + + void BiomeDefault(); + + void SlopeApply(Color oneLow, Color oneHigh, Color twoLow, Color twoHigh); + + void SlopeDefault(); + + void ResourceApply(Color one, Color two); + + void ResourceApplyToAll(Color one, Color two); + + void ResourceDefault(); + + void ResourceDefaultToAll(); + + void ResourceSaveToConfig(Color one, Color two); + + void TerrainApply(); + + void TerrainDefault(); + + void TerrainSaveToConfig(); + + void Refresh(); + } +} diff --git a/SCANsat.Unity/SCAN_ColorPicker.cs b/SCANsat.Unity/SCAN_ColorPicker.cs new file mode 100644 index 000000000..9488ee08b --- /dev/null +++ b/SCANsat.Unity/SCAN_ColorPicker.cs @@ -0,0 +1,91 @@ +using System; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; +using SCANsat.Unity.HSVPicker.UI; + +namespace SCANsat.Unity +{ + public class SCAN_ColorPicker : MonoBehaviour + { + [SerializeField] + private ColorImage m_ColorOne = null; + [SerializeField] + private ColorImage m_ColorTwo = null; + [SerializeField] + private Image m_OldColorOne = null; + [SerializeField] + private Image m_OldColorTwo = null; + + private ColorPicker picker; + + public Color GetColorOne + { + get { return m_ColorOne.CurrentColor; } + } + + public Color GetColorTwo + { + get { return m_ColorTwo.CurrentColor; } + } + + private void Awake() + { + picker = GetComponent(); + } + + public void Setup(Color one, Color two, bool reset) + { + if (picker != null && reset) + picker.CurrentColor = one; + + if (m_ColorOne != null) + { + m_ColorOne.SetColor(one); + + if (reset) + m_ColorOne.IsActive = true; + } + + if (m_ColorTwo != null) + m_ColorTwo.SetColor(two); + + if (m_OldColorOne != null) + m_OldColorOne.color = one; + + if (m_OldColorTwo != null) + m_OldColorTwo.color = two; + } + + public void ColorOne(bool isOn) + { + if (m_ColorOne == null) + return; + + m_ColorOne.IsActive = isOn; + + if (isOn) + picker.CurrentColor = m_ColorOne.CurrentColor; + } + + public void ColorTwo(bool isOn) + { + if (m_ColorTwo == null) + return; + + m_ColorTwo.IsActive = isOn; + + if (isOn) + picker.CurrentColor = m_ColorTwo.CurrentColor; + } + + public void Apply() + { + if (m_OldColorOne != null && m_ColorOne != null) + m_OldColorOne.color = m_ColorOne.CurrentColor; + + if (m_OldColorTwo != null && m_ColorTwo != null) + m_OldColorTwo.color = m_ColorTwo.CurrentColor; + } + } +} diff --git a/SCANsat.Unity/Unity/SCAN_ColorAltimetry.cs b/SCANsat.Unity/Unity/SCAN_ColorAltimetry.cs new file mode 100644 index 000000000..a0f106877 --- /dev/null +++ b/SCANsat.Unity/Unity/SCAN_ColorAltimetry.cs @@ -0,0 +1,671 @@ +using System; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; +using UnityEngine.Events; +using UnityEngine.EventSystems; +using SCANsat.Unity.Interfaces; +using SCANsat.Unity.HSVPicker.UI; + +namespace SCANsat.Unity.Unity +{ + public class SCAN_ColorAltimetry : SettingsPage + { + [SerializeField] + private ToggleGroup m_DropDownToggles = null; + [SerializeField] + private GameObject m_PalettePrefab = null; + [SerializeField] + private Transform m_PaletteGrid = null; + [SerializeField] + private Transform m_PaletteSelection = null; + [SerializeField] + private TextHandler m_PaletteName = null; + [SerializeField] + private RawImage m_PaletteOld = null; + [SerializeField] + private RawImage m_PalettePreview = null; + [SerializeField] + private Transform m_PlanetSelection = null; + [SerializeField] + private TextHandler m_PlanetName = null; + [SerializeField] + private Slider m_MinSlider = null; + [SerializeField] + private Slider m_MaxSlider = null; + [SerializeField] + private Slider m_ClampSlider = null; + [SerializeField] + private Slider m_SizeSlider = null; + [SerializeField] + private GameObject m_ClampObject = null; + [SerializeField] + private GameObject m_SizeObject = null; + [SerializeField] + private TextHandler m_MinSliderLabelOne = null; + [SerializeField] + private TextHandler m_MinSliderLabelTwo = null; + [SerializeField] + private TextHandler m_MaxSliderLabelOne = null; + [SerializeField] + private TextHandler m_MaxSliderLabelTwo = null; + [SerializeField] + private TextHandler m_ClampSliderLabelOne = null; + [SerializeField] + private TextHandler m_ClampSliderLabelTwo = null; + [SerializeField] + private TextHandler m_SizeSliderLabelOne = null; + [SerializeField] + private TextHandler m_SizeSliderLabelTwo = null; + [SerializeField] + private TextHandler m_MinText = null; + [SerializeField] + private TextHandler m_MaxText = null; + [SerializeField] + private TextHandler m_ClampText = null; + [SerializeField] + private TextHandler m_SizeText = null; + [SerializeField] + private InputField m_MinInputField = null; + [SerializeField] + private InputField m_MaxInputField = null; + [SerializeField] + private InputField m_ClampInputField = null; + [SerializeField] + private Toggle m_ClampToggle = null; + [SerializeField] + private Toggle m_ReverseToggle = null; + [SerializeField] + private Toggle m_DiscreteToggle = null; + + private bool loaded; + + private ISCAN_Color colorInterface; + private ISCAN_Settings settingsInterface; + + private List paletteButtons = new List(); + + private void Awake() + { + if (m_MinInputField != null) + m_MinInputField.onValueChanged.AddListener(new UnityAction(OnMinInputChange)); + + if (m_MaxInputField != null) + m_MaxInputField.onValueChanged.AddListener(new UnityAction(OnMaxInputChange)); + + if (m_ClampInputField != null) + m_ClampInputField.onValueChanged.AddListener(new UnityAction(OnClampInputChange)); + } + + private void Update() + { + if (settingsInterface == null) + return; + + if (settingsInterface.LockInput) + { + if (m_MinInputField != null && !m_MinInputField.isFocused + && m_MaxInputField != null && !m_MaxInputField.isFocused + && m_ClampInputField != null && !m_ClampInputField.isFocused) + settingsInterface.LockInput = false; + } + } + + public void SetTerrain(ISCAN_Color color, ISCAN_Settings settings) + { + if (color == null || settings == null) + return; + + colorInterface = color; + settingsInterface = settings; + + color.Refresh(); + + SetUI(); + } + + private void SetUI() + { + if (colorInterface == null) + return; + + SetMinSlider(); + + SetMaxSlider(); + + if (m_MinSlider != null) + m_MinSlider.value = colorInterface.TerrainCurrentMin; + + if (m_MaxSlider != null) + m_MaxSlider.value = colorInterface.TerrainCurrentMax; + + if (colorInterface.TerrainClampOn && m_ClampSlider != null) + m_ClampSlider.value = colorInterface.TerrainClamp; + + if (m_ClampToggle != null) + m_ClampToggle.isOn = colorInterface.TerrainClampOn; + + if (m_ReverseToggle != null) + m_ReverseToggle.isOn = colorInterface.TerrainReverse; + + if (m_DiscreteToggle != null) + m_DiscreteToggle.isOn = colorInterface.TerrainDiscrete; + + if (m_PaletteName != null) + m_PaletteName.OnTextUpdate.Invoke(colorInterface.TerrainPaletteStyle); + + if (m_PlanetName != null) + m_PlanetName.OnTextUpdate.Invoke(colorInterface.TerrainPlanet); + + if (m_PaletteName != null) + m_PaletteName.OnTextUpdate.Invoke(colorInterface.TerrainPaletteStyle); + + CreatePalettes(colorInterface.TerrainPalettes); + + SetPalettePreviews(); + + SetSizeSlider(); + + loaded = true; + } + + public void OnInputClick(BaseEventData eventData) + { + if (!(eventData is PointerEventData) || settingsInterface == null) + return; + + if (((PointerEventData)eventData).button != PointerEventData.InputButton.Left) + return; + + settingsInterface.LockInput = true; + } + + public override void OnPointerDown(PointerEventData eventData) + { + if (SCAN_Settings.Instance == null) + return; + + if (SCAN_Settings.Instance.DropDown == null) + return; + + RectTransform r = SCAN_Settings.Instance.DropDown.GetComponent(); + + if (r == null) + return; + + if (RectTransformUtility.RectangleContainsScreenPoint(r, eventData.position, eventData.pressEventCamera)) + return; + + SCAN_Settings.Instance.DropDown.FadeOut(); + SCAN_Settings.Instance.DropDown = null; + + if (m_DropDownToggles != null) + m_DropDownToggles.SetAllTogglesOff(); + } + + public void PaletteStyleDropDown(bool isOn) + { + if (SCAN_Settings.Instance.DropDown != null) + { + SCAN_Settings.Instance.DropDown.FadeOut(true); + SCAN_Settings.Instance.DropDown = null; + } + + if (!isOn) + return; + + if (m_PaletteSelection == null || SCAN_Settings.Instance.DropDownPrefab == null || colorInterface == null) + return; + + SCAN_Settings.Instance.DropDown = Instantiate(SCAN_Settings.Instance.DropDownPrefab).GetComponent(); + + if (SCAN_Settings.Instance.DropDown == null) + return; + + SCAN_Settings.Instance.DropDown.transform.SetParent(m_PaletteSelection, false); + + SCAN_Settings.Instance.DropDown.Setup(colorInterface.PaletteStyleNames, colorInterface.TerrainPaletteStyle); + + SCAN_Settings.Instance.DropDown.OnSelectUpdate.AddListener(new UnityEngine.Events.UnityAction(PaletteStyle)); + } + + public void PaletteStyle(string style) + { + if (m_PaletteName != null) + m_PaletteName.OnTextUpdate.Invoke(style); + + SCAN_Settings.Instance.DropDown.FadeOut(true); + SCAN_Settings.Instance.DropDown = null; + + if (m_DropDownToggles != null) + m_DropDownToggles.SetAllTogglesOff(); + + if (colorInterface == null) + return; + + colorInterface.TerrainPaletteStyle = style; + + ClearPalettes(); + + CreatePalettes(colorInterface.TerrainPalettes); + + SetPalettePreviews(); + + SetSizeSlider(); + } + + private void ClearPalettes() + { + for (int i = paletteButtons.Count - 1; i >= 0; i--) + { + SCAN_PaletteButton button = paletteButtons[i]; + + button.gameObject.SetActive(false); + DestroyImmediate(button.gameObject); + } + + paletteButtons.Clear(); + } + + private void CreatePalettes(IList> palettes) + { + if (colorInterface == null || m_PaletteGrid == null || m_PalettePrefab == null || palettes == null) + return; + + for (int i = 0; i < palettes.Count; i++) + { + KeyValuePair palette = palettes[i]; + + CreatePalette(palette); + } + } + + private void CreatePalette(KeyValuePair palette) + { + SCAN_PaletteButton button = Instantiate(m_PalettePrefab).GetComponent(); + + if (button == null) + return; + + button.transform.SetParent(m_PaletteGrid, false); + + button.setup(palette.Value, palette.Key, this); + + paletteButtons.Add(button); + } + + public void SetPalette(string palette) + { + if (string.IsNullOrEmpty(palette) || colorInterface == null) + return; + + colorInterface.TerrainPalette = palette; + + SetPalettePreviews(); + + SetSizeSlider(); + } + + private void SetPalettePreviews() + { + if (colorInterface == null) + return; + + if (m_PaletteOld != null) + m_PaletteOld.texture = colorInterface.TerrainPaletteOld; + + if (m_PalettePreview != null) + m_PalettePreview.texture = colorInterface.TerrainPaletteNew; + } + + public void PlanetDropDown(bool isOn) + { + if (SCAN_Settings.Instance.DropDown != null) + { + SCAN_Settings.Instance.DropDown.FadeOut(true); + SCAN_Settings.Instance.DropDown = null; + } + + if (!isOn) + return; + + if (m_PlanetSelection == null || SCAN_Settings.Instance.DropDownPrefab == null || colorInterface == null) + return; + + SCAN_Settings.Instance.DropDown = Instantiate(SCAN_Settings.Instance.DropDownPrefab).GetComponent(); + + if (SCAN_Settings.Instance.DropDown == null) + return; + + SCAN_Settings.Instance.DropDown.transform.SetParent(m_PlanetSelection, false); + + SCAN_Settings.Instance.DropDown.Setup(colorInterface.CelestialBodies, colorInterface.TerrainPlanet); + + SCAN_Settings.Instance.DropDown.OnSelectUpdate.AddListener(new UnityEngine.Events.UnityAction(Planet)); + } + + public void Planet(string planet) + { + SCAN_Settings.Instance.DropDown.FadeOut(true); + SCAN_Settings.Instance.DropDown = null; + + if (m_DropDownToggles != null) + m_DropDownToggles.SetAllTogglesOff(); + + if (colorInterface == null) + return; + + colorInterface.TerrainPlanet = planet; + + loaded = false; + + ClearPalettes(); + + SetUI(); + } + + public void OnMinChange(float value) + { + if (colorInterface == null) + return; + + float max = (((int)(colorInterface.TerrainCurrentMax * 100)) / 100) - 200; + + if (value > max) + value = max; + else if (value < colorInterface.TerrainGlobalMin) + value = colorInterface.TerrainGlobalMin; + + colorInterface.TerrainCurrentMin = value; + + SetMaxSlider(); + + if (m_MinText != null) + m_MinText.OnTextUpdate.Invoke(string.Format("Min: {0:N0}m", value)); + + if (colorInterface.TerrainClampOn) + SetClamp(); + } + + public void OnMinInputChange(string input) + { + if (m_MinSlider == null) + return; + + float min = SCAN_ColorControl.ParseInput(input, m_MinSlider.value, m_MinSlider.minValue, m_MinSlider.maxValue, 0); + + if (min != m_MinSlider.value) + m_MinSlider.value = min; + } + + public void OnMaxChange(float value) + { + if (colorInterface == null) + return; + + float min = (((int)(colorInterface.TerrainCurrentMin * 100)) / 100) + 200; + + if (value < min) + value = min; + else if (value > colorInterface.TerrainGlobalMax) + value = colorInterface.TerrainGlobalMax; + + colorInterface.TerrainCurrentMax = value; + + SetMinSlider(); + + if (m_MaxText != null) + m_MaxText.OnTextUpdate.Invoke(string.Format("Max: {0:N0}m", value)); + + if (colorInterface.TerrainClampOn) + SetClamp(); + } + + public void OnMaxInputChange(string input) + { + if (m_MaxSlider == null) + return; + + float max = SCAN_ColorControl.ParseInput(input, m_MaxSlider.value, m_MaxSlider.minValue, m_MaxSlider.maxValue, 0); + + if (max != m_MaxSlider.value) + m_MaxSlider.value = max; + } + + public void OnClampChange(float value) + { + if (colorInterface == null) + return; + + if (m_ClampText != null) + m_ClampText.OnTextUpdate.Invoke(string.Format("Clamp: {0:N0}m", value)); + + if (!loaded) + return; + + colorInterface.TerrainClamp = value; + } + + public void OnClampInputChange(string input) + { + if (m_ClampSlider == null) + return; + + float clamp = SCAN_ColorControl.ParseInput(input, m_ClampSlider.value, m_ClampSlider.minValue, m_ClampSlider.maxValue, 0); + + if (clamp != m_ClampSlider.value) + m_ClampSlider.value = clamp; + } + + public void ClampToggle(bool isOn) + { + if (m_ClampObject != null) + m_ClampObject.SetActive(isOn); + + if (isOn) + SetClamp(); + + if (!loaded || colorInterface == null) + return; + + colorInterface.TerrainClampOn = isOn; + + SetPalettePreviews(); + } + + private void SetMinSlider() + { + if (colorInterface == null || m_MinSlider == null) + return; + + float min = (((int)(colorInterface.TerrainGlobalMin * 100)) / 100); + + float max = (((int)(colorInterface.TerrainCurrentMax * 100)) / 100) - 200; + + m_MinSlider.minValue = min; + m_MinSlider.maxValue = max; + + if (m_MinSliderLabelOne != null) + m_MinSliderLabelOne.OnTextUpdate.Invoke(string.Format("|\n{0:N0}m", min)); + + if (m_MinSliderLabelTwo != null) + m_MinSliderLabelTwo.OnTextUpdate.Invoke(string.Format("|\n{0:N0}m", max)); + } + + private void SetMaxSlider() + { + if (colorInterface == null || m_MaxSlider == null) + return; + + float min = (((int)(colorInterface.TerrainCurrentMin * 100)) / 100) + 200; + + float max = (((int)(colorInterface.TerrainGlobalMax * 100)) / 100); + + m_MaxSlider.minValue = min; + m_MaxSlider.maxValue = max; + + if (m_MaxSliderLabelOne != null) + m_MaxSliderLabelOne.OnTextUpdate.Invoke(string.Format("|\n{0:N0}m", min)); + + if (m_MaxSliderLabelTwo != null) + m_MaxSliderLabelTwo.OnTextUpdate.Invoke(string.Format("|\n{0:N0}m", max)); + } + + private void SetClamp() + { + if (colorInterface == null || m_ClampSlider == null) + return; + + float min = (((int)(colorInterface.TerrainCurrentMin * 100)) / 100) + 100; + + float max = (((int)(colorInterface.TerrainCurrentMax * 100)) / 100) - 100; + + m_ClampSlider.minValue = min; + m_ClampSlider.maxValue = max; + + if (m_ClampSliderLabelOne != null) + m_ClampSliderLabelOne.OnTextUpdate.Invoke(string.Format("|\n{0:N0}m", min)); + + if (m_ClampSliderLabelTwo != null) + m_ClampSliderLabelTwo.OnTextUpdate.Invoke(string.Format("|\n{0:N0}m", max)); + + float clamp = colorInterface.TerrainClamp; + + if (clamp <= min) + clamp = min; + else if (clamp >= max) + clamp = max; + + m_ClampSlider.value = clamp; + } + + private void SetSizeSlider() + { + if (colorInterface == null || m_SizeSlider == null) + return; + + if (m_SizeObject != null) + m_SizeObject.SetActive(colorInterface.TerrainHasSize); + + if (!colorInterface.TerrainHasSize) + return; + + int min = colorInterface.TerrainSizeMin; + int max = colorInterface.TerrainSizeMax; + + m_SizeSlider.minValue = min; + m_SizeSlider.maxValue = max; + + if (m_SizeSliderLabelOne != null) + m_SizeSliderLabelOne.OnTextUpdate.Invoke(string.Format("|\n{0}", min)); + + if (m_SizeSliderLabelTwo != null) + m_SizeSliderLabelTwo.OnTextUpdate.Invoke(string.Format("|\n{0}", max)); + + int size = colorInterface.TerrainSize; + + if (size < min) + size = min; + else if (size > max) + size = max; + + m_SizeSlider.value = size; + } + + public void OnSizeChange(float value) + { + if (m_SizeText != null) + m_SizeText.OnTextUpdate.Invoke(string.Format("Size: {0}", (int)value)); + + if (!loaded || colorInterface == null) + return; + + colorInterface.TerrainSize = (int)value; + } + + public void ReverseToggle(bool isOn) + { + if (!loaded || colorInterface == null) + return; + + colorInterface.TerrainReverse = isOn; + + SetPalettePreviews(); + } + + public void DiscreteToggle(bool isOn) + { + if (!loaded || colorInterface == null) + return; + + colorInterface.TerrainDiscrete = isOn; + + SetPalettePreviews(); + } + + public void Apply() + { + if (colorInterface == null) + return; + + if (settingsInterface != null) + settingsInterface.LockInput = false; + + colorInterface.TerrainApply(); + } + + public void Default() + { + if (colorInterface == null) + return; + + if (settingsInterface != null) + settingsInterface.LockInput = false; + + colorInterface.TerrainDefault(); + + loaded = false; + + ClearPalettes(); + + SetUI(); + } + + public void SaveToConfig() + { + if (SCAN_Settings.Instance == null) + return; + + if (SCAN_Settings.Instance.WarningPopup != null) + { + SCAN_Settings.Instance.WarningPopup.FadeOut(true); + SCAN_Settings.Instance.WarningPopup = null; + } + + if (SCAN_Settings.Instance.PopupPrefab == null) + return; + + SCAN_Settings.Instance.WarningPopup = Instantiate(SCAN_Settings.Instance.PopupPrefab).GetComponent(); + + if (SCAN_Settings.Instance.WarningPopup == null) + return; + + SCAN_Settings.Instance.WarningPopup.transform.SetParent(transform, false); + + SCAN_Settings.Instance.WarningPopup.Setup(settingsInterface.SaveToConfig); + + SCAN_Settings.Instance.WarningPopup.OnSelectUpdate.AddListener(ConfirmSaveToConfig); + } + + private void ConfirmSaveToConfig() + { + if (colorInterface == null) + return; + + if (settingsInterface != null) + settingsInterface.LockInput = false; + + colorInterface.TerrainSaveToConfig(); + } + } +} diff --git a/SCANsat.Unity/Unity/SCAN_ColorBiome.cs b/SCANsat.Unity/Unity/SCAN_ColorBiome.cs new file mode 100644 index 000000000..820d9d4d1 --- /dev/null +++ b/SCANsat.Unity/Unity/SCAN_ColorBiome.cs @@ -0,0 +1,179 @@ +using System; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; +using UnityEngine.Events; +using UnityEngine.EventSystems; +using SCANsat.Unity.Interfaces; +using SCANsat.Unity.HSVPicker.UI; + +namespace SCANsat.Unity.Unity +{ + public class SCAN_ColorBiome : SettingsPage + { + [SerializeField] + private SCAN_ColorPicker m_ColorPicker = null; + [SerializeField] + private Toggle m_BigMapColor = null; + [SerializeField] + private Toggle m_BigMapBorder = null; + [SerializeField] + private Toggle m_SmallMapColor = null; + [SerializeField] + private Toggle m_SmallMapBorder = null; + [SerializeField] + private Slider m_TransparencySlider = null; + [SerializeField] + private TextHandler m_TransparencyText = null; + [SerializeField] + private InputField m_TransInputField = null; + + private bool loaded; + + private ISCAN_Color colorInterface; + private ISCAN_Settings settingsInterface; + + private void Awake() + { + if (m_TransInputField != null) + m_TransInputField.onValueChanged.AddListener(new UnityAction(OnTransparencyInputChange)); + } + + public void SetBiome(ISCAN_Color color, ISCAN_Settings settings) + { + if (color == null) + return; + + colorInterface = color; + settingsInterface = settings; + + color.Refresh(); + + if (m_BigMapColor != null) + m_BigMapColor.isOn = color.BiomeBigMapStockColor; + + if (m_BigMapBorder != null) + m_BigMapBorder.isOn = color.BiomeBigMapWhiteBoder; + + if (m_SmallMapColor != null) + m_SmallMapColor.isOn = color.BiomeSmallMapStockColor; + + if (m_SmallMapBorder != null) + m_SmallMapBorder.isOn = color.BiomeSmallMapWhiteBorder; + + if (m_TransparencySlider != null) + m_TransparencySlider.value = color.BiomeTransparency; + + if (m_ColorPicker != null) + m_ColorPicker.Setup(color.BiomeColorOne, color.BiomeColorTwo, true); + + loaded = true; + } + + public void OnInputClick(BaseEventData eventData) + { + if (!(eventData is PointerEventData) || settingsInterface == null) + return; + + if (((PointerEventData)eventData).button != PointerEventData.InputButton.Left) + return; + + settingsInterface.LockInput = true; + } + + public void BigMapColor(bool isOn) + { + if (!loaded || colorInterface == null) + return; + + colorInterface.BiomeBigMapStockColor = isOn; + } + + public void BigMapBorder(bool isOn) + { + if (!loaded || colorInterface == null) + return; + + colorInterface.BiomeBigMapWhiteBoder = isOn; + } + + public void SmallMapColor(bool isOn) + { + if (!loaded || colorInterface == null) + return; + + colorInterface.BiomeSmallMapStockColor = isOn; + } + + public void SmallMapBorder(bool isOn) + { + if (!loaded || colorInterface == null) + return; + + colorInterface.BiomeSmallMapWhiteBorder = isOn; + } + + public void Transparency(float value) + { + if (m_TransparencyText != null) + m_TransparencyText.OnTextUpdate.Invoke(string.Format("Terrain Transparency: {0:N0}%", value)); + + if (!loaded || colorInterface == null) + return; + + colorInterface.BiomeTransparency = value; + } + + public void OnTransparencyInputChange(string input) + { + if (m_TransparencySlider == null) + return; + + float tran = SCAN_ColorControl.ParseInput(input, m_TransparencySlider.value, m_TransparencySlider.minValue, m_TransparencySlider.maxValue, 0); + + if (tran != m_TransparencySlider.value) + m_TransparencySlider.value = tran; + } + + public void Apply() + { + if (colorInterface == null || m_ColorPicker == null) + return; + + colorInterface.BiomeApply(m_ColorPicker.GetColorOne, m_ColorPicker.GetColorTwo); + + if (m_ColorPicker != null) + m_ColorPicker.Setup(m_ColorPicker.GetColorOne, m_ColorPicker.GetColorTwo, false); + } + + public void Default() + { + if (colorInterface == null) + return; + + colorInterface.BiomeDefault(); + + if (m_ColorPicker != null) + m_ColorPicker.Setup(colorInterface.BiomeColorOne, colorInterface.BiomeColorTwo, false); + + loaded = false; + + if (m_BigMapColor != null) + m_BigMapColor.isOn = colorInterface.BiomeBigMapStockColor; + + if (m_BigMapBorder != null) + m_BigMapBorder.isOn = colorInterface.BiomeBigMapWhiteBoder; + + if (m_SmallMapColor != null) + m_SmallMapColor.isOn = colorInterface.BiomeSmallMapStockColor; + + if (m_SmallMapBorder != null) + m_SmallMapBorder.isOn = colorInterface.BiomeSmallMapWhiteBorder; + + if (m_TransparencySlider != null) + m_TransparencySlider.value = colorInterface.BiomeTransparency; + + loaded = true; + } + } +} diff --git a/SCANsat.Unity/Unity/SCAN_ColorControl.cs b/SCANsat.Unity/Unity/SCAN_ColorControl.cs new file mode 100644 index 000000000..8af84f266 --- /dev/null +++ b/SCANsat.Unity/Unity/SCAN_ColorControl.cs @@ -0,0 +1,195 @@ +using System; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; +using UnityEngine.EventSystems; +using SCANsat.Unity.Interfaces; + +namespace SCANsat.Unity.Unity +{ + public class SCAN_ColorControl : SettingsPage + { + [SerializeField] + private GameObject m_AltimetryPrefab = null; + [SerializeField] + private GameObject m_SlopePrefab = null; + [SerializeField] + private GameObject m_BiomePrefab = null; + [SerializeField] + private GameObject m_ResourcePrefab = null; + [SerializeField] + private Transform m_ContentTransform = null; + + private ISCAN_Settings settingsInterface; + private ISCAN_Color colorInterface; + + private SettingsPage currentPage; + + public void setup(ISCAN_Settings settings, ISCAN_Color color) + { + if (settings == null || color == null) + return; + + settingsInterface = settings; + colorInterface = color; + + AltimetrySettings(true); + } + + public override void OnPointerDown(PointerEventData eventData) + { + if (currentPage != null) + currentPage.OnPointerDown(eventData); + } + + public void AltimetrySettings(bool isOn) + { + if (!isOn) + return; + + if (currentPage != null) + { + currentPage.gameObject.SetActive(false); + DestroyImmediate(currentPage.gameObject); + } + + if (m_ContentTransform == null || m_AltimetryPrefab == null || settingsInterface == null) + return; + + if (settingsInterface.LockInput) + settingsInterface.LockInput = false; + + currentPage = Instantiate(m_AltimetryPrefab).GetComponent(); + + if (currentPage == null) + return; + + currentPage.transform.SetParent(m_ContentTransform, false); + + ((SCAN_ColorAltimetry)currentPage).SetTerrain(colorInterface, settingsInterface); + + if (SCAN_Settings.Instance != null) + SCAN_Settings.Instance.ProcessTooltips(); + + if (SCAN_Settings.Instance != null) + SCAN_Settings.Instance.ClearWarningsAndDropDown(); + } + + public void SlopeSettings(bool isOn) + { + if (!isOn) + return; + + if (currentPage != null) + { + currentPage.gameObject.SetActive(false); + DestroyImmediate(currentPage.gameObject); + } + + if (m_ContentTransform == null || m_SlopePrefab == null || settingsInterface == null) + return; + + if (settingsInterface.LockInput) + settingsInterface.LockInput = false; + + currentPage = Instantiate(m_SlopePrefab).GetComponent(); + + if (currentPage == null) + return; + + currentPage.transform.SetParent(m_ContentTransform, false); + + ((SCAN_ColorSlope)currentPage).SetSlope(colorInterface, settingsInterface); + + if (SCAN_Settings.Instance != null) + SCAN_Settings.Instance.ProcessTooltips(); + + if (SCAN_Settings.Instance != null) + SCAN_Settings.Instance.ClearWarningsAndDropDown(); + } + + public void BiomeSettings(bool isOn) + { + if (!isOn) + return; + + if (currentPage != null) + { + currentPage.gameObject.SetActive(false); + DestroyImmediate(currentPage.gameObject); + } + + if (m_ContentTransform == null || m_BiomePrefab == null || settingsInterface == null) + return; + + if (settingsInterface.LockInput) + settingsInterface.LockInput = false; + + currentPage = Instantiate(m_BiomePrefab).GetComponent(); + + if (currentPage == null) + return; + + currentPage.transform.SetParent(m_ContentTransform, false); + + ((SCAN_ColorBiome)currentPage).SetBiome(colorInterface, settingsInterface); + + if (SCAN_Settings.Instance != null) + SCAN_Settings.Instance.ProcessTooltips(); + + if (SCAN_Settings.Instance != null) + SCAN_Settings.Instance.ClearWarningsAndDropDown(); + } + + public void ResourceSettings(bool isOn) + { + if (!isOn) + return; + + if (currentPage != null) + { + currentPage.gameObject.SetActive(false); + DestroyImmediate(currentPage.gameObject); + } + + if (m_ContentTransform == null || m_ResourcePrefab == null || settingsInterface == null) + return; + + if (settingsInterface.LockInput) + settingsInterface.LockInput = false; + + currentPage = Instantiate(m_ResourcePrefab).GetComponent(); + + if (currentPage == null) + return; + + currentPage.transform.SetParent(m_ContentTransform, false); + + ((SCAN_ColorResource)currentPage).SetResource(colorInterface, settingsInterface); + + if (SCAN_Settings.Instance != null) + SCAN_Settings.Instance.ProcessTooltips(); + + if (SCAN_Settings.Instance != null) + SCAN_Settings.Instance.ClearWarningsAndDropDown(); + } + + public static float ParseInput(string input, float original, float min, float max, int digits) + { + float f = original; + + if (!float.TryParse(input, out f)) + return f; + + if (f < min) + return original; + else if (f > max) + return original; + + f = (float)Math.Round(f, digits); + + return f; + } + + } +} diff --git a/SCANsat.Unity/Unity/SCAN_ColorResource.cs b/SCANsat.Unity/Unity/SCAN_ColorResource.cs new file mode 100644 index 000000000..276a5188f --- /dev/null +++ b/SCANsat.Unity/Unity/SCAN_ColorResource.cs @@ -0,0 +1,455 @@ +using System; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; +using UnityEngine.Events; +using UnityEngine.EventSystems; +using SCANsat.Unity.Interfaces; +using SCANsat.Unity.HSVPicker.UI; + +namespace SCANsat.Unity.Unity +{ + public class SCAN_ColorResource : SettingsPage + { + [SerializeField] + private SCAN_ColorPicker m_ColorPicker = null; + [SerializeField] + private Transform m_PlanetSelection = null; + [SerializeField] + private Transform m_ResourceSelection = null; + [SerializeField] + private ToggleGroup m_DropDownToggles = null; + [SerializeField] + private TextHandler m_PlanetName = null; + [SerializeField] + private TextHandler m_ResourceName = null; + [SerializeField] + private Slider m_MinSlider = null; + [SerializeField] + private Slider m_MaxSlider = null; + [SerializeField] + private Slider m_TransSlider = null; + [SerializeField] + private TextHandler m_MinSliderLabelTwo = null; + [SerializeField] + private TextHandler m_MaxSliderLabelOne = null; + [SerializeField] + private TextHandler m_MinText = null; + [SerializeField] + private TextHandler m_MaxText = null; + [SerializeField] + private TextHandler m_TransText = null; + [SerializeField] + private InputField m_MinInputField = null; + [SerializeField] + private InputField m_MaxInputField = null; + [SerializeField] + private InputField m_TransInputField = null; + + private ISCAN_Color colorInterface; + private ISCAN_Settings settingsInterface; + + private void Awake() + { + if (m_MinInputField != null) + m_MinInputField.onValueChanged.AddListener(new UnityAction(OnMinInputChange)); + + if (m_MaxInputField != null) + m_MaxInputField.onValueChanged.AddListener(new UnityAction(OnMaxInputChange)); + + if (m_TransInputField != null) + m_TransInputField.onValueChanged.AddListener(new UnityAction(OnTransparencyInputChange)); + } + + private void Update() + { + if (settingsInterface == null) + return; + + if (settingsInterface.LockInput) + { + if (m_MinInputField != null && !m_MinInputField.isFocused + && m_MaxInputField != null && !m_MaxInputField.isFocused + && m_TransInputField != null && !m_TransInputField.isFocused) + settingsInterface.LockInput = false; + } + } + + public void SetResource(ISCAN_Color color, ISCAN_Settings settings) + { + if (color == null || settings == null) + return; + + colorInterface = color; + settingsInterface = settings; + + color.Refresh(); + + SetUI(); + } + + private void SetUI(bool color = true) + { + if (colorInterface == null) + return; + + SetMinSlider(); + + SetMaxSlider(); + + if (m_MinSlider != null) + m_MinSlider.value = colorInterface.ResourceMin; + + if (m_MaxSlider != null) + m_MaxSlider.value = colorInterface.ResourceMax; + + if (m_TransSlider != null) + m_TransSlider.value = colorInterface.ResourceTransparency; + + if (m_ColorPicker != null && color) + m_ColorPicker.Setup(colorInterface.ResourceColorOne, colorInterface.ResourceColorTwo, true); + + if (m_PlanetName != null) + m_PlanetName.OnTextUpdate.Invoke(colorInterface.ResourcePlanet); + + if (m_ResourceName != null) + m_ResourceName.OnTextUpdate.Invoke(colorInterface.ResourceCurrent); + } + + public override void OnPointerDown(PointerEventData eventData) + { + if (SCAN_Settings.Instance == null) + return; + + if (SCAN_Settings.Instance.DropDown == null) + return; + + RectTransform r = SCAN_Settings.Instance.DropDown.GetComponent(); + + if (r == null) + return; + + if (RectTransformUtility.RectangleContainsScreenPoint(r, eventData.position, eventData.pressEventCamera)) + return; + + SCAN_Settings.Instance.DropDown.FadeOut(); + SCAN_Settings.Instance.DropDown = null; + + if (m_DropDownToggles != null) + m_DropDownToggles.SetAllTogglesOff(); + } + + public void PlanetDropDown(bool isOn) + { + if (SCAN_Settings.Instance.DropDown != null) + { + SCAN_Settings.Instance.DropDown.FadeOut(true); + SCAN_Settings.Instance.DropDown = null; + } + + if (!isOn) + return; + + if (m_PlanetSelection == null || SCAN_Settings.Instance.DropDownPrefab == null || colorInterface == null) + return; + + SCAN_Settings.Instance.DropDown = Instantiate(SCAN_Settings.Instance.DropDownPrefab).GetComponent(); + + if (SCAN_Settings.Instance.DropDown == null) + return; + + SCAN_Settings.Instance.DropDown.transform.SetParent(m_PlanetSelection, false); + + SCAN_Settings.Instance.DropDown.Setup(colorInterface.CelestialBodies, colorInterface.ResourcePlanet); + + SCAN_Settings.Instance.DropDown.OnSelectUpdate.AddListener(new UnityEngine.Events.UnityAction(Planet)); + } + + public void Planet(string planet) + { + if (m_PlanetName != null) + m_PlanetName.OnTextUpdate.Invoke(planet); + + SCAN_Settings.Instance.DropDown.FadeOut(true); + SCAN_Settings.Instance.DropDown = null; + + if (m_DropDownToggles != null) + m_DropDownToggles.SetAllTogglesOff(); + + if (colorInterface == null) + return; + + colorInterface.ResourcePlanet = planet; + + SetUI(false); + } + + public void ResourceDropDown(bool isOn) + { + if (SCAN_Settings.Instance.DropDown != null) + { + SCAN_Settings.Instance.DropDown.FadeOut(true); + SCAN_Settings.Instance.DropDown = null; + } + + if (!isOn) + return; + + if (m_ResourceSelection == null || SCAN_Settings.Instance.DropDownPrefab == null || colorInterface == null) + return; + + SCAN_Settings.Instance.DropDown = Instantiate(SCAN_Settings.Instance.DropDownPrefab).GetComponent(); + + if (SCAN_Settings.Instance.DropDown == null) + return; + + SCAN_Settings.Instance.DropDown.transform.SetParent(m_ResourceSelection, false); + + SCAN_Settings.Instance.DropDown.Setup(colorInterface.Resources, colorInterface.ResourceCurrent); + + SCAN_Settings.Instance.DropDown.OnSelectUpdate.AddListener(new UnityEngine.Events.UnityAction(Resource)); + } + + public void Resource(string resource) + { + if (m_ResourceName != null) + m_ResourceName.OnTextUpdate.Invoke(resource); + + SCAN_Settings.Instance.DropDown.FadeOut(true); + SCAN_Settings.Instance.DropDown = null; + + if (m_DropDownToggles != null) + m_DropDownToggles.SetAllTogglesOff(); + + if (colorInterface == null) + return; + + colorInterface.ResourceCurrent = resource; + + SetUI(); + } + + public void OnInputClick(BaseEventData eventData) + { + if (!(eventData is PointerEventData) || settingsInterface == null) + return; + + if (((PointerEventData)eventData).button != PointerEventData.InputButton.Left) + return; + + settingsInterface.LockInput = true; + } + + public void OnMinChange(float value) + { + if (colorInterface == null) + return; + + float max = colorInterface.ResourceMax - 1; + + if (value > max) + value = max; + else if (value < 0) + value = 0; + + colorInterface.ResourceMin = value; + + SetMaxSlider(); + + if (m_MinText != null) + m_MinText.OnTextUpdate.Invoke(string.Format("Min: {0:N2}%", value)); + } + + public void OnMinInputChange(string input) + { + if (m_MinSlider == null) + return; + + float min = SCAN_ColorControl.ParseInput(input, m_MinSlider.value, m_MinSlider.minValue, m_MinSlider.maxValue, 2); + + if (min != m_MinSlider.value) + m_MinSlider.value = min; + } + + public void OnMaxChange(float value) + { + if (colorInterface == null) + return; + + float min = colorInterface.ResourceMin + 1; + + if (value < min) + value = min; + else if (value > 100) + value = 100; + + colorInterface.ResourceMax = value; + + SetMinSlider(); + + if (m_MaxText != null) + m_MaxText.OnTextUpdate.Invoke(string.Format("Max: {0:N2}%", value)); + } + + public void OnMaxInputChange(string input) + { + if (m_MaxSlider == null) + return; + + float max = SCAN_ColorControl.ParseInput(input, m_MaxSlider.value, m_MaxSlider.minValue, m_MaxSlider.maxValue, 2); + + if (max != m_MaxSlider.value) + m_MaxSlider.value = max; + } + + private void SetMinSlider() + { + if (colorInterface == null || m_MinSlider == null) + return; + + float max = colorInterface.ResourceMax - 1; + + m_MinSlider.minValue = 0; + m_MinSlider.maxValue = max; + + if (m_MinSliderLabelTwo != null) + m_MinSliderLabelTwo.OnTextUpdate.Invoke(string.Format("|\n{0:N1}%", max)); + } + + private void SetMaxSlider() + { + if (colorInterface == null || m_MaxSlider == null) + return; + + float min = colorInterface.ResourceMin + 1; + + m_MaxSlider.minValue = min; + m_MaxSlider.maxValue = 100; + + if (m_MaxSliderLabelOne != null) + m_MaxSliderLabelOne.OnTextUpdate.Invoke(string.Format("|\n{0:N1}%", min)); + } + + public void OnTransparencyChange(float value) + { + if (m_TransText != null) + m_TransText.OnTextUpdate.Invoke(string.Format("Trans: {0:N0}%", value)); + + if (colorInterface == null) + return; + + colorInterface.ResourceTransparency = value; + } + + public void OnTransparencyInputChange(string input) + { + if (m_TransSlider == null) + return; + + float tran = SCAN_ColorControl.ParseInput(input, m_TransSlider.value, m_TransSlider.minValue, m_TransSlider.maxValue, 0); + + if (tran != m_TransSlider.value) + m_TransSlider.value = tran; + } + + public void Apply() + { + if (colorInterface == null || m_ColorPicker == null) + return; + + if (settingsInterface != null) + settingsInterface.LockInput = false; + + colorInterface.ResourceApply(m_ColorPicker.GetColorOne, m_ColorPicker.GetColorTwo); + + if (m_ColorPicker != null) + m_ColorPicker.Setup(m_ColorPicker.GetColorOne, m_ColorPicker.GetColorTwo, false); + } + + public void ApplyToAll() + { + if (colorInterface == null || m_ColorPicker == null) + return; + + if (settingsInterface != null) + settingsInterface.LockInput = false; + + colorInterface.ResourceApplyToAll(m_ColorPicker.GetColorOne, m_ColorPicker.GetColorTwo); + + if (m_ColorPicker != null) + m_ColorPicker.Setup(m_ColorPicker.GetColorOne, m_ColorPicker.GetColorTwo, false); + } + + public void Default() + { + if (colorInterface == null) + return; + + if (settingsInterface != null) + settingsInterface.LockInput = false; + + colorInterface.ResourceDefault(); + + if (m_ColorPicker != null) + m_ColorPicker.Setup(colorInterface.ResourceColorOne, colorInterface.ResourceColorTwo, false); + + SetUI(); + } + + public void DefaultToAll() + { + if (colorInterface == null) + return; + + if (settingsInterface != null) + settingsInterface.LockInput = false; + + colorInterface.ResourceDefaultToAll(); + + if (m_ColorPicker != null) + m_ColorPicker.Setup(colorInterface.ResourceColorOne, colorInterface.ResourceColorTwo, false); + + SetUI(); + } + + public void SaveToConfig() + { + if (SCAN_Settings.Instance == null) + return; + + if (SCAN_Settings.Instance.WarningPopup != null) + { + SCAN_Settings.Instance.WarningPopup.FadeOut(true); + SCAN_Settings.Instance.WarningPopup = null; + } + + if (SCAN_Settings.Instance.PopupPrefab == null) + return; + + SCAN_Settings.Instance.WarningPopup = Instantiate(SCAN_Settings.Instance.PopupPrefab).GetComponent(); + + if (SCAN_Settings.Instance.WarningPopup == null) + return; + + SCAN_Settings.Instance.WarningPopup.transform.SetParent(transform, false); + + SCAN_Settings.Instance.WarningPopup.Setup(settingsInterface.SaveToConfig); + + SCAN_Settings.Instance.WarningPopup.OnSelectUpdate.AddListener(ConfirmSaveToConfig); + } + + private void ConfirmSaveToConfig() + { + if (colorInterface == null || m_ColorPicker == null) + return; + + if (settingsInterface != null) + settingsInterface.LockInput = false; + + colorInterface.ResourceSaveToConfig(m_ColorPicker.GetColorOne, m_ColorPicker.GetColorTwo); + + if (m_ColorPicker != null) + m_ColorPicker.Setup(m_ColorPicker.GetColorOne, m_ColorPicker.GetColorTwo, false); + } + } +} diff --git a/SCANsat.Unity/Unity/SCAN_ColorSlope.cs b/SCANsat.Unity/Unity/SCAN_ColorSlope.cs new file mode 100644 index 000000000..f1d4cfb5e --- /dev/null +++ b/SCANsat.Unity/Unity/SCAN_ColorSlope.cs @@ -0,0 +1,119 @@ +using System; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; +using UnityEngine.Events; +using UnityEngine.EventSystems; +using SCANsat.Unity.Interfaces; +using SCANsat.Unity.HSVPicker.UI; + +namespace SCANsat.Unity.Unity +{ + public class SCAN_ColorSlope : SettingsPage + { + [SerializeField] + private SCAN_ColorPicker m_ColorPickerOne = null; + [SerializeField] + private SCAN_ColorPicker m_ColorPickerTwo = null; + [SerializeField] + private Slider m_CutoffSlider = null; + [SerializeField] + private TextHandler m_CutoffText = null; + [SerializeField] + private InputField m_CutoffInputField = null; + + private bool loaded; + + private ISCAN_Color colorInterface; + private ISCAN_Settings settingsInterface; + + private void Awake() + { + if (m_CutoffInputField != null) + m_CutoffInputField.onValueChanged.AddListener(new UnityAction(OnCutoffInputChange)); + } + + public void SetSlope(ISCAN_Color color, ISCAN_Settings settings) + { + if (color == null) + return; + + colorInterface = color; + settingsInterface = settings; + + color.Refresh(); + + if (m_CutoffSlider != null) + m_CutoffSlider.value = color.SlopeCutoff; + + if (m_ColorPickerOne != null) + m_ColorPickerOne.Setup(color.SlopeColorOneLo, color.SlopeColorOneHi, true); + + if (m_ColorPickerTwo != null) + m_ColorPickerTwo.Setup(color.SlopeColorTwoLo, color.SlopeColorTwoHi, true); + + loaded = true; + } + + public void OnInputClick(BaseEventData eventData) + { + if (!(eventData is PointerEventData) || settingsInterface == null) + return; + + if (((PointerEventData)eventData).button != PointerEventData.InputButton.Left) + return; + + settingsInterface.LockInput = true; + } + + public void Cutoff(float value) + { + if (m_CutoffText != null) + m_CutoffText.OnTextUpdate.Invoke(string.Format("Slope Cutoff: {0:N1}", value)); + + if (!loaded || colorInterface == null) + return; + + colorInterface.SlopeCutoff = value; + } + + public void OnCutoffInputChange(string input) + { + if (m_CutoffSlider == null) + return; + + float cutoff = SCAN_ColorControl.ParseInput(input, m_CutoffSlider.value, m_CutoffSlider.minValue, m_CutoffSlider.maxValue, 1); + + if (cutoff != m_CutoffSlider.value) + m_CutoffSlider.value = cutoff; + } + + public void Apply() + { + if (colorInterface == null || m_ColorPickerOne == null || m_ColorPickerTwo == null) + return; + + colorInterface.SlopeApply(m_ColorPickerOne.GetColorOne, m_ColorPickerOne.GetColorTwo, m_ColorPickerTwo.GetColorOne, m_ColorPickerTwo.GetColorTwo); + + if (m_ColorPickerOne != null) + m_ColorPickerOne.Setup(m_ColorPickerOne.GetColorOne, m_ColorPickerOne.GetColorTwo, false); + + if (m_ColorPickerTwo != null) + m_ColorPickerTwo.Setup(m_ColorPickerTwo.GetColorOne, m_ColorPickerTwo.GetColorTwo, false); + } + + public void Default() + { + if (colorInterface == null) + return; + + colorInterface.SlopeDefault(); + + if (m_ColorPickerOne != null) + m_ColorPickerOne.Setup(colorInterface.SlopeColorOneLo, colorInterface.SlopeColorOneHi, false); + + if (m_ColorPickerTwo != null) + m_ColorPickerTwo.Setup(colorInterface.SlopeColorTwoLo, colorInterface.SlopeColorTwoHi, false); + } + } +} diff --git a/SCANsat.Unity/Unity/SCAN_PaletteButton.cs b/SCANsat.Unity/Unity/SCAN_PaletteButton.cs new file mode 100644 index 000000000..ec085da87 --- /dev/null +++ b/SCANsat.Unity/Unity/SCAN_PaletteButton.cs @@ -0,0 +1,33 @@ +using System; +using UnityEngine; +using UnityEngine.UI; + +namespace SCANsat.Unity.Unity +{ + public class SCAN_PaletteButton : MonoBehaviour + { + [SerializeField] + private RawImage m_Palette = null; + + private string paletteName; + private SCAN_ColorAltimetry color; + + public void setup(Texture2D tex, string palette, SCAN_ColorAltimetry c) + { + if (m_Palette == null || c == null) + return; + + m_Palette.texture = tex; + paletteName = palette; + color = c; + } + + public void Select() + { + if (color == null) + return; + + color.SetPalette(paletteName); + } + } +} diff --git a/SCANsat/SCAN_Unity/SCAN_UI_Color.cs b/SCANsat/SCAN_Unity/SCAN_UI_Color.cs new file mode 100644 index 000000000..fceae3ea0 --- /dev/null +++ b/SCANsat/SCAN_Unity/SCAN_UI_Color.cs @@ -0,0 +1,670 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using UnityEngine; +using SCANsat.Unity.Interfaces; +using SCANsat.Unity.Unity; +using SCANsat.SCAN_Data; +using SCANsat.SCAN_Map; +using SCANsat.SCAN_Platform.Palettes; +using palette = SCANsat.SCAN_UI.UI_Framework.SCANpalette; + +namespace SCANsat.SCAN_Unity +{ + public class SCAN_UI_Color : ISCAN_Color + { + private string _resourceCurrent; + private string _resourcePlanet; + private string _terrainPlanet; + private string _terrainPalette; + private string _terrainPaletteStyle; + + private bool _biomeBigMapStockColor; + private bool _biomeBigMapWhiteBorder; + private bool _biomeSmallMapStockColor; + private bool _biomeSmallMapWhiteBorder; + private bool _terrainClampOn; + private bool _terrainReverse; + private bool _terrainDiscrete; + + private float _biomeTransparency; + private float _slopeCutoff; + private float _resourceMin; + private float _resourceMax; + private float _resourceTransparency; + private float _terrainCurrentMin; + private float _terrainCurrentMax; + private float _terrainClamp; + + private int _terrainSize; + + private SCANterrainConfig currentTerrain; + private Palette currentPalette; + + private SCANresourceGlobal currentResource; + private List loadedResources; + + public SCAN_UI_Color() + { + if (HighLogic.LoadedScene == GameScenes.SPACECENTER || HighLogic.LoadedScene == GameScenes.TRACKSTATION) + _resourcePlanet = Planetarium.fetch.Home.bodyName; + else if (HighLogic.LoadedSceneIsFlight) + _resourcePlanet = FlightGlobals.currentMainBody.bodyName; + + _terrainPlanet = _resourcePlanet; + } + + public void Refresh() + { + _biomeBigMapStockColor = SCAN_Settings_Config.Instance.BigMapStockBiomes; + _biomeBigMapWhiteBorder = SCAN_Settings_Config.Instance.BigMapBiomeBorder; + _biomeSmallMapStockColor = SCAN_Settings_Config.Instance.SmallMapStockBiomes; + _biomeSmallMapWhiteBorder = SCAN_Settings_Config.Instance.SmallMapBiomeBorder; + _biomeTransparency = SCAN_Settings_Config.Instance.BiomeTransparency * 100; + + _slopeCutoff = SCAN_Settings_Config.Instance.SlopeCutoff; + + loadedResources = SCANcontroller.setLoadedResourceList(); + currentResource = new SCANresourceGlobal(loadedResources[0]); + + if (currentResource != null) + { + currentResource.CurrentBodyConfig(_resourcePlanet); + _resourceCurrent = currentResource.Name; + _resourceMin = currentResource.CurrentBody.MinValue; + _resourceMax = currentResource.CurrentBody.MaxValue; + _resourceTransparency = currentResource.Transparency; + } + + currentTerrain = SCANcontroller.getTerrainNode(_terrainPlanet); + + if (currentTerrain != null) + { + currentPalette = currentTerrain.ColorPal; + + palette.CurrentPalettes = palette.setCurrentPalettesType(currentPalette.kind, currentPalette.size); + + _terrainPalette = currentTerrain.ColorPal.name; + _terrainPaletteStyle = currentTerrain.ColorPal.kind.ToString(); + + _terrainCurrentMin = currentTerrain.MinTerrain; + _terrainCurrentMax = currentTerrain.MaxTerrain; + _terrainClampOn = currentTerrain.ClampTerrain != null; + _terrainClamp = currentTerrain.ClampTerrain == null ? 0 : (float)currentTerrain.ClampTerrain; + _terrainDiscrete = currentTerrain.PalDis; + _terrainReverse = currentTerrain.PalRev; + _terrainSize = currentTerrain.PalSize; + } + } + + public string ResourcePlanet + { + get { return _resourcePlanet; } + set + { + _resourcePlanet = value; + + if (currentResource != null) + { + currentResource.CurrentBodyConfig(value); + + _resourceMin = currentResource.CurrentBody.MinValue; + _resourceMax = currentResource.CurrentBody.MaxValue; + } + } + } + + public string ResourceCurrent + { + get { return _resourceCurrent; } + set + { + _resourceCurrent = value; + + if (currentResource.Name != value) + { + for (int i = loadedResources.Count - 1; i >= 0; i--) + { + SCANresourceGlobal res = loadedResources[i]; + + if (res.Name != value) + continue; + + currentResource = res; + break; + } + + if (currentResource == null) + currentResource = SCANcontroller.GetFirstResource; + + if (currentResource != null) + { + currentResource.CurrentBodyConfig(_resourcePlanet); + + _resourceCurrent = currentResource.Name; + _resourceMin = currentResource.CurrentBody.MinValue; + _resourceMax = currentResource.CurrentBody.MaxValue; + _resourceTransparency = currentResource.Transparency; + } + } + } + } + + public string TerrainPlanet + { + get { return _terrainPlanet; } + set + { + _terrainPlanet = value; + + currentTerrain = SCANcontroller.getTerrainNode(value); + + if (currentTerrain != null) + { + currentPalette = currentTerrain.ColorPal; + + palette.CurrentPalettes = palette.setCurrentPalettesType(currentPalette.kind, currentPalette.size); + + _terrainPalette = currentTerrain.ColorPal.name; + _terrainPaletteStyle = currentTerrain.ColorPal.kind.ToString(); + + _terrainCurrentMin = currentTerrain.MinTerrain; + _terrainCurrentMax = currentTerrain.MaxTerrain; + _terrainClampOn = currentTerrain.ClampTerrain != null; + _terrainClamp = currentTerrain.ClampTerrain == null ? 0 : (float)currentTerrain.ClampTerrain; + _terrainDiscrete = currentTerrain.PalDis; + _terrainReverse = currentTerrain.PalRev; + _terrainSize = currentTerrain.PalSize; + } + } + } + + public string TerrainPalette + { + get { return _terrainPalette; } + set + { + _terrainPalette = value; + + for (int i = palette.CurrentPalettes.Length - 1; i >= 0; i--) + { + Palette p = palette.CurrentPalettes.availablePalettes[i]; + + if (p.name != value) + continue; + + currentPalette = p; + break; + } + } + } + + public string TerrainPaletteStyle + { + get { return _terrainPaletteStyle; } + set + { + _terrainPaletteStyle = value; + + Palette.Kind kind = Palette.Kind.Diverging; + + try + { + kind = (Palette.Kind)Enum.Parse(typeof(Palette.Kind), value); + } + catch (Exception e) + { + SCANUtil.SCANlog("Error in palette style type\n{0}", e); + } + + palette.CurrentPalettes = palette.setCurrentPalettesType(kind, _terrainSize); + + currentPalette = palette.CurrentPalettes.availablePalettes[0]; + + _terrainPalette = currentPalette.name; + } + } + + public bool BiomeBigMapStockColor + { + get { return _biomeBigMapStockColor; } + set { _biomeBigMapStockColor = value; } + } + + public bool BiomeBigMapWhiteBoder + { + get { return _biomeBigMapWhiteBorder; } + set { _biomeBigMapWhiteBorder = value; } + } + + public bool BiomeSmallMapStockColor + { + get { return _biomeSmallMapStockColor; } + set { _biomeSmallMapStockColor = value; } + } + + public bool BiomeSmallMapWhiteBorder + { + get { return _biomeSmallMapWhiteBorder; } + set { _biomeSmallMapWhiteBorder = value; } + } + + public bool TerrainClampOn + { + get { return _terrainClampOn; } + set { _terrainClampOn = value; } + } + + public bool TerrainReverse + { + get { return _terrainReverse; } + set { _terrainReverse = value; } + } + + public bool TerrainDiscrete + { + get { return _terrainDiscrete; } + set { _terrainDiscrete = value; } + } + + public bool TerrainHasSize + { + get { return currentPalette.kind != Palette.Kind.Fixed; } + } + + public float BiomeTransparency + { + get { return _biomeTransparency; } + set { _biomeTransparency = value; } + } + + public float SlopeCutoff + { + get { return _slopeCutoff; } + set { _slopeCutoff = value; } + } + + public float ResourceMin + { + get { return _resourceMin; } + set { _resourceMin = value; } + } + + public float ResourceMax + { + get { return _resourceMax; } + set { _resourceMax = value; } + } + + public float ResourceTransparency + { + get { return _resourceTransparency; } + set { _resourceTransparency = value; } + } + + public float TerrainCurrentMin + { + get { return _terrainCurrentMin; } + set { _terrainCurrentMin = value; } + } + + public float TerrainGlobalMin + { + get { return currentTerrain.DefaultMinHeight - SCANconfigLoader.SCANNode.RangeBelowMinHeight; } + } + + public float TerrainCurrentMax + { + get { return _terrainCurrentMax; } + set { _terrainCurrentMax = value; } + } + + public float TerrainGlobalMax + { + get { return currentTerrain.DefaultMaxHeight + SCANconfigLoader.SCANNode.RangeAboveMaxHeight; } + } + + public float TerrainClamp + { + get { return _terrainClamp; } + set { _terrainClamp = value; } + } + + public int TerrainSize + { + get { return _terrainSize; } + set + { + _terrainSize = value; + + + } + } + + public int TerrainSizeMin + { + get { return 3; } + } + + public int TerrainSizeMax + { + get + { + switch(currentTerrain.ColorPal.kind) + { + case Palette.Kind.Diverging: + return 11; + case Palette.Kind.Qualitative: + return 12; + case Palette.Kind.Sequential: + return 9; + } + + return 12; + } + } + + public Color BiomeColorOne + { + get { return SCAN_Settings_Config.Instance.LowBiomeColor; } + } + + public Color BiomeColorTwo + { + get { return SCAN_Settings_Config.Instance.HighBiomeColor; } + } + + public Color SlopeColorOneLo + { + get { return SCAN_Settings_Config.Instance.BottomLowSlopeColor; } + } + + public Color SlopeColorOneHi + { + get { return SCAN_Settings_Config.Instance.BottomHighSlopeColor; } + } + + public Color SlopeColorTwoLo + { + get { return SCAN_Settings_Config.Instance.TopLowSlopeColor; } + } + + public Color SlopeColorTwoHi + { + get { return SCAN_Settings_Config.Instance.TopHighSlopeColor; } + } + + public Color ResourceColorOne + { + get { return currentResource.MinColor; } + } + + public Color ResourceColorTwo + { + get { return currentResource.MaxColor; } + } + + public Texture2D TerrainPaletteOld + { + get { return SCANmapLegend.getStaticLegend(currentTerrain); } + } + + public Texture2D TerrainPaletteNew + { + get + { + Color32[] c = currentPalette.colors; + + if (_terrainReverse) + c = currentPalette.colorsReverse; + + return SCANmapLegend.getStaticLegend(_terrainCurrentMax, _terrainCurrentMin, _terrainCurrentMax - _terrainCurrentMin, _terrainClampOn ? (float?)_terrainClamp : null, _terrainDiscrete, c); + } + } + + public IList> TerrainPalettes + { + get + { + List> values = new List>(); + + for (int i = 0; i < palette.CurrentPalettes.Length; i++) + { + Palette p = palette.CurrentPalettes.availablePalettes[i]; + + values.Add(new KeyValuePair(p.name, palette.CurrentPalettes.paletteSwatch[i])); + } + + return values; + } + } + + public IList Resources + { + get { return new List(loadedResources.Select(r => r.Name)); } + } + + public IList CelestialBodies + { + get { return new List(FlightGlobals.Bodies.Select(d => d.bodyName)); } + } + + public IList PaletteStyleNames + { + get { return new List(Palette.kindNames); } + } + + public void BiomeApply(Color one, Color two) + { + SCAN_Settings_Config.Instance.LowBiomeColor = one; + SCAN_Settings_Config.Instance.HighBiomeColor = two; + SCANcontroller.controller.lowBiomeColor32 = one; + SCANcontroller.controller.highBiomeColor32 = two; + + SCAN_Settings_Config.Instance.BigMapStockBiomes = _biomeBigMapStockColor; + SCAN_Settings_Config.Instance.BigMapBiomeBorder = _biomeBigMapWhiteBorder; + SCAN_Settings_Config.Instance.SmallMapStockBiomes = _biomeSmallMapStockColor; + SCAN_Settings_Config.Instance.SmallMapBiomeBorder = _biomeSmallMapWhiteBorder; + SCAN_Settings_Config.Instance.BiomeTransparency = _biomeTransparency / 100; + + if (SCAN_UI_BigMap.Instance != null && SCAN_UI_BigMap.Instance.IsVisible && SCAN_UI_BigMap.Instance.CurrentMapType == "Biome") + SCAN_UI_BigMap.Instance.RefreshMap(); + + if (SCAN_UI_MainMap.Instance != null && SCAN_UI_MainMap.Instance.IsVisible && SCAN_UI_MainMap.Instance.MapType) + SCAN_UI_MainMap.Instance.resetImages(); + } + + public void BiomeDefault() + { + SCAN_Settings_Config.Instance.LowBiomeColor = palette.xkcd_CamoGreen; + SCANcontroller.controller.lowBiomeColor32 = palette.xkcd_CamoGreen; + SCAN_Settings_Config.Instance.HighBiomeColor = palette.xkcd_Marigold; + SCANcontroller.controller.highBiomeColor32 = palette.xkcd_Marigold; + + SCAN_Settings_Config.Instance.BigMapStockBiomes = true; + SCAN_Settings_Config.Instance.BigMapBiomeBorder = true; + SCAN_Settings_Config.Instance.SmallMapStockBiomes = true; + SCAN_Settings_Config.Instance.SmallMapBiomeBorder = false; + SCAN_Settings_Config.Instance.BiomeTransparency = 0.4f; + + _biomeBigMapStockColor = true; + _biomeBigMapWhiteBorder = true; + _biomeSmallMapStockColor = true; + _biomeSmallMapWhiteBorder = false; + _biomeTransparency = 40; + + if (SCAN_UI_BigMap.Instance != null && SCAN_UI_BigMap.Instance.IsVisible && SCAN_UI_BigMap.Instance.CurrentMapType == "Biome") + SCAN_UI_BigMap.Instance.RefreshMap(); + + if (SCAN_UI_MainMap.Instance != null && SCAN_UI_MainMap.Instance.IsVisible && SCAN_UI_MainMap.Instance.MapType) + SCAN_UI_MainMap.Instance.resetImages(); + } + + public void SlopeApply(Color oneLow, Color oneHigh, Color twoLow, Color twoHigh) + { + SCAN_Settings_Config.Instance.BottomLowSlopeColor = oneLow; + SCAN_Settings_Config.Instance.BottomHighSlopeColor = oneHigh; + SCAN_Settings_Config.Instance.TopLowSlopeColor = twoLow; + SCAN_Settings_Config.Instance.TopHighSlopeColor = twoHigh; + SCANcontroller.controller.lowSlopeColorOne32 = oneLow; + SCANcontroller.controller.highSlopeColorOne32 = oneHigh; + SCANcontroller.controller.lowSlopeColorTwo32 = twoLow; + SCANcontroller.controller.highSlopeColorTwo32 = twoHigh; + + SCAN_Settings_Config.Instance.SlopeCutoff = _slopeCutoff; + + if (SCAN_UI_BigMap.Instance != null && SCAN_UI_BigMap.Instance.IsVisible && SCAN_UI_BigMap.Instance.CurrentMapType == "Slope") + SCAN_UI_BigMap.Instance.RefreshMap(); + } + + public void SlopeDefault() + { + SCAN_Settings_Config.Instance.BottomLowSlopeColor = palette.xkcd_PukeGreen; + SCAN_Settings_Config.Instance.BottomHighSlopeColor = palette.xkcd_Lemon; + SCAN_Settings_Config.Instance.TopLowSlopeColor = palette.xkcd_Lemon; + SCAN_Settings_Config.Instance.TopHighSlopeColor = palette.xkcd_OrangeRed; + SCANcontroller.controller.lowSlopeColorOne32 = palette.xkcd_PukeGreen; + SCANcontroller.controller.highSlopeColorOne32 = palette.xkcd_Lemon; + SCANcontroller.controller.lowSlopeColorTwo32 = palette.xkcd_Lemon; + SCANcontroller.controller.highSlopeColorTwo32 = palette.xkcd_OrangeRed; + + SCAN_Settings_Config.Instance.SlopeCutoff = 1; + + if (SCAN_UI_BigMap.Instance != null && SCAN_UI_BigMap.Instance.IsVisible && SCAN_UI_BigMap.Instance.CurrentMapType == "Slope") + SCAN_UI_BigMap.Instance.RefreshMap(); + } + + public void ResourceApply(Color one, Color two) + { + currentResource.CurrentBody.MinValue = _resourceMin; + currentResource.CurrentBody.MaxValue = _resourceMax; + currentResource.MinColor = one; + currentResource.MaxColor = two; + currentResource.Transparency = _resourceTransparency; + + SCANcontroller.updateSCANresource(currentResource, false); + + if (SCAN_UI_BigMap.Instance != null && SCAN_UI_BigMap.Instance.IsVisible && SCAN_UI_BigMap.Instance.ResourceToggle) + SCAN_UI_BigMap.Instance.RefreshMap(); + } + + public void ResourceApplyToAll(Color one, Color two) + { + currentResource.CurrentBody.MinValue = _resourceMin; + currentResource.CurrentBody.MaxValue = _resourceMax; + currentResource.MinColor = one; + currentResource.MaxColor = two; + currentResource.Transparency = _resourceTransparency; + + SCANcontroller.updateSCANresource(currentResource, true); + + if (SCAN_UI_BigMap.Instance != null && SCAN_UI_BigMap.Instance.IsVisible && SCAN_UI_BigMap.Instance.ResourceToggle) + SCAN_UI_BigMap.Instance.RefreshMap(); + } + + public void ResourceDefault() + { + currentResource.CurrentBody.MinValue = currentResource.CurrentBody.DefaultMinValue; + currentResource.CurrentBody.MaxValue = currentResource.CurrentBody.DefaultMaxValue; + currentResource.MinColor = currentResource.DefaultLowColor; + currentResource.MaxColor = currentResource.DefaultHighColor; + currentResource.Transparency = currentResource.DefaultTrans; + + SCANcontroller.updateSCANresource(currentResource, false); + + if (SCAN_UI_BigMap.Instance != null && SCAN_UI_BigMap.Instance.IsVisible && SCAN_UI_BigMap.Instance.ResourceToggle) + SCAN_UI_BigMap.Instance.RefreshMap(); + } + + public void ResourceDefaultToAll() + { + currentResource.CurrentBody.MinValue = currentResource.CurrentBody.DefaultMinValue; + currentResource.CurrentBody.MaxValue = currentResource.CurrentBody.DefaultMaxValue; + currentResource.MinColor = currentResource.DefaultLowColor; + currentResource.MaxColor = currentResource.DefaultHighColor; + currentResource.Transparency = currentResource.DefaultTrans; + + SCANcontroller.updateSCANresource(currentResource, true); + + if (SCAN_UI_BigMap.Instance != null && SCAN_UI_BigMap.Instance.IsVisible && SCAN_UI_BigMap.Instance.ResourceToggle) + SCAN_UI_BigMap.Instance.RefreshMap(); + } + + public void ResourceSaveToConfig(Color one, Color two) + { + currentResource.CurrentBody.MinValue = _resourceMin; + currentResource.CurrentBody.MaxValue = _resourceMax; + currentResource.MinColor = one; + currentResource.MaxColor = two; + currentResource.Transparency = _resourceTransparency; + + SCANcontroller.updateSCANresource(currentResource, false); + + if (SCAN_UI_BigMap.Instance != null && SCAN_UI_BigMap.Instance.IsVisible && SCAN_UI_BigMap.Instance.ResourceToggle) + SCAN_UI_BigMap.Instance.RefreshMap(); + + SCANconfigLoader.SCANNode.Save(); + } + + public void TerrainApply() + { + currentTerrain.MinTerrain = _terrainCurrentMin; + currentTerrain.MaxTerrain = _terrainCurrentMax; + currentTerrain.ClampTerrain = _terrainClampOn ? (float?)_terrainClamp : null; + currentTerrain.PalDis = _terrainDiscrete; + currentTerrain.PalRev = _terrainReverse; + currentTerrain.PalSize = _terrainSize; + + currentTerrain.ColorPal = currentPalette; + + SCANcontroller.updateTerrainConfig(currentTerrain); + + if (SCAN_UI_BigMap.Instance != null && SCAN_UI_BigMap.Instance.IsVisible && SCAN_UI_BigMap.Instance.CurrentMapType == "Altimetry") + SCAN_UI_BigMap.Instance.RefreshMap(); + + if (SCAN_UI_MainMap.Instance != null && SCAN_UI_MainMap.Instance.IsVisible && !SCAN_UI_MainMap.Instance.MapType) + SCAN_UI_MainMap.Instance.resetImages(); + } + + public void TerrainDefault() + { + currentTerrain.MinTerrain = currentTerrain.DefaultMinHeight; + currentTerrain.MaxTerrain = currentTerrain.DefaultMaxHeight; + currentTerrain.ClampTerrain = currentTerrain.DefaultClampHeight; + currentTerrain.ColorPal = currentTerrain.DefaultPalette; + currentTerrain.PalRev = currentTerrain.DefaultReverse; + currentTerrain.PalDis = currentTerrain.DefaultDiscrete; + currentTerrain.PalSize = currentTerrain.DefaultPaletteSize; + + SCANcontroller.updateTerrainConfig(currentTerrain); + + Refresh(); + + if (SCAN_UI_BigMap.Instance != null && SCAN_UI_BigMap.Instance.IsVisible && SCAN_UI_BigMap.Instance.CurrentMapType == "Altimetry") + SCAN_UI_BigMap.Instance.RefreshMap(); + + if (SCAN_UI_MainMap.Instance != null && SCAN_UI_MainMap.Instance.IsVisible && !SCAN_UI_MainMap.Instance.MapType) + SCAN_UI_MainMap.Instance.resetImages(); + } + + public void TerrainSaveToConfig() + { + currentTerrain.MinTerrain = _terrainCurrentMin; + currentTerrain.MaxTerrain = _terrainCurrentMax; + currentTerrain.ClampTerrain = _terrainClampOn ? (float?)_terrainClamp : null; + currentTerrain.PalDis = _terrainDiscrete; + currentTerrain.PalRev = _terrainReverse; + currentTerrain.PalSize = _terrainSize; + + SCANcontroller.updateTerrainConfig(currentTerrain); + + SCANconfigLoader.SCANNode.Save(); + + if (SCAN_UI_BigMap.Instance != null && SCAN_UI_BigMap.Instance.IsVisible && SCAN_UI_BigMap.Instance.CurrentMapType == "Altimetry") + SCAN_UI_BigMap.Instance.RefreshMap(); + + if (SCAN_UI_MainMap.Instance != null && SCAN_UI_MainMap.Instance.IsVisible && !SCAN_UI_MainMap.Instance.MapType) + SCAN_UI_MainMap.Instance.resetImages(); + } + } +}