Exemplo n.º 1
0
    public void Draw(PuzzleImage.TilePosition screenPos, PuzzleImage.TilePosition imgPos, bool solved)
    {
        Game game = Game.Get();
        // Create object
        GameObject gameObject = new GameObject("PuzzleTile");

        gameObject.tag = "dialog";

        gameObject.transform.parent = game.uICanvas.transform;

        RectTransform trans = gameObject.AddComponent <RectTransform>();

        trans.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, UIScaler.GetPixelsPerUnit() + (UIScaler.GetPixelsPerUnit() * screenPos.y * height), height * UIScaler.GetPixelsPerUnit());
        trans.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, (UIScaler.GetHCenter(-11.5f) * UIScaler.GetPixelsPerUnit()) + (UIScaler.GetPixelsPerUnit() * screenPos.x * width), width * UIScaler.GetPixelsPerUnit());
        gameObject.AddComponent <CanvasRenderer>();

        // Create the image
        UnityEngine.UI.Image image = gameObject.AddComponent <UnityEngine.UI.Image>();
        image.sprite = imageSprite[imgPos.x][imgPos.y];
        image.rectTransform.sizeDelta = new Vector2(width * UIScaler.GetPixelsPerUnit(), height * UIScaler.GetPixelsPerUnit());

        if (solved)
        {
            return;
        }
        BlockSlider slider = gameObject.AddComponent <BlockSlider>();

        slider.screenPos = screenPos;
        slider.win       = this;
    }
        public override void SetLocationPixels(float x, float y, float width, float height)
        {
            UIElement ui = new UIElement(tag, bg.transform);

            ui.SetLocationPixels(0, -UIScaler.GetPixelsPerUnit(), width, UIScaler.GetPixelsPerUnit());
            new UIElementBorder(ui);

            base.SetLocationPixels(x, y + UIScaler.GetPixelsPerUnit(), width, height - UIScaler.GetPixelsPerUnit());
            Dictionary <string, string> CHARS = null;

            EventManager.CHARS_MAP.TryGetValue(Game.Get().gameType.TypeName(), out CHARS);

            if (CHARS != null)
            {
                float buttonWidth = width / CHARS.Keys.Count;
                float xPos        = 0;
                foreach (string oneChar in CHARS.Keys)
                {
                    StringKey translated  = new StringKey(null, oneChar);
                    string    translation = null;
                    CHARS.TryGetValue(oneChar, out translation);
                    ui = new UIElement(tag, bg.transform);
                    ui.SetLocationPixels(xPos, -UIScaler.GetPixelsPerUnit(), buttonWidth, UIScaler.GetPixelsPerUnit());
                    ui.SetText(translated);
                    ui.SetButton(delegate { InsertCharacter(translation); });

                    xPos += buttonWidth;
                }
            }
        }
Exemplo n.º 3
0
    public void Create(Transform t, Color c, Vector2 size, string tag)
    {
        // Create objects
        bLine = new GameObject[4];
        for (int i = 0; i < 4; i++)
        {
            bLine[i] = new GameObject("Border" + i);
            if (!tag.Equals(""))
            {
                bLine[i].tag = "dialog";
            }
            bLine[i].AddComponent <RectTransform>();
            bLine[i].AddComponent <CanvasRenderer>();
            bLine[i].transform.SetParent(t);
            UnityEngine.UI.Image blImage = bLine[i].AddComponent <UnityEngine.UI.Image>();
            blImage.color = c;
        }

        float thick = 0.05f * UIScaler.GetPixelsPerUnit();

        bLine[0].GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Bottom, 0, thick);
        bLine[0].GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, -thick, size.x * UIScaler.GetPixelsPerUnit());

        bLine[1].GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, -thick, thick);
        bLine[1].GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, -thick, size.x * UIScaler.GetPixelsPerUnit());

        bLine[2].GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, -thick, size.y * UIScaler.GetPixelsPerUnit());
        bLine[2].GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, -thick, thick);

        bLine[3].GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, -thick, size.y * UIScaler.GetPixelsPerUnit());
        bLine[3].GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Right, 0, thick);
    }
Exemplo n.º 4
0
        private void CreateBorder(Transform transform, RectTransform rectTrans, string tag, Color color, float thickness = 0.05f)
        {
            bLine = new GameObject[4];

            // create 4 lines
            for (int i = 0; i < 4; i++)
            {
                bLine[i]     = new GameObject("Border" + i);
                bLine[i].tag = tag;
                bLine[i].AddComponent <UnityEngine.UI.Image>().color = color;
                bLine[i].transform.SetParent(transform);
            }

            // Set the thickness of the lines
            float thick = thickness * UIScaler.GetPixelsPerUnit();

            // Bottom line
            bLine[0].GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Bottom, 0, thick);
            bLine[0].GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, -thick, rectTrans.rect.width);
            // Top line
            bLine[1].GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, -thick, thick);
            bLine[1].GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, -thick, rectTrans.rect.width);

            // Left line
            bLine[2].GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, -thick, rectTrans.rect.height + thick);
            bLine[2].GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, -thick, thick);
            // Right line
            bLine[3].GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, -thick, rectTrans.rect.height + thick);
            bLine[3].GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Right, 0, thick);
        }
Exemplo n.º 5
0
    void AddMonster(Quest.Monster m, Game game)
    {
        Sprite mSprite;

        Texture2D newTex = ContentData.FileToTexture(m.monsterData.image);

        GameObject mImg = new GameObject("monsterImg" + m.monsterData.name);

        mImg.tag = "monsters";

        mImg.transform.parent = game.uICanvas.transform;

        RectTransform trans = mImg.AddComponent <RectTransform>();

        trans.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, (0.25f + offset) * UIScaler.GetPixelsPerUnit(), monsterSize * UIScaler.GetPixelsPerUnit());
        offset += monsterSize + 0.5f;
        trans.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Right, 0.25f * UIScaler.GetPixelsPerUnit(), monsterSize * UIScaler.GetPixelsPerUnit());
        mImg.AddComponent <CanvasRenderer>();

        UnityEngine.UI.Image image = mImg.AddComponent <UnityEngine.UI.Image>();
        icons.Add(m.monsterData.name, image);
        mSprite      = Sprite.Create(newTex, new Rect(0, 0, newTex.width, newTex.height), Vector2.zero, 1);
        image.sprite = mSprite;
        image.rectTransform.sizeDelta = new Vector2(monsterSize * UIScaler.GetPixelsPerUnit(), monsterSize * UIScaler.GetPixelsPerUnit());

        UnityEngine.UI.Button button = mImg.AddComponent <UnityEngine.UI.Button>();
        button.interactable = true;
        button.onClick.AddListener(delegate { MonsterDiag(m.monsterData.name); });
    }
