private IEnumerator loadFonts() { UrlDir.UrlConfig[] fontConfigs = GameDatabase.Instance.GetConfigs("ASP_BITMAP_FONT"); _totalFonts = fontConfigs.Length; _loadedFonts = 0; foreach (UrlDir.UrlConfig url in fontConfigs) { if (!url.config.HasValue("name")) { Utils.Log("missing font name in {0}", url); } _statusText = url.config.GetValue("displayName") + "-" + url.config.GetValue("size"); Utils.Log("FontCache: Loading font {0}", _statusText); try { BitmapFont font = new BitmapFont(url.config, url.parent.url); _fontCache.addFont(font); ++_loadedFonts; } catch { Utils.LogError("error loading font {0}", _statusText); } yield return null; } _fontCache.updateCache(); _ready = true; }
public void drawText(string text, BitmapFont font, IntVector2 position, Rotation rotation, Color32 color, bool mirror, AlphaOption alphaOption, byte textureAlpha, BlendMethod blendMethod, BoundingBox boundingBox = null) { if (Global.Debug2) Utils.Log("text {0}, x {1}, y {2}", text, position.x, position.y); IntVector2 charPos = new IntVector2(position); bool escapeMode = false; string textToWrite = string.Empty; if (mirror) textToWrite = ASP.Utils.Reverse(text); else textToWrite = text; foreach (char c in textToWrite) { if (c == '\\') { escapeMode = !escapeMode; } if (escapeMode) { if (c == 'n') { switch (rotation) { case Rotation.R90: charPos.x -= font.size; charPos.y = position.y; break; case Rotation.R270: charPos.x += font.size; charPos.y = position.y; break; case Rotation.R0: charPos.y -= font.size; charPos.x = position.x; break; case Rotation.R180: default: charPos.y += font.size; charPos.x = position.x; break; } } if (c != '\\') escapeMode = false; } else drawCharacter(c, font, ref charPos, rotation, color, mirror, alphaOption, textureAlpha, blendMethod, boundingBox); } }
public void addFont(BitmapFont font) { _dictionary[font.id] = font; }
public void drawCharacter(char c, BitmapFont font, ref IntVector2 position, Rotation rotation, Color32 color, bool mirror, AlphaOption alphaOption, byte textureAlpha, BlendMethod blendMethod, BoundingBox boundingBox = null) { if (Global.Debug3) Utils.Log("char {0}, x {1}, y {2}", c, position.x, position.y); ASP.BitmapChar charMap; IntVector2 cPos = new IntVector2(); if (font.characterMap.TryGetValue(c, out charMap) == false) { c = '?'; if (font.characterMap.TryGetValue(c, out charMap) == false) return; } Image charImage = new Image(charMap.image); charImage.recolor(Global.Black32, color, false, true); if (mirror) charImage.flipHorizontally(); switch (rotation) { case Rotation.R180: charImage.rotate180(); cPos.x = position.x - ((int)charMap.vx + (int)charMap.vw); cPos.y = position.y - (font.size + (int)charMap.vy); position.x -= (int) charMap.cw; break; case Rotation.R90: charImage.flipXY(true); cPos.x = position.x + (font.size + (int)charMap.vy + (int)charMap.vh); cPos.y = position.y - ((int)charMap.vx + (int)charMap.vw); position.y -= (int)charMap.cw; break; case Rotation.R270: charImage.flipXY(false); cPos.x = position.x - (font.size + (int)charMap.vy); cPos.y = position.y + (int)charMap.vx; position.y += (int)charMap.cw; break; case Rotation.R0: default: cPos.x = position.x + (int)charMap.vx; cPos.y = position.y + (font.size + (int)charMap.vy + (int)charMap.vh); position.x += (int)charMap.cw; break; } blendImage(charImage, blendMethod, cPos, alphaOption, textureAlpha, boundingBox); }