Beispiel #1
0
        public static bool ClickedNear(UI ui, Vector2 mousePos,
                                       out Group clickedGroup,
                                       out Generator clickedGen,
                                       out IOutlet <object> clickedLayer,
                                       out IInlet <object> clickedLink,
                                       out IInlet <object> clickedInlet,
                                       out IOutlet <object> clickedOutlet,
                                       out FieldInfo clickedField)
        /// Returns the top clicked object (or null) in clickedGroup-to-clickedField priority
        {
            clickedGroup  = null;
            clickedGen    = null;
            clickedLayer  = null;
            clickedLink   = null;
            clickedInlet  = null;
            clickedOutlet = null;
            clickedField  = null;

            List <Cell> cellsUnderCursor = new List <Cell>();

            ui.rootCell.FillCellsUnderCursor(cellsUnderCursor, mousePos);

            //checking cells
            for (int i = 0; i < cellsUnderCursor.Count; i++)
            {
                Cell cell = cellsUnderCursor[i];

                //GeneratorDraw.genCellLut.TryGetValue(cell, out clickedGen);  //TryGet will overwrite to null if not found

                if (ui.cellObjs.TryGetObject(cell, "Generator", out Generator gen))
                {
                    clickedGen = gen;
                }
                if (ui.cellObjs.TryGetObject(cell, "Group", out Group group))
                {
                    clickedGroup = group;
                }
                if (ui.cellObjs.TryGetObject(cell, "Layer", out IOutlet <object> layer))
                {
                    clickedLayer = layer;
                }
                if (ui.cellObjs.TryGetObject(cell, "Inlet", out IInlet <object> inlet))
                {
                    clickedInlet = inlet;
                }
                if (ui.cellObjs.TryGetObject(cell, "Outlet", out IOutlet <object> outlet))
                {
                    clickedOutlet = outlet;
                }
                if (ui.cellObjs.TryGetObject(cell, "Field", out FieldInfo field))
                {
                    clickedField = field;
                }

                if (clickedGen != null && clickedOutlet == null && clickedGen is IOutlet <object> o)
                {
                    clickedOutlet = o;
                }
                //assigning outlet if clicked on single-outlet gen
            }

            //checking links
            float minDist = 10 / ui.scrollZoom.zoom;           //10 pixels is max dist to link

            foreach (var kvp in GraphWindow.current.graph.links)
            {
                float dist = GeneratorDraw.DistToLink(mousePos, kvp.Value, kvp.Key);
                if (dist < minDist)
                {
                    minDist = dist; clickedLink = kvp.Key;
                }
            }

            return(clickedGroup != null || clickedGen != null || clickedLayer != null || clickedLink != null || clickedInlet != null || clickedOutlet != null || clickedField != null);
        }