GearText.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System.Collections.Generic;
  2. using FairyGUI.Utils;
  3. namespace FairyGUI
  4. {
  5. /// <summary>
  6. /// Gear is a connection between object and controller.
  7. /// </summary>
  8. public class GearText : GearBase
  9. {
  10. Dictionary<string, string> _storage;
  11. string _default;
  12. public GearText(GObject owner)
  13. : base(owner)
  14. {
  15. }
  16. protected override void Init()
  17. {
  18. _default = _owner.text;
  19. _storage = new Dictionary<string, string>();
  20. }
  21. override protected void AddStatus(string pageId, ByteBuffer buffer)
  22. {
  23. if (pageId == null)
  24. _default = buffer.ReadS();
  25. else
  26. _storage[pageId] = buffer.ReadS();
  27. }
  28. override public void Apply()
  29. {
  30. _owner._gearLocked = true;
  31. string cv;
  32. if (!_storage.TryGetValue(_controller.selectedPageId, out cv))
  33. cv = _default;
  34. _owner.text = cv;
  35. _owner._gearLocked = false;
  36. }
  37. override public void UpdateState()
  38. {
  39. _storage[_controller.selectedPageId] = _owner.text;
  40. }
  41. }
  42. }