<commit_before>﻿using ImGuiNET;
using OpenKh.Engine.Extensions;
using OpenKh.Engine.Renders;
using OpenKh.Tools.LayoutEditor.Interfaces;
using OpenKh.Tools.LayoutEditor.Models;
using System;
using System.Numerics;

namespace OpenKh.Tools.LayoutEditor.Dialogs
{
    class SpriteEditDialog : IDisposable
    {
        private readonly SpriteModel _spriteModel;
        private readonly ISpriteDrawing _spriteDrawing;
        private readonly ISpriteTexture _atlasTexture;
        private readonly ITextureBinder _textureBinder;
        private readonly IEditorSettings _settings;
        private readonly ISpriteTexture _cropAtlasTexture;
        private readonly IntPtr _cropAtlasTextureId;

        public SpriteEditDialog(
            SpriteModel spriteModel,
            ISpriteDrawing spriteDrawing,
            ISpriteTexture atlasTexture,
            ITextureBinder textureBinder,
            IEditorSettings settings)
        {
            _spriteModel = spriteModel;
            _spriteDrawing = spriteDrawing;
            _atlasTexture = atlasTexture;
            _textureBinder = textureBinder;
            _settings = settings;
            _settings.OnChangeBackground += (o, e) => DrawCropAtlasTexture();

            _cropAtlasTexture = _spriteDrawing.CreateSpriteTexture(atlasTexture.Width, atlasTexture.Height);
            _cropAtlasTextureId = _textureBinder.BindTexture(_cropAtlasTexture);
            DrawCropAtlasTexture();
        }

        public void Dispose()
        {
            if (_cropAtlasTextureId != IntPtr.Zero)
                _textureBinder.UnbindTexture(_cropAtlasTextureId);
            _cropAtlasTexture?.Dispose();
        }

