Пример #1
0
        public static void UpdateRewardGrid(string newRewardId = null)
        {
            guiScript?.rewardGrid.Clear();

            if (Plugin.Instance?.twitchRewards == null)
            {
                return;
            }

            foreach (Reward reward in Plugin.Instance.twitchRewards.Data)
            {
                try
                {
                    var customReward = Plugin.Instance.twitchCustomRewards.Data.Exists(x => x.Id == reward.Id);

                    //Log.Info($"Reward: {reward.Title} - custom: {customReward}");

                    var title          = reward.Title;
                    var data           = RewardsConfig.Get(reward.Id);
                    var color          = Colors.FromHex(reward.BackgroundColor);
                    var texture        = TextureLoader.LoadFromURL((reward.Image ?? reward.DefaultImage).Url4x);
                    var rewardGridItem = new RewardGridItem(reward.Id, title, color, texture, customReward, data);

                    bool isNew = newRewardId == reward.Id;

                    guiScript.rewardGrid.Add(rewardGridItem, isNew);
                }
                catch (Exception e)
                {
                    Log.Error(e.ToString());
                    //Log.Warning($"Reward image unavailable: {reward.Title}");
                }
            }
        }
Пример #2
0
    public GameObject Add(RewardGridItem item, bool isNew = false)
    {
        var go = Instantiate(rewardButton, gameObject.transform);

        var script = go.GetComponent <RewardButton>();

        script.rewardSettings = rewardSettings;
        script.reward         = item;

        var bgImage = go.GetComponent <Image>();

        bgImage.color = item.color;

        var actionIndex = item.data?["Action"].Value <int>();

        if (actionIndex == null || actionIndex == 0)
        {
            bgImage.color = new Color32(0, 0, 0, 127);
        }

        if (item.customReward)
        {
            script.managedBadge.gameObject.SetActive(true);
        }

        item.image = go.transform.GetChild(0).GetComponent <Image>();
        var rect   = new Rect(0, 0, item.imageTexture.width, item.imageTexture.height);
        var sprite = Sprite.Create(item.imageTexture, rect, new Vector2(0.5f, 0.5f));

        item.image.preserveAspect = true;
        item.image.sprite         = sprite;

        var text = go.transform.GetChild(1).GetComponent <Text>();

        text.text = item.title;

        if (text.text.Length > 25)
        {
            text.text = text.text.Substring(0, 25).TrimEnd() + ". . .";
        }

        if (isNew)
        {
            rewardSettings.SetReward(item);
        }

        return(go);
    }
Пример #3
0
    public void SetReward(RewardGridItem reward)
    {
        SetActive(true);

        this.reward  = reward;
        title.text   = reward.title;
        image.sprite = reward.image.sprite;

        var action = reward.data?["Action"]?.Value <int>();

        actionsDropdown.value = action ?? 0;
        actionsDropdown.Select();

        if (action != null)
        {
            currentSettingsPanel.SetData(reward.data);
        }
    }