public sealed class Hp : ShipLabel\r
{\r
private bool _hpPercent;\r
- private Font _strongFont;\r
- private ShipLabel _hpStrongLabel;\r
- private Font StrongFont => _strongFont ?? (_strongFont = new Font("Leelawadee", BaseFont.Size));\r
\r
public Hp()\r
{\r
\r
public override void Reset()\r
{\r
- if (_hpStrongLabel != null)\r
- _hpStrongLabel.Text = "";\r
Text = "";\r
BackColor = InitialBackColor;\r
}\r
public override void Set(ShipStatus status)\r
{\r
Status = status;\r
- if (_hpStrongLabel != null)\r
- _hpStrongLabel.Text = "";\r
Font = BaseFont;\r
- if (_hpPercent)\r
- {\r
- var percent = $"{(int)Floor(status.NowHp * 100.0 / status.MaxHp):D}";\r
- if (status.DamageLevel == ShipStatus.Damage.Badly)\r
- {\r
- Text = "%";\r
- if (_hpStrongLabel == null)\r
- CreateHpStrongLabel();\r
- _hpStrongLabel.Text = percent;\r
- }\r
- else\r
- {\r
- Text = percent + "%";\r
- }\r
- }\r
- else\r
- {\r
- Text = $"{status.NowHp:D}/{status.MaxHp:D}";\r
- if (status.DamageLevel == ShipStatus.Damage.Badly)\r
- Font = StrongFont;\r
- }\r
+ Text = _hpPercent ? $"{(int)Floor(status.NowHp * 100.0 / status.MaxHp):D}%" : $"{status.NowHp:D}/{status.MaxHp:D}";\r
BackColor = DamageColor(status);\r
}\r
\r
- private void CreateHpStrongLabel()\r
- {\r
- _hpStrongLabel = new Hp(Scaler.Move(Left, Top, 4, 0), Height)\r
- {\r
- Font = StrongFont,\r
- BackColor = CUDColors.Red\r
- };\r
- _hpStrongLabel.DoubleClick += (sender, e) => { OnDoubleClick(e); };\r
- Parent.Controls.Add(_hpStrongLabel);\r
- var index = Parent.Controls.GetChildIndex(this);\r
- Parent.Controls.SetChildIndex(_hpStrongLabel, index + 1);\r
- }\r
-\r
public void ToggleHpPercent()\r
{\r
_hpPercent = !_hpPercent;\r