GuiEditorCtrlProperties.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. $currentTarget = "";
  2. // Doing this in script might end up being a waste of time
  3. // but because of the way the current inspector is messing about
  4. // it is needed.
  5. function GuiEditorCtrlProperties::update(%this, %target)
  6. {
  7. // We can only get here from the guiEdit so its definitely a
  8. // gui control, no need to check.
  9. if(%target == 0)
  10. {
  11. GuiEditorCtrlProperties.clear();
  12. $currentTarget = "";
  13. }
  14. else
  15. {
  16. if($currentTarget != %target)
  17. {
  18. %this.build(%target);
  19. }
  20. else
  21. {
  22. // if we are locked update the gui to reflect it.
  23. if($currentTarget.getFieldValue("locked"))
  24. {
  25. $targetprevLocked = true;
  26. %this.build($currentTarget);
  27. }
  28. // if we were prev locked we need to rebuild
  29. else if($targetprevLocked)
  30. {
  31. // just so this isn't always happening
  32. // sometimes we only want to updateValues
  33. %this.build($currentTarget);
  34. $targetprevLocked = false;
  35. }
  36. // update values of fields.
  37. %this.updateValues(%target);
  38. }
  39. }
  40. }
  41. function GuiEditorCtrlProperties::updateValues(%this, %target)
  42. {
  43. // go through every field and updates.
  44. %count = %target.getFieldCount();
  45. for(%i = 0; %i < %count; %i++)
  46. {
  47. %field = %target.getField(%i);
  48. %fieldType = %target.getFieldType(%field);
  49. if(%fieldType $= "Point2I")
  50. {
  51. %fieldVal = %target.getFieldValue(%field);
  52. %fieldEditX = %field @ "editX";
  53. %fieldEditY = %field @ "editY";
  54. %fieldEditX.setText(%fieldVal.x);
  55. %fieldEditY.setText(%fieldVal.y);
  56. }
  57. else if(%fieldType $= "bool")
  58. {
  59. %fieldEdit = %field @ "edit";
  60. %fieldEdit.setStateOn(%target.getFieldValue(%field));
  61. }
  62. else
  63. {
  64. %fieldEdit = %field @ "edit";
  65. %fieldEdit.setText(%target.getFieldValue(%field));
  66. }
  67. }
  68. }
  69. function GuiEditorCtrlProperties::build(%this, %target)
  70. {
  71. // assign target so we can keep track.
  72. $currentTarget = %target;
  73. GuiEditorCtrlProperties.clear();
  74. // every field gets a gui
  75. %count = %target.getFieldCount();
  76. for(%i = 0; %i < %count; %i++)
  77. {
  78. %field = %target.getField(%i);
  79. // we only want the locked field.
  80. if($currentTarget.getFieldValue("locked"))
  81. {
  82. if(%field !$= "locked")
  83. {
  84. continue;
  85. }
  86. }
  87. %fieldCtrl = new GuiControl()
  88. {
  89. extent = "320 30";
  90. horizSizing = "right";
  91. vertSizing = "bottom";
  92. profile = "GuiDefaultProfile";
  93. visible = "1";
  94. };
  95. %fieldLabel = new GuiControl()
  96. {
  97. text = %field @ ": ";
  98. profile = "GuiTextRightProfile";
  99. Position = "10 0";
  100. extent = "150 30";
  101. horizSizing = "right";
  102. vertSizing = "bottom";
  103. visible = "1";
  104. };
  105. %fieldType = %target.getFieldType(%field);
  106. %fieldVal = %target.getFieldValue(%field);
  107. %fieldEdit = %this.buildEdit(%field,%fieldType,%fieldVal);
  108. %fieldCtrl.add(%fieldLabel);
  109. %fieldCtrl.add(%fieldEdit);
  110. GuiEditorCtrlProperties.add(%fieldCtrl);
  111. }
  112. // we don't want dynamic fields either.
  113. if($currentTarget.getFieldValue("locked"))
  114. {
  115. return;
  116. }
  117. // build dynamic fields
  118. %dynCtrl = new GuiPanelCtrl()
  119. {
  120. position = "10 0";
  121. extent = "320 20";
  122. horizSizing = "right";
  123. vertSizing = "bottom";
  124. profile = "GuiPanelProfile";
  125. visible = "1";
  126. Text = "Dynamic Fields";
  127. };
  128. GuiEditorCtrlProperties.add(%dynCtrl);
  129. %addDyn = new GuiControl()
  130. {
  131. Position = "0 20";
  132. extent = "320 30";
  133. horizSizing = "right";
  134. vertSizing = "bottom";
  135. profile = "GuiDefaultProfile";
  136. visible = "1";
  137. };
  138. %label = new GuiControl()
  139. {
  140. text = "Add Dynamic Field";
  141. profile = "GuiTextProfile";
  142. Position = "10 0";
  143. extent = "150 30";
  144. horizSizing = "right";
  145. vertSizing = "bottom";
  146. visible = "1";
  147. };
  148. %bttn = new GuiButtonCtrl()
  149. {
  150. text = "+";
  151. profile = "GuiButtonDynProfile";
  152. Position = "280 0";
  153. extent = "30 30";
  154. Command = "GuiEditorCtrlProperties.addDynamic();";
  155. };
  156. %addDyn.add(%label);
  157. %addDyn.add(%bttn);
  158. %dynCtrl.add(%addDyn);
  159. if(isObject(DynamicContainer))
  160. {
  161. DynamicContainer.clear();
  162. DynamicContainer.delete();
  163. }
  164. %dynChain = new GuiChainCtrl(DynamicContainer)
  165. {
  166. position = "0 50";
  167. extent = "320 30";
  168. };
  169. %dynCtrl.add(%dynChain);
  170. // dynamic fields need to be updated separately.
  171. // eventually should separate fields by group.
  172. GuiEditorCtrlProperties.updateDynamicFields();
  173. }
  174. function GuiEditorCtrlProperties::addDynamic(%this)
  175. {
  176. %name = "dynamicField" @ $currentTarget.getDynamicFieldCount();
  177. $currentTarget.setFieldValue(%name,"defaultValue");
  178. GuiEditorCtrlProperties.updateDynamicFields();
  179. }
  180. function GuiEditorCtrlProperties::removeDynamic(%this, %field)
  181. {
  182. // giving a dynamic field a null value deletes it.
  183. $currentTarget.setFieldValue(%field,"");
  184. GuiEditorCtrlProperties.updateDynamicFields();
  185. }
  186. function GuiEditorCtrlProperties::renameDynamic(%this, %field, %newName, %fieldVal)
  187. {
  188. $currentTarget.setFieldValue(%newName, %fieldVal);
  189. $currentTarget.setFieldValue(%field,"");
  190. GuiEditorCtrlProperties.updateDynamicFields();
  191. }
  192. function GuiEditorCtrlProperties::updateDynamicFields(%this)
  193. {
  194. %count = $currentTarget.getDynamicFieldCount();
  195. DynamicContainer.clear();
  196. for(%i = 0; %i < %count; %i++)
  197. {
  198. %field = $currentTarget.getDynamicField(%i);
  199. %fieldVal = $currentTarget.getFieldValue(%field);
  200. %dynCtrl = new GuiControl()
  201. {
  202. extent = "320 30";
  203. horizSizing = "right";
  204. vertSizing = "bottom";
  205. profile = "GuiDefaultProfile";
  206. visible = "1";
  207. };
  208. %label = new GuiTextEditCtrl()
  209. {
  210. text = %field;
  211. profile = "GuiTextEditProfile";
  212. Position = "10 0";
  213. extent = "130 30";
  214. horizSizing = "right";
  215. vertSizing = "bottom";
  216. visible = "1";
  217. };
  218. %val = new GuiTextEditCtrl()
  219. {
  220. text = %fieldVal;
  221. profile = "GuiTextEditProfile";
  222. Position = "140 0";
  223. extent = "130 30";
  224. horizSizing = "right";
  225. vertSizing = "bottom";
  226. visible = "1";
  227. };
  228. %label.setFieldValue("AltCommand", "GuiEditorCtrlProperties.renameDynamic(" @ %field @ "," @ %label.getId() @ ".getText()," @ %val.getId() @ ".getText());");
  229. %label.setFieldValue("Validate", "GuiEditorCtrlProperties.renameDynamic(" @ %field @ "," @ %label.getId() @ ".getText()," @ %val.getId() @ ".getText());");
  230. %val.setFieldValue("AltCommand", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %val.getId() @ ".getText());");
  231. %val.setFieldValue("Validate", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %val.getId() @ ".getText());");
  232. %bttn = new GuiButtonCtrl()
  233. {
  234. text = "X";
  235. profile = "GuiButtonDynProfile";
  236. Position = "280 0";
  237. extent = "30 30";
  238. };
  239. %bttn.setFieldValue("Command", "GuiEditorCtrlProperties.removeDynamic(" @ %field @ ");");
  240. %dynCtrl.add(%label);
  241. %dynCtrl.add(%val);
  242. %dynCtrl.add(%bttn);
  243. DynamicContainer.add(%dynCtrl);
  244. DynamicContainer.getParent().setExpanded(0);
  245. DynamicContainer.getParent().setExpanded(1);
  246. }
  247. }
  248. function GuiEditorCtrlProperties::setData(%this,%field, %val)
  249. {
  250. $currentTarget.setEditFieldValue(%field, %val);
  251. %this.update($currentTarget);
  252. }
  253. function GuiEditorCtrlProperties::buildEdit(%this,%field,%fieldType,%fieldVal)
  254. {
  255. // items yet to be added:
  256. // filename
  257. // RectI
  258. // assetIdString
  259. // audioAssetPtr
  260. %fieldEdit = %field @ "edit";
  261. echo(%field TAB %fieldType TAB %fieldVal);
  262. switch$(%fieldType)
  263. {
  264. case "float":
  265. %ctrl = new GuiTextEditCtrl(%fieldEdit)
  266. {
  267. Text = %fieldVal;
  268. Position = "160 0";
  269. extent = "160 30";
  270. horizSizing = "right";
  271. vertSizing = "bottom";
  272. visible = "1";
  273. Profile = "GuiTextEditProfile";
  274. };
  275. %ctrl.setFieldValue("AltCommand", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrl.getId() @ ".getText());");
  276. %ctrl.setFieldValue("Validate", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrl.getId() @ ".getText());");
  277. return %ctrl;
  278. case "ColorF":
  279. %ctrl = new GuiTextEditCtrl(%fieldEdit)
  280. {
  281. Text = %fieldVal;
  282. Position = "160 0";
  283. extent = "160 30";
  284. horizSizing = "right";
  285. vertSizing = "bottom";
  286. visible = "1";
  287. Profile = "GuiTextEditProfile";
  288. };
  289. %ctrl.setFieldValue("AltCommand", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrl.getId() @ ".getText());");
  290. %ctrl.setFieldValue("Validate", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrl.getId() @ ".getText());");
  291. return %ctrl;
  292. case "ColorI":
  293. %ctrl = new GuiTextEditCtrl(%fieldEdit)
  294. {
  295. Text = %fieldVal;
  296. Position = "160 0";
  297. extent = "160 30";
  298. horizSizing = "right";
  299. vertSizing = "bottom";
  300. visible = "1";
  301. Profile = "GuiTextEditProfile";
  302. };
  303. %ctrl.setFieldValue("AltCommand", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrl.getId() @ ".getText());");
  304. %ctrl.setFieldValue("Validate", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrl.getId() @ ".getText());");
  305. return %ctrl;
  306. case "SimObjectPtr":
  307. return %ctrl = new GuiControl(%fieldEdit)
  308. {
  309. Text = %fieldVal;
  310. Position = "160 0";
  311. extent = "160 30";
  312. horizSizing = "right";
  313. vertSizing = "bottom";
  314. visible = "1";
  315. Profile = "GuiTextProfile";
  316. };
  317. case "int":
  318. %ctrl = new GuiTextEditCtrl(%fieldEdit)
  319. {
  320. Text = %fieldVal;
  321. Position = "160 0";
  322. extent = "160 30";
  323. horizSizing = "right";
  324. vertSizing = "bottom";
  325. visible = "1";
  326. Profile = "GuiNumberEditProfile";
  327. };
  328. %ctrl.setFieldValue("AltCommand", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrl.getId() @ ".getText());");
  329. %ctrl.setFieldValue("Validate", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrl.getId() @ ".getText());");
  330. return %ctrl;
  331. case "bool":
  332. %ctrl = new GuiCheckBoxCtrl(%fieldEdit)
  333. {
  334. text = "";
  335. stateOn = %fieldVal;
  336. Position = "160 0";
  337. extent = "160 30";
  338. horizSizing = "relative";
  339. vertSizing = "relative";
  340. visible = "1";
  341. Profile = "GuiCheckBoxProfile";
  342. };
  343. %ctrl.setFieldValue("Command", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrl.getId() @ ".getStateOn());");
  344. return %ctrl;
  345. case "Point2I":
  346. return %this.buildPoint2ICtrl(%field,%fieldVal);
  347. case "Point2F":
  348. return %this.buildPoint2ICtrl(%field,%fieldVal);
  349. case "enumval":
  350. %ctrl = new GuiPopUpMenuCtrl(%fieldEdit)
  351. {
  352. text = %fieldVal;
  353. Position = "160 6";
  354. extent = "160 18";
  355. Profile="GuiPopUpMenuProfile2";
  356. HorizSizing="relative";
  357. VertSizing="relative";
  358. maxLength="1024";
  359. maxPopupHeight="200";
  360. bitmapBounds="16 16";
  361. };
  362. %cl = $currentTarget.getClassName();
  363. %ctrl.setEnumContent(%cl, %field);
  364. %ctrl.sort();
  365. %ctrl.setFieldValue("Command", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrl.getId() @ ".getText());");
  366. return %ctrl;
  367. case "GuiProfile":
  368. return %ctrl = %this.buildGuiProfileCtrl(%field, %fieldVal);
  369. default:
  370. // better lazy than complicated.
  371. %ctrl = new GuiTextEditCtrl(%fieldEdit)
  372. {
  373. Text = %fieldVal;
  374. Position = "160 0";
  375. extent = "160 30";
  376. horizSizing = "right";
  377. vertSizing = "bottom";
  378. visible = "1";
  379. Profile = "GuiTextEditProfile";
  380. };
  381. %ctrl.setFieldValue("AltCommand", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrl.getId() @ ".getText());");
  382. %ctrl.setFieldValue("Validate", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrl.getId() @ ".getText());");
  383. return %ctrl;
  384. }
  385. }
  386. function GuiEditorCtrlProperties::buildGuiProfileCtrl(%this,%field,%fieldVal)
  387. {
  388. %fieldEdit = %field @ "edit";
  389. %ctrl = new GuiPopUpMenuCtrl(%fieldEdit)
  390. {
  391. text = %fieldVal;
  392. Position = "160 6";
  393. extent = "160 18";
  394. Profile="GuiPopUpMenuProfile2";
  395. HorizSizing="relative";
  396. VertSizing="relative";
  397. maxLength="1024";
  398. maxPopupHeight="200";
  399. bitmapBounds="16 16";
  400. };
  401. %count = GuiDataGroup.getCount();
  402. for(%i = 0; %i < %count; %i++)
  403. {
  404. %obj = GuiDataGroup.getObject(%i);
  405. if(%obj.getClassName() $= "GuiControlProfile")
  406. {
  407. %cat = %obj.category;
  408. if(%cat !$= "")
  409. {
  410. echo(%cat);
  411. }
  412. if(%obj.getName() !$= "")
  413. {
  414. %ctrl.add(%obj.getName(), 0);
  415. }
  416. }
  417. }
  418. %ctrl.sort();
  419. %ctrl.setFieldValue("Command", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrl.getId() @ ".getText());");
  420. return %ctrl;
  421. }
  422. function GuiEditorCtrlProperties::buildPoint2ICtrl(%this,%field, %fieldVal)
  423. {
  424. %fieldEditX = %field @ "editX";
  425. %fieldEditY = %field @ "editY";
  426. %cont = new GuiControl()
  427. {
  428. extent = "160 30";
  429. Position = "160 0";
  430. horizSizing = "right";
  431. vertSizing = "bottom";
  432. profile = "GuiDefaultProfile";
  433. visible = "1";
  434. };
  435. %xLabel = new GuiControl()
  436. {
  437. text = "x:";
  438. extent = "30 30";
  439. Position = "0 0";
  440. horizSizing = "right";
  441. vertSizing = "bottom";
  442. profile = "GuiTextRightProfile";
  443. visible = "1";
  444. };
  445. %ctrlX = new GuiTextEditCtrl(%fieldEditX)
  446. {
  447. Text = %fieldVal.x;
  448. Position = "30 0";
  449. extent = "50 30";
  450. horizSizing = "right";
  451. vertSizing = "bottom";
  452. visible = "1";
  453. Profile = "GuiTextEditProfile";
  454. };
  455. %yLabel = new GuiControl()
  456. {
  457. text = "y:";
  458. extent = "30 30";
  459. Position = "80 0";
  460. horizSizing = "right";
  461. vertSizing = "bottom";
  462. profile = "GuiTextRightProfile";
  463. visible = "1";
  464. };
  465. %ctrlY = new GuiTextEditCtrl(%fieldEditY)
  466. {
  467. Text = %fieldVal.y;
  468. Position = "110 0";
  469. extent = "50 30";
  470. horizSizing = "right";
  471. vertSizing = "bottom";
  472. visible = "1";
  473. Profile = "GuiTextEditProfile";
  474. };
  475. %ctrlX.setFieldValue("AltCommand", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrlX.getId() @ ".getText() SPC " @ %ctrlY.getId() @ ".getText());");
  476. %ctrlX.setFieldValue("Validate", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrlX.getId() @ ".getText() SPC " @ %ctrlY.getId() @ ".getText());");
  477. %ctrlY.setFieldValue("AltCommand", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrlX.getId() @ ".getText() SPC " @ %ctrlY.getId() @ ".getText());");
  478. %ctrlY.setFieldValue("Validate", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrlX.getId() @ ".getText() SPC " @ %ctrlY.getId() @ ".getText());");
  479. %cont.add(%xLabel);
  480. %cont.add(%ctrlX);
  481. %cont.add(%yLabel);
  482. %cont.add(%ctrlY);
  483. return %cont;
  484. }