UITable.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package com.l2jserver.gameserver.datatables;
  16. import java.io.BufferedReader;
  17. import java.io.File;
  18. import java.io.FileNotFoundException;
  19. import java.io.FileReader;
  20. import java.io.LineNumberReader;
  21. import java.util.ArrayList;
  22. import java.util.HashMap;
  23. import java.util.List;
  24. import java.util.Map;
  25. import java.util.StringTokenizer;
  26. import java.util.logging.Level;
  27. import java.util.logging.Logger;
  28. import com.l2jserver.Config;
  29. import com.l2jserver.gameserver.model.entity.ActionKey;
  30. /**
  31. * @author mrTJO
  32. */
  33. public class UITable
  34. {
  35. private static final Logger _log = Logger.getLogger(UITable.class.getName());
  36. private Map<Integer, List<ActionKey>> _storedKeys = new HashMap<>();
  37. private Map<Integer, List<Integer>> _storedCategories = new HashMap<>();
  38. protected UITable()
  39. {
  40. parseCatData();
  41. parseKeyData();
  42. _log.info(getClass().getSimpleName() + ": Loaded " + _storedCategories.size() + " Categories.");
  43. _log.info(getClass().getSimpleName() + ": Loaded " + _storedKeys.size() + " Keys.");
  44. }
  45. private void parseCatData()
  46. {
  47. final File uiData = new File(Config.DATAPACK_ROOT, "data/uicats_en.csv");
  48. try (FileReader fr = new FileReader(uiData);
  49. BufferedReader br = new BufferedReader(fr);
  50. LineNumberReader lnr = new LineNumberReader(br))
  51. {
  52. String line = null;
  53. while ((line = lnr.readLine()) != null)
  54. {
  55. if (line.trim().length() == 0 || line.startsWith("#"))
  56. continue;
  57. StringTokenizer st = new StringTokenizer(line, ";");
  58. int cat = Integer.parseInt(st.nextToken());
  59. int cmd = Integer.parseInt(st.nextToken());
  60. insertCategory(cat, cmd);
  61. }
  62. }
  63. catch (FileNotFoundException e)
  64. {
  65. _log.warning(getClass().getSimpleName() + ": uicats_en.csv is missing in data folder");
  66. }
  67. catch (Exception e)
  68. {
  69. _log.log(Level.WARNING, getClass().getSimpleName() + ": Error while creating UI Default Categories table " + e.getMessage(), e);
  70. }
  71. }
  72. private void parseKeyData()
  73. {
  74. final File uiData = new File(Config.DATAPACK_ROOT, "data/uikeys_en.csv");
  75. try (FileReader fr = new FileReader(uiData);
  76. BufferedReader br = new BufferedReader(fr);
  77. LineNumberReader lnr = new LineNumberReader(br))
  78. {
  79. String line = null;
  80. while ((line = lnr.readLine()) != null)
  81. {
  82. if (line.trim().length() == 0 || line.startsWith("#"))
  83. continue;
  84. StringTokenizer st = new StringTokenizer(line, ";");
  85. int cat = Integer.parseInt(st.nextToken());
  86. int cmd = Integer.parseInt(st.nextToken());
  87. int key = Integer.parseInt(st.nextToken());
  88. int tk1 = Integer.parseInt(st.nextToken());
  89. int tk2 = Integer.parseInt(st.nextToken());
  90. int shw = Integer.parseInt(st.nextToken());
  91. insertKey(cat, cmd, key, tk1, tk2, shw);
  92. }
  93. }
  94. catch (FileNotFoundException e)
  95. {
  96. _log.warning(getClass().getSimpleName() + ": uikeys_en.csv is missing in data folder");
  97. }
  98. catch (Exception e)
  99. {
  100. _log.log(Level.WARNING, getClass().getSimpleName() + ": Error while creating UI Default Keys table " + e.getMessage(), e);
  101. }
  102. }
  103. private void insertCategory(int cat, int cmd)
  104. {
  105. if (_storedCategories.containsKey(cat))
  106. _storedCategories.get(cat).add(cmd);
  107. else
  108. {
  109. List<Integer> tmp = new ArrayList<>();
  110. tmp.add(cmd);
  111. _storedCategories.put(cat, tmp);
  112. }
  113. }
  114. private void insertKey(int cat, int cmdId, int key, int tgKey1, int tgKey2, int show)
  115. {
  116. ActionKey tmk = new ActionKey(cat, cmdId, key, tgKey1, tgKey2, show);
  117. if (_storedKeys.containsKey(cat))
  118. _storedKeys.get(cat).add(tmk);
  119. else
  120. {
  121. List<ActionKey> tmp = new ArrayList<>();
  122. tmp.add(tmk);
  123. _storedKeys.put(cat, tmp);
  124. }
  125. }
  126. public Map<Integer, List<Integer>> getCategories()
  127. {
  128. return _storedCategories;
  129. }
  130. public Map<Integer, List<ActionKey>> getKeys()
  131. {
  132. return _storedKeys;
  133. }
  134. public static UITable getInstance()
  135. {
  136. return SingletonHolder._instance;
  137. }
  138. private static class SingletonHolder
  139. {
  140. protected static final UITable _instance = new UITable();
  141. }
  142. }