<commit_before>﻿using System.Collections.Generic;
using System.Threading.Tasks;
using AGS.API;

namespace AGS.Engine
{
    public class GameDebugDisplayList : IDebugTab
    {
        private List<IObject> _lastDisplayList;
        private IListboxComponent _listBox;
        private IPanel _listPanel, _scrollingPanel, _parent;
        private ITextBox _searchBox;
        private IStackLayoutComponent _layout;
        private readonly IRenderLayer _layer;
        private readonly IGame _game;

        public GameDebugDisplayList(IGame game, IRenderLayer layer)
        {
            _game = game;
            _layer = layer;
            game.RenderLoop.OnBeforeRenderingDisplayList.Subscribe(onBeforeRenderingDisplayList);
        }

        public IPanel Panel => _scrollingPanel;

        public void Load(IPanel parent)
        {
            _parent = parent;
            var factory = _game.Factory;

            _searchBox = factory.UI.GetTextBox("GameDebugDisplayListSearchBox", 0f, parent.Height, parent, "Search...", width: parent.Width, height: 30f);
            _searchBox.RenderLayer = _layer;
            _searchBox.Border = AGSBorders.SolidColor(Colors.Green, 2f);
            _searchBox.Tint = Colors.Transparent;
            _searchBox.Pivot = new PointF(0f, 1f);
            _searchBox.Visible = false;

            _scrollingPanel = factory.UI.GetPanel("GameDebugDisplayListScrollingPanel", parent.Width, parent.Height - _searchBox.Height, 0f, 0f, parent);
			_scrollingPanel.RenderLayer = _layer;
			_scrollingPanel.Pivot = new PointF(0f, 0f);
			_scrollingPanel.Tint = Colors.Transparent;
			_scrollingPanel.Border = AGSBorders.SolidColor(Colors.Green, 2f);
            _scrollingPanel.Visible = false;

            _listPanel = factory.UI.GetPanel("GameDebugDisplayListPanel", 1f, 1f, 0f, _scrollingPanel.Height - 10, _scrollingPanel);
            _listPanel.Tint = Colors.Transparent;
            _listPanel.RenderLayer = _layer;
            _listPanel.Pivot = new PointF(0f, 1f);
            _listPanel.AddComponent<IBoundingBoxWithChildrenComponent>();
            _layout = _listPanel.AddComponent<IStackLayoutComponent>();
            _listBox = _listPanel.AddComponent<IListboxComponent>();
            var yellowBrush = factory.Graphics.Brushes.LoadSolidBrush(Colors.Yellow);
            var whiteBrush = factory.Graphics.Brushes.LoadSolidBrush(Colors.White);
            _listBox.ItemButtonFactory = text =>
            {
                var button = factory.UI.GetButton("GameDebugDisplayListPanel_" + text,
                                                  new ButtonAnimation(null, new AGSTextConfig(whiteBrush, autoFit: AutoFit.TextShouldWrapAndLabelShouldFitHeight), null),
                                                  new ButtonAnimation(null, new AGSTextConfig(yellowBrush, autoFit: AutoFit.TextShouldWrapAndLabelShouldFitHeight), null),
                                                  new ButtonAnimation(null, new AGSTextConfig(yellowBrush, outlineBrush: whiteBrush, outlineWidth: 0.5f, autoFit: AutoFit.TextShouldWrapAndLabelShouldFitHeight), null),
                                                  0f, 0f, width: 500f, height: 50f);
                button.RenderLayer = parent.RenderLayer;
                return button;
            };
            factory.UI.CreateScrollingPanel(_scrollingPanel);
            parent.GetComponent<IScaleComponent>().PropertyChanged += (_, args) =>
			{
                if (args.PropertyName != nameof(IScaleComponent.Height)) return;
                _scrollingPanel.Image = new EmptyImage(_scrollingPanel.Width, parent.Height - _searchBox.Height);
                _listPanel.Y = _scrollingPanel.Height - 10f;
                _searchBox.Y = _parent.Height;
			};
        }

        public async Task Show()
        {
            await Task.Run(() => refresh());
            _layout.StartLayout();
            _scrollingPanel.Visible = true;
            _searchBox.Visible = true;
        }

        public void Hide()
        {
            _scrollingPanel.Visible = false;
            _searchBox.Visible = false;
            _layout.StopLayout();
            _listBox.Items.Clear();
        }

		public void Resize()
		{
			_scrollingPanel.Image = new EmptyImage(_parent.Width, _scrollingPanel.Image.Height);
            _searchBox.LabelRenderSize = new SizeF(_parent.Width, _searchBox.Height);
		}

        private void refresh()
        {
            _listBox.Items.Clear();
            if (_lastDisplayList == null) return;
            foreach (var obj in _lastDisplayList)
            {
                _listBox.Items.Add(new AGSStringItem { Text = obj.ID });
            }
        }

        private void onBeforeRenderingDisplayList(DisplayListEventArgs args)
        {
            SortDebugger.DebugIfNeeded(args.DisplayList);
            _lastDisplayList = args.DisplayList;
        }

    }
}<commit_msg>Debug display list- add search<commit_after>﻿using System.Collections.Generic;
using System.ComponentModel;
using System.Threading.Tasks;
using AGS.API;

