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 = ActivityId.GetTypeName(_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. if (_attributeBases != null)
  75. {
  76. _attributeBases.Clear();
  77. _attributeBases = null;
  78. }
  79. _expandPanel.QueueFree();
  80. _expandPanel = null;
  81. _altitude = null;
  82. _vSpeed = null;
  83. }
  84.  
  85. SetExpandState(false);
  86. }
  87.  
  88. /// <summary>
  89. /// 获取标记数据对象
  90. /// </summary>
  91. public MarkInfoItem GetMarkInfoItem()
  92. {
  93. var markInfoItem = Data;
  94. //额外属性
  95. if (_attributeBases != null)
  96. {
  97. markInfoItem.Attr = null;
  98. foreach (var attributeBase in _attributeBases)
  99. {
  100. if (attributeBase.Visible)
  101. {
  102. if (attributeBase.AttrName == "VSpeed" || attributeBase.AttrName == "Altitude") //不能是公共属性
  103. {
  104. continue;
  105. }
  106.  
  107. if (markInfoItem.Attr == null)
  108. {
  109. markInfoItem.Attr = new Dictionary<string, string>();
  110. }
  111. markInfoItem.Attr.Add(attributeBase.AttrName, attributeBase.GetAttributeValue());
  112. }
  113. }
  114. }
  115.  
  116.  
  117. if (Data.SpecialMarkType == SpecialMarkType.Normal)
  118. {
  119. //权重
  120. markInfoItem.Weight = (int)CellNode.L_VBoxContainer.L_HBoxContainer.L_WeightEdit.Instance.Value;
  121. }
  122.  
  123. //海拔高度
  124. if (_altitude != null && _altitude.Instance.Visible)
  125. {
  126. markInfoItem.Altitude = (int)_altitude.L_NumInput.Instance.Value;
  127. }
  128. //纵轴速度
  129. if (_vSpeed != null && _vSpeed.Instance.Visible)//海拔高度
  130. {
  131. markInfoItem.VerticalSpeed = (float)_vSpeed.L_NumInput.Instance.Value;
  132. }
  133.  
  134. return markInfoItem;
  135. }
  136.  
  137. //点击删除按钮
  138. private void OnDeleteClick()
  139. {
  140. Grid.RemoveByIndex(Index);
  141. }
  142.  
  143. //点击展开按钮
  144. private void OnExpandClick()
  145. {
  146. //展开图标
  147. SetExpandState(!_isExpand);
  148. }
  149.  
  150. //设置展开状态
  151. private void SetExpandState(bool flag)
  152. {
  153. _isExpand = flag;
  154. if (_isExpand)
  155. {
  156. CellNode.L_VBoxContainer.L_HBoxContainer.L_ExpandButton.Instance.Icon =
  157. ResourceManager.LoadTexture2D(ResourcePath.resource_sprite_ui_commonIcon_Down_png);
  158. }
  159. else
  160. {
  161. CellNode.L_VBoxContainer.L_HBoxContainer.L_ExpandButton.Instance.Icon =
  162. ResourceManager.LoadTexture2D(ResourcePath.resource_sprite_ui_commonIcon_Right_png);
  163. }
  164.  
  165. if (_expandPanel != null)
  166. {
  167. _expandPanel.Instance.Visible = _isExpand;
  168. }
  169. }
  170.  
  171. private void CreateExpandPanel(ExcelConfig.ActivityBase activityObject, MarkInfoItem markInfoItem)
  172. {
  173. if (_expandPanel != null)
  174. {
  175. throw new Exception("已经创建过ExpandPanel, 不能重复创建!");
  176. }
  177. _expandPanel = CellNode.UiPanel.S_ExpandPanel.Clone();
  178. _expandPanel.Instance.Visible = _isExpand;
  179. CellNode.L_VBoxContainer.AddChild(_expandPanel);
  180. //公有类型
  181. _altitude = CellNode.UiPanel.CreateNumberBar("Altitude", "初始纵轴高度:");
  182. _vSpeed = CellNode.UiPanel.CreateNumberBar("VSpeed", "初始纵轴速度:");
  183. _altitude.L_NumInput.Instance.MaxValue = 128;
  184. _altitude.L_NumInput.Instance.MinValue = 0;
  185. _altitude.L_NumInput.Instance.Step = 1;
  186. _vSpeed.L_NumInput.Instance.MaxValue = 1000;
  187. _vSpeed.L_NumInput.Instance.MinValue = -1000;
  188. _vSpeed.L_NumInput.Instance.Step = 0.1;
  189. _expandPanel.L_ExpandGrid.AddChild(_altitude);
  190. _expandPanel.L_ExpandGrid.AddChild(_vSpeed);
  191.  
  192. if (markInfoItem != null)
  193. {
  194. //海拔高度
  195. _altitude.L_NumInput.Instance.Value = markInfoItem.Altitude;
  196. //纵轴速度
  197. _vSpeed.L_NumInput.Instance.Value = markInfoItem.VerticalSpeed;
  198. }
  199. if (activityObject.Type == ActivityType.Weapon) //武器类型
  200. {
  201. var numberBar = CellNode.UiPanel.CreateNumberBar("CurrAmmon", "弹夹弹药量:");
  202. var numberBar2 = CellNode.UiPanel.CreateNumberBar("ResidueAmmo", "剩余弹药量:");
  203. _expandPanel.L_ExpandGrid.AddChild(numberBar);
  204. _expandPanel.L_ExpandGrid.AddChild(numberBar2);
  205. _attributeBases = new List<AttributeBase>();
  206. _attributeBases.Add(numberBar.Instance);
  207. _attributeBases.Add(numberBar2.Instance);
  208. if (markInfoItem != null) //初始化数据
  209. {
  210. numberBar.L_NumInput.Instance.MinValue = 0;
  211. numberBar2.L_NumInput.Instance.MinValue = 0;
  212. //武器配置数据
  213. var weapon = Weapon.GetWeaponAttribute(activityObject.Id);
  214. if (weapon != null)
  215. {
  216. numberBar.L_NumInput.Instance.MaxValue = weapon.AmmoCapacity; //弹夹上限
  217. numberBar2.L_NumInput.Instance.MaxValue = weapon.MaxAmmoCapacity; //容量上限
  218. }
  219.  
  220. if (markInfoItem.Attr != null)
  221. {
  222. if (markInfoItem.Attr.TryGetValue("CurrAmmon", out var currAmmon)) //弹夹弹药量
  223. {
  224. numberBar.L_NumInput.Instance.Value = float.Parse(currAmmon);
  225. }
  226. if (markInfoItem.Attr.TryGetValue("ResidueAmmo", out var residueAmmo)) //剩余弹药量
  227. {
  228. numberBar2.L_NumInput.Instance.Value = float.Parse(residueAmmo);
  229. }
  230. }
  231. else
  232. {
  233. numberBar.L_NumInput.Instance.Value = numberBar.L_NumInput.Instance.MaxValue;
  234. numberBar2.L_NumInput.Instance.Value = (int)(numberBar2.L_NumInput.Instance.MaxValue / 2);
  235. }
  236. }
  237. }
  238. else if (activityObject.Type == ActivityType.Enemy) //敌人
  239. {
  240. var faceBar = CellNode.UiPanel.CreateOptionBar("Face", "脸朝向:");
  241. faceBar.Instance.AddItem("随机", 0);
  242. faceBar.Instance.AddItem("左", (int)FaceDirection.Left);
  243. faceBar.Instance.AddItem("右", (int)FaceDirection.Right);
  244. var weaponBar = CellNode.UiPanel.CreateObjectBar("Weapon", "携带武器:", ActivityType.Weapon);
  245. var numberBar2 = CellNode.UiPanel.CreateNumberBar("CurrAmmon", "弹夹弹药量:");
  246. var numberBar3 = CellNode.UiPanel.CreateNumberBar("ResidueAmmo", "剩余弹药量:");
  247. weaponBar.Instance.SetRelevancyAttr(numberBar2, numberBar3);
  248. _expandPanel.L_ExpandGrid.AddChild(faceBar);
  249. _expandPanel.L_ExpandGrid.AddChild(weaponBar);
  250. _expandPanel.L_ExpandGrid.AddChild(numberBar2);
  251. _expandPanel.L_ExpandGrid.AddChild(numberBar3);
  252. _attributeBases = new List<AttributeBase>();
  253. _attributeBases.Add(faceBar.Instance);
  254. _attributeBases.Add(weaponBar.Instance);
  255. _attributeBases.Add(numberBar2.Instance);
  256. _attributeBases.Add(numberBar3.Instance);
  257. if (markInfoItem != null) //初始化数据
  258. {
  259. numberBar2.L_NumInput.Instance.MinValue = 0;
  260. numberBar3.L_NumInput.Instance.MinValue = 0;
  261. if (markInfoItem.Attr != null)
  262. {
  263. if (markInfoItem.Attr.TryGetValue("Face", out var face)) //朝向
  264. {
  265. faceBar.Instance.SetSelectItem(int.Parse(face));
  266. }
  267. if (markInfoItem.Attr.TryGetValue("Weapon", out var weaponId)) //武器
  268. {
  269. weaponBar.Instance.SelectWeapon(Weapon.GetWeaponAttribute(weaponId));
  270. }
  271. if (markInfoItem.Attr.TryGetValue("CurrAmmon", out var currAmmon)) //弹夹弹药量
  272. {
  273. numberBar2.L_NumInput.Instance.Value = float.Parse(currAmmon);
  274. }
  275. if (markInfoItem.Attr.TryGetValue("ResidueAmmo", out var residueAmmo)) //剩余弹药量
  276. {
  277. numberBar3.L_NumInput.Instance.Value = float.Parse(residueAmmo);
  278. }
  279. }
  280. else
  281. {
  282. faceBar.Instance.SetSelectItem(0);
  283. numberBar2.L_NumInput.Instance.Value = numberBar2.L_NumInput.Instance.MaxValue;
  284. numberBar3.L_NumInput.Instance.Value = (int)(numberBar3.L_NumInput.Instance.MaxValue / 2);
  285. }
  286. }
  287. }
  288. }
  289. }