using System; using System.Collections.Generic; using System.Data; using TMPro; using UnityEngine; using UnityEngine.UI; using static UnityEngine.Rendering.DebugUI.Table; public class SimpleCalculator : MonoBehaviour { public AppLayer appLayer; [Header("Настройки")] public GameObject buttonPrefab; public Font font; private Text displayText; private RectTransform gridRect; private GridLayoutGroup gridLayout; // Поля для программиста private GameObject programmerPanel; private Text hexVal, decVal, octVal, binVal; private string currentInput = ""; private bool isProgrammerMode = false; private Dictionary sysTexts = new Dictionary(); private int currentBase = 10; private readonly string[] normalLayout = { "%", "CE", "CLR", "<-", "1/x", "x²", "√x", "/", "7", "8", "9", "x", "4", "5", "6", "-", "1", "2", "3", "+", "+/-", "0", ",", "=" }; private readonly string[] programmerLayout = { "A", "<<", ">>", "CLR", "<-", "B", "(", ")", "%", "/", "C", "7", "8", "9", "x", "D", "4", "5", "6", "-", "E", "1", "2", "3", "+", "F", "+/-", "0", ",", "=" }; [Header("Индикация выбора")] private Image selectionIndicator; private string activeSystem = "DEC"; private Button normalModeBtn; private Button programmerModeBtn; private void Awake() { appLayer = GetComponentInParent(); } void Start() { appLayer.appMinSize = new Vector2(300, 400); appLayer.sizeDelta = new Vector2(300, 400); appLayer.color = new Color(31, 31, 31); InitializeUI(); //SetMode(true); } void InitializeUI() { // 1. Дисплей GameObject displayObj = new GameObject("Display", typeof(RectTransform), typeof(Image)); displayObj.transform.SetParent(transform, false); displayObj.GetComponent().color = new Color(0.1f, 0.1f, 0.1f, 0.8f); RectTransform dispRT = displayObj.GetComponent(); dispRT.anchorMin = new Vector2(0, 0.65f); dispRT.anchorMax = new Vector2(1, 0.9f); dispRT.offsetMin = dispRT.offsetMax = Vector2.zero; displayText = CreateTextElement("0", 100, displayObj.transform); displayText.alignment = TextAnchor.MiddleRight; displayText.rectTransform.sizeDelta = new Vector2(0, 0); // 2. Создаем панель систем счисления CreateProgrammerInfoPanel(); // 3. Сетка кнопок GameObject gridObj = new GameObject("Grid", typeof(RectTransform), typeof(GridLayoutGroup)); gridObj.transform.SetParent(transform, false); gridRect = gridObj.GetComponent(); gridRect.anchorMin = new Vector2(0, 0); gridRect.anchorMax = new Vector2(1, 0.6f); gridRect.offsetMin = gridRect.offsetMax = Vector2.zero; gridLayout = gridObj.GetComponent(); gridLayout.padding = new RectOffset(5, 5, 5, 5); gridLayout.spacing = new Vector2(2, 2); gridLayout.constraint = GridLayoutGroup.Constraint.FixedColumnCount; CreateModeButtons(); SetMode(false); // Начинаем с обычного режима } void CreateModeButtons() { GameObject panel = new GameObject("ModeButtons", typeof(RectTransform)); panel.transform.SetParent(transform, false); RectTransform rt = panel.GetComponent(); rt.anchorMin = new Vector2(0, 0.90f); rt.anchorMax = new Vector2(1, 1); rt.offsetMin = rt.offsetMax = Vector2.zero; HorizontalLayoutGroup hlg = panel.AddComponent(); hlg.spacing = 10; hlg.childForceExpandWidth = true; hlg.childAlignment = TextAnchor.MiddleCenter; normalModeBtn = CreateModeButton("Обычный", panel.transform); programmerModeBtn = CreateModeButton("Программист", panel.transform); normalModeBtn.onClick.AddListener(() => SetMode(false)); programmerModeBtn.onClick.AddListener(() => SetMode(true)); UpdateModeButtonsVisual(); } Button CreateModeButton(string text, Transform parent) { GameObject btnObj = Instantiate(buttonPrefab, parent); btnObj.name = text + "Button"; RectTransform rt = btnObj.GetComponent(); rt.sizeDelta = new Vector2(160, 32); TextMeshProUGUI label = btnObj.GetComponentInChildren(); label.text = text; return btnObj.GetComponent