private void DrawText(FontLocation[] font, Texture fontTexture, Vector2 startPos, float spacing, float scaling, bool centred, string text) { char[] charArray = text.ToCharArray(); int length = charArray.Length; FontLocation[] cache = null; if (centred) { cache = new FontLocation[length]; float textLength = 0; for (int i = 0; i < length; i++) { cache[i] = FontLookup.FindLetterLocation(font, charArray[i]); textLength += cache[i].width; } startPos.X -= (textLength + spacing * (length - 1)) * speedoScale * scaling / 2f; } for (int i = 0; i < length; i++) { FontLocation letterLocation; if (cache != null) { letterLocation = cache[i]; } else { letterLocation = FontLookup.FindLetterLocation(font, charArray[i]); } dial.Transform = Matrix.Transformation2D(Vector2.Zero, 0f, new Vector2(speedoScale, speedoScale) * scaling, Vector2.Zero, 0f, startPos); Rectangle?rectangle = new Rectangle(letterLocation.x, letterLocation.y, letterLocation.width, letterLocation.height); dial.Draw(fontTexture, baseColour, rectangle, new Vector3?(), new Vector3?()); startPos.X += (letterLocation.width + spacing) * speedoScale * scaling; } }
public void Load() { try { Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; // Consistent parsing of numbers in XML themeConfig = ThemeLookup.ReadXML(baseDirectory + "\\Themes\\" + theme + "\\Design.xml"); } catch { speedoInterface.Message(MessageType.Error, "Failed to load asset: Design.xml"); return; } dial = new Sprite(device); if (themeConfig.Dial.Show) { try { carTexture = Texture.FromFile(device, baseDirectory + "\\Themes\\" + theme + "\\Dial_Car.png"); boatTexture = Texture.FromFile(device, baseDirectory + "\\Themes\\" + theme + "\\Dial_Boat.png"); planeTexture = Texture.FromFile(device, baseDirectory + "\\Themes\\" + theme + "\\Dial_Plane.png"); if (themeConfig.Dial.ShowBackground) { try { backgroundTexture = Texture.FromFile(device, baseDirectory + "\\Themes\\" + theme + "\\Dial_Background.png"); } catch { speedoInterface.Message(MessageType.Warning, "Failed to load asset: Dial_Background.png"); themeConfig.Dial.ShowBackground = false; } } if (themeConfig.Dial.ShowGlow) { try { glowTexture = Texture.FromFile(device, baseDirectory + "\\Themes\\" + theme + "\\Glow.png"); } catch { speedoInterface.Message(MessageType.Warning, "Failed to load asset: Glow.png"); themeConfig.Dial.ShowGlow = false; } } } catch { speedoInterface.Message(MessageType.Warning, "Failed to load assets: Dial_Car.png, Dial_Boat.png, Dial_Plane.png"); themeConfig.Dial.Show = false; } } if (themeConfig.Needle.Show) { try { needleTexture = Texture.FromFile(device, baseDirectory + "\\Themes\\" + theme + "\\Needle.png"); } catch { speedoInterface.Message(MessageType.Warning, "Failed to load asset: Needle.png"); themeConfig.Needle.Show = false; } } if (themeConfig.Speed.Show) { try { speedFontLookup = FontLookup.ReadXML(baseDirectory + "\\Themes\\" + theme + "\\" + themeConfig.Speed.FontName + ".xml"); speedFontTexture = Texture.FromFile(device, baseDirectory + "\\Themes\\" + theme + "\\" + themeConfig.Speed.FontName + ".png"); } catch { speedoInterface.Message(MessageType.Warning, "Failed to load assets: {0}.png, {0}.xml", themeConfig.Speed.FontName); themeConfig.Speed.Show = false; } } if (themeConfig.BoostLevel.Show) { try { boostLevelFontLookup = FontLookup.ReadXML(baseDirectory + "\\Themes\\" + theme + "\\" + themeConfig.BoostLevel.FontName + ".xml"); boostLevelFontTexture = Texture.FromFile(device, baseDirectory + "\\Themes\\" + theme + "\\" + themeConfig.BoostLevel.FontName + ".png"); } catch { speedoInterface.Message(MessageType.Warning, "Failed to load assets: {0}.png, {0}.xml", themeConfig.BoostLevel.FontName); themeConfig.BoostLevel.Show = false; } } if (themeConfig.VehicleForm.Show) { try { vehicleFormFontLookup = FontLookup.ReadXML(baseDirectory + "\\Themes\\" + theme + "\\" + themeConfig.VehicleForm.FontName + ".xml"); vehicleFormFontTexture = Texture.FromFile(device, baseDirectory + "\\Themes\\" + theme + "\\" + themeConfig.VehicleForm.FontName + ".png"); } catch { speedoInterface.Message(MessageType.Warning, "Failed to load assets: {0}.png, {0}.xml", themeConfig.BoostLevel.FontName); themeConfig.VehicleForm.Show = false; } } if (themeConfig.StuntLight.Show) { try { lightTexture = Texture.FromFile(device, baseDirectory + "\\Themes\\" + theme + "\\Light.png"); } catch { speedoInterface.Message(MessageType.Warning, "Failed to load asset: Light.png"); themeConfig.StuntLight.Show = false; } } loaded = true; }