Beispiel #1
0
    // --------
    void ShowRadarPos(GUIBase_Widget targetWidget, Vector3 targetPos, Vector3 centerPos, Vector3 centerDir)
    {
        Vector3 dirToEnemy = targetPos - centerPos;

        dirToEnemy.y = 0;
        float   distance = dirToEnemy.magnitude;
        Vector3 finalPos;

        distance /= RadarRange;
        if (distance > 1.0f)
        {
            distance = Mathf.Clamp(1.0f + (distance - 1.0f) / 21f, 0, 1.1f);
        }

        dirToEnemy.Normalize();
        float angle = Mathf.Atan2(-dirToEnemy.z, dirToEnemy.x) - Mathf.Atan2(-centerDir.z, centerDir.x);

        finalPos  = new Vector3(Mathf.Sin(angle), -Mathf.Cos(angle), 0);
        finalPos *= distance * RadarScreenRadius + RadarCenterRadius;
        finalPos += RadarCenter.transform.position;

        Transform targetTrans = targetWidget.transform;

        if (targetTrans.position != finalPos)
        {
            targetTrans.position = finalPos;
            targetWidget.SetModify(true);
        }

        if (!targetWidget.IsVisible())
        {
            targetWidget.Show(true, true);
        }
    }
Beispiel #2
0
    private static bool ProceedLayoutAndButton(string layoutName, string buttonName, bool probeOnly = false)
    {
        GUIBase_Layout layout = MFGuiManager.Instance.GetLayout(layoutName);

        if (null != layout)
        {
            if (layout.IsEnabled(true) && layout.IsVisible(false))
            {
                GUIBase_Widget widget = layout.GetWidget(buttonName);

                if (null != widget)
                {
                    if (widget.IsEnabled(true) && widget.IsVisible(false))
                    {
                        if (!probeOnly)
                        {
                            m_CoroutineRunning = true;

                            if (null != Game.Instance)
                            {
                                Game.Instance.StartCoroutine(AutoClick(widget));
                            }
                        }

                        return(true);
                    }
                }
            }
        }

        return(false);
    }
Beispiel #3
0
    public bool SetTextAndAdjustBackground(string text, GUIBase_Label label, GUIBase_Widget background, float BaseSize, float TextScale)
    {
        float CorrectionPerChar = 35 * (1 - TextScale);       //15f;
        bool  modif             = false;

        if (label.GetText() != text)
        {
            label.SetNewText(text);
            modif = true;
        }
        int   len      = text.Length;
        float textSize = label.textSize.x - CorrectionPerChar * (float)len;
        float xScale   = 0.2f + textSize / BaseSize;

        if ((Mathf.Abs(background.transform.localScale.x - xScale) > 0.01f) || (Mathf.Abs(label.transform.localScale.y - TextScale) > 0.01f))
        {
            background.transform.localScale = new Vector3(xScale, 1.0f, 1.0f);
            label.transform.localScale      = new Vector3(TextScale / xScale, TextScale, TextScale);
            modif = true;
        }

        if (!background.IsVisible() || !label.Widget.IsVisible())
        {
            background.Show(true, true);
            label.Widget.Show(true, true);
        }

        return(modif);
    }
Beispiel #4
0
 //---------------------------------------------------------
 void LateUpdate()
 {
     if (m_Dirty == true && m_Widget.IsVisible())
     {
         ShowSwitchButton(true);
         m_Dirty = false;
     }
 }
Beispiel #5
0
    protected override void OnHide()
    {
        foreach (var crosshair in m_Crosshair)
        {
            if (crosshair != null)
            {
                crosshair.Widget.Show(false, true);
            }
        }

        m_CrosshairHit.Widget.Show(false, false);
        m_EnemyLabel.Show(false, true);

        if (m_PrepareForFire.IsVisible())
        {
            m_PrepareForFire.Show(false, true);
        }

        base.OnHide();
    }