        public void Run()
        {
            ImGui.Image(_cropAtlasTextureId, new Vector2(_atlasTexture.Width, _atlasTexture.Height));

            var source = new int[]
            {
                _spriteModel.Sprite.Left, _spriteModel.Sprite.Top,
                _spriteModel.Sprite.Right, _spriteModel.Sprite.Bottom
            };
            if (ImGui.DragInt4("Source", ref source[0]))
            {
                _spriteModel.Sprite.Left = source[0];
                _spriteModel.Sprite.Top = source[1];
                _spriteModel.Sprite.Right = source[2];
                _spriteModel.Sprite.Bottom = source[3];
                _spriteModel.SizeChanged();
                DrawCropAtlasTexture();
            }

            var colorTopLeft = Utilities.ConvertColor(_spriteModel.Sprite.ColorLeft);
            if (ImGui.ColorEdit4("Top left", ref colorTopLeft))
                _spriteModel.Sprite.ColorLeft = Utilities.ConvertColor(colorTopLeft);

            var colorTopRight = Utilities.ConvertColor(_spriteModel.Sprite.ColorTop);
            if (ImGui.ColorEdit4("Top right", ref colorTopRight))
                _spriteModel.Sprite.ColorTop = Utilities.ConvertColor(colorTopRight);

            var colorBottomLeft = Utilities.ConvertColor(_spriteModel.Sprite.ColorRight);
            if (ImGui.ColorEdit4("Bottom left", ref colorBottomLeft))
                _spriteModel.Sprite.ColorRight = Utilities.ConvertColor(colorBottomLeft);

            var colorBottomRight = Utilities.ConvertColor(_spriteModel.Sprite.ColorBottom);
            if (ImGui.ColorEdit4("Bottom right", ref colorBottomRight))
                _spriteModel.Sprite.ColorBottom = Utilities.ConvertColor(colorBottomRight);

            var uvAnim = new Vector2(_spriteModel.Sprite.UTranslation, _spriteModel.Sprite.VTranslation);
            if (ImGui.DragFloat2("UV animation", ref uvAnim, 0.0001f))
            {
                _spriteModel.Sprite.UTranslation = uvAnim.X;
                _spriteModel.Sprite.VTranslation = uvAnim.Y;
            }

            var unknown00 = _spriteModel.Sprite.Unknown00;
            if (ImGui.DragInt("Unknown00", ref unknown00))
                _spriteModel.Sprite.Unknown00 = unknown00;
<commit_msg>Change labels on sprite edit dialog<commit_after>﻿using ImGuiNET;
using OpenKh.Engine.Extensions;
using OpenKh.Engine.Renders;
using OpenKh.Kh2;
using OpenKh.Tools.LayoutEditor.Interfaces;
using OpenKh.Tools.LayoutEditor.Models;
using System;
using System.Numerics;

namespace OpenKh.Tools.LayoutEditor.Dialogs
{
    class SpriteEditDialog : IDisposable
    {
        private readonly SpriteModel _spriteModel;
        private readonly ISpriteDrawing _spriteDrawing;
        private readonly ISpriteTexture _atlasTexture;
        private readonly ITextureBinder _textureBinder;
        private readonly IEditorSettings _settings;
        private readonly ISpriteTexture _cropAtlasTexture;
        private readonly IntPtr _cropAtlasTextureId;

        public SpriteEditDialog(
            SpriteModel spriteModel,
            ISpriteDrawing spriteDrawing,
            ISpriteTexture atlasTexture,
            ITextureBinder textureBinder,
            IEditorSettings settings)
        {
            _spriteModel = spriteModel;
            _spriteDrawing = spriteDrawing;
            _atlasTexture = atlasTexture;
            _textureBinder = textureBinder;
            _settings = settings;
            _settings.OnChangeBackground += (o, e) => DrawCropAtlasTexture();

            _cropAtlasTexture = _spriteDrawing.CreateSpriteTexture(atlasTexture.Width, atlasTexture.Height);
            _cropAtlasTextureId = _textureBinder.BindTexture(_cropAtlasTexture);
            DrawCropAtlasTexture();
        }

        public void Dispose()
        {
            if (_cropAtlasTextureId != IntPtr.Zero)
                _textureBinder.UnbindTexture(_cropAtlasTextureId);
            _cropAtlasTexture?.Dispose();
        }

        public void Run()
        {
            ImGui.Image(_cropAtlasTextureId, new Vector2(_atlasTexture.Width, _atlasTexture.Height));

            var source = new int[]
            {
                _spriteModel.Sprite.Left, _spriteModel.Sprite.Top,
                _spriteModel.Sprite.Right, _spriteModel.Sprite.Bottom
            };

            ImGui.Columns(4);
            bool sourceChanged = ImGui.DragInt("UA", ref source[0]); ImGui.NextColumn();
            sourceChanged |= ImGui.DragInt("VA", ref source[1]); ImGui.NextColumn();
            sourceChanged |= ImGui.DragInt("UB", ref source[2]); ImGui.NextColumn();
            sourceChanged |= ImGui.DragInt("VB", ref source[3]);
            if (sourceChanged)
            {
                _spriteModel.Sprite.Left = source[0];
                _spriteModel.Sprite.Top = source[1];
                _spriteModel.Sprite.Right = source[2];
                _spriteModel.Sprite.Bottom = source[3];
                _spriteModel.SizeChanged();
                DrawCropAtlasTexture();
            }
            ImGui.Columns(1);

            var colorTopLeft = Utilities.ConvertColor(_spriteModel.Sprite.ColorLeft);
            if (ImGui.ColorEdit4("Top left", ref colorTopLeft))
                _spriteModel.Sprite.ColorLeft = Utilities.ConvertColor(colorTopLeft);

            var colorTopRight = Utilities.ConvertColor(_spriteModel.Sprite.ColorTop);
            if (ImGui.ColorEdit4("Top right", ref colorTopRight))
                _spriteModel.Sprite.ColorTop = Utilities.ConvertColor(colorTopRight);

            var colorBottomLeft = Utilities.ConvertColor(_spriteModel.Sprite.ColorRight);
            if (ImGui.ColorEdit4("Bottom left", ref colorBottomLeft))
                _spriteModel.Sprite.ColorRight = Utilities.ConvertColor(colorBottomLeft);

            var colorBottomRight = Utilities.ConvertColor(_spriteModel.Sprite.ColorBottom);
            if (ImGui.ColorEdit4("Bottom right", ref colorBottomRight))
                _spriteModel.Sprite.ColorBottom = Utilities.ConvertColor(colorBottomRight);

            var uvAnim = new Vector2(_spriteModel.Sprite.UTranslation, _spriteModel.Sprite.VTranslation);
            if (ImGui.DragFloat2("UV animation", ref uvAnim, 0.0001f))
            {
                _spriteModel.Sprite.UTranslation = uvAnim.X;
                _spriteModel.Sprite.VTranslation = uvAnim.Y;
            }

            var unknown00 = _spriteModel.Sprite.Unknown00;
            if (ImGui.DragInt("Unknown00", ref unknown00))
                _spriteModel.Sprite.Unknown00 = unknown00;

{'fraction_non_alphanumeric': 0.08169495664916351, 'fraction_numerical': 0.007937477103431432, 'mean_word_length': 2.3927091963545983, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5320600', 'n_tokens_mistral': 2253, 'n_tokens_neox': 2215, 'n_words': 387}