menuInputHandling.tscript 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729
  1. //==============================================================================
  2. // Menu Input Buttons
  3. // This file manages the Menu Input Buttons stuff
  4. // Any time you have a GUI button that should be clickable AND map to a key input
  5. // such as a gamepad button, or enter, etc, this stuff can be used
  6. //==============================================================================
  7. /*
  8. Gamepad input reference for 360 controller
  9. btn_a = A
  10. btn_b = B
  11. btn_x = X
  12. btn_y = Y
  13. btn_r = Right Bumper
  14. btn_l = Right Bumper
  15. upov = Dpad Up
  16. dpov = Dpad Down
  17. lpov = Dpad Left
  18. rpov = Dpad Right
  19. xaxis = Left Stick | + values = up, - values = down
  20. yaxis = Left Stick | + values = up, - values = down
  21. rxaxis = Right Stick | + values = up, - values = down
  22. ryaxis = Right Stick | + values = up, - values = down
  23. zaxis = Left Trigger
  24. rzaxis = Right Trigger
  25. btn_start = Start
  26. btn_back = Back/Select
  27. */
  28. //==============================================================================
  29. /// Summary:
  30. /// This is used with the main UI menu lists, when a non-axis input event is called
  31. /// such as pressing a button
  32. /// It is called from the engine
  33. ///
  34. /// \param %device (string) The name of the device the input event is coming fromt
  35. /// \param %action (string) The specific key/input action
  36. /// \param %state (bool) The down/up state of the event sent
  37. function UIMenuButtonList::onInputEvent(%this, %device, %action, %state)
  38. {
  39. if(%state)
  40. $activeMenuButtonContainer.processInputs(%device, %action);
  41. }
  42. //==============================================================================
  43. /// Summary:
  44. /// This is used with the main UI menu lists, when an axis input event is called
  45. /// such as moving a joystick
  46. /// It is called from the engine
  47. ///
  48. /// \param %device (string) The name of the device the input event is coming fromt
  49. /// \param %action (string) The specific key/input action
  50. /// \param %axisVal (float) The float value of the axis event
  51. function UIMenuButtonList::onAxisEvent(%this, %device, %action, %axisVal)
  52. {
  53. //Skip out of the value is too low as it could just be noise or miscalibrated defaults
  54. if(%axisVal < 0.02)
  55. return;
  56. $activeMenuButtonContainer.processAxisEvent(%device, %action);
  57. }
  58. //==============================================================================
  59. /// Summary:
  60. /// Sets the command and text for the specified button. If %text and %command
  61. /// are left empty, the button will be disabled and hidden.
  62. ///
  63. /// \param %gamepadButton (string) The button to set for when using gamepad input. See the input map reference comment at the top of the file
  64. /// \param %keyboardButton (string) The button to set for when using keyboard/mouse input.
  65. /// \param %text (string) The text to display next to the A button graphic.
  66. /// \param %command (string) The command executed when the A button is pressed.
  67. function MenuInputButton::set(%this, %gamepadButton, %keyboardButton, %text, %command)
  68. {
  69. %this.setHidden(false);
  70. %set = (! ((%text $= "") && (%command $= "")));
  71. %this.gamepadButton = %gamepadButton;
  72. %this.keyboardButton = %keyboardButton;
  73. if(%gamepadButton $= "")
  74. %this.gamepadValid = false;
  75. else
  76. %this.gamepadValid = true;
  77. if(%keyboardButton $= "")
  78. %this.kbmValid = false;
  79. else
  80. %this.kbmValid = true;
  81. if((!%this.kbmValid && $activeControllerType !$= "gamepad") ||
  82. (!%this.gamepadValid && $activeControllerType $= "gamepad"))
  83. %set = false;
  84. %this.setText(%text);
  85. %this.Command = %command;
  86. %this.refresh();
  87. }
  88. //==============================================================================
  89. /// Summary:
  90. /// Disables the MenuInputButton, marking it as not to consume inputs or display
  91. function MenuInputButton::disable(%this)
  92. {
  93. %this.setText("");
  94. %this.Command = "";
  95. %this.setActive(false);
  96. %this.setVisible(false);
  97. }
  98. //==============================================================================
  99. /// Summary:
  100. /// Refreshes the specific button, updating it's visbility status and the displayed input image
  101. function MenuInputButton::refresh(%this)
  102. {
  103. %set = (! ((%this.text $= "") && (%this.command $= "")));
  104. //Do a check so if a MenuInput is selectively bound and we're not using the
  105. //matched input type, then we skip
  106. if((!%this.kbmValid && $activeControllerType !$= "gamepad") ||
  107. (!%this.gamepadValid && $activeControllerType $= "gamepad"))
  108. %set = false;
  109. %this.setActive(%set);
  110. %this.setVisible(%set);
  111. if(!%this.isActive())
  112. return;
  113. if($activeControllerType $= "gamepad")
  114. {
  115. if(%this.gamepadButton !$= "")
  116. {
  117. %assetId = "";
  118. if($activeControllerName $= "PS4 Controller")
  119. {
  120. %assetId = "UI:PS4_";
  121. if(%this.gamepadButton $= "btn_a")
  122. %assetId = %assetId @ "Cross";
  123. else if(%this.gamepadButton $= "btn_b")
  124. %assetId = %assetId @ "Circle";
  125. else if(%this.gamepadButton $= "btn_x")
  126. %assetId = %assetId @ "Square";
  127. else if(%this.gamepadButton $= "btn_y")
  128. %assetId = %assetId @ "Triangle";
  129. else if(%this.gamepadButton $= "btn_l")
  130. %assetId = %assetId @ "L1";
  131. else if(%this.gamepadButton $= "zaxis")
  132. %assetId = %assetId @ "L2";
  133. else if(%this.gamepadButton $= "btn_r")
  134. %assetId = %assetId @ "R1";
  135. else if(%this.gamepadButton $= "rzaxis")
  136. %assetId = %assetId @ "R2";
  137. else if(%this.gamepadButton $= "btn_start")
  138. %assetId = %assetId @ "Options";
  139. else if(%this.gamepadButton $= "btn_back")
  140. %assetId = %assetId @ "Share";
  141. }
  142. else if($activeControllerName $= "Nintendo Switch Pro Controller")
  143. {
  144. %assetId = "UI:Switch_";
  145. if(%this.gamepadButton $= "btn_a")
  146. %assetId = %assetId @ "B";
  147. else if(%this.gamepadButton $= "btn_b")
  148. %assetId = %assetId @ "A";
  149. else if(%this.gamepadButton $= "btn_x")
  150. %assetId = %assetId @ "Y";
  151. else if(%this.gamepadButton $= "btn_y")
  152. %assetId = %assetId @ "X";
  153. else if(%this.gamepadButton $= "btn_l")
  154. %assetId = %assetId @ "LB";
  155. else if(%this.gamepadButton $= "zaxis")
  156. %assetId = %assetId @ "LT";
  157. else if(%this.gamepadButton $= "btn_r")
  158. %assetId = %assetId @ "RB";
  159. else if(%this.gamepadButton $= "rzaxis")
  160. %assetId = %assetId @ "RT";
  161. else if(%this.gamepadButton $= "btn_start")
  162. %assetId = %assetId @ "Plus";
  163. else if(%this.gamepadButton $= "btn_back")
  164. %assetId = %assetId @ "Minus";
  165. }
  166. else if($activeControllerName !$= "")
  167. {
  168. %assetId = "UI:Xbox_";
  169. if(%this.gamepadButton $= "btn_a")
  170. %assetId = %assetId @ "A";
  171. else if(%this.gamepadButton $= "btn_b")
  172. %assetId = %assetId @ "B";
  173. else if(%this.gamepadButton $= "btn_x")
  174. %assetId = %assetId @ "X";
  175. else if(%this.gamepadButton $= "btn_y")
  176. %assetId = %assetId @ "Y";
  177. else if(%this.gamepadButton $= "btn_l")
  178. %assetId = %assetId @ "LB";
  179. else if(%this.gamepadButton $= "zaxis")
  180. %assetId = %assetId @ "LT";
  181. else if(%this.gamepadButton $= "btn_r")
  182. %assetId = %assetId @ "RB";
  183. else if(%this.gamepadButton $= "rzaxis")
  184. %assetId = %assetId @ "RT";
  185. else if(%this.gamepadButton $= "btn_start")
  186. %assetId = %assetId @ "Menu";
  187. else if(%this.gamepadButton $= "btn_back")
  188. %assetId = %assetId @ "Windows";
  189. }
  190. }
  191. }
  192. else
  193. {
  194. if(%this.keyboardButton !$= "")
  195. {
  196. %assetId = "UI:Keyboard_Black_" @ %this.keyboardButton;
  197. }
  198. }
  199. %this.setBitmap(%assetId @ "_image");
  200. return true;
  201. }
  202. //==============================================================================
  203. /// Summary:
  204. /// Refreshes a menu input container, updating the buttons inside it
  205. function MenuInputButtonContainer::refresh(%this)
  206. {
  207. %count = %this.getCount();
  208. for(%i=0; %i < %count; %i++)
  209. {
  210. %btn = %this.getObject(%i);
  211. %btn.refresh();
  212. }
  213. }
  214. //==============================================================================
  215. /// Summary:
  216. /// Sets the given MenuInputButtonContainer as the active one. This directs input events
  217. /// to it's buttons, ensures it's visible, and auto-hides the old active container if it was set
  218. function MenuInputButtonContainer::setActive(%this)
  219. {
  220. if(isObject($activeMenuButtonContainer))
  221. $activeMenuButtonContainer.hidden = true;
  222. $activeMenuButtonContainer = %this;
  223. $activeMenuButtonContainer.hidden = false;
  224. $activeMenuButtonContainer.refresh();
  225. }
  226. //==============================================================================
  227. /// Summary:
  228. /// Checks the input manager for if we have a gamepad active and gets it's name
  229. /// If we have one, also sets the active input type to gamepad
  230. function MenuInputButtonContainer::checkGamepad(%this)
  231. {
  232. %controllerName = SDLInputManager::JoystickNameForIndex(0);
  233. $activeControllerName = %controllerName;
  234. if($activeControllerName $= "")
  235. $activeControllerType = "K&M";
  236. else
  237. $activeControllerType = "gamepad";
  238. }
  239. //==============================================================================
  240. /// Summary:
  241. /// This is called by the earlier inputs callback that comes from the menu list
  242. /// this allows us to first check what the input type is, and if the device is different
  243. /// (such as going from keyboard and mouse to gamepad) we can refresh the buttons to update
  244. /// the display
  245. /// Then we process the input to see if it matches to any of the button maps for our
  246. /// MenuInputButtons. If we have a match, we execute it's command.
  247. ///
  248. /// \param %device (string) The device that is causing the input event
  249. /// \param %action (string) The name of the input action
  250. function MenuInputButtonContainer::processInputs(%this, %device, %action)
  251. {
  252. //check to see if our status has changed
  253. %changed = false;
  254. %oldDevice = $activeControllerName;
  255. %deviceName = stripTrailingNumber(%device);
  256. if(%deviceName $= "keyboard" || %deviceName $= "mouse")
  257. {
  258. if($activeControllerName !$= "K&M")
  259. %changed = true;
  260. $activeControllerName = "K&M";
  261. $activeControllerType = "K&M";
  262. Canvas.showCursor();
  263. }
  264. else
  265. {
  266. if(%this.checkGamepad())
  267. {
  268. Canvas.hideCursor();
  269. }
  270. if($activeControllerType !$= %oldDevice)
  271. %changed = true;
  272. }
  273. if(%changed)
  274. %this.refresh();
  275. //Now process the input for the button accelerator, if applicable
  276. //Set up our basic buttons
  277. for(%i=0; %i < %this.getCount(); %i++)
  278. {
  279. %btn = %this.getObject(%i);
  280. if(!%btn.isActive())
  281. continue;
  282. if($activeControllerType !$= "K&M")
  283. {
  284. if(%btn.gamepadButton $= %action)
  285. {
  286. eval(%btn.command);
  287. }
  288. }
  289. else
  290. {
  291. if(%btn.keyboardButton $= %action)
  292. {
  293. eval(%btn.command);
  294. }
  295. }
  296. }
  297. }
  298. //==============================================================================
  299. /// Summary:
  300. /// This is called by the earlier inputs callback that comes from the menu list
  301. /// this allows us to first check what the input type is, and if the device is different
  302. /// (such as going from keyboard and mouse to gamepad) we can refresh the buttons to update
  303. /// the display
  304. ///
  305. /// \param %device (string) The name of the device the input event is coming fromt
  306. /// \param %action (string) The specific key/input action
  307. /// \param %axisVal (float) The float value of the axis event
  308. function MenuInputButtonContainer::processAxisEvent(%this, %device, %action, %axisVal)
  309. {
  310. //check to see if our status has changed
  311. %changed = false;
  312. %oldDevice = $activeControllerName;
  313. %deviceName = stripTrailingNumber(%device);
  314. if(%deviceName $= "mouse")
  315. {
  316. if($activeControllerName !$= "K&M")
  317. %changed = true;
  318. $activeControllerName = "K&M";
  319. $activeControllerType = "K&M";
  320. Canvas.showCursor();
  321. }
  322. else
  323. {
  324. if(%this.checkGamepad())
  325. {
  326. Canvas.hideCursor();
  327. }
  328. if($activeControllerType !$= %oldDevice)
  329. %changed = true;
  330. }
  331. if(%changed)
  332. %this.refresh();
  333. }
  334. //
  335. //
  336. function onSDLDeviceConnected(%sdlIndex, %deviceName, %deviceType)
  337. {
  338. /*if(GamepadButtonsGui.checkGamepad())
  339. {
  340. GamepadButtonsGui.hidden = false;
  341. }*/
  342. }
  343. function onSDLDeviceDisconnected(%sdlIndex)
  344. {
  345. /*if(!GamepadButtonsGui.checkGamepad())
  346. {
  347. GamepadButtonsGui.hidden = true;
  348. }*/
  349. }
  350. //==============================================================================
  351. // Menu Input processing
  352. // These functions manage the Menu input processing in general
  353. // Whenever a MenuInputHandler consumes an input event, it'll process them here
  354. // This'll let the active menu list be navigated, as well as buttons be processed
  355. // and ultimately handled by the Input Buttons above
  356. //==============================================================================
  357. //==============================================================================
  358. /// Summary:
  359. /// This is used with the main UI menu lists, when an axis input event is called
  360. /// such as moving a joystick
  361. /// It is called from the engine
  362. ///
  363. /// \param %device (string) The name of the device the input event is coming fromt
  364. /// \param %action (string) The specific key/input action
  365. /// \param %axisVal (float) The float value of the axis event
  366. function MenuInputHandler::onAxisEvent(%this, %device, %action, %value)
  367. {
  368. //this is to force a refresh of the menu
  369. if(%value == 1 || %value == -1)
  370. $activeMenuButtonContainer.processInputs(%device, %action);
  371. if(startsWith(%device, "mouse"))
  372. return;
  373. if((%action $= "upov" && %value > 0) || (%action $= "yaxis" && %value == -1))
  374. {
  375. $activeMenuList.navigateUp();
  376. }
  377. if((%action $= "dpov" && %value > 0) || (%action $= "yaxis" && %value == 1))
  378. {
  379. $activeMenuList.navigateDown();
  380. }
  381. //How we deal with the left and right navigation is dependant on the mode of the
  382. //menu list
  383. if($activeMenuListMode $= "Settings")
  384. {
  385. if((%action $= "lpov" && %value > 0) || (%action $= "xaxis" && %value == -1))
  386. {
  387. echo("Options menu nudged left!");
  388. //$activeMenuList.navigateLeft();
  389. }
  390. if((%action $= "rpov" && %value > 0) || (%action $= "xaxis" && %value == -1))
  391. {
  392. echo("Options menu nudged right!");
  393. //$activeMenuList.navigateRight();
  394. }
  395. }
  396. else
  397. {
  398. if((%action $= "lpov" && %value > 0) || (%action $= "xaxis" && %value == -1))
  399. {
  400. $activeMenuList.navigateLeft();
  401. }
  402. if((%action $= "rpov" && %value > 0) || (%action $= "xaxis" && %value == -1))
  403. {
  404. $activeMenuList.navigateRight();
  405. }
  406. }
  407. }
  408. //==============================================================================
  409. /// Summary:
  410. /// This is used with the main UI menu lists, when a non-axis input event is called
  411. /// such as pressing a button
  412. /// It is called from the engine
  413. ///
  414. /// \param %device (string) The name of the device the input event is coming fromt
  415. /// \param %action (string) The specific key/input action
  416. /// \param %state (bool) The down/up state of the event sent
  417. function MenuInputHandler::onInputEvent(%this, %device, %action, %state)
  418. {
  419. if(%action $= "upov" || %action $= "dpov" || %action $= "lpov" || %action $= "rpov")
  420. {
  421. %this.onAxisEvent(%device, %action, %state);
  422. return;
  423. }
  424. if(%state)
  425. $activeMenuButtonContainer.processInputs(%device, %action);
  426. }
  427. //==============================================================================
  428. // Menu List processing
  429. // These functions manage the navigation and activation of the Menu Lists
  430. //==============================================================================
  431. //==============================================================================
  432. /// Summary:
  433. /// Is the GUIContainer with this MenuList namespace the 'active' menulist as far
  434. /// as UI interfaces is concerned?
  435. function MenuList::isActiveMenuList(%this)
  436. {
  437. if($activeMenuList == %this)
  438. return true;
  439. return false;
  440. }
  441. //==============================================================================
  442. /// Summary:
  443. /// Sets the GUIContainer with this MenuList namespace as the active menulist.
  444. /// This means that any input events caught in MenuInputHandlers is directed at
  445. /// this menu list to navigate it
  446. ///
  447. /// \param %startPosition (Point2F) The X and Y starting positions of the selection for this menuList
  448. /// \param %menuMode (string) Indicates the mode/type of menuList, allowing for special behaviors depending on type
  449. function MenuList::setAsActiveMenuList(%this, %startPosition, %menuMode)
  450. {
  451. if(%startPosition $= "")
  452. %startPosition = "0 0";
  453. if(%menuMode $= "")
  454. %menuMode = "Menu";
  455. $activeMenuList = %this;
  456. $activeMenuList.hidden = false;
  457. $activeMenuList.ListPosition = %startPosition;
  458. $activeMenuListMode = %menuMode;
  459. %this.refresh();
  460. }
  461. //==============================================================================
  462. /// Summary:
  463. /// Activates the currently highlighted child object
  464. function MenuList::activate(%this)
  465. {
  466. //check for a highlighted element
  467. if($activeMenuList.ListPosition.y > -1 && $activeMenuList.ListPosition < $activeMenuList.getCount())
  468. {
  469. %btn = $activeMenuList.getObject($activeMenuList.ListPosition.y);
  470. %btn.performClick();
  471. }
  472. }
  473. //==============================================================================
  474. /// Summary:
  475. /// refreshes the menuList, updating children highlight status and if there is
  476. /// a button pointer control defined on our list, we update it's position as
  477. /// needed
  478. function MenuList::refresh(%this)
  479. {
  480. %selectedObject = -1;
  481. for(%i=0; %i < $activeMenuList.getCount(); %i++)
  482. {
  483. %btn = $activeMenuList.getObject(%i);
  484. %isSelected = %i == $activeMenuList.ListPosition.y;
  485. %btn.setHighlighted(%isSelected);
  486. if(%isSelected)
  487. %selectedObject = %i;
  488. }
  489. if(isObject(%this.buttonPointerCtrl))
  490. {
  491. if(%selectedObject != -1)
  492. {
  493. %this.buttonPointerCtrl.setHidden(false);
  494. %buttonCenter = $activeMenuList.getObject(%selectedObject).getGlobalCenter();
  495. if(%this.centerButtonPointerCtrl)
  496. {
  497. %this.buttonPointerCtrl.setCenter(%buttonCenter.x, %buttonCenter.y);
  498. }
  499. else
  500. {
  501. //if we're not centering, then left-justify
  502. %this.buttonPointerCtrl.setCenter(%buttonCenter.x - $activeMenuList.getObject(%selectedObject).extent.x / 2, %buttonCenter.y);
  503. }
  504. }
  505. else
  506. {
  507. %this.buttonPointerCtrl.setHidden(true);
  508. }
  509. }
  510. if($activeMenuList.isMethod("onNavigate"))
  511. $activeMenuList.onNavigate($activeMenuList.ListPosition.y);
  512. %parent = $activeMenuList.getParent();
  513. if(%parent.getClassName() $= "GuiScrollCtrl")
  514. {
  515. %parent.scrollToObject(%selectedObject);
  516. }
  517. }
  518. //==============================================================================
  519. /// Summary:
  520. /// Selects the next 'up' child item in the menuList. If the current is the topmost
  521. /// then nothing happens
  522. function MenuList::navigateUp(%this)
  523. {
  524. $activeMenuList.ListPosition.y -= 1;
  525. if($activeMenuList.ListPosition.y < 0)
  526. $activeMenuList.ListPosition.y = 0;
  527. %this.refresh();
  528. }
  529. //==============================================================================
  530. /// Summary:
  531. /// Selects the next 'down' child item in the menuList. If the current is the bottommost
  532. /// then nothing happens
  533. function MenuList::navigateDown(%this)
  534. {
  535. $activeMenuList.ListPosition.y += 1;
  536. if($activeMenuList.ListPosition.y >= $activeMenuList.getCount())
  537. $activeMenuList.ListPosition.y = $activeMenuList.getCount()-1;
  538. %this.refresh();
  539. }
  540. //==============================================================================
  541. /// Summary:
  542. /// Selects the next 'left' child item in the menuList. If the current item is the leftmost
  543. /// then nothing happens
  544. function MenuList::navigateLeft()
  545. {
  546. //Atm, we're only handling specific control types, namely options entries, but
  547. //this could readily be expanded upon to handle grids like for inventory screens
  548. //or the like
  549. %btn = $activeMenuList.getObject($activeMenuList.ListPosition.y);
  550. if(%btn.getClassName() $= "GuiGameSettingsCtrl" && %btn.isEnabled())
  551. {
  552. %mode = %btn.getMode();
  553. if(%mode == 0) //options list
  554. {
  555. %optionId = %btn.getCurrentOptionIndex() - 1;
  556. %btn.selectOptionByIndex(%optionId);
  557. %btn.onChange();
  558. }
  559. else if(%mode == 1) //slider
  560. {
  561. %value = %btn.getValue();
  562. %adjustedValue = %value - %btn.getIncrement();
  563. %minValue = %btn.getRange().x;
  564. if(%adjustedValue < %minValue)
  565. %adjustedValue = %minValue;
  566. %btn.setValue(%adjustedValue);
  567. %btn.onChange();
  568. }
  569. }
  570. }
  571. //==============================================================================
  572. /// Summary:
  573. /// Selects the next 'right' child item in the menuList. If the current item is the rightmost
  574. /// then nothing happens
  575. function MenuList::navigateRight()
  576. {
  577. %btn = $activeMenuList.getObject($activeMenuList.ListPosition.y);
  578. if(%btn.getClassName() $= "GuiGameSettingsCtrl" && %btn.isEnabled())
  579. {
  580. %mode = %btn.getMode();
  581. if(%mode == 0) //options list
  582. {
  583. %optionId = %btn.getCurrentOptionIndex() + 1;
  584. %btn.selectOptionByIndex(%optionId);
  585. %btn.onChange();
  586. }
  587. else if(%mode == 1) //slider
  588. {
  589. %value = %btn.getValue();
  590. %adjustedValue = %value + %btn.getIncrement();
  591. %maxValue = %btn.getRange().y;
  592. if(%adjustedValue > %maxValue)
  593. %adjustedValue = %maxValue;
  594. %btn.setValue(%adjustedValue);
  595. %btn.onChange();
  596. }
  597. }
  598. }
  599. //==============================================================================
  600. /// Summary:
  601. /// Gets the current vertical positionally selected child object
  602. function MenuList::getActiveRow(%this)
  603. {
  604. return $activeMenuList.ListPosition.y;
  605. }
  606. //==============================================================================
  607. /// Summary:
  608. /// Called from the engine when a GUIButtonBase-derived class with MenuListButton namespace class
  609. /// has its highlighting status changed. Allows us to react to this change of state and trigger refreshse
  610. /// or other events to keep the navigation tracking up to date
  611. ///
  612. /// \param %state (bool) The on/off state of the button being highlighted
  613. function MenuListButton::onHighlighted(%this, %state)
  614. {
  615. echo("MenuListButton::onHighlighted() - " @ %this.internalName @ " was " @ %state @ " highlighted");
  616. %parentContainer = %this.getParent();
  617. if(%parentContainer.class $= "MenuList" || %parentContainer.superClass $= "MenuList")
  618. {
  619. if(isObject(%parentContainer.buttonPointerCtrl))
  620. {
  621. if(%state)
  622. {
  623. %parentContainer.buttonPointerCtrl.setHidden(false);
  624. %buttonCenter = %this.getGlobalCenter();
  625. echo(" - button center:" @ %buttonCenter);
  626. if(%parentContainer.centerButtonPointerCtrl)
  627. {
  628. %parentContainer.buttonPointerCtrl.setGlobalCenter(%buttonCenter.x, %buttonCenter.y);
  629. }
  630. else
  631. {
  632. //if we're not centering, then left-justify
  633. %parentContainer.buttonPointerCtrl.setGlobalCenter(%buttonCenter.x - %this.extent.x / 2, %buttonCenter.y);
  634. }
  635. echo(" - pointer position:" @ %parentContainer.buttonPointerCtrl.getPosition());
  636. }
  637. /*else
  638. {
  639. %parentContainer.buttonPointerCtrl.setHidden(true);
  640. }*/
  641. }
  642. }
  643. }