Exemplo n.º 6
0
        /// <summary>
        /// Get the amount of space for additional lines in the box, can be negative.</summary>
        /// <returns>Amount of vertical space, less padding value in UIScaler units</returns>
        protected float GetVerticalTextSpace()
        {
            float gap = text.GetComponent <RectTransform>().rect.height - text.GetComponent <UnityEngine.UI.Text>().preferredHeight;

            gap -= textPaddingDefault * 2f;
            return(gap / UIScaler.GetPixelsPerUnit());
        }
Exemplo n.º 7
0
        /// <summary>
        /// Draw the contents to the screen
        /// </summary>
        /// <param name="display">Text to display</param>
        private void Draw(string display)
        {
            // Create an object
            GameObject logo = new GameObject("logo");

            // Mark it as dialog
            logo.tag = Game.DIALOG;
            logo.transform.SetParent(Game.Get().uICanvas.transform);

            RectTransform transBg = logo.AddComponent <RectTransform>();

            transBg.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, UIScaler.GetHCenter(-3) * UIScaler.GetPixelsPerUnit(), 6 * UIScaler.GetPixelsPerUnit());
            transBg.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 8 * UIScaler.GetPixelsPerUnit(), 6 * UIScaler.GetPixelsPerUnit());

            // Create the image
            Texture2D tex    = Resources.Load("sprites/logo") as Texture2D;
            Sprite    sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), Vector2.zero, 1);

            UnityEngine.UI.Image uiImage = logo.AddComponent <UnityEngine.UI.Image>();
            uiImage.sprite = sprite;
            logo.AddComponent <SpritePulser>();

            // Display message
            UIElement ui = new UIElement();

            ui.SetLocation(2, 20, UIScaler.GetWidthUnits() - 4, 2);
            ui.SetText(display);
            ui.SetFontSize(UIScaler.GetMediumFont());
        }
Exemplo n.º 8
0
        /// <summary>
        /// Construct a screen with pulsing logo, download progress and optional text label
        /// </summary>
        /// <param name="download">WWW object tracking download</param>
        /// <param name="display">Text to display</param>
        public LoadingScreen(WWW download, string display = "")
        {
            Destroyer.Dialog();
            Draw(display);

            // Create border
            UIElement ui = new UIElement();

            ui.SetLocation(3, 27, UIScaler.GetWidthUnits() - 6, 2);
            ui.SetBGColor(Color.clear);
            new UIElementBorder(ui);

            // Create an object
            GameObject bar = new GameObject("progress");

            // Mark it as dialog
            bar.tag = Game.DIALOG;
            bar.transform.SetParent(Game.Get().uICanvas.transform);

            RectTransform transBg = bar.AddComponent <RectTransform>();

            transBg.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, 3 * UIScaler.GetPixelsPerUnit(), (UIScaler.GetWidthUnits() - 6) * UIScaler.GetPixelsPerUnit());
            transBg.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 27 * UIScaler.GetPixelsPerUnit(), 2 * UIScaler.GetPixelsPerUnit());

            // Create the image
            UnityEngine.UI.Image uiImage = bar.AddComponent <UnityEngine.UI.Image>();
            uiImage.color = Color.white;
            bar.AddComponent <ProgressBar>().SetDownload(download);
        }
Exemplo n.º 9
0
        private void CreateBorder(UIElement element, Color color)
        {
            GameObject[] bLine = new GameObject[4];

            // create 4 lines
            for (int i = 0; i < 4; i++)
            {
                bLine[i]     = new GameObject("Border" + i);
                bLine[i].tag = element.GetTag();
                bLine[i].AddComponent <UnityEngine.UI.Image>().color = color;
                bLine[i].transform.SetParent(element.GetTransform());
            }

            // Set the thickness of the lines
            float thick = 0.05f * UIScaler.GetPixelsPerUnit();

            bLine[0].GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Bottom, 0, thick);
            bLine[0].GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, -thick, element.GetRectTransform().rect.width);

            bLine[1].GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, -thick, thick);
            bLine[1].GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, -thick, element.GetRectTransform().rect.width);

            bLine[2].GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, -thick, element.GetRectTransform().rect.height);
            bLine[2].GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, -thick, thick);

            bLine[3].GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, -thick, element.GetRectTransform().rect.height);
            bLine[3].GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Right, 0, thick);
        }
Exemplo n.º 10
0
        // Create the about dialog
        public void About()
        {
            // This will destroy all, because we shouldn't have anything left at the main menu
            Destroyer.Destroy();

            Sprite bannerSprite;
            Texture2D newTex = Resources.Load("sprites/banner") as Texture2D;

            GameObject banner = new GameObject("banner");
            banner.tag = "dialog";

            banner.transform.parent = Game.Get().uICanvas.transform;

            RectTransform trans = banner.AddComponent<RectTransform>();
            trans.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 1 * UIScaler.GetPixelsPerUnit(), 7f * UIScaler.GetPixelsPerUnit());
            trans.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, (UIScaler.GetWidthUnits() - 18f) * UIScaler.GetPixelsPerUnit() / 2f, 18f * UIScaler.GetPixelsPerUnit());
            banner.AddComponent<CanvasRenderer>();


            UnityEngine.UI.Image image = banner.AddComponent<UnityEngine.UI.Image>();
            bannerSprite = Sprite.Create(newTex, new Rect(0, 0, newTex.width, newTex.height), Vector2.zero, 1);
            image.sprite = bannerSprite;
            image.rectTransform.sizeDelta = new Vector2(18f * UIScaler.GetPixelsPerUnit(), 7f * UIScaler.GetPixelsPerUnit());

            DialogBox db = new DialogBox(new Vector2((UIScaler.GetWidthUnits() - 30f) / 2, 10f), new Vector2(30, 6), "Valkyrie is a game master helper tool inspired by Fantasy Flight Games' Descent: Road to Legend.  Most images used are imported from FFG applications are are copyright FFG and other rights holders.");
            db.textObj.GetComponent<UnityEngine.UI.Text>().fontSize = UIScaler.GetMediumFont();

            db = new DialogBox(new Vector2((UIScaler.GetWidthUnits() - 30f) / 2, 18f), new Vector2(30, 5), "Valkyrie uses DotNetZip-For-Unity and has code derived from Unity Studio.");
            db.textObj.GetComponent<UnityEngine.UI.Text>().fontSize = UIScaler.GetMediumFont();

            TextButton tb = new TextButton(new Vector2(1, UIScaler.GetBottom(-3)), new Vector2(8, 2), "Back", delegate { Destroyer.MainMenu(); });
            tb.background.GetComponent<UnityEngine.UI.Image>().color = new Color(0, 0.03f, 0f);
            tb.SetFont(Game.Get().gameType.GetHeaderFont());
        }
