CharacterInfoForm.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Reflection;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. using Server.Account;
  12. using Server.Database;
  13. using Server.MirDatabase;
  14. using Server.MirEnvir;
  15. using Server.MirForms.Systems;
  16. using Server.MirObjects;
  17. using Server.Systems;
  18. using static System.Windows.Forms.VisualStyles.VisualStyleElement;
  19. namespace Server.Account
  20. {
  21. public partial class CharacterInfoForm : Form
  22. {
  23. public CharacterInfoForm()
  24. {
  25. InitializeComponent();
  26. LoadCharacters();
  27. }
  28. #region Load Characters
  29. private void LoadCharacters()
  30. {
  31. CharacterCountLabel.Text = string.Format("Characters count: {0}", SMain.Envir.CharacterList.Count);
  32. CharactersList.Items.Clear();
  33. var characterList = SMain.Envir.CharacterList;
  34. if (characterList == null)
  35. {
  36. MessageBox.Show("Character list is not available.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
  37. return;
  38. }
  39. foreach (var character in characterList)
  40. {
  41. string characterIndex = character.Index.ToString();
  42. string characterPlayer = character.Name;
  43. string accountName = character.AccountInfo.AccountID;
  44. string accountIP = character.AccountInfo.CreationIP;
  45. ListViewItem item = new ListViewItem(characterIndex);
  46. item.SubItems.Add(characterPlayer);
  47. item.SubItems.Add(accountName);
  48. item.SubItems.Add(accountIP);
  49. CharactersList.Items.Add(item);
  50. }
  51. }
  52. #endregion
  53. #region Filter
  54. private List<ListViewItem> originalItems = new List<ListViewItem>();
  55. private void RefreshButton_Click(object sender, EventArgs e)
  56. {
  57. RefreshInterface();
  58. }
  59. public void RefreshInterface()
  60. {
  61. if (InvokeRequired)
  62. {
  63. Invoke((Action)RefreshInterface);
  64. return;
  65. }
  66. // Update Character count label
  67. CharacterCountLabel.Text = string.Format("Characters count: {0}", SMain.Envir.CharacterList.Count);
  68. // Get filtered characters based on filter text and checkbox state
  69. List<CharacterInfo> filteredCharacters = SMain.Envir.CharacterList;
  70. if (FilterPlayerTextBox.Text.Length > 0)
  71. {
  72. filteredCharacters = SMain.Envir.MatchPlayer(FilterPlayerTextBox.Text, MatchFilterCheckBox.Checked);
  73. }
  74. if (FilterItemTextBox.Text.Length > 0)
  75. {
  76. filteredCharacters = SMain.Envir.MatchPlayerbyItem(FilterItemTextBox.Text, MatchFilterCheckBox.Checked);
  77. }
  78. // Clear existing items in CharactersList
  79. CharactersList.Items.Clear();
  80. // Populate CharactersList with filtered character information
  81. foreach (CharacterInfo character in filteredCharacters)
  82. {
  83. ListViewItem tempItem = CreateListViewItem(character);
  84. if (tempItem != null)
  85. {
  86. CharactersList.Items.Add(tempItem);
  87. }
  88. }
  89. }
  90. private ListViewItem CreateListViewItem(CharacterInfo character)
  91. {
  92. ListViewItem item = new ListViewItem(character.Index.ToString());
  93. item.SubItems.Add(character.Name);
  94. item.SubItems.Add(character.AccountInfo.AccountID);
  95. item.SubItems.Add(character.AccountInfo.CreationIP);
  96. item.Tag = character; // Store CharacterInfo object in Tag for reference
  97. return item;
  98. }
  99. #endregion
  100. }
  101. }