guiDropDownCtrl_ScriptBinding.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. ConsoleMethodGroupBeginWithDocs(GuiDropDownCtrl, GuiControl)
  23. /*! Opens the drop down. Does nothing if the drop down is already open.
  24. @return No return value.
  25. */
  26. ConsoleMethodWithDocs(GuiDropDownCtrl, openDropDown, ConsoleVoid, 2, 2, "()")
  27. {
  28. object->openDropDown();
  29. }
  30. /*! Closes the drop down. Does nothing if the drop down is already closed.
  31. @return No return value.
  32. */
  33. ConsoleMethodWithDocs(GuiDropDownCtrl, closeDropDown, ConsoleVoid, 2, 2, "()")
  34. {
  35. object->closeDropDown();
  36. }
  37. /*! Removes all items from the listbox.
  38. @return No return value.
  39. */
  40. ConsoleMethodWithDocs(GuiDropDownCtrl, clearItems, ConsoleVoid, 2, 2, "()")
  41. {
  42. object->getList()->clearItems();
  43. }
  44. /*! Unselects any items that have been selected.
  45. @return No return value.
  46. */
  47. ConsoleMethodWithDocs(GuiDropDownCtrl, clearSelection, ConsoleVoid, 2, 2, "()")
  48. {
  49. object->getList()->clearSelection();
  50. }
  51. /*! Sets an item to selected or unselected using an index.
  52. @param index The zero-based index of the item that should be selected.
  53. @param isSelected If true, the item is selected. If false, it is unselected. If omitted, will default to true.
  54. @return No return value.
  55. */
  56. ConsoleMethodWithDocs(GuiDropDownCtrl, setSelected, ConsoleVoid, 3, 4, "(S32 index, [bool isSelected])")
  57. {
  58. bool value = true;
  59. if (argc == 4)
  60. value = dAtob(argv[3]);
  61. if (value == true)
  62. object->getList()->addSelection(dAtoi(argv[2]));
  63. else
  64. object->getList()->removeSelection(dAtoi(argv[2]));
  65. }
  66. /*! Sets an item's ID using an index.
  67. @param index The zero-based index of the item that should have the ID.
  68. @param ID An interger value that numerically represents this item.
  69. @return No return value.
  70. */
  71. ConsoleMethodWithDocs(GuiDropDownCtrl, setItemID, ConsoleVoid, 4, 4, "(int index, int ID)")
  72. {
  73. if (argc != 4)
  74. {
  75. Con::warnf("GuiDropDownCtrl::setItemID() - Invalid number of parameters! Should be (index, ID).");
  76. }
  77. else
  78. {
  79. object->getList()->setItemID(dAtoi(argv[2]), dAtoi(argv[3]));
  80. }
  81. }
  82. /*! Returns an item's ID using an index.
  83. @param index The zero-based index of the item with the needed ID.
  84. @return No return value.
  85. */
  86. ConsoleMethodWithDocs(GuiDropDownCtrl, getItemID, ConsoleInt, 3, 3, "(int index)")
  87. {
  88. if (argc != 3)
  89. {
  90. Con::warnf("GuiDropDownCtrl::getItemID() - Invalid number of parameters! Should be (index).");
  91. }
  92. else
  93. {
  94. return object->getList()->getItemID(dAtoi(argv[2]));
  95. }
  96. return 0;
  97. }
  98. /*! Finds the first item with the given ID.
  99. @param ID The item ID to search for.
  100. @return The first matching item index or -1 if no item is found.
  101. */
  102. ConsoleMethodWithDocs(GuiDropDownCtrl, findItemID, ConsoleInt, 3, 3, "(int ID)")
  103. {
  104. if (argc != 3)
  105. {
  106. Con::warnf("GuiDropDownCtrl::findItemID() - Invalid number of parameters! Should be (ID).");
  107. return -1;
  108. }
  109. return object->getList()->findItemID(dAtoi(argv[2]));
  110. }
  111. /*! Sets an item active using an index.
  112. @param index The zero-based index of the item that should be active.
  113. @return No return value.
  114. */
  115. ConsoleMethodWithDocs(GuiDropDownCtrl, setItemActive, ConsoleVoid, 3, 3, "(int index)")
  116. {
  117. if (argc != 3)
  118. {
  119. Con::warnf("GuiDropDownCtrl::setItemActive() - Invalid number of parameters! Should be (index).");
  120. }
  121. else
  122. {
  123. object->getList()->setItemActive(dAtoi(argv[2]));
  124. }
  125. }
  126. /*! Disables an item using an index.
  127. @param index The zero-based index of the item that should be inactive.
  128. @return No return value.
  129. */
  130. ConsoleMethodWithDocs(GuiDropDownCtrl, setItemInactive, ConsoleVoid, 3, 3, "(int index)")
  131. {
  132. if (argc != 3)
  133. {
  134. Con::warnf("GuiDropDownCtrl::setItemInactive() - Invalid number of parameters! Should be (index).");
  135. }
  136. else
  137. {
  138. object->getList()->setItemInactive(dAtoi(argv[2]));
  139. }
  140. }
  141. /*! Returns if an item is active or not using an index.
  142. @param index The zero-based index of the item.
  143. @return No return value.
  144. */
  145. ConsoleMethodWithDocs(GuiDropDownCtrl, getItemActive, ConsoleBool, 3, 3, "(int index)")
  146. {
  147. if (argc != 3)
  148. {
  149. Con::warnf("GuiDropDownCtrl::getItemActive() - Invalid number of parameters! Should be (index).");
  150. }
  151. else
  152. {
  153. return object->getList()->getItemActive(dAtoi(argv[2]));
  154. }
  155. return true;
  156. }
  157. /*! Returns the number of items in the list.
  158. @return The number of items.
  159. */
  160. ConsoleMethodWithDocs(GuiDropDownCtrl, getItemCount, ConsoleInt, 2, 2, "()")
  161. {
  162. return object->getList()->getItemCount();
  163. }
  164. /*! Returns the index of the selected item.
  165. @return The index of the selected item or -1 if no item is selected.
  166. */
  167. ConsoleMethodWithDocs(GuiDropDownCtrl, getSelectedItem, ConsoleInt, 2, 2, "()")
  168. {
  169. return object->getList()->getSelectedItem();
  170. }
  171. /*! Finds all items with the given text.
  172. @param itemText The text to search for.
  173. @param caseSensitive If true, a case-sensitive search will be performed.
  174. @return A space-delimited list of matching item indexes or -1 if no items are found.
  175. */
  176. ConsoleMethodWithDocs(GuiDropDownCtrl, findItemText, ConsoleInt, 3, 4, "(string itemText, bool caseSensitive)")
  177. {
  178. bool bCaseSensitive = false;
  179. if (argc == 4)
  180. bCaseSensitive = dAtob(argv[3]);
  181. return object->getList()->findItemText(argv[2], bCaseSensitive);
  182. }
  183. /*! Selects the item at the given index.
  184. @param index The zero-based index of the item that should be selected. Passing a -1 clears the selection.
  185. @return No return value.
  186. */
  187. ConsoleMethodWithDocs(GuiDropDownCtrl, setCurSel, ConsoleVoid, 3, 3, "(S32 index)")
  188. {
  189. object->getList()->setCurSel(dAtoi(argv[2]));
  190. }
  191. /*! Adds an item to the end of the list with an optional color bullet.
  192. @param text The text of the new item.
  193. @param color The optional color of a color bullet that will appear to the left of the text. Values range between 0 and 255.
  194. @return No return value.
  195. */
  196. ConsoleMethodWithDocs(GuiDropDownCtrl, addItem, ConsoleVoid, 3, 4, "(string text, [color red / green / blue / [alpha]])")
  197. {
  198. if (argc == 3)
  199. {
  200. object->getList()->addItem(argv[2]);
  201. }
  202. else if (argc == 4)
  203. {
  204. const U32 colorCount = Utility::mGetStringElementCount(argv[3]);
  205. if (colorCount != 4 && colorCount != 3)
  206. {
  207. Con::warnf("GuiDropDownCtrl::addItem() - Invalid color! Colors require three or four values (red / green / blue / [alpha])!");
  208. object->getList()->addItem(argv[2]);
  209. return;
  210. }
  211. F32 red, green, blue, alpha;
  212. red = dAtof(Utility::mGetStringElement(argv[3], 0));
  213. green = dAtof(Utility::mGetStringElement(argv[3], 1));
  214. blue = dAtof(Utility::mGetStringElement(argv[3], 2));
  215. alpha = colorCount > 3 ? dAtof(Utility::mGetStringElement(argv[3], 3)) : 255;
  216. object->getList()->addItemWithColor(argv[2], ColorI(red, green, blue, alpha));
  217. }
  218. else
  219. {
  220. Con::warnf("GuiDropDownCtrl::addItem() - Invalid number of parameters!");
  221. }
  222. }
  223. /*! Adds an item to the end of the list with an ID.
  224. @param text The text of the new item.
  225. @param ID The ID to assign to the item.
  226. @return No return value.
  227. */
  228. ConsoleMethodWithDocs(GuiDropDownCtrl, addItemWithID, ConsoleVoid, 4, 4, "(string text, int ID")
  229. {
  230. if (argc == 4)
  231. {
  232. object->getList()->addItemWithID(argv[2], dAtoi(argv[3]));
  233. }
  234. else
  235. {
  236. Con::warnf("GuiDropDownCtrl::addItemWithID() - Invalid number of parameters! Should be (text, ID).");
  237. }
  238. }
  239. /*! Sets the color of the color bullet at the given index.
  240. @param index The zero-based index of the item that should have a color bullet.
  241. @param color The color of a color bullet that will appear to the left of the text. Values range between 0 and 255.
  242. @return No return value.
  243. */
  244. ConsoleMethodWithDocs(GuiDropDownCtrl, setItemColor, ConsoleVoid, 4, 4, "(S32 index, color red / green / blue / [alpha])")
  245. {
  246. if (argc == 4)
  247. {
  248. const U32 colorCount = Utility::mGetStringElementCount(argv[3]);
  249. if (colorCount != 4 && colorCount != 3)
  250. {
  251. Con::warnf("GuiDropDownCtrl::setItemColor() - Invalid color! Colors require three or four values (red / green / blue / [alpha])!");
  252. return;
  253. }
  254. F32 red, green, blue, alpha;
  255. red = dAtof(Utility::mGetStringElement(argv[3], 0));
  256. green = dAtof(Utility::mGetStringElement(argv[3], 1));
  257. blue = dAtof(Utility::mGetStringElement(argv[3], 2));
  258. alpha = colorCount > 3 ? dAtof(Utility::mGetStringElement(argv[3], 3)) : 255;
  259. object->getList()->setItemColor(dAtoi(argv[2]), ColorI(red, green, blue, alpha));
  260. }
  261. else
  262. {
  263. Con::warnf("GuiDropDownCtrl::setItemColor() - Invalid number of parameters!");
  264. }
  265. }
  266. /*! Clears the color of the color bullet at the given index.
  267. @param index The zero-based index of the item's color bullet.
  268. @return No return value.
  269. */
  270. ConsoleMethodWithDocs(GuiDropDownCtrl, clearItemColor, ConsoleVoid, 3, 3, "(S32 index)")
  271. {
  272. object->getList()->clearItemColor(dAtoi(argv[2]));
  273. }
  274. /*! Clears the color bullets on all items.
  275. @return No return value.
  276. */
  277. ConsoleMethodWithDocs(GuiDropDownCtrl, clearAllColors, ConsoleVoid, 2, 2, "()")
  278. {
  279. object->getList()->clearAllColors();
  280. }
  281. /*! Inserts an item into the list at the specified index.
  282. @param index The zero-based index of the new location of the item.
  283. @param text The text of the new item.
  284. @return Returns the index assigned or -1 on error.
  285. */
  286. ConsoleMethodWithDocs(GuiDropDownCtrl, insertItem, ConsoleVoid, 4, 4, "(S32 index, string text)")
  287. {
  288. object->getList()->insertItem(dAtoi(argv[2]), argv[3]);
  289. }
  290. /*! Removes the item at the given index.
  291. @param index The zero-based index of the item to delete.
  292. @return No return value.
  293. */
  294. ConsoleMethodWithDocs(GuiDropDownCtrl, deleteItem, ConsoleVoid, 3, 3, "(S32 index)")
  295. {
  296. object->getList()->deleteItem(dAtoi(argv[2]));
  297. }
  298. /*! Returns the text of the given item index.
  299. @param index The zero-based index of the item to inspect.
  300. @return The text of the inspected item.
  301. */
  302. ConsoleMethodWithDocs(GuiDropDownCtrl, getItemText, ConsoleString, 3, 3, "(S32 index)")
  303. {
  304. return object->getList()->getItemText(dAtoi(argv[2]));
  305. }
  306. /*! Returns the text of the selected item.
  307. @return The text of the selected item.
  308. */
  309. ConsoleMethodWithDocs(GuiDropDownCtrl, getText, ConsoleString, 2, 2, "()")
  310. {
  311. S32 index = object->getList()->getSelectedItem();
  312. if(index != -1)
  313. {
  314. return object->getList()->getItemText(index);
  315. }
  316. return "";
  317. }
  318. /*! Sets the text of the item at the given item index.
  319. @param index The zero-based index of the item that will be updated.
  320. @param text The text value to update with.
  321. @return No return value.
  322. */
  323. ConsoleMethodWithDocs(GuiDropDownCtrl, setItemText, ConsoleVoid, 4, 4, "(S32 index, string text)")
  324. {
  325. object->getList()->setItemText(dAtoi(argv[2]), argv[3]);
  326. }
  327. /*! Sets the currently used BackgroundProfile for the GuiControl
  328. @param p The BackgroundProfile applies to the the entire screen when the list opens.
  329. @return No return value
  330. */
  331. ConsoleMethodWithDocs(GuiDropDownCtrl, setBackgroundProfile, ConsoleVoid, 3, 3, (GuiControlProfile p))
  332. {
  333. GuiControlProfile* profile;
  334. if (Sim::findObject(argv[2], profile))
  335. object->setControlBackgroundProfile(profile);
  336. }
  337. /*! Sets the currently used ListBoxProfile for the GuiControl
  338. @param p The ListBoxProfile is applied to each item in the drop down.
  339. @return No return value
  340. */
  341. ConsoleMethodWithDocs(GuiDropDownCtrl, setListBoxProfile, ConsoleVoid, 3, 3, (GuiControlProfile p))
  342. {
  343. GuiControlProfile* profile;
  344. if (Sim::findObject(argv[2], profile))
  345. object->setControlListBoxProfile(profile);
  346. }
  347. /*! Sets the currently used ScrollProfile for the GuiControl
  348. @param p The ScrollProfile is applied the to scrollable area.
  349. @return No return value
  350. */
  351. ConsoleMethodWithDocs(GuiDropDownCtrl, setScrollProfile, ConsoleVoid, 3, 3, (GuiControlProfile p))
  352. {
  353. GuiControlProfile* profile;
  354. if (Sim::findObject(argv[2], profile))
  355. object->setControlScrollProfile(profile);
  356. }
  357. /*! Sets the currently used ThumbProfile for the GuiControl
  358. @param p The ThumbProfile is applied to the thumb of the scrollbar.
  359. @return No return value
  360. */
  361. ConsoleMethodWithDocs(GuiDropDownCtrl, setThumbProfile, ConsoleVoid, 3, 3, (GuiControlProfile p))
  362. {
  363. GuiControlProfile* profile;
  364. if (Sim::findObject(argv[2], profile))
  365. object->setControlThumbProfile(profile);
  366. }
  367. /*! Sets the currently used TrackProfile for the GuiControl
  368. @param p The TrackProfile is applied to the track area used by the scroll thumb.
  369. @return No return value
  370. */
  371. ConsoleMethodWithDocs(GuiDropDownCtrl, setTrackProfile, ConsoleVoid, 3, 3, (GuiControlProfile p))
  372. {
  373. GuiControlProfile* profile;
  374. if (Sim::findObject(argv[2], profile))
  375. object->setControlTrackProfile(profile);
  376. }
  377. /*! Sets the currently used ArrowProfile for the GuiControl
  378. @param p The ArrowProfile is applied to the arrow buttons of the scrollbar if you turn them on.
  379. @return No return value
  380. */
  381. ConsoleMethodWithDocs(GuiDropDownCtrl, setArrowProfile, ConsoleVoid, 3, 3, (GuiControlProfile p))
  382. {
  383. GuiControlProfile* profile;
  384. if (Sim::findObject(argv[2], profile))
  385. object->setControlArrowProfile(profile);
  386. }
  387. /*! Sorts the items in the list by their text values.
  388. @param ascending An optional direction. If true, text will be sorted ascending (A-Z). If false, text will be sorted descending (Z-A). Defaults to Ascending.
  389. @return No return value.
  390. */
  391. ConsoleMethodWithDocs(GuiDropDownCtrl, sortByText, ConsoleVoid, 2, 3, "([bool ascending = true])")
  392. {
  393. bool direction = true;
  394. if (argc >= 3)
  395. {
  396. direction = dAtob(argv[3]);
  397. }
  398. object->getList()->sortByText(direction);
  399. }
  400. /*! Sorts the items in the list by their IDs.
  401. @param ascending An optional direction. If true, IDs will be sorted ascending (1, 2, 3...). If false, IDs will be sorted descending (3, 2, 1...). Defaults to Ascending.
  402. @return No return value.
  403. */
  404. ConsoleMethodWithDocs(GuiDropDownCtrl, sortByID, ConsoleVoid, 2, 3, "([bool ascending = true])")
  405. {
  406. bool direction = true;
  407. if (argc >= 3)
  408. {
  409. direction = dAtob(argv[3]);
  410. }
  411. object->getList()->sortByID(direction);
  412. }
  413. ConsoleMethodGroupEndWithDocs(GuiDropDownCtrl)