<commit_before>﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.UI;

namespace UserInterface
{
    [AddComponentMenu(NamingHelper.Button.Name, 0)]
    public class GMButton : Button {
        public List<Graphic> colorizeElements = new List<Graphic>();
        public Color defaultColor;
        public Color highlightColor;
        public Color pressedColor;
        public Color disabledColor;

        // Event delegate triggered on mouse or touch down.
        [SerializeField]
        GMButtonRightClickEvent _onRightClick = new GMButtonRightClickEvent();

        [Serializable]
        public class GMButtonRightClickEvent : UnityEvent { }

        protected GMButton() { }

        public override void OnPointerClick(PointerEventData eventData) {
            if (eventData.button == PointerEventData.InputButton.Left) {
                if (interactable) onClick.Invoke();
            } else if (eventData.button == PointerEventData.InputButton.Right) {
                if (interactable) _onRightClick.Invoke();
            }
        }

        public GMButtonRightClickEvent onRightClick {
            get { return _onRightClick; }
            set { _onRightClick = value; }
        }

        protected override void DoStateTransition(SelectionState state, bool instant)
        {
            base.DoStateTransition(state, instant);

            if (state == SelectionState.Disabled)
            {
                foreach (Graphic colorizeElement in colorizeElements)
                {
                    colorizeElement.color = disabledColor;
                }
            } else if (state == SelectionState.Highlighted)
            {
                foreach (Graphic colorizeElement in colorizeElements)
                {
                    colorizeElement.color = highlightColor;
                }
            } else if (state == SelectionState.Normal)
            {
                foreach (Graphic colorizeElement in colorizeElements)
                {
                    colorizeElement.color = defaultColor;
                }
            } else if (state == SelectionState.Pressed)
            {
                foreach (Graphic colorizeElement in colorizeElements)
                {
                    colorizeElement.color = pressedColor;
                }
            }
        }

        public void Highlight(bool highlight) {
            if (highlight) {
                DoStateTransition(SelectionState.Highlighted, true);
            } else {
                if (interactable) {
                    DoStateTransition(SelectionState.Normal, true);
                } else {
                    DoStateTransition(SelectionState.Disabled, true);
                }
            }
        }
    }
}
<commit_msg>GMButton now has a pressed event<commit_after>﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.UI;

namespace UserInterface
{
    [AddComponentMenu(NamingHelper.Button.Name, 0)]
    public class GMButton : Button {
        public List<Graphic> colorizeElements = new List<Graphic>();
        public Color defaultColor;
        public Color highlightColor;
        public Color pressedColor;
        public Color disabledColor;

        public bool isPressed {
            get; private set;
        }

        // Event delegate triggered on mouse or touch down.
        [SerializeField]
        GMButtonRightClickEvent _onRightClick = new GMButtonRightClickEvent();

        [Serializable]
        public class GMButtonRightClickEvent : UnityEvent { }

        [SerializeField]
        GMButtonPressedEvent _onPressed = new GMButtonPressedEvent();

        [Serializable]
        public class GMButtonPressedEvent : UnityEvent { }

        [SerializeField]
        GMButtonReleaseEvent _onRelease = new GMButtonReleaseEvent();

        [Serializable]
        public class GMButtonReleaseEvent : UnityEvent { }

        protected GMButton() { }

        public override void OnPointerClick(PointerEventData eventData) {
            if (eventData.button == PointerEventData.InputButton.Left) {
                if (interactable && !isPressed) onClick.Invoke();
            } else if (eventData.button == PointerEventData.InputButton.Right) {
                if (interactable) onRightClick.Invoke();
            }
        }

        public GMButtonRightClickEvent onRightClick {
            get { return _onRightClick; }
            set { _onRightClick = value; }
        }

        public GMButtonPressedEvent onPressed {
            get { return _onPressed; }
            set { _onPressed = value; }
        }

        public GMButtonReleaseEvent onRelease {
            get { return _onRelease; }
            set { _onRelease = value; }
        }



        protected override void DoStateTransition(SelectionState state, bool instant)
        {
            base.DoStateTransition(state, instant);

            if (state == SelectionState.Disabled)
            {
                foreach (Graphic colorizeElement in colorizeElements)
                {
                    colorizeElement.color = disabledColor;
                }
            } else if (state == SelectionState.Highlighted)
            {
                foreach (Graphic colorizeElement in colorizeElements)
                {
                    colorizeElement.color = highlightColor;
                }
            } else if (state == SelectionState.Normal)
            {
                foreach (Graphic colorizeElement in colorizeElements)
                {
                    colorizeElement.color = defaultColor;
                }
            } else if (state == SelectionState.Pressed)
            {
                isPressed = true;

                foreach (Graphic colorizeElement in colorizeElements)
                {
                    colorizeElement.color = pressedColor;
                }
            }
        }

        public override void OnPointerExit(PointerEventData eventData) {
            base.OnPointerExit(eventData);

            if (isPressed) {
                onRelease.Invoke();
                isPressed = false;
            }
        }

        public override void OnPointerUp(PointerEventData eventData) {
            base.OnPointerUp(eventData);

            if (isPressed) {
                onRelease.Invoke();
                isPressed = false;
            }
        }

        private void Update() {
            if (isPressed) {
                onPressed.Invoke();
            }
        }

        public void Highlight(bool highlight) {
            if (highlight) {
                DoStateTransition(SelectionState.Highlighted, true);
            } else {
                if (interactable) {
                    DoStateTransition(SelectionState.Normal, true);
                } else {
                    DoStateTransition(SelectionState.Disabled, true);
                }
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.06985605419136325, 'fraction_numerical': 0.0002822466836014677, 'mean_word_length': 1.6632844795189778, 'pattern_counts': {'":': 0, '<': 7, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5102819', 'n_tokens_mistral': 1712, 'n_tokens_neox': 1626, 'n_words': 388}