PageRenderTime 48ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/cwxeditor_src/cwx/editor/gui/dwt/smalldialogs.d

https://bitbucket.org/k4nagatsuki/cwxeditor
D | 988 lines | 904 code | 77 blank | 7 comment | 88 complexity | 9b26866a6da040f20608b022edaaca5c MD5 | raw file
Possible License(s): LGPL-2.1
  1. module cwx.editor.gui.dwt.smalldialogs;
  2. import cwx.utils;
  3. import cwx.versioninfo;
  4. import cwx.structs;
  5. import cwx.menu;
  6. import cwx.summary;
  7. import cwx.archive;
  8. import cwx.cab;
  9. import cwx.types;
  10. import cwx.script;
  11. import cwx.event;
  12. import cwx.importutils;
  13. import cwx.flag;
  14. import cwx.editor.gui.dwt.dprops;
  15. import cwx.editor.gui.dwt.absdialog;
  16. import cwx.editor.gui.dwt.centerlayout;
  17. import cwx.editor.gui.dwt.dskin;
  18. import cwx.editor.gui.dwt.dutils;
  19. import cwx.editor.gui.dwt.commons;
  20. import cwx.editor.gui.dwt.dmenu;
  21. import cwx.editor.gui.dwt.customtable;
  22. import cwx.editor.gui.dwt.scripterrordialog;
  23. import cwx.editor.gui.dwt.settingsdialog;
  24. import std.string;
  25. import std.conv;
  26. import std.path;
  27. import std.file;
  28. import std.functional;
  29. import std.array;
  30. import std.traits;
  31. import std.typecons;
  32. import org.eclipse.swt.all;
  33. class CreateScenarioDialog : AbsDialog {
  34. private:
  35. Commons _comm;
  36. Props _prop;
  37. Text _name;
  38. Combo _skinC;
  39. Combo _templateC;
  40. string _nameVal, _skinVal;
  41. Button _baseSkin;
  42. Button _baseTemplate;
  43. ScTemplate[int] _tTbl;
  44. bool[string] _isClassic;
  45. bool _useTemplate;
  46. Summary _fromTemplate = null;
  47. Text _dir;
  48. Button _dirRef;
  49. Button _dirOpen;
  50. Button _createScDir;
  51. string _dirVal;
  52. bool _classic = false;
  53. void enabledClassicDir() { mixin(S_TRACE);
  54. _dir.setEnabled(legacy);
  55. _dirRef.setEnabled(legacy);
  56. _createScDir.setEnabled(legacy);
  57. }
  58. void refSkinVal() { mixin(S_TRACE);
  59. if (_skinC.getSelectionIndex() == _skinC.getItemCount() - 1) { mixin(S_TRACE);
  60. _skinVal = "";
  61. } else { mixin(S_TRACE);
  62. _skinVal = _skinC.getText();
  63. }
  64. }
  65. void refClassic() { mixin(S_TRACE);
  66. refSkinVal();
  67. scope (exit) enabledClassicDir();
  68. if (_baseTemplate.getSelection()) { mixin(S_TRACE);
  69. string tPath = _tTbl[_templateC.getSelectionIndex()].path;
  70. if (!.exists(tPath)) { mixin(S_TRACE);
  71. _classic = false;
  72. } else { mixin(S_TRACE);
  73. auto p = tPath in _isClassic;
  74. if (p) { mixin(S_TRACE);
  75. _classic = *p;
  76. } else { mixin(S_TRACE);
  77. bool r;
  78. if (.isDir(tPath)) { mixin(S_TRACE);
  79. r = tPath.buildPath("Summary.wsm").exists();
  80. } else if (.fnstartsWith(tPath.baseName(), "Summary")) { mixin(S_TRACE);
  81. r = tPath.baseName().cfnmatch("Summary.wsm");
  82. } else { mixin(S_TRACE);
  83. if (.extension(tPath).cfnmatch(".cab") && canUncab) { mixin(S_TRACE);
  84. r = cabHasFile(tPath, "Summary.wsm");
  85. } else { mixin(S_TRACE);
  86. r = zipHasFile(tPath, "Summary.wsm");
  87. }
  88. }
  89. _isClassic[tPath] = r;
  90. _classic = r;
  91. }
  92. }
  93. } else { mixin(S_TRACE);
  94. _classic = skin.length == 0;
  95. }
  96. }
  97. public:
  98. this (Commons comm, Props prop, Shell shell, bool currentWin) { mixin(S_TRACE);
  99. _comm = comm;
  100. _prop = prop;
  101. _useTemplate = currentWin;
  102. string title = currentWin ? _prop.msgs.dlgTitNewScenario : _prop.msgs.dlgTitNewScenarioAtNewWin;
  103. auto img = currentWin ? _prop.images.menu(MenuID.New) : _prop.images.menu(MenuID.NewAtNewWindow);
  104. super(_prop, shell, title, img, true, _prop.var.newScDlg);
  105. enterClose = true;
  106. }
  107. @property
  108. string name() { mixin(S_TRACE);
  109. return _nameVal;
  110. }
  111. @property
  112. string skin() { mixin(S_TRACE);
  113. return _skinVal;
  114. }
  115. @property
  116. Summary fromTemplate() { mixin(S_TRACE);
  117. return _fromTemplate;
  118. }
  119. @property
  120. bool legacy() { mixin(S_TRACE);
  121. return _classic;
  122. }
  123. @property
  124. string classicDir() { mixin(S_TRACE);
  125. auto dir = nabs(_prop.toAppAbs(_dirVal));
  126. if (_prop.var.etc.createScenarioDir) { mixin(S_TRACE);
  127. dir = dir.buildPath(toFileName(name)).createNewFileName(true);
  128. }
  129. return dir;
  130. }
  131. static string createClassicDir(Props prop, Shell parent) { mixin(S_TRACE);
  132. auto dlg = new DirectoryDialog(parent);
  133. dlg.setText(prop.msgs.newClassicDir);
  134. dlg.setMessage(prop.msgs.newClassicDirDesc);
  135. dlg.setFilterPath(prop.var.etc.scenarioPath);
  136. while (true) { mixin(S_TRACE);
  137. auto path = dlg.open();
  138. if (path) { mixin(S_TRACE);
  139. if (clistdir(path).length) { mixin(S_TRACE);
  140. auto q = new MessageBox(parent, SWT.OK | SWT.CANCEL | SWT.ICON_QUESTION);
  141. q.setText(prop.msgs.dlgTitQuestion);
  142. q.setMessage(.tryFormat(prop.msgs.notEmptyDir, path));
  143. if (SWT.OK != q.open()) continue;
  144. }
  145. prop.var.etc.scenarioPath = dlg.getFilterPath();
  146. return path;
  147. }
  148. break;
  149. }
  150. return null;
  151. }
  152. protected:
  153. override void setup(Composite area) { mixin(S_TRACE);
  154. auto cl = new CenterLayout(SWT.HORIZONTAL | SWT.VERTICAL, 0);
  155. cl.fillHorizontal = true;
  156. area.setLayout(cl);
  157. auto comp = new Composite(area, SWT.NONE);
  158. comp.setLayout(new GridLayout(1, true));
  159. { mixin(S_TRACE);
  160. auto grp = new Group(comp, SWT.NONE);
  161. grp.setText(_prop.msgs.scenarioName);
  162. grp.setLayoutData(new GridData(GridData.FILL_BOTH));
  163. grp.setLayout(new GridLayout(1, true));
  164. _name = new Text(grp, SWT.BORDER);
  165. createTextMenu!Text(_comm, _prop, _name, &catchMod);
  166. auto gd = new GridData(GridData.FILL_HORIZONTAL);
  167. gd.widthHint = _prop.var.etc.nameWidth;
  168. _name.setLayoutData(gd);
  169. }
  170. { mixin(S_TRACE);
  171. auto grp = new Group(comp, SWT.NONE);
  172. grp.setText(_prop.msgs.initialize);
  173. grp.setLayoutData(new GridData(GridData.FILL_BOTH));
  174. grp.setLayout(new GridLayout(2, false));
  175. void refRadio() { mixin(S_TRACE);
  176. _skinC.setEnabled(_baseSkin.getSelection());
  177. _templateC.setEnabled(_baseTemplate.getSelection());
  178. enabledClassicDir();
  179. }
  180. _baseSkin = new Button(grp, SWT.RADIO);
  181. _baseSkin.setText(_prop.msgs.type);
  182. listener(_baseSkin, SWT.Selection, &refRadio);
  183. _skinC = new Combo(grp, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY);
  184. _skinC.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
  185. string[] skins;
  186. foreach (key, value; skinTable(_prop)) { mixin(S_TRACE);
  187. skins ~= key;
  188. }
  189. // FIXME: ????????
  190. // auto skins = skinTable(_prop).keys;
  191. if (_prop.var.etc.logicalSort) { mixin(S_TRACE);
  192. skins = sort!(ncmp)(skins);
  193. } else { mixin(S_TRACE);
  194. skins = sort!(cmp)(skins);
  195. }
  196. foreach (type; skins) { mixin(S_TRACE);
  197. _skinC.add(type);
  198. }
  199. if (!_skinC.getItemCount()) { mixin(S_TRACE);
  200. // ??????
  201. _skinC.add(_prop.var.etc.defaultSkin);
  202. }
  203. _skinC.add(_prop.msgs.classic);
  204. _skinC.setText(_prop.var.etc.defaultSkin);
  205. _skinVal = _prop.var.etc.defaultSkin;
  206. if (_skinC.getSelectionIndex() == -1) _skinC.select(0);
  207. _baseTemplate = new Button(grp, SWT.RADIO);
  208. _baseTemplate.setText(_prop.msgs.scenarioTemplate);
  209. listener(_baseTemplate, SWT.Selection, &refRadio);
  210. _templateC = new Combo(grp, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY);
  211. _templateC.setVisibleItemCount(_prop.var.etc.comboVisibleItemCount);
  212. auto tgd = new GridData(GridData.FILL_HORIZONTAL);
  213. tgd.widthHint = 0;
  214. _templateC.setLayoutData(tgd);
  215. foreach (i, sct; _prop.var.etc.scenarioTemplates) { mixin(S_TRACE);
  216. _templateC.add(.tryFormat(_prop.msgs.templateDesc, sct.name, sct.path));
  217. if (cfnmatch(sct.path, _prop.var.etc.defaultScenarioTemplate)) { mixin(S_TRACE);
  218. _templateC.select(i);
  219. }
  220. _tTbl[i] = sct;
  221. }
  222. bool tenbl = _templateC.getItemCount() > 0 && _useTemplate;
  223. if (!tenbl) _templateC.add(_prop.msgs.noTemplate);
  224. if (_templateC.getSelectionIndex() == -1) _templateC.select(0);
  225. _baseTemplate.setEnabled(tenbl);
  226. _baseSkin.setSelection(!tenbl || !_prop.var.etc.defaultIsTemplate);
  227. _baseTemplate.setSelection(!_baseSkin.getSelection());
  228. _skinC.setEnabled(_baseSkin.getSelection());
  229. _templateC.setEnabled(_baseTemplate.getSelection());
  230. .listener(_skinC, SWT.Selection, &refClassic);
  231. .listener(_baseTemplate, SWT.Selection, &refClassic);
  232. .listener(_templateC, SWT.Selection, &refClassic);
  233. }
  234. { mixin(S_TRACE);
  235. auto grp = new Group(comp, SWT.NONE);
  236. grp.setText(_prop.msgs.createClassicDir);
  237. grp.setLayoutData(new GridData(GridData.FILL_BOTH));
  238. grp.setLayout(new GridLayout(3, false));
  239. _dir = new Text(grp, SWT.BORDER);
  240. .listener(_dir, SWT.Modify, { mixin(S_TRACE);
  241. _dirVal = _dir.getText();
  242. });
  243. createTextMenu!Text(_comm, _prop, _dir, &catchMod);
  244. _dir.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
  245. _dirRef = new Button(grp, SWT.PUSH);
  246. _dirRef.setText(_prop.msgs.reference);
  247. .listener(_dirRef, SWT.Selection, { mixin(S_TRACE);
  248. selectDir(_prop, _dir, _prop.msgs.newClassicDir, _prop.msgs.newClassicDirDesc, _dir.getText());
  249. });
  250. _dirOpen = createOpenButton(_comm, grp, {return _prop.toAppAbs(_dir.getText());}, true);
  251. _createScDir = new Button(grp, SWT.CHECK);
  252. _createScDir.setText(_prop.msgs.createScenarioNameDir);
  253. auto gd = new GridData;
  254. gd.horizontalSpan = 3;
  255. _createScDir.setLayoutData(gd);
  256. .listener(_createScDir, SWT.Selection, { mixin(S_TRACE);
  257. _prop.var.etc.createScenarioDir = _createScDir.getSelection();
  258. });
  259. setupDropFile(grp, _dir, toDelegate(&dropDir));
  260. }
  261. _dir.setText(_prop.var.etc.scenarioPath);
  262. _createScDir.setSelection(_prop.var.etc.createScenarioDir);
  263. refClassic();
  264. }
  265. override bool close(bool ok, out bool cancel) { mixin(S_TRACE);
  266. if (ok) { mixin(S_TRACE);
  267. _nameVal = _name.getText();
  268. if (!_nameVal.length) _nameVal = _prop.msgs.newScenarioName;
  269. auto dir = classicDir;
  270. if (legacy) { mixin(S_TRACE);
  271. if (dir.exists() && clistdir(dir).length) { mixin(S_TRACE);
  272. auto q = new MessageBox(getShell(), SWT.OK | SWT.CANCEL | SWT.ICON_QUESTION);
  273. q.setText(_prop.msgs.dlgTitQuestion);
  274. q.setMessage(.tryFormat(_prop.msgs.notEmptyDir, dir));
  275. if (SWT.OK != q.open()) { mixin(S_TRACE);
  276. cancel = true;
  277. return false;
  278. }
  279. }
  280. }
  281. if (_baseTemplate.getSelection()) { mixin(S_TRACE);
  282. Summary summ = null;
  283. string tPath = _tTbl[_templateC.getSelectionIndex()].path;
  284. if (!.exists(tPath)) { mixin(S_TRACE);
  285. if (!dir.exists()) mkdirRecurse(dir);
  286. summ = new Summary(_nameVal, skin, dir, false, true);
  287. } else if (.isDir(tPath) && !tPath.buildPath("Summary.wsm").exists() && !tPath.buildPath("Summary.xml").exists()) { mixin(S_TRACE);
  288. auto cursors = setWaitCursors(topShell(getShell()));
  289. scope (exit) {
  290. resetCursors(cursors);
  291. }
  292. // ???????????????????
  293. summ = Summary.createScenario(_prop.sys, _prop.tempPath, name, findSkin2(_prop, skin));
  294. tPath.copyAll(summ.scenarioPath);
  295. } else { mixin(S_TRACE);
  296. auto cursors = setWaitCursors(topShell(getShell()));
  297. scope (exit) {
  298. resetCursors(cursors);
  299. }
  300. try { mixin(S_TRACE);
  301. LoadOption opt;
  302. opt.cardOnly = false;
  303. opt.textOnly = false;
  304. opt.doubleIO = _prop.var.etc.doubleIO;
  305. opt.expandXMLs = _prop.var.etc.expandXMLs;
  306. summ = Summary.loadScenarioFromFile(_prop.parent, opt, tPath, _prop.tempPath, () => dir);
  307. } catch (SummaryException e) {
  308. // Nothing;
  309. debugln(e);
  310. }
  311. }
  312. if (ok) { mixin(S_TRACE);
  313. if (!summ) { mixin(S_TRACE);
  314. summ = Summary.createScenario(_prop.sys, _prop.tempPath, name, findSkin2(_prop, skin));
  315. }
  316. summ.setBaseParams(name, _prop.var.etc.defaultAuthor);
  317. _prop.var.etc.defaultScenarioTemplate = tPath;
  318. _prop.var.etc.defaultIsTemplate = true;
  319. _fromTemplate = summ;
  320. }
  321. } else if (ok) { mixin(S_TRACE);
  322. _prop.var.etc.defaultIsTemplate = false;
  323. }
  324. }
  325. return ok;
  326. }
  327. }
  328. class VersionDialog : AbsDialog {
  329. private:
  330. Commons _comm;
  331. Props _prop;
  332. class OpenLink : SelectionAdapter {
  333. override void widgetSelected(SelectionEvent e) { mixin(S_TRACE);
  334. auto prog = Program.findProgram("html");
  335. if (prog) prog.execute(e.text);
  336. }
  337. }
  338. public:
  339. this(Commons comm, Props prop, Shell shell) { mixin(S_TRACE);
  340. super(prop, shell, true, prop.msgs.dlgTitVersion, prop.images.menu(MenuID.VersionInfo), false, null, false, false);
  341. _comm = comm;
  342. _prop = prop;
  343. enterClose = true;
  344. firstFocusIsOK = true;
  345. }
  346. protected:
  347. override void setup(Composite area) { mixin(S_TRACE);
  348. auto gl = new GridLayout(2, false);
  349. gl.marginWidth = 10;
  350. gl.horizontalSpacing = 15;
  351. area.setLayout(gl);
  352. auto d = Display.getCurrent();
  353. auto img = new Label(area, SWT.CENTER);
  354. img.setImage(_prop.images.largeIcon);
  355. auto gd = new GridData;
  356. auto rect = _prop.images.largeIcon.getBounds();
  357. gd.widthHint = rect.width;
  358. gd.heightHint = rect.height;
  359. gd.verticalSpan = 2;
  360. img.setLayoutData(gd);
  361. { mixin(S_TRACE);
  362. auto comp = new Composite(area, SWT.NONE);
  363. comp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
  364. comp.setLayout(zeroGridLayout(1, true));
  365. auto l1 = new Label(comp, SWT.NONE);
  366. l1.setText(_prop.msgs.application ~ " / " ~ APP_VERSION);
  367. auto ln = new Link(comp, SWT.NONE);
  368. ln.setText("<a>" ~ APP_WEB_SITE_URI ~ "</a>");
  369. ln.addSelectionListener(new OpenLink);
  370. auto l2 = new Label(comp, SWT.NONE);
  371. l2.setText(_prop.msgs.appDesc);
  372. }
  373. auto build = new Text(area, SWT.READ_ONLY | SWT.BORDER | SWT.MULTI);
  374. createTextMenu!Text(_comm, _prop, build, null);
  375. build.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
  376. build.setText(APP_BUILD);
  377. }
  378. }
  379. class ErrorDialog : AbsDialog {
  380. private Commons _comm;
  381. private Props _prop;
  382. private string _desc;
  383. this (Commons comm, Props prop, Shell shell, string desc) { mixin(S_TRACE);
  384. auto size = new class DSize {
  385. void width(int v) {}
  386. void height(int v) {}
  387. int width() {return 600;}
  388. int height() {return 400;}
  389. };
  390. auto info = ButtonInfo(prop.msgs.shutdown, {std.c.stdlib.exit(0);});
  391. super (prop, shell, false, prop.msgs.dlgTitError, shell.getImage(), true, size, false, false, [info]);
  392. _comm = comm;
  393. _prop = prop;
  394. _desc = desc;
  395. }
  396. override void setup(Composite area) { mixin(S_TRACE);
  397. auto d = area.getDisplay();
  398. auto gl = new GridLayout(2, false);
  399. gl.horizontalSpacing = 0;
  400. area.setLayout(gl);
  401. { mixin(S_TRACE);
  402. auto comp = new Composite(area, SWT.NONE);
  403. auto cgl = new GridLayout(1, true);
  404. cgl.marginWidth = 10;
  405. cgl.marginHeight = 10;
  406. comp.setLayout(cgl);
  407. auto img = new Label(comp, SWT.NONE);
  408. img.setImage(d.getSystemImage(SWT.ICON_ERROR));
  409. }
  410. auto l = new Link(area, SWT.WRAP);
  411. l.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
  412. l.setText(.tryFormat(_prop.msgs.unknownError, "<a>" ~ nabs(cwx.utils.debugLog) ~ "</a>"));
  413. .listener(l, SWT.Selection, (Event e) { mixin(S_TRACE);
  414. auto prog = Program.findProgram("log");
  415. if (prog) { mixin(S_TRACE);
  416. prog.execute(e.text);
  417. } else { mixin(S_TRACE);
  418. prog = Program.findProgram("txt");
  419. if (prog) { mixin(S_TRACE);
  420. prog.execute(e.text);
  421. } else { mixin(S_TRACE);
  422. openFolder(cwx.utils.debugLog.dirName());
  423. }
  424. }
  425. });
  426. auto msg = new Text(area, SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL | SWT.READ_ONLY);
  427. createTextMenu!Text(_comm, _prop, msg, null);
  428. auto msgL = new GridData(GridData.FILL_BOTH);
  429. msgL.horizontalSpan = 2;
  430. msg.setLayoutData(msgL);
  431. msg.setText(_desc);
  432. }
  433. }
  434. class ReNumDialog(A) : AbsDialog {
  435. private:
  436. Props _prop;
  437. A _area;
  438. ulong _minId;
  439. Spinner _id;
  440. ulong _newId;
  441. public:
  442. this (Props prop, Shell shell, A area, ulong minId) { mixin(S_TRACE);
  443. _prop = prop;
  444. _area = area;
  445. _minId = minId;
  446. super(prop, shell, prop.msgs.dlgTitReNumbering, prop.images.menu(MenuID.ReNumbering), false);
  447. enterClose = true;
  448. }
  449. @property
  450. ulong newId() { mixin(S_TRACE);
  451. return _newId;
  452. }
  453. protected:
  454. override void setup(Composite area) { mixin(S_TRACE);
  455. area.setLayout(new GridLayout(1, false));
  456. { mixin(S_TRACE);
  457. auto grp = new Group(area, SWT.NONE);
  458. grp.setLayoutData(new GridData(GridData.FILL_BOTH));
  459. grp.setText(_prop.msgs.reNumbering);
  460. grp.setLayout(new CenterLayout(SWT.VERTICAL | SWT.HORIZONTAL, 0));
  461. auto comp = new Composite(grp, SWT.NONE);
  462. comp.setLayout(new GridLayout(3, false));
  463. string cName = objName!A(_prop);
  464. auto l1 = new Label(comp, SWT.NONE);
  465. l1.setText(.tryFormat(_prop.msgs.reNumbering1, cName, _area.name));
  466. _id = new Spinner(comp, SWT.BORDER);
  467. initSpinner(_id);
  468. _id.setMaximum(_prop.looks.idMax);
  469. _id.setMinimum(cast(int) _minId);
  470. auto l2 = new Label(comp, SWT.NONE);
  471. l2.setText(.tryFormat(_prop.msgs.reNumbering2, cName, _area.name));
  472. }
  473. }
  474. override bool close(bool ok) { mixin(S_TRACE);
  475. if (ok) { mixin(S_TRACE);
  476. _newId = _id.getSelection();
  477. }
  478. return ok;
  479. }
  480. }
  481. class ScriptVarSetDialog : AbsDialog {
  482. private:
  483. /// ?????(?????)?
  484. enum VarKind {
  485. Variant, /// ???????
  486. Boolean, /// true, false?
  487. Flag, /// ???(???)?
  488. Step, /// ????(???)?
  489. Area, /// ???(ID)?
  490. Battle, /// ???(ID)?
  491. Package, /// ?????(ID)?
  492. Cast, /// ???????(ID)?
  493. Skill, /// ??????(ID)?
  494. Item, /// ???????(ID)?
  495. Beast, /// ??????(ID)?
  496. Info, /// ?????(ID)?
  497. Coupon, /// ????(???)?
  498. Gossip, /// ????(???)?
  499. CompleteStamp, /// ???(???)?
  500. File /// ???????
  501. }
  502. Commons _comm;
  503. Summary _summ;
  504. const string[] _vars;
  505. string _script, _base;
  506. string[] _values;
  507. Table _table;
  508. Combo _editor = null;
  509. string[] _editorTable;
  510. const CompileOption _opt;
  511. Content[] _contents;
  512. void editEnd(TableItem itm, int column, string text) { mixin(S_TRACE);
  513. int i = _editor.getSelectionIndex();
  514. auto row = itm.getParent().indexOf(itm);
  515. if (-1 == i) { mixin(S_TRACE);
  516. _values[row] = text;
  517. } else { mixin(S_TRACE);
  518. _values[row] = _editorTable[i];
  519. }
  520. itm.setText(column, _values[row]);
  521. }
  522. Control createEditor(TableItem itm, int column) { mixin(S_TRACE);
  523. string[] strs;
  524. _editorTable.length = 0;
  525. strs ~= "true";
  526. _editorTable ~= "true";
  527. strs ~= "false";
  528. _editorTable ~= "false";
  529. if (_summ) { mixin(S_TRACE);
  530. foreach (f; _summ.flagDirRoot.allFlags) { mixin(S_TRACE);
  531. strs ~= objName!(typeof(f))(_comm.prop) ~ " - " ~ f.path;
  532. _editorTable ~= CWXScript.createString(f.path);
  533. }
  534. foreach (f; _summ.flagDirRoot.allSteps) { mixin(S_TRACE);
  535. strs ~= objName!(typeof(f))(_comm.prop) ~ " - " ~ f.path;
  536. _editorTable ~= CWXScript.createString(f.path);
  537. }
  538. foreach (a; _summ.areas) { mixin(S_TRACE);
  539. strs ~= objName!(typeof(a))(_comm.prop) ~ " - " ~ .text(a.id) ~ "." ~ a.name;
  540. _editorTable ~= .text(a.id);
  541. }
  542. foreach (a; _summ.battles) { mixin(S_TRACE);
  543. strs ~= objName!(typeof(a))(_comm.prop) ~ " - " ~ .text(a.id) ~ "." ~ a.name;
  544. _editorTable ~= .text(a.id);
  545. }
  546. foreach (a; _summ.packages) { mixin(S_TRACE);
  547. strs ~= objName!(typeof(a))(_comm.prop) ~ " - " ~ .text(a.id) ~ "." ~ a.name;
  548. _editorTable ~= .text(a.id);
  549. }
  550. foreach (a; _summ.casts) { mixin(S_TRACE);
  551. strs ~= objName!(typeof(a))(_comm.prop) ~ " - " ~ .text(a.id) ~ "." ~ a.name;
  552. _editorTable ~= .text(a.id);
  553. }
  554. foreach (a; _summ.skills) { mixin(S_TRACE);
  555. strs ~= objName!(typeof(a))(_comm.prop) ~ " - " ~ .text(a.id) ~ "." ~ a.name;
  556. _editorTable ~= .text(a.id);
  557. }
  558. foreach (a; _summ.items) { mixin(S_TRACE);
  559. strs ~= objName!(typeof(a))(_comm.prop) ~ " - " ~ .text(a.id) ~ "." ~ a.name;
  560. _editorTable ~= .text(a.id);
  561. }
  562. foreach (a; _summ.beasts) { mixin(S_TRACE);
  563. strs ~= objName!(typeof(a))(_comm.prop) ~ " - " ~ .text(a.id) ~ "." ~ a.name;
  564. _editorTable ~= .text(a.id);
  565. }
  566. foreach (a; _summ.infos) { mixin(S_TRACE);
  567. strs ~= objName!(typeof(a))(_comm.prop) ~ " - " ~ .text(a.id) ~ "." ~ a.name;
  568. _editorTable ~= .text(a.id);
  569. }
  570. foreach (a; _summ.useCounter.coupon.keys.sort) { mixin(S_TRACE);
  571. strs ~= _comm.prop.msgs.coupon ~ " - " ~ a;
  572. _editorTable ~= CWXScript.createString(a);
  573. }
  574. foreach (a; _summ.useCounter.gossip.keys.sort) { mixin(S_TRACE);
  575. strs ~= _comm.prop.msgs.gossip ~ " - " ~ a;
  576. _editorTable ~= CWXScript.createString(a);
  577. }
  578. foreach (a; _summ.useCounter.completeStamp.keys.sort) { mixin(S_TRACE);
  579. strs ~= _comm.prop.msgs.completeStamp ~ " - " ~ a;
  580. _editorTable ~= CWXScript.createString(a);
  581. }
  582. foreach (p; _summ.allMaterials(_comm.skin, _comm.prop.var.etc.ignorePaths, _comm.prop.var.etc.logicalSort, false)) { mixin(S_TRACE);
  583. strs ~= _comm.prop.msgs.material ~ " - " ~ p;
  584. _editorTable ~= CWXScript.createString(p);
  585. }
  586. }
  587. _editor = createComboEditor(_comm, _comm.prop, _table, strs, itm.getText(column), false);
  588. return _editor;
  589. }
  590. public:
  591. this (Commons comm, Summary summ, Shell shell, in string[] vars, string script, string base, in CompileOption opt) { mixin(S_TRACE);
  592. _comm = comm;
  593. _summ = summ;
  594. _vars = vars;
  595. _values.length = _vars.length;
  596. _script = script;
  597. _base = base;
  598. _opt = opt;
  599. auto size = comm.prop.var.scriptVarSetDlg;
  600. super(comm.prop, shell, true, comm.prop.msgs.dlgTitScriptVarSet, comm.prop.images.menu(MenuID.EvTemplates), true, size);
  601. enterClose = false;
  602. }
  603. @property
  604. Content[] contents() { mixin(S_TRACE);
  605. return _contents;
  606. }
  607. protected:
  608. override void setup(Composite area) { mixin(S_TRACE);
  609. area.setLayout(new GridLayout(1, false));
  610. auto grp = new Group(area, SWT.NONE);
  611. grp.setLayoutData(new GridData(GridData.FILL_BOTH));
  612. grp.setText(_comm.prop.msgs.scriptVarSet);
  613. grp.setLayout(new GridLayout(1, false));
  614. _table = new Table(grp, SWT.BORDER | SWT.FULL_SELECTION);
  615. auto vgd = new GridData(GridData.FILL_BOTH);
  616. vgd.heightHint = _comm.prop.var.etc.scriptVarTableHeight;
  617. _table.setLayoutData(vgd);
  618. _table.setHeaderVisible(true);
  619. auto nameCol = new TableColumn(_table, SWT.NONE);
  620. nameCol.setText(_comm.prop.msgs.scriptVarNameColumn);
  621. nameCol.setResizable(false);
  622. auto valueCol = new FullTableColumn(_table, SWT.NONE);
  623. valueCol.column.setText(_comm.prop.msgs.scriptVarValueColumn);
  624. foreach (var; _vars) { mixin(S_TRACE);
  625. auto itm = new TableItem(_table, SWT.NONE);
  626. itm.setText(var);
  627. }
  628. nameCol.pack();
  629. new TableTextEdit(_comm, _comm.prop, _table, 1, &editEnd, null, &createEditor);
  630. }
  631. override bool close(bool ok, out bool cancel) { mixin(S_TRACE);
  632. if (ok) { mixin(S_TRACE);
  633. CompileOption opt = _opt;
  634. try { mixin(S_TRACE);
  635. VarSet[] varTable;
  636. foreach (i, var; _vars) { mixin(S_TRACE);
  637. varTable ~= VarSet(var, _values[i]);
  638. }
  639. _contents = cwx.script.compile(_comm.prop.parent, _summ, CWXScript.pushVars(_script, varTable, opt), opt);
  640. } catch (CWXScriptException e) {
  641. auto dlg = new ScriptErrorDialog(_comm, _comm.prop, _table, e, _base, opt);
  642. dlg.open();
  643. ok = false;
  644. cancel = true;
  645. }
  646. }
  647. return ok;
  648. }
  649. }
  650. class EventTemplateDialog : AbsDialog {
  651. private Commons _comm;
  652. private Props _prop;
  653. private Summary _summ;
  654. private ToolsPane!EvTemplate _evTempls;
  655. private EvTemplate[] _tmpls;
  656. this (Commons comm, Props prop, Summary summ, Shell shell, EvTemplate[] tmpls) { mixin(S_TRACE);
  657. _comm = comm;
  658. _prop = prop;
  659. _summ = summ;
  660. _tmpls = tmpls;
  661. auto size = comm.prop.var.evTemplDlg;
  662. super (prop, shell, false, title, prop.images.menu(MenuID.EvTemplates), true, size, true, true);
  663. }
  664. @property
  665. private string title() { mixin(S_TRACE);
  666. return .tryFormat(_prop.msgs.dlgTitEvTemplates, _summ.scenarioName);
  667. }
  668. @property
  669. EvTemplate[] eventTemplates() { return _tmpls; }
  670. private void refScenarioName() { mixin(S_TRACE);
  671. getShell().setText(title);
  672. }
  673. private void refScenario(Summary summ) { mixin(S_TRACE);
  674. if (_summ !is summ) forceCancel();
  675. }
  676. protected override void setup(Composite area) { mixin(S_TRACE);
  677. area.setLayout(windowGridLayout(1, true));
  678. _evTempls = new ToolsPane!EvTemplate(_comm, (b) { ignoreMod = b; }, &catchMod, &applyEnabled, area, SWT.NONE);
  679. _evTempls.setup(_tmpls, _prop.var.etc.eventTemplatesOfScenarioSashL.value, _prop.var.etc.eventTemplatesOfScenarioSashR.value);
  680. _evTempls.setShortcutWeights(_prop.var.etc.eventTemplateOfScenarioShortcutSashL.value, _prop.var.etc.eventTemplateOfScenarioShortcutSashR.value);
  681. _evTempls.setLayoutData(new GridData(GridData.FILL_BOTH));
  682. _comm.refScenarioName.add(&refScenarioName);
  683. _comm.refScenario.add(&refScenario);
  684. .listener(_evTempls, SWT.Dispose, {
  685. _comm.refScenarioName.remove(&refScenarioName);
  686. _comm.refScenario.remove(&refScenario);
  687. });
  688. }
  689. protected override bool apply() { mixin(S_TRACE);
  690. if (_evTempls.noApply) {
  691. auto dlg = new MessageBox(getShell(), SWT.YES | SWT.NO | SWT.ICON_QUESTION);
  692. dlg.setText(_prop.msgs.dlgTitQuestion);
  693. dlg.setMessage(.tryFormat(_prop.msgs.dlgMsgExistsNoApplySettingsSingle, _evTempls.boxName));
  694. if (SWT.YES != dlg.open()) return false;
  695. }
  696. _tmpls = _evTempls.array;
  697. return true;
  698. }
  699. }
  700. class ImportOptionDialog : AbsDialog {
  701. private Commons _comm;
  702. private ImportOption _opt;
  703. private Props _prop;
  704. private Combo _materials;
  705. private Combo _variables;
  706. private Combo _casts;
  707. private Combo _skills;
  708. private Combo _items;
  709. private Combo _beasts;
  710. private Combo _infos;
  711. private Combo _areas;
  712. private Combo _battles;
  713. private Combo _packages;
  714. private Combo _includedFiles;
  715. private Combo _includedBgImages;
  716. private Combo _hands;
  717. private Combo _beastsInMotions;
  718. this (Commons comm, Shell shell) { mixin(S_TRACE);
  719. _comm = comm;
  720. _prop = comm.prop;
  721. super (_prop, shell, true, _prop.msgs.dlgTitImportOption, _prop.images.menu(MenuID.Import), false);
  722. }
  723. @property
  724. ImportOption option() { return _opt; }
  725. protected override void setup(Composite area) { mixin(S_TRACE);
  726. area.setLayout(new GridLayout(4, false));
  727. Combo create(T)(Image icon, string name, int opValue, T value) { mixin(S_TRACE);
  728. if (opValue < value.min || value.max < opValue) opValue = value;
  729. value = cast(T)opValue;
  730. auto label = new CLabel(area, SWT.NONE);
  731. label.setText(name);
  732. label.setImage(icon);
  733. auto combo = new Combo(area, SWT.READ_ONLY | SWT.DROP_DOWN | SWT.BORDER);
  734. mod(combo);
  735. combo.setVisibleItemCount(_prop.var.etc.comboVisibleItemCount);
  736. foreach (t; EnumMembers!T) { mixin(S_TRACE);
  737. static if (is(T:ImportTypeIncluded)) {
  738. combo.add(_prop.msgs.importTypeIncludedName(t));
  739. } else static if (is(T:ImportTypeReference1)) {
  740. combo.add(_prop.msgs.importTypeReference1Name(t));
  741. } else static if (is(T:ImportTypeReference2)) {
  742. combo.add(_prop.msgs.importTypeReference2Name(t));
  743. } else static assert (0);
  744. if (t is value) { mixin(S_TRACE);
  745. combo.select(combo.getItemCount() - 1);
  746. }
  747. }
  748. combo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
  749. return combo;
  750. }
  751. _materials = create(_prop.images.text, _prop.msgs.importOptionMaterials, _prop.var.etc.importOptionMaterials, _opt.materials);
  752. _variables = create(_prop.images.flagDir, _prop.msgs.importOptionVariables, _prop.var.etc.importOptionVariables, _opt.variables);
  753. _casts = create(_prop.images.casts, _prop.msgs.importOptionCasts, _prop.var.etc.importOptionCasts, _opt.casts);
  754. _skills = create(_prop.images.skill, _prop.msgs.importOptionSkills, _prop.var.etc.importOptionSkills, _opt.skills);
  755. _items = create(_prop.images.item, _prop.msgs.importOptionItems, _prop.var.etc.importOptionItems, _opt.items);
  756. _beasts = create(_prop.images.beast, _prop.msgs.importOptionBeasts, _prop.var.etc.importOptionBeasts, _opt.beasts);
  757. _infos = create(_prop.images.info, _prop.msgs.importOptionInfos, _prop.var.etc.importOptionInfos, _opt.infos);
  758. _areas = create(_prop.images.area, _prop.msgs.importOptionAreas, _prop.var.etc.importOptionAreas, _opt.areas);
  759. _battles = create(_prop.images.battle, _prop.msgs.importOptionBattles, _prop.var.etc.importOptionBattles, _opt.battles);
  760. _packages = create(_prop.images.packages, _prop.msgs.importOptionPackages, _prop.var.etc.importOptionPackages, _opt.packages);
  761. _includedFiles = create(_prop.images.cards, _prop.msgs.importOptionIncludedFiles, _prop.var.etc.importOptionIncludedFiles, _opt.includedFiles);
  762. _includedBgImages = create(_prop.images.backs, _prop.msgs.importOptionIncludedBgImages, _prop.var.etc.importOptionIncludedBgImages, _opt.includedBgImages);
  763. _hands = create(_prop.images.menu(MenuID.OpenHand), _prop.msgs.importOptionHands, _prop.var.etc.importOptionHands, _opt.hands);
  764. _beastsInMotions = create(_prop.images.beast, _prop.msgs.importOptionBeastsInMotions, _prop.var.etc.importOptionBeastsInMotions, _opt.beastsInMotions);
  765. }
  766. protected override bool close(bool ok) { mixin(S_TRACE);
  767. if (!ok) return ok;
  768. void put(T)(Combo combo, ref int opValue, ref T value) { mixin(S_TRACE);
  769. auto arr = EnumMembers!T;
  770. auto index = combo.getSelectionIndex();
  771. foreach (i, t; arr) { mixin(S_TRACE);
  772. if (i == index) { mixin(S_TRACE);
  773. opValue = cast(int)t;
  774. value = t;
  775. break;
  776. }
  777. }
  778. }
  779. put(_materials, _prop.var.etc.importOptionMaterials.value, _opt.materials);
  780. put(_variables, _prop.var.etc.importOptionVariables.value, _opt.variables);
  781. put(_casts, _prop.var.etc.importOptionCasts.value, _opt.casts);
  782. put(_skills, _prop.var.etc.importOptionSkills.value, _opt.skills);
  783. put(_items, _prop.var.etc.importOptionItems.value, _opt.items);
  784. put(_beasts, _prop.var.etc.importOptionBeasts.value, _opt.beasts);
  785. put(_infos, _prop.var.etc.importOptionInfos.value, _opt.infos);
  786. put(_areas, _prop.var.etc.importOptionAreas.value, _opt.areas);
  787. put(_battles, _prop.var.etc.importOptionBattles.value, _opt.battles);
  788. put(_packages, _prop.var.etc.importOptionPackages.value, _opt.packages);
  789. put(_includedFiles, _prop.var.etc.importOptionIncludedFiles.value, _opt.includedFiles);
  790. put(_includedBgImages, _prop.var.etc.importOptionIncludedBgImages.value, _opt.includedBgImages);
  791. put(_hands, _prop.var.etc.importOptionHands.value, _opt.hands);
  792. put(_beastsInMotions, _prop.var.etc.importOptionBeastsInMotions.value, _opt.beastsInMotions);
  793. return ok;
  794. }
  795. }
  796. /// ?????????????????????
  797. class ImportResultDialog : AbsDialog {
  798. private Commons _comm;
  799. private Props _prop;
  800. private Summary _summ;
  801. private ImportResult _result;
  802. private Table _list;
  803. this (Commons comm, Summary summ, Shell shell, ImportResult result) { mixin(S_TRACE);
  804. _comm = comm;
  805. _prop = comm.prop;
  806. _summ = summ;
  807. _result = result;
  808. auto size = _prop.var.importResultDlg;
  809. super (_prop, shell, true, _prop.msgs.dlgTitImportResult, _prop.images.menu(MenuID.Import), true, size, false, true);
  810. }
  811. @property
  812. ImportResult checkedResult() { return _result; }
  813. private Tuple!(string, F)[] sortedVars(F)(F[][string] table) { mixin(S_TRACE);
  814. Tuple!(string, F)[] flags;
  815. auto sorter = _prop.var.etc.logicalSort ? (string a, string b) => ncmp(a, b) < 0 : (string a, string b) => cmp(a, b) < 0;
  816. auto sorter2 = _prop.var.etc.logicalSort ? (F a, F b) => ncmp(a.name, b.name) < 0 : (F a, F b) => cmp(a.name, b.name) < 0;
  817. foreach (dir; table.keys.sortDlg(sorter)) { mixin(S_TRACE);
  818. foreach (f; table[dir].dup.sortDlg(sorter2)) { mixin(S_TRACE);
  819. flags ~= Tuple!(string, F)(dir, f);
  820. }
  821. }
  822. return flags;
  823. }
  824. protected override void setup(Composite area) { mixin(S_TRACE);
  825. area.setLayout(new GridLayout(1, false));
  826. auto label = new Label(area, SWT.WRAP);
  827. label.setText(_prop.msgs.importResourceList);
  828. label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
  829. _list = new Table(area, SWT.MULTI | SWT.CHECK | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
  830. _list.setLayoutData(new GridData(GridData.FILL_BOTH));
  831. new FullTableColumn(_list, SWT.NONE);
  832. .listener(_list, SWT.Selection, .toDelegate(&updateChecked!Event));
  833. auto menu = new Menu(_list.getShell(), SWT.POP_UP);
  834. createMenuItem(_comm, menu, MenuID.SelectAll, &_list.selectAll, () => _list.getItemCount() && _list.getSelectionCount() != _list.getItemCount());
  835. _list.setMenu(menu);
  836. auto skin = _comm.skin;
  837. foreach (m; _result.materials) { mixin(S_TRACE);
  838. auto itm = new TableItem(_list, SWT.NONE);
  839. itm.setImage(.fimage(_prop, m.src, skin));
  840. auto text = m.dst.relativePath(_summ.scenarioPath).encodePath();
  841. if (m.overwrite) text = .tryFormat(_prop.msgs.overwriteMark, text);
  842. itm.setText(text);
  843. itm.setChecked(true);
  844. }
  845. void putVars(F)(Image icon, F[string] table) { mixin(S_TRACE);
  846. foreach (t; sortedVars(table)) { mixin(S_TRACE);
  847. auto itm = new TableItem(_list, SWT.NONE);
  848. itm.setImage(icon);
  849. auto path = t[0].length ? FlagDir.join(t[0], t[1].name) : t[1].name;
  850. auto text = .tryFormat(_prop.msgs.searchResultFlag, path);
  851. if (t[1].overwrite) text = .tryFormat(_prop.msgs.overwriteMark, text);
  852. itm.setText(text);
  853. itm.setChecked(true);
  854. }
  855. }
  856. putVars(_prop.images.flag, _result.flags);
  857. putVars(_prop.images.step, _result.steps);
  858. void putRes(T)(T[ulong] table) { mixin(S_TRACE);
  859. foreach (id; table.keys.sort) { mixin(S_TRACE);
  860. auto itm = new TableItem(_list, SWT.NONE);
  861. Image icon, icon2;
  862. string text, text2;
  863. getSymbols(_comm, _summ, table[id], text, text2, icon, icon2);
  864. itm.setImage(icon);
  865. itm.setText(text);
  866. itm.setChecked(true);
  867. }
  868. }
  869. putRes(_result.casts);
  870. putRes(_result.skills);
  871. putRes(_result.items);
  872. putRes(_result.beasts);
  873. putRes(_result.infos);
  874. putRes(_result.areas);
  875. putRes(_result.battles);
  876. putRes(_result.packages);
  877. }
  878. protected override bool close(bool ok) { mixin(S_TRACE);
  879. if (!ok) return ok;
  880. ImportResult result2;
  881. int i = 0;
  882. foreach (m; _result.materials) { mixin(S_TRACE);
  883. if (_list.getItem(i).getChecked()) result2.materials ~= m;
  884. i++;
  885. }
  886. void putVars(F)(Image icon, F[string] table, ref F[string] table2) { mixin(S_TRACE);
  887. foreach (t; sortedVars(table)) { mixin(S_TRACE);
  888. if (_list.getItem(i).getChecked()) table2[t[0]] ~= t[1];
  889. i++;
  890. }
  891. }
  892. putVars(_prop.images.flag, _result.flags, result2.flags);
  893. putVars(_prop.images.step, _result.steps, result2.steps);
  894. void putRes(T)(T[ulong] table, ref T[ulong] table2) { mixin(S_TRACE);
  895. foreach (id; table.keys.sort) { mixin(S_TRACE);
  896. if (_list.getItem(i).getChecked()) table2[id] = table[id];
  897. i++;
  898. }
  899. }
  900. putRes(_result.casts, result2.casts);
  901. putRes(_result.skills, result2.skills);
  902. putRes(_result.items, result2.items);
  903. putRes(_result.beasts, result2.beasts);
  904. putRes(_result.infos, result2.infos);
  905. putRes(_result.areas, result2.areas);
  906. putRes(_result.battles, result2.battles);
  907. putRes(_result.packages, result2.packages);
  908. _result = result2;
  909. return ok;
  910. }
  911. }