Пример #1
0
    public override void SubmitUI(Editor arg)
    {
        if (Raylib.IsMouseButtonPressed(MouseButton.MOUSE_BUTTON_RIGHT))
        {
            Vector2 clickedPos = arg.GetWorldMousePos().SnapToGrid();

            arg.OpenContextMenu("test", () =>
            {
                if (ImGui.MenuItem("Create Wire"))
                {
                    arg.FirstClickedWireNode = node;
                    arg.FirstClickedWire     = wire;
                    this.GoToState <ESCreateWireFromWireNode>(0);
                    return(false);
                }

                if (ImGui.MenuItem("Delete Junction", "", false, wire?.Graph.AdjacentDegree(this.node !) == 2 || wire?.Graph.AdjacentDegree(this.node !) == 1))
                {
                    if (wire?.Graph.AdjacentDegree(this.node !) == 2)
                    {
                        CommandDeleteJunction cdj = new CommandDeleteJunction(clickedPos);
                        arg.Execute(cdj, arg);
                    }
                    else
                    {
                        Edge <WireNode> edge          = wire.Graph.AdjacentEdges(this.node !).First();
                        CommandDeleteWireSegment cdws = new CommandDeleteWireSegment(edge.MiddleOfEdge());
                        arg.Execute(cdws, arg);
                    }


                    return(false);
                }
Пример #2
0
    public override void Update(Editor arg)
    {
        if (arg.Simulator.TryGetJunctionFromPosition(arg.GetWorldMousePos(), out JunctionWireNode? jwn, out Wire? nodeOnWire))
        {
            this.GoToState <ESHoveringJunctionNode>(0);
        }

        if (!arg.Simulator.TryGetEdgeFromPosition(arg.GetWorldMousePos(), out Edge <WireNode>?e, out Wire? w))
        {
            this.GoToState <ESNone>(0);
        }
        else
        {
            if (Raylib.IsMouseButtonPressed(MouseButton.MOUSE_BUTTON_RIGHT))
            {
                Vector2 clickedMousePos = arg.GetWorldMousePos().SnapToGrid();

                arg.OpenContextMenu("test", () =>
                {
                    if (ImGui.MenuItem("Delete Segment"))
                    {
                        CommandDeleteWireSegment cdws = new CommandDeleteWireSegment(clickedMousePos);
                        arg.Execute(cdws, arg);

                        return(false);
                    }
                    if (ImGui.MenuItem("Add Junction"))
                    {
                        CommandAddJunction caj = new CommandAddJunction(edge.Source.GetPosition(), edge.Target.GetPosition(), clickedMousePos);
                        arg.Execute(caj, arg);

                        return(false);
                    }
                    if (ImGui.MenuItem("Delete Wire"))
                    {
                        CommandDeleteWire cdw = new CommandDeleteWire(clickedMousePos);
                        arg.Execute(cdw, arg);
                        return(false);
                    }

                    return(true);
                });
            }
        }
    }