Beispiel #6
0
    //---------------------------------------------------------
    void RegenerateSprites()
    {
        if (IsDataRegenerationNeaded() == false || m_Widget.IsVisible() == false)
        {
            return;
        }

        // regenerate runtime data for new text...
        GenerateRunTimeData();

        string text = Text;

        if (string.IsNullOrEmpty(text) == false && m_Uppercase)
        {
            text = text.ToUpper();
        }

        // destroy old text if any exist...
        m_Widget.PrepareSprites(string.IsNullOrEmpty(text) == true ? 0 : text.Length);

        if (string.IsNullOrEmpty(text) == false && text.Length > 0)
        {
            Vector3 scale = Vector3.one;

            Texture texture = fontTexture;

            int texWidth  = texture ? texture.width : 1;
            int texHeight = texture ? texture.height : 1;

            float lineHeight = m_LineSize.y * texHeight;
            float lineWidth  = m_LineSize.x;
            float widthMult  = m_Widget.GetWidth() / lineWidth;

            // compute down scale if needed
            if (m_Boundaries.IsEmpty() == false)
            {
                Rect clientRect = GetRect();
                Rect rect       = m_Boundaries.Intersect(clientRect);

                float scaleX = rect.width / clientRect.width;
                float scaleY = rect.height / clientRect.height;

                if (scaleY > scaleX)
                {
                    scaleY = scaleX;
                }
                else
                {
                    scaleX = scaleY;
                }

                scale.x *= scaleX;
                scale.y *= scaleY;
            }

            // setup cursor ...
            Vector2 cursor    = GetLeftUpPos(m_Widget.GetOrigPos(), scale);
            float   lineBegin = cursor.x;
            cursor.y += lineHeight * scale.y * 0.5f;         // textHeight*0.5f;

            bool multiline = IsMultiline(text);

            if (multiline == true)
            {
                cursor = SetupCursorForTextAlign(cursor, text, 0, m_Alignment, font, lineBegin, lineWidth, widthMult * scale.x);
            }

            for (int i = 0; i < text.Length; ++i)
            {
                int character = text[i];
                switch (character)
                {
                case '\n':
                    if (multiline == true)
                    {
                        cursor = SetupCursorForTextAlign(cursor, text, i + 1, m_Alignment, font, lineBegin, lineWidth, widthMult * scale.x);
                    }
                    else
                    {
                        cursor.x = lineBegin;
                    }

                    cursor.y = cursor.y + (lineHeight + lineSpace * texHeight) * scale.y;
                    m_Widget.SetTextureCoords(i, 0.0f, 0.0f, 0.0f, 0.0f);
                    m_Widget.UpdateSpritePosAndSize(i, 0, -Screen.height, 1.0f, 1.0f);
                    m_Widget.ShowSprite(i, false);
                    break;

                default:
                {
                    if (useFontEx == false)
                    {
                        Vector2 inTexPos  = new Vector2();
                        Vector2 inTexSize = new Vector2();
                        float   width;

                        GUIBase_Font fontOld = font as GUIBase_Font;
                        fontOld.GetCharDscr(character, out width, ref inTexPos, ref inTexSize);
                        width *= widthMult;

                        int texU = (int)(texWidth * inTexPos.x);
                        int texV = (int)(texHeight * inTexPos.y);
                        int texW = (int)(texWidth * inTexSize.x);
                        int texH = (int)(texHeight * inTexSize.y);

                        cursor.x += 0.5f * width * scale.x;
                        m_Widget.SetTextureCoords(i, texU, texV, texW, texH);
                        m_Widget.UpdateSpritePosAndSize(i, cursor.x, cursor.y, width, lineHeight);
                        cursor.x += 0.5f * width * scale.x;
                    }
                    else
                    {
                        float width;
                        Rect  spriteRect, texRect;

                        GUIBase_FontEx fontEx = font as GUIBase_FontEx;

                        if (fontEx.GetCharDescription(text[i], out width, out spriteRect, out texRect, false, false))
                        {
                            width *= widthMult;

                            Vector2 inCharSize = new Vector2(spriteRect.width * scale.x, spriteRect.height /*****/ * texHeight * scale.y);
                            // TODO :: rewite without texHeight...
                            Vector2 inCharCenter = cursor + new Vector2(spriteRect.center.x * scale.x, 0.0f);

                            m_Widget.SetTextureCoords(i, (int)texRect.x, (int)texRect.y, (int)texRect.width, (int)texRect.height);
                            m_Widget.UpdateSpritePosAndSize(i, inCharCenter.x, inCharCenter.y, inCharSize.x, inCharSize.y);
                            cursor.x += width * scale.x;
                        }
                    }
                    break;
                }
                }
            }
        }

        // we have to force widget update.
        m_RegenerationNeeded = false;
        m_Widget.SetModify();
    }
