guiListBoxCtrl_ScriptBinding.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  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(GuiListBoxCtrl, GuiControl)
  23. /*! If true, allows the user to select multiple items.
  24. @param allowMultiSelection True to allow multi-selection. False to allow single selection.
  25. @return No return value.
  26. */
  27. ConsoleMethodWithDocs(GuiListBoxCtrl, setMultiSelection, ConsoleVoid, 3, 3, "(bool allowMultiSelection)")
  28. {
  29. object->setMultipleSelection(dAtob(argv[2]));
  30. }
  31. /*! Reports if multi-selection is enabled.
  32. @return Returns true if multi-selection is enabled. False otherwise.
  33. */
  34. ConsoleMethodWithDocs(GuiListBoxCtrl, getMultiSelection, ConsoleVoid, 2, 2, "()")
  35. {
  36. object->getMultipleSelection();
  37. }
  38. /*! Removes all items from the listbox.
  39. @return No return value.
  40. */
  41. ConsoleMethodWithDocs(GuiListBoxCtrl, clearItems, ConsoleVoid, 2, 2, "()")
  42. {
  43. object->clearItems();
  44. }
  45. /*! Unselects any items that have been selected.
  46. @return No return value.
  47. */
  48. ConsoleMethodWithDocs(GuiListBoxCtrl, clearSelection, ConsoleVoid, 2, 2, "()")
  49. {
  50. object->clearSelection();
  51. }
  52. /*! Sets an item to selected or unselected using an index.
  53. @param index The zero-based index of the item that should be selected.
  54. @param isSelected If true, the item is selected. If false, it is unselected. If omitted, will default to true.
  55. @return No return value.
  56. */
  57. ConsoleMethodWithDocs(GuiListBoxCtrl, setSelected, ConsoleVoid, 3, 4, "(int index, [bool isSelected])")
  58. {
  59. bool value = true;
  60. if (argc == 4)
  61. value = dAtob(argv[3]);
  62. if (value == true)
  63. object->addSelection(dAtoi(argv[2]));
  64. else
  65. object->removeSelection(dAtoi(argv[2]));
  66. }
  67. /*! Sets an item's ID using an index.
  68. @param index The zero-based index of the item that should have the ID.
  69. @param ID An interger value that numerically represents this item.
  70. @return No return value.
  71. */
  72. ConsoleMethodWithDocs(GuiListBoxCtrl, setItemID, ConsoleVoid, 4, 4, "(int index, int ID)")
  73. {
  74. if(argc != 4)
  75. {
  76. Con::warnf("GuiListBoxCtrl::setItemID() - Invalid number of parameters! Should be (index, ID).");
  77. }
  78. else
  79. {
  80. object->setItemID(dAtoi(argv[2]), dAtoi(argv[3]));
  81. }
  82. }
  83. /*! Returns an item's ID using an index.
  84. @param index The zero-based index of the item with the needed ID.
  85. @return The ID of the item.
  86. */
  87. ConsoleMethodWithDocs(GuiListBoxCtrl, getItemID, ConsoleInt, 3, 3, "(int index)")
  88. {
  89. if (argc != 3)
  90. {
  91. Con::warnf("GuiListBoxCtrl::getItemID() - Invalid number of parameters! Should be (index).");
  92. }
  93. else
  94. {
  95. return object->getItemID(dAtoi(argv[2]));
  96. }
  97. return 0;
  98. }
  99. /*! Finds the first item with the given ID.
  100. @param ID The item ID to search for.
  101. @return The first matching item index or -1 if no item is found.
  102. */
  103. ConsoleMethodWithDocs(GuiListBoxCtrl, findItemID, ConsoleInt, 3, 3, "(int ID)")
  104. {
  105. if (argc != 3)
  106. {
  107. Con::warnf("GuiListBoxCtrl::findItemID() - Invalid number of parameters! Should be (ID).");
  108. return -1;
  109. }
  110. return object->findItemID(dAtoi(argv[2]));
  111. }
  112. /*! Sets an item active using an index.
  113. @param index The zero-based index of the item that should be active.
  114. @return No return value.
  115. */
  116. ConsoleMethodWithDocs(GuiListBoxCtrl, setItemActive, ConsoleVoid, 3, 3, "(int index)")
  117. {
  118. if (argc != 3)
  119. {
  120. Con::warnf("GuiListBoxCtrl::setItemActive() - Invalid number of parameters! Should be (index).");
  121. }
  122. else
  123. {
  124. object->setItemActive(dAtoi(argv[2]));
  125. }
  126. }
  127. /*! Disables an item using an index.
  128. @param index The zero-based index of the item that should be inactive.
  129. @return No return value.
  130. */
  131. ConsoleMethodWithDocs(GuiListBoxCtrl, setItemInactive, ConsoleVoid, 3, 3, "(int index)")
  132. {
  133. if (argc != 3)
  134. {
  135. Con::warnf("GuiListBoxCtrl::setItemInactive() - Invalid number of parameters! Should be (index).");
  136. }
  137. else
  138. {
  139. object->setItemInactive(dAtoi(argv[2]));
  140. }
  141. }
  142. /*! Returns if an item is active or not using an index.
  143. @param index The zero-based index of the item.
  144. @return True if the item is active and false otherwise.
  145. */
  146. ConsoleMethodWithDocs(GuiListBoxCtrl, getItemActive, ConsoleBool, 3, 3, "(int index)")
  147. {
  148. if (argc != 3)
  149. {
  150. Con::warnf("GuiListBoxCtrl::getItemActive() - Invalid number of parameters! Should be (index).");
  151. }
  152. else
  153. {
  154. return object->getItemActive(dAtoi(argv[2]));
  155. }
  156. return true;
  157. }
  158. /*! Returns the number of items in the list.
  159. @return The number of items.
  160. */
  161. ConsoleMethodWithDocs(GuiListBoxCtrl, getItemCount, ConsoleInt, 2, 2, "()")
  162. {
  163. return object->getItemCount();
  164. }
  165. /*! Returns the number of selected items in the list.
  166. @return The number of items currently selected.
  167. */
  168. ConsoleMethodWithDocs(GuiListBoxCtrl, getSelCount, ConsoleInt, 2, 2, "()")
  169. {
  170. return object->getSelCount();
  171. }
  172. /*! Returns the index of the first selected item.
  173. @return The index of the first selected item or -1 if no item is selected.
  174. */
  175. ConsoleMethodWithDocs(GuiListBoxCtrl, getSelectedItem, ConsoleInt, 2, 2, "()")
  176. {
  177. return object->getSelectedItem();
  178. }
  179. /*! Returns a list of selected item indexes.
  180. @return A space-delimited list of selected item indexes or -1 if no items are selected.
  181. */
  182. ConsoleMethodWithDocs(GuiListBoxCtrl, getSelectedItems, ConsoleString, 2, 2, "()")
  183. {
  184. S32 selCount = object->getSelCount();
  185. if (selCount == -1 || selCount == 0)
  186. return StringTable->lookup("-1");
  187. else if (selCount == 1)
  188. return Con::getIntArg(object->getSelectedItem());
  189. Vector<S32> selItems;
  190. object->getSelectedItems(selItems);
  191. if (selItems.empty())
  192. return StringTable->lookup("-1");
  193. UTF8 *retBuffer = Con::getReturnBuffer(selItems.size() * 4);
  194. dMemset(retBuffer, 0, selItems.size() * 4);
  195. Vector<S32>::iterator i = selItems.begin();
  196. for (; i != selItems.end(); i++)
  197. {
  198. UTF8 retFormat[12];
  199. dSprintf(retFormat, 12, "%d ", (*i));
  200. dStrcat(retBuffer, retFormat);
  201. }
  202. return retBuffer;
  203. }
  204. /*! Finds all items with the given text.
  205. @param itemText The text to search for.
  206. @param caseSensitive If true, a case-sensitive search will be performed.
  207. @return A space-delimited list of matching item indexes or -1 if no items are found.
  208. */
  209. ConsoleMethodWithDocs(GuiListBoxCtrl, findItemText, ConsoleInt, 3, 4, "(string itemText, bool caseSensitive)")
  210. {
  211. bool bCaseSensitive = false;
  212. if (argc == 4)
  213. bCaseSensitive = dAtob(argv[3]);
  214. return object->findItemText(argv[2], bCaseSensitive);
  215. }
  216. /*! Selects the item at the given index.
  217. @param index The zero-based index of the item that should be selected. Passing a -1 clears the selection.
  218. @return No return value.
  219. */
  220. ConsoleMethodWithDocs(GuiListBoxCtrl, setCurSel, ConsoleVoid, 3, 3, "(S32 index)")
  221. {
  222. object->setCurSel(dAtoi(argv[2]));
  223. }
  224. /*! Selects a range of items from a start index to the end or an ending index.
  225. @param start The zero-based index of the start of the selected range.
  226. @param stop The optional, zero-based index of the end of the selected range. If no stop is given, the selection will go to the end of the list.
  227. @return No return value.
  228. */
  229. ConsoleMethodWithDocs(GuiListBoxCtrl, setCurSelRange, ConsoleVoid, 3, 4, "(S32 start, [S32 stop])")
  230. {
  231. if (argc == 4)
  232. object->setCurSelRange(dAtoi(argv[2]), dAtoi(argv[3]));
  233. else
  234. object->setCurSelRange(dAtoi(argv[2]), 999999);
  235. }
  236. /*! Adds an item to the end of the list with an optional color bullet.
  237. @param text The text of the new item.
  238. @param color The optional color of a color bullet that will appear to the left of the text. Values range between 0 and 255.
  239. @return No return value.
  240. */
  241. ConsoleMethodWithDocs(GuiListBoxCtrl, addItem, ConsoleVoid, 3, 4, "(string text, [color red / green / blue / [alpha]])")
  242. {
  243. if (argc == 3)
  244. {
  245. object->addItem(argv[2]);
  246. }
  247. else if (argc == 4)
  248. {
  249. const U32 colorCount = Utility::mGetStringElementCount(argv[3]);
  250. if (colorCount != 4 && colorCount != 3)
  251. {
  252. Con::warnf("GuiListBoxCtrl::addItem() - Invalid color! Colors require three or four values (red / green / blue / [alpha])!");
  253. object->addItem(argv[2]);
  254. return;
  255. }
  256. F32 red, green, blue, alpha;
  257. red = dAtof(Utility::mGetStringElement(argv[3], 0));
  258. green = dAtof(Utility::mGetStringElement(argv[3], 1));
  259. blue = dAtof(Utility::mGetStringElement(argv[3], 2));
  260. alpha = colorCount > 3 ? dAtof(Utility::mGetStringElement(argv[3], 3)) : 255;
  261. object->addItemWithColor(argv[2], ColorI(red, green, blue, alpha));
  262. }
  263. else
  264. {
  265. Con::warnf("GuiListBoxCtrl::addItem() - Invalid number of parameters!");
  266. }
  267. }
  268. /*! Adds an item to the end of the list with an ID.
  269. @param text The text of the new item.
  270. @param ID The ID to assign to the item.
  271. @return No return value.
  272. */
  273. ConsoleMethodWithDocs(GuiListBoxCtrl, addItemWithID, ConsoleVoid, 4, 4, "(string text, int ID")
  274. {
  275. if (argc == 4)
  276. {
  277. object->addItemWithID(argv[2], dAtoi(argv[3]));
  278. }
  279. else
  280. {
  281. Con::warnf("GuiListBoxCtrl::addItemWithID() - Invalid number of parameters! Should be (text, ID).");
  282. }
  283. }
  284. /*! Sets the color of the color bullet at the given index.
  285. @param index The zero-based index of the item that should have a color bullet.
  286. @param color The color of a color bullet that will appear to the left of the text. Values range between 0 and 255.
  287. @return No return value.
  288. */
  289. ConsoleMethodWithDocs(GuiListBoxCtrl, setItemColor, ConsoleVoid, 4, 4, "(S32 index, color red / green / blue / [alpha])")
  290. {
  291. if (argc == 4)
  292. {
  293. const U32 colorCount = Utility::mGetStringElementCount(argv[3]);
  294. if (colorCount != 4 && colorCount != 3)
  295. {
  296. Con::warnf("GuiListBoxCtrl::setItemColor() - Invalid color! Colors require three or four values (red / green / blue / [alpha])!");
  297. return;
  298. }
  299. F32 red, green, blue, alpha;
  300. red = dAtof(Utility::mGetStringElement(argv[3], 0));
  301. green = dAtof(Utility::mGetStringElement(argv[3], 1));
  302. blue = dAtof(Utility::mGetStringElement(argv[3], 2));
  303. alpha = colorCount > 3 ? dAtof(Utility::mGetStringElement(argv[3], 3)) : 255;
  304. object->setItemColor(dAtoi(argv[2]), ColorI(red, green, blue, alpha));
  305. }
  306. else
  307. {
  308. Con::warnf("GuiListBoxCtrl::setItemColor() - Invalid number of parameters!");
  309. }
  310. }
  311. /*! Clears the color of the color bullet at the given index.
  312. @param index The zero-based index of the item's color bullet.
  313. @return No return value.
  314. */
  315. ConsoleMethodWithDocs(GuiListBoxCtrl, clearItemColor, ConsoleVoid, 3, 3, "(S32 index)")
  316. {
  317. object->clearItemColor(dAtoi(argv[2]));
  318. }
  319. /*! Clears the color bullets on all items.
  320. @return No return value.
  321. */
  322. ConsoleMethodWithDocs(GuiListBoxCtrl, clearAllColors, ConsoleVoid, 2, 2, "()")
  323. {
  324. object->clearAllColors();
  325. }
  326. /*! Inserts an item into the list at the specified index.
  327. @param index The zero-based index of the new location of the item.
  328. @param text The text of the new item.
  329. @return Returns the index assigned or -1 on error.
  330. */
  331. ConsoleMethodWithDocs(GuiListBoxCtrl, insertItem, ConsoleVoid, 4, 4, "(S32 index, string text)")
  332. {
  333. object->insertItem(dAtoi(argv[2]), argv[3]);
  334. }
  335. /*! Removes the item at the given index.
  336. @param index The zero-based index of the item to delete.
  337. @return No return value.
  338. */
  339. ConsoleMethodWithDocs(GuiListBoxCtrl, deleteItem, ConsoleVoid, 3, 3, "(S32 index)")
  340. {
  341. object->deleteItem(dAtoi(argv[2]));
  342. }
  343. /*! Returns the text of the given item index.
  344. @param index The zero-based index of the item to inspect.
  345. @return The text of the inspected item.
  346. */
  347. ConsoleMethodWithDocs(GuiListBoxCtrl, getItemText, ConsoleString, 3, 3, "(S32 index)")
  348. {
  349. return object->getItemText(dAtoi(argv[2]));
  350. }
  351. /*! Sets the text of the item at the given item index.
  352. @param index The zero-based index of the item that will be updated.
  353. @param text The text value to update with.
  354. @return No return value.
  355. */
  356. ConsoleMethodWithDocs(GuiListBoxCtrl, setItemText, ConsoleVoid, 4, 4, "(S32 index, string text)")
  357. {
  358. object->setItemText(dAtoi(argv[2]), argv[3]);
  359. }
  360. /*! Sorts the items in the list by their text values.
  361. @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.
  362. @return No return value.
  363. */
  364. ConsoleMethodWithDocs(GuiListBoxCtrl, sortByText, ConsoleVoid, 2, 3, "([bool ascending = true])")
  365. {
  366. bool direction = true;
  367. if (argc >= 3)
  368. {
  369. direction = dAtob(argv[3]);
  370. }
  371. object->sortByText(direction);
  372. }
  373. /*! Sorts the items in the list by their IDs.
  374. @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.
  375. @return No return value.
  376. */
  377. ConsoleMethodWithDocs(GuiListBoxCtrl, sortByID, ConsoleVoid, 2, 3, "([bool ascending = true])")
  378. {
  379. bool direction = true;
  380. if (argc >= 3)
  381. {
  382. direction = dAtob(argv[3]);
  383. }
  384. object->sortByID(direction);
  385. }
  386. ConsoleMethodGroupEndWithDocs(GuiListBoxCtrl)