Exemplo n.º 11
0
        public override void SetLocationPixels(float x, float y, float width, float height)
        {
            UIElement ui = new UIElement(tag, bg.transform);

            ui.SetLocationPixels(0, -UIScaler.GetPixelsPerUnit(), width, UIScaler.GetPixelsPerUnit());
            new UIElementBorder(ui);

            base.SetLocationPixels(x, y + UIScaler.GetPixelsPerUnit(), width, height - UIScaler.GetPixelsPerUnit());
            Dictionary <string, string> CHARS = EventManager.GetCharacterMap(true);

            if (CHARS != null)
            {
                float buttonWidth = width / CHARS.Keys.Count;
                float xPos        = 0;
                foreach (string textKey in CHARS.Keys)
                {
                    ui = new UIElement(tag, bg.transform);
                    ui.SetLocationPixels(xPos, -UIScaler.GetPixelsPerUnit(), buttonWidth, UIScaler.GetPixelsPerUnit());
                    ui.SetText(CHARS[textKey]);
                    ui.SetButton(delegate { InsertCharacter(textKey); });

                    xPos += buttonWidth;
                }
            }
        }
Exemplo n.º 12
0
    // Create window, call event on cancel
    public void EditText(UnityEngine.Events.UnityAction call)
    {
        Destroyer.Dialog();
        cancelCall = call;

        // Border
        DialogBox db = new DialogBox(new Vector2(21, 0), new Vector2(20, 6), "");

        db.AddBorder();

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

        Game       game     = Game.Get();
        GameObject textObj  = new GameObject("textEdit");
        GameObject inputObj = new GameObject("textInput");

        textObj.tag  = "dialog";
        inputObj.tag = "dialog";

        inputObj.transform.parent = game.uICanvas.transform;
        textObj.transform.parent  = inputObj.transform;

        RectTransform transBg = inputObj.AddComponent <RectTransform>();

        transBg.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 2 * UIScaler.GetPixelsPerUnit(), UIScaler.GetPixelsPerUnit());
        transBg.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, 22 * UIScaler.GetPixelsPerUnit(), 18 * UIScaler.GetPixelsPerUnit());

        RectTransform transTx = textObj.AddComponent <RectTransform>();

        transTx.SetParent(transBg);
        transTx.localScale = transBg.localScale;
        transTx.sizeDelta  = transBg.sizeDelta;

        inputObj.AddComponent <CanvasRenderer>();
        textObj.AddComponent <CanvasRenderer>();

        UnityEngine.UI.Text uiText = textObj.AddComponent <UnityEngine.UI.Text>();
        iField = inputObj.AddComponent <UnityEngine.UI.InputField>();

        uiText.color    = Color.white;
        uiText.font     = game.gameType.GetFont();
        uiText.material = uiText.font.material;
        uiText.fontSize = UIScaler.GetSmallFont();

        iField.textComponent = uiText;
        iField.text          = value;

        TextButton tb = new TextButton(new Vector2(23f, 4), new Vector2(6, 1), "OK", OKButton);

        tb.background.GetComponent <UnityEngine.UI.Image>().color = new Color(0.0f, 0.03f, 0f);
        tb.button.GetComponent <UnityEngine.UI.Text>().fontSize   = UIScaler.GetSmallFont();

        tb = new TextButton(new Vector2(31f, 4), new Vector2(6, 1), "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();
    }
