Example #1
0
    public void DrawPartyItems()
    {
        UIElement ui = new UIElement(Game.SHOP);

        ui.SetLocation(UIScaler.GetHCenter(7), 0.5f, 10, 2);
        ui.SetText(new StringKey("val", "SELL"));
        ui.SetFontSize(UIScaler.GetMediumFont());
        ui.SetFont(game.gameType.GetHeaderFont());
        new UIElementBorder(ui);

        UIElementScrollVertical scrollArea = new UIElementScrollVertical(Game.SHOP);

        scrollArea.SetLocation(UIScaler.GetHCenter(7), 2.5f, 10, 24.5f);
        new UIElementBorder(scrollArea);

        float vOffset = 0.5f;

        foreach (string itemName in game.quest.items)
        {
            var itemData = game.cd.Get <ItemData>(itemName);
            if (itemData.ContainsTrait("relic"))
            {
                continue;
            }

            ui = new UIElement(Game.SHOP, scrollArea.GetScrollTransform());
            ui.SetLocation(0.5f, vOffset + 4.5f, 8, 2);
            ui.SetText(itemData.name, Color.black);
            ui.SetFontSize(ui.GetText().Length > LARGE_FONT_LIMIT ? UIScaler.GetSmallerFont() : UIScaler.GetSmallFont());
            ui.SetButton(delegate { Sell(itemName); });
            ui.SetBGColor(Color.white);

            ui = new UIElement(Game.SHOP, scrollArea.GetScrollTransform());
            ui.SetLocation(2.5f, vOffset + 0.5f, 4, 4);
            ui.SetButton(delegate { Sell(itemName); });
            Texture2D itemTex    = ContentData.FileToTexture(itemData.image);
            Sprite    itemSprite = Sprite.Create(itemTex, new Rect(0, 0, itemTex.width, itemTex.height), Vector2.zero, 1, 0, SpriteMeshType.FullRect);
            ui.SetImage(itemSprite);

            StringKey act = new StringKey(null, "-", false);
            if (itemData.ContainsTrait("class"))
            {
                act = new StringKey("val", "CLASS");
            }
            if (itemData.ContainsTrait("act1"))
            {
                act = new StringKey("val", "ACT_1");
            }
            if (itemData.ContainsTrait("act2"))
            {
                act = new StringKey("val", "ACT_2");
            }
            ui = new UIElement(Game.SHOP, scrollArea.GetScrollTransform());
            ui.SetLocation(3, vOffset + 3.9f, 3, 0.7f);
            ui.SetText(act);
            ui.SetFontSize(UIScaler.GetSmallerFont());
            ui.SetButton(delegate { Sell(itemName); });
            ui.SetBGColor(Color.grey);
            new UIElementBorder(ui, Color.black);

            ui = new UIElement(Game.SHOP, scrollArea.GetScrollTransform());
            ui.SetLocation(3, vOffset, 3, 1);
            ui.SetText(GetSellPrice(itemData).ToString());
            ui.SetButton(delegate { Sell(itemName); });
            ui.SetBGColor(new Color32(178, 154, 0, 255)); // dark gold
            new UIElementBorder(ui, Color.black);

            vOffset += 7;
        }
        scrollArea.SetScrollSize(vOffset - 0.5f);
    }
Example #2
0
    public InvestigatorItems()
    {
        Game game = Game.Get();

        // Items from heroes
        foreach (Quest.Hero h in game.quest.heroes)
        {
            if (h.heroData != null)
            {
                if (game.cd.ContainsKey <ItemData>(h.heroData.item))
                {
                    game.quest.items.Add(h.heroData.item);
                }
            }
        }

        foreach (KeyValuePair <string, QuestData.QuestComponent> kv in game.quest.qd.components)
        {
            QuestData.QItem item = kv.Value as QuestData.QItem;
            if (item != null && item.starting && game.quest.itemSelect.ContainsKey(kv.Key) &&
                item.tests != null && game.quest.vars.Test(item.tests))
            {
                game.quest.items.Add(game.quest.itemSelect[kv.Key]);
                if (item.inspect.Length > 0)
                {
                    if (game.quest.itemInspect.ContainsKey(game.quest.itemSelect[kv.Key]))
                    {
                        game.quest.itemInspect.Remove(game.quest.itemSelect[kv.Key]);
                    }
                    game.quest.itemInspect.Add(game.quest.itemSelect[kv.Key], item.inspect);
                }
            }
        }

        // If a dialog window is open we force it closed (this shouldn't happen)
        foreach (GameObject go in GameObject.FindGameObjectsWithTag(Game.DIALOG))
        {
            Object.Destroy(go);
        }

        UIElement ui = new UIElement();

        ui.SetLocation(10, 0.5f, UIScaler.GetWidthUnits() - 20, 2);
        ui.SetText(STARTING_ITEMS);
        ui.SetFontSize(UIScaler.GetMediumFont());
        ui.SetFont(Game.Get().gameType.GetHeaderFont());

        SortedList <string, SortedList <string, string> > itemSort = new SortedList <string, SortedList <string, string> >();

        foreach (string item in game.quest.items)
        {
            // Ignore "ItemX", find next capital letter
            int charIndex = 5;
            while (charIndex < item.Length - 1)
            {
                if (System.Char.IsUpper(item[charIndex++]))
                {
                    break;
                }
            }
            string typeString        = item.Substring(0, charIndex);
            string translationString = game.cd.Get <ItemData>(item).name.Translate();

            if (!itemSort.ContainsKey(typeString))
            {
                itemSort.Add(typeString, new SortedList <string, string>());
            }

            // Duplicate names
            while (itemSort[typeString].ContainsKey(translationString))
            {
                translationString += "D";
            }

            itemSort[typeString].Add(translationString, item);
        }

        int y = 0;
        int x = 0;

        foreach (string category in itemSort.Keys)
        {
            foreach (string item in itemSort[category].Values)
            {
                var       itemData = game.cd.Get <ItemData>(item);
                Texture2D tex      = ContentData.FileToTexture(itemData.image);
                Sprite    sprite   = null;
                if (tex != null)
                {
                    sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), Vector2.zero, 1, 0, SpriteMeshType.FullRect);
                }

                ui = new UIElement();
                ui.SetLocation(UIScaler.GetHCenter(8f * x) - 19, 5f + (9f * y), 6, 6);
                if (sprite != null)
                {
                    ui.SetImage(sprite);
                }

                ui = new UIElement();
                ui.SetLocation(UIScaler.GetHCenter(8f * x) - 20, 11f + (9f * y), 8, 1);
                ui.SetText(itemData.name);
                ui.SetFontSize(ui.GetText().Length > LARGE_FONT_LIMIT ? UIScaler.GetSmallerFont() : UIScaler.GetSmallFont());
                x++;
                if (x > 4)
                {
                    x = 0;
                    y++;
                }
            }
        }
        ui = new UIElement();
        ui.SetLocation(UIScaler.GetHCenter(-6f), 27f, 12, 2);
        ui.SetText(CommonStringKeys.FINISHED);
        ui.SetFont(game.gameType.GetHeaderFont());
        ui.SetFontSize(UIScaler.GetMediumFont());
        ui.SetButton(game.QuestStartEvent);
        new UIElementBorder(ui);
    }