示例#1
0
        private static unsafe void SubmitInspectorWindow(EntityAdmin admin)
        {
            ImGui.Begin("Inspector");

            if (ImGui.Checkbox("Lock", ref inspectorLocked))
            {
                lockedInspectorEntityComponent = inspectorLocked ? SelectedEntityComponent : null;
            }

            object selectedObject = inspectorLocked ? lockedInspectorEntityComponent : SelectedEntityComponent;


            if (selectedObject != null)
            {
                var entity    = selectedObject as Entity;
                var component = selectedObject as Component;

                if (entity != null)
                {
                    ImGui.PushFont(ImGuiController.BoldFont);
                    ImGui.Text("Entity: " + entity.Name);
                    ImGui.PopFont();

                    ImGui.Separator();
                    Type componentType;
                    if (SubmitAddComponent("Add Component", out componentType))
                    {
                        selectedObject = admin.AddComponent(entity, componentType);
                        entity         = null;
                        component      = selectedObject as Component;
                    }
                }

                if (component != null)
                {
                    ImGui.PushFont(ImGuiController.BoldFont);
                    ImGui.Text("Entity: " + component.Entity.Name);
                    ImGui.Text("Component: " + component.Name);
                    ImGui.PopFont();

                    if (ImGui.Button("Remove Component"))
                    {
                        admin.RemoveComponent(component);
                    }

                    Type missingSystem;
                    bool hasRequiredSystems = RequiresSystem.HasECSSystemForType(component.GetType(), HostHelper.GameSystems, out missingSystem);
                    if (!hasRequiredSystems)
                    {
                        ImGui.Separator();
                        ImGui.NewLine();
                        ImGui.PushStyleColor(ImGuiCol.Text, new Vector4(1f, 0f, 0f, 1f));
                        ImGui.PushFont(ImGuiController.BoldFont);
                        ImGui.Text("ERROR: MISSING REQUIRED SYSTEM " + missingSystem);
                        ImGui.PopFont();
                        ImGui.PopStyleColor();
                        ImGui.NewLine();
                    }
                }

                ImGui.Separator();
                ImGui.BeginChild("scrolling", Vector2.Zero, false, ImGuiWindowFlags.HorizontalScrollbar);

                SubmitObjectInspector(selectedObject);

                ComponentGroup compGroup = selectedObject as ComponentGroup;
                if (compGroup != null)
                {
                    ImGui.NewLine();
                    ImGui.Separator();

                    ImGui.PushFont(ImGuiController.BoldFont);
                    ImGui.Text($"Component Group: {compGroup.FileName}");
                    ImGui.PopFont();
                    if (!string.IsNullOrWhiteSpace(compGroup.FileName))
                    {
                        if (ImGui.Button("Save"))
                        {
                            SaveClearComponentGroup(admin, compGroup, true, false);
                        }
                        if (ImGui.Button("Save & Clear from Scene"))
                        {
                            SaveClearComponentGroup(admin, compGroup, true, true);
                        }
                        if (ImGui.Button("Clear Without Saving"))
                        {
                            SaveClearComponentGroup(admin, compGroup, false, true);
                        }
                    }
                    else
                    {
                        ImGui.Text("(Please set file name to reveal saving functionality.)");
                    }
                }
            }

            ImGui.End();
        }
