Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / ui / mapEditorCreateMark / attribute / OptionAttribute.cs
  1. using System.Collections.Generic;
  2.  
  3. namespace UI.MapEditorCreateMark;
  4.  
  5. public partial class OptionAttribute : AttributeBase
  6. {
  7. private MapEditorCreateMark.OptionBar _optionBar;
  8. private int _index = 0;
  9. private Dictionary<int, int> _map = new Dictionary<int, int>();
  10. public override void SetUiNode(IUiNode uiNode)
  11. {
  12. _optionBar = (MapEditorCreateMark.OptionBar)uiNode;
  13. }
  14.  
  15. public override void OnDestroy()
  16. {
  17. }
  18. public override string GetAttributeValue()
  19. {
  20. return _map[_optionBar.L_OptionInput.Instance.Selected].ToString();
  21. }
  22.  
  23. /// <summary>
  24. /// 根据值选中选项
  25. /// </summary>
  26. public void SetSelectItem(int value)
  27. {
  28. foreach (var keyValuePair in _map)
  29. {
  30. if (keyValuePair.Value == value)
  31. {
  32. _optionBar.L_OptionInput.Instance.Select(keyValuePair.Key);
  33. return;
  34. }
  35. }
  36. _optionBar.L_OptionInput.Instance.Select(-1);
  37. }
  38. /// <summary>
  39. /// 添加选项
  40. /// </summary>
  41. /// <param name="label">选项显示文本</param>
  42. /// <param name="value">选项值</param>
  43. public void AddItem(string label, int value)
  44. {
  45. var index = _index++;
  46. _map.Add(index, value);
  47. _optionBar.L_OptionInput.Instance.AddItem(label, index);
  48. }
  49. }