namespace AGS.Engine
{
    public class GameDebugDisplayList : IDebugTab
    {
        private List<IObject> _lastDisplayList;
        private IListboxComponent _listBox;
        private IPanel _listPanel, _scrollingPanel, _parent;
        private ITextBox _searchBox;
        private IStackLayoutComponent _layout;
        private readonly IRenderLayer _layer;
        private readonly IGame _game;

        public GameDebugDisplayList(IGame game, IRenderLayer layer)
        {
            _game = game;
            _layer = layer;
            game.RenderLoop.OnBeforeRenderingDisplayList.Subscribe(onBeforeRenderingDisplayList);
        }

        public IPanel Panel => _scrollingPanel;

        public void Load(IPanel parent)
        {
            _parent = parent;
            var factory = _game.Factory;

            _searchBox = factory.UI.GetTextBox("GameDebugDisplayListSearchBox", 0f, parent.Height, parent, "Search...", width: parent.Width, height: 30f);
            _searchBox.RenderLayer = _layer;
            _searchBox.Border = AGSBorders.SolidColor(Colors.Green, 2f);
            _searchBox.Tint = Colors.Transparent;
            _searchBox.Pivot = new PointF(0f, 1f);
            _searchBox.Visible = false;
            _searchBox.GetComponent<ITextComponent>().PropertyChanged += onSearchPropertyChanged;

            _scrollingPanel = factory.UI.GetPanel("GameDebugDisplayListScrollingPanel", parent.Width, parent.Height - _searchBox.Height, 0f, 0f, parent);
			_scrollingPanel.RenderLayer = _layer;
			_scrollingPanel.Pivot = new PointF(0f, 0f);
			_scrollingPanel.Tint = Colors.Transparent;
			_scrollingPanel.Border = AGSBorders.SolidColor(Colors.Green, 2f);
            _scrollingPanel.Visible = false;

            const float lineHeight = 42f;
            _listPanel = factory.UI.GetPanel("GameDebugDisplayListPanel", 1f, 1f, 0f, _scrollingPanel.Height - lineHeight, _scrollingPanel);
            _listPanel.Tint = Colors.Transparent;
            _listPanel.RenderLayer = _layer;
            _listPanel.Pivot = new PointF(0f, 1f);
            _listPanel.AddComponent<IBoundingBoxWithChildrenComponent>();
            _layout = _listPanel.AddComponent<IStackLayoutComponent>();
            _listBox = _listPanel.AddComponent<IListboxComponent>();
            var yellowBrush = factory.Graphics.Brushes.LoadSolidBrush(Colors.Yellow);
            var whiteBrush = factory.Graphics.Brushes.LoadSolidBrush(Colors.White);
            _listBox.ItemButtonFactory = text =>
            {
                var button = factory.UI.GetButton("GameDebugDisplayListPanel_" + text,
                                                  new ButtonAnimation(null, new AGSTextConfig(whiteBrush, autoFit: AutoFit.LabelShouldFitText), null),
                                                  new ButtonAnimation(null, new AGSTextConfig(yellowBrush, autoFit: AutoFit.LabelShouldFitText), null),
                                                  new ButtonAnimation(null, new AGSTextConfig(yellowBrush, outlineBrush: whiteBrush, outlineWidth: 0.5f, autoFit: AutoFit.LabelShouldFitText), null),
                                                  0f, 0f, width: 500f, height: 50f);
                button.RenderLayer = parent.RenderLayer;
                return button;
            };
            factory.UI.CreateScrollingPanel(_scrollingPanel);
            parent.GetComponent<IScaleComponent>().PropertyChanged += (_, args) =>
			{
                if (args.PropertyName != nameof(IScaleComponent.Height)) return;
                _scrollingPanel.Image = new EmptyImage(_scrollingPanel.Width, parent.Height - _searchBox.Height);
                _listPanel.Y = _scrollingPanel.Height - 10f;
                _searchBox.Y = _parent.Height;
			};
        }

        public async Task Show()
        {
            await Task.Run(() => refresh());
            _layout.StartLayout();
            _scrollingPanel.Visible = true;
            _searchBox.Visible = true;
        }

        public void Hide()
        {
            _scrollingPanel.Visible = false;
            _searchBox.Visible = false;
            _layout.StopLayout();
            _listBox.Items.Clear();
        }

		public void Resize()
		{
			_scrollingPanel.Image = new EmptyImage(_parent.Width, _scrollingPanel.Image.Height);
            _searchBox.LabelRenderSize = new SizeF(_parent.Width, _searchBox.Height);
		}

        private void refresh()
        {
            _listBox.Items.Clear();
            if (_lastDisplayList == null) return;
            foreach (var obj in _lastDisplayList)
            {
                _listBox.Items.Add(new AGSStringItem { Text = obj.ID });
            }
        }

        private void onBeforeRenderingDisplayList(DisplayListEventArgs args)
        {
            SortDebugger.DebugIfNeeded(args.DisplayList);
            _lastDisplayList = args.DisplayList;
        }

        private void onSearchPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName != nameof(ITextComponent.Text)) return;
            _listBox.SearchFilter = _searchBox.Text;
        }
    }
}
{'fraction_non_alphanumeric': 0.08621198700915264, 'fraction_numerical': 0.005708099596496408, 'mean_word_length': 2.1986150456405413, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1795286', 'n_tokens_mistral': 2815, 'n_tokens_neox': 2658, 'n_words': 514}