TC_NodeGroupGUI.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. using UnityEngine;
  2. using UnityEditor;
  3. using System;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. namespace TerrainComposer2
  7. {
  8. static public class TC_NodeGroupGUI
  9. {
  10. static public int Draw(TC_NodeGroup nodeGroup, ref Vector2 pos, Color colGroupNode, Color colNode, Color colBracket, float activeMulti, bool nodeFoldout, bool drawMethod, bool colorPreviewTex, bool hideSelectNodes)
  11. {
  12. if (nodeGroup == null) return 0;
  13. // bool select = false;
  14. // Draw total node
  15. Rect dropDownRect;
  16. float activeMultiOld = activeMulti;
  17. activeMulti *= nodeGroup.active ? 1 : 0.75f;
  18. bool isCulled = false;
  19. TC_GlobalSettings g = TC_Settings.instance.global;
  20. // if ((nodeGroup.foldout == 1 && nodeGroup.itemList.Count == 1) || nodeGroup.itemList.Count == 0) nodeGroup.foldout = 0;
  21. // Closing Bracket
  22. TD.DrawBracket(ref pos, nodeFoldout, true, colBracket * activeMultiOld, ref nodeGroup.foldout, true, nodeGroup.itemList.Count > 0);
  23. if (nodeGroup.foldout > 0)
  24. {
  25. if ((nodeGroup.itemList.Count != 1 || nodeGroup.foldout != 1) && nodeGroup.itemList.Count != 0 && !hideSelectNodes) pos.x -= TD.texCardBody.width;
  26. if (nodeGroup.itemList.Count > 1 && !hideSelectNodes)
  27. {
  28. dropDownRect = TD.DrawNode(nodeGroup, pos, colGroupNode, Color.white, ref isCulled, activeMulti, nodeFoldout, drawMethod, false);
  29. if (nodeGroup.foldout == 2) pos.x -= TD.texCardBody.width + g.nodeHSpace;
  30. DropDownMenu(dropDownRect, nodeGroup);
  31. }
  32. //if (colorPreviewTex)
  33. //{
  34. // startOffset.x -= TD.nodeWidth;
  35. // TD.DrawNode(nodeGroup, drawMethod, ref startOffset, true, color, click, Color.white, ref isCulled);
  36. // startOffset.x -= TD.nodeWidth;
  37. //}
  38. // Draw ()
  39. //if (nodeGroup.itemList.Count > 1)
  40. //{
  41. // startOffset.x += 10;
  42. // Draw ItemList Count
  43. // if (!nodeGroup.foldout)
  44. // {
  45. // TD.DrawRect(new Rect(startOffset.x - 9, (startOffset.y + TD.nodeHeight / 2) - 5, 18, 10), TC_Settings.instance.global.colTextBackGround);
  46. // TD.DrawText(new Vector2(startOffset.x + 2, startOffset.y + TD.nodeHeight / 2), nodeGroup.itemList.Count.ToString(), 8, FontStyle.Bold, Color.white, HorTextAlign.Center, VerTextAlign.Center);
  47. // }
  48. // startOffset.x -= TD.nodeWidthSpace;
  49. //}
  50. if (nodeGroup.foldout == 2 && !hideSelectNodes)
  51. {
  52. if (nodeGroup.itemList.Count > 1 && nodeFoldout) TD.DrawMethod(nodeGroup, pos + new Vector2(TD.texCardBody.width - 18, 172), true, colNode, activeMulti);
  53. for (int i = nodeGroup.itemList.Count - 1; i >= 0; --i)
  54. {
  55. TC_Node node = nodeGroup.itemList[i] as TC_Node;
  56. if (node != null)
  57. {
  58. TC_NodeGUI.Draw(node, nodeFoldout, i == 0 ? false : true, pos, colNode, activeMulti);
  59. if (i != 0) pos.x -= TD.nodeWidthHSpace;
  60. if (node.inputKind != InputKind.Current && node.inputKind != InputKind.Portal && i != 0 && nodeFoldout)
  61. {
  62. TD.DrawMethod(node, pos + new Vector2(TD.texCardBody.width - 18, 172), false, colNode, (node.active ? 1 : 0.5f) * activeMulti);
  63. }
  64. }
  65. else
  66. {
  67. TC_NodeGroup nodeGroupChild = nodeGroup.itemList[i] as TC_NodeGroup;
  68. if (nodeGroupChild != null)
  69. {
  70. pos.x += TD.nodeWidthHSpace;
  71. Draw(nodeGroupChild, ref pos, colGroupNode, colNode, colBracket, activeMulti, nodeFoldout, drawMethod, false, false);
  72. if (i != 0)
  73. {
  74. pos.x -= TD.nodeWidthHSpace;
  75. TD.DrawMethod(nodeGroupChild, pos + new Vector2(TD.texCardBody.width - 18, 172), false, colNode, (nodeGroupChild.active ? 1 : 0.5f) * activeMulti);
  76. }
  77. }
  78. }
  79. }
  80. }
  81. }
  82. if (nodeFoldout)
  83. {
  84. int mouseClick = TD.DrawNodeCount(nodeGroup, ref pos, nodeGroup.itemList.Count, nodeFoldout, ref nodeGroup.foldout, (nodeGroup.foldout == 1 && nodeGroup.itemList.Count != 1 ? colGroupNode * 0.75f : colBracket) * activeMulti);
  85. if (mouseClick == 0 && nodeGroup.itemList.Count == 0) nodeGroup.Add<TC_Node>("", false, false, true);
  86. }
  87. // Opening Bracket
  88. TD.DrawBracket(ref pos, nodeFoldout, false, colBracket * activeMultiOld, ref nodeGroup.foldout, true, nodeGroup.itemList.Count > 0);
  89. return 0;
  90. }
  91. static public void DropDownMenu(Rect rect, TC_NodeGroup nodeGroup)
  92. {
  93. if (TD.ClickRect(rect) != 1) return;
  94. GenericMenu menu = new GenericMenu();
  95. // menu.AddItem(new GUIContent("Add Layer"), false, LeftClickMenu, "Add Layer");
  96. string instanceID = nodeGroup.GetInstanceID().ToString();
  97. menu.AddItem(new GUIContent("Clear Nodes"), false, LeftClickMenu, instanceID + ":Clear Nodes");
  98. menu.ShowAsContext();
  99. }
  100. static public void LeftClickMenu(object obj)
  101. {
  102. int instanceID;
  103. string command = TD.ObjectToCommandAndInstanceID(obj, out instanceID);
  104. TC_NodeGroup nodeGroup = EditorUtility.InstanceIDToObject(instanceID) as TC_NodeGroup;
  105. if (nodeGroup != null)
  106. {
  107. if (command == "Clear Nodes")
  108. {
  109. nodeGroup.Clear(true);
  110. }
  111. }
  112. }
  113. }
  114. }