Exemple #1
0
        /// <summary>Called when an @font-face font fully loads.</summary>
        public void FontLoaded(DynamicFont font)
        {
            if (FontToDraw == null || Characters == null)
            {
                return;
            }

            if (FontToDraw == font)
            {
                Kerning   = null;
                SpaceSize = 0f;
                SetText();

                if (Visible)
                {
                    NowOnScreen();
                }

                return;
            }

            DynamicFont fallback = FontToDraw.Fallback;

            while (fallback != null)
            {
                if (fallback == font)
                {
                    // Fallback font now available - might change the rendering.
                    Kerning   = null;
                    SpaceSize = 0f;
                    SetText();

                    if (Visible)
                    {
                        NowOnScreen();
                    }

                    return;
                }

                fallback = fallback.Fallback;
            }
        }
Exemple #2
0
        protected void LoadFontSettings(
            string file,
            IDictionary <string, Tuple <float, float> > sizes,
            IDictionary <string, DynamicFont> fonts)
        {
            if (File.Exists(file) == false)
            {
                GlobalConstants.ActionLog.Log("Could not find font settings file " + file, LogLevel.Warning);
                return;
            }

            JSONParseResult result = JSON.Parse(File.ReadAllText(file));

            if (result.Error != Error.Ok)
            {
                this.ValueExtractor.PrintFileParsingError(result, file);
            }

            if (!(result.Result is Dictionary dictionary))
            {
                GlobalConstants.ActionLog.Log("Could not parse JSON to Dictionary from " + file, LogLevel.Warning);
                return;
            }

            ICollection <Dictionary> fontSettings =
                this.ValueExtractor.GetArrayValuesCollectionFromDictionary <Dictionary>(dictionary, "GUIData");

            foreach (Dictionary fontDict in fontSettings)
            {
                string name        = this.ValueExtractor.GetValueFromDictionary <string>(fontDict, "Name");
                string value       = this.ValueExtractor.GetValueFromDictionary <string>(fontDict, "Value");
                float  minFontSize = this.ValueExtractor.GetValueFromDictionary <float>(fontDict, "MinFontSize");
                float  maxFontSize = this.ValueExtractor.GetValueFromDictionary <float>(fontDict, "MaxFontSize");

                DynamicFont font = GD.Load <DynamicFont>(
                    GlobalConstants.GODOT_ASSETS_FOLDER +
                    "Fonts/" +
                    value) ?? this.LoadedFonts["default"];

                sizes.Add(name, new Tuple <float, float>(minFontSize, maxFontSize));
                fonts.Add(name, font);
            }
        }
        /// <summary>
        /// Initializes the control with provided values.
        /// </summary>
        /// <param name="deselectedTexture">Texture of deactivated control</param>
        /// <param name="selectedTexture">Texture of activated control</param>
        /// <param name="controlValue">Value of the control</param>
        /// <param name="defaultSelected">Sets whether the control is selected by default</param>
        /// <param name="labelText">Text of the control's label</param>
        /// <param name="font">Font of the control's label</param>
        public void Init(Texture deselectedTexture, Texture selectedTexture, int controlValue, bool defaultSelected = false,
                         string labelText = null, DynamicFont font = null)
        {
            base.Init(deselectedTexture, selectedTexture, controlValue, defaultSelected);

            _labelText = labelText;
            _font      = font;

            _centerContainer = GetNode <CenterContainer>("CenterContainer");
            Label            = _centerContainer.GetNode <Label>("Label");

            Label.Align  = Label.AlignEnum.Center;
            Label.Valign = Label.VAlign.Center;

            if (!string.IsNullOrEmpty(_labelText) && _font != null)
            {
                Label.AddFontOverride("font", _font);
                Label.Text = _labelText;
            }
        }
        /// <summary>Called when an @font-face font loads.</summary>
        public void FontLoaded(DynamicFont font)
        {
            if (childNodes_ == null)
            {
                return;
            }

            int count = childNodes_.length;

            for (int i = 0; i < count; i++)
            {
                IRenderableNode node = (childNodes_[i] as IRenderableNode);

                if (node == null)
                {
                    continue;
                }

                node.FontLoaded(font);
            }
        }
