public static UIDynamicPanels.DynamicPanelInfo CreatePanelInfo(UIView view)
        {
            KlyteMonoUtils.CreateUIElement(out UIPanel mainPanel, null, PANEL_ID);
            mainPanel.enabled                   = false;
            mainPanel.maximumSize               = new Vector2(0, view.fixedHeight);
            mainPanel.minimumSize               = new Vector2(800, 70);
            mainPanel.backgroundSprite          = "MenuPanel2";
            mainPanel.anchor                    = UIAnchorStyle.CenterHorizontal | UIAnchorStyle.CenterVertical;
            mainPanel.autoLayout                = true;
            mainPanel.autoFitChildrenVertically = true;
            mainPanel.autoLayoutDirection       = LayoutDirection.Vertical;
            mainPanel.autoLayoutStart           = LayoutStart.TopLeft;
            mainPanel.padding                   = new RectOffset(5, 5, 0, 0);
            mainPanel.autoLayoutPadding         = new RectOffset(0, 0, 0, 10);


            #region Title
            KlyteMonoUtils.CreateUIElement(out UIPanel titleContainer, mainPanel.transform, "TitleContainer");
            titleContainer.size = new Vector2(mainPanel.width, 40);


            KlyteMonoUtils.CreateUIElement(out UILabel title, titleContainer.transform, "Title");
            title.text          = "<k45symbol K45_HexagonIcon_NOBORDER,5e35b1,K> Klyte45";
            title.anchor        = UIAnchorStyle.CenterHorizontal | UIAnchorStyle.CenterVertical;
            title.minimumSize   = new Vector3(titleContainer.width - 100, 0);
            title.textScale     = 2;
            title.textAlignment = UIHorizontalAlignment.Center;



            KlyteMonoUtils.CreateUIElement(out UISprite modIcon, titleContainer.transform, "ModIcon", new Vector4(5, 5, 32, 32));
            modIcon.tooltip = $"v{VERSION}{CommonProperties.Acronym}";

            KlyteMonoUtils.CreateUIElement(out UIButton closeButton, titleContainer.transform, "CloseButton");
            closeButton.area            = new Vector4(mainPanel.width - 37, 3, 32, 32);
            closeButton.normalBgSprite  = "buttonclose";
            closeButton.hoveredBgSprite = "buttonclosehover";
            closeButton.pressedBgSprite = "buttonclosepressed";


            #endregion

            #region Texture area
            KlyteMonoUtils.CreateUIElement(out UIPanel textureContainer, mainPanel.transform, "TextureSupContainer");
            textureContainer.size = new Vector2(800, 0);
            textureContainer.autoFitChildrenVertically = true;

            KlyteMonoUtils.CreateUIElement(out UIPanel textureSubContainer, textureContainer.transform, "TextureContainer");
            textureSubContainer.anchor = UIAnchorStyle.CenterHorizontal | UIAnchorStyle.Top;
            textureSubContainer.pivot  = UIPivotPoint.TopCenter;
            textureSubContainer.autoFitChildrenVertically   = true;
            textureSubContainer.autoFitChildrenHorizontally = true;
            textureSubContainer.autoLayout       = true;
            textureSubContainer.relativePosition = new Vector3(0, 0);

            KlyteMonoUtils.CreateUIElement(out UITextureSprite textureSprite, textureSubContainer.transform, "TextureSprite");
            textureSprite.size = default;
            #endregion

            #region Text area
            KlyteMonoUtils.CreateUIElement(out UILabel boxText, mainPanel.transform, "BoxText");
            boxText.minimumSize       = new Vector2(800, 60);
            boxText.maximumSize       = new Vector2(0, view.fixedHeight * 0.8f);
            boxText.clipChildren      = true;
            boxText.wordWrap          = true;
            boxText.autoSize          = false;
            boxText.autoHeight        = true;
            boxText.processMarkup     = true;
            boxText.padding           = new RectOffset(10, 10, 5, 5);
            boxText.textAlignment     = UIHorizontalAlignment.Center;
            boxText.verticalAlignment = UIVerticalAlignment.Middle;
            #endregion

            #region Inputs
            CreateInputs(mainPanel, boxText);
            #endregion

            #region Action Buttons
            KlyteMonoUtils.CreateUIElement(out UIPanel buttonContainer, mainPanel.transform, "ButtonSupContainer");
            buttonContainer.size = new Vector2(800, 70);
            buttonContainer.autoFitChildrenVertically = true;

            KlyteMonoUtils.CreateUIElement(out UIPanel buttonSubContainer, buttonContainer.transform, "ButtonContainer");
            buttonSubContainer.anchor = UIAnchorStyle.CenterHorizontal | UIAnchorStyle.Top;
            buttonSubContainer.pivot  = UIPivotPoint.TopCenter;
            buttonSubContainer.autoFitChildrenVertically   = true;
            buttonSubContainer.autoFitChildrenHorizontally = true;
            buttonSubContainer.autoLayout        = true;
            buttonSubContainer.autoLayoutPadding = new RectOffset(5, 5, 0, 0);
            buttonSubContainer.relativePosition  = new Vector3(0, 0);

            KlyteMonoUtils.CreateUIElement(out UIButton button1, buttonSubContainer.transform, "ButtonAction1");
            button1.anchor   = UIAnchorStyle.CenterHorizontal | UIAnchorStyle.Top;
            button1.size     = new Vector2(150, 60);
            button1.text     = "AAAAA";
            button1.wordWrap = true;
            KlyteMonoUtils.InitButtonFull(button1, false, "ButtonMenu");
            KlyteMonoUtils.CreateUIElement(out UIButton button2, buttonSubContainer.transform, "ButtonAction2");
            button2.anchor   = UIAnchorStyle.CenterHorizontal | UIAnchorStyle.Top;
            button2.size     = new Vector2(150, 60);
            button2.text     = "BBBBB";
            button2.wordWrap = true;
            KlyteMonoUtils.InitButtonFull(button2, false, "ButtonMenu");
            KlyteMonoUtils.CreateUIElement(out UIButton button3, buttonSubContainer.transform, "ButtonAction3");
            button3.anchor   = UIAnchorStyle.CenterHorizontal | UIAnchorStyle.Top;
            button3.size     = new Vector2(150, 60);
            button3.text     = "CCCCC";
            button3.wordWrap = true;
            KlyteMonoUtils.InitButtonFull(button3, false, "ButtonMenu");
            KlyteMonoUtils.CreateUIElement(out UIButton button4, buttonSubContainer.transform, "ButtonAction4");
            button4.anchor   = UIAnchorStyle.CenterHorizontal | UIAnchorStyle.Top;
            button4.size     = new Vector2(150, 60);
            button4.text     = "DDDDD";
            button4.wordWrap = true;
            KlyteMonoUtils.InitButtonFull(button4, false, "ButtonMenu");
            KlyteMonoUtils.CreateUIElement(out UIButton button5, buttonSubContainer.transform, "ButtonAction5");
            button5.anchor   = UIAnchorStyle.CenterHorizontal | UIAnchorStyle.Top;
            button5.size     = new Vector2(150, 60);
            button5.text     = "EEEEE";
            button5.wordWrap = true;
            KlyteMonoUtils.InitButtonFull(button5, false, "ButtonMenu");
            #endregion

            #region Bindings creation
            mainPanel.gameObject.AddComponent <K45DialogControl>();
            BindPropertyByKey bindByKey = mainPanel.gameObject.AddComponent <BindPropertyByKey>();
            bindByKey.m_Bindings.AddRange(new List <BindPropertyByKey.BindingInfo>()
            {
                CreateBind("title", title, "text"),
                CreateBind("icon", modIcon, "spriteName"),
                CreateBind("showClose", closeButton, "isVisible"),
                CreateBind("message", boxText, "text"),
                CreateBind("messageAlign", boxText, "textAlignment"),
                CreateBind("showButton1", button1, "isVisible"),
                CreateBind("showButton2", button2, "isVisible"),
                CreateBind("showButton3", button3, "isVisible"),
                CreateBind("showButton4", button4, "isVisible"),
                CreateBind("showButton5", button5, "isVisible"),
                CreateBind("textButton1", button1, "text"),
                CreateBind("textButton2", button2, "text"),
                CreateBind("textButton3", button3, "text"),
                CreateBind("textButton4", button4, "text"),
                CreateBind("textButton5", button5, "text"),
            });
            #endregion

            #region Declare Dynamic Panel Info
            var panelTestInfo = new UIDynamicPanels.DynamicPanelInfo();
            panelTestInfo.GetType().GetField("m_Name", RedirectorUtils.allFlags).SetValue(panelTestInfo, PANEL_ID);
            panelTestInfo.GetType().GetField("m_PanelRoot", RedirectorUtils.allFlags).SetValue(panelTestInfo, mainPanel);
            panelTestInfo.GetType().GetField("m_IsModal", RedirectorUtils.allFlags).SetValue(panelTestInfo, true);
            #endregion

            return(panelTestInfo);
        }