示例#2
0
        private static unsafe void SubmitEntitiesWindow(EntityAdmin admin, Dictionary <Entity, List <int> > entityToComponentGroups)
        {
            ImGui.Begin("Entities and Components");

            bool createEntity = SubmitAddComponent("Create Entity", out Type componentType);

            Entity entityToDestroy = SelectedEntityComponent as Entity;
            bool   disabled        = entityToDestroy == null;

            if (disabled)
            {
                Util.ImGuiUtil.BeginDisable();
            }
            if (ImGui.Button("Destroy Entity") && !disabled)
            {
                admin.DestroyEntity(entityToDestroy);
            }
            if (disabled)
            {
                Util.ImGuiUtil.EndDisable();
            }

            ImGui.Separator();
            ImGui.BeginChild("scrolling", Vector2.Zero, false, ImGuiWindowFlags.HorizontalScrollbar);

            var entities = EntityAdminUtil.GetEntities(admin);

            foreach (var entity in entities)
            {
                var components = entity.Components;

                ImGuiTreeNodeFlags nodeFlags = ImGuiTreeNodeFlags.OpenOnArrow | ImGuiTreeNodeFlags.OpenOnDoubleClick | ImGuiTreeNodeFlags.SpanAvailWidth; // OpenOnDoubleClick doesn't seem to work. Not sure why.
                if (entity.Components.Count == 0)
                {
                    nodeFlags |= ImGuiTreeNodeFlags.Leaf;
                }
                if (entity == SelectedEntityComponent)
                {
                    nodeFlags |= ImGuiTreeNodeFlags.Selected;
                    if (scrollEntitiesView)
                    {
                        ImGui.SetScrollHereY();
                    }
                }

                if (entity.HasComponent <DontDestroyOnClear>(true))
                {
                    ImGui.PushFont(ImGuiController.BoldFont);
                }
                if (!entity.IsActive)
                {
                    ImGui.PushStyleColor(ImGuiCol.Text, new Vector4(0.5f, 0.5f, 0.5f, 1f));
                }
                bool errorInEntity = false;
                for (int i = 0; i < components.Count; i++)
                {
                    if (!RequiresSystem.HasECSSystemForType(components[i].GetType(), HostHelper.GameSystems, out _))
                    {
                        errorInEntity = true;
                    }
                    if (components[i] == SelectedEntityComponent)
                    {
                        ImGui.SetNextItemOpen(true);
                    }
                }
                string componentGroupsText = string.Empty;
                if (entityToComponentGroups.ContainsKey(entity))
                {
                    foreach (int groupNum in entityToComponentGroups[entity])
                    {
                        componentGroupsText = $"({groupNum}){componentGroupsText}";
                    }
                    if (entityToComponentGroups[entity].Count() > 1)
                    {
                        errorInEntity = true;
                    }
                }
                if (errorInEntity)
                {
                    ImGui.PushStyleColor(ImGuiCol.Text, new Vector4(1f, 0f, 0f, 1f));
                }
                string entityTransformText = !entity.HasComponent <Transform>(true) ? "~ " : "";
                string entityLabelText     = $"{componentGroupsText}{entityTransformText}{entity.Name}";
                bool   expanded            = ImGui.TreeNodeEx(entity.Guid.ToString(), nodeFlags, entityLabelText);
                if (errorInEntity)
                {
                    ImGui.PopStyleColor();
                }
                if (!entity.IsActive)
                {
                    ImGui.PopStyleColor();
                }
                if (entity.HasComponent <DontDestroyOnClear>(true))
                {
                    ImGui.PopFont();
                }

                if (ImGui.IsItemClicked())
                {
                    SelectedEntityComponent = entity;
                    scrollSceneGraphView    = true;
                }

                if (ImGui.BeginDragDropSource())
                {
                    ImGui.SetDragDropPayload(PAYLOAD_STRING, IntPtr.Zero, 0); // Payload is needed to trigger BeginDragDropTarget()
                    draggedObject = entity;
                    ImGui.Text(entity.Name);
                    ImGui.EndDragDropSource();
                }

                if (expanded)
                {
                    for (int i = 0; i < components.Count; i++)
                    {
                        Component component = components[i];
                        nodeFlags = ImGuiTreeNodeFlags.Leaf | ImGuiTreeNodeFlags.SpanAvailWidth | ImGuiTreeNodeFlags.NoTreePushOnOpen; // This last one means that you can't do aImGui.TreePop(); or things will be messed up.
                        if (component == SelectedEntityComponent)
                        {
                            nodeFlags |= ImGuiTreeNodeFlags.Selected;
                            if (scrollEntitiesView)
                            {
                                ImGui.SetScrollHereY();
                            }
                        }
                        if (!component.IsActive)
                        {
                            ImGui.PushStyleColor(ImGuiCol.Text, new Vector4(0.5f, 0.5f, 0.5f, 1f));
                        }
                        bool hasRequiredSystems = RequiresSystem.HasECSSystemForType(component.GetType(), HostHelper.GameSystems, out _);
                        if (!hasRequiredSystems)
                        {
                            ImGui.PushStyleColor(ImGuiCol.Text, new Vector4(1f, 0f, 0f, 1f));
                        }
                        ImGui.TreeNodeEx(component.Guid.ToString(), nodeFlags, component.Name);
                        if (!hasRequiredSystems)
                        {
                            ImGui.PopStyleColor();
                        }
                        if (!component.IsActive)
                        {
                            ImGui.PopStyleColor();
                        }
                        if (ImGui.IsItemClicked())
                        {
                            SelectedEntityComponent = component;
                            scrollSceneGraphView    = true;
                        }
                        if (ImGui.BeginDragDropSource())
                        {
                            ImGui.SetDragDropPayload(PAYLOAD_STRING, IntPtr.Zero, 0); // Payload is needed to trigger BeginDragDropTarget()
                            draggedObject = component;
                            ImGui.Text(component.Name);
                            ImGui.EndDragDropSource();
                        }
                    }
                    ImGui.TreePop();
                }
            }

            scrollEntitiesView = false;
            if (createEntity)
            {
                var entity = admin.CreateEntity($"{componentType.Name}'s Entity");
                SelectedEntityComponent = admin.AddComponent(entity, componentType);
                scrollEntitiesView      = true; // For some reason this doesn't work half the time -_- Not sure why...
            }

            ImGui.End();
        }