Exemple #5
0
    public override void _Ready()
    {
        var font = new DynamicFont();

        font.FontData = ResourceLoader.Load <DynamicFontData>("res://assets/TechTreeFont.ttf");
        font.Size     = 28;

        for (var i = 1; i < 6; i++)
        {
            var nodePath = GetNodePath(i);
            GetNode <Label>($"{nodePath}/Name").AddFontOverride("font", font);
            GetNode <Label>($"{nodePath}/Score").AddFontOverride("font", font);
            GetNode <Label>($"{nodePath}/Raw").AddFontOverride("font", font);
            GetNode <Label>($"{nodePath}/Science").AddFontOverride("font", font);
            GetNode <Label>($"{nodePath}/Power").AddFontOverride("font", font);
        }

        Signals.PlayerUpdatedEvent += OnPlayerUpdated;

        SetLeaderboardRows();
    }
Exemple #6
0
        /// <summary>Finds and connects the font(s) for the given text renderer.</summary>
        private void Find(string fontName, TextRenderingProperty text)
        {
            fontName = fontName.Replace("\"", "");

            string[] pieces = fontName.Split(',');

            DynamicFont current = null;

            // Grab the doc:
            Document doc = text.Element.Document;

            for (int i = 0; i < pieces.Length; i++)
            {
                // Trim the name:
                fontName = pieces[i].Trim();

                // Get the font from this DOM:
                DynamicFont backup = doc.GetOrCreateFont(fontName);

                if (backup == null)
                {
                    // Font not described in the HTML at all or isn't available in the project.
                    continue;
                }

                if (current != null)
                {
                    // Hook up the fallback:
                    current.Fallback = backup;
                }

                current = backup;

                if (text.FontToDraw == null)
                {
                    text.FontToDraw = current;
                }
            }
        }
Exemple #7
0
        public override void Load(IResourceCache cache, ResourcePath path)
        {
            if (!cache.ContentFileExists(path))
            {
                throw new FileNotFoundException("Content file does not exist for texture");
            }
            if (!cache.TryGetDiskFilePath(path, out string diskPath))
            {
                throw new InvalidOperationException("Textures can only be loaded from disk.");
            }

            var res = ResourceLoader.Load(diskPath);

            if (!(res is DynamicFontData fontData))
            {
                throw new InvalidDataException("Path does not point to a font.");
            }

            FontData = fontData;
            Font     = new DynamicFont();
            Font.AddFallback(FontData);
        }
Exemple #8
0
    /// <summary>
    /// Initialization
    /// </summary>
    public override void _Ready()
    {
        vbox              = GetNode <VBoxContainer>("ScrollContainer/VBoxContainer");
        gridContainer     = GetNode <GridContainer>("ScrollContainer/VBoxContainer/GridContainer");
        assignmentBL      = new AssignmentBL();
        assignmentScoreBL = new AssignmentScoreBL();
        nextBtn           = GetNode <TextureButton>("NextBtn");
        prevBtn           = GetNode <TextureButton>("PrevBtn");
        title             = GetNode <Sprite>("Title");
        dFont             = new DynamicFont();
        dFont.FontData    = ResourceLoader.Load("res://Fonts/Candy Beans.otf") as DynamicFontData;
        dFont.Size        = 26;


        dFont2          = new DynamicFont();
        dFont2.FontData = ResourceLoader.Load("res://Fonts/Candy Beans.otf") as DynamicFontData;
        dFont2.Size     = 18;
        assignmentList  = assignmentBL.GetStudentAssignment(Global.StudentId);
        DisplayHeader();
        DisplayAssignment();
        prevBtn.Disabled = true;
    }
