PaletteColorPicker.xaml.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using Content.Shared.Decals;
  2. using Robust.Client.AutoGenerated;
  3. using Robust.Client.Graphics;
  4. using Robust.Client.ResourceManagement;
  5. using Robust.Client.UserInterface.CustomControls;
  6. using Robust.Client.UserInterface.XAML;
  7. using Robust.Shared.Prototypes;
  8. namespace Content.Client.Decals.UI;
  9. [GenerateTypedNameReferences]
  10. public sealed partial class PaletteColorPicker : DefaultWindow
  11. {
  12. [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
  13. [Dependency] private readonly IResourceCache _resourceCache = default!;
  14. private readonly TextureResource _tex;
  15. public PaletteColorPicker()
  16. {
  17. RobustXamlLoader.Load(this);
  18. IoCManager.InjectDependencies(this);
  19. _tex = _resourceCache.GetResource<TextureResource>("/Textures/Interface/Nano/button.svg.96dpi.png");
  20. var i = 0;
  21. foreach (var palette in _prototypeManager.EnumeratePrototypes<ColorPalettePrototype>())
  22. {
  23. Palettes.AddItem(palette.Name);
  24. Palettes.SetItemMetadata(i, palette); // ew
  25. i += 1;
  26. }
  27. Palettes.OnItemSelected += args =>
  28. {
  29. Palettes.SelectId(args.Id);
  30. SetupList();
  31. };
  32. Palettes.Select(0);
  33. SetupList();
  34. }
  35. private void SetupList()
  36. {
  37. PaletteList.Clear();
  38. foreach (var (color, value) in (Palettes.SelectedMetadata as ColorPalettePrototype)!.Colors)
  39. {
  40. var item = PaletteList.AddItem(color, _tex.Texture);
  41. item.Metadata = value;
  42. item.IconModulate = value;
  43. }
  44. }
  45. }