예제 #1
0
 public void Awake()
 {
     Logger = base.Logger;
     Extension.Logger.logger = Logger;
     if (TextPlugin.Awake())
     {
         UIUtility.Init();
         Harmony.CreateAndPatchAll(typeof(Patches));
     }
 }
예제 #2
0
        public void Start()
        {
            Default_New_Text    = Config.Bind <string>("Config", "Default New Text", "NewText", "Text for new text. This is not affected by the Auto Change setting.");
            Auto_change_default = Config.Bind <bool>("Config", "Auto Change Default", true, "Save all text settings to create the next new Text Object.");

            Default_FontName  = Config.Bind <string>("Default Settings", "FontName", "MS Gothic", new ConfigDescription("", new AcceptableValueList <string>(TextPlugin.GetDynamicFontNames().ToArray())));
            Default_FontSize  = Config.Bind <float>("Default Settings", "FontSize", 1f, "Enter only floating point numbers.");
            Default_Color     = Config.Bind <Color>("Default Settings", "Color", Color.white);
            Default_FontStyle = Config.Bind <FontStyle>("Default Settings", "FontStyle", FontStyle.Normal);
            Default_Alignment = Config.Bind <TextAlignment>("Default Settings", "Alignment", TextAlignment.Center);
            Default_Anchor    = Config.Bind <TextAnchor>("Default Settings", "Anchor", TextAnchor.MiddleCenter);
        }
