Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / ui / mapEditorCreateMark / attribute / ObjectAttribute.cs
  1. using Config;
  2.  
  3. namespace UI.MapEditorCreateMark;
  4.  
  5. public partial class ObjectAttribute : AttributeBase
  6. {
  7. /// <summary>
  8. /// 可选择的物体类型
  9. /// </summary>
  10. public ActivityType ActivityType { get; set; }
  11. private MapEditorCreateMark.ObjectBar _objectBar;
  12. //选择的武器数据
  13. private ExcelConfig.Weapon _selectWeapon;
  14. //关联属性
  15. private MapEditorCreateMark.NumberBar _currAmmonAttr;
  16. private MapEditorCreateMark.NumberBar _residueAmmoAttr;
  17.  
  18. public override void SetUiNode(IUiNode uiNode)
  19. {
  20. _objectBar = (MapEditorCreateMark.ObjectBar)uiNode;
  21. _objectBar.L_HBoxContainer.L_SelectButton.Instance.Pressed += OnClickEdit;
  22. _objectBar.L_HBoxContainer.L_DeleteButton.Instance.Pressed += OnClickDelete;
  23. }
  24.  
  25. public override string GetAttributeValue()
  26. {
  27. if (_selectWeapon == null)
  28. {
  29. return null;
  30. }
  31. return _selectWeapon.WeaponId;
  32. }
  33.  
  34. //点击编辑按钮
  35. private void OnClickEdit()
  36. {
  37. EditorWindowManager.ShowSelectObject(ActivityType.Weapon, OnSelectObject, _objectBar.UiPanel);
  38. }
  39.  
  40. //点击删除按钮
  41. private void OnClickDelete()
  42. {
  43. SelectWeapon(null);
  44. }
  45.  
  46. private void OnSelectObject(ExcelConfig.ActivityObject activityObject)
  47. {
  48. var weapon = ExcelConfig.Weapon_List.Find(weapon => weapon.WeaponId == activityObject.Id);
  49. if (weapon != null)
  50. {
  51. SelectWeapon(weapon);
  52. }
  53. }
  54.  
  55. /// <summary>
  56. /// 设置选择的武器物体
  57. /// </summary>
  58. public void SelectWeapon(ExcelConfig.Weapon weapon)
  59. {
  60. if (weapon == null)
  61. {
  62. _objectBar.L_HBoxContainer.L_DeleteButton.Instance.Visible = false;
  63. _selectWeapon = null;
  64. //隐藏关联属性
  65. _currAmmonAttr.Instance.Visible = false;
  66. _residueAmmoAttr.Instance.Visible = false;
  67. _objectBar.L_HBoxContainer.L_ObjectIcon.Instance.Visible = false;
  68. _objectBar.L_HBoxContainer.L_ObjectName.Instance.Text = "<未选择>";
  69. }
  70. else
  71. {
  72. _objectBar.L_HBoxContainer.L_DeleteButton.Instance.Visible = true;
  73. _selectWeapon = weapon;
  74. var o = ExcelConfig.ActivityObject_Map[weapon.WeaponId];
  75. //显示关联属性
  76. _currAmmonAttr.Instance.Visible = true;
  77. _residueAmmoAttr.Instance.Visible = true;
  78. //显示数据
  79. _objectBar.L_HBoxContainer.L_ObjectName.Instance.Text = o.Name;
  80. _objectBar.L_HBoxContainer.L_ObjectIcon.Instance.Visible = true;
  81. _objectBar.L_HBoxContainer.L_ObjectIcon.Instance.Texture = ResourceManager.LoadTexture2D(o.Icon);
  82. //弹药
  83. _currAmmonAttr.L_NumInput.Instance.MaxValue = weapon.AmmoCapacity;
  84. _residueAmmoAttr.L_NumInput.Instance.MaxValue = weapon.MaxAmmoCapacity;
  85. }
  86. }
  87.  
  88. /// <summary>
  89. /// 设置关联的属性
  90. /// </summary>
  91. public void SetRelevancyAttr(MapEditorCreateMark.NumberBar currAmmonAttr, MapEditorCreateMark.NumberBar residueAmmoAttr)
  92. {
  93. _currAmmonAttr = currAmmonAttr;
  94. _residueAmmoAttr = residueAmmoAttr;
  95. currAmmonAttr.Instance.Visible = false;
  96. residueAmmoAttr.Instance.Visible = false;
  97. }
  98. }