Пример #1
0
        protected override void RenderContent(RenderComposer composer)
        {
            if (ImGui.Button("Choose File"))
            {
                var explorer = new FileExplorer <TextAsset>(LoadFile);
                Parent.AddWindow(explorer);
            }

            ImGui.Text($"Current File: {_file?.Name ?? "None"}");
            if (_file == null)
            {
                return;
            }
            if (ImGui.Button("Reload"))
            {
                LoadFile(FileExplorer <TextAsset> .ExplorerLoadAsset(_file.Name));
            }

            ImGui.Text("Tile Layers");
            for (var i = 0; i < _map.TiledMap.TileLayers.Count; i++)
            {
                TmxLayer curLayer = _map.TiledMap.TileLayers[i];
                ImGui.Text($"{curLayer.Name} {curLayer.Width}x{curLayer.Height}" + (curLayer.Visible ? "" : " Hidden"));
            }

            composer.SetUseViewMatrix(true);
            composer.Render(_map);
        }
Пример #2
0
        protected override void RenderContent(RenderComposer composer)
        {
            if (ImGui.Button("New From Image"))
            {
                var explorer = new FileExplorer<TextureAsset>(LoadSpriteSheetFile);
                Parent.AddWindow(explorer);
            }

            ImGui.SameLine();

            if (ImGui.Button("Open AnimatedTexture"))
            {
                var explorer = new FileExplorer<XMLAsset<AnimatedTexture>>(LoadAnimatedTexture);
                Parent.AddWindow(explorer);
            }

            ImGui.SameLine();

            if (ImGui.Button("Open AnimationController"))
            {
                var explorer = new FileExplorer<XMLAsset<AnimationController>>(LoadAnimationController);
                Parent.AddWindow(explorer);
            }

            if (_spriteSheetTexture == null) return;
            if (Animation == null)
            {
                ImGui.Text("How are the frames contained in your spritesheet?");

                if (ImGui.Button("Grid"))
                {
                    var win = new AnimationCreateFrom(this, (fs, s) => { Animation = new AnimatedTexture(_spriteSheetTexture, fs, s, AnimationLoopType.Normal, 1000); },
                        (r, c) => { Animation = new AnimatedTexture(_spriteSheetTexture, c, r, AnimationLoopType.Normal, 1000); });
                    Parent.AddWindow(win);
                }

                ImGui.SameLine();

                if (ImGui.Button("Auto Detect Frames"))
                {
                    Rectangle[] frames = AutoDetectFrames(_spriteSheetTexture.Texture);
                    Animation = new AnimatedTexture(_spriteSheetTexture, frames, AnimationLoopType.Normal, 1000);
                }

                return;
            }

            ImGui.Text($"Current File: {_saveName ?? "None"}");
            ImGui.Text($"Texture File: {_spriteSheetTexture.Name} / Resolution: {_spriteSheetTexture.Texture.Size}");

            if (ImGui.Button("Reload Image")) LoadSpriteSheetFile(FileExplorer<TextureAsset>.ExplorerLoadAsset(_spriteSheetTexture.Name));
            ImGui.SameLine();
            if (_playing)
            {
                if (ImGui.Button("Pause"))
                    _playing = false;
            }
            else
            {
                if (ImGui.Button("Play"))
                    _playing = true;
                ImGui.SameLine();
                if (ImGui.Button("<"))
                    Animation.ForceSetFrame(Animation.GetPrevFrameIdx(out bool _, out bool reverse), reverse);
                ImGui.SameLine();
                if (ImGui.Button(">"))
                    Animation.ForceSetFrame(Animation.GetNextFrameIdx(out bool _, out bool reverse), reverse);
            }

            ImGui.Text($"Display Scale: {Scale}");
            ImGui.SameLine();
            if (ImGui.Button("-")) Scale -= 1;
            ImGui.SameLine();
            if (ImGui.Button("+")) Scale += 1;
            ImGui.SameLine();
            if (ImGui.Button($"Mirror (Currently: {(Mirrored ? "Mirrored" : "Not Mirrored")})")) Mirrored = !Mirrored;

            if (ImGui.Button("Place Anchor Points"))
                if (_anchorPlacerWindow == null || !_anchorPlacerWindow.Open)
                    Parent.AddWindow(_anchorPlacerWindow = new AnchorPlacingWindow(this, Animation));

            ImGui.SameLine();
            if (ImGui.Button("Order Frames"))
                if (_orderWindow == null || !_orderWindow.Open)
                    Parent.AddWindow(_orderWindow = new FrameOrderWindow(this, Animation));

            ImGui.SameLine();
            if (ImGui.Button("Redetect Frames"))
            {
                Rectangle[] previousFrames = Animation.Frames;
                Rectangle[] frames = AutoDetectFrames(_spriteSheetTexture.Texture);

                // Try to maintain the old order.
                for (var i = 0; i < frames.Length; i++)
                {
                    for (var old = 0; old < previousFrames.Length; old++)
                    {
                        if (frames[i] != previousFrames[old] || i == old || old >= frames.Length - 1) continue;
                        Rectangle temp = frames[i];
                        frames[i] = frames[old];
                        frames[old] = temp;
                        break;
                    }
                }

                Animation.Frames = frames;
            }

            ImGui.Text($"Current Frame: {Animation.CurrentFrameIndex - Animation.StartingFrame + 1}/{Animation.AnimationFrames + 1} (Total: {Animation.TotalFrames})");
            ImGui.Text($"Current Anchor: {(Animation.Anchors.Length > 0 ? Animation.Anchors[Animation.CurrentFrameIndex].ToString() : "Unknown")}");

            for (var i = 0; i <= Animation.TotalFrames; i++)
            {
                if (i != 0 && i % 10 != 0) ImGui.SameLine(0, 5);

                bool current = Animation.CurrentFrameIndex == i;

                Rectangle frameBounds = Animation.GetFrameBounds(i);
                (Vector2 u1, Vector2 u2) = Animation.Texture.GetImGuiUV(frameBounds);

                ImGui.Image(new IntPtr(Animation.Texture.Pointer), frameBounds.Size / 2f, u1, u2, Vector4.One,
                    current ? new Vector4(1, 0, 0, 1) : new Vector4(0, 0, 0, 1));
            }

            RenderCurrentAnimationSettings();

            RenderSaveSection(composer);
            RenderAnimation(composer);
        }