Ejemplo n.º 2
0
        private void Awake()
        {
            m_pagePanel                     = GetComponent <UIPanel>();
            m_pagePanel.padding             = new RectOffset(0, 0, 0, 0);
            m_pagePanel.autoLayout          = true;
            m_pagePanel.autoLayoutDirection = LayoutDirection.Horizontal;
            m_pagePanel.autoLayoutPadding   = new RectOffset(0, 0, 0, 3);
            m_pagePanel.clipChildren        = true;
            float height = m_pagePanel.height;

            KlyteMonoUtils.CreateUIElement(out m_infoLabel, m_pagePanel.transform, "infoLabel", new UnityEngine.Vector4(0, 0, m_pagePanel.width * .4f, height));
            m_infoLabel.verticalAlignment = UIVerticalAlignment.Middle;
            m_infoLabel.minimumSize       = new Vector2(m_pagePanel.width * .4f, height);
            KlyteMonoUtils.LimitWidthAndBox(m_infoLabel, m_pagePanel.width * .4f);

            KlyteMonoUtils.CreateUIElement(out UILabel itemsPerPageLbl, m_pagePanel.transform, "itemsPerPageLbl", new UnityEngine.Vector4(0, 0, m_pagePanel.width * .2f, height));
            itemsPerPageLbl.verticalAlignment = UIVerticalAlignment.Middle;
            itemsPerPageLbl.text          = Locale.Get("K45_CMNS_ITEMSPERPAGE");
            itemsPerPageLbl.minimumSize   = new Vector2(m_pagePanel.width * .2f, height);
            itemsPerPageLbl.textAlignment = UIHorizontalAlignment.Right;
            KlyteMonoUtils.LimitWidthAndBox(itemsPerPageLbl, m_pagePanel.width * .2f);

            m_itemsPerPageDD = UIHelperExtension.CloneBasicDropDownNoLabel(
                m_allowedItemCount.Select(x => x.ToString("0")).ToArray(),
                (idx) =>
            {
                if (idx >= 0)
                {
                    SetItemsPerpage(m_allowedItemCount[idx]);
                }
            },
                m_pagePanel);
            m_itemsPerPageDD.area = new Vector4(0, 0, m_pagePanel.width * .1f, height);


            KlyteMonoUtils.CreateUIElement(out m_firstPage, m_pagePanel.transform, "firstPage", new UnityEngine.Vector4(0, 0, m_pagePanel.width * .05f, height));
            KlyteMonoUtils.InitButton(m_firstPage, false, "ButtonMenu");
            m_firstPage.text          = "<<";
            m_firstPage.eventClicked += (x, y) => GoToPage(1);
            KlyteMonoUtils.CreateUIElement(out m_backPage, m_pagePanel.transform, "backPage", new UnityEngine.Vector4(0, 0, m_pagePanel.width * .05f, height));
            KlyteMonoUtils.InitButton(m_backPage, false, "ButtonMenu");
            m_backPage.text          = "<";
            m_backPage.eventClicked += (x, y) => GoToPage(m_currentPage - 1);

            KlyteMonoUtils.CreateUIElement(out m_pageInput, m_pagePanel.transform, "firstPage", new UnityEngine.Vector4(0, 0, m_pagePanel.width * .05f, height));
            KlyteMonoUtils.UiTextFieldDefaults(m_pageInput);
            m_pageInput.horizontalAlignment = UIHorizontalAlignment.Right;
            m_pageInput.numericalOnly       = true;
            m_pageInput.allowNegative       = false;
            m_pageInput.allowFloats         = false;
            m_pageInput.verticalAlignment   = UIVerticalAlignment.Top;
            m_pageInput.padding.top         = (int)((height - m_pageInput.font.size) / 2f);
            m_pageInput.submitOnFocusLost   = true;
            m_pageInput.eventTextSubmitted += (x, y) =>
            {
                if (int.TryParse(y, out int page))
                {
                    GoToPage(page);
                }
                else
                {
                    m_pageInput.text = m_currentPage.ToString("0");
                }
            };


            KlyteMonoUtils.CreateUIElement(out m_totalPage, m_pagePanel.transform, "firstPage", new UnityEngine.Vector4(0, 0, m_pagePanel.width * .05f, height));
            m_totalPage.prefix            = "/";
            m_totalPage.verticalAlignment = UIVerticalAlignment.Middle;
            m_totalPage.minimumSize       = new Vector2(m_pagePanel.width * .05f, height);
            KlyteMonoUtils.LimitWidthAndBox(m_totalPage, m_pagePanel.width * .05f);

            KlyteMonoUtils.CreateUIElement(out m_nextPage, m_pagePanel.transform, "nextPage", new UnityEngine.Vector4(0, 0, m_pagePanel.width * .05f, height));
            KlyteMonoUtils.InitButton(m_nextPage, false, "ButtonMenu");
            m_nextPage.text          = ">";
            m_nextPage.eventClicked += (x, y) => GoToPage(m_currentPage + 1);
            KlyteMonoUtils.CreateUIElement(out m_lastPage, m_pagePanel.transform, "lastPage", new UnityEngine.Vector4(0, 0, m_pagePanel.width * .05f, height));
            KlyteMonoUtils.InitButton(m_lastPage, false, "ButtonMenu");
            m_lastPage.text          = ">>";
            m_lastPage.eventClicked += (x, y) => GoToPage(TotalPages);

            SetNewLength(0);
            GoToPage(1);
        }
