Ejemplo n.º 1
0
    private static UnderFont GetUnderFont(string fontName)
    {
        XmlDocument xml      = new XmlDocument();
        string      fontPath = FileLoader.requireFile("Sprites/UI/Fonts/" + fontName + ".png");
        string      xmlPath  = FileLoader.requireFile("Sprites/UI/Fonts/" + fontName + ".xml", false);

        if (xmlPath == null)
        {
            return(null);
        }
        try { xml.Load(xmlPath); }
        catch (XmlException ex) {
            UnitaleUtil.DisplayLuaError("Instanciating a font", "An error was encountered while loading the font \"" + fontName + "\":\n\n" + ex.Message);
            return(null);
        }
        if (xml["font"] == null)
        {
            UnitaleUtil.DisplayLuaError("Instanciating a font", "The font '" + fontName + "' doesn't have a font element at its root.");
            return(null);
        }
        Dictionary <char, Sprite> fontMap = LoadBuiltInFont(xml["font"]["spritesheet"], fontPath);

        UnderFont underfont;

        try { underfont = new UnderFont(fontMap, fontName); }
        catch {
            UnitaleUtil.DisplayLuaError("Instanciating a font", "The fonts need a space character to compute their line height, and the font '" + fontName + "' doesn't have one.");
            return(null);
        }

        if (xml["font"]["voice"] != null)
        {
            underfont.Sound = AudioClipRegistry.GetVoice(xml["font"]["voice"].InnerText);
        }
        if (xml["font"]["linespacing"] != null)
        {
            underfont.LineSpacing = ParseUtil.GetFloat(xml["font"]["linespacing"].InnerText);
        }
        if (xml["font"]["charspacing"] != null)
        {
            underfont.CharSpacing = ParseUtil.GetFloat(xml["font"]["charspacing"].InnerText);
        }
        if (xml["font"]["color"] != null)
        {
            underfont.DefaultColor = ParseUtil.GetColor(xml["font"]["color"].InnerText);
        }

        return(underfont);
    }