PageRenderTime 104ms CodeModel.GetById 24ms RepoModel.GetById 6ms app.codeStats 0ms

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

https://bitbucket.org/k4nagatsuki/cwxeditor
D | 1467 lines | 1429 code | 35 blank | 3 comment | 150 complexity | c2109dab7a21c1543df97af3836e90bb MD5 | raw file
Possible License(s): LGPL-2.1
  1. module cwx.editor.gui.dwt.castcarddialog;
  2. import cwx.coupon;
  3. import cwx.summary;
  4. import cwx.card;
  5. import cwx.types;
  6. import cwx.features;
  7. import cwx.utils;
  8. import cwx.race;
  9. import cwx.xml;
  10. import cwx.skin;
  11. import cwx.motion;
  12. import cwx.path;
  13. import cwx.menu;
  14. import cwx.types;
  15. import cwx.imagesize;
  16. import cwx.editor.gui.dwt.dprops;
  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.materialselect;
  21. import cwx.editor.gui.dwt.imageselect;
  22. import cwx.editor.gui.dwt.customtext;
  23. import cwx.editor.gui.dwt.customtable;
  24. import cwx.editor.gui.dwt.centerlayout;
  25. import cwx.editor.gui.dwt.radarspinner;
  26. import cwx.editor.gui.dwt.xmlbytestransfer;
  27. import cwx.editor.gui.dwt.absdialog;
  28. import cwx.editor.gui.dwt.undo;
  29. import cwx.editor.gui.dwt.dmenu;
  30. import cwx.editor.gui.dwt.couponview;
  31. import cwx.editor.gui.dwt.scales;
  32. import std.datetime;
  33. import std.string;
  34. import std.conv;
  35. import org.eclipse.swt.all;
  36. import java.lang.all;
  37. public:
  38. /// ???????????????????
  39. class CastCardDialog : AbsDialog {
  40. private:
  41. string _id;
  42. int _readOnly = 0;
  43. Commons _comm;
  44. Props _prop;
  45. Summary _summ;
  46. CastCard _card;
  47. ImageSelect!(MtType.CARD) _imgPath;
  48. FixedWidthText _desc;
  49. GBLimitText _name;
  50. Spinner _level;
  51. Spinner _lifeMax;
  52. CouponView!(CVType.Cast) _couponView;
  53. Combo _race;
  54. Button[Sex] _sex;
  55. Button _sexU;
  56. Button[Period] _period;
  57. Button _periodU;
  58. Composite _natureComp;
  59. Button[Nature] _nature;
  60. Button _natureU;
  61. bool _showSpNature = false;
  62. Button[Makings] _makings;
  63. Button _resW;
  64. Button _resM;
  65. Button _undead;
  66. Button _automaton;
  67. Button _unholy;
  68. Button _constructure;
  69. Button _res[Element];
  70. Button _weak[Element];
  71. int[Physical] _phyTbl;
  72. Composite _phyParent;
  73. RadarSpinner _phyR = null;
  74. Scales _phyS = null;
  75. Scale[Mental] _mtl;
  76. Label _sumPhy;
  77. int[Enhance] _enhTbl;
  78. Composite _enhParent;
  79. RadarSpinner _enhR = null;
  80. Scales _enhS = null;
  81. Spinner _life;
  82. Button _lifeUseMax;
  83. Spinner[Enhance] _liveEnh;
  84. Spinner[Enhance] _enhRound;
  85. Spinner _paralyze;
  86. Spinner _poison;
  87. Spinner _bind;
  88. Spinner _silence;
  89. Spinner _faceUp;
  90. Spinner _antiMagic;
  91. Mentality[int] _mtlyTbl;
  92. Combo _mtly;
  93. Spinner _mtlyRound;
  94. Skin _summSkin;
  95. @property
  96. Skin summSkin() { mixin(S_TRACE);
  97. return _summSkin ? _summSkin : _comm.skin;
  98. }
  99. void refreshWarning() { mixin(S_TRACE);
  100. string[] ws;
  101. if (_name.over) { mixin(S_TRACE);
  102. ws ~= .tryFormat(_prop.msgs.warningNameLenOver, _prop.looks.castNameLimit, _prop.looks.castNameLimit / 2);
  103. }
  104. ws ~= _imgPath.warnings;
  105. warning = ws;
  106. }
  107. @property
  108. Race selectedRace() { mixin(S_TRACE);
  109. if (_race) { mixin(S_TRACE);
  110. int index = _race.getSelectionIndex();
  111. if (index > 0) { mixin(S_TRACE);
  112. return summSkin.races[index - 1];
  113. }
  114. }
  115. return null;
  116. }
  117. void raceToolTip() { mixin(S_TRACE);
  118. if (_race) { mixin(S_TRACE);
  119. auto race = selectedRace;
  120. _race.setToolTipText(race ? race.desc : "");
  121. }
  122. }
  123. class SelectRace : SelectionAdapter {
  124. override void widgetSelected(SelectionEvent e) { mixin(S_TRACE);
  125. raceToolTip();
  126. }
  127. }
  128. class BasicResist : SelectionAdapter {
  129. override void widgetSelected(SelectionEvent e) { mixin(S_TRACE);
  130. auto race = selectedRace;
  131. if (race) { mixin(S_TRACE);
  132. _automaton.setSelection(race.automaton);
  133. _constructure.setSelection(race.constructure);
  134. _undead.setSelection(race.undead);
  135. _unholy.setSelection(race.unholy);
  136. _resW.setSelection(race.weaponResist);
  137. _resM.setSelection(race.magicResist);
  138. foreach (el; _res.keys) { mixin(S_TRACE);
  139. _res[el].setSelection(race.resist(el));
  140. _weak[el].setSelection(race.weakness(el));
  141. }
  142. } else { mixin(S_TRACE);
  143. _automaton.setSelection(false);
  144. _constructure.setSelection(false);
  145. _undead.setSelection(false);
  146. _unholy.setSelection(false);
  147. _resW.setSelection(false);
  148. _resM.setSelection(false);
  149. foreach (el; _res.keys) { mixin(S_TRACE);
  150. _res[el].setSelection(false);
  151. _weak[el].setSelection(false);
  152. }
  153. }
  154. }
  155. }
  156. class BasicEnhance : SelectionAdapter {
  157. override void widgetSelected(SelectionEvent e) { mixin(S_TRACE);
  158. auto race = selectedRace;
  159. if (race) { mixin(S_TRACE);
  160. foreach (enh, i; _enhTbl) { mixin(S_TRACE);
  161. if (_enhR) { mixin(S_TRACE);
  162. _enhR.setValue(i, race.defaultEnhance(enh));
  163. } else { mixin(S_TRACE);
  164. _enhS.setValue(i, race.defaultEnhance(enh));
  165. }
  166. }
  167. } else { mixin(S_TRACE);
  168. foreach (enh, i; _enhTbl) { mixin(S_TRACE);
  169. if (_enhR) { mixin(S_TRACE);
  170. _enhR.setValue(i, 0);
  171. } else { mixin(S_TRACE);
  172. _enhS.setValue(i, 0);
  173. }
  174. }
  175. }
  176. }
  177. }
  178. class SelLifeC : SelectionAdapter {
  179. override void widgetSelected(SelectionEvent e) { mixin(S_TRACE);
  180. auto vit = _phyTbl[Physical.VIT];
  181. auto min = _phyTbl[Physical.MIN];
  182. _lifeMax.setSelection(_prop.looks.lifeCalc(_level.getSelection(),
  183. (_phyR ? _phyR.getValue(vit) : _phyS.getValue(vit)),
  184. (_phyR ? _phyR.getValue(min) : _phyS.getValue(min))));
  185. }
  186. }
  187. void constructBase(CTabFolder tabf) { mixin(S_TRACE);
  188. auto comp = new Composite(tabf, SWT.NONE);
  189. comp.setLayout(new GridLayout(2, false));
  190. auto skin = summSkin;
  191. { mixin(S_TRACE);
  192. auto comp2 = new Composite(comp, SWT.NONE);
  193. comp2.setLayoutData(new GridData(GridData.FILL_BOTH));
  194. comp2.setLayout(zeroMarginGridLayout(1, false));
  195. { mixin(S_TRACE);
  196. auto grp = new Group(comp2, SWT.NONE);
  197. grp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
  198. grp.setLayout(new GridLayout(2, false));
  199. grp.setText(_prop.msgs.name);
  200. _name = new GBLimitText(_prop.looks.monospace,
  201. _prop.looks.castNameLimit, false, grp, SWT.BORDER | _readOnly);
  202. _name.limitEvent ~= &refreshWarning;
  203. mod(_name.widget);
  204. createTextMenu!Text(_comm, _prop, _name.widget, &catchMod);
  205. auto gd = new GridData(GridData.FILL_HORIZONTAL);
  206. gd.widthHint = _name.computeSize(SWT.DEFAULT, SWT.DEFAULT).x;
  207. _name.widget.setLayoutData(gd);
  208. auto l = new Label(grp, SWT.NONE);
  209. l.setText(.tryFormat(_prop.msgs.nameLimit, _prop.looks.castNameLimit, _prop.looks.castNameLimit / 2));
  210. }
  211. { mixin(S_TRACE);
  212. bool including = _card && isBinImg(_card.path);
  213. _imgPath = new ImageSelect!(MtType.CARD)(comp2, _readOnly, _comm, _prop, _summ,
  214. _prop.looks.cardSize.width, _prop.looks.cardSize.height, including, true, &_name.getText);
  215. mod(_imgPath);
  216. _imgPath.modEvent ~= &refreshWarning;
  217. _imgPath.widget.setLayoutData(new GridData(GridData.FILL_BOTH));
  218. _imgPath.cardMode = CardMode.Cast;
  219. }
  220. }
  221. { mixin(S_TRACE);
  222. auto compr = new Composite(comp, SWT.NONE);
  223. compr.setLayoutData(new GridData(GridData.FILL_VERTICAL));
  224. compr.setLayout(zeroMarginGridLayout(1, false));
  225. { mixin(S_TRACE);
  226. auto grp = new Group(compr, SWT.NONE);
  227. grp.setLayoutData(new GridData(GridData.FILL_BOTH));
  228. grp.setLayout(new CenterLayout);
  229. grp.setText(_prop.msgs.level);
  230. auto comp2 = new Composite(grp, SWT.NONE);
  231. comp2.setLayout(zeroMarginGridLayout(2, false));
  232. _level = new Spinner(comp2, SWT.BORDER | _readOnly);
  233. initSpinner(_level);
  234. mod(_level);
  235. _level.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
  236. _level.setMinimum(1);
  237. _level.setMaximum(_prop.var.etc.castLevelMax);
  238. auto hint = new Label(comp2, SWT.RIGHT);
  239. hint.setText(.tryFormat(_prop.msgs.rangeHint, 1, _prop.var.etc.castLevelMax));
  240. }
  241. { mixin(S_TRACE);
  242. auto grp = new Group(compr, SWT.NONE);
  243. grp.setLayoutData(new GridData(GridData.FILL_BOTH));
  244. grp.setLayout(new CenterLayout);
  245. grp.setText(_prop.msgs.life);
  246. auto comp2 = new Composite(grp, SWT.NONE);
  247. comp2.setLayout(zeroMarginGridLayout(2, false));
  248. _lifeMax = new Spinner(comp2, SWT.BORDER | _readOnly);
  249. initSpinner(_lifeMax);
  250. mod(_lifeMax);
  251. _lifeMax.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
  252. _lifeMax.setMinimum(1);
  253. _lifeMax.setMaximum(_prop.var.etc.lifeMax);
  254. _lifeMax.addModifyListener(new LifeMaxL);
  255. auto hint = new Label(comp2, SWT.RIGHT);
  256. hint.setText(.tryFormat(_prop.msgs.rangeHint, 1, _prop.var.etc.lifeMax));
  257. auto lifec = new Button(comp2, SWT.PUSH);
  258. mod(lifec);
  259. lifec.setEnabled(!_readOnly);
  260. auto lgd = new GridData(GridData.FILL_HORIZONTAL);
  261. lgd.horizontalSpan = 2;
  262. lifec.setLayoutData(lgd);
  263. lifec.setText(_prop.msgs.lifeCalc);
  264. lifec.addSelectionListener(new SelLifeC);
  265. }
  266. auto grp = new Group(compr, SWT.NONE);
  267. grp.setText(_prop.msgs.race);
  268. grp.setLayoutData(new GridData(GridData.FILL_BOTH));
  269. auto cl = new CenterLayout;
  270. cl.fillHorizontal = true;
  271. grp.setLayout(cl);
  272. _race = new Combo(grp, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY);
  273. mod(_race);
  274. _race.setEnabled(!_readOnly);
  275. _race.setVisibleItemCount(_prop.var.etc.comboVisibleItemCount);
  276. _race.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
  277. _race.add(_prop.msgs.noRace);
  278. foreach (race; skin.races) { mixin(S_TRACE);
  279. _race.add(race.name);
  280. }
  281. _race.addSelectionListener(new SelectRace);
  282. refreshRace();
  283. }
  284. auto tab = new CTabItem(tabf, SWT.NONE);
  285. tab.setText(_prop.msgs.card);
  286. tab.setControl(comp);
  287. }
  288. void setMaxLife() { mixin(S_TRACE);
  289. _life.setMaximum(_lifeMax.getSelection());
  290. if (_lifeUseMax.getSelection()) { mixin(S_TRACE);
  291. _life.setSelection(_lifeMax.getSelection());
  292. }
  293. _life.getParent().layout();
  294. _life.setSelection(_life.getSelection());
  295. }
  296. class LifeMaxL : ModifyListener {
  297. public override void modifyText(ModifyEvent e) { mixin(S_TRACE);
  298. setMaxLife();
  299. }
  300. }
  301. void constructDesc(CTabFolder tabf) { mixin(S_TRACE);
  302. auto comp = new Composite(tabf, SWT.NONE);
  303. comp.setLayout(new GridLayout(2, false));
  304. { mixin(S_TRACE);
  305. auto grp = new Group(comp, SWT.NONE);
  306. auto gd = new GridData(GridData.FILL_BOTH);
  307. grp.setLayoutData(gd);
  308. gd.horizontalSpan = 2;
  309. auto cl = new CenterLayout(SWT.HORIZONTAL);
  310. cl.fillVertical = true;
  311. grp.setLayout(cl);
  312. grp.setText(_prop.msgs.desc);
  313. _desc = new FixedWidthText(dwtData(_prop.looks.cardDescFont(_summ.legacy)), _prop.looks.cardDescLen, grp, SWT.BORDER | _readOnly);
  314. mod(_desc.widget);
  315. createTextMenu!Text(_comm, _prop, _desc.widget, &catchMod);
  316. auto p = _desc.computeTextBaseSize(1);
  317. p.y = SWT.DEFAULT;
  318. _desc.widget.setLayoutData(p);
  319. }
  320. auto tab = new CTabItem(tabf, SWT.NONE);
  321. tab.setText(_prop.msgs.desc);
  322. tab.setControl(comp);
  323. }
  324. Button createR(Composite parent, string name, int hAlignHint = -1) { mixin(S_TRACE);
  325. auto radio = new Button(parent, SWT.RADIO);
  326. mod(radio);
  327. radio.setEnabled(!_readOnly);
  328. auto gd = new GridData(GridData.FILL_BOTH);
  329. if (0 <= hAlignHint) { mixin(S_TRACE);
  330. hAlignHint %= 2;
  331. gd.grabExcessHorizontalSpace = true;
  332. if (0 == hAlignHint) { mixin(S_TRACE);
  333. gd.horizontalAlignment = SWT.LEFT;
  334. } else { mixin(S_TRACE);
  335. gd.horizontalAlignment = SWT.RIGHT;
  336. }
  337. }
  338. radio.setLayoutData(gd);
  339. radio.setText(name);
  340. return radio;
  341. }
  342. void constructHistory(CTabFolder tabf) { mixin(S_TRACE);
  343. auto comp = new Composite(tabf, SWT.NONE);
  344. comp.setLayout(new GridLayout(2, false));
  345. auto skin = summSkin;
  346. { mixin(S_TRACE);
  347. auto grp = new Group(comp, SWT.NONE);
  348. grp.setText(_prop.msgs.coupons);
  349. grp.setLayoutData(new GridData(GridData.FILL_BOTH));
  350. grp.setLayout(new GridLayout(1, true));
  351. _couponView = new CouponView!(CVType.Cast)(_comm, _summ, grp, _readOnly, &catchMod);
  352. _couponView.setLayoutData(new GridData(GridData.FILL_BOTH));
  353. mod(_couponView);
  354. }
  355. { mixin(S_TRACE);
  356. auto comp2 = new Composite(comp, SWT.NONE);
  357. comp2.setLayoutData(new GridData(GridData.FILL_VERTICAL));
  358. comp2.setLayout(zeroMarginGridLayout(2, false));
  359. { mixin(S_TRACE);
  360. auto comp3 = createButtonGroup(comp2, _prop.msgs.sexTitle, 1, 1);
  361. foreach (s; SEX_ALL) { mixin(S_TRACE);
  362. auto name = skin.sexName(s);
  363. _sex[s] = createR(comp3, _prop.msgs.sex.get(name, name));
  364. }
  365. _sexU = createR(comp3, _prop.msgs.sexUnknown);
  366. }
  367. { mixin(S_TRACE);
  368. auto comp3 = createButtonGroup(comp2, _prop.msgs.periodTitle, 2, 1);
  369. foreach (p; PERIOD_ALL) { mixin(S_TRACE);
  370. auto name = skin.periodName(p);
  371. _period[p] = createR(comp3, _prop.msgs.period.get(name, name));
  372. }
  373. _periodU = createR(comp3, _prop.msgs.periodUnknown);
  374. }
  375. { mixin(S_TRACE);
  376. auto comp3 = new Group(comp2, SWT.NONE);
  377. comp3.setText(_prop.msgs.natureTitle);
  378. auto cgd = new GridData(GridData.FILL_BOTH);
  379. cgd.horizontalSpan = 2;
  380. comp3.setLayoutData(cgd);
  381. comp3.setLayout(new GridLayout(2, true));
  382. _natureComp = comp3;
  383. updateNature();
  384. }
  385. }
  386. auto tab = new CTabItem(tabf, SWT.NONE);
  387. tab.setText(_prop.msgs.history);
  388. tab.setControl(comp);
  389. }
  390. class MSListener : SelectionAdapter {
  391. override void widgetSelected(SelectionEvent e) { mixin(S_TRACE);
  392. auto radio = cast(Button) e.widget;
  393. if (radio.getSelection()) { mixin(S_TRACE);
  394. auto m = cast(Makings) (cast(Integer) radio.getData()).intValue();
  395. auto r = reverseMakings(m);
  396. _makings[r].setSelection(false);
  397. }
  398. }
  399. };
  400. void constructMakings(CTabFolder tabf) { mixin(S_TRACE);
  401. auto comp = new Composite(tabf, SWT.NONE);
  402. comp.setLayout(new GridLayout(1, false));
  403. auto skin = summSkin;
  404. { mixin(S_TRACE);
  405. auto comp3 = createButtonGroup(comp, _prop.msgs.coupons, 4, 1, true);
  406. auto sl = new MSListener;
  407. foreach (m; MAKINGS_LEFT) { mixin(S_TRACE);
  408. void createR(Makings m) { mixin(S_TRACE);
  409. auto radio = new Button(comp3, SWT.CHECK);
  410. mod(radio);
  411. radio.setEnabled(!_readOnly);
  412. radio.setLayoutData(new GridData(GridData.FILL_BOTH));
  413. auto name = skin.makingsName(m);
  414. radio.setText(_prop.msgs.makings.get(name, name));
  415. radio.setData(new Integer(m));
  416. radio.addSelectionListener(sl);
  417. _makings[m] = radio;
  418. }
  419. createR(m);
  420. createR(reverseMakings(m));
  421. }
  422. }
  423. auto tab = new CTabItem(tabf, SWT.NONE);
  424. tab.setText(_prop.msgs.makingsTitle);
  425. tab.setControl(comp);
  426. }
  427. Composite createButtonGroup(Composite parent, string name,
  428. int row, int horSpan = 1, bool min = false) { mixin(S_TRACE);
  429. auto grp = new Group(parent, SWT.NONE);
  430. grp.setText(name);
  431. auto gd = new GridData(GridData.FILL_BOTH);
  432. gd.horizontalSpan = horSpan;
  433. grp.setLayoutData(gd);
  434. auto cl = new CenterLayout(SWT.HORIZONTAL | SWT.VERTICAL, 0);
  435. cl.fillVertical = true;
  436. grp.setLayout(cl);
  437. auto comp3 = new Composite(grp, SWT.NONE);
  438. auto gl = new GridLayout(row, true);
  439. if (min) gl.verticalSpacing = 2;
  440. comp3.setLayout(gl);
  441. return comp3;
  442. }
  443. class ESListener : SelectionAdapter {
  444. private Button _targ;
  445. this(Button targ) { mixin(S_TRACE);
  446. _targ = targ;
  447. }
  448. override void widgetSelected(SelectionEvent e) { mixin(S_TRACE);
  449. auto radio = cast(Button) e.widget;
  450. if (radio.getSelection()) { mixin(S_TRACE);
  451. _targ.setSelection(false);
  452. }
  453. }
  454. };
  455. void constructResist(CTabFolder tabf) { mixin(S_TRACE);
  456. auto comp = new Composite(tabf, SWT.NONE);
  457. comp.setLayout(new GridLayout(1, false));
  458. Button createC(Composite parent, string name, string desc) { mixin(S_TRACE);
  459. auto comp = new Composite(parent, SWT.NONE);
  460. comp.setLayoutData(new GridData(GridData.FILL_BOTH));
  461. comp.setLayout(zeroGridLayout(2, false));
  462. auto c = new Button(comp, SWT.CHECK);
  463. mod(c);
  464. c.setEnabled(!_readOnly);
  465. auto cgd = new GridData(GridData.FILL_HORIZONTAL);
  466. cgd.horizontalSpan = 2;
  467. c.setLayoutData(cgd);
  468. c.setText(name);
  469. auto dummy = new Composite(comp, SWT.NONE);
  470. auto dgd = new GridData;
  471. dgd.widthHint = 20;
  472. dgd.heightHint = 0;
  473. dummy.setLayoutData(dgd);
  474. auto l = new Label(comp, SWT.NONE);
  475. l.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
  476. l.setText(desc);
  477. return c;
  478. }
  479. { mixin(S_TRACE);
  480. Composite tcomp, bcomp;
  481. { mixin(S_TRACE);
  482. tcomp = createButtonGroup(comp, _prop.msgs.tolerantBase, 2, 1);
  483. auto gl = cast(GridLayout) tcomp.getLayout();
  484. gl.horizontalSpacing = 15;
  485. _resW = createC(tcomp, _prop.msgs.resistWeapon, _prop.msgs.descResistWeapon);
  486. _resM = createC(tcomp, _prop.msgs.resistMagic, _prop.msgs.descResistMagic);
  487. }
  488. { mixin(S_TRACE);
  489. bcomp = createButtonGroup(comp, _prop.msgs.tolerantElement, 2, 1);
  490. auto gl = cast(GridLayout) bcomp.getLayout();
  491. gl.horizontalSpacing = 15;
  492. _undead = createC(bcomp, _prop.msgs.undead, _prop.msgs.descUndead);
  493. _automaton = createC(bcomp, _prop.msgs.automaton, _prop.msgs.descAutomaton);
  494. _unholy = createC(bcomp, _prop.msgs.unholy, _prop.msgs.descUnholy);
  495. _constructure = createC(bcomp, _prop.msgs.constructure, _prop.msgs.descConstructure);
  496. foreach (e; [Element.FIRE, Element.ICE]) { mixin(S_TRACE);
  497. string eName = _prop.msgs.elementName(e);
  498. auto res = createC(bcomp, .tryFormat(_prop.msgs.resistText, eName), .tryFormat(_prop.msgs.descResist, eName));
  499. auto weak = createC(bcomp, .tryFormat(_prop.msgs.weaknessText, eName), .tryFormat(_prop.msgs.descWeakness, eName));
  500. res.addSelectionListener(new ESListener(weak));
  501. weak.addSelectionListener(new ESListener(res));
  502. _res[e] = res;
  503. _weak[e] = weak;
  504. }
  505. }
  506. auto ts = tcomp.computeSize(SWT.DEFAULT, SWT.DEFAULT);
  507. auto bs = bcomp.computeSize(SWT.DEFAULT, SWT.DEFAULT);
  508. int maxW = ts.x > bs.x ? ts.x : bs.x;
  509. ts.x = maxW;
  510. bs.x = maxW;
  511. tcomp.setLayoutData(ts);
  512. bcomp.setLayoutData(bs);
  513. }
  514. { mixin(S_TRACE);
  515. auto basic = new Button(comp, SWT.PUSH);
  516. mod(basic);
  517. basic.setEnabled(!_readOnly);
  518. basic.setText(_prop.msgs.basicResist);
  519. basic.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
  520. basic.addSelectionListener(new BasicResist);
  521. }
  522. auto tab = new CTabItem(tabf, SWT.NONE);
  523. tab.setText(_prop.msgs.tolerant);
  524. tab.setControl(comp);
  525. }
  526. static immutable PHYSICALS = [Physical.DEX, Physical.AGL, Physical.INT,
  527. Physical.STR, Physical.VIT, Physical.MIN];
  528. void initPhysical() { mixin(S_TRACE);
  529. int[] values = [];
  530. if (_phyR) { mixin(S_TRACE);
  531. values = _phyR.getValues();
  532. _phyR.dispose();
  533. _phyR = null;
  534. }
  535. if (_phyS) { mixin(S_TRACE);
  536. values = _phyS.getValues();
  537. _phyS.dispose();
  538. _phyS = null;
  539. }
  540. string[] names;
  541. names.length = PHYSICALS.length;
  542. int[Physical] table;
  543. foreach (i, p; PHYSICALS) { mixin(S_TRACE);
  544. table[p] = i;
  545. names[i] = _prop.msgs.physicalName(p);
  546. }
  547. _phyTbl = table;
  548. int page = _prop.var.etc.physicalMax / 5;
  549. if (_prop.var.etc.radarStyleParams) { mixin(S_TRACE);
  550. _phyR = new RadarSpinner(_phyParent, _readOnly);
  551. _phyR.setRadar(_prop.var.etc.physicalMax + 1, names, 0);
  552. _phyR.antialias = true;
  553. _phyR.borderlines = cast(int[]) _prop.looks.physicalBorders;
  554. _phyR.lineStep = page;
  555. if (values.length) _phyR.setValues(values);
  556. mod(_phyR);
  557. _phyR.modEvent ~= &modPhysical;
  558. } else { mixin(S_TRACE);
  559. _phyS = new Scales(_phyParent, _readOnly);
  560. _phyS.setScales(_prop.var.etc.physicalMax + 1, names, page, 0);
  561. _phyS.borderlines = cast(int[]) _prop.looks.physicalBorders;
  562. if (values.length) _phyS.setValues(values);
  563. mod(_phyS);
  564. _phyS.modEvent ~= &modPhysical;
  565. }
  566. _phyParent.layout();
  567. }
  568. void modPhysical() { mixin(S_TRACE);
  569. int[] vals;
  570. if (_phyR) vals = _phyR.getValues();
  571. if (_phyS) vals = _phyS.getValues();
  572. int sum = 0;
  573. foreach (val; vals) { mixin(S_TRACE);
  574. sum += val;
  575. }
  576. _sumPhy.setText(.tryFormat(_prop.msgs.physicalSum, sum));
  577. }
  578. void constructPhysical(CTabFolder tabf) { mixin(S_TRACE);
  579. auto comp = new Composite(tabf, SWT.NONE);
  580. comp.setLayout(new GridLayout(2, false));
  581. { mixin(S_TRACE);
  582. auto grp = new Group(comp, SWT.NONE);
  583. grp.setText(_prop.msgs.physicalParams);
  584. auto gd = new GridData(GridData.FILL_BOTH);
  585. gd.horizontalSpan = 2;
  586. grp.setLayoutData(gd);
  587. auto cl = new CenterLayout;
  588. cl.fillHorizontal = true;
  589. cl.fillVertical = true;
  590. grp.setLayout(cl);
  591. _phyParent = grp;
  592. initPhysical();
  593. }
  594. { mixin(S_TRACE);
  595. _sumPhy = new Label(comp, SWT.NONE);
  596. _sumPhy.setLayoutData(new GridData(GridData.FILL_HORIZONTAL|GridData.HORIZONTAL_ALIGN_BEGINNING));
  597. }
  598. { mixin(S_TRACE);
  599. auto basic = new Button(comp, SWT.PUSH);
  600. mod(basic);
  601. basic.setEnabled(!_readOnly);
  602. basic.setText(_prop.msgs.physicalCalc);
  603. basic.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
  604. basic.addSelectionListener(new CalcPhysical);
  605. }
  606. auto tab = new CTabItem(tabf, SWT.NONE);
  607. tab.setText(_prop.msgs.physicalParams);
  608. tab.setControl(comp);
  609. }
  610. real calcPhy(E)(in Skin skin, Physical phy, Button[E] radios, bool all) { mixin(S_TRACE);
  611. real r = 0.0;
  612. foreach (e, radio; radios) { mixin(S_TRACE);
  613. if (radio.getSelection()) { mixin(S_TRACE);
  614. r += skin.physicalMod(e, phy);
  615. if (!all) break;
  616. }
  617. }
  618. return r;
  619. }
  620. class CalcPhysical : SelectionAdapter {
  621. override void widgetSelected(SelectionEvent e) { mixin(S_TRACE);
  622. real[Physical] p;
  623. int[Physical] min;
  624. int[Physical] max;
  625. auto race = selectedRace;
  626. foreach (phy; _phyTbl.keys) { mixin(S_TRACE);
  627. int pmin = _prop.looks.physicalCutMin;
  628. int pmax;
  629. if (race) { mixin(S_TRACE);
  630. int v = race.physical(phy);
  631. pmax = v + _prop.looks.physicalCutMaxBase;
  632. if (pmax > _prop.var.etc.physicalMax) pmax = _prop.var.etc.physicalMax;
  633. if (v < pmin) pmin = v;
  634. p[phy] = v;
  635. } else { mixin(S_TRACE);
  636. int v = _prop.looks.physicalNormal;
  637. pmax = v + _prop.looks.physicalCutMaxBase;
  638. p[phy] = v;
  639. }
  640. min[phy] = pmin;
  641. max[phy] = pmax;
  642. }
  643. foreach (phy, val; p) { mixin(S_TRACE);
  644. val += calcPhy!(Sex)(summSkin, phy, _sex, false);
  645. val += calcPhy!(Period)(summSkin, phy, _period, false);
  646. val += calcPhy!(Nature)(summSkin, phy, _nature, false);
  647. val += calcPhy!(Makings)(summSkin, phy, _makings, true);
  648. p[phy] = val;
  649. }
  650. int[] vals;
  651. vals.length = p.length;
  652. foreach (phy, val; p) { mixin(S_TRACE);
  653. int v = cast(int) val;
  654. if (v < min[phy]) v = min[phy];
  655. if (v > max[phy]) v = max[phy];
  656. vals[_phyTbl[phy]] = v;
  657. }
  658. if (_phyR) { mixin(S_TRACE);
  659. _phyR.setValues(vals);
  660. } else { mixin(S_TRACE);
  661. _phyS.setValues(vals);
  662. }
  663. modPhysical();
  664. }
  665. }
  666. void constructMental(CTabFolder tabf) { mixin(S_TRACE);
  667. auto comp = new Composite(tabf, SWT.NONE);
  668. comp.setLayout(new GridLayout(1, false));
  669. { mixin(S_TRACE);
  670. auto grp = new Group(comp, SWT.NONE);
  671. grp.setText(_prop.msgs.mentalParams);
  672. grp.setLayoutData(new GridData(GridData.FILL_BOTH));
  673. auto ggl = new GridLayout(3, false);
  674. ggl.verticalSpacing = 0;
  675. grp.setLayout(ggl);
  676. static const Ms = [Mental.AGGRESSIVE, Mental.CHEERFUL, Mental.BRAVE,
  677. Mental.CAUTIOUS, Mental.TRICKISH];
  678. foreach (m; Ms) { mixin(S_TRACE);
  679. auto minl = new Label(grp, SWT.NONE);
  680. minl.setText(_prop.msgs.mentalName(reverseMental(m)));
  681. auto scale = new Scale(grp, SWT.NONE);
  682. mod(scale);
  683. scale.setEnabled(!_readOnly);
  684. scale.setLayoutData(new GridData(GridData.FILL_BOTH));
  685. scale.setMaximum(_prop.var.etc.mentalMax * 2);
  686. scale.setMinimum(0);
  687. scale.setIncrement(1);
  688. scale.setPageIncrement(_prop.var.etc.mentalMax);
  689. auto maxl = new Label(grp, SWT.NONE);
  690. maxl.setText(_prop.msgs.mentalName(m));
  691. _mtl[m] = scale;
  692. }
  693. }
  694. { mixin(S_TRACE);
  695. auto basic = new Button(comp, SWT.PUSH);
  696. mod(basic);
  697. basic.setEnabled(!_readOnly);
  698. basic.setText(_prop.msgs.mentalCalc);
  699. basic.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
  700. basic.addSelectionListener(new CalcMental);
  701. }
  702. auto tab = new CTabItem(tabf, SWT.NONE);
  703. tab.setText(_prop.msgs.mentalParams);
  704. tab.setControl(comp);
  705. }
  706. real calcMtl(E)(in Skin skin, Mental mtl, Button[E] radios, bool all) { mixin(S_TRACE);
  707. real r = 0.0;
  708. foreach (e, radio; radios) { mixin(S_TRACE);
  709. if (radio.getSelection()) { mixin(S_TRACE);
  710. r += skin.mentalMod(e, mtl);
  711. if (!all) break;
  712. }
  713. }
  714. return r;
  715. }
  716. class CalcMental : SelectionAdapter {
  717. override void widgetSelected(SelectionEvent e) { mixin(S_TRACE);
  718. auto race = selectedRace;
  719. foreach (mtl, scale; _mtl) { mixin(S_TRACE);
  720. int min = cast(int) _prop.looks.mentalCut * -1;
  721. int max = _prop.looks.mentalCut;
  722. real val;
  723. if (race) { mixin(S_TRACE);
  724. int ival = race.mental(mtl);
  725. val = ival;
  726. if (ival < min) min = ival;
  727. if (ival > max) max = ival;
  728. } else { mixin(S_TRACE);
  729. val = 0.0;
  730. }
  731. val += calcMtl!(Sex)(summSkin, mtl, _sex, false);
  732. val += calcMtl!(Period)(summSkin, mtl, _period, false);
  733. val += calcMtl!(Nature)(summSkin, mtl, _nature, false);
  734. val += calcMtl!(Makings)(summSkin, mtl, _makings, true);
  735. int v = cast(int) val;
  736. if (v < min) v = min;
  737. if (v > max) v = max;
  738. scale.setSelection(v + _prop.var.etc.mentalMax);
  739. }
  740. }
  741. }
  742. static immutable ENHANCE = [Enhance.AVOID, Enhance.RESIST, Enhance.DEFENSE];
  743. void initEnhance() { mixin(S_TRACE);
  744. int[] values = [];
  745. if (_enhR) { mixin(S_TRACE);
  746. values = _enhR.getValues();
  747. _enhR.dispose();
  748. _enhR = null;
  749. }
  750. if (_enhS) { mixin(S_TRACE);
  751. values = _enhS.getValues();
  752. _enhS.dispose();
  753. _enhS = null;
  754. }
  755. string[] names;
  756. names.length = ENHANCE.length;
  757. foreach (i, enh; ENHANCE) { mixin(S_TRACE);
  758. _enhTbl[enh] = i;
  759. names[i] = .tryFormat(_prop.msgs.enhanceBonus, _prop.msgs.enhanceName(enh));
  760. }
  761. int stepC = _prop.var.etc.enhanceMax * 2 + 1;
  762. int min = cast(int) _prop.var.etc.enhanceMax * -1;
  763. int page = _prop.var.etc.enhanceMax / 2;
  764. if (_prop.var.etc.radarStyleParams) { mixin(S_TRACE);
  765. _enhR = new RadarSpinner(_enhParent, _readOnly);
  766. _enhR.setRadar(stepC, names, min);
  767. _enhR.antialias = true;
  768. _enhR.borderlines = [0];
  769. _enhR.lineStep = page;
  770. if (values.length) _enhR.setValues(values);
  771. mod(_enhR);
  772. } else { mixin(S_TRACE);
  773. _enhS = new Scales(_enhParent, _readOnly);
  774. _enhS.setScales(stepC, names, page, min);
  775. _enhS.borderlines = [0];
  776. if (values.length) _enhS.setValues(values);
  777. mod(_enhS);
  778. }
  779. _enhParent.layout();
  780. }
  781. void constructEnhance(CTabFolder tabf) { mixin(S_TRACE);
  782. auto comp = new Composite(tabf, SWT.NONE);
  783. comp.setLayout(new GridLayout(1, false));
  784. { mixin(S_TRACE);
  785. auto grp = new Group(comp, SWT.NONE);
  786. grp.setText(_prop.msgs.castEnhance);
  787. grp.setLayoutData(new GridData(GridData.FILL_BOTH));
  788. auto cl = new CenterLayout;
  789. cl.fillHorizontal = true;
  790. cl.fillVertical = true;
  791. grp.setLayout(cl);
  792. _enhParent = grp;
  793. initEnhance();
  794. }
  795. { mixin(S_TRACE);
  796. auto basic = new Button(comp, SWT.PUSH);
  797. mod(basic);
  798. basic.setEnabled(!_readOnly);
  799. basic.setText(_prop.msgs.basicEnhance);
  800. basic.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
  801. basic.addSelectionListener(new BasicEnhance);
  802. }
  803. auto tab = new CTabItem(tabf, SWT.NONE);
  804. tab.setText(_prop.msgs.castEnhance);
  805. tab.setControl(comp);
  806. }
  807. void constructStatus(CTabFolder tabf) { mixin(S_TRACE);
  808. auto comp = new Composite(tabf, SWT.NONE);
  809. comp.setLayout(new GridLayout(1, false));
  810. Label[] lbls1, lbls2;
  811. Composite[] spns;
  812. Spinner createSpn(Composite comp) { mixin(S_TRACE);
  813. // ???Composite???????Spinner#computeSize()?????????
  814. Composite comp2 = new Composite(comp, SWT.NONE);
  815. comp2.setLayout(new FillLayout);
  816. auto spn = new Spinner(comp2, SWT.BORDER | _readOnly);
  817. initSpinner(spn);
  818. mod(spn);
  819. spns ~= comp2;
  820. return spn;
  821. }
  822. Composite createGrp(string text) { mixin(S_TRACE);
  823. auto grp = new Group(comp, SWT.NONE);
  824. grp.setLayoutData(new GridData(GridData.FILL_BOTH));
  825. auto gl = new GridLayout(2, false);
  826. gl.horizontalSpacing = 15;
  827. grp.setLayout(gl);
  828. grp.setText(text);
  829. return grp;
  830. }
  831. Composite createComp(Composite grp) { mixin(S_TRACE);
  832. auto comp2 = new Composite(grp, SWT.NONE);
  833. comp2.setLayoutData(new GridData(GridData.FILL_BOTH));
  834. auto rl = new RowLayout(SWT.HORIZONTAL);
  835. rl.center = true;
  836. rl.marginLeft = 0;
  837. rl.marginRight = 0;
  838. rl.marginTop = 0;
  839. rl.marginBottom = 0;
  840. comp2.setLayout(rl);
  841. return comp2;
  842. }
  843. { mixin(S_TRACE);
  844. auto grp = createGrp(_prop.msgs.lifeAndMentality);
  845. { mixin(S_TRACE);
  846. auto comp2 = createComp(grp);
  847. auto l = new Label(comp2, SWT.NONE);
  848. l.setText(_prop.msgs.life);
  849. lbls1 ~= l;
  850. _life = new Spinner(comp2, SWT.BORDER | _readOnly);
  851. initSpinner(_life);
  852. mod(_life);
  853. _lifeUseMax = new Button(comp2, SWT.CHECK);
  854. mod(_lifeUseMax);
  855. _lifeUseMax.setEnabled(!_readOnly);
  856. _lifeUseMax.setText(_prop.msgs.useMax);
  857. _lifeUseMax.addSelectionListener(new LifeUseMax);
  858. }
  859. { mixin(S_TRACE);
  860. auto comp2 = createComp(grp);
  861. auto lm = new Label(comp2, SWT.NONE);
  862. lm.setText(_prop.msgs.mentality);
  863. lbls1 ~= lm;
  864. _mtly = new Combo(comp2, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY);
  865. mod(_mtly);
  866. _mtly.setEnabled(!_readOnly);
  867. _mtly.setVisibleItemCount(_prop.var.etc.comboVisibleItemCount);
  868. foreach (i, mtly; [Mentality.NORMAL, Mentality.SLEEP, Mentality.CONFUSE,
  869. Mentality.OVERHEAT, Mentality.BRAVE, Mentality.PANIC]) { mixin(S_TRACE);
  870. _mtly.add(_prop.msgs.mentalityName(mtly));
  871. _mtlyTbl[i] = mtly;
  872. if (_card && _card.mentality is mtly) { mixin(S_TRACE);
  873. _mtly.select(i);
  874. }
  875. }
  876. if (_mtly.getSelectionIndex() < 0) _mtly.select(0);
  877. _mtly.addSelectionListener(new SelMentality);
  878. _mtlyRound = createSpn(comp2);
  879. _mtlyRound.setMaximum(_prop.var.etc.roundMax);
  880. _mtlyRound.setMinimum(Motion.round_min);
  881. spns ~= _mtlyRound;
  882. auto lm2 = new Label(comp2, SWT.NONE);
  883. lm2.setText(_prop.msgs.unitRound);
  884. }
  885. }
  886. { mixin(S_TRACE);
  887. auto grp = createGrp(_prop.msgs.enhanceLiveBonus);
  888. foreach (enh; [Enhance.ACTION, Enhance.AVOID, Enhance.RESIST, Enhance.DEFENSE]) { mixin(S_TRACE);
  889. auto comp2 = createComp(grp);
  890. auto l = new Label(comp2, SWT.NONE);
  891. l.setText(_prop.msgs.enhanceLiveBonusName(enh));
  892. lbls1 ~= l;
  893. auto spn = createSpn(comp2);
  894. spn.setMaximum(_prop.var.etc.enhanceMax);
  895. spn.setMinimum(-(cast(int) _prop.var.etc.enhanceMax));
  896. spns ~= spn;
  897. _liveEnh[enh] = spn;
  898. auto rnd = createSpn(comp2);
  899. rnd.setMaximum(_prop.var.etc.roundMax);
  900. rnd.setMinimum(Motion.round_min);
  901. spns ~= rnd;
  902. _enhRound[enh] = rnd;
  903. auto l2 = new Label(comp2, SWT.NONE);
  904. l2.setText(_prop.msgs.unitRound);
  905. spn.addSelectionListener(new LiveEnh);
  906. }
  907. }
  908. Spinner createStSpn(Composite grp, string name, uint max, string val) { mixin(S_TRACE);
  909. auto comp2 = createComp(grp);
  910. auto l = new Label(comp2, SWT.NONE);
  911. l.setText(name);
  912. lbls1 ~= l;
  913. auto spn = createSpn(comp2);
  914. spn.setMaximum(max);
  915. spn.setMinimum(0);
  916. spns ~= spn;
  917. auto l2 = new Label(comp2, SWT.NONE);
  918. l2.setText(val);
  919. lbls2 ~= l2;
  920. return spn;
  921. }
  922. { mixin(S_TRACE);
  923. auto grp = createGrp(_prop.msgs.status);
  924. _paralyze = createStSpn(grp, _prop.msgs.paralyze, _prop.var.etc.paralyzeMax, _prop.msgs.unitValue);
  925. _poison = createStSpn(grp, _prop.msgs.poison, _prop.var.etc.poisonMax, _prop.msgs.unitValue);
  926. _bind = createStSpn(grp, _prop.msgs.bind, _prop.var.etc.roundMax, _prop.msgs.unitRound);
  927. _silence = createStSpn(grp, _prop.msgs.silence, _prop.var.etc.roundMax, _prop.msgs.unitRound);
  928. _faceUp = createStSpn(grp, _prop.msgs.faceUp, _prop.var.etc.roundMax, _prop.msgs.unitRound);
  929. _antiMagic = createStSpn(grp, _prop.msgs.antiMagic, _prop.var.etc.roundMax, _prop.msgs.unitRound);
  930. }
  931. void setlblw(Control[] lbls) { mixin(S_TRACE);
  932. int maxW = 0;
  933. foreach (lbl; lbls) { mixin(S_TRACE);
  934. int w = lbl.computeSize(SWT.DEFAULT, SWT.DEFAULT).x;
  935. if (maxW < w) maxW = w;
  936. }
  937. foreach (lbl; lbls) { mixin(S_TRACE);
  938. auto gd = new RowData(maxW, SWT.DEFAULT);
  939. lbl.setLayoutData(gd);
  940. }
  941. }
  942. setlblw(cast(Control[]) lbls1);
  943. setlblw(cast(Control[]) lbls2);
  944. setlblw(cast(Control[]) spns);
  945. { mixin(S_TRACE);
  946. auto reset = new Button(comp, SWT.PUSH);
  947. mod(reset);
  948. reset.setEnabled(!_readOnly);
  949. reset.setText(_prop.msgs.resetLiveStatus);
  950. reset.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
  951. reset.addSelectionListener(new ResetLiveStatus);
  952. }
  953. auto tab = new CTabItem(tabf, SWT.NONE);
  954. tab.setText(_prop.msgs.liveStatus);
  955. tab.setControl(comp);
  956. }
  957. class LiveEnh : SelectionAdapter {
  958. override void widgetSelected(SelectionEvent e) { mixin(S_TRACE);
  959. changeLiveEnhance();
  960. }
  961. }
  962. class SelMentality : SelectionAdapter {
  963. override void widgetSelected(SelectionEvent e) { mixin(S_TRACE);
  964. changeMentality();
  965. }
  966. }
  967. class LifeUseMax : SelectionAdapter {
  968. override void widgetSelected(SelectionEvent e) { mixin(S_TRACE);
  969. changeLifeUseMax();
  970. }
  971. }
  972. class ResetLiveStatus : SelectionAdapter {
  973. override void widgetSelected(SelectionEvent e) { mixin(S_TRACE);
  974. resetLiveStatus();
  975. }
  976. }
  977. void changeLiveEnhance() { mixin(S_TRACE);
  978. foreach (enh, spn; _liveEnh) { mixin(S_TRACE);
  979. _enhRound[enh].setEnabled(!_readOnly && spn.getSelection() != 0);
  980. }
  981. }
  982. void changeMentality() { mixin(S_TRACE);
  983. _mtlyRound.setEnabled(!_readOnly && _mtly.getSelectionIndex() != 0);
  984. }
  985. void changeLifeUseMax() { mixin(S_TRACE);
  986. _life.setEnabled(!_readOnly && !_lifeUseMax.getSelection());
  987. }
  988. void resetLiveStatus() { mixin(S_TRACE);
  989. _life.setSelection(_lifeMax.getSelection());
  990. _lifeUseMax.setSelection(true);
  991. foreach (enh, spn; _liveEnh) { mixin(S_TRACE);
  992. spn.setSelection(0);
  993. }
  994. foreach (enh, spn; _enhRound) { mixin(S_TRACE);
  995. spn.setSelection(0);
  996. }
  997. _paralyze.setSelection(0);
  998. _poison.setSelection(0);
  999. _bind.setSelection(0);
  1000. _silence.setSelection(0);
  1001. _faceUp.setSelection(0);
  1002. _antiMagic.setSelection(0);
  1003. _mtly.select(0);
  1004. _mtlyRound.setSelection(0);
  1005. changeLiveEnhance();
  1006. changeMentality();
  1007. changeLifeUseMax();
  1008. }
  1009. void delCard(CastCard c) { mixin(S_TRACE);
  1010. if (_card is c) { mixin(S_TRACE);
  1011. forceCancel();
  1012. }
  1013. }
  1014. void refScenario(Summary summ) { mixin(S_TRACE);
  1015. forceCancel();
  1016. }
  1017. class Dispose : DisposeListener {
  1018. override void widgetDisposed(DisposeEvent e) { mixin(S_TRACE);
  1019. _comm.refRadarStyle.remove(&initPhysical);
  1020. _comm.refRadarStyle.remove(&initEnhance);
  1021. _comm.delCast.remove(&delCard);
  1022. _comm.refScenario.remove(&refScenario);
  1023. _comm.refSkin.remove(&refSkin);
  1024. _comm.refCoupons.remove(&updateNature);
  1025. }
  1026. }
  1027. void refSkin() { mixin(S_TRACE);
  1028. _desc.font = dwtData(_prop.looks.cardDescFont(_summ.legacy));
  1029. refreshRace();
  1030. refreshSex();
  1031. refreshPeriod();
  1032. refreshNature();
  1033. refreshMakings();
  1034. }
  1035. void refreshRace() { mixin(S_TRACE);
  1036. _race.setEnabled(!_readOnly && !_summ.legacy);
  1037. }
  1038. void refreshSex() { mixin(S_TRACE);
  1039. foreach (s, b; _sex) { mixin(S_TRACE);
  1040. auto name = summSkin.sexName(s);
  1041. b.setText(_prop.msgs.sex.get(name, name));
  1042. }
  1043. }
  1044. void refreshPeriod() { mixin(S_TRACE);
  1045. foreach (p, b; _period) { mixin(S_TRACE);
  1046. auto name = summSkin.periodName(p);
  1047. b.setText(_prop.msgs.period.get(name, name));
  1048. }
  1049. }
  1050. void refreshNature() { mixin(S_TRACE);
  1051. foreach (n, b; _nature) { mixin(S_TRACE);
  1052. auto name = summSkin.natureName(n);
  1053. b.setText(_prop.msgs.nature.get(name, name));
  1054. }
  1055. }
  1056. void refreshMakings() { mixin(S_TRACE);
  1057. foreach (m, b; _makings) { mixin(S_TRACE);
  1058. auto name = summSkin.makingsName(m);
  1059. b.setText(_prop.msgs.makings.get(name, name));
  1060. }
  1061. }
  1062. void updateNature() { mixin(S_TRACE);
  1063. if (getShell().isVisible()) getShell().setRedraw(false);
  1064. scope (exit) {
  1065. if (getShell().isVisible()) getShell().setRedraw(true);
  1066. }
  1067. bool first = (0 == _natureComp.getChildren().length);
  1068. string nature = "";
  1069. if (first || _showSpNature != _prop.var.etc.showSpNature) { mixin(S_TRACE);
  1070. foreach (n, b; _nature) { mixin(S_TRACE);
  1071. if (b.getSelection()) { mixin(S_TRACE);
  1072. nature = summSkin.natureCoupon(n);
  1073. break;
  1074. }
  1075. }
  1076. foreach (chld; _natureComp.getChildren()) { mixin(S_TRACE);
  1077. chld.dispose();
  1078. }
  1079. typeof(_nature) tbl;
  1080. _nature = tbl;
  1081. bool selected = false;
  1082. void sep() { mixin(S_TRACE);
  1083. auto sep = new Label(_natureComp, SWT.SEPARATOR | SWT.HORIZONTAL);
  1084. auto gd = new GridData(GridData.FILL_HORIZONTAL);
  1085. gd.horizontalSpan = 2;
  1086. sep.setLayoutData(gd);
  1087. }
  1088. void put(Nature n) { mixin(S_TRACE);
  1089. auto name = summSkin.natureName(n);
  1090. auto b = createR(_natureComp, _prop.msgs.nature.get(name, name), (_nature.length + 1) % 2);
  1091. _nature[n] = b;
  1092. if (!first && nature == summSkin.natureCoupon(n)) { mixin(S_TRACE);
  1093. b.setSelection(true);
  1094. selected = true;
  1095. }
  1096. }
  1097. foreach (n; NATURE_DEF) { mixin(S_TRACE);
  1098. put(n);
  1099. }
  1100. if (_prop.var.etc.showSpNature) { mixin(S_TRACE);
  1101. sep();
  1102. foreach (n; NATURE_EXT) { mixin(S_TRACE);
  1103. put(n);
  1104. }
  1105. }
  1106. sep();
  1107. _natureU = createR(_natureComp, _prop.msgs.natureUnknown, 1);
  1108. if (!first && !selected) { mixin(S_TRACE);
  1109. _natureU.setSelection(true);
  1110. selected = true;
  1111. }
  1112. }
  1113. if (!first && _showSpNature != _prop.var.etc.showSpNature) { mixin(S_TRACE);
  1114. _showSpNature = _prop.var.etc.showSpNature;
  1115. _natureComp.layout(true);
  1116. _natureComp.getParent().layout(true);
  1117. _natureComp.getParent().getParent().layout(true);
  1118. if (_showSpNature) { mixin(S_TRACE);
  1119. if (_natureU.getSelection()) { mixin(S_TRACE);
  1120. cp: foreach (i, cp; _couponView.coupons) { mixin(S_TRACE);
  1121. if (0 == cp.value) { mixin(S_TRACE);
  1122. foreach (n; NATURE_EXT) { mixin(S_TRACE);
  1123. if (cp.name == summSkin.natureCoupon(n)) { mixin(S_TRACE);
  1124. _nature[n].setSelection(true);
  1125. _natureU.setSelection(false);
  1126. _couponView.delCoupon(i);
  1127. break cp;
  1128. }
  1129. }
  1130. }
  1131. }
  1132. }
  1133. } else { mixin(S_TRACE);
  1134. if (_natureU.getSelection() && "" != nature) { mixin(S_TRACE);
  1135. _couponView.addCoupon(new Coupon(nature, 0));
  1136. }
  1137. }
  1138. }
  1139. }
  1140. public:
  1141. this(Commons comm, Props prop, Shell shell, Summary summ, CastCard card, bool readOnly) { mixin(S_TRACE);
  1142. assert (summ !is null);
  1143. _id = format("%08X", &this) ~ "-" ~ to!(string)(Clock.currTime());
  1144. _comm = comm;
  1145. _summ = summ;
  1146. _card = card;
  1147. _prop = prop;
  1148. _readOnly = readOnly ? SWT.READ_ONLY : SWT.NONE;
  1149. if (_readOnly) _summSkin = findSkin(_comm, _prop, _summ);
  1150. super(prop, shell, _readOnly, false, _card ? .tryFormat(_prop.msgs.dlgTitCast, _card.name) : _prop.msgs.dlgTitNewCast,
  1151. _prop.images.casts, true, _prop.var.castCardDlg, true);
  1152. }
  1153. @property
  1154. CastCard card() { mixin(S_TRACE);
  1155. return _card;
  1156. }
  1157. bool openCWXPath(string path, bool shellActivate) { mixin(S_TRACE);
  1158. return cpempty(path);
  1159. }
  1160. protected:
  1161. override void setup(Composite area) { mixin(S_TRACE);
  1162. area.setLayout(windowGridLayout(1));
  1163. auto tabf = new CTabFolder(area, SWT.BORDER);
  1164. constructBase(tabf);
  1165. constructDesc(tabf);
  1166. constructHistory(tabf);
  1167. constructMakings(tabf);
  1168. constructResist(tabf);
  1169. constructPhysical(tabf);
  1170. constructMental(tabf);
  1171. constructEnhance(tabf);
  1172. constructStatus(tabf);
  1173. _comm.delCast.add(&delCard);
  1174. _comm.refScenario.add(&refScenario);
  1175. _comm.refSkin.add(&refSkin);
  1176. _comm.refCoupons.add(&updateNature);
  1177. _comm.refRadarStyle.add(&initPhysical);
  1178. _comm.refRadarStyle.add(&initEnhance);
  1179. area.addDisposeListener(new Dispose);
  1180. // Windows Vista???????????????????????????
  1181. scope maxSize = new Point(0, 0);
  1182. foreach (tab; tabf.getItems()) { mixin(S_TRACE);
  1183. scope size = tab.getControl().computeSize(SWT.DEFAULT, SWT.DEFAULT);
  1184. if (maxSize.x < size.x) maxSize.x = size.x;
  1185. if (maxSize.y < size.y) maxSize.y = size.y;
  1186. }
  1187. scope rect = tabf.computeTrim(SWT.DEFAULT, SWT.DEFAULT, maxSize.x, maxSize.y);
  1188. auto gd = new GridData(GridData.FILL_BOTH);
  1189. gd.widthHint = rect.width;
  1190. gd.heightHint = rect.height;
  1191. tabf.setLayoutData(gd);
  1192. refCard(_card);
  1193. }
  1194. private void refCard(CastCard card) { mixin(S_TRACE);
  1195. if (_card && _card !is card) return;
  1196. ignoreMod = true;
  1197. scope (exit) ignoreMod = false;
  1198. auto skin = summSkin;
  1199. if (_card) { mixin(S_TRACE);
  1200. _imgPath.image = _card.path;
  1201. if (_race) _race.select(0);
  1202. _desc.setText(_card.desc);
  1203. _name.setText(_card.name);
  1204. _level.setSelection(_card.level);
  1205. _lifeMax.setSelection(_card.lifeMax);
  1206. bool sex = false, period = false, nature = false;
  1207. scope makings = new HashSet!(Makings);
  1208. Coupon[] coupons;
  1209. cp: foreach (c; _card.coupons) { mixin(S_TRACE);
  1210. foreach (s, b; _sex) { mixin(S_TRACE);
  1211. if (c.name == skin.sexCoupon(s)) { mixin(S_TRACE);
  1212. if (!sex) b.setSelection(true);
  1213. sex = true;
  1214. continue cp;
  1215. }
  1216. }
  1217. foreach (per, b; _period) { mixin(S_TRACE);
  1218. if (c.name == skin.periodCoupon(per)) { mixin(S_TRACE);
  1219. if (!period) b.setSelection(true);
  1220. period = true;
  1221. continue cp;
  1222. }
  1223. }
  1224. foreach (nat, b; _nature) { mixin(S_TRACE);
  1225. if (c.name == skin.natureCoupon(nat)) { mixin(S_TRACE);
  1226. if (!nature) b.setSelection(true);
  1227. nature = true;
  1228. continue cp;
  1229. }
  1230. }
  1231. foreach (m, b; _makings) { mixin(S_TRACE);
  1232. if (c.name == skin.makingsCoupon(m)) { mixin(S_TRACE);
  1233. if (!makings.contains(m)) b.setSelection(true);
  1234. makings.add(m);
  1235. continue cp;
  1236. }
  1237. }
  1238. if (_race) { mixin(S_TRACE);
  1239. foreach (i, r; summSkin.races) { mixin(S_TRACE);
  1240. if (c.name == _prop.sys.raceCoupon(r.name)) { mixin(S_TRACE);
  1241. _race.select(i + 1);
  1242. raceToolTip();
  1243. continue cp;
  1244. }
  1245. }
  1246. }
  1247. coupons ~= new Coupon(c);
  1248. }
  1249. _couponView.coupons = coupons;
  1250. if (!sex) _sexU.setSelection(true);
  1251. if (!period) _periodU.setSelection(true);
  1252. if (!nature) _natureU.setSelection(true);
  1253. _resW.setSelection(_card.weaponResist);
  1254. _resM.setSelection(_card.magicResist);
  1255. _undead.setSelection(_card.undead);
  1256. _automaton.setSelection(_card.automaton);
  1257. _unholy.setSelection(_card.unholy);
  1258. _constructure.setSelection(_card.constructure);
  1259. foreach (e, radio; _res) { mixin(S_TRACE);
  1260. radio.setSelection(_card.resist(e));
  1261. }
  1262. foreach (e, radio; _weak) { mixin(S_TRACE);
  1263. radio.setSelection(_card.weakness(e));
  1264. }
  1265. foreach (phy, i; _phyTbl) { mixin(S_TRACE);
  1266. if (_phyR) { mixin(S_TRACE);
  1267. _phyR.setValue(i, _card.physical(phy));
  1268. } else { mixin(S_TRACE);
  1269. _phyS.setValue(i, _card.physical(phy));
  1270. }
  1271. }
  1272. foreach (mtl, scale; _mtl) { mixin(S_TRACE);
  1273. scale.setSelection(_prop.var.etc.mentalMax + _card.mental(mtl));
  1274. }
  1275. foreach (enh, i; _enhTbl) { mixin(S_TRACE);
  1276. if (_enhR) { mixin(S_TRACE);
  1277. _enhR.setValue(i, _card.defaultEnhance(enh));
  1278. } else { mixin(S_TRACE);
  1279. _enhS.setValue(i, _card.defaultEnhance(enh));
  1280. }
  1281. }
  1282. _life.setSelection(_card.life);
  1283. _lifeUseMax.setSelection(_card.life == _card.lifeMax);
  1284. foreach (enh, spn; _liveEnh) { mixin(S_TRACE);
  1285. spn.setSelection(_card.enhance(enh));
  1286. }
  1287. foreach (enh, spn; _enhRound) { mixin(S_TRACE);
  1288. spn.setSelection(_card.enhanceRound(enh));
  1289. }
  1290. _paralyze.setSelection(_card.paralyze);
  1291. _poison.setSelection(_card.poison);
  1292. _bind.setSelection(_card.bindRound);
  1293. _silence.setSelection(_card.silenceRound);
  1294. _faceUp.setSelection(_card.faceUpRound);
  1295. _antiMagic.setSelection(_card.antiMagicRound);
  1296. _mtlyRound.setSelection(_card.mentalityRound);
  1297. changeLiveEnhance();
  1298. changeMentality();
  1299. changeLifeUseMax();
  1300. } else { mixin(S_TRACE);
  1301. _imgPath.image = "";
  1302. if (_race) _race.select(0);
  1303. _sexU.setSelection(true);
  1304. _periodU.setSelection(true);
  1305. _natureU.setSelection(true);
  1306. int[] phys;
  1307. phys.length = PHYSICALS.length;
  1308. phys[] = _prop.looks.physicalNormal;
  1309. if (_phyR) { mixin(S_TRACE);
  1310. _phyR.setValues(phys);
  1311. } else { mixin(S_TRACE);
  1312. _phyS.setValues(phys);
  1313. }
  1314. foreach (radio; _mtl) { mixin(S_TRACE);
  1315. radio.setSelection(_prop.var.etc.mentalMax);
  1316. }
  1317. int[] bonus;
  1318. bonus.length = ENHANCE.length;
  1319. bonus[] = 0;
  1320. if (_enhR) { mixin(S_TRACE);
  1321. _enhR.setValues(bonus);
  1322. } else { mixin(S_TRACE);
  1323. _enhS.setValues(bonus);
  1324. }
  1325. resetLiveStatus();
  1326. }
  1327. setMaxLife();
  1328. modPhysical();
  1329. }
  1330. private Coupon createCoupon(E)(Button[E] radios, string delegate(E) coupon) { mixin(S_TRACE);
  1331. foreach (e, radio; radios) { mixin(S_TRACE);
  1332. if (radio.getSelection()) { mixin(S_TRACE);
  1333. return new Coupon(coupon(e), 0);
  1334. }
  1335. }
  1336. return null;
  1337. }
  1338. override bool apply() { mixin(S_TRACE);
  1339. if (_card) { mixin(S_TRACE);
  1340. _card.path = _imgPath.image;
  1341. _card.desc = _desc.getRRText();
  1342. _card.name = _name.getText();
  1343. _card.level = _level.getSelection();
  1344. _card.lifeMax = _lifeMax.getSelection();
  1345. _card.life = _lifeMax.getSelection();
  1346. } else { mixin(S_TRACE);
  1347. _card = new CastCard(_summ.newId!(CastCard), _name.getText(), _imgPath.image,
  1348. _desc.getRRText(), _level.getSelection(), _lifeMax.getSelection());
  1349. }
  1350. auto skin = summSkin;
  1351. string legacyName = skin.legacyName;
  1352. alias contains!("a.name == b.name", Coupon, Coupon) cContains;
  1353. auto tblCoupons = _couponView.coupons;
  1354. Coupon[] cs;
  1355. auto sex = createCoupon!(Sex)(_sex, &skin.sexCoupon);
  1356. if (sex && !cContains(tblCoupons, sex)) cs ~= sex;
  1357. auto race = selectedRace;
  1358. if (race) { mixin(S_TRACE);
  1359. auto rc = new Coupon(_prop.sys.raceCoupon(race.name), 0);
  1360. if (!cContains(tblCoupons, rc)) cs ~= rc;
  1361. }
  1362. auto period = createCoupon!(Period)(_period, &skin.periodCoupon);
  1363. if (period && !cContains(tblCoupons, period)) cs ~= period;
  1364. auto nature = createCoupon!(Nature)(_nature, &skin.natureCoupon);
  1365. if (nature && !cContains(tblCoupons, nature)) cs ~= nature;
  1366. foreach (m, radio; _makings) { mixin(S_TRACE);
  1367. if (radio.getSelection()) { mixin(S_TRACE);
  1368. auto mc = new Coupon(skin.makingsCoupon(m), 0);
  1369. if (!cContains(tblCoupons, mc)) cs ~= mc;
  1370. }
  1371. }
  1372. cs ~= tblCoupons;
  1373. _card.coupons = cs;
  1374. _card.weaponResist = _resW.getSelection();
  1375. _card.magicResist = _resM.getSelection();
  1376. _card.undead = _undead.getSelection();
  1377. _card.automaton = _automaton.getSelection();
  1378. _card.unholy = _unholy.getSelection();
  1379. _card.constructure = _constructure.getSelection();
  1380. foreach (e, radio; _res) { mixin(S_TRACE);
  1381. _card.resist(e, radio.getSelection());
  1382. }
  1383. foreach (e, radio; _weak) { mixin(S_TRACE);
  1384. _card.weakness(e, radio.getSelection());
  1385. }
  1386. foreach (phy, i; _phyTbl) { mixin(S_TRACE);
  1387. if (_phyR) { mixin(S_TRACE);
  1388. _card.physical(phy, _phyR.getValue(i));
  1389. } else { mixin(S_TRACE);
  1390. _card.physical(phy, _phyS.getValue(i));
  1391. }
  1392. }
  1393. foreach (mtl, scale; _mtl) { mixin(S_TRACE);
  1394. _card.mental(mtl, cast(int) scale.getSelection() - _prop.var.etc.mentalMax);
  1395. }
  1396. foreach (enh, i; _enhTbl) { mixin(S_TRACE);
  1397. if (_enhR) { mixin(S_TRACE);
  1398. _card.defaultEnhance(enh, _enhR.getValue(i));
  1399. } else { mixin(S_TRACE);
  1400. _card.defaultEnhance(enh, _enhS.getValue(i));
  1401. }
  1402. }
  1403. _card.life = _lifeUseMax.getSelection() ? _card.lifeMax : _life.getSelection();
  1404. foreach (enh, spn; _liveEnh) { mixin(S_TRACE);
  1405. if (_enhRound[enh].getSelection() > 0) { mixin(S_TRACE);
  1406. _card.enhance(enh, spn.getSelection());
  1407. } else { mixin(S_TRACE);
  1408. _card.enhance(enh, 0);
  1409. }
  1410. }
  1411. foreach (enh, spn; _enhRound) { mixin(S_TRACE);
  1412. if (_card.enhance(enh) != 0) { mixin(S_TRACE);
  1413. _card.enhanceRound(enh, spn.getSelection());
  1414. } else { mixin(S_TRACE);
  1415. _card.enhanceRound(enh, 0);
  1416. }
  1417. }
  1418. _card.paralyze = _paralyze.getSelection();
  1419. _card.poison = _poison.getSelection();
  1420. _card.bindRound = _bind.getSelection();
  1421. _card.silenceRound = _silence.getSelection();
  1422. _card.faceUpRound = _faceUp.getSelection();
  1423. _card.antiMagicRound = _antiMagic.getSelection();
  1424. _card.mentality = _mtlyRound.getSelection() == 0
  1425. ? Mentality.NORMAL : _mtlyTbl[_mtly.getSelectionIndex()];
  1426. _card.mentalityRound = _card.mentality == Mentality.NORMAL
  1427. ? 0 : _mtlyRound.getSelection();
  1428. _comm.refCoupons.call();
  1429. getShell().setText(.tryFormat(_prop.msgs.dlgTitCast, _card.name));
  1430. return true;
  1431. }
  1432. }