<commit_before>using Assets.Scripts.Content;
using Assets.Scripts.UI;
using UnityEngine;
using System.Collections.Generic;


// Tokens are events that are tied to a token placed on the board
public class ShopInterface : Quest.BoardComponent
{
    GameObject panel;
    QuestData.Event eventData;

    // Construct with quest info and reference to Game
    public ShopInterface(List<string> items, Game gameObject, string eventName) : base(gameObject)
    {
        game = gameObject;
        if (!game.quest.shops.ContainsKey(eventName))
        {
            List<string> contentItems = new List<string>();
            foreach (string s in items)
            {
                if (game.quest.itemSelect.ContainsKey(s))
                {
                    contentItems.Add(game.quest.itemSelect[s]);
                }
            }
            game.quest.shops.Add(eventName, contentItems);
        }
        eventData = game.quest.qd.components[eventName] as QuestData.Event;
        // Find quest UI panel
        panel = GameObject.Find("QuestUIPanel");
        if (panel == null)
        {
            // Create UI Panel
            panel = new GameObject("QuestUIPanel");
            panel.tag = Game.BOARD;
            panel.transform.SetParent(game.uICanvas.transform);
            panel.transform.SetAsFirstSibling();
            panel.AddComponent<RectTransform>();
            panel.GetComponent<RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 0, Screen.height);
            panel.GetComponent<RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Right, 0, Screen.width);
        }
        Update();
    }

    public override QuestData.Event GetEvent()
    {
        return null;
    }

    // Clean up
    public override void Remove()
    {
        foreach (GameObject go in GameObject.FindGameObjectsWithTag(Game.SHOP))
            Object.Destroy(go);
        game.quest.activeShop = "";
    }

    public void Update()
    {
        Remove();
        game.quest.activeShop = eventData.sectionName;
        DrawButtons();
        DrawShopItems();
        DrawPartyItems();
        DrawGold();
    }

    public void DrawButtons()
    {
        float offset = 3;

        for (int i = 0; i < eventData.buttons.Count; i++)
        {
            StringKey label = new StringKey(null, EventManager.OutputSymbolReplace(eventData.buttons[i].Translate()), false);
            Color colour = Color.white;
            string colorRGB = ColorUtil.FromName(eventData.buttonColors[i]);
            // Check format is valid
            if ((colorRGB.Length != 7) || (colorRGB[0] != '#'))
            {
                Game.Get().quest.log.Add(new Quest.LogEntry("Warning: Button color must be in #RRGGBB format or a known name", true));
            }

            // Hexadecimal to float convert (0x00-0xFF -> 0.0-1.0)
            colour[0] = (float)System.Convert.ToInt32(colorRGB.Substring(1, 2), 16) / 255f;
            colour[1] = (float)System.Convert.ToInt32(colorRGB.Substring(3, 2), 16) / 255f;
            colour[2] = (float)System.Convert.ToInt32(colorRGB.Substring(5, 2), 16) / 255f;

            int tmp = i;
            UIElement ui = new UIElement(Game.SHOP);
            ui.SetLocation(UIScaler.GetHCenter(-17), offset, 10, 2);
            ui.SetText(label, colour);
            ui.SetFontSize(UIScaler.GetMediumFont());
            ui.SetButton(game.QuestStartEvent);
            new UIElementBorder(ui, colour);

            offset += 3;
        }
    }

    public void OnButton(int i)
    {
        if (GameObject.FindGameObjectWithTag(Game.DIALOG) != null) return;
        game.quest.Save();
        game.quest.eManager.EndEvent(eventData, i);
    }

    public void DrawShopItems()
    {
        UIElement ui = new UIElement(Game.SHOP);
        ui.SetLocation(UIScaler.GetHCenter(-5), 0.5f, 10, 2);
        ui.SetText(new StringKey("val", "BUY"));
        ui.SetFontSize(UIScaler.GetMediumFont());
        ui.SetFont(game.gameType.GetHeaderFont());
        new UIElementBorder(ui);

        UIElementScrollVertical scrollArea = new UIElementScrollVertical(Game.SHOP);
        scrollArea.SetLocation(UIScaler.GetHCenter(-5), 2.5f, 10, 24.5f);
        new UIElementBorder(scrollArea);<commit_msg>#733 Fixing shop events.<commit_after>using Assets.Scripts.Content;
using Assets.Scripts.UI;
using UnityEngine;
using System.Collections.Generic;


// Tokens are events that are tied to a token placed on the board
public class ShopInterface : Quest.BoardComponent
{
    GameObject panel;
    QuestData.Event eventData;

    // Construct with quest info and reference to Game
    public ShopInterface(List<string> items, Game gameObject, string eventName) : base(gameObject)
    {
        game = gameObject;
        if (!game.quest.shops.ContainsKey(eventName))
        {
            List<string> contentItems = new List<string>();
            foreach (string s in items)
            {
                if (game.quest.itemSelect.ContainsKey(s))
                {
                    contentItems.Add(game.quest.itemSelect[s]);
                }
            }
            game.quest.shops.Add(eventName, contentItems);
        }
        eventData = game.quest.qd.components[eventName] as QuestData.Event;
        // Find quest UI panel
        panel = GameObject.Find("QuestUIPanel");
        if (panel == null)
        {
            // Create UI Panel
            panel = new GameObject("QuestUIPanel");
            panel.tag = Game.BOARD;
            panel.transform.SetParent(game.uICanvas.transform);
            panel.transform.SetAsFirstSibling();
            panel.AddComponent<RectTransform>();
            panel.GetComponent<RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 0, Screen.height);
            panel.GetComponent<RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Right, 0, Screen.width);
        }
        Update();
    }

    public override QuestData.Event GetEvent()
    {
        return null;
    }

    // Clean up
    public override void Remove()
    {
        foreach (GameObject go in GameObject.FindGameObjectsWithTag(Game.SHOP))
            Object.Destroy(go);
        game.quest.activeShop = "";
    }

    public void Update()
    {
        Remove();
        game.quest.activeShop = eventData.sectionName;
        DrawButtons();
        DrawShopItems();
        DrawPartyItems();
        DrawGold();
    }

    public void DrawButtons()
    {
        float offset = 3;

        for (int i = 0; i < eventData.buttons.Count; i++)
        {
            StringKey label = new StringKey(null, EventManager.OutputSymbolReplace(eventData.buttons[i].Translate()), false);
            Color colour = Color.white;
            string colorRGB = ColorUtil.FromName(eventData.buttonColors[i]);
            // Check format is valid
            if ((colorRGB.Length != 7) || (colorRGB[0] != '#'))
            {
                Game.Get().quest.log.Add(new Quest.LogEntry("Warning: Button color must be in #RRGGBB format or a known name", true));
            }

            // Hexadecimal to float convert (0x00-0xFF -> 0.0-1.0)
            colour[0] = (float)System.Convert.ToInt32(colorRGB.Substring(1, 2), 16) / 255f;
            colour[1] = (float)System.Convert.ToInt32(colorRGB.Substring(3, 2), 16) / 255f;
            colour[2] = (float)System.Convert.ToInt32(colorRGB.Substring(5, 2), 16) / 255f;

            int tmp = i;
            UIElement ui = new UIElement(Game.SHOP);
            ui.SetLocation(UIScaler.GetHCenter(-17), offset, 10, 2);
            ui.SetText(label, colour);
            ui.SetFontSize(UIScaler.GetMediumFont());
            ui.SetButton(delegate { OnButton(tmp); });
            new UIElementBorder(ui, colour);

            offset += 3;
        }
    }

    public void OnButton(int i)
    {
        if (GameObject.FindGameObjectWithTag(Game.DIALOG) != null) return;
        game.quest.Save();
        game.quest.eManager.EndEvent(eventData, i);
    }

    public void DrawShopItems()
    {
        UIElement ui = new UIElement(Game.SHOP);
        ui.SetLocation(UIScaler.GetHCenter(-5), 0.5f, 10, 2);
        ui.SetText(new StringKey("val", "BUY"));
        ui.SetFontSize(UIScaler.GetMediumFont());
        ui.SetFont(game.gameType.GetHeaderFont());
        new UIElementBorder(ui);

        UIElementScrollVertical scrollArea = new UIElementScrollVertical(Game.SHOP);
        scrollArea.SetLocation(UIScaler.GetHCenter(-5), 2.5f, 10, 24.5f);
        new UIElementBorder(scrollArea);
{'fraction_non_alphanumeric': 0.11705371803893971, 'fraction_numerical': 0.01536476659629369, 'mean_word_length': 2.2068446784505453, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2879669', 'n_tokens_mistral': 2572, 'n_tokens_neox': 2458, 'n_words': 503}