Exemple #9
0
    public override void _Ready()
    {
        GD.Randomize();

        // Get references to all the nodes we need to manipulate
        _mortar            = GetNode <Mortar>("MortarPestle/Mortar");
        _potionCircle      = GetNode <PotionCircle>("MortarPestle/Crush/PotionCircle");
        _potionReagentsBox = GetNode <VBoxContainer>("MortarPestle/PickReagents/PotionReagentsBox");
        _helpDialog        = GetNode <AcceptDialog>("HelpDialog");
        _proceedToCrush    = GetNode <Button>("MortarPestle/PickReagents/ProceedToCrush");
        _tween             = GetNode <Tween>("MortarPestle/PickReagents/Tween");
        _inventory         = GetNode <Inventory>("MortarPestle/PickReagents/Inventory");
        _inventory.SetSize(4, 4);
        _inventory.DrawPosition = new Vector2(324f, 16f);
        _inventory.CanDeselect  = false;
        _itemTooltip            = GetNode <ItemTooltip>("MortarPestle/PickReagents/ItemTooltip");
        _debugOverlay           = GetNode <DebugOverlay>("DebugOverlay");

        // Load assets needed
        _itemBtnBg      = GD.Load <Texture>("res://textures/item_slot.png");
        _singleItemSlot = GD.Load <Texture>("res://textures/single_item_slot.png");
        _smallFont      = GD.Load <DynamicFont>("res://font/small_font.tres");

        // Signal connections
        GetNode <TouchScreenButton>("HelpButton").Connect("released", this, nameof(DisplayHelpPopup));
        _proceedToCrush.Connect("pressed", this, nameof(ProceedToCrushPressed));
        _tween.Connect("tween_all_completed", this, nameof(TweenAllCompleted));
        _inventory.Connect("ItemSlotSelected", this, nameof(InventorySlotSelected));
        GetNode <Button>("MortarPestle/PickReagents/AddToPotion").Connect("pressed", this, nameof(ItemButtonReleased));

        // Adding items to simulate an inventory
        _itemList.AddRange(new Item.ItemStack[] { new Item.ItemStack(Items.BRIMSTONE, 1), new Item.ItemStack(Items.FLY_AGARIC, 3), new Item.ItemStack(Items.ELDERBERRIES, 5), new Item.ItemStack(Items.ORPIMENT, 1), new Item.ItemStack(Items.HOLLY_BERRIES, 3) });
        _inventory.UpdateSlots(_itemList);

        // Tracking stuff for debug
        _debugOverlay.TrackProperty(nameof(_mortarPestleStage), this, "MortarPestleStage");
        _debugOverlay.TrackProperty(nameof(_mortar.CurrentParticleColour), _mortar, "Splash Colour");
    }
        /// <summary>Gets the best font face.</summary>
        public FontFace GetFace(int style, int synth)
        {
            FontFace result = null;

            for (int i = 0; i < Fonts.Length; i++)
            {
                // Loaded?
                DynamicFont df = Fonts[i];

                if (df.Family != null)
                {
                    result = df.Family.GetFace(style, synth);

                    if (result != null)
                    {
                        return(result);
                    }
                }
            }

            // No suitable face found.
            return(null);
        }
        /// <summary>Gets the font with the given name. May load it from the cache or generate a new one.</summary>
        /// <param name="fontName">The name of the font to find.</param>
        /// <returns>A dynamic font if found; null otherwise.</returns>
        public DynamicFont GetOrCreateFont(string fontName)
        {
            if (fontName == null)
            {
                return(null);
            }

            DynamicFont result;

            // Cache contains all available fonts for this document/ renderer.
            ActiveFonts.TryGetValue(fontName, out result);

            if (result == null)
            {
                // Go get the font now:
                result = DynamicFont.Get(fontName);

                // And add it:
                ActiveFonts[fontName] = result;
            }

            return(result);
        }
