123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377 |
- using UnityEngine;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEditor;
- namespace TerrainComposer2
- {
- static class DrawCommand
- {
- static List<TextureCommand> drawTextureList0 = new List<TextureCommand>();
- static List<TextureCommand> drawTextureList1 = new List<TextureCommand>();
- static List<TextureCommand> drawTextureList2 = new List<TextureCommand>();
- static List<TextCommand> drawTextList = new List<TextCommand>();
- static public void Add(Rect rect, Texture tex, Color color, int queue = 0)
- {
- if (queue == 0) drawTextureList0.Add(new TextureCommand(rect, tex, color));
- else if (queue == 1) drawTextureList1.Add(new TextureCommand(rect, tex, color));
- else if (queue == 2) drawTextureList2.Add(new TextureCommand(rect, tex, color));
- }
- static public void Add(Vector2 pos, Texture tex, Color color, int queue = 0)
- {
- if (queue == 0) drawTextureList0.Add(new TextureCommand(pos, tex, color));
- else if (queue == 1) drawTextureList1.Add(new TextureCommand(pos, tex, color));
- else if (queue == 2) drawTextureList2.Add(new TextureCommand(pos, tex, color));
- }
- static public void Add(Vector2 pos, string text, int fontSize, Color color, FontStyle fontStyle = FontStyle.Normal, HorTextAlign horTextAlign = HorTextAlign.Left, VerTextAlign vertTextAlign = VerTextAlign.Top)
- {
- drawTextList.Add(new TextCommand(pos, text, fontSize, color, fontStyle, horTextAlign, vertTextAlign));
- }
- static public void Add(Vector2 pos, int space, string prefixText, string text, int fontSize, Color color, FontStyle fontStyle = FontStyle.Normal, HorTextAlign horTextAlign = HorTextAlign.Left, VerTextAlign vertTextAlign = VerTextAlign.Top)
- {
- drawTextList.Add(new TextCommand(pos, prefixText, fontSize, color, fontStyle, horTextAlign, vertTextAlign));
- drawTextList.Add(new TextCommand(pos + new Vector2(space, 0), text, fontSize, color, fontStyle, horTextAlign, vertTextAlign));
- }
- static public void DrawTextureList(List<TextureCommand> drawTextureList)
- {
- for (int i = 0; i < drawTextureList.Count; i++)
- {
- TextureCommand textureCommand = drawTextureList[i];
- TD.DrawTextureScaled(textureCommand.rect, textureCommand.tex, textureCommand.color);
- }
- drawTextureList.Clear();
- }
- static public void DrawCommandLists()
- {
- DrawTextureList(drawTextureList0);
- DrawTextureList(drawTextureList1);
- DrawTextureList(drawTextureList2);
- for (int i = 0; i < drawTextList.Count; i++) drawTextList[i].Draw();
- GUI.color = Color.white;
- drawTextList.Clear();
- }
- public class TextureCommand
- {
- public Rect rect;
- public Texture tex;
- public Color color;
- public TextureCommand(Vector2 pos, Texture tex, Color color)
- {
- rect = new Rect(pos.x, pos.y, tex.width, tex.height);
- this.tex = tex; this.color = color;
- }
- public TextureCommand(Rect rect, Texture tex, Color color)
- {
- this.rect = rect;
- this.tex = tex; this.color = color;
- }
- }
- public class TextCommand
- {
- public Vector2 pos;
- public string text;
- public int fontSize;
- public Color color;
- public FontStyle fontStyle;
- public HorTextAlign horTextAlign;
- public VerTextAlign vertTextAlign;
- public TextCommand(Vector2 pos, string text, int fontSize, Color color, FontStyle fontStyle = FontStyle.Normal, HorTextAlign horTextAlign = HorTextAlign.Left, VerTextAlign vertTextAlign = VerTextAlign.Top)
- {
- this.pos = pos; this.text = text; this.color = color; this.fontSize = fontSize; this.fontStyle = fontStyle; this.horTextAlign = horTextAlign; this.vertTextAlign = vertTextAlign;
- }
- public void Draw()
- {
- TD.DrawText(pos, text, fontSize, color, fontStyle, horTextAlign, vertTextAlign);
- }
- }
- }
- static public class TC_LayerGroupGUI
- {
- static public Rect DrawLayerOrLayerGroup(TC_ItemBehaviour item, ref Vector2 pos, Color color, ref bool isCulled, float activeMulti, bool drawMethod, bool isFirst, bool isLast)
- {
- TC_GlobalSettings g = TC_Settings.instance.global; // TODO: Make global static and init
- TC_LayerGroup layerGroup = item as TC_LayerGroup;
- TC_Layer layer = item as TC_Layer;
- bool nodeFoldout = (layerGroup != null) ? layerGroup.nodeFoldout : layer.nodeFoldout;
- if (isFirst)
- {
- pos.y += TD.shelfOffsetY;
- TD.DrawTextureScaled(pos.x, pos.y, TD.texShelfLinesConnectDown, Color.white);
- TD.DrawTextureScaled(pos.x, pos.y, TD.texLineConnectDown, g.colLayer * activeMulti);
- pos.y += TD.texShelfLinesConnectDown.height;
- }
- else if (item.level == 0)
- {
- TD.DrawTextureScaled(pos.x + 64, pos.y, TD.texShelfStartConnect, Color.white);
- }
- else pos.y += 15;
- Texture texShelf;
- Texture texLine = null;
-
- if (item.level == 0)
- {
- if (nodeFoldout) texShelf = TD.texShelfStartOutput; else texShelf = TD.texShelfStartOutputCollapsed;
- }
- else if (isLast)
- {
- if (nodeFoldout) { texShelf = TD.texShelfLayerStart2; texLine = TD.texLineLayerStart2; }
- else { texShelf = TD.texShelfLayerCollapsedStart2; texLine = TD.texLineLayerStart2; }
- }
- else
- {
- if (nodeFoldout) { texShelf = TD.texShelfLayerStart1; texLine = TD.texLineLayerStart1; }
- else { texShelf = TD.texShelfLayerCollapsedStart1; texLine = TD.texLineLayerCollapsedStart1; }
- }
- TD.DrawTextureScaled(pos.x, pos.y, texShelf, Color.white);
- if (item.level > 0) TD.DrawTextureScaled(pos.x, pos.y, texLine, g.colLayer * activeMulti);
-
- TD.DrawTextureScaled(pos.x - TD.texShelfStartOutput.width, pos.y, nodeFoldout ? TD.texShelfLayer : TD.texShelfLayerCollapsed, Color.white, false, StretchMode.Left);
-
- pos.y += TD.shelfOffsetY;
- pos.x -= TD.texCardBody.width - (item.level == 0 ? 20 : 34);
- isCulled = false;
-
- Rect nodeRect = TD.DrawNode(item, pos, color, Color.white, ref isCulled, activeMulti, nodeFoldout, drawMethod);
- if (isCulled) return nodeRect;
- int mouseButton = TD.Button(new Rect(pos.x + 245.1f, pos.y + 6.5f, 20, 20), TD.texFoldout, true, new Color(1, 1, 1, 0.25f), Color.white, Color.white, true);
- if (mouseButton >= 0)
- {
- if (layerGroup != null)
- {
- layerGroup.nodeFoldout = !layerGroup.nodeFoldout;
- if (mouseButton == 0) layerGroup.foldout = layerGroup.nodeFoldout ? 2 : 0;
- }
- else layer.nodeFoldout = !layer.nodeFoldout;
- Event.current.Use();
- }
-
- //if (GUI.Button(TD.GetRectScaled(pos.x + 225, pos.y + 2, 40, 25), ""))
- //{
- // if (layerGroup != null) layerGroup.nodeFoldout = !layerGroup.nodeFoldout;
- // else layer.nodeFoldout = !layer.nodeFoldout;
- //}
-
- if (item.method == Method.Lerp && drawMethod)
- {
- // TD.DrawSlider(startOffset, ref item.overlay, 0, 1);
- // if (GUI.changed) TC_Generate.singleton.AutoGenerate();
- }
- if (item.level > 0)
- {
- DrawConnectionIndicator(item, new Vector2(pos.x + 289, pos.y - 27), false, true);
- if (isLast)
- {
- DrawConnectionIndicator(item, new Vector2(pos.x + 289, pos.y + TD.cardHeight + 4), true, nodeFoldout);
- }
- }
-
- return nodeRect;
- }
- static void DrawConnectionIndicator(TC_ItemBehaviour item, Vector2 pos, bool addBefore, bool nodeFoldout)
- {
- if (!nodeFoldout) pos.y -= 351;
- //if (TD.startDrag)
- //{
- // Rect dropRect = TD.GetRectScaled(new Rect(pos.x, pos.y, TD.texConnectionIndicator.width, TD.texConnectionIndicator.height));
- // // TD.DragDropNode(item, dropRect);
- // DrawTextureCommand.Add(pos, TD.texConnectionIndicator, Color.white);
- //}
- //else
- //{
- TC_GlobalSettings g = TC_Settings.instance.global;
- pos -= new Vector2(2.5f, 2.5f);
- Rect rect = new Rect(pos.x + g.rect4.x, pos.y + g.rect4.y, g.rect4.width, g.rect4.width);
- // DrawTextureCommand.Add(rect, TD.texCardCounter, TD.g.colLayer * 0.25f);
- int clickedButton = TD.Button(rect, TD.texAddFirstCard, true, new Color(1, 1, 1, 0.25f), Color.white, Color.white, true, true);
- // tooltip
- //Vector2 mousePosition = Event.current.mousePosition;
- //if (rectScaled.Contains(mousePosition))
- //{
- // DrawCommand.Add(mousePosition + new Vector2(9, 19), 65, "Left Click", "-> Add a new Layer", Color.white);
- // DrawCommand.Add(mousePosition + new Vector2(9, 19 + TD.labelHeight), 65, "Right Click","-> Add a new Layer Group", Color.white);
- // TD.repaintNodeWindow = true;
- //}
- if (clickedButton == 0) Undo.RegisterCreatedObjectUndo(item.Add<TC_Layer>("", true, addBefore, true).gameObject, "Created Layer");
- else if (clickedButton == 1) Undo.RegisterCreatedObjectUndo(item.Add<TC_LayerGroup>("", true, addBefore, true).gameObject, "Created GameObject");
- //}
- }
- static public void Draw(TC_LayerGroup layerGroup, bool drawMethod, ref Vector2 pos, float activeMulti, bool isFirst, bool isLast, ref float shelfLineVerticalStartY)
- {
- TC_GlobalSettings g = TC_Settings.instance.global;
- if (layerGroup.level == 0) pos.x -= TD.texShelfStartOutput.width;
- float posOldX = pos.x;
-
- bool isCulled = false;
- layerGroup.nodePos = pos - new Vector2(0, TD.cardHeight);
- Rect rect = DrawLayerOrLayerGroup(layerGroup, ref pos, g.colLayerGroup, ref isCulled, activeMulti, drawMethod, isFirst, isLast);
- activeMulti = layerGroup.active ? activeMulti : activeMulti * 0.75f;
- // Rect rectFoldout = TD.GetRectScaled(pos.x + 240, pos.y + 43 + (layerGroup.nodeFoldout ? TD.cardHeight : 32), 20, 20);
- // if (GUI.Button(rectFoldout, "")) layerGroup.foldout = !layerGroup.foldout;
- shelfLineVerticalStartY = pos.y + (layerGroup.nodeFoldout ? TD.texShelfLayerStart1.height : TD.texShelfLayerCollapsed.height) - TD.shelfOffsetY;
-
- DropDownMenu(rect, layerGroup);
- Vector2 bar2 = pos;
- bar2.x -= TD.texCardBody.width * 1.5f;
- bar2.y += TD.cardHeight;
- TC_NodeGroupGUI.Draw(layerGroup.maskNodeGroup, ref pos, g.colMaskNodeGroup, g.colMaskNode, g.colLayerGroup, activeMulti, layerGroup.nodeFoldout, false, false, false);
- // if (startOffsetXMax > startOffset.x) startOffsetXMax = startOffset.x;
- // Draw Result Node
- TC_LayerGroupResultGUI.Draw(layerGroup, ref pos, posOldX, activeMulti, layerGroup.nodeFoldout);
-
- int layerGroupCount = 0;
- int layerCount = 0;
- float lineOffsetX;
- if (layerGroup.maskNodeGroup.itemList.Count > 0) { lineOffsetX = 2.5f; } else lineOffsetX = 0;
- bool m_isFirst, m_isLast;
- float m_shelfLineVerticalStartY = 0;
- pos.y += layerGroup.nodeFoldout ? (TD.cardHeight) : 32;
- if (layerGroup.foldout == 2)
- {
- for (int i = layerGroup.groupResult.itemList.Count - 1; i >= 0; --i)
- {
- pos.x = posOldX;// - lineOffsetX ;
- pos.x -= g.layerHSpace;
- TC_LayerGroup layerGroupChild = layerGroup.groupResult.itemList[i] as TC_LayerGroup;
- m_isLast = (i == 0);
- m_isFirst = (i == layerGroup.groupResult.itemList.Count - 1);
- if (layerGroupChild != null)
- {
- Draw(layerGroupChild, i != 0, ref pos, activeMulti, m_isFirst, m_isLast, ref m_shelfLineVerticalStartY);
- if (!m_isLast)
- {
- pos.y += layerGroupChild.nodeFoldout ? 0 : 32;
-
- TD.DrawTextureScaledV(pos.x + 64, m_shelfLineVerticalStartY, (pos.y - m_shelfLineVerticalStartY) + 16, TD.texShelfLinesVertical, Color.white);
- TD.DrawTextureScaledV(pos.x + 64, m_shelfLineVerticalStartY, (pos.y - m_shelfLineVerticalStartY) + 16, TD.texLineVertical, g.colLayer * activeMulti);
- }
- ++layerGroupCount;
- }
- else
- {
- TC_Layer layer = layerGroup.groupResult.itemList[i] as TC_Layer;
- if (layer == null) continue;
- TC_LayerGUI.Draw(layer, ref pos, activeMulti, i != 0, m_isFirst, m_isLast);
- pos.y += layer.nodeFoldout ? TD.cardHeight : 32;
- ++layerCount;
- }
- }
- }
-
- pos.y += 64;
-
- Rect clickRect = TD.GetRectScaled(new Rect(bar2.x + (TD.texCardBody.width * 1.5f) - (2.5f + lineOffsetX), bar2.y - 5f, 10, 10));
- if (TD.ClickRect(clickRect, 0))
- {
- if (layerGroup.foldout == 0) layerGroup.foldout = 2; else layerGroup.foldout = 0;
- }
-
- pos.x = posOldX;
- }
-
- static void DropDownMenu(Rect rect, TC_LayerGroup layerGroup)
- {
- if (TD.ClickRect(rect) != 1) return;
- GenericMenu menu = new GenericMenu();
- // menu.AddItem(new GUIContent("Add Layer"), false, LeftClickMenu, "Add Layer");
- string instanceID = layerGroup.GetInstanceID().ToString();
- //if (layerGroup.level > 1)
- //{
- // menu.AddSeparator("");
- // menu.AddItem(new GUIContent("Add Layer"), false, LeftClickMenu, instanceID + ":Add Layer");
- // menu.AddItem(new GUIContent("Add Layer Group"), false, LeftClickMenu, instanceID + ":Add LayerGroup");
- // menu.AddItem(new GUIContent("Duplicate Layer Group"), false, LeftClickMenu, instanceID + ":Duplicate LayerGroup");
- // menu.AddSeparator("");
- //}
- if (layerGroup.groupResult.itemList.Count > 0)
- {
- //if (layerGroup.level == 0 && layerGroup.outputId == TC.heightOutput)
- //{
- // menu.AddItem(new GUIContent("Export Heightmap"), false, LeftClickMenu, instanceID + ":Export Heightmap");
- // menu.AddSeparator("");
- //}
- //else if (layerGroup.level == 0 && layerGroup.outputId == TC.colorOutput)
- //{
- // menu.AddItem(new GUIContent("Export Colormap"), false, LeftClickMenu, instanceID + ":Export Colormap");
- // menu.AddSeparator("");
- //}
-
- menu.AddItem(new GUIContent("Clear Layer Group"), false, LeftClickMenu, instanceID + ":Clear LayerGroup");
- }
- // if (layerGroup.level > 1) menu.AddItem(new GUIContent("Erase Layer Group"), false, LeftClickMenu, instanceID + ":Erase LayerGroup");
- menu.ShowAsContext();
- }
- static public void LeftClickMenu(object obj)
- {
- int instanceID;
- string command = TD.ObjectToCommandAndInstanceID(obj, out instanceID);
-
- TC_LayerGroup layerGroup = EditorUtility.InstanceIDToObject(instanceID) as TC_LayerGroup;
- if (layerGroup != null)
- {
- if (command == "Add Mask")
- {
- layerGroup.maskNodeGroup.Add<TC_Node>("", false, false, true, 0);
- }
- else if (command == "Add Layer Inside") layerGroup.groupResult.Add<TC_Layer>("", false, true);
- else if (command == "Add LayerGroup Inside") layerGroup.groupResult.Add<TC_LayerGroup>("", false, false, true);
- else if (command == "Add Layer") layerGroup.groupResult.Add<TC_Layer>("", true, true);
- else if (command == "Add LayerGroup") layerGroup.groupResult.Add<TC_LayerGroup>("", true, false, true);
- else if (command == "Duplicate LayerGroup") layerGroup.Duplicate(layerGroup.t.parent);
- else if (command == "Clear LayerGroup") layerGroup.groupResult.Clear(true);
- else if (command == "Erase LayerGroup") layerGroup.DestroyMe(true);
- }
- }
- }
- }
|