Пример #1
0
        // Loading the content and setting up said content
        public void LoadContent(ContentManager Content, GraphicsDevice graphicsDevice)
        {
            backgroundManager.LoadContent(Content, graphicsDevice, @"Backgrounds\Clouds\Cloud-Plasma-1", @"Backgrounds\Clouds\Cloud-Plasma-2");

            HeaderFont = Content.Load <SpriteFont>(@"Fonts\StartMenuHeaderFont");
            HUDFont    = Content.Load <SpriteFont>(@"Fonts\HUDFont");

            HeaderPosition = new Vector2(Game1.ViewPortWidth / 2 - (HeaderFont.MeasureString(MenuTitle).X / 2), Game1.ViewPortHeight / 20);
            MadeByPosition = new Vector2(10, Game1.ViewPortHeight - HUDFont.MeasureString("Made by Nathan Todd").Y);

            boxHeaderLine = new Box(new Vector2(Game1.ViewPortWidth / 2 - (float)((
                                                                                      HeaderFont.MeasureString(MenuTitle).X * 1.3) / 2), Game1.ViewPortHeight / 6),
                                    (int)(HeaderFont.MeasureString(MenuTitle).X * 1.3), 2, 0, Color.White * 0.4f, Color.White, graphicsDevice);

            btnNewGame = new Button(new Vector2(Game1.ViewPortWidth / 2 - 168, Game1.ViewPortHeight / 3), 336, 69, 0, Color.Black * 0.3f, Color.YellowGreen * 0.3f,
                                    Color.White, Color.White * 0.6f, "New Game", @"Fonts\StartMenuButtonFont");

            btnOptions = new Button(new Vector2(Game1.ViewPortWidth / 2 - 168, Game1.ViewPortHeight / 3 + 69), 336, 69, 0, Color.Black * 0.15f, Color.YellowGreen * 0.15f,
                                    Color.White, Color.White * 0.6f, "Options", @"Fonts\StartMenuButtonFont");

            btnExit = new Button(new Vector2(Game1.ViewPortWidth / 2 - 168, Game1.ViewPortHeight / 3 + 138), 336, 69, 0, Color.Black * 0.3f, Color.YellowGreen * 0.3f,
                                 Color.White, Color.White * 0.6f, "Exit", @"Fonts\StartMenuButtonFont");

            guiSystem.Add(boxHeaderLine);
            guiSystem.Add(btnNewGame);
            guiSystem.Add(btnOptions);
            guiSystem.Add(btnExit);

            guiSystem.LoadContent(Content, graphicsDevice);
            guiSystem.ButtonIndexUpdate(0);
        }
Пример #2
0
    /*
     * Converts each of the characters into the given enumerators
     */
    HUDFont[] FromStringToEnum(string input, FontStyle style = FontStyle.SR)
    {
        if (input == null)
        {
            return(null);
        }

        char[]    charArray   = input.ToCharArray();
        HUDFont[] returnArray = new HUDFont[charArray.Length];
        for (int i = 0; i < charArray.Length; i++)
        {
            string  charName = charToName(charArray[i]);
            HUDFont result;
            // if we cannot TryParse, and it fails, we add a ? in place of that value
            // unless that font doesn't contain a ?, in which case we're going to use a WhiteSp
            if (Enum.TryParse <HUDFont>(style.ToString() + charName, out result))
            {
                returnArray[i] = result;
            }
            else
            {
                returnArray[i] = (HUDFont)Enum.Parse(typeof(HUDFont), "WhiteSp"); // in the event there's no known symbol to match, we simply use whitespace
            }
        }

        return(returnArray);
    }
Пример #3
0
    /*
     * Updates the onscreen text.
     */
    void UpdateText()
    {
        //lastUpdate = 0;

        HUDFont[] characters = FromStringToEnum(value, _style);
        if (characters == null)
        {
            return;
        }
        // if we're doing right to left, the characters must be reversed in order to not appear backwards
        if (fromRight)
        {
            Array.Reverse(characters);
        }

        SyncImageAmount(characters.Length);

        float startPos = 0;

        for (int i = 0; i < characters.Length; i++)
        {
            Transform child = transform.GetChild(i);
            Image     image = child.GetComponent <Image>();
            image.material = imageMaterial;
            RectTransform rt = child.GetComponent <RectTransform>();
            Sprite        sprite;
            HUDFont       currentChar = characters[i];

            if (image == null)
            {
                continue;
            }

            // setting anchor on the right side if we're starting from the right (numbers and such)
            if (fromRight)
            {
                rt.anchorMin = new Vector2(1, yAnchor);
                rt.anchorMax = new Vector2(1, yAnchor);
            }
            else
            {
                rt.anchorMax = new Vector2(0, yAnchor);
                rt.anchorMin = new Vector2(0, yAnchor);
            }

            // defined whitespace size by 0, as all HUDFonts have a 0 and is reasonble size to become a space.
            if (currentChar == HUDFont.WhiteSp)
            {
                if (!Enum.TryParse(_style.ToString() + "0", out currentChar))
                {
                    continue;
                }
                // disabling the image so we don't see a 0 in place of where white space should exist.
                image.enabled = false;
            }
            else
            {
                image.enabled = true;
            }


            sprite = UISpriteLoader.instance.RetrieveSprite("HUD_Font", "HUD_Font_" + (int)currentChar);

            if (sprite == null)
            {
                continue;
            }

            image.sprite = sprite;
            // multiplying the rect by letter scaling so characters aren't too small
            rt.sizeDelta = new Vector2(sprite.rect.size.x * letterScaling, sprite.rect.size.y * letterScaling);
            // position on the x axis is defined by the center of the image
            float xPos = (rt.sizeDelta.x / 2) + startPos;
            rt.localScale = new Vector3(1, 1, 1);

            if (fromRight)
            {
                xPos *= -1;
            }

            rt.anchoredPosition = new Vector2(xPos, 0);

            // shifting the start position of each letter by the last + the spacing
            startPos += rt.sizeDelta.x + letterSpacing;
        }
    }