Exemple #12
0
    /// <summary>
    /// Initialization
    /// </summary>
    public override void _Ready()
    {
        customLevelBL   = new CustomLevelBL();
        customLevelList = customLevelBL.GetCustomLevels();
        vbox            = GetNode <VBoxContainer>("ScrollContainer/VBoxContainer");
        nextBtn         = GetNode <TextureButton>("NextBtn");
        prevBtn         = GetNode <TextureButton>("PrevBtn");
        title           = GetNode <Sprite>("Title");

        gridContainer  = GetNode <GridContainer>("ScrollContainer/VBoxContainer/GridContainer");
        dFont          = new DynamicFont();
        dFont.FontData = ResourceLoader.Load("res://Fonts/Candy Beans.otf") as DynamicFontData;
        dFont.Size     = 26;


        dFont2          = new DynamicFont();
        dFont2.FontData = ResourceLoader.Load("res://Fonts/Candy Beans.otf") as DynamicFontData;
        dFont2.Size     = 18;

        prevBtn.Disabled = true;
        DisplayHeader();
        DisplayGameList();
    }
Exemple #13
0
 public override void _EnterTree()
 {
     _debugFont = GD.Load <DynamicFont>("res://core/debug_font.tres");
 }
 /// <summary>Called when a font-face is ready.</summary>
 public void FontLoaded(DynamicFont font)
 {
 }
Exemple #15
0
 public override void _Ready()
 {
     square    = GD.Load <Image>("res://white_square_128.png");
     gridFont  = GD.Load <DynamicFont>("res://grid_label_font.tres");
     gridTheme = GD.Load <Theme>("res://grid_square_theme.tres");
 }
//--------------------------------------
		/// <summary>Called when an @font-face font fully loads.</summary>
		public void FontLoaded(DynamicFont font){
			
			if(FontToDraw==null || Characters==null){
				return;
			}
			
			if(FontToDraw==font){
				Kerning=null;
				SpaceSize=0f;
				SetText();
				
				if(Visible){
					NowOnScreen();
				}
				
				return;
				
			}
				
			DynamicFont fallback=FontToDraw.Fallback;
			while(fallback!=null){
				
				if(fallback==font){
					// Fallback font now available - might change the rendering.
					Kerning=null;
					SpaceSize=0f;
					SetText();
					
					if(Visible){
						NowOnScreen();
					}
					
					return;
				}
				
				fallback=fallback.Fallback;
			}
			
		}