Ejemplo n.º 3
0
        public static Texture2D RenderSpriteLine(UIDynamicFont font, UITextureAtlas atlas, string spriteName, Color bgColor, string text, float textScale = 1)
        {
            UITextureAtlas.SpriteInfo spriteInfo = atlas[spriteName];
            if (spriteInfo == null)
            {
                CODebugBase <InternalLogChannel> .Warn(InternalLogChannel.UI, "Missing sprite " + spriteName + " in " + atlas.name);

                return(null);
            }
            else
            {
                textScale *= 2;

                Texture2D texture        = atlas.texture;
                float     calcHeight     = font.size * textScale * 2;
                float     calcProportion = spriteInfo.region.width * texture.width / (spriteInfo.region.height * texture.height);
                float     calcWidth      = Mathf.CeilToInt(calcHeight * calcProportion);

                int height = Mathf.CeilToInt(calcHeight);
                int width  = Mathf.CeilToInt(calcWidth);

                float textureScale = height / (spriteInfo.region.height * texture.height);

                LogUtils.DoLog($"height = {height} - width = {width} -  renderer.pixelRatio = 1 - textureScale = {height} / {(spriteInfo.region.height * texture.height)}");

                var   size        = new Vector3(width, height);
                float borderWidth = textScale * 3;

                Vector2 textDimensions = MeasureTextWidth(font, text, textScale, out Vector2 yBounds);
                float   borderBottom   = Mathf.Max(0, (spriteInfo.border.bottom * textScale * 2) + Mathf.Min(0, yBounds.x));
                var     textAreaSize   = new Vector4((spriteInfo.border.left * textScale * 2) + borderWidth, borderBottom + borderWidth, width - (spriteInfo.border.horizontal * textScale * 2) - borderWidth, height - (spriteInfo.border.top * textScale * 2) - borderBottom - borderWidth);

                float multipler = Mathf.Min(Mathf.Min(3.5f, textAreaSize.z / textDimensions.x), Mathf.Min(3.5f, textAreaSize.w / textDimensions.y));
                if (multipler > 1)
                {
                    textScale     *= 1 + ((multipler - 1) / 2.1f);
                    multipler      = 1;
                    textDimensions = MeasureTextWidth(font, text, textScale, out yBounds);
                }

                var imageSize = new Vector2(Mathf.NextPowerOfTwo((int)Mathf.Max(textDimensions.x * multipler, width)), Mathf.NextPowerOfTwo((int)Mathf.Max(textDimensions.y, height)));


                var tex = new Texture2D((int)imageSize.x, (int)imageSize.y, TextureFormat.ARGB32, false);
                tex.SetPixels(new Color[(int)(imageSize.x * imageSize.y)]);


                var texText = new Texture2D((int)textDimensions.x, (int)textDimensions.y, TextureFormat.ARGB32, false);
                texText.SetPixels(new Color[(int)(textDimensions.x * textDimensions.y)]);

                Color contrastColor = KlyteMonoUtils.ContrastColor(bgColor);

                Vector2 position = RenderSprite(atlas, spriteName, contrastColor, tex, textureScale);
                RenderSprite(atlas, spriteName, bgColor, tex, null, tex.height - (int)(borderWidth * 2), null, new Vector2((textScale / 2) - 0.5f, (textScale / 2) - 0.5f), (a, b) =>
                {
                    if (b.a == 1)
                    {
                        return(b);
                    }

                    if (b.a == 0)
                    {
                        return(a);
                    }

                    float totalAlpha = a.a + b.a;
                    return((a * (1 - b.a)) + (b * b.a));
                });
                Vector2 posText = position + VectorUtils.XY(textAreaSize) + new Vector2((textAreaSize.z / 2) - (textDimensions.x * multipler / 2) + 1, (textAreaSize.w / 2) - (textDimensions.y / 2) - (yBounds.x / 2));

                RenderText(font, text, new Vector3(0, -yBounds.x), textScale, contrastColor, bgColor, texText);

                if (multipler < 1)
                {
                    TextureScaler.scale(texText, (int)(texText.width * multipler), texText.height);
                }
                MergeTextures(tex, texText.GetPixels(), (int)posText.x, (int)posText.y, texText.width, texText.height, false);
                UnityEngine.Object.Destroy(texText);
                tex.Apply();

                return(tex);
            }
        }