Beispiel #7
0
    //---------------------------------------------------------
    void RegenerateSprites()
    {
        if (m_RegenerateSprites == false || m_Widget.IsVisible() == false)
        {
            return;
        }

        if (m_Font == null)
        {
            m_Font = MFFontManager.GetFont(m_FontName) as GUIBase_FontEx;
            if (m_Font == null)
            {
                Debug.LogError(gameObject.GetFullName() + " Can't load font with name " + m_FontName);
                return;
            }
        }

        if (m_TextID > 0)
        {
            m_Text = TextDatabase.instance[m_TextID];
        }

        // destroy old text if any exist...
        int maxSprites = text != null && text.Length > 0 ? Mathf.CeilToInt(text.Length * 0.1f) * 10 : 0;

        m_Widget.PrepareSprites(maxSprites);

        if (text != null && text.Length > 0)
        {
            Vector3 scale = transform.lossyScale;
            scale = Vector3.one;

            // setup cursor ...
            Vector2 leftUpPos = new Vector2(m_Widget.GetOrigPos().x - m_Widget.GetWidth() * 0.5f * scale.x,
                                            m_Widget.GetOrigPos().y - m_Widget.GetHeight() * 0.5f * scale.y);
            Vector2 cursor = leftUpPos;

            float maxLineSize = m_Widget.GetWidth() * scale.x;

            scale.x = m_TextScale.x;
            scale.y = m_TextScale.y;

            List <TextLine> textLines = GetLines(text, m_Font, alignment, maxLineSize, scale, lineSpace, IsForTextField);
            if (textLines == null || textLines.Count <= 0)
            {
                return;
            }

            float fontHeight = m_Font.GetFontHeight();
            m_TextSize = new Vector2(m_Widget.GetWidth(), textLines.Count * fontHeight * scale.y + (textLines.Count - 1) * lineSpace * fontHeight * scale.y);

            float width;
            Rect  spriteRect, texRect;

            int spriteIdx = 0;
            foreach (TextLine line in textLines)
            {
                cursor = leftUpPos + line.m_Offset;

                for (int i = line.m_StartIndex; i < line.m_EndIndex; ++i)
                {
                    int character = text[i];

                    if (!IsForTextField && character == ' ')
                    {
                        cursor.x += line.m_SpaceWidth;
                        continue;
                    }
                    switch (character)
                    {
                    case '\n':
                        Debug.LogWarning("function GetLines doesn't work correctly");
                        break;

                    default:
                    {
                        if (m_Font.GetCharDescription(text[i], out width, out spriteRect, out texRect, false, false, false))
                        {
                            Vector2 inCharSize   = new Vector2(spriteRect.width * scale.x, spriteRect.height * scale.y);
                            Vector2 inCharCenter = cursor + new Vector2(spriteRect.center.x * scale.x, 0.0f);

                            m_Widget.SetTextureCoords(spriteIdx, (int)texRect.x, (int)texRect.y, (int)texRect.width, (int)texRect.height);
                            m_Widget.UpdateSpritePosAndSize(spriteIdx, inCharCenter.x, inCharCenter.y, inCharSize.x, inCharSize.y);
                            m_Widget.ShowSprite(spriteIdx, true);
                            cursor.x += width * scale.x;

                            spriteIdx++;
                        }
                        break;
                    }
                    }
                }
            }

            // hide all unused sprites
            while (spriteIdx < maxSprites)
            {
                m_Widget.SetTextureCoords(spriteIdx, 0.0f, 0.0f, 0.0f, 0.0f);
                m_Widget.UpdateSpritePosAndSize(spriteIdx, 0.0f, -Screen.height, 1.0f, 1.0f);
                m_Widget.ShowSprite(spriteIdx, false);
                spriteIdx++;
            }
        }

        // we have to force widget update.
        m_RegenerateSprites = false;
        m_Widget.SetModify();
    }
Beispiel #8
0
    //---------------------------------------------------------
    // Show/Hide all widgets
    public void ShowImmediate(bool showFlag, bool playAnimAndSound = true)
    {
        // Animation, sound
        if (showFlag)
        {
            Visible = true;

            if (m_InAnimation && playAnimAndSound && m_Anim != null)
            {
                StopAnim(m_Anim);

                m_Anim.clip = m_InAnimation;
                PlayAnim(m_Anim, null, LayoutAnimFinished, (int)GUIBase_Platform.E_SpecialAnimIdx.E_SAI_INANIM);

                m_IsPlayingAnimation = true;
            }

            if (m_InSound && playAnimAndSound)
            {
                MFGuiManager.Instance.PlayOneShot(m_InSound);
            }

            //
            // Show widgets
            //

            if (m_Elements != null)
            {
                foreach (GUIBase_Element element in m_Elements)
                {
                    GUIBase_Widget widget = element as GUIBase_Widget;
                    if (widget != null)
                    {
                        widget.ShowImmediate(widget.m_VisibleOnLayoutShow || widget.IsVisible(), false);
                    }
                }
            }
        }
        else
        {
            if (m_OutAnimation && playAnimAndSound && m_Anim != null)
            {
                StopAnim(m_Anim);

                m_Anim.clip = m_OutAnimation;
                PlayAnim(m_Anim, null, LayoutAnimFinished, (int)GUIBase_Platform.E_SpecialAnimIdx.E_SAI_OUTANIM);

                m_IsPlayingAnimation = true;
            }

            if (m_OutSound && playAnimAndSound)
            {
                MFGuiManager.Instance.PlayOneShot(m_OutSound);
            }

            if (!m_OutAnimation || !playAnimAndSound)
            {
                // make layout invisible
                Visible = false;

                // hide widgets instantly

                if (m_Elements != null)
                {
                    foreach (GUIBase_Element element in m_Elements)
                    {
                        GUIBase_Widget widget = element as GUIBase_Widget;
                        if (widget != null)
                        {
                            widget.ShowImmediate(false, false);
                        }
                    }
                }
            }
        }
    }