Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / ui / mapEditorCreateMark / MarkObjectCell.cs
  1. using System;
  2. using System.Collections.Generic;
  3. using Config;
  4.  
  5. namespace UI.MapEditorCreateMark;
  6.  
  7. public class MarkObjectCell : UiCell<MapEditorCreateMark.MarkObject, MarkInfoItem>
  8. {
  9. //是否展开
  10. private bool _isExpand = false;
  11. private MapEditorCreateMark.ExpandPanel _expandPanel;
  12. //自定义额外属性
  13. private List<AttributeBase> _attributeBases;
  14. private ExcelConfig.ActivityBase _activityObject;
  15.  
  16. private MapEditorCreateMark.NumberBar _altitude;
  17. private MapEditorCreateMark.NumberBar _vSpeed;
  18. public override void OnInit()
  19. {
  20. CellNode.L_VBoxContainer.L_HBoxContainer.L_ExpandButton.Instance.Pressed += OnExpandClick;
  21. CellNode.L_VBoxContainer.L_HBoxContainer.L_CenterContainer.L_DeleteButton.Instance.Pressed += OnDeleteClick;
  22. }
  23.  
  24. public override void OnSetData(MarkInfoItem data)
  25. {
  26. //物体Id
  27. CellNode.L_VBoxContainer.L_HBoxContainer.L_IdLabel.Instance.Text = data.Id;
  28. //权重
  29. CellNode.L_VBoxContainer.L_HBoxContainer.L_WeightEdit.Instance.Value = data.Weight;
  30. if (data.SpecialMarkType == SpecialMarkType.BirthPoint) //出生标记
  31. {
  32. //物体名称
  33. CellNode.L_VBoxContainer.L_HBoxContainer.L_NameLabel.Instance.Text = PreinstallMarkManager.GetSpecialName(data.SpecialMarkType);
  34. //物体类型
  35. CellNode.L_VBoxContainer.L_HBoxContainer.L_TypeLabel.Instance.Text = ActivityId.GetTypeName(ActivityType.Player);
  36. //图标
  37. CellNode.L_VBoxContainer.L_HBoxContainer.L_Icon.Instance.Visible = true;
  38. CellNode.L_VBoxContainer.L_HBoxContainer.L_Icon.Instance.Texture = ResourceManager.LoadTexture2D(ResourcePath.resource_sprite_ui_commonIcon_BirthMark_png);
  39. CellNode.L_VBoxContainer.L_HBoxContainer.L_CenterContainer.L_DeleteButton.Instance.Visible = false;
  40. CellNode.L_VBoxContainer.L_HBoxContainer.L_WeightEdit.Instance.Visible = false;
  41. }
  42. else //普通标记
  43. {
  44. //记得判断随机对象, 后面再做
  45. _activityObject = PreinstallMarkManager.GetMarkConfig(data.Id);
  46. //物体名称
  47. CellNode.L_VBoxContainer.L_HBoxContainer.L_NameLabel.Instance.Text = _activityObject.Name;
  48. //物体类型
  49. CellNode.L_VBoxContainer.L_HBoxContainer.L_TypeLabel.Instance.Text = NameManager.GetActivityTypeName(_activityObject.Type);
  50. //图标
  51. if (string.IsNullOrEmpty(_activityObject.Icon))
  52. {
  53. CellNode.L_VBoxContainer.L_HBoxContainer.L_Icon.Instance.Visible = false;
  54. }
  55. else
  56. {
  57. CellNode.L_VBoxContainer.L_HBoxContainer.L_Icon.Instance.Visible = true;
  58. CellNode.L_VBoxContainer.L_HBoxContainer.L_Icon.Instance.Texture = ResourceManager.LoadTexture2D(_activityObject.Icon);
  59. }
  60. // 包含额外属性
  61. if (_expandPanel == null)
  62. {
  63. CreateExpandPanel(_activityObject, data);
  64. }
  65. CellNode.L_VBoxContainer.L_HBoxContainer.L_CenterContainer.L_DeleteButton.Instance.Visible = true;
  66. CellNode.L_VBoxContainer.L_HBoxContainer.L_WeightEdit.Instance.Visible = true;
  67. }
  68. }
  69.  
  70. public override void OnDisable()
  71. {
  72. if (_expandPanel != null)
  73. {
  74. _attributeBases.Clear();
  75. _attributeBases = null;
  76. _expandPanel.QueueFree();
  77. _expandPanel = null;
  78. _altitude = null;
  79. _vSpeed = null;
  80. }
  81.  
  82. SetExpandState(false);
  83. }
  84.  
  85. /// <summary>
  86. /// 获取标记数据对象
  87. /// </summary>
  88. public MarkInfoItem GetMarkInfoItem()
  89. {
  90. var markInfoItem = Data;
  91. //额外属性
  92. if (_attributeBases != null)
  93. {
  94. markInfoItem.Attr = null;
  95. foreach (var attributeBase in _attributeBases)
  96. {
  97. if (attributeBase.Visible)
  98. {
  99. if (attributeBase.AttrName == "VSpeed" || attributeBase.AttrName == "Altitude") //不能是公共属性
  100. {
  101. continue;
  102. }
  103.  
  104. if (markInfoItem.Attr == null)
  105. {
  106. markInfoItem.Attr = new Dictionary<string, string>();
  107. }
  108. markInfoItem.Attr.Add(attributeBase.AttrName, attributeBase.GetAttributeValue());
  109. }
  110. }
  111. }
  112.  
  113.  
  114. if (Data.SpecialMarkType == SpecialMarkType.Normal)
  115. {
  116. //权重
  117. markInfoItem.Weight = (int)CellNode.L_VBoxContainer.L_HBoxContainer.L_WeightEdit.Instance.Value;
  118. }
  119.  
  120. //海拔高度
  121. if (_altitude != null && _altitude.Instance.Visible)
  122. {
  123. markInfoItem.Altitude = (int)_altitude.L_NumInput.Instance.Value;
  124. }
  125. //纵轴速度
  126. if (_vSpeed != null && _vSpeed.Instance.Visible)//海拔高度
  127. {
  128. markInfoItem.VerticalSpeed = (float)_vSpeed.L_NumInput.Instance.Value;
  129. }
  130.  
  131. return markInfoItem;
  132. }
  133.  
  134. //点击删除按钮
  135. private void OnDeleteClick()
  136. {
  137. Grid.RemoveByIndex(Index);
  138. }
  139.  
  140. //点击展开按钮
  141. private void OnExpandClick()
  142. {
  143. //展开图标
  144. SetExpandState(!_isExpand);
  145. }
  146.  
  147. //设置展开状态
  148. private void SetExpandState(bool flag)
  149. {
  150. _isExpand = flag;
  151. if (_isExpand)
  152. {
  153. CellNode.L_VBoxContainer.L_HBoxContainer.L_ExpandButton.Instance.Icon =
  154. ResourceManager.LoadTexture2D(ResourcePath.resource_sprite_ui_commonIcon_Down_png);
  155. }
  156. else
  157. {
  158. CellNode.L_VBoxContainer.L_HBoxContainer.L_ExpandButton.Instance.Icon =
  159. ResourceManager.LoadTexture2D(ResourcePath.resource_sprite_ui_commonIcon_Right_png);
  160. }
  161.  
  162. if (_expandPanel != null)
  163. {
  164. _expandPanel.Instance.Visible = _isExpand;
  165. }
  166. }
  167.  
  168. private void CreateExpandPanel(ExcelConfig.ActivityBase activityObject, MarkInfoItem markInfoItem)
  169. {
  170. if (_expandPanel != null)
  171. {
  172. throw new Exception("已经创建过ExpandPanel, 不能重复创建!");
  173. }
  174. _expandPanel = CellNode.UiPanel.S_ExpandPanel.Clone();
  175. _expandPanel.Instance.Visible = _isExpand;
  176. CellNode.L_VBoxContainer.AddChild(_expandPanel);
  177. //公有类型
  178. _altitude = CellNode.UiPanel.CreateNumberBar("Altitude", "初始纵轴高度:");
  179. _vSpeed = CellNode.UiPanel.CreateNumberBar("VSpeed", "初始纵轴速度:");
  180. _altitude.L_NumInput.Instance.MaxValue = 128;
  181. _altitude.L_NumInput.Instance.MinValue = 0;
  182. _altitude.L_NumInput.Instance.Step = 1;
  183. _vSpeed.L_NumInput.Instance.MaxValue = 1000;
  184. _vSpeed.L_NumInput.Instance.MinValue = -1000;
  185. _vSpeed.L_NumInput.Instance.Step = 0.1;
  186. _expandPanel.L_ExpandGrid.AddChild(_altitude);
  187. _expandPanel.L_ExpandGrid.AddChild(_vSpeed);
  188.  
  189. if (markInfoItem != null)
  190. {
  191. //海拔高度
  192. _altitude.L_NumInput.Instance.Value = markInfoItem.Altitude;
  193. //纵轴速度
  194. _vSpeed.L_NumInput.Instance.Value = markInfoItem.VerticalSpeed;
  195. }
  196. if (activityObject.Type == (int)ActivityType.Weapon) //武器类型
  197. {
  198. var numberBar = CellNode.UiPanel.CreateNumberBar("CurrAmmon", "弹夹弹药量:");
  199. var numberBar2 = CellNode.UiPanel.CreateNumberBar("ResidueAmmo", "剩余弹药量:");
  200. _expandPanel.L_ExpandGrid.AddChild(numberBar);
  201. _expandPanel.L_ExpandGrid.AddChild(numberBar2);
  202. _attributeBases = new List<AttributeBase>();
  203. _attributeBases.Add(numberBar.Instance);
  204. _attributeBases.Add(numberBar2.Instance);
  205. if (markInfoItem != null) //初始化数据
  206. {
  207. numberBar.L_NumInput.Instance.MinValue = 0;
  208. numberBar2.L_NumInput.Instance.MinValue = 0;
  209. //武器配置数据
  210. var weapon = Weapon.GetWeaponAttribute(activityObject.Id);
  211. if (weapon != null)
  212. {
  213. numberBar.L_NumInput.Instance.MaxValue = weapon.AmmoCapacity; //弹夹上限
  214. numberBar2.L_NumInput.Instance.MaxValue = weapon.MaxAmmoCapacity; //容量上限
  215. }
  216.  
  217. if (markInfoItem.Attr != null)
  218. {
  219. if (markInfoItem.Attr.TryGetValue("CurrAmmon", out var currAmmon)) //弹夹弹药量
  220. {
  221. numberBar.L_NumInput.Instance.Value = float.Parse(currAmmon);
  222. }
  223. if (markInfoItem.Attr.TryGetValue("ResidueAmmo", out var residueAmmo)) //剩余弹药量
  224. {
  225. numberBar2.L_NumInput.Instance.Value = float.Parse(residueAmmo);
  226. }
  227. }
  228. else
  229. {
  230. numberBar.L_NumInput.Instance.Value = numberBar.L_NumInput.Instance.MaxValue;
  231. numberBar2.L_NumInput.Instance.Value = (int)(numberBar2.L_NumInput.Instance.MaxValue / 2);
  232. }
  233. }
  234. }
  235. else if (activityObject.Type == (int)ActivityType.Enemy) //敌人
  236. {
  237. var faceBar = CellNode.UiPanel.CreateOptionBar("Face", "脸朝向:");
  238. faceBar.Instance.AddItem("随机", 0);
  239. faceBar.Instance.AddItem("左", (int)FaceDirection.Left);
  240. faceBar.Instance.AddItem("右", (int)FaceDirection.Right);
  241. var weaponBar = CellNode.UiPanel.CreateObjectBar("Weapon", "携带武器:", ActivityType.Weapon);
  242. var numberBar2 = CellNode.UiPanel.CreateNumberBar("CurrAmmon", "弹夹弹药量:");
  243. var numberBar3 = CellNode.UiPanel.CreateNumberBar("ResidueAmmo", "剩余弹药量:");
  244. weaponBar.Instance.SetRelevancyAttr(numberBar2, numberBar3);
  245. _expandPanel.L_ExpandGrid.AddChild(faceBar);
  246. _expandPanel.L_ExpandGrid.AddChild(weaponBar);
  247. _expandPanel.L_ExpandGrid.AddChild(numberBar2);
  248. _expandPanel.L_ExpandGrid.AddChild(numberBar3);
  249. _attributeBases = new List<AttributeBase>();
  250. _attributeBases.Add(faceBar.Instance);
  251. _attributeBases.Add(weaponBar.Instance);
  252. _attributeBases.Add(numberBar2.Instance);
  253. _attributeBases.Add(numberBar3.Instance);
  254. if (markInfoItem != null) //初始化数据
  255. {
  256. numberBar2.L_NumInput.Instance.MinValue = 0;
  257. numberBar3.L_NumInput.Instance.MinValue = 0;
  258. if (markInfoItem.Attr != null)
  259. {
  260. if (markInfoItem.Attr.TryGetValue("Face", out var face)) //朝向
  261. {
  262. faceBar.Instance.SetSelectItem(int.Parse(face));
  263. }
  264. if (markInfoItem.Attr.TryGetValue("Weapon", out var weaponId)) //武器
  265. {
  266. weaponBar.Instance.SelectWeapon(Weapon.GetWeaponAttribute(weaponId));
  267. }
  268. if (markInfoItem.Attr.TryGetValue("CurrAmmon", out var currAmmon)) //弹夹弹药量
  269. {
  270. numberBar2.L_NumInput.Instance.Value = float.Parse(currAmmon);
  271. }
  272. if (markInfoItem.Attr.TryGetValue("ResidueAmmo", out var residueAmmo)) //剩余弹药量
  273. {
  274. numberBar3.L_NumInput.Instance.Value = float.Parse(residueAmmo);
  275. }
  276. }
  277. else
  278. {
  279. faceBar.Instance.SetSelectItem(0);
  280. numberBar2.L_NumInput.Instance.Value = numberBar2.L_NumInput.Instance.MaxValue;
  281. numberBar3.L_NumInput.Instance.Value = (int)(numberBar3.L_NumInput.Instance.MaxValue / 2);
  282. }
  283. }
  284. }
  285. }
  286. }