Exemplo n.º 13
0
    // Create window, call event on cancel
    public void EditText(UnityEngine.Events.UnityAction call)
    {
        Destroyer.Dialog();
        cancelCall = call;

        // Border
        DialogBox db = new DialogBox(new Vector2(UIScaler.GetHCenter(-10), 1), new Vector2(20, 6), StringKey.NULL);

        db.AddBorder();

        // Heading
        db = new DialogBox(new Vector2(UIScaler.GetHCenter(-9.5f), 1), new Vector2(19, 1), title);

        Game       game     = Game.Get();
        GameObject textObj  = new GameObject("textEdit");
        GameObject inputObj = new GameObject("textInput");

        textObj.tag  = Game.DIALOG;
        inputObj.tag = Game.DIALOG;

        inputObj.transform.SetParent(game.uICanvas.transform);
        textObj.transform.SetParent(inputObj.transform);

        RectTransform transBg = inputObj.AddComponent <RectTransform>();

        transBg.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 3 * UIScaler.GetPixelsPerUnit(), UIScaler.GetPixelsPerUnit());
        transBg.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, UIScaler.GetHCenter(-9) * UIScaler.GetPixelsPerUnit(), 18 * UIScaler.GetPixelsPerUnit());

        RectTransform transTx = textObj.AddComponent <RectTransform>();

        transTx.SetParent(transBg);
        transTx.localScale = transBg.localScale;
        transTx.sizeDelta  = transBg.sizeDelta;

        inputObj.AddComponent <CanvasRenderer>();
        textObj.AddComponent <CanvasRenderer>();

        UnityEngine.UI.Text uiText = textObj.AddComponent <UnityEngine.UI.Text>();

        uiText.color    = Color.white;
        uiText.font     = game.gameType.GetFont();
        uiText.material = uiText.font.material;
        uiText.fontSize = UIScaler.GetSmallFont();

        iField = inputObj.AddComponent <PanCancelInputField>();
        iField.textComponent = uiText;
        iField.text          = value;

        TextButton tb = new TextButton(new Vector2(UIScaler.GetHCenter(-8), 5), new Vector2(6, 1), CommonStringKeys.OK, OKButton);

        tb.background.GetComponent <UnityEngine.UI.Image>().color = new Color(0.0f, 0.03f, 0f);
        tb.button.GetComponent <UnityEngine.UI.Text>().fontSize   = UIScaler.GetSmallFont();

        tb = new TextButton(new Vector2(UIScaler.GetHCenter(2), 5), new Vector2(6, 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();
    }
Exemplo n.º 14
0
    public void CreateWindow()
    {
        Destroyer.Dialog();
        DialogBox db = new DialogBox(new Vector2(UIScaler.GetHCenter(-14f), 0.5f), new Vector2(28f, 22f), "");

        db.AddBorder();

        // Puzzle goes here
        GameObject background = new GameObject("puzzleContent");

        background.tag = "dialog";
        RectTransform transBg = background.AddComponent <RectTransform>();

        background.transform.SetParent(Game.Get().uICanvas.transform);
        transBg.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, UIScaler.GetPixelsPerUnit() * 2.5f, 18f * UIScaler.GetPixelsPerUnit());
        transBg.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, UIScaler.GetHCenter(-12f) * UIScaler.GetPixelsPerUnit(), 24f * UIScaler.GetPixelsPerUnit());

        DrawSlideFrame(background.transform);

        foreach (PuzzleSlide.Block b in puzzle.puzzle)
        {
            CreateBlock(b, transBg, b.target);
        }

        db = new DialogBox(new Vector2(UIScaler.GetHCenter(7f), 3f), new Vector2(6f, 2f), "Skill:");
        db.textObj.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetMediumFont();

        db = new DialogBox(new Vector2(UIScaler.GetHCenter(8.5f), 5f), new Vector2(3f, 2f), EventManager.SymbolReplace(questPuzzle.skill));
        db.textObj.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetMediumFont();
        db.AddBorder();

        db = new DialogBox(new Vector2(UIScaler.GetHCenter(7f), 12.5f), new Vector2(6f, 2f), "Moves:");
        db.textObj.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetMediumFont();

        db = new DialogBox(new Vector2(UIScaler.GetHCenter(8.5f), 14.5f), new Vector2(3f, 2f), (puzzle.moves - lastMoves).ToString());
        db.textObj.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetMediumFont();
        db.AddBorder();

        db = new DialogBox(new Vector2(UIScaler.GetHCenter(7f), 17f), new Vector2(6f, 2f), "Total Moves:");
        db.textObj.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetMediumFont();

        db = new DialogBox(new Vector2(UIScaler.GetHCenter(8.5f), 19f), new Vector2(3f, 2f), puzzle.moves.ToString());
        db.textObj.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetMediumFont();
        db.AddBorder();

        if (puzzle.Solved())
        {
            new TextButton(new Vector2(UIScaler.GetHCenter(-13f), 23.5f), new Vector2(8f, 2), "Close", delegate {; }, Color.grey);
            new TextButton(new Vector2(UIScaler.GetHCenter(5f), 23.5f), new Vector2(8f, 2), eventData.GetButtons()[0].label, delegate { Finished(); });
        }
        else
        {
            new TextButton(new Vector2(UIScaler.GetHCenter(-13f), 23.5f), new Vector2(8f, 2), "Close", delegate { Close(); });
            new TextButton(new Vector2(UIScaler.GetHCenter(5f), 23.5f), new Vector2(8f, 2), eventData.GetButtons()[0].label, delegate {; }, Color.grey);
        }
    }
Exemplo n.º 15
0
        public override void SetScrollSize(float size)
        {
            float width = size * UIScaler.GetPixelsPerUnit();

            if (width < scrollBar.GetComponent <RectTransform>().rect.width)
            {
                width = scrollBar.GetComponent <RectTransform>().rect.width;
            }
            scrollArea.GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, 0, width);
        }
Exemplo n.º 16
0
        public virtual void SetScrollSize(float size)
        {
            float height = size * UIScaler.GetPixelsPerUnit();

            if (height < scrollBar.GetComponent <RectTransform>().rect.height)
            {
                height = scrollBar.GetComponent <RectTransform>().rect.height;
            }
            scrollArea.GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 0, height);
        }
Exemplo n.º 17
0
        public override void SetText(string content, Color textColor)
        {
            UnityEngine.UI.Text uiText = null;
            if (text == null)
            {
                input     = new GameObject("UIInput");
                input.tag = tag;
                PanCancelInputField uiInput = input.AddComponent <PanCancelInputField>();
                uiInput.lineType = UnityEngine.UI.InputField.LineType.MultiLineNewline;
                input.transform.SetParent(bg.transform);
                RectTransform transform = input.AddComponent <RectTransform>();
                transform.anchorMin     = Vector2.zero;
                transform.anchorMax     = Vector2.one;
                transform.localPosition = Vector3.zero;
                transform.localScale    = Vector3.one;
                transform.offsetMin     = Vector2.zero;
                transform.offsetMax     = Vector2.zero;

                text                      = new GameObject("UIText");
                text.tag                  = tag;
                uiText                    = text.AddComponent <UnityEngine.UI.Text>();
                uiText.alignment          = TextAnchor.MiddleCenter;
                uiText.font               = Game.Get().gameType.GetFont();
                uiText.fontSize           = UIScaler.GetSmallFont();
                uiText.horizontalOverflow = HorizontalWrapMode.Wrap;
                text.transform.SetParent(input.transform);
                transform               = text.GetComponent <RectTransform>();
                transform.anchorMin     = Vector2.zero;
                transform.anchorMax     = Vector2.one;
                transform.localPosition = Vector3.zero;
                transform.localScale    = Vector3.one;
                transform.offsetMin     = new Vector2(textPadding * UIScaler.GetPixelsPerUnit(), 0);
                transform.offsetMax     = new Vector2(-textPadding * UIScaler.GetPixelsPerUnit(), 0);

                uiInput.textComponent = uiText;

                if (buttonCall != null)
                {
                    uiInput.onEndEdit.AddListener(delegate { buttonCall(); });
                }
            }
            uiText       = text.GetComponent <UnityEngine.UI.Text>();
            uiText.color = textColor;
            if (textColor.Equals(Color.black))
            {
                uiText.material = (Material)Resources.Load("Fonts/FontMaterial");
            }
            else
            {
                uiText.material = uiText.font.material;
            }
            input.GetComponent <PanCancelInputField>().text = content;
            lastText = content;
        }
