public void PlayUnit(CombatantInfo unitInfo) { if (this.InvokeRequired) { this.BeginInvoke(new Action <CombatantInfo>(PlayUnit), unitInfo); return; } this.combatRenderer.OnUnitTurn(unitInfo); var context = LocalizationManifest.Get.CurrentLanguage["FormMain"]; var formatter = new ThousandsFormatter(); var decimalFormat = new DecimalsFormatter(0, 0); Func <string, double, double, string> hpText = (label, x, max) => { var hpFormat = ThousandsFormatter.MaxMagnitudeFormat(x, max); return(context[label].Text() + ": " + hpFormat.Format(x) + " / " + hpFormat.Format(max)); }; shipCount.Text = context["ShipCount"].Text() + ": " + formatter.Format(unitInfo.Count); armorInfo.Text = hpText("ArmorLabel", unitInfo.ArmorHp, unitInfo.ArmorHpMax); shieldInfo.Text = hpText("ShieldLabel", unitInfo.ShieldHp, unitInfo.ShieldHpMax); if (unitInfo.MovementEta > 0) { movementInfo.Text = context["MovementEta"].Text( new Var("eta", unitInfo.MovementEta).Get, new TextVar("eta", unitInfo.MovementEta.ToString()).Get ); } else { movementInfo.Text = context["MovementPoints"].Text() + " (" + decimalFormat.Format(unitInfo.MovementPoints * 100) + " %)"; } this.abilityList.Controls.Clear(); Func <Image, string, object, Button> buttonMaker = (image, text, tag) => { var button = new Button { Image = image, ImageAlign = ContentAlignment.MiddleLeft, Margin = new Padding(3, 3, 3, 0), Size = new Size(80, 32), Text = text, TextImageRelation = TextImageRelation.ImageBeforeText, UseVisualStyleBackColor = true, Tag = tag }; button.Click += selectAbility_Click; return(button); }; this.abilityList.Controls.Add(buttonMaker( null, context["MoveAction"].Text(), null )); foreach (var ability in unitInfo.Abilities) { this.abilityList.Controls.Add(buttonMaker( ImageCache.Get.Resized(ability.ImagePath, new Size(24, 24)), "x " + formatter.Format(ability.Quantity), ability )); } }
private string hpText(string label, double x, double max) { var hpFormat = ThousandsFormatter.MaxMagnitudeFormat(x, max); return($"{textFor(label).Text()}: {hpFormat.Format(x)} / {hpFormat.Format(max)}"); }