Esempio n. 1
0
    public void CreateWindow()
    {
        // Draw text
        text = eventData.GetText();
        DialogBox db = new DialogBox(new Vector2(UIScaler.GetHCenter(-14f), 0.5f), new Vector2(28, 8),
                                     new StringKey(null, text, false));
        float offset = (db.textObj.GetComponent <UnityEngine.UI.Text>().preferredHeight / UIScaler.GetPixelsPerUnit()) + 1;

        db.Destroy();

        if (offset < 4)
        {
            offset = 4;
        }

        db = new DialogBox(new Vector2(UIScaler.GetHCenter(-14f), 0.5f), new Vector2(28, offset),
                           new StringKey(null, text, false));
        db.AddBorder();
        offset += 1f;

        // Determine button size
        float buttonWidth   = 8;
        float hOffset       = UIScaler.GetWidthUnits() - 19f;
        float hOffsetCancel = 11;
        float offsetCancel  = offset;

        List <DialogWindow.EventButton> buttons = eventData.GetButtons();

        foreach (EventButton eb in buttons)
        {
            db = new DialogBox(new Vector2(UIScaler.GetHCenter(-14f), 0.5f), new Vector2(28, offset), eb.GetLabel());
            db.textObj.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetMediumFont();
            float length = (db.textObj.GetComponent <UnityEngine.UI.Text>().preferredWidth / UIScaler.GetPixelsPerUnit()) + 1;
            if (length > buttonWidth)
            {
                buttonWidth   = length;
                hOffset       = UIScaler.GetHCenter(-length / 2);
                hOffsetCancel = UIScaler.GetHCenter(-4);
                offsetCancel  = offset + (2.5f * buttons.Count);
            }
            db.Destroy();
        }

        int num = 1;

        foreach (EventButton eb in buttons)
        {
            int numTmp = num++;
            new TextButton(new Vector2(hOffset, offset), new Vector2(buttonWidth, 2),
                           eb.GetLabel(), delegate { onButton(numTmp); }, eb.colour);
            offset += 2.5f;
        }

        // Do we have a cancel button?
        if (eventData.qEvent.cancelable)
        {
            new TextButton(new Vector2(hOffsetCancel, offsetCancel), new Vector2(8f, 2), CommonStringKeys.CANCEL, delegate { onCancel(); });
        }
    }
Esempio n. 2
0
    public void CreateQuotaWindow()
    {
        // Draw text
        DialogBox db = new DialogBox(new Vector2(UIScaler.GetHCenter(-14f), 0.5f), new Vector2(28, 8),
                                     new StringKey(null, text, false));
        float offset = (db.textObj.GetComponent <UnityEngine.UI.Text>().preferredHeight / UIScaler.GetPixelsPerUnit()) + 1;

        db.Destroy();

        if (offset < 4)
        {
            offset = 4;
        }

        db = new DialogBox(new Vector2(UIScaler.GetHCenter(-14f), 0.5f), new Vector2(28, offset),
                           new StringKey(null, text, false));
        db.AddBorder();
        offset += 1;

        if (quota == 0)
        {
            new TextButton(new Vector2(11, offset), new Vector2(2f, 2f), CommonStringKeys.MINUS, delegate {; }, Color.grey);
        }
        else
        {
            new TextButton(new Vector2(11, offset), new Vector2(2f, 2f), CommonStringKeys.MINUS, delegate { quotaDec(); }, Color.white);
        }

        db = new DialogBox(new Vector2(14, offset), new Vector2(2f, 2f), quota);
        db.textObj.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetMediumFont();
        db.AddBorder();

        if (quota >= 10)
        {
            new TextButton(new Vector2(17, offset), new Vector2(2f, 2f), CommonStringKeys.PLUS, delegate {; }, Color.grey);
        }
        else
        {
            new TextButton(new Vector2(17, offset), new Vector2(2f, 2f), CommonStringKeys.PLUS, delegate { quotaInc(); }, Color.white);
        }

        // Only one button, action depends on quota
        new TextButton(
            new Vector2(UIScaler.GetWidthUnits() - 19, offset), new Vector2(8f, 2),
            eventData.GetButtons()[0].GetLabel(), delegate { onQuota(); }, Color.white);

        // Do we have a cancel button?
        if (eventData.qEvent.cancelable)
        {
            new TextButton(new Vector2(UIScaler.GetHCenter(-4f), offset + 2.5f), new Vector2(8f, 2), CommonStringKeys.CANCEL, delegate { onCancel(); });
        }
    }