Пример #3
0
        protected override void RenderContent(RenderComposer composer)
        {
            if (ImGui.Button("New From Image"))
            {
                var explorer = new FileExplorer <TextureAsset>(LoadSpriteSheetFile);
                Parent.AddWindow(explorer);
            }

            ImGui.SameLine();

            if (ImGui.Button("Open AnimatedTexture"))
            {
                var explorer = new FileExplorer <XMLAsset <AnimatedTexture> >(LoadAnimatedTexture);
                Parent.AddWindow(explorer);
            }

            ImGui.SameLine();

            if (ImGui.Button("Open AnimationController"))
            {
                var explorer = new FileExplorer <XMLAsset <AnimationController> >(LoadAnimationController);
                Parent.AddWindow(explorer);
            }

            if (_spriteSheetTexture == null)
            {
                return;
            }
            if (_animation == null)
            {
                ImGui.Text("How are the frames contained in your spritesheet?");

                if (ImGui.Button("Grid"))
                {
                    var win = new GridSettingsWindow(this, (fs, s) => { _animation = new AnimatedTexture(_spriteSheetTexture, fs, s, AnimationLoopType.Normal, 1000); },
                                                     (r, c) => { _animation = new AnimatedTexture(_spriteSheetTexture, c, r, AnimationLoopType.Normal, 1000); });
                    Parent.AddWindow(win);
                }

                ImGui.SameLine();

                if (ImGui.Button("Auto Detect Frames"))
                {
                    Rectangle[] frames = AutoDetectFrames(_spriteSheetTexture.Texture);
                    _animation = new AnimatedTexture(_spriteSheetTexture, frames, AnimationLoopType.Normal, 1000);
                }

                return;
            }

            ImGui.Text($"Current File: {_saveName ?? "None"}");
            ImGui.Text($"Texture File: {_spriteSheetTexture.Name} / Resolution: {_spriteSheetTexture.Texture.Size}");

            if (ImGui.Button("Reload Image"))
            {
                LoadSpriteSheetFile(FileExplorer <TextureAsset> .ExplorerLoadAsset(_spriteSheetTexture.Name));
            }
            if (_playing)
            {
                if (ImGui.Button("Pause"))
                {
                    _playing = false;
                }
            }
            else
            {
                if (ImGui.Button("Play"))
                {
                    _playing = true;
                }
            }

            ImGui.InputInt("Display Scale", ref Scale);
            ImGui.SameLine();
            if (ImGui.Button("Mirror"))
            {
                _mirrored = !_mirrored;
            }

            if (ImGui.Button("Place Anchor Points"))
            {
                if (_anchorPlacerWindow == null || !_anchorPlacerWindow.Open)
                {
                    Parent.AddWindow(_anchorPlacerWindow = new AnchorPlacer(this, _animation));
                }
            }

            if (ImGui.Button("Order Frames"))
            {
                if (_orderWindow == null || !_orderWindow.Open)
                {
                    Parent.AddWindow(_orderWindow = new FrameOrderWindow(this, _animation));
                }
            }

            ImGui.Text($"Current Frame: {_animation.CurrentFrameIndex + 1}/{_animation.AnimationFrames + 1}");
            ImGui.Text($"Current Anchor: {(_animation.Anchors.Length > 0 ? _animation.Anchors[_animation.CurrentFrameIndex].ToString() : "Unknown")}");

            for (var i = 0; i <= _animation.TotalFrames; i++)
            {
                if (i != 0 && i % 5 != 0)
                {
                    ImGui.SameLine(0, 5);
                }

                bool current = _animation.CurrentFrameIndex == i;

                Rectangle frameBounds = _animation.GetFrameBounds(i);
                (Vector2 u1, Vector2 u2) = _animation.Texture.GetImGuiUV(frameBounds);

                ImGui.Image(new IntPtr(_animation.Texture.Pointer), frameBounds.Size / 2f, u1, u2, Vector4.One,
                            current ? new Vector4(1, 0, 0, 1) : Vector4.Zero);
            }

            RenderCurrentAnimationSettings();

            RenderSaveSection();
            RenderAnimation(composer);
        }