<commit_before>﻿using System;
using AGS.API;

namespace AGS.Engine
{
    public class NumberPropertyEditor : IInspectorPropertyEditor
    {
        private readonly IGameFactory _factory;
        private readonly bool _wholeNumbers;
        private const float SLIDER_HEIGHT = 5f;
        private const float ROW_HEIGHT = 20f;

        public NumberPropertyEditor(IGameFactory factory, bool wholeNumbers)
        {
            _factory = factory;
            _wholeNumbers = wholeNumbers;
        }

        public void AddEditorUI(string id, ITreeNodeView view, InspectorProperty property)
        {
            var label = view.TreeItem;

            var textPanel = _factory.UI.GetPanel(id + "_TextPanel", 100f, ROW_HEIGHT, label.X, label.Y, label.TreeNode.Parent);
            textPanel.RenderLayer = label.RenderLayer;
            textPanel.Z = label.Z;
            textPanel.Tint = Colors.Transparent;
            var textbox = addTextBox(id, textPanel, property.Value);
            var numberEditor = textbox.AddComponent<INumberEditorComponent>();
            addSlider(id, textPanel, numberEditor);
            numberEditor.EditWholeNumbersOnly = _wholeNumbers;
            numberEditor.Value = float.Parse(property.Value);
            numberEditor.OnValueChanged.Subscribe(() =>
            {
                if (_wholeNumbers)
                {
                    property.Prop.SetValue(property.Object, (int)Math.Round(numberEditor.Value));
                }
                else property.Prop.SetValue(property.Object, numberEditor.Value);
            });
            addArrowButtons(id, label, numberEditor);
        }

        private ITextBox addTextBox(string id, IUIControl panel, string text)
        {
            AGSTextConfig config = new AGSTextConfig(autoFit: AutoFit.LabelShouldFitText);
            var textbox = _factory.UI.GetTextBox(id + "_Textbox",
                                              0f, SLIDER_HEIGHT + 1f, panel,
                                              text, config, width: 100f, height: ROW_HEIGHT);
            textbox.RenderLayer = panel.RenderLayer;
            textbox.Z = panel.Z;
            HoverEffect.Add(textbox, Colors.Transparent, Colors.DarkSlateBlue);
            return textbox;
        }

        private void addArrowButtons(string id, IUIControl label, 
                                     INumberEditorComponent numberEditor)
        {
            var icons = _factory.Graphics.Icons;
            var arrowUpIdle = icons.GetArrowIcon(ArrowDirection.Up, Colors.White);
            var arrowDownIdle = icons.GetArrowIcon(ArrowDirection.Down, Colors.White);
            var arrowUpHovered = icons.GetArrowIcon(ArrowDirection.Up, Colors.Black);
            var arrowDownHovered = icons.GetArrowIcon(ArrowDirection.Down, Colors.Black);
            var buttonsPanel = _factory.UI.GetPanel(id + "_ButtonsPanel", 1f, 1f, 0f, label.Y, label.TreeNode.Parent);
            buttonsPanel.RenderLayer = label.RenderLayer;
            buttonsPanel.Tint = Colors.Transparent;
            float halfRowHeight = ROW_HEIGHT / 2f;
            float buttonBottomPadding = 4.5f;
            float betweenButtonsPadding = 1f;
            float buttonHeight = halfRowHeight - betweenButtonsPadding * 2;
            var upButton = _factory.UI.GetButton(id + "_UpButton", new ButtonAnimation(arrowUpIdle, null, Colors.Purple),
                                              new ButtonAnimation(arrowUpHovered, null, Colors.Yellow), new ButtonAnimation(arrowUpIdle, null, Colors.Blue),
                                              0f, buttonBottomPadding + buttonHeight + betweenButtonsPadding, buttonsPanel, width: 20f, height: buttonHeight);
            upButton.RenderLayer = label.RenderLayer;
            upButton.Z = label.Z;

            var downButton = _factory.UI.GetButton(id + "_DownButton", new ButtonAnimation(arrowDownIdle, null, Colors.Purple),
                                                new ButtonAnimation(arrowDownHovered, null, Colors.Yellow), new ButtonAnimation(arrowDownIdle, null, Colors.Blue),
                                                0f, buttonBottomPadding, buttonsPanel, width: 20f, height: buttonHeight);
            downButton.RenderLayer = label.RenderLayer;
            downButton.Z = label.Z;
            numberEditor.UpButton = upButton;
            numberEditor.DownButton = downButton;
        }

