예제 #1
0
        private void DrawEntryWindow(Sdl2Window window)
        {
            Vector2 pos = Vector2.One;

            pos.X = 500;
            pos.Y = 18;
            ImGui.SetNextWindowPos(pos, ImGuiCond.Always, Vector2.Zero);
            ImGui.SetNextWindowSize(new Vector2(window.Width - pos.X, window.Height - 18), ImGuiCond.Always);

            if (ImGui.Begin("##entry_window", ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoTitleBar))
            {
                AlfEntry entry = Alf.Entries[SelectedEntry];

                ImGui.Text($"Filename: {entry.Name}");
                ImGui.SameLine();
                ImGui.Text($"   Type: {FormatHelper.GetFileType(entry.Name.End(3))}");

                if (ImGui.Button("Extract"))
                {
                    const string path          = @"Y:\Projekte\Reverse Engineering\NLT\OpenShadows";
                    byte[]       entryContents = entry.GetContents();
                    File.WriteAllBytes(Path.Combine(path, entry.Name), entryContents);
                }

                if (string.Equals(entry.Name.End(3), "AIF", StringComparison.OrdinalIgnoreCase))
                {
                    DrawImageViewer("AIF");
                }
                if (string.Equals(entry.Name.End(3), "NVF", StringComparison.OrdinalIgnoreCase))
                {
                    DrawImageViewer("NVF");
                }
                if (string.Equals(entry.Name.End(3), "ACE", StringComparison.OrdinalIgnoreCase))
                {
                    DrawImageViewer("ACE");
                }

                if (string.Equals(entry.Name.End(3), "LXT", StringComparison.Ordinal))
                {
                    DrawTextViewer("lxt");
                }
                if (string.Equals(entry.Name.End(3), "XDF", StringComparison.Ordinal))
                {
                    DrawTextViewer("xdf");
                }

                ImGui.End();
            }
        }
예제 #2
0
        private void DrawTextureWindow(Sdl2Window window)
        {
            Vector2 pos = Vector2.One;

            pos.X = 500 + 350 - 1;
            pos.Y = 18;
            ImGui.SetNextWindowPos(pos, ImGuiCond.Always, Vector2.Zero);
            ImGui.SetNextWindowSize(new Vector2(window.Width - pos.X, window.Height - 18), ImGuiCond.Always);

            if (ImGui.Begin("##texture_window", ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoTitleBar))
            {
                AlfModule levelModule     = Alf.Modules[SelectedEntry];
                AlfModule textureModule   = Alf.Modules[SelectedEntry + 1];
                AlfEntry  selectedTexture = textureModule.Entries[SelectedTexture];

                ImGui.Text($"Texture: {selectedTexture.Name}");

                if (!HasImage && ImGui.Button("View me"))
                {
                    byte[]  paletteData = levelModule.Entries.Find(e => e.Name.EndsWith("PAL")).GetContents();
                    var     br          = new BinaryReader(new MemoryStream(paletteData));
                    Palette p           = Palette.LoadFromPal(br);

                    byte[]    imageData = selectedTexture.GetContents();
                    ImageData temp      = PixExtractor.ExtractImage(imageData, p);

                    Texture img = Gd.ResourceFactory.CreateTexture(new TextureDescription
                    {
                        Height      = (uint)temp.Height,
                        Width       = (uint)temp.Width,
                        Format      = PixelFormat.R8_G8_B8_A8_UNorm_SRgb,
                        Type        = TextureType.Texture2D,
                        Usage       = TextureUsage.Sampled,
                        MipLevels   = 1,
                        Depth       = 1,
                        ArrayLayers = 1
                    });

                    GCHandle pinnedArray = GCHandle.Alloc(temp.PixelData, GCHandleType.Pinned);
                    IntPtr   pointer     = pinnedArray.AddrOfPinnedObject();

                    Gd.UpdateTexture(img, pointer, (uint)temp.PixelData.Length, 0, 0, 0, (uint)temp.Width, (uint)temp.Height, 1, 0, 0);

                    pinnedArray.Free();

                    CurrentImage = img;
                    HasImage     = true;
                    ZoomFactor   = 1;
                }

                if (HasImage && CurrentImage != null)
                {
                    if (ImGui.Button("Close me"))
                    {
                        HasImage = false;
                        CurrentImage.Dispose();
                    }

                    ImGui.SameLine();

                    if (ImGui.Button("+"))
                    {
                        ZoomFactor++;
                    }

                    ImGui.SameLine();

                    if (ImGui.Button("-"))
                    {
                        ZoomFactor = ZoomFactor == 1 ? 1 : ZoomFactor - 1;
                    }

                    ImGui.Text($"Image Size: {CurrentImage.Width}x{CurrentImage.Height}");

                    ImGui.Image(ImGuiRenderer.GetOrCreateImGuiBinding(Gd.ResourceFactory, CurrentImage), new Vector2(CurrentImage.Width * ZoomFactor, CurrentImage.Height * ZoomFactor));
                }

                ImGui.End();
            }
        }