Example #1
0
    protected virtual bool CreateStatsDisplay()
    {
        GameTextDatabase textDatabase     = null;
        int             totalStats        = 0;
        string          statName          = null;
        string          textName          = null;
        string          textValue         = null;
        float           statValueOriginal = 0f;
        float           statValueBase     = 0f;
        float           statEquippedSum   = 0f;
        bool            toDiscard         = false;
        GameObject      textObject        = null;
        RectTransform   textTransform     = null;
        SpritedStringUI textComponent     = null;
        Vector2         textDimensions    = Vector2.zero;
        Vector2         textScales        = Vector2.zero;
        Vector2         textPositionRates = Vector2.zero;
        TextAlignment   textAnchor        = TextAlignment.Center;

        textDatabase = GameTextDatabase.Instance;
        if (statsDisplayValid && (interfaceCanvasTrans != null) && (player != null) && (textDatabase != null))
        {
            if (statsDisplay.displayLevel && (levelObject == null))
            {
                statName          = textDatabase.GetSystemText(GameTextDatabase.TEXT_ID_PLAYER_LEVEL, ref toDiscard);
                statName         += " " + player.GetCurrentLevel();
                textScales        = statsDisplay.levelScales;
                textPositionRates = statsDisplay.levelPositionRates;
                textAnchor        = statsDisplay.levelAnchorAlignment;
                CreateTextDisplayObject("LevelDisplay", statName, textScales, textPositionRates, textAnchor, ref levelObject,
                                        ref levelTransform, ref levelText);
            }
            if (statObjects == null)
            {
                stats = statsDisplay.attributes;
                if (stats != null)
                {
                    totalStats = stats.Length;
                    if (totalStats > 0)
                    {
                        statObjects    = new GameObject[totalStats][];
                        statTransforms = new RectTransform[totalStats][];
                        statTexts      = new SpritedStringUI[totalStats][];
                        statValues     = new int[totalStats][];
                        GameObject[]      newStatObjects    = null;
                        RectTransform[]   newStatTransforms = null;
                        SpritedStringUI[] newStatTexts      = null;
                        int[]             newStatValues     = null;
                        int  statValue              = -1;
                        int  percentageBase         = 0;
                        int  percentageBaseLimited  = 0;
                        int  percentageEquip        = 0;
                        int  percentageEquipLimited = 0;
                        int  percentageTotal        = 0;
                        int  percentageTotalLimited = 0;
                        bool percentageBaseReady    = false;
                        bool percentageEquipReady   = false;
                        textAnchor = statsDisplay.attributeAnchorAlignment;
                        textScales = statsDisplay.attributeScales;
                        for (int i = 0; i < stats.Length; i++)
                        {
                            newStatObjects    = new GameObject[aspects.Length];
                            newStatTransforms = new RectTransform[aspects.Length];
                            newStatTexts      = new SpritedStringUI[aspects.Length];
                            newStatValues     = new int[aspects.Length];
                            statName          = textDatabase.GetEquipAttributeName(stats[i]);
                            player.GetStatValueSegments(stats[i], ref statValueOriginal, ref statValueBase, ref statEquippedSum);
                            percentageBaseReady  = false;
                            percentageEquipReady = false;
                            for (int j = 0; j < aspects.Length; j++)
                            {
                                switch (aspects[j])
                                {
                                case AttributeAspect.Name:
                                    textName          = "StatName" + statName;
                                    textValue         = statName;
                                    textPositionRates = statsDisplay.attributeNamePosRates[i];
                                    statValue         = -1;
                                    break;

                                case AttributeAspect.Base:
                                    textName = "StatBase" + statName;
                                    if (!percentageBaseReady)
                                    {
                                        percentageBase        = UsefulFunctions.GetPercentage(statValueBase, statValueOriginal);
                                        statValue             = percentageBase;
                                        percentageBaseLimited = (percentageBase > percentageLimit) ? percentageLimit : percentageBase;
                                        percentageBaseReady   = true;
                                    }
                                    textValue         = percentageBaseLimited.ToString();
                                    textPositionRates = statsDisplay.attributeBasePosRates[i];
                                    break;

                                case AttributeAspect.Equip:
                                    textName = "StatEquip" + statName;
                                    if (!percentageEquipReady)
                                    {
                                        percentageEquip        = UsefulFunctions.GetPercentage(statEquippedSum);
                                        statValue              = percentageEquip;
                                        percentageEquipLimited = (percentageEquip > percentageLimit) ? percentageLimit : percentageEquip;
                                        percentageEquipReady   = true;
                                    }
                                    textValue         = percentageEquipLimited.ToString();
                                    textPositionRates = statsDisplay.attributeEquipPosRates[i];
                                    break;

                                case AttributeAspect.Total:
                                    textName = "StatTotal" + statName;
                                    if (!percentageBaseReady)
                                    {
                                        percentageBase        = UsefulFunctions.GetPercentage(statValueBase, statValueOriginal);
                                        percentageBaseLimited = (percentageBase > percentageLimit) ? percentageLimit : percentageBase;
                                        percentageBaseReady   = true;
                                    }
                                    if (!percentageEquipReady)
                                    {
                                        percentageEquip        = UsefulFunctions.GetPercentage(statEquippedSum);
                                        percentageEquipLimited = (percentageEquip > percentageLimit) ? percentageLimit : percentageEquip;
                                        percentageEquipReady   = true;
                                    }
                                    percentageTotal        = percentageBase + percentageEquip;
                                    statValue              = percentageTotal;
                                    percentageTotalLimited = (percentageTotal > percentageLimit) ? percentageLimit : percentageTotal;
                                    textValue              = percentageTotalLimited.ToString();
                                    textPositionRates      = statsDisplay.attributeTotalPosRates[i];
                                    break;
                                }
                                CreateTextDisplayObject(textName, textValue, textScales, textPositionRates,
                                                        textAnchor, ref textObject, ref textTransform, ref textComponent);
                                newStatObjects[j]    = textObject;
                                newStatTransforms[j] = textTransform;
                                newStatTexts[j]      = textComponent;
                                newStatValues[j]     = statValue;
                            }
                            statObjects[i]    = newStatObjects;
                            statTransforms[i] = newStatTransforms;
                            statTexts[i]      = newStatTexts;
                            statValues[i]     = newStatValues;
                        }
                    }
                }
            }
            return(true);
        }
        return(false);
    }