//********************************** Banshee Engine (www.banshee3d.com) **************************************************// //**************** Copyright (c) 2016 Marko Pintera (marko.pintera@gmail.com). All rights reserved. **********************// using System.Collections.Generic; using BansheeEngine; namespace BansheeEditor { /** @addtogroup Inspectors * @{ */ /// /// Renders an inspector for the component. /// [CustomInspector(typeof(ReflectionProbe))] internal class ReflectionProbeInspector : Inspector { private GUIEnumField probeTypeField = new GUIEnumField(typeof(ReflectionProbeType), new LocEdString("Probe type")); private GUIVector3Field extentsField = new GUIVector3Field(new LocEdString("Extents")); private GUIFloatField radiusField = new GUIFloatField(new LocEdString("Radius")); private GUITextureField customTextureField = new GUITextureField(new LocEdString("Custom texture")); private GUIButton captureButton = new GUIButton(new LocEdString("Capture")); private InspectableState modifyState; /// protected internal override void Initialize() { if (InspectedObject != null) { ReflectionProbe probe = (ReflectionProbe)InspectedObject; probeTypeField.OnSelectionChanged += x => { probe.Type = (ReflectionProbeType)x; ToggleTypeSpecificFields((ReflectionProbeType) x); }; radiusField.OnChanged += x => { probe.Radius = x; MarkAsModified(); }; radiusField.OnConfirmed += ConfirmModify; radiusField.OnFocusLost += ConfirmModify; extentsField.OnChanged += x => { probe.Extents = x; MarkAsModified(); }; extentsField.OnConfirmed += ConfirmModify; extentsField.OnFocusLost += ConfirmModify; customTextureField.OnChanged += x => { probe.CustomTexture = Resources.Load(x.UUID); MarkAsModified(); ConfirmModify(); }; captureButton.OnClick += () => probe.Capture(); Layout.AddElement(probeTypeField); Layout.AddElement(radiusField); Layout.AddElement(extentsField); Layout.AddElement(customTextureField); Layout.AddSpace(10); Layout.AddElement(captureButton); ToggleTypeSpecificFields(probe.Type); } } /// protected internal override InspectableState Refresh() { ReflectionProbe probe = InspectedObject as ReflectionProbe; if (probe == null) return InspectableState.NotModified; ReflectionProbeType probeType = probe.Type; if (probeTypeField.Value != (ulong)probeType) ToggleTypeSpecificFields(probeType); probeTypeField.Value = (ulong)probeType; radiusField.Value = probe.Radius; extentsField.Value = probe.Extents; customTextureField.ValueRef = probe.CustomTexture; InspectableState oldState = modifyState; if (modifyState.HasFlag(InspectableState.Modified)) modifyState = InspectableState.NotModified; return oldState; } /// /// Enables or disables different GUI elements depending on the probe type. /// /// Probe type to show GUI elements for. private void ToggleTypeSpecificFields(ReflectionProbeType type) { bool isBox = type == ReflectionProbeType.Box; radiusField.Active = !isBox; extentsField.Active = isBox; } /// /// Marks the contents of the inspector as modified. /// protected void MarkAsModified() { modifyState |= InspectableState.ModifyInProgress; } /// /// Confirms any queued modifications. /// protected void ConfirmModify() { if (modifyState.HasFlag(InspectableState.ModifyInProgress)) modifyState |= InspectableState.Modified; } } /** @} */ }