InspectableInt.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using BansheeEngine;
  7. namespace BansheeEditor
  8. {
  9. public class InspectableInt : InspectableObjectBase
  10. {
  11. private int oldPropertyValue;
  12. private GUIIntField guiIntField;
  13. private bool isInitialized;
  14. public InspectableInt(string title, InspectableFieldLayout layout, SerializableProperty property)
  15. : base(title, layout, property)
  16. {
  17. }
  18. private void Initialize(int layoutIndex)
  19. {
  20. if (property.Type == SerializableProperty.FieldType.Int)
  21. {
  22. guiIntField = new GUIIntField(new GUIContent(title));
  23. guiIntField.OnChanged += OnFieldValueChanged;
  24. layout.AddElement(layoutIndex, guiIntField);
  25. }
  26. isInitialized = true;
  27. }
  28. protected override bool IsModified()
  29. {
  30. if (!isInitialized)
  31. return true;
  32. int newPropertyValue = property.GetValue<int>();
  33. if (oldPropertyValue != newPropertyValue)
  34. {
  35. oldPropertyValue = newPropertyValue;
  36. return true;
  37. }
  38. return base.IsModified();
  39. }
  40. protected override void Update(int layoutIndex)
  41. {
  42. base.Update(layoutIndex);
  43. if (!isInitialized)
  44. Initialize(layoutIndex);
  45. // TODO - Skip update if it currently has input focus so user can modify the value in peace
  46. if(guiIntField != null)
  47. guiIntField.Value = property.GetValue<int>();
  48. }
  49. private void OnFieldValueChanged(int newValue)
  50. {
  51. property.SetValue<int>(newValue);
  52. }
  53. }
  54. }