SharedWeightExamineInfoSystem.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using Content.Shared.Examine;
  2. namespace Content.Shared._Stalker.Weight;
  3. public sealed class SharedWeightExamineInfoSystem : EntitySystem
  4. {
  5. public override void Initialize()
  6. {
  7. base.Initialize();
  8. SubscribeLocalEvent<STWeightComponent, ExaminedEvent>(OnWeightExamine);
  9. }
  10. private void OnWeightExamine(EntityUid uid, STWeightComponent component, ExaminedEvent args)
  11. {
  12. if (!args.IsInDetailsRange)
  13. return;
  14. var r = HexFromId(255);
  15. var g = HexFromId(255 - 255 / 30 * ((int)component.Total - 50));
  16. if (component.Total < 50f)
  17. {
  18. r = HexFromId(255 / 50 * (int)component.Total);
  19. g = HexFromId(255);
  20. }
  21. var colorString = $"#{r}{g}00";
  22. var str = $"Weighs [color={colorString}]{component.Total:0.00}[/color] kg";
  23. args.PushMarkup(str);
  24. }
  25. private string HexFromId(int id)
  26. {
  27. switch (id)
  28. {
  29. case < 0:
  30. return "00";
  31. case < 16:
  32. return "0" + id.ToString("X");
  33. case > 255:
  34. id = 255;
  35. return id.ToString("X");
  36. default:
  37. return id.ToString("X");
  38. }
  39. }
  40. }