index.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. "use strict";
  2. const { shell } = require("electron");
  3. let config = {
  4. hieroPath: "",
  5. fontPath: "",
  6. exportName: "",
  7. exportDir: "",
  8. /** 导出文本来源 0:输入框 1:txt文件 */
  9. textFrom: 0,
  10. textStr: "",
  11. textPath: "",
  12. fontSize: 32,
  13. padding: 5,
  14. scale: 10,
  15. width: 1024,
  16. height: 1024
  17. };
  18. Editor.Panel.extend({
  19. style: `
  20. :host {
  21. display: flex;
  22. flex-direction: column;
  23. flex-wrap: nowrap;
  24. position: relative;
  25. box-sizing: border-box;
  26. contain: content;
  27. color: #bdbdbd;
  28. cursor: default;
  29. }
  30. .section {
  31. margin: 10px;
  32. padding: 0 10px;
  33. flex: 1;
  34. overflow-y: auto;
  35. }
  36. .footer {
  37. border-top: 1px solid #666;
  38. display: block;
  39. padding: 15px 0;
  40. margin: 0 20px;
  41. justify-content: flex-end;
  42. }
  43. .end-area {
  44. display: flex;
  45. align-items: center;
  46. justify-content: flex-end;
  47. }
  48. `,
  49. template: `
  50. <div class="section">
  51. <ui-prop name="Hiero路径" class="flex-1" tabindex="-1">
  52. <ui-input id="hieroPath" placeholder="Hiero path..." class="flex-2" tabindex="-1"></ui-input>
  53. <ui-button id="btnHiero" class="tiny" tabindex="-1">...</ui-button>
  54. <ui-button id="btnDownload" class="tiny" tabindex="-1">下载</ui-button>
  55. </ui-prop>
  56. <ui-prop name="源字体" class="flex-1" tabindex="-1">
  57. <ui-input id="fontPath" placeholder="font path..." class="flex-2" tabindex="-1"></ui-input>
  58. <ui-button id="btnFontPath" class="tiny" tabindex="-1">...</ui-button>
  59. </ui-prop>
  60. <ui-prop name="导出目录" class="flex-1" tabindex="-1">
  61. <ui-input id="exportDir" placeholder="export path..." class="flex-2" tabindex="-1"></ui-input>
  62. <ui-button id="btnExportDir" class="tiny" tabindex="-1">...</ui-button>
  63. </ui-prop>
  64. <ui-prop name="导出名称" class="flex-1" tabindex="-1">
  65. <ui-input id="exportName" placeholder="export font name..." class="flex-1" tabindex="-1"></ui-input>
  66. </ui-prop>
  67. <ui-prop name="导出文本" class="flex-1" tabindex="-1">
  68. <ui-select id="textSelect" value="0">
  69. <option value="0">输入框</option>
  70. <option value="1">文本文件</option>
  71. </ui-select>
  72. </ui-prop>
  73. <ui-prop id="textStr" name="输入框" type="string" value="" multiline auto-height class="flex-1" tabindex="1"></ui-prop>
  74. <ui-prop id="textPathElement" name="文本文件" class="flex-1" tabindex="1">
  75. <ui-input id="textPath" placeholder="txt path..." class="flex-2" tabindex="2"></ui-input>
  76. <ui-button id="btnTextPath" class="tiny" tabindex="-1">...</ui-button>
  77. </ui-prop>
  78. <ui-prop name="字体参数" class="flex-1" tabindex="-1">
  79. <ui-prop id="fontSize" name="Font Size" type="number" value="32" class="flex-1" tabindex="-1"></ui-prop>
  80. <ui-prop id="padding" name="Padding" type="number" value="5" class="flex-1" tabindex="-1"></ui-prop>
  81. </ui-prop>
  82. <ui-prop name="纹理参数" class="flex-1" tabindex="-1">
  83. <ui-prop id="width" name="Width" type="number" value="1024" class="flex-1" tabindex="-1"></ui-prop>
  84. <ui-prop id="height" name="Height" type="number" value="1024" class="flex-1" tabindex="-1"></ui-prop>
  85. </ui-prop>
  86. <ui-prop id="scale" name="SDF Scale" type="number" value="10" class="flex-1" tabindex="-1"></ui-prop>
  87. </div>
  88. <div class="footer">
  89. <div class="end-area">
  90. <ui-button id="btnSave" class="tiny green" tabindex="-1">Save</ui-button>
  91. <ui-button id="btnExport" class="tiny green" tabindex="-1">Export</ui-button>
  92. </div>
  93. </div class="footer">
  94. `,
  95. $: {
  96. hieroPath: "#hieroPath",
  97. btnHiero: "#btnHiero",
  98. btnDownload: "#btnDownload",
  99. fontPath: "#fontPath",
  100. btnFontPath: "#btnFontPath",
  101. exportName: "#exportName",
  102. exportDir: "#exportDir",
  103. btnExportDir: "#btnExportDir",
  104. textSelect: "#textSelect",
  105. textStr: "#textStr",
  106. textPathElement: "#textPathElement",
  107. textPath: "#textPath",
  108. btnTextPath: "#btnTextPath",
  109. fontSize: "#fontSize",
  110. padding: "#padding",
  111. scale: "#scale",
  112. width: "#width",
  113. height: "#height",
  114. btnSave: "#btnSave",
  115. btnExport: "#btnExport",
  116. },
  117. ready() {
  118. // 初始化
  119. Editor.Ipc.sendToMain("textmeshpro-tool:onPanelInit");
  120. // 事件监听
  121. this.$btnExportDir.addEventListener("confirm", () => {
  122. Editor.Ipc.sendToMain("textmeshpro-tool:onClickBtnExportDir");
  123. });
  124. this.$btnFontPath.addEventListener("confirm", () => {
  125. Editor.Ipc.sendToMain("textmeshpro-tool:onClickBtnFontPath");
  126. });
  127. this.$btnHiero.addEventListener("confirm", () => {
  128. Editor.Ipc.sendToMain("textmeshpro-tool:onClickBtnHiero");
  129. });
  130. this.$btnDownload.addEventListener("confirm", () => {
  131. shell.openExternal("https://libgdx.com/wiki/tools/hiero");
  132. });
  133. this.$exportName.addEventListener("confirm", () => {
  134. Editor.Ipc.sendToMain("textmeshpro-tool:onChangeConfig", "exportFileName", this.$exportName.value);
  135. });
  136. this.$textSelect.addEventListener("confirm", () => {
  137. this.$textStr.style.display = Number(this.$textSelect.value) === 0 ? "" : "none";
  138. this.$textPathElement.style.display = Number(this.$textSelect.value) === 1 ? "" : "none";
  139. Editor.Ipc.sendToMain("textmeshpro-tool:onChangeConfig", "textFrom", Number(this.$textSelect.value));
  140. });
  141. this.$textStr.addEventListener("confirm", () => {
  142. Editor.Ipc.sendToMain("textmeshpro-tool:onChangeConfig", "textStr", this.$textStr.value);
  143. });
  144. this.$btnTextPath.addEventListener("confirm", () => {
  145. Editor.Ipc.sendToMain("textmeshpro-tool:onClickBtnTextPath");
  146. });
  147. this.$fontSize.addEventListener("confirm", () => {
  148. Editor.Ipc.sendToMain("textmeshpro-tool:onChangeConfig", "fontSize", this.$fontSize.value);
  149. });
  150. this.$padding.addEventListener("confirm", () => {
  151. Editor.Ipc.sendToMain("textmeshpro-tool:onChangeConfig", "padding", this.$padding.value);
  152. });
  153. this.$scale.addEventListener("confirm", () => {
  154. Editor.Ipc.sendToMain("textmeshpro-tool:onChangeConfig", "scale", this.$scale.value);
  155. });
  156. this.$width.addEventListener("confirm", () => {
  157. Editor.Ipc.sendToMain("textmeshpro-tool:onChangeConfig", "width", this.$width.value);
  158. });
  159. this.$height.addEventListener("confirm", () => {
  160. Editor.Ipc.sendToMain("textmeshpro-tool:onChangeConfig", "height", this.$height.value);
  161. });
  162. let saveCall = () => {
  163. config.exportName = this.$exportName.value;
  164. config.exportDir = this.$exportDir.value;
  165. config.fontPath = this.$fontPath.value;
  166. config.hieroPath = this.$hieroPath.value;
  167. config.textFrom = Number(this.$textSelect.value);
  168. config.textStr = this.$textStr.value;
  169. config.textPath = this.$textPath.value;
  170. config.fontSize = this.$fontSize.value;
  171. config.padding = this.$padding.value;
  172. config.scale = this.$scale.value;
  173. config.width = this.$width.value;
  174. config.height = this.$height.value;
  175. Editor.Ipc.sendToMain("textmeshpro-tool:onClickBtnSave", config);
  176. };
  177. this.$btnSave.addEventListener("confirm", () => {
  178. saveCall();
  179. });
  180. this.$btnExport.addEventListener("confirm", () => {
  181. saveCall();
  182. Editor.Ipc.sendToMain("textmeshpro-tool:onClickBtnExport");
  183. });
  184. },
  185. listeners: {
  186. mousedown(event) {
  187. event.stopPropagation();
  188. },
  189. "panel-resize"(event) {
  190. event.stopPropagation();
  191. }
  192. },
  193. messages: {
  194. refreshConfig(event, arg) {
  195. config = arg;
  196. this.$exportName.value = config.exportName;
  197. this.$exportDir.value = config.exportDir;
  198. this.$fontPath.value = config.fontPath;
  199. this.$hieroPath.value = config.hieroPath;
  200. this.$textSelect.value = config.textFrom;
  201. this.$textStr.style.display = Number(this.$textSelect.value) === 0 ? "" : "none";
  202. this.$textPathElement.style.display = Number(this.$textSelect.value) === 1 ? "" : "none";
  203. this.$textStr.value = config.textStr;
  204. this.$textPath.value = config.textPath;
  205. this.$fontSize.value = config.fontSize;
  206. this.$padding.value = config.padding;
  207. this.$scale.value = config.scale;
  208. this.$width.value = config.width;
  209. this.$height.value = config.height;
  210. }
  211. }
  212. });