UITable.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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.List;
  22. import java.util.Map;
  23. import java.util.StringTokenizer;
  24. import java.util.logging.Logger;
  25. import javolution.util.FastList;
  26. import javolution.util.FastMap;
  27. import com.l2jserver.Config;
  28. import com.l2jserver.gameserver.model.entity.ActionKey;
  29. /**
  30. *
  31. * @author mrTJO
  32. */
  33. public class UITable
  34. {
  35. private static Logger _log = Logger.getLogger(UITable.class.getName());
  36. private Map<Integer, List<ActionKey>> _storedKeys;
  37. private Map<Integer, List<Integer>> _storedCategories;
  38. public static UITable getInstance()
  39. {
  40. return SingletonHolder._instance;
  41. }
  42. private UITable()
  43. {
  44. _storedKeys = new FastMap<Integer, List<ActionKey>>();
  45. _storedCategories = new FastMap<Integer, List<Integer>>();
  46. parseCatData();
  47. parseKeyData();
  48. _log.config("UITable: Loaded " + _storedCategories.size() + " Categories.");
  49. _log.config("UITable: Loaded " + _storedKeys.size() + " Keys.");
  50. }
  51. private void parseCatData()
  52. {
  53. LineNumberReader lnr = null;
  54. try
  55. {
  56. File uiData = new File(Config.DATAPACK_ROOT, "data/uicats_en.csv");
  57. lnr = new LineNumberReader(new BufferedReader(new FileReader(uiData)));
  58. String line = null;
  59. while ((line = lnr.readLine()) != null)
  60. {
  61. if (line.trim().length() == 0 || line.startsWith("#"))
  62. continue;
  63. StringTokenizer st = new StringTokenizer(line, ";");
  64. int cat = Integer.parseInt(st.nextToken());
  65. int cmd = Integer.parseInt(st.nextToken());
  66. insertCategory(cat, cmd);
  67. }
  68. }
  69. catch (FileNotFoundException e)
  70. {
  71. _log.warning("uicats_en.csv is missing in data folder");
  72. }
  73. catch (Exception e)
  74. {
  75. _log.warning("error while creating UI Default Categories table " + e);
  76. }
  77. finally
  78. {
  79. try
  80. {
  81. lnr.close();
  82. }
  83. catch (Exception e)
  84. {
  85. }
  86. }
  87. }
  88. private void parseKeyData()
  89. {
  90. LineNumberReader lnr = null;
  91. try
  92. {
  93. File uiData = new File(Config.DATAPACK_ROOT, "data/uikeys_en.csv");
  94. lnr = new LineNumberReader(new BufferedReader(new FileReader(uiData)));
  95. String line = null;
  96. while ((line = lnr.readLine()) != null)
  97. {
  98. if (line.trim().length() == 0 || line.startsWith("#"))
  99. continue;
  100. StringTokenizer st = new StringTokenizer(line, ";");
  101. int cat = Integer.parseInt(st.nextToken());
  102. int cmd = Integer.parseInt(st.nextToken());
  103. int key = Integer.parseInt(st.nextToken());
  104. int tk1 = Integer.parseInt(st.nextToken());
  105. int tk2 = Integer.parseInt(st.nextToken());
  106. int shw = Integer.parseInt(st.nextToken());
  107. insertKey(cat, cmd, key, tk1, tk2, shw);
  108. }
  109. }
  110. catch (FileNotFoundException e)
  111. {
  112. _log.warning("uikeys_en.csv is missing in data folder");
  113. }
  114. catch (Exception e)
  115. {
  116. _log.warning("error while creating UI Default Keys table " + e);
  117. }
  118. finally
  119. {
  120. try
  121. {
  122. lnr.close();
  123. }
  124. catch (Exception e)
  125. {
  126. }
  127. }
  128. }
  129. private void insertCategory(int cat, int cmd)
  130. {
  131. if (_storedCategories.containsKey(cat))
  132. _storedCategories.get(cat).add(cmd);
  133. else
  134. {
  135. List<Integer> tmp = new FastList<Integer>();
  136. tmp.add(cmd);
  137. _storedCategories.put(cat, tmp);
  138. }
  139. }
  140. private void insertKey(int cat, int cmdId, int key, int tgKey1, int tgKey2, int show)
  141. {
  142. ActionKey tmk = new ActionKey(cat, cmdId, key, tgKey1, tgKey2, show);
  143. if (_storedKeys.containsKey(cat))
  144. _storedKeys.get(cat).add(tmk);
  145. else
  146. {
  147. List<ActionKey> tmp = new FastList<ActionKey>();
  148. tmp.add(tmk);
  149. _storedKeys.put(cat, tmp);
  150. }
  151. }
  152. public Map<Integer, List<Integer>> getCategories()
  153. {
  154. return _storedCategories;
  155. }
  156. public Map<Integer, List<ActionKey>> getKeys()
  157. {
  158. return _storedKeys;
  159. }
  160. @SuppressWarnings("synthetic-access")
  161. private static class SingletonHolder
  162. {
  163. protected static final UITable _instance = new UITable();
  164. }
  165. }