Example #1
0
        void DrawCreateEntityPopup()
        {
            if (ImGui.BeginPopup("create-entity"))
            {
                ImGui.Text("New Entity Name:");
                ImGui.InputText("##newEntityName", ref _newEntityName, 25);

                if (ImGui.Button("Cancel"))
                {
                    _newEntityName = "";
                    ImGui.CloseCurrentPopup();
                }

                ImGui.SameLine(ImGui.GetContentRegionAvail().X - ImGui.GetItemRectSize().X);

                ImGui.PushStyleColor(ImGuiCol.Button, Microsoft.Xna.Framework.Color.Green.PackedValue);
                if (ImGui.Button("Create"))
                {
                    _newEntityName = _newEntityName.Length > 0 ? _newEntityName : Utils.RandomString(8);
                    var newEntity = new ECEntity(_newEntityName);
                    newEntity.Transform.Position = CastScene.Camera.Transform.Position;
                    CastScene.AddEntity(newEntity);

                    _newEntityName = "";
                    ImGui.CloseCurrentPopup();
                }

                ImGui.PopStyleColor();
            }
        }
Example #2
0
        public EntityInspector(ECEntity entity)
        {
            Entity = entity;
            _transformInspector = new TransformInspector(Entity.Transform);

            for (var i = 0; i < entity.Components.Count; i++)
            {
                _componentInspectors.Add(new ComponentInspector(entity.Components[i]));
            }
        }
Example #3
0
        void DrawEntityContextMenuPopup(ECEntity entity)
        {
            if (ImGui.BeginPopup("entityContextMenu"))
            {
                if (ImGui.Selectable("Clone Entity " + entity.Name))
                {
                    var clone = entity.Clone(CastScene.Camera.Position);
                    entity.Scene.AddEntity(clone);
                }

                if (ImGui.Selectable("Destroy Entity"))
                {
                    entity.Destroy();
                }

                if (ImGui.Selectable("Create Child Entity", false, ImGuiSelectableFlags.DontClosePopups))
                {
                    ImGui.OpenPopup("create-new-entity");
                }

                if (ImGui.BeginPopup("create-new-entity"))
                {
                    ImGui.Text("New Entity Name:");
                    ImGui.InputText("##newChildEntityName", ref _newEntityName, 25);

                    if (ImGui.Button("Cancel"))
                    {
                        _newEntityName = "";
                        ImGui.CloseCurrentPopup();
                    }

                    ImGui.SameLine(ImGui.GetContentRegionAvail().X - ImGui.GetItemRectSize().X);

                    ImGui.PushStyleColor(ImGuiCol.Button, Microsoft.Xna.Framework.Color.Green.PackedValue);
                    if (ImGui.Button("Create"))
                    {
                        _newEntityName = _newEntityName.Length > 0 ? _newEntityName : Utils.RandomString(8);
                        var newEntity = new ECEntity(_newEntityName);
                        newEntity.Transform.SetParent(entity.Transform);
                        entity.Scene.AddEntity(newEntity);

                        _newEntityName = "";
                        ImGui.CloseCurrentPopup();
                    }

                    ImGui.PopStyleColor();

                    ImGui.EndPopup();
                }

                ImGui.EndPopup();
            }
        }
Example #4
0
 /// <summary>
 /// removes the EntityInspector for this Entity
 /// </summary>
 /// <param name="entity"></param>
 public void StopInspectingEntity(ECEntity entity)
 {
     for (var i = 0; i < _entityInspectors.Count; i++)
     {
         var inspector = _entityInspectors[i];
         if (inspector.Entity == entity)
         {
             _entityInspectors.RemoveAt(i);
             return;
         }
     }
 }
Example #5
0
        void DrawEntity(ECEntity entity, bool onlyDrawRoots = true)
        {
            if (onlyDrawRoots && entity.Transform.Parent != null)
            {
                return;
            }

            ImGui.PushID((int)entity.Id);
            bool treeNodeOpened;

            if (entity.Transform.ChildCount > 0)
            {
                treeNodeOpened = ImGui.TreeNodeEx($"{entity.Name} ({entity.Transform.ChildCount})###{entity.Id}",
                                                  ImGuiTreeNodeFlags.OpenOnArrow);
            }
            else
            {
                treeNodeOpened = ImGui.TreeNodeEx($"{entity.Name} ({entity.Transform.ChildCount})###{entity.Id}",
                                                  ImGuiTreeNodeFlags.Leaf | ImGuiTreeNodeFlags.OpenOnArrow);
            }

            NezImGui.ShowContextMenuTooltip();

            // context menu for entity commands
            ImGui.OpenPopupOnItemClick("entityContextMenu", ImGuiMouseButton.Right);
            DrawEntityContextMenuPopup(entity);

            // we are looking for a double-click that is not on the arrow
            if (ImGui.IsMouseDoubleClicked(0) && ImGui.IsItemClicked() &&
                (ImGui.GetMousePos().X - ImGui.GetItemRectMin().X) > ImGui.GetTreeNodeToLabelSpacing())
            {
                Core.GetGlobalManager <ImGuiManager>().StartInspectingEntity(entity);
            }

            if (treeNodeOpened)
            {
                for (var i = 0; i < entity.Transform.ChildCount; i++)
                {
                    DrawEntity(entity.Transform.GetChild(i).Entity, false);
                }

                ImGui.TreePop();
            }

            ImGui.PopID();
        }
Example #6
0
        /// <summary>
        /// creates an EntityInspector window
        /// </summary>
        /// <param name="entity"></param>
        public void StartInspectingEntity(ECEntity entity)
        {
            // if we are already inspecting the Entity focus the window
            foreach (var inspector in _entityInspectors)
            {
                if (inspector.Entity == entity)
                {
                    inspector.SetWindowFocus();
                    return;
                }
            }

            var entityInspector = new EntityInspector(entity);

            entityInspector.SetWindowFocus();
            _entityInspectors.Add(entityInspector);
        }
Example #7
0
 public virtual void OnEntitySubmitted(OgmoEntity entity, ECEntity output)
 {
 }