Exemple #18
0
 public static ImFontPtr AddFont(DynamicFont font)
 {
     return(AddFont(font.FontData, font.Size));
 }
    public void OnLevelCompleted(LevelResult result, SceneManager parent)
    {
        this.parent = parent;

        VBoxContainer textContainer  = (VBoxContainer)FindNode("TextContainer");
        VBoxContainer splitContainer = (VBoxContainer)FindNode("UISplitContainer");

        splitContainer.Set("custom_constants/separation", 200 - result.enemies.Count * 18);

        DynamicFont headerFont = new DynamicFont();

        headerFont.FontData     = (DynamicFontData)ResourceLoader.Load("res://fonts/Comfortaa-Bold.ttf");
        headerFont.OutlineSize  = 3;
        headerFont.OutlineColor = new Color("#000000");
        headerFont.Size         = 36;

        Label waveCompletedLabel = new Label();

        waveCompletedLabel.Text = "Game over";
        waveCompletedLabel.AddFontOverride("font", headerFont);

        textContainer.AddChild(waveCompletedLabel);

        DynamicFont waveClearedFont = new DynamicFont();

        waveClearedFont.FontData     = (DynamicFontData)ResourceLoader.Load("res://fonts/Comfortaa-Bold.ttf");
        waveClearedFont.OutlineSize  = 3;
        waveClearedFont.OutlineColor = new Color("#000000");
        waveClearedFont.Size         = 24;

        Label waveClearedLabel = new Label();

        waveClearedLabel.Text = "Reached wave " + result.waveNum + " at -" + result.altitude + "M";
        waveClearedLabel.AddFontOverride("font", waveClearedFont);

        textContainer.AddChild(waveClearedLabel);

        DynamicFont font = new DynamicFont();

        font.FontData     = (DynamicFontData)ResourceLoader.Load("res://fonts/Comfortaa-Bold.ttf");
        font.OutlineSize  = 2;
        font.OutlineColor = new Color("#000000");
        font.Size         = 16;

        Label enemyHeaderLabel = new Label();

        enemyHeaderLabel.Text = "Enemies slain";
        enemyHeaderLabel.AddFontOverride("font", font);

        textContainer.AddChild(enemyHeaderLabel);

        int totalXP = 0;

        foreach (KeyValuePair <string, EnemyResult> entry in result.getEnemies())
        {
            Label label = new Label();
            label.Text = "    " + entry.Value.count + " x " + entry.Key;
            label.AddFontOverride("font", font);

            totalXP += entry.Value.xp * entry.Value.count;

            textContainer.AddChild(label);
        }

        Label totalTotalXpLabel = new Label();

        totalTotalXpLabel.Text = "Total xp";
        totalTotalXpLabel.AddFontOverride("font", font);

        textContainer.AddChild(totalTotalXpLabel);

        Label totalTotalTotalXpLabel = new Label();

        totalTotalTotalXpLabel.Text = "    " + result.getTotalXp();
        totalTotalTotalXpLabel.AddFontOverride("font", font);

        textContainer.AddChild(totalTotalTotalXpLabel);
    }
        private bool LoadFont(Value value)
        {
            Value  path = value["url"];
            string pathValue;

            if (path != null)
            {
                // Get the text value:
                pathValue = path.Text;
            }
            else
            {
                // Read the raw value:
                pathValue = value.Text;
            }

            DataPackage package = new DataPackage(pathValue, Document.basepath);

            package.onload = delegate(UIEvent e){
                // Load the face - it will by default add to it's "native" family:
                FontFace loaded = FontLoader.Load(package.responseBytes);

                if (loaded == null || loaded.Family == null)
                {
                    Dom.Log.Add("@font-face error: invalid font file at " + package.location.absolute);
                    return;
                }

                // Got any weight, stretch or style overrides?
                Css.Value styleValue   = style["font-style"];
                Css.Value weightValue  = style["font-weight"];
                Css.Value stretchValue = style["font-stretch"];

                if (styleValue != null || weightValue != null || stretchValue != null)
                {
                    // Yep!

                    // New style value:
                    int styleV = (styleValue == null) ? loaded.Style : styleValue.GetInteger(null, Css.Properties.FontStyle.GlobalProperty);

                    // New weight value:
                    int weight = (weightValue == null) ? loaded.Weight : weightValue.GetInteger(null, Css.Properties.FontWeight.GlobalProperty);

                    // New stretch value:
                    int stretch = (stretchValue == null) ? loaded.Stretch : stretchValue.GetInteger(null, Css.Properties.FontStretch.GlobalProperty);

                    // Update the flags:
                    loaded.SetFlags(styleV, weight, stretch);
                }

                Value family = style["font-family"];

                // Grab the family name:
                string familyName;

                if (family == null || family.Text == null)
                {
                    familyName = loaded.Family.Name;
                }
                else
                {
                    familyName = family.Text.Trim();
                }

                // Add as an active font:
                Dictionary <string, DynamicFont> fonts = Document.ActiveFonts;

                DynamicFont dFont;
                if (!fonts.TryGetValue(familyName, out dFont))
                {
                    // Create the font object:
                    dFont        = new DynamicFont(familyName);
                    dFont.Family = loaded.Family;

                    fonts[familyName] = dFont;
                }
                else
                {
                    // Hook up the "real" family:
                    dFont.Family = loaded.Family;

                    // Tell all instances using this dFont that the font is ready:
                    Document.FontLoaded(dFont);
                }
            };

            // Send now:
            package.send();

            return(true);
        }