UITable.java 4.8 KB

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