Example #1
0
        private void RenderCurrentAnimationSettings()
        {
            if (AnimController == null)
            {
                if (ImGui.Button("Create Controller"))
                {
                    AnimController = new AnimationController(Animation);
                    AnimController.AddAnimation(new AnimationNode("Default")
                    {
                        EndingFrame = Animation.EndingFrame,
                        StartingFrame = Animation.StartingFrame,
                        LoopType = Animation.LoopType
                    });
                }

                int frameTime = Animation.TimeBetweenFrames;
                if (ImGui.InputInt("MS Between Frames", ref frameTime))
                {
                    Animation.TimeBetweenFrames = frameTime;
                    Animation.Reset();
                }

                ImGui.Text("Starting and ending frames are 0 indexed and inclusive.");

                int startingFrame = Animation.StartingFrame;
                if (ImGui.InputInt("Starting Frame", ref startingFrame))
                {
                    Animation.StartingFrame = startingFrame;
                    Animation.Reset();
                }

                int endingFrame = Animation.EndingFrame;
                if (ImGui.InputInt("Ending Frame", ref endingFrame))
                {
                    Animation.EndingFrame = endingFrame;
                    Animation.Reset();
                }

                var loopType = (int) Animation.LoopType;
                if (ImGui.Combo("Loop Type", ref loopType, string.Join('\0', Enum.GetNames(typeof(AnimationLoopType)))))
                {
                    Animation.LoopType = (AnimationLoopType) loopType;
                    Animation.Reset();
                }
            }
            else
            {
                ImGui.Text("Animations");
                ImGui.PushID("animList");
                foreach (AnimationNode n in AnimController.Animations.Values)
                {
                    bool activeOverlay = _overlayAnimation == n;
                    ImGui.PushID(n.Name);
                    if (n == AnimController.CurrentAnimation)
                    {
                        ImGui.Text(n.Name);
                    }
                    else
                    {
                        if (ImGui.Button(n.Name)) AnimController.SetAnimation(n.Name);
                    }

                    ImGui.SameLine();
                    ImGui.Text($"({n.StartingFrame}-{n.EndingFrame})");
                    ImGui.SameLine();
                    if (ImGui.Checkbox("Overlay", ref activeOverlay)) _overlayAnimation = activeOverlay ? n : null;
                    ImGui.PopID();
                }

                bool enableShortcuts = !ImGui.IsAnyItemActive();
                if (ImGui.Button("(C)reate") || enableShortcuts && Engine.Host.IsKeyDown(Key.C) && AnimController.Animations.All(x => x.Key != "NewAnim"))
                {
                    var newNode = new AnimationNode("NewAnim");
                    AnimController.AddAnimation(newNode);
                    AnimController.SetAnimation(newNode.Name);
                }

                ImGui.SameLine();
                if (AnimController.CurrentAnimation == null)
                {
                    ImGui.PopID();
                    return;
                }

                if (ImGui.Button("Remove")) AnimController.RemoveAnimation(AnimController.CurrentAnimation.Name);
                ImGui.SameLine();
                if (ImGui.Button("(R)ename") || enableShortcuts && Engine.Host.IsKeyDown(Key.R))
                {
                    var newName = new StringInputModal(s =>
                        {
                            AnimController.CurrentAnimation.Name = s;
                            AnimController.Reindex();
                        },
                        $"New name for {AnimController.CurrentAnimation.Name}");
                    Parent.AddWindow(newName);
                }

                ImGui.PopID();

                AnimationNode cur = AnimController.CurrentAnimation;
                var modified = false;

                int frameTime = cur.TimeBetweenFrames;
                if (ImGui.InputInt("MS Between Frames", ref frameTime))
                {
                    cur.TimeBetweenFrames = frameTime;
                    modified = true;
                }

                ImGui.Text("Starting and ending frames are 0 indexed and inclusive.");

                int startingFrame = cur.StartingFrame;
                if (ImGui.InputInt("Starting Frame", ref startingFrame))
                {
                    cur.StartingFrame = startingFrame;
                    modified = true;
                }

                int endingFrame = cur.EndingFrame;
                if (ImGui.InputInt("Ending Frame", ref endingFrame))
                {
                    cur.EndingFrame = endingFrame;
                    modified = true;
                }

                var loopType = (int) cur.LoopType;
                if (ImGui.Combo("Loop Type", ref loopType, string.Join('\0', Enum.GetNames(typeof(AnimationLoopType)))))
                {
                    cur.LoopType = (AnimationLoopType) loopType;
                    modified = true;
                }

                if (modified) AnimController.SetAnimation(cur.Name, true);
            }
        }
