예제 #1
0
        private void UpdateSelection(object selected)
        {
            InputHandler.ClearSelection();

            if (selected == InputHandler.CurrentSelectedObject)
            {
                InputHandler.CurrentSelectedObject = null;
            }
            else
            {
                if (selected is Manipulator manipulator)
                {
                    InputHandler.AddSelection(manipulator.Joints.Select(joint => joint.Collider.Body));
                    InputHandler.AddSelection(manipulator.Links.Select(link => link.Collider.Body));
                }
                else if (selected is Joint joint)
                {
                    InputHandler.AddSelection(joint.Collider.Body);
                }
                else if (selected is Link link)
                {
                    InputHandler.AddSelection(link.Collider.Body);
                }
                else if (selected is Obstacle obstacle)
                {
                    InputHandler.AddSelection(obstacle.Collider.Body);
                }

                InputHandler.CurrentSelectedObject = selected;
                SwapPropertiesWindows();
            }
        }
예제 #2
0
        private void RenderObstaclesWindow()
        {
            // obstacles window
            if (ImGui.Begin("Obstacles",
                            ImGuiWindowFlags.NoCollapse |
                            ImGuiWindowFlags.NoMove |
                            ImGuiWindowFlags.NoResize |
                            ImGuiWindowFlags.HorizontalScrollbar))
            {
                ImGui.SetWindowPos(new System.Numerics.Vector2(0, (int)(0.5 * (Window.Size.Y - 19) + 19)));
                ImGui.SetWindowSize(new System.Numerics.Vector2((int)(0.25 * Window.Size.X - 2), (int)(0.5 * (Window.Size.Y - 19))));

                if (ImGui.Button("Create"))
                {
                    ImGui.OpenPopup("ObstacleCreate");
                }

                ImGui.SameLine();

                if (ImGui.Button("Remove"))
                {
                    if (InputHandler.CurrentSelectedObject is Obstacle obstacle)
                    {
                        ObstacleHandler.Remove(obstacle);
                        InputHandler.ClearSelection();
                    }
                }

                if (ImGui.BeginPopup("ObstacleCreate"))
                {
                    foreach (var shape in ObstacleHandler.Shapes)
                    {
                        if (ImGui.Selectable(shape))
                        {
                            var shapeValue = (ObstacleShape)Enum.Parse(typeof(ObstacleShape), shape);
                            ObstacleHandler.AddDefault(shapeValue);

                            ImGui.CloseCurrentPopup();
                        }
                    }

                    ImGui.EndPopup();
                }

                ImGui.Separator();

                ImGui.PushStyleVar(ImGuiStyleVar.ChildRounding, 5);
                if (ImGui.BeginChild("ObstacleList", ImGui.GetContentRegionAvail(), true))
                {
                    if (ObstacleHandler.Count != 0)
                    {
                        for (int i = 0; i < ObstacleHandler.Count; i++)
                        {
                            var obstacle = ObstacleHandler.Obstacles[i];
                            ImGui.TreeNodeEx($"Obstacle {i}", _baseTreeLeafFlags | GetTreeNodeSelectionFlag(obstacle));
                            if (ImGui.IsItemDeactivated())
                            {
                                UpdateSelection(obstacle);
                            }
                        }
                    }
                    else
                    {
                        ImGui.Text("Empty.");
                    }

                    ImGui.EndChild();
                }

                ImGui.End();
            }
        }