Esempio n. 3
0
    public void CreateWindow()
    {
        // Draw text
        text = eventData.GetText();
        DialogBox db     = new DialogBox(new Vector2(UIScaler.GetHCenter(-14f), 0.5f), new Vector2(28, 8), new StringKey(text, false));
        float     offset = (db.textObj.GetComponent <UnityEngine.UI.Text>().preferredHeight / UIScaler.GetPixelsPerUnit()) + 1;

        db.Destroy();

        if (offset < 4)
        {
            offset = 4;
        }

        db = new DialogBox(new Vector2(UIScaler.GetHCenter(-14f), 0.5f), new Vector2(28, offset),
                           new StringKey(text, false));
        db.AddBorder();

        offset += 1f;
        int   num     = 1;
        float length  = 8f;
        float hOffset = UIScaler.GetWidthUnits() - 19f;

        if (eventData.GetButtons().Count > 2)
        {
            length  = 16f;
            hOffset = UIScaler.GetHCenter(-8f);
        }
        else
        {
            if (eventData.qEvent.cancelable)
            {
                new TextButton(new Vector2(11, offset), new Vector2(8f, 2), CommonStringKeys.CANCEL, delegate { onCancel(); });
            }
        }
        foreach (EventButton eb in eventData.GetButtons())
        {
            int numTmp = num++;
            new TextButton(new Vector2(hOffset, offset), new Vector2(length, 2),
                           new StringKey(eb.label, false), delegate { onButton(numTmp); }, eb.colour);
            offset += 2.5f;
        }

        // Do we have a cancel button?
        if (eventData.qEvent.cancelable && (eventData.GetButtons().Count > 2))
        {
            new TextButton(new Vector2(hOffset, offset), new Vector2(8f, 2), CommonStringKeys.CANCEL, delegate { onCancel(); });
        }
    }
Esempio n. 4
0
    // Destroy list, call on cancel
    public void SelectItem(UnityEngine.Events.UnityAction call)
    {
        Destroyer.Dialog();
        cancelCall = call;

        // Border
        DialogBox db = new DialogBox(new Vector2(21, 0), new Vector2(20, 30), StringKey.NULL);

        db.AddBorder();

        // Title
        db = new DialogBox(new Vector2(21, 0), new Vector2(20, 1), title);

        List <SelectionListEntry> filtered = items;

        if (filter.Count > 0)
        {
            filtered = new List <SelectionListEntry>();
            foreach (SelectionListEntry e in items)
            {
                bool valid = true;
                foreach (string s in filter)
                {
                    if (!e.filter.Contains(s))
                    {
                        valid = false;
                    }
                }
                if (valid)
                {
                    filtered.Add(e);
                }
            }
        }

        float      offset = 2f;
        TextButton tb     = null;

        float hOffset = 22;

        foreach (string s in traits)
        {
            db = new DialogBox(Vector2.zero, new Vector2(10, 1), new StringKey(s, false));
            float width = (db.textObj.GetComponent <UnityEngine.UI.Text>().preferredWidth / UIScaler.GetPixelsPerUnit()) + 0.5f;
            db.Destroy();
            if (hOffset + width > 40)
            {
                hOffset = 22;
                offset++;
            }
            string tmp = s;
            if (filter.Count == 0)
            {
                tb = new TextButton(new Vector2(hOffset, offset), new Vector2(width, 1), new StringKey(tmp, false), delegate { SetFilter(s); });
            }
            else if (filter.Contains(s))
            {
                tb = new TextButton(new Vector2(hOffset, offset), new Vector2(width, 1), new StringKey(tmp, false), delegate { ClearFilter(s); });
            }
            else
            {
                bool valid = false;
                foreach (SelectionListEntry e in filtered)
                {
                    if (e.filter.Contains(tmp))
                    {
                        valid = true;
                    }
                }
                if (valid)
                {
                    tb = new TextButton(new Vector2(hOffset, offset), new Vector2(width, 1), new StringKey(tmp, false), delegate { SetFilter(s); }, Color.gray);
                }
                else
                {
                    tb = new TextButton(new Vector2(hOffset, offset), new Vector2(width, 1), new StringKey(tmp, false), delegate {; }, new Color(0.5f, 0, 0));
                }
            }
            tb.button.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetSmallFont();
            hOffset += width;
        }

        if (traits.Count > 0)
        {
            offset += 2;
        }
        perPage = 27 - Mathf.RoundToInt(offset);

        // All items on this page
        for (int i = indexOffset; i < (perPage + indexOffset); i++)
        {
            // limit to array length
            if (filtered.Count > i)
            {
                string key = filtered[i].name;
                tb = new TextButton(new Vector2(21, offset), new Vector2(20, 1), new StringKey(key, false), delegate { SelectComponent(key); }, filtered[i].color);
                tb.button.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetSmallFont();
            }
            offset += 1;
        }
        // Paged
        if (filtered.Count > perPage)
        {
            // Prev button
            offset += 1;
            tb      = new TextButton(new Vector2(22f, offset), new Vector2(1, 1), new StringKey("<", false), delegate { PreviousPage(); });
            tb.background.GetComponent <UnityEngine.UI.Image>().color = new Color(0.03f, 0.0f, 0f);
            tb.button.GetComponent <UnityEngine.UI.Text>().fontSize   = UIScaler.GetSmallFont();
            // Next button
            tb = new TextButton(new Vector2(39f, offset), new Vector2(1, 1), new StringKey(">", false), delegate { NextPage(); });
            tb.background.GetComponent <UnityEngine.UI.Image>().color = new Color(0.03f, 0.0f, 0f);
            tb.button.GetComponent <UnityEngine.UI.Text>().fontSize   = UIScaler.GetSmallFont();
        }
        // Cancel button
        tb = new TextButton(new Vector2(26.5f, offset), new Vector2(9, 1), CommonStringKeys.CANCEL, cancelCall);
        tb.background.GetComponent <UnityEngine.UI.Image>().color = new Color(0.03f, 0.0f, 0f);
        tb.button.GetComponent <UnityEngine.UI.Text>().fontSize   = UIScaler.GetSmallFont();
    }
Esempio n. 5
0
        public QuestDetailsScreen(QuestData.Quest q)
        {
            Game game = Game.Get();

            LocalizationRead.scenarioDict = q.localizationDict;
            // 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);
            }

            // Heading
            DialogBox db = new DialogBox(
                new Vector2(2, 0.5f),
                new Vector2(UIScaler.GetWidthUnits() - 4, 3),
                q.name);

            db.textObj.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetLargeFont();
            db.SetFont(game.gameType.GetHeaderFont());

            // Draw Image
            if (q.image.Length > 0)
            {
                Texture2D tex    = ContentData.FileToTexture(Path.Combine(q.path, q.image));
                Sprite    sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), Vector2.zero, 1);

                db = new DialogBox(new Vector2(UIScaler.GetHCenter(-20), 4),
                                   new Vector2(8, 8),
                                   StringKey.NULL,
                                   Color.white,
                                   Color.white);
                db.background.GetComponent <UnityEngine.UI.Image>().sprite = sprite;
                db.AddBorder();
            }

            // Draw Description
            db = new DialogBox(Vector2.zero, new Vector2(30, 30), q.description);
            float height = (db.textObj.GetComponent <UnityEngine.UI.Text>().preferredHeight / UIScaler.GetPixelsPerUnit()) + 1;

            db.Destroy();
            if (height > 25)
            {
                height = 25;
            }

            db = new DialogBox(new Vector2(UIScaler.GetHCenter(-7), 15 - (height / 2)), new Vector2(30, height), q.description);
            db.AddBorder();

            // Draw authors
            db     = new DialogBox(Vector2.zero, new Vector2(14, 30), q.authors);
            height = (db.textObj.GetComponent <UnityEngine.UI.Text>().preferredHeight / UIScaler.GetPixelsPerUnit()) + 1;
            db.Destroy();
            if (height > 25)
            {
                height = 25;
            }

            db = new DialogBox(new Vector2(UIScaler.GetHCenter(-23), 18.5f - (height / 2)), new Vector2(14, height), q.authors);
            db.AddBorder();

            // Difficulty
            if (q.difficulty != 0)
            {
                db = new DialogBox(new Vector2(UIScaler.GetHCenter(-13), 27), new Vector2(11, 1), new StringKey("val", "DIFFICULTY"));
                string symbol = "*";
                if (game.gameType is MoMGameType)
                {
                    symbol = new StringKey("val", "ICON_SUCCESS_RESULT").Translate();
                }
                db = new DialogBox(new Vector2(UIScaler.GetHCenter(-13), 28), new Vector2(11, 2), new StringKey(null, symbol + symbol + symbol + symbol + symbol, false));
                db.textObj.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetMediumFont();
                db = new DialogBox(new Vector2(UIScaler.GetHCenter(-10.95f) + (q.difficulty * 6.9f), 28), new Vector2((1 - q.difficulty) * 6.9f, 2), StringKey.NULL, Color.clear, new Color(0, 0, 0, 0.7f));
            }

            // Duration
            if (q.lengthMax != 0)
            {
                db = new DialogBox(new Vector2(UIScaler.GetHCenter(2), 27), new Vector2(11, 1), new StringKey("val", "DURATION"));
                db = new DialogBox(new Vector2(UIScaler.GetHCenter(2), 28f), new Vector2(4, 2), q.lengthMin);
                db.textObj.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetMediumFont();
                db = new DialogBox(new Vector2(UIScaler.GetHCenter(6.5f), 28f), new Vector2(2, 2), new StringKey(null, "-", false));
                db.textObj.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetMediumFont();
                db = new DialogBox(new Vector2(UIScaler.GetHCenter(9), 28f), new Vector2(4, 2), q.lengthMax);
                db.textObj.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetMediumFont();
            }

            TextButton tb = new TextButton(
                new Vector2(0.5f, UIScaler.GetBottom(-2.5f)), new Vector2(8, 2),
                CommonStringKeys.BACK, delegate { Cancel(); }, Color.red);

            tb.SetFont(game.gameType.GetHeaderFont());

            tb = new TextButton(
                new Vector2(UIScaler.GetRight(-8.5f), UIScaler.GetBottom(-2.5f)), new Vector2(8, 2),
                new StringKey("val", "START"), delegate { Start(q); }, Color.green);
            tb.SetFont(game.gameType.GetHeaderFont());
        }