Example #2
0
        private void RenderCurrentAnimationSettings()
        {
            if (_animController == null)
            {
                if (ImGui.Button("Create Controller"))
                {
                    _animController = new AnimationController(_animation);
                    _animController.AddAnimation(new AnimationNode("Default")
                    {
                        EndingFrame   = _animation.EndingFrame,
                        StartingFrame = _animation.StartingFrame,
                        LoopType      = _animation.LoopType
                    });
                }

                int frameTime = _animation.TimeBetweenFrames;
                ImGui.InputInt("MS Between Frames", ref frameTime);
                if (frameTime != _animation.TimeBetweenFrames)
                {
                    _animation.TimeBetweenFrames = frameTime;
                }

                int startingFrame = _animation.StartingFrame;
                ImGui.InputInt("Starting Frame", ref startingFrame);
                if (startingFrame != _animation.StartingFrame)
                {
                    _animation.StartingFrame = startingFrame;
                }

                int endingFrame = _animation.EndingFrame;
                ImGui.InputInt("Ending Frame", ref endingFrame);
                if (endingFrame != _animation.EndingFrame)
                {
                    _animation.EndingFrame = endingFrame;
                }

                var loopType = (int)_animation.LoopType;
                ImGui.Combo("Loop Type", ref loopType, string.Join('\0', Enum.GetNames(typeof(AnimationLoopType))));
                if ((AnimationLoopType)loopType != _animation.LoopType)
                {
                    _animation.LoopType = (AnimationLoopType)loopType;
                    _animation.Reset();
                }
            }
            else
            {
                ImGui.Text("Animations");
                ImGui.PushID("animList");
                foreach (AnimationNode n in _animController.Animations.Values)
                {
                    if (n == _animController.CurrentAnimation)
                    {
                        ImGui.Text(n.Name);
                    }
                    else
                    {
                        if (ImGui.Button(n.Name))
                        {
                            _animController.SetAnimation(n.Name);
                        }
                    }
                }

                if (ImGui.Button("Create") && _animController.Animations.All(x => x.Key != "NewAnim"))
                {
                    var newNode = new AnimationNode("NewAnim");
                    _animController.AddAnimation(newNode);
                }

                ImGui.SameLine();
                if (_animController.CurrentAnimation == null)
                {
                    ImGui.PopID();
                    return;
                }

                if (ImGui.Button("Remove"))
                {
                    _animController.RemoveAnimation(_animController.CurrentAnimation.Name);
                }
                ImGui.SameLine();
                if (ImGui.Button("Rename"))
                {
                    var newName = new StringInputModal(s =>
                    {
                        _animController.CurrentAnimation.Name = s;
                        _animController.Reindex();
                    },
                                                       $"New name for {_animController.CurrentAnimation.Name}");
                    Parent.AddWindow(newName);
                }

                ImGui.PopID();

                AnimationNode cur      = _animController.CurrentAnimation;
                var           modified = false;

                int frameTime = cur.TimeBetweenFrames;
                ImGui.InputInt("MS Between Frames", ref frameTime);
                if (frameTime != cur.TimeBetweenFrames)
                {
                    cur.TimeBetweenFrames = frameTime;
                    modified = true;
                }

                int startingFrame = cur.StartingFrame;
                ImGui.InputInt("Starting Frame", ref startingFrame);
                if (startingFrame != cur.StartingFrame)
                {
                    cur.StartingFrame = startingFrame;
                    modified          = true;
                }

                int endingFrame = cur.EndingFrame;
                ImGui.InputInt("Ending Frame", ref endingFrame);
                if (endingFrame != cur.EndingFrame)
                {
                    cur.EndingFrame = endingFrame;
                    modified        = true;
                }

                var loopType = (int)cur.LoopType;
                ImGui.Combo("Loop Type", ref loopType, string.Join('\0', Enum.GetNames(typeof(AnimationLoopType))));
                if ((AnimationLoopType)loopType != cur.LoopType)
                {
                    cur.LoopType = (AnimationLoopType)loopType;
                    modified     = true;
                }

                if (modified)
                {
                    _animController.SetAnimation(cur.Name);
                }
            }
        }