<commit_before>﻿using System;
using Mod.Keybinds;
using UnityEngine;

namespace Mod.Interface
{
    public class InGameMenu : Gui
    {
        private Texture2D _background;
        private Texture2D _topBar;
        private GUIStyle _menuItem;
        private GUIStyle _menuValue;
        private GUIStyle _menuCategory;
        private GUIStyle _menuEntry;
        private GUIStyle _selectedEntry;
        private float _lastAnimationUpdate;
        private SubMenu _currentMenu;
        
        protected override void OnShow()
        {
            _background = Texture(255, 255, 255);
            _topBar = Texture(255, 0, 0);
            
            _menuEntry = new GUIStyle
            {
                normal = {textColor = Color(112, 112, 112)},
                fontSize = 20,
                alignment = TextAnchor.MiddleCenter
            };
            _selectedEntry = new GUIStyle(_menuEntry);
            _menuCategory = new GUIStyle
            {
                normal = {textColor = Color(255, 111, 0)},
                fontSize = 16,
                alignment = TextAnchor.UpperCenter
            };
            _menuItem = new GUIStyle
            {
                fontSize = 13,
                alignment = TextAnchor.MiddleLeft
            };
            _menuValue = new GUIStyle(_menuItem)
            {
                alignment = TextAnchor.MiddleRight
            };
        }

        private void Update()
        {
            if (_isListening)
            {
                try
                {
                    var input = Input.inputString;
                    for (int i = 0; i < 6; i++)
                        if (Input.GetMouseButtonDown(i))
                            input = $"Mouse{i}";
                    
                    if (string.IsNullOrEmpty(input))
                        return;
                    
                    KeyCode code = (KeyCode) Enum.Parse(typeof(KeyCode), input, true);
                    Shelter.InputManager[_action] = code;
                    Shelter.InputManager.Save(); //TODO: Save after Save is pressed

                    _isListening = false;
                }
                catch (ArgumentException)
                {
                    // ignored
                }
                return;
            }
            
            if (!Visible && Shelter.InputManager.IsDown(InputAction.OpenMenu))
                Enable();
            else if (Visible && (Shelter.InputManager.IsDown(InputAction.OpenMenu) || Input.GetKeyDown(KeyCode.Escape)))
                Disable();
        }

        private bool EnableDisableButton(Rect rect, string text, bool value)
        {
            GUI.Label(rect, text, _menuItem);
            GUI.Label(rect, value ? "Enabled" : "Disabled", _menuValue);
            if (GUI.Button(rect, string.Empty, GUIStyle.none))
                return !value;
            return value;
        }

        protected override void Render()
        {
            var color = Shelter.Animation.ToColor();
            _selectedEntry.normal.textColor = color;
            <commit_msg>Improved GUI open close logic<commit_after>﻿using System;
using Mod.Keybinds;
using UnityEngine;

namespace Mod.Interface
{
    public class InGameMenu : Gui
    {
        private Texture2D _background;
        private Texture2D _topBar;
        private GUIStyle _menuItem;
        private GUIStyle _menuValue;
        private GUIStyle _menuCategory;
        private GUIStyle _menuEntry;
        private GUIStyle _selectedEntry;
        private float _lastAnimationUpdate;
        private SubMenu _currentMenu;
        
        protected override void OnShow()
        {
            _background = Texture(255, 255, 255);
            _topBar = Texture(255, 0, 0);
            
            _menuEntry = new GUIStyle
            {
                normal = {textColor = Color(112, 112, 112)},
                fontSize = 20,
                alignment = TextAnchor.MiddleCenter
            };
            _selectedEntry = new GUIStyle(_menuEntry);
            _menuCategory = new GUIStyle
            {
                normal = {textColor = Color(255, 111, 0)},
                fontSize = 16,
                alignment = TextAnchor.UpperCenter
            };
            _menuItem = new GUIStyle
            {
                fontSize = 13,
                alignment = TextAnchor.MiddleLeft
            };
            _menuValue = new GUIStyle(_menuItem)
            {
                alignment = TextAnchor.MiddleRight
            };
        }

        private void Update()
        {
            if (_isListening)
            {
                try
                {
                    var input = Input.inputString;
                    for (int i = 0; i < 6; i++)
                        if (Input.GetMouseButtonDown(i))
                            input = $"Mouse{i}";
                    
                    if (string.IsNullOrEmpty(input))
                        return;
                    
                    KeyCode code = (KeyCode) Enum.Parse(typeof(KeyCode), input, true);
                    Shelter.InputManager[_action] = code;
                    Shelter.InputManager.Save(); //TODO: Save after Save is pressed

                    _isListening = false;
                }
                catch (ArgumentException)
                {
                    // ignored
                }
                return;
            }
            
            if (Shelter.InputManager.IsDown(InputAction.OpenMenu))
                Toggle();
            if (Visible && Input.GetKeyDown(KeyCode.Escape))
                Disable();
        }

        private bool EnableDisableButton(Rect rect, string text, bool value)
        {
            GUI.Label(rect, text, _menuItem);
            GUI.Label(rect, value ? "Enabled" : "Disabled", _menuValue);
            if (GUI.Button(rect, string.Empty, GUIStyle.none))
                return !value;
            return value;
        }

        protected override void Render()
        {
            var color = Shelter.Animation.ToColor();
            _selectedEntry.normal.textColor = color;
            
{'fraction_non_alphanumeric': 0.07785016286644951, 'fraction_numerical': 0.013029315960912053, 'mean_word_length': 1.2241941325606664, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '7372519', 'n_tokens_mistral': 1613, 'n_tokens_neox': 1467, 'n_words': 355}