public static LinearGradient Build(AssetManager manager, GradientAsset asset, float size)
        {
            string filePath = System.IO.Path.Combine(GRADIENT_DIR, asset.ToString() + FILE_EXTENSION);

            var test  = manager.List("fonts/");
            var test2 = manager.List("gradients/");
            var test3 = manager.List("Assets/gradients/");

            var gradient = OpenAndReadGradient(manager, filePath);

            return(new LinearGradient(0, 0, 0, 0, gradient.GetColorAsArgb(), gradient.GetColorPositions(), Shader.TileMode.Mirror));
        }
        public static GradientDrawable BuildDrawable(AssetManager manager, GradientAsset asset)
        {
            string filePath = IOPath.Combine(GRADIENT_DIR, asset.ToString() + FILE_EXTENSION);

            var gradient = manager.OpenAndReadJson <Gradient>(filePath);

            //var result = test.GetBottomNavigationItemView(2).GetChildAt<AppCompatImageView>(0);
            //result.Background = GetDrawable(R.Drawable.bg_gradient_soft);

            var shape = new GradientDrawable(GradientDrawable.Orientation.BlTr, gradient.GetColorAsArgb());

            return(shape);
        }
        public static LinearGradient BuildGradient(AssetManager manager, GradientAsset asset, double length)
        {
            string filePath = IOPath.Combine(GRADIENT_DIR, asset.ToString() + FILE_EXTENSION);

            var gradient = manager.OpenAndReadJson <Gradient>(filePath);

            //double angleInRadians = MathHelper.ConvertToRadians(gradient.Angle);

            float endX = (float)(Math.Cos(gradient.Angle) * length);
            float endY = (float)(Math.Sin(gradient.Angle) * length);

            int[] colors = gradient.GetColorAsArgb().ToArray();
            //float[] positions = gradient.GetColorPositions().ToArray();

            //return new LinearGradient(0, 0, endX, endY, gradient.GetColorAsArgb(), gradient.GetColorPositions(), Shader.TileMode.Mirror);
            return(new LinearGradient(0, 0, endX, endY, Color.ParseColor(gradient.Colors.ToArray()[0]), Color.ParseColor(gradient.Colors.ToArray()[1]), Shader.TileMode.Mirror));
        }
Example #4
0
        public static TextView SetForegroundGradient(this TextView view, AssetManager mgr, GradientAsset gradient)
        {
            view.Paint.SetShader(GradientFactory.BuildGradient(mgr, gradient, view.TextSize));

            return(view);
        }