Exemplo n.º 18
0
        // Create the about dialog
        public void About()
        {
            ValkyrieDebug.Log("INFO: Accessing about");

            // This will destroy all, because we shouldn't have anything left at the main menu
            Destroyer.Destroy();

            Sprite    bannerSprite;
            Texture2D newTex = Resources.Load("sprites/banner") as Texture2D;

            GameObject banner = new GameObject("banner");

            banner.tag = Game.DIALOG;

            banner.transform.SetParent(Game.Get().uICanvas.transform);

            RectTransform trans = banner.AddComponent <RectTransform>();

            trans.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 1 * UIScaler.GetPixelsPerUnit(), 7f * UIScaler.GetPixelsPerUnit());
            trans.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, (UIScaler.GetWidthUnits() - 18f) * UIScaler.GetPixelsPerUnit() / 2f, 18f * UIScaler.GetPixelsPerUnit());
            banner.AddComponent <CanvasRenderer>();


            Image image = banner.AddComponent <Image>();

            bannerSprite = Sprite.Create(newTex, new Rect(0, 0, newTex.width, newTex.height), Vector2.zero, 1);
            image.sprite = bannerSprite;
            image.rectTransform.sizeDelta = new Vector2(18f * UIScaler.GetPixelsPerUnit(), 7f * UIScaler.GetPixelsPerUnit());

            UIElement ui = new UIElement();

            ui.SetLocation((UIScaler.GetWidthUnits() - 30f) / 2, 10, 30, 6);
            ui.SetText(ABOUT_FFG);
            ui.SetFontSize(UIScaler.GetMediumFont());

            ui = new UIElement();
            ui.SetLocation((UIScaler.GetWidthUnits() - 30f) / 2, 18, 30, 5);
            ui.SetText(ABOUT_LIBS);
            ui.SetFontSize(UIScaler.GetMediumFont());

            ui = new UIElement();
            ui.SetLocation(UIScaler.GetWidthUnits() - 5, UIScaler.GetBottom(-3), 5, 2);
            ui.SetText(Game.Get().version);
            ui.SetFontSize(UIScaler.GetMediumFont());

            ui = new UIElement();
            ui.SetLocation(1, UIScaler.GetBottom(-3), 8, 2);
            ui.SetText(CommonStringKeys.BACK);
            ui.SetFont(Game.Get().gameType.GetHeaderFont());
            ui.SetFontSize(UIScaler.GetMediumFont());
            ui.SetButton(GameStateManager.MainMenu);
            ui.SetBGColor(BUTTON_BG_COLOR);
            new UIElementBorder(ui);
        }
Exemplo n.º 19
0
        // Create the about dialog
        public void About()
        {
            // This will destroy all, because we shouldn't have anything left at the main menu
            Destroyer.Destroy();

            Sprite    bannerSprite;
            Texture2D newTex = Resources.Load("sprites/banner") as Texture2D;

            GameObject banner = new GameObject("banner");

            banner.tag = Game.DIALOG;

            banner.transform.SetParent(Game.Get().uICanvas.transform);

            RectTransform trans = banner.AddComponent <RectTransform>();

            trans.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 1 * UIScaler.GetPixelsPerUnit(), 7f * UIScaler.GetPixelsPerUnit());
            trans.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, (UIScaler.GetWidthUnits() - 18f) * UIScaler.GetPixelsPerUnit() / 2f, 18f * UIScaler.GetPixelsPerUnit());
            banner.AddComponent <CanvasRenderer>();


            UnityEngine.UI.Image image = banner.AddComponent <UnityEngine.UI.Image>();
            bannerSprite = Sprite.Create(newTex, new Rect(0, 0, newTex.width, newTex.height), Vector2.zero, 1);
            image.sprite = bannerSprite;
            image.rectTransform.sizeDelta = new Vector2(18f * UIScaler.GetPixelsPerUnit(), 7f * UIScaler.GetPixelsPerUnit());

            DialogBox db = new DialogBox(
                new Vector2((UIScaler.GetWidthUnits() - 30f) / 2, 10f),
                new Vector2(30, 6),
                ABOUT_FFG);

            db.textObj.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetMediumFont();

            db = new DialogBox(
                new Vector2((UIScaler.GetWidthUnits() - 30f) / 2, 18f),
                new Vector2(30, 5),
                ABOUT_LIBS);
            db.textObj.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetMediumFont();

            db = new DialogBox(
                new Vector2(UIScaler.GetWidthUnits() - 5, UIScaler.GetBottom(-3)),
                new Vector2(5, 2),
                new StringKey(null, Game.Get().version, false));
            db.textObj.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetMediumFont();

            TextButton tb = new TextButton(
                new Vector2(1, UIScaler.GetBottom(-3)),
                new Vector2(8, 2),
                CommonStringKeys.BACK,
                delegate { Destroyer.MainMenu(); });

            tb.background.GetComponent <UnityEngine.UI.Image>().color = new Color(0, 0.03f, 0f);
            tb.SetFont(Game.Get().gameType.GetHeaderFont());
        }
Exemplo n.º 20
0
    public static void DrawMonster(Quest.Monster monster, bool displayHealth = false)
    {
        Game game = Game.Get();

        Texture2D newTex          = ContentData.FileToTexture(monster.monsterData.image);
        Texture2D dupeTex         = Resources.Load("sprites/monster_duplicate_" + monster.duplicate) as Texture2D;
        Sprite    iconSprite      = Sprite.Create(newTex, new Rect(0, 0, newTex.width, newTex.height), Vector2.zero, 1);
        Sprite    duplicateSprite = null;

        if (dupeTex != null)
        {
            duplicateSprite = Sprite.Create(dupeTex, new Rect(0, 0, dupeTex.width, dupeTex.height), Vector2.zero, 1);
        }

        GameObject mImg = new GameObject("monsterImg" + monster.monsterData.name);

        mImg.tag = Game.DIALOG;
        mImg.transform.SetParent(game.uICanvas.transform);

        RectTransform trans = mImg.AddComponent <RectTransform>();

        trans.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 1f * UIScaler.GetPixelsPerUnit(), 8f * UIScaler.GetPixelsPerUnit());
        trans.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, 1f * UIScaler.GetPixelsPerUnit(), 8f * UIScaler.GetPixelsPerUnit());
        mImg.AddComponent <CanvasRenderer>();

        UnityEngine.UI.Image icon = mImg.AddComponent <UnityEngine.UI.Image>();
        icon.sprite = iconSprite;
        icon.rectTransform.sizeDelta = new Vector2(8f * UIScaler.GetPixelsPerUnit(), 8f * UIScaler.GetPixelsPerUnit());

        UnityEngine.UI.Image iconDupe = null;
        if (duplicateSprite != null)
        {
            GameObject mImgDupe = new GameObject("monsterDupe" + monster.monsterData.name);
            mImgDupe.tag = Game.DIALOG;
            mImgDupe.transform.SetParent(game.uICanvas.transform);

            RectTransform dupeFrame = mImgDupe.AddComponent <RectTransform>();
            dupeFrame.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 5f * UIScaler.GetPixelsPerUnit(), UIScaler.GetPixelsPerUnit() * 4f);
            dupeFrame.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, 5f * UIScaler.GetPixelsPerUnit(), 4f * UIScaler.GetPixelsPerUnit());
            mImgDupe.AddComponent <CanvasRenderer>();

            iconDupe        = mImgDupe.AddComponent <UnityEngine.UI.Image>();
            iconDupe.sprite = duplicateSprite;
            iconDupe.rectTransform.sizeDelta = new Vector2(4f * UIScaler.GetPixelsPerUnit(), 4f * UIScaler.GetPixelsPerUnit());
        }

        if (displayHealth)
        {
            DrawMonsterHealth(monster, DrawMonster);
        }
    }