예제 #3
0
        internal static void DrawConfigPanel()
        {
            if (isConfigPanelCreated)
            {
                return;
            }
            GameObject panelRoot = GameObject.Find("StudioScene/Canvas Main Menu/02_Manipulate/04_Folder");

            //畫Config視窗
            panel = UIUtility.CreatePanel("ConfigPanel", panelRoot.transform);
            panel.transform.SetRect(new Vector2(0, 1), new Vector2(0, 1), new Vector2(0, -510), new Vector2(160, -70));

            //畫大輸入視窗
            Image nameInputPanel = UIUtility.CreatePanel("FolderNameInputPanel", panel.transform);

            nameInputPanel.transform.SetRect(Vector2.up, Vector2.up, new Vector2(165f, -200f), new Vector2(645f, 0f));
            InputField inputField = UIUtility.CreateInputField("FolderNameInput", nameInputPanel.transform, "");

            inputField.transform.SetRect(Vector2.zero, Vector2.one, new Vector2(5f, 5f), new Vector2(-5f, -5f));
            inputField.textComponent.resizeTextMinSize = 15;
            inputField.textComponent.resizeTextMaxSize = 20;
            inputField.text     = StudioTextPlugin.Default_New_Text.Value;
            inputField.lineType = InputField.LineType.MultiLineNewline;
            inputField.textComponent.alignment = TextAnchor.UpperLeft;
            nameInputPanel.gameObject.SetActive(false);

            //Config1: Font
            Text text1 = UIUtility.CreateText("FontText", panel.transform, "Font");

            text1.transform.SetRect(Vector2.up, Vector2.up, new Vector2(5f, -30f), new Vector2(155f, -5f));

            //畫SelectFont視窗
            panelSelectFont = UIUtility.CreatePanel("SelectFontPanel", panel.transform);
            if (!TextPlugin.DisablePreview)
            {
                panelSelectFont.transform.SetRect(Vector2.up, Vector2.up, new Vector2(165f, -900f), new Vector2(645f, 0f));
            }
            else
            {
                panelSelectFont.transform.SetRect(Vector2.up, Vector2.up, new Vector2(165f, -900f), new Vector2(500f, 0f));
            }

            Button selectFontBtn = UIUtility.CreateButton("SelectFontBtn", panel.transform, "MS Gothic");

            selectFontBtn.GetComponentInChildren <Text>(true).color = Color.white;
            selectFontBtn.GetComponent <Image>().color = Color.gray;
            selectFontBtn.transform.SetRect(Vector2.up, Vector2.up, new Vector2(5f, -85f), new Vector2(155f, -35f));
            selectFontBtn.GetComponentInChildren <Text>(true).transform.SetRect(Vector2.zero, new Vector2(1f, 1f), new Vector2(5f, 1f), new Vector2(-5f, -2f));
            selectFontBtn.onClick.AddListener(delegate {
                panelSelectFont.gameObject.SetActive(!panelSelectFont.gameObject.activeSelf);
            });

            //滾動元件
            ScrollRect    scrollRect = UIUtility.CreateScrollView("scroll", panelSelectFont.transform);
            RectTransform btnGroup   = scrollRect.content;

            scrollRect.transform.SetRect(Vector2.zero, Vector2.one, new Vector2(0f, 5f), new Vector2(0, -5f));
            scrollRect.GetComponent <Image>().color = new Color32(0, 0, 0, 0);
            foreach (Image img in scrollRect.verticalScrollbar.GetComponentsInChildren <Image>())
            {
                img.color = Color.Lerp(img.color, Color.black, 0.6f);
            }
            (scrollRect.verticalScrollbar.transform as RectTransform).offsetMin = new Vector2(-16f, 0);
            scrollRect.scrollSensitivity = 50;
            //字體預覽之按鈕清單
            List <Button> tmpBtns = new List <Button>();

            foreach (string fontName in TextPlugin.GetDynamicFontNames())
            {
                Button fontDisplayBtn = UIUtility.CreateButton("fontDisplayBtn", btnGroup.transform, fontName);
                Text   text           = fontDisplayBtn.GetComponentInChildren <Text>(true);
                text.color = Color.white;
                text.transform.SetRect(Vector2.zero, new Vector2(1f, 1f), new Vector2(5f, 7.5f), new Vector2(-5f, -5f));
                text.text = fontName;

                if (!TextPlugin.DisablePreview)
                {
                    text.alignment            = TextAnchor.UpperLeft;
                    text.resizeTextForBestFit = false;
                    text.fontSize             = 30;
                    Text demoText = UnityEngine.Object.Instantiate(text, text.transform.parent);
                    demoText.name      = "demoText";
                    demoText.alignment = TextAnchor.LowerLeft;
                    demoText.text      = StudioTextPlugin.Default_New_Text.Value;
                    demoText.font      = TextPlugin.GetFont(fontName);
                    demoText.font.RequestCharactersInTexture(StudioTextPlugin.Default_New_Text.Value);
                    demoText.transform.SetRect(Vector2.zero, new Vector2(1f, 1f), new Vector2(5f, 7.5f), new Vector2(-5f, -30f));
                    fontDisplayBtn.transform.SetRect(Vector2.up, Vector2.one, new Vector2(5f, -75f * (tmpBtns.Count + 1)), new Vector2(-5f, -75f * tmpBtns.Count));
                }
                else
                {
                    text.alignment = TextAnchor.MiddleLeft;
                    fontDisplayBtn.transform.SetRect(Vector2.up, Vector2.one, new Vector2(5f, -35f * (tmpBtns.Count + 1)), new Vector2(-5f, -35f * tmpBtns.Count));
                }

                fontDisplayBtn.GetComponent <Image>().color = Color.gray;
                fontDisplayBtn.onClick.AddListener(delegate {
                    if (!onUpdating)
                    {
                        selectFontBtn.GetComponentInChildren <Text>().text = fontName;
                        TextPlugin.ChangeFont(fontName);
                        panelSelectFont.gameObject.SetActive(false);
                    }
                });
                tmpBtns.Add(fontDisplayBtn);
            }
            if (TextPlugin.DisablePreview)
            {
                btnGroup.transform.SetRect(Vector2.zero, new Vector2(1f, 1f), new Vector2(0, 900f - (35f * tmpBtns.Count) - 10f), new Vector2(0, 0));
            }
            else
            {
                btnGroup.transform.SetRect(Vector2.zero, new Vector2(1f, 1f), new Vector2(0, 900f - (75f * tmpBtns.Count) - 10f), new Vector2(0, 0));
            }
            EventTrigger trigger3 = panelSelectFont.gameObject.AddComponent <EventTrigger>();

            EventTrigger.Entry entry3 = new EventTrigger.Entry {
                eventID = EventTriggerType.Deselect
            };
            entry3.callback.AddListener((data) => {
                panelSelectFont.gameObject.SetActive(false);
                Logger.LogDebug("LostFocus.");
            });
            trigger3.triggers.Add(entry3);
            panelSelectFont.gameObject.SetActive(false);

            //Config2: FontSize (CharacterSize)
            Text text2 = UIUtility.CreateText("FontSize", panel.transform, "FontSize");

            text2.transform.SetRect(Vector2.up, Vector2.up, new Vector2(5f, -115f), new Vector2(155f, -90f));
            InputField input = UIUtility.CreateInputField("fontSizeInput", panel.transform, "e.g., 1.56 (float)");

            input.transform.SetRect(Vector2.up, Vector2.up, new Vector2(5f, -155f), new Vector2(155f, -120f));
            input.text = "1";
            input.onEndEdit.AddListener(delegate {
                if (!onUpdating)
                {
                    if (!float.TryParse(input.text, out float f))
                    {
                        Logger.LogError("FormatException: Please input only numbers into FontSize.");
                        Logger.LogMessage("FormatException: Please input only numbers into FontSize.");
                        input.text = TextPlugin.GetConfig(null, TextPlugin.Config.FontSize);
                    }
                    else
                    {
                        TextPlugin.ChangeCharacterSize(f);
                    }
                }
            });