Example #5
0
    void Start()
    {
        instance = this;
        allChar  = Resources.LoadAll <Character>("classes");
        allHaz   = Resources.LoadAll <Hazard>("hazards");
        List <int> availLevels = new List <int>();

        classOpts = new List <Dropdown.OptionData>();
        foreach (Character c in allChar)
        {
            if (!classOpts.Any(ooo => ooo.text == c.name))
            {
                Dropdown.OptionData opt = new Dropdown.OptionData(c.name);
                classOpts.Add(opt);
            }
            if (!availLevels.Contains(c.level))
            {
                availLevels.Add(c.level);
            }
        }
        levelOpts = new List <Dropdown.OptionData>();
        availLevels.Sort();
        foreach (int lv in availLevels)
        {
            levelOpts.Add(new Dropdown.OptionData(lv.ToString()));
        }
        diffDropdown.onValueChanged.AddListener(v => {
            diffSetting = v;
        });
        Transform legend = topBar.Find("Legend");

        legend.Find("Hover").GetComponent <Image>().AddHover(p => {
            ShowTooltip(legend.transform.position + new Vector3(-50, -100, 0), "Indicates an approximate result of making a roll against challenges of the indicated difficulty as an average between all possible outcomes (nat-1 to nat-20).\nE.g. if only two results are possible (fail or success) then the average will be a blend between the two (yellow).", 4, 1, false);
        });
        legend.Find("Hover2").GetComponent <Image>().AddHover(p => {
            ShowTooltip(legend.transform.position + new Vector3(-50, -100, 0), "Black: Critical Failure\nRed: Failure\nGreen: Success\nBlue: Critical Success\nBlend: Some mixture.", 4, 1, false);
        });
        Color[] col = new Color[20];
        for (int i = 0; i < 20; i++)
        {
            col[i] = gradient.gradient.Evaluate((float)i / 19);
        }
        legend.GetComponentInChildren <BreakdownBar>().SetBitColors(col);
        legend.GetComponentInChildren <Dropdown>().onValueChanged.AddListener(v => {
            gradient     = gradients[v];
            Color[] cols = new Color[20];
            for (int i = 0; i < 20; i++)
            {
                cols[i] = gradient.gradient.Evaluate((float)i / 19);
            }
            legend.GetComponentInChildren <BreakdownBar>().SetBitColors(cols);
            foreach (GameObject window in resultWindow)
            {
                window.GetComponent <ResultWindow>().RefreshColor();
            }
        });
        ToggleDropdown togg = topBar.Find("SourceDropdown").GetComponent <ToggleDropdown>();

        togg.onValueChanged.AddListener(_ => {
            allMons = new Monster[0];
            foreach (int i in togg.activeValues)
            {
                Dropdown.OptionData dat = togg.options[i];
                Monster[] mons          = Resources.LoadAll <Monster>("specific_monsters/" + dat.text.Replace(" ", "_").ToLower());
                int olen = allMons.Length;
                Array.Resize <Monster>(ref allMons, olen + mons.Length);
                Array.Copy(mons, 0, allMons, olen, mons.Length);
            }
        });
        togg.value = 1;
        //legend.GetComponentInChildren<BreakdownBar>().SetNotches(-1, -1);
        Debug.Log(allMons.Length);
        foreach (MStatAttr atr in Enum.GetValues(typeof(MStatAttr)))
        {
            if (atr == MStatAttr.DISABLE)
            {
                continue;
            }
            int ext  = 0;
            int high = 0;
            int mod  = 0;
            int low  = 0;
            int ter  = 0;
            int wrst = 0;
            int bnk  = 0;
            foreach (Monster mon in allMons)
            {
                MTEML teml = mon.GetAttribute(atr);
                switch (teml)
                {
                case MTEML.THE_WORST:
                    wrst++;
                    break;

                case MTEML.TERRIBLE:
                    ter++;
                    break;

                case MTEML.LOW:
                    low++;
                    break;

                case MTEML.MODERATE:
                    mod++;
                    break;

                case MTEML.HIGH:
                    high++;
                    break;

                case MTEML.EXTREME:
                    ext++;
                    break;

                case MTEML.JUST_BONKERS:
                    bnk++;
                    break;
                }
            }
            Debug.Log(atr.ToString() +
                      "\nwrst: " + wrst +
                      "\nter: " + ter +
                      "\nlow: " + low +
                      "\nmod: " + mod +
                      "\nhigh: " + high +
                      "\next: " + ext +
                      "\nbnk: " + bnk);
        }
        topBar.Find("DifficultySelect/UpdateBtn").GetComponent <Button>().onClick.AddListener(() => {
            foreach (GameObject window in resultWindow)
            {
                window.GetComponent <ResultWindow>().UpdateDifficulty();
            }
        });
        topBar.Find("CycleToggle").GetComponent <Toggle>().onValueChanged.AddListener(b => {
            if (b)
            {
                StartCoroutine(CycleLevelValues());
            }
        });
        forbidExtreme = false;
        topBar.Find("DifficultySelect/ExtremeToggle").GetComponent <Toggle>().onValueChanged.AddListener(b => {
            forbidExtreme = b;
        });
    }
    public void DisplayResult(StatisticsResults result, GradientAsset gradient)
    {
        lastResult = result;
        if (result == null)
        {
            return;
        }
        BreakdownBar bar = transform.Find("Attack").GetComponentInChildren <BreakdownBar>();

        Color[] cols = new Color[20];
        for (int i = 0; i < 20; i++)
        {
            if (result.attacktot > 0)
            {
                float v = (result.attack[i] / 3f) / result.attacktot;
                cols[i] = gradient.gradient.Evaluate(v);
            }
            else
            {
                cols[i]           = new Color(.5f, .5f, .5f, 1);
                result.attack[20] = result.attack[21] = -1;
            }
        }
        bar.SetBitColors(cols);
        bar.SetNotches((int)result.attack[20], (int)result.attack[21]);
        bar  = transform.Find("Abilities").GetComponentInChildren <BreakdownBar>();
        cols = new Color[20];
        for (int i = 0; i < 20; i++)
        {
            if (result.spellDCtot > 0)
            {
                float v = (result.classSpellDC[i] / 3f) / result.spellDCtot;
                cols[i] = gradient.gradient.Evaluate(1 - v);
            }
            else
            {
                cols[i] = new Color(.5f, .5f, .5f, 1);
                result.classSpellDC[20] = result.classSpellDC[21] = -1;
            }
        }
        bar.SetBitColors(cols);
        bar.SetNotches((int)result.classSpellDC[20], (int)result.classSpellDC[21]);
        bar  = transform.Find("Fort").GetComponentInChildren <BreakdownBar>();
        cols = new Color[20];
        for (int i = 0; i < 20; i++)
        {
            if (result.forttot > 0)
            {
                float v = (result.fort[i] / 3f) / result.forttot;
                cols[i] = gradient.gradient.Evaluate(v);
            }
            else
            {
                cols[i]         = new Color(.5f, .5f, .5f, 1);
                result.fort[20] = result.fort[21] = -1;
            }
        }
        bar.SetBitColors(cols);
        bar.SetNotches((int)result.fort[20], (int)result.fort[21]);
        bar  = transform.Find("Refx").GetComponentInChildren <BreakdownBar>();
        cols = new Color[20];
        for (int i = 0; i < 20; i++)
        {
            if (result.refxtot > 0)
            {
                float v = (result.refx[i] / 3f) / result.refxtot;
                cols[i] = gradient.gradient.Evaluate(v);
            }
            else
            {
                cols[i]         = new Color(.5f, .5f, .5f, 1);
                result.refx[20] = result.refx[21] = -1;
            }
        }
        bar.SetBitColors(cols);
        bar.SetNotches((int)result.refx[20], (int)result.refx[21]);
        bar  = transform.Find("Will").GetComponentInChildren <BreakdownBar>();
        cols = new Color[20];
        for (int i = 0; i < 20; i++)
        {
            if (result.willtot > 0)
            {
                float v = (result.will[i] / 3f) / result.willtot;
                cols[i] = gradient.gradient.Evaluate(v);
            }
            else
            {
                cols[i]         = new Color(.5f, .5f, .5f, 1);
                result.will[20] = result.will[21] = -1;
            }
        }
        bar.SetBitColors(cols);
        bar.SetNotches((int)result.will[20], (int)result.will[21]);
        bar  = transform.Find("Armor").GetComponentInChildren <BreakdownBar>();
        cols = new Color[20];
        for (int i = 0; i < 20; i++)
        {
            if (result.armortot > 0)
            {
                float v = (result.armorClass[i] / 3f) / result.armortot;
                cols[i] = gradient.gradient.Evaluate(1 - v);
            }
            else
            {
                cols[i] = new Color(.5f, .5f, .5f, 1);
                result.armorClass[20] = result.armorClass[21] = -1;
            }
        }
        bar.SetBitColors(cols);
        bar.SetNotches((int)result.armorClass[20], (int)result.armorClass[21]);
        bar  = transform.Find("Perception").GetComponentInChildren <BreakdownBar>();
        cols = new Color[20];
        for (int i = 0; i < 20; i++)
        {
            if (result.perceptiontot > 0)
            {
                float v = (result.perception[i] / 3f) / (result.perceptiontot);
                cols[i] = gradient.gradient.Evaluate(v);
            }
            else
            {
                cols[i] = new Color(.5f, .5f, .5f, 1);
                result.perception[20] = result.perception[21] = -1;
            }
        }
        bar.SetBitColors(cols);
        bar.SetNotches((int)result.perception[20], -1);
        bar  = transform.Find("Skill1").GetComponentInChildren <BreakdownBar>();
        cols = new Color[20];
        for (int i = 0; i < 20; i++)
        {
            if (result.totSkills > 0)
            {
                float v = (result.skillSpecialist[i] / 3f) / (result.totSkills);
                cols[i] = gradient.gradient.Evaluate(v);
            }
            else
            {
                cols[i] = new Color(.5f, .5f, .5f, 1);
                result.skillSpecialist[20] = result.skillSpecialist[21] = -1;
            }
        }
        bar.SetBitColors(cols);
        bar.SetNotches((int)result.skillSpecialist[20], (int)result.skillSpecialist[21]);
        bar  = transform.Find("Skill2").GetComponentInChildren <BreakdownBar>();
        cols = new Color[20];
        for (int i = 0; i < 20; i++)
        {
            if (result.totSkills > 0)
            {
                float v = (result.skillDecent[i] / 3f) / (result.totSkills);
                cols[i] = gradient.gradient.Evaluate(v);
            }
            else
            {
                cols[i] = new Color(.5f, .5f, .5f, 1);
                result.skillDecent[20] = result.skillDecent[21] = -1;
            }
        }
        bar.SetBitColors(cols);
        bar.SetNotches((int)result.skillDecent[20], (int)result.skillDecent[21]);
        bar  = transform.Find("Skill3").GetComponentInChildren <BreakdownBar>();
        cols = new Color[20];
        for (int i = 0; i < 20; i++)
        {
            if (result.totSkills > 0)
            {
                float v = (result.skillDabbler[i] / 3f) / (result.totSkills);
                cols[i] = gradient.gradient.Evaluate(v);
            }
            else
            {
                cols[i] = new Color(.5f, .5f, .5f, 1);
                result.skillDabbler[20] = result.skillDabbler[21] = -1;
            }
        }
        bar.SetBitColors(cols);
        bar.SetNotches((int)result.skillDabbler[20], (int)result.skillDabbler[21]);
    }