Example #1
0
        static void SaveClearComponentGroup(EntityAdmin admin, ComponentGroup compGroup, bool save, bool clear)
        {
            List <Component> components = clear ? new List <Component>() : null;
            var json = Serialization.SerializationHelper.Serialize(compGroup, components);

            if (save)
            {
                Directory.CreateDirectory(ComponentGroup.ROOT_PATH);
                FileLoader.SaveTextFile(compGroup.ComponentGroupPath, json);
            }
            if (clear)
            {
                foreach (var component in components)
                {
                    admin.RemoveComponent(component);
                }
            }
        }
Example #2
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();
        }