        private void addSlider(string id, IUIControl panel, INumberEditorComponent numberEditor)
        {
            var slider = _factory.UI.GetSlider(id + "_Slider", null, null, 0f, 0f, 0f, panel);
            slider.Y = 0f;
            slider.Z = panel.Z - 1f;
            slider.HandleGraphics.Anchor = new PointF(0f, 0.5f);
            slider.Direction = SliderDirection.LeftToRight;
            slider.Graphics.Anchor = new PointF(0f, 0.5f);
            slider.Graphics.Image = new EmptyImage(20f, SLIDER_HEIGHT);<commit_msg>Number editor- changed up/down button padding to align with textbook<commit_after>﻿using System;
using AGS.API;

namespace AGS.Engine
{
    public class NumberPropertyEditor : IInspectorPropertyEditor
    {
        private readonly IGameFactory _factory;
        private readonly bool _wholeNumbers;
        private const float SLIDER_HEIGHT = 5f;
        private const float ROW_HEIGHT = 20f;

        public NumberPropertyEditor(IGameFactory factory, bool wholeNumbers)
        {
            _factory = factory;
            _wholeNumbers = wholeNumbers;
        }

        public void AddEditorUI(string id, ITreeNodeView view, InspectorProperty property)
        {
            var label = view.TreeItem;

            var textPanel = _factory.UI.GetPanel(id + "_TextPanel", 100f, ROW_HEIGHT, label.X, label.Y, label.TreeNode.Parent);
            textPanel.RenderLayer = label.RenderLayer;
            textPanel.Z = label.Z;
            textPanel.Tint = Colors.Transparent;
            var textbox = addTextBox(id, textPanel, property.Value);
            var numberEditor = textbox.AddComponent<INumberEditorComponent>();
            addSlider(id, textPanel, numberEditor);
            numberEditor.EditWholeNumbersOnly = _wholeNumbers;
            numberEditor.Value = float.Parse(property.Value);
            numberEditor.OnValueChanged.Subscribe(() =>
            {
                if (_wholeNumbers)
                {
                    property.Prop.SetValue(property.Object, (int)Math.Round(numberEditor.Value));
                }
                else property.Prop.SetValue(property.Object, numberEditor.Value);
            });
            addArrowButtons(id, label, numberEditor);
        }

        private ITextBox addTextBox(string id, IUIControl panel, string text)
        {
            AGSTextConfig config = new AGSTextConfig(autoFit: AutoFit.LabelShouldFitText);
            var textbox = _factory.UI.GetTextBox(id + "_Textbox",
                                              0f, SLIDER_HEIGHT + 1f, panel,
                                              text, config, width: 100f, height: ROW_HEIGHT);
            textbox.RenderLayer = panel.RenderLayer;
            textbox.Z = panel.Z;
            HoverEffect.Add(textbox, Colors.Transparent, Colors.DarkSlateBlue);
            return textbox;
        }

        private void addArrowButtons(string id, IUIControl label, 
                                     INumberEditorComponent numberEditor)
        {
            var icons = _factory.Graphics.Icons;
            var arrowUpIdle = icons.GetArrowIcon(ArrowDirection.Up, Colors.White);
            var arrowDownIdle = icons.GetArrowIcon(ArrowDirection.Down, Colors.White);
            var arrowUpHovered = icons.GetArrowIcon(ArrowDirection.Up, Colors.Black);
            var arrowDownHovered = icons.GetArrowIcon(ArrowDirection.Down, Colors.Black);
            var buttonsPanel = _factory.UI.GetPanel(id + "_ButtonsPanel", 1f, 1f, 0f, label.Y, label.TreeNode.Parent);
            buttonsPanel.RenderLayer = label.RenderLayer;
            buttonsPanel.Tint = Colors.Transparent;
            float halfRowHeight = ROW_HEIGHT / 2f;
            float buttonBottomPadding = 12f;
            float betweenButtonsPadding = 1f;
            float buttonHeight = halfRowHeight - betweenButtonsPadding * 2;
            var upButton = _factory.UI.GetButton(id + "_UpButton", new ButtonAnimation(arrowUpIdle, null, Colors.Purple),
                                              new ButtonAnimation(arrowUpHovered, null, Colors.Yellow), new ButtonAnimation(arrowUpIdle, null, Colors.Blue),
                                              0f, buttonBottomPadding + buttonHeight + betweenButtonsPadding, buttonsPanel, width: 20f, height: buttonHeight);
            upButton.RenderLayer = label.RenderLayer;
            upButton.Z = label.Z;

            var downButton = _factory.UI.GetButton(id + "_DownButton", new ButtonAnimation(arrowDownIdle, null, Colors.Purple),
                                                new ButtonAnimation(arrowDownHovered, null, Colors.Yellow), new ButtonAnimation(arrowDownIdle, null, Colors.Blue),
                                                0f, buttonBottomPadding, buttonsPanel, width: 20f, height: buttonHeight);
            downButton.RenderLayer = label.RenderLayer;
            downButton.Z = label.Z;
            numberEditor.UpButton = upButton;
            numberEditor.DownButton = downButton;
        }

        private void addSlider(string id, IUIControl panel, INumberEditorComponent numberEditor)
        {
            var slider = _factory.UI.GetSlider(id + "_Slider", null, null, 0f, 0f, 0f, panel);
            slider.Y = 0f;
            slider.Z = panel.Z - 1f;
            slider.HandleGraphics.Anchor = new PointF(0f, 0.5f);
            slider.Direction = SliderDirection.LeftToRight;
            slider.Graphics.Anchor = new PointF(0f, 0.5f);
            slider.Graphics.Image = new EmptyImage(20f, SLIDER_HEIGHT);
{'fraction_non_alphanumeric': 0.08274398868458274, 'fraction_numerical': 0.007678318852293393, 'mean_word_length': 2.075178626902765, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 26, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2409935', 'n_tokens_mistral': 2683, 'n_tokens_neox': 2556, 'n_words': 562}