Exemplo n.º 21
0
    // Internal function to create the text from constructors
    void createDialog(Vector2 location, Vector2 size, StringKey textKey, Color fgColour, Color bgColour)
    {
        // Object name includes first 10 chars of text
        string objName = textKey.key;

        if (objName.Length > 10)
        {
            objName = objName.Substring(0, 10);
        }
        // Create an object

        textObj    = new GameObject("text" + objName);
        background = new GameObject("buttonBg" + objName);
        // Mark it as dialog
        textObj.tag    = "dialog";
        background.tag = "dialog";

        Game game = Game.Get();

        background.transform.parent = game.uICanvas.transform;

        RectTransform transBg = background.AddComponent <RectTransform>();

        transBg.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, location.y * UIScaler.GetPixelsPerUnit(), size.y * UIScaler.GetPixelsPerUnit());
        transBg.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, location.x * UIScaler.GetPixelsPerUnit(), size.x * UIScaler.GetPixelsPerUnit());

        textObj.transform.parent = background.transform;

        RectTransform transBt = textObj.AddComponent <RectTransform>();

        transBt.SetParent(transBg);
        transBt.localPosition = Vector2.zero;
        transBt.localScale    = transBg.localScale;
        transBt.sizeDelta     = transBg.sizeDelta;
        transBt.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, 0.1f * UIScaler.GetPixelsPerUnit(), transBt.sizeDelta.x - (0.1f * UIScaler.GetPixelsPerUnit()));

        textObj.AddComponent <CanvasRenderer>();
        background.AddComponent <CanvasRenderer>();

        UnityEngine.UI.Image uiImage = background.AddComponent <UnityEngine.UI.Image>();
        uiImage.color = bgColour;

        UnityEngine.UI.Text uiText = textObj.AddComponent <UnityEngine.UI.Text>();
        uiText.color     = fgColour;
        uiText.text      = textKey.Translate();
        uiText.alignment = TextAnchor.MiddleCenter;
        uiText.font      = game.gameType.GetFont();
        uiText.material  = uiText.font.material;
        uiText.fontSize  = UIScaler.GetSmallFont();
    }
Exemplo n.º 22
0
    // Internal function to create button from constructors
    void createButton(Vector2 location, Vector2 size, string text, UnityEngine.Events.UnityAction call, Color colour, int id)
    {
        // Create objects
        button     = new GameObject("button" + text + id);
        background = new GameObject("buttonBg" + text + id);
        border     = new RectangleBorder(background.transform, colour, size);

        // Mark it as dialog (this can be changed with applytag)
        button.tag     = "dialog";
        background.tag = "dialog";

        Game game = Game.Get();

        background.transform.parent = game.uICanvas.transform;

        RectTransform transBg = background.AddComponent <RectTransform>();

        transBg.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, location.y * UIScaler.GetPixelsPerUnit(), size.y * UIScaler.GetPixelsPerUnit());
        transBg.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, location.x * UIScaler.GetPixelsPerUnit(), size.x * UIScaler.GetPixelsPerUnit());

        button.transform.parent = background.transform;

        RectTransform transBt = button.AddComponent <RectTransform>();

        transBt.SetParent(transBg);

        transBt.localPosition = Vector2.zero;
        transBt.localScale    = transBg.localScale;
        transBt.sizeDelta     = transBg.sizeDelta;

        button.AddComponent <CanvasRenderer>();
        background.AddComponent <CanvasRenderer>();

        UnityEngine.UI.Image uiImage = background.AddComponent <UnityEngine.UI.Image>();
        // Background is partially transparent black
        uiImage.color = new Color(0, 0, 0, (float)0.9);

        UnityEngine.UI.Button uiButton = background.AddComponent <UnityEngine.UI.Button>();
        uiButton.interactable = true;
        uiButton.onClick.AddListener(call);

        uiText           = button.AddComponent <UnityEngine.UI.Text>();
        uiText.color     = colour;
        uiText.text      = text;
        uiText.alignment = TextAnchor.MiddleCenter;
        uiText.font      = game.gameType.GetFont();
        uiText.material  = uiText.font.material;
        // Default to medium font size
        uiText.fontSize = UIScaler.GetMediumFont();
    }
Exemplo n.º 23
0
        /// <summary>
        /// Set the UIElement to text height plus vertical padding</summary>
        /// <param name="space">Additional vertical padding in UIScaler units</param>
        /// <returns>New UIElement height in UIScaler units</returns>
        public virtual float HeightToTextPadding(float space = 0)
        {
            float newHeight = (text.GetComponent <UnityEngine.UI.Text>().preferredHeight / UIScaler.GetPixelsPerUnit()) + (textPaddingDefault * 2f) + space;

            if (newHeight < 1 + (textPaddingDefault * 2f))
            {
                newHeight = 1 + (textPaddingDefault * 2f);
            }
            float oldHeight       = GetRectTransform().sizeDelta.y;
            float newHeightPixels = newHeight * UIScaler.GetPixelsPerUnit();

            GetRectTransform().anchoredPosition = new Vector2(GetRectTransform().anchoredPosition.x, GetRectTransform().anchoredPosition.y - ((newHeightPixels - oldHeight) / 2f));
            GetRectTransform().sizeDelta        = new Vector2(GetRectTransform().sizeDelta.x, newHeightPixels);
            return(newHeight);
        }
Exemplo n.º 24
0
        /// <summary>
        /// Set element text.</summary>
        /// <param name="content">Text to display.</param>
        /// <param name="textColor">Color to display text.</param>
        public virtual void SetText(string content, Color textColor)
        {
            UnityEngine.UI.Text uiText = null;
            if (text == null)
            {
                text                    = new GameObject("UIText");
                text.tag                = tag;
                uiText                  = text.AddComponent <UnityEngine.UI.Text>();
                uiText.alignment        = TextAnchor.MiddleCenter;
                uiText.verticalOverflow = VerticalWrapMode.Overflow;
                uiText.font             = Game.Get().gameType.GetFont();
                uiText.fontSize         = UIScaler.GetSmallFont();
                text.transform.SetParent(bg.transform);
                RectTransform transform = text.GetComponent <RectTransform>();
                transform.anchorMin     = Vector2.zero;
                transform.anchorMax     = Vector2.one;
                transform.localPosition = Vector3.zero;
                transform.localScale    = Vector3.one;
                transform.offsetMin     = new Vector2(textPadding * UIScaler.GetPixelsPerUnit(), 0);
                transform.offsetMax     = new Vector2(-textPadding * UIScaler.GetPixelsPerUnit(), 0);

                if (buttonCall != null)
                {
                    UnityEngine.UI.Button uiButton = text.AddComponent <UnityEngine.UI.Button>();
                    uiButton.interactable = true;
                    uiButton.onClick.AddListener(buttonCall);
                }
                if (buttonCallWithParams != null)
                {
                    UnityEngine.UI.Button uiButton = text.AddComponent <UnityEngine.UI.Button>();
                    uiButton.interactable = true;
                    // use button text as parameters
                    uiButton.onClick.AddListener(delegate { buttonCallWithParams(content); });
                }
            }
            uiText       = text.GetComponent <UnityEngine.UI.Text>();
            uiText.color = textColor;
            if (textColor.Equals(Color.black))
            {
                uiText.material = (Material)Resources.Load("Fonts/FontMaterial");
            }
            else
            {
                uiText.material = uiText.font.material;
            }
            uiText.text = content;
        }
Exemplo n.º 25
0
    public void DrawSlideFrame(Transform trans, float scale = 3f)
    {
        GameObject[] bLine = new GameObject[8];
        // create 4 lines
        for (int i = 0; i < 8; i++)
        {
            bLine[i]     = new GameObject("PuzzleFrame" + i);
            bLine[i].tag = "dialog";
            bLine[i].AddComponent <RectTransform>();
            bLine[i].AddComponent <CanvasRenderer>();
            bLine[i].transform.SetParent(trans);
            UnityEngine.UI.Image blImage = bLine[i].AddComponent <UnityEngine.UI.Image>();
            blImage.color = Color.white;
        }

        // Set the thickness of the lines
        float thick = 0.05f * UIScaler.GetPixelsPerUnit();

        bLine[0].GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Bottom, -thick, thick);
        bLine[0].GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, -thick, (scale * 6f * UIScaler.GetPixelsPerUnit()) + (2 * thick));

        bLine[1].GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, -thick, thick);
        bLine[1].GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, -thick, (scale * 6f * UIScaler.GetPixelsPerUnit()) + (2 * thick));

        bLine[2].GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, -thick, thick);
        bLine[2].GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, -thick, (scale * 6f * UIScaler.GetPixelsPerUnit()) + (2 * thick));

        bLine[3].GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Right, (scale * 2f * UIScaler.GetPixelsPerUnit()) - thick, thick);
        bLine[3].GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, -thick, (scale * 2f * UIScaler.GetPixelsPerUnit()) + thick);

        bLine[4].GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Right, (scale * 2f * UIScaler.GetPixelsPerUnit()) - thick, thick);
        bLine[4].GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Bottom, -thick, (scale * 3f * UIScaler.GetPixelsPerUnit()) + thick);

        bLine[5].GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Right, -thick, thick);
        bLine[5].GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, (scale * 2f * UIScaler.GetPixelsPerUnit()) - thick, (scale * UIScaler.GetPixelsPerUnit()) + (2 * thick));

        bLine[6].GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, (scale * 2f * UIScaler.GetPixelsPerUnit()) - thick, thick);
        bLine[6].GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Right, -thick, (scale * 2f * UIScaler.GetPixelsPerUnit()) + thick);

        bLine[7].GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Bottom, (scale * 3f * UIScaler.GetPixelsPerUnit()) - thick, thick);
        bLine[7].GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Right, -thick, (scale * 2f * UIScaler.GetPixelsPerUnit()) + thick);
    }
Exemplo n.º 26
0
        // Import content
        public void Import(string type)
        {
            Destroyer.Destroy();

            // Create an object
            GameObject logo = new GameObject("logo");

            // Mark it as dialog
            logo.tag = Game.DIALOG;
            logo.transform.SetParent(Game.Get().uICanvas.transform);

            RectTransform transBg = logo.AddComponent <RectTransform>();

            transBg.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, UIScaler.GetHCenter(-3) * UIScaler.GetPixelsPerUnit(), 6 * UIScaler.GetPixelsPerUnit());
            transBg.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 8 * UIScaler.GetPixelsPerUnit(), 6 * UIScaler.GetPixelsPerUnit());

            // Create the image
            Texture2D tex    = Resources.Load("sprites/logo") as Texture2D;
            Sprite    sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), Vector2.zero, 1);

            UnityEngine.UI.Image uiImage = logo.AddComponent <UnityEngine.UI.Image>();
            uiImage.sprite = sprite;
            logo.AddComponent <SpritePulser>();

            // Display message
            UIElement ui = new UIElement();

            ui.SetLocation(2, 20, UIScaler.GetWidthUnits() - 4, 2);
            ui.SetText(CONTENT_IMPORTING);
            ui.SetFontSize(UIScaler.GetMediumFont());
            if (type.Equals("D2E"))
            {
                importThread = new Thread(new ThreadStart(delegate { fcD2E.Import(); }));
            }
            if (type.Equals("MoM"))
            {
                importThread = new Thread(new ThreadStart(delegate { fcMoM.Import(); }));
            }
            importThread.Start();
            //while (!importThread.IsAlive) ;
        }
Exemplo n.º 27
0
    // Update redraws the selection UI
    virtual public void Update()
    {
        RefreshReference();

        game = Game.Get();

        float scrollPos = -14.5f * UIScaler.GetPixelsPerUnit();

        if (scrollArea != null && !scrollArea.ObjectDestroyed())
        {
            scrollPos = scrollArea.GetScrollPosition();
        }
        Clean();

        AddScrollArea();

        float offset = 0;

        offset = DrawComponentSelection(offset);

        offset = AddSubComponents(offset);

        offset = AddSource(offset);

        offset = AddComment(offset);

        scrollArea.SetScrollSize(offset);
        scrollArea.SetScrollPosition(scrollPos);

        UIElement ui = new UIElement(Game.EDITOR);

        ui.SetLocation(0, 0, 1, 1);
        ui.SetText("<b>⇦</b>", Color.cyan);
        ui.SetTextAlignment(TextAnchor.LowerCenter);
        ui.SetButton(delegate { QuestEditorData.Back(); });
        ui.SetBGColor(Color.black);
        new UIElementBorder(ui, Color.cyan);

        AddTitle();
    }
Exemplo n.º 28
0
    void AddHero(Game.Hero h, Game game)
    {
        Sprite heroSprite;

        string    heroName = h.id.ToString();
        Texture2D newTex   = Resources.Load("sprites/tokens/objective-token-black") as Texture2D;

        if (h.heroData != null)
        {
            string imagePath = @"file://" + h.heroData.image;
            WWW    www       = new WWW(imagePath);
            newTex = new Texture2D(256, 256, TextureFormat.DXT5, false);
            www.LoadImageIntoTexture(newTex);
            heroName = h.heroData.name;
        }

        GameObject heroImg = new GameObject("heroImg" + heroName);

        heroImg.tag = "herodisplay";

        heroImg.transform.parent = game.uICanvas.transform;

        RectTransform trans = heroImg.AddComponent <RectTransform>();

        trans.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, (0.25f + offset) * UIScaler.GetPixelsPerUnit(), heroSize * UIScaler.GetPixelsPerUnit());
        offset += heroSize + 0.5f;
        trans.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, 0.25f * UIScaler.GetPixelsPerUnit(), heroSize * UIScaler.GetPixelsPerUnit());
        heroImg.AddComponent <CanvasRenderer>();

        UnityEngine.UI.Image image = heroImg.AddComponent <UnityEngine.UI.Image>();
        icons.Add(h.id, image);
        heroSprite   = Sprite.Create(newTex, new Rect(0, 0, newTex.width, newTex.height), Vector2.zero, 1);
        image.sprite = heroSprite;
        image.rectTransform.sizeDelta = new Vector2(heroSize * UIScaler.GetPixelsPerUnit(), heroSize * UIScaler.GetPixelsPerUnit());

        UnityEngine.UI.Button button = heroImg.AddComponent <UnityEngine.UI.Button>();
        button.interactable = true;
        button.onClick.AddListener(delegate { HeroDiag(h.id); });
    }
Exemplo n.º 29
0
    public void HeroSelectButton(Vector2 position, HeroData hd, int id, bool disabled = false)
    {
        Sprite    heroSprite;
        Texture2D newTex = Resources.Load("sprites/tokens/objective-token-black") as Texture2D;
        string    name   = "";

        if (hd != null)
        {
            string imagePath = @"file://" + hd.image;
            WWW    www       = new WWW(imagePath);
            newTex = new Texture2D(256, 256, TextureFormat.DXT5, false);
            www.LoadImageIntoTexture(newTex);
            name = hd.name;
        }

        GameObject heroImg = new GameObject("heroImg" + name);

        heroImg.tag = "dialog";

        Game game = Game.Get();

        heroImg.transform.parent = game.uICanvas.transform;

        RectTransform trans = heroImg.AddComponent <RectTransform>();

        trans.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, position.y * UIScaler.GetPixelsPerUnit(), 5f * UIScaler.GetPixelsPerUnit());
        trans.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, position.x * UIScaler.GetPixelsPerUnit(), 5f * UIScaler.GetPixelsPerUnit());
        heroImg.AddComponent <CanvasRenderer>();


        UnityEngine.UI.Image image = heroImg.AddComponent <UnityEngine.UI.Image>();
        heroSprite   = Sprite.Create(newTex, new Rect(0, 0, newTex.width, newTex.height), Vector2.zero, 1);
        image.sprite = heroSprite;
        image.rectTransform.sizeDelta = new Vector2(5f * UIScaler.GetPixelsPerUnit(), 5f * UIScaler.GetPixelsPerUnit());

        UnityEngine.UI.Button button = heroImg.AddComponent <UnityEngine.UI.Button>();
        button.interactable = !disabled;
        button.onClick.AddListener(delegate { SelectHero(id, name); });
    }
Exemplo n.º 30
0
    // Create a button for a hero selection option
    public void HeroSelectButton(Vector2 position, HeroData hd, int id, bool disabled = false)
    {
        Sprite heroSprite;
        // Should be game type specific
        Texture2D newTex = Resources.Load("sprites/borders/grey_frame") as Texture2D;
        string    name   = "";

        // is this an empty hero option?
        if (hd != null)
        {
            newTex = ContentData.FileToTexture(hd.image);
            name   = hd.name;
        }

        GameObject heroImg = new GameObject("heroImg" + name);

        heroImg.tag = "dialog";

        Game game = Game.Get();

        heroImg.transform.parent = game.uICanvas.transform;

        RectTransform trans = heroImg.AddComponent <RectTransform>();

        trans.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, position.y * UIScaler.GetPixelsPerUnit(), 4.25f * UIScaler.GetPixelsPerUnit());
        trans.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, position.x * UIScaler.GetPixelsPerUnit(), 4.25f * UIScaler.GetPixelsPerUnit());
        heroImg.AddComponent <CanvasRenderer>();


        UnityEngine.UI.Image image = heroImg.AddComponent <UnityEngine.UI.Image>();
        heroSprite   = Sprite.Create(newTex, new Rect(0, 0, newTex.width, newTex.height), Vector2.zero, 1);
        image.sprite = heroSprite;
        image.rectTransform.sizeDelta = new Vector2(4.25f * UIScaler.GetPixelsPerUnit(), 4.25f * UIScaler.GetPixelsPerUnit());

        UnityEngine.UI.Button button = heroImg.AddComponent <UnityEngine.UI.Button>();
        button.interactable = !disabled;
        button.onClick.AddListener(delegate { SelectHero(id, name); });
    }