SocketDialog.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using Client.MirControls;
  2. using Client.MirGraphics;
  3. using Client.MirSounds;
  4. namespace Client.MirScenes.Dialogs
  5. {
  6. public sealed class SocketDialog : MirImageControl
  7. {
  8. public MirItemCell[] Grid;
  9. public MirButton CloseButton;
  10. public SocketDialog()
  11. {
  12. Index = 20;
  13. Library = Libraries.Prguse3;
  14. Movable = true;
  15. Sort = true;
  16. Location = new Point(0, 0);
  17. Grid = new MirItemCell[6 * 2];
  18. for (int x = 0; x < 6; x++)
  19. {
  20. for (int y = 0; y < 2; y++)
  21. {
  22. int idx = 6 * y + x;
  23. Grid[idx] = new MirItemCell
  24. {
  25. ItemSlot = idx,
  26. GridType = MirGridType.Socket,
  27. Library = Libraries.Items,
  28. Parent = this,
  29. Location = new Point(x * 36 + 23 + x, y * 33 + 15 + y),
  30. };
  31. }
  32. }
  33. CloseButton = new MirButton
  34. {
  35. HoverIndex = 361,
  36. Index = 360,
  37. Location = new Point(Size.Width - 23, 3),
  38. Library = Libraries.Prguse2,
  39. Parent = this,
  40. PressedIndex = 362,
  41. Sound = SoundList.ButtonA,
  42. };
  43. CloseButton.Click += (o, e) => Hide();
  44. }
  45. private void BindGrid()
  46. {
  47. int count = 0;
  48. if (GameScene.SelectedItem != null)
  49. {
  50. count = GameScene.SelectedItem.Slots.Length;
  51. }
  52. for (int x = 0; x < 6; x++)
  53. {
  54. for (int y = 0; y < 2; y++)
  55. {
  56. int idx = 6 * y + x;
  57. Grid[idx].Visible = idx < count;
  58. }
  59. }
  60. }
  61. public MirItemCell GetCell(ulong id)
  62. {
  63. for (int i = 0; i < Grid.Length; i++)
  64. {
  65. if (Grid[i].Item == null || Grid[i].Item.UniqueID != id) continue;
  66. return Grid[i];
  67. }
  68. return null;
  69. }
  70. public override void Hide()
  71. {
  72. GameScene.SelectedItem = null;
  73. base.Hide();
  74. }
  75. public void Show(MirGridType grid, UserItem item)
  76. {
  77. if (item.Slots.Length == 0)
  78. {
  79. GameScene.SelectedItem = null;
  80. Visible = false;
  81. return;
  82. }
  83. GameScene.SelectedItem = item;
  84. Index = 20 + (GameScene.SelectedItem.Slots.Length - 1);
  85. BindGrid();
  86. CloseButton.Location = new Point(Size.Width - 23, 3);
  87. switch (grid)
  88. {
  89. case MirGridType.Inventory:
  90. Location = new Point(
  91. GameScene.Scene.InventoryDialog.Location.X + ((GameScene.Scene.InventoryDialog.Size.Width - Size.Width) / 2),
  92. GameScene.Scene.InventoryDialog.Location.Y + GameScene.Scene.InventoryDialog.Size.Height + 5);
  93. break;
  94. case MirGridType.Equipment:
  95. Location = new Point(
  96. GameScene.Scene.CharacterDialog.Location.X + ((GameScene.Scene.CharacterDialog.Size.Width - Size.Width) / 2),
  97. GameScene.Scene.CharacterDialog.Location.Y + GameScene.Scene.CharacterDialog.Size.Height + 5);
  98. break;
  99. }
  100. Visible = true;
  101. }
  102. }
  103. }