ExUISetting.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * Copyright (C) 2004-2015 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J Server is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.l2jserver.gameserver.network.serverpackets;
  20. import java.util.List;
  21. import com.l2jserver.gameserver.model.ActionKey;
  22. import com.l2jserver.gameserver.model.UIKeysSettings;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. /**
  25. * @author mrTJO
  26. */
  27. public class ExUISetting extends L2GameServerPacket
  28. {
  29. private final UIKeysSettings _uiSettings;
  30. private int buffsize, categories;
  31. public ExUISetting(L2PcInstance player)
  32. {
  33. _uiSettings = player.getUISettings();
  34. calcSize();
  35. }
  36. private void calcSize()
  37. {
  38. int size = 16; // initial header and footer
  39. int category = 0;
  40. int numKeyCt = _uiSettings.getKeys().size();
  41. for (int i = 0; i < numKeyCt; i++)
  42. {
  43. size++;
  44. if (_uiSettings.getCategories().containsKey(category))
  45. {
  46. List<Integer> catElList1 = _uiSettings.getCategories().get(category);
  47. size = size + catElList1.size();
  48. }
  49. category++;
  50. size++;
  51. if (_uiSettings.getCategories().containsKey(category))
  52. {
  53. List<Integer> catElList2 = _uiSettings.getCategories().get(category);
  54. size = size + catElList2.size();
  55. }
  56. category++;
  57. size = size + 4;
  58. if (_uiSettings.getKeys().containsKey(i))
  59. {
  60. List<ActionKey> keyElList = _uiSettings.getKeys().get(i);
  61. size = size + (keyElList.size() * 20);
  62. }
  63. }
  64. buffsize = size;
  65. categories = category;
  66. }
  67. @Override
  68. protected void writeImpl()
  69. {
  70. writeC(0xFE);
  71. writeH(0x70);
  72. writeD(buffsize);
  73. writeD(categories);
  74. int category = 0;
  75. int numKeyCt = _uiSettings.getKeys().size();
  76. writeD(numKeyCt);
  77. for (int i = 0; i < numKeyCt; i++)
  78. {
  79. if (_uiSettings.getCategories().containsKey(category))
  80. {
  81. List<Integer> catElList1 = _uiSettings.getCategories().get(category);
  82. writeC(catElList1.size());
  83. for (int cmd : catElList1)
  84. {
  85. writeC(cmd);
  86. }
  87. }
  88. else
  89. {
  90. writeC(0x00);
  91. }
  92. category++;
  93. if (_uiSettings.getCategories().containsKey(category))
  94. {
  95. List<Integer> catElList2 = _uiSettings.getCategories().get(category);
  96. writeC(catElList2.size());
  97. for (int cmd : catElList2)
  98. {
  99. writeC(cmd);
  100. }
  101. }
  102. else
  103. {
  104. writeC(0x00);
  105. }
  106. category++;
  107. if (_uiSettings.getKeys().containsKey(i))
  108. {
  109. List<ActionKey> keyElList = _uiSettings.getKeys().get(i);
  110. writeD(keyElList.size());
  111. for (ActionKey akey : keyElList)
  112. {
  113. writeD(akey.getCommandId());
  114. writeD(akey.getKeyId());
  115. writeD(akey.getToogleKey1());
  116. writeD(akey.getToogleKey2());
  117. writeD(akey.getShowStatus());
  118. }
  119. }
  120. else
  121. {
  122. writeD(0x00);
  123. }
  124. }
  125. writeD(0x11);
  126. writeD(0x10);
  127. }
  128. }