1
0

configtarget.m 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #include <lib/std.mi>
  2. // ------------------------------------------------------------------------------------
  3. Global GuiObject target;
  4. Global ComponentBucket buck;
  5. // ------------------------------------------------------------------------------------
  6. Function turnAllOffExcept(GuiObject except);
  7. Function turnOn(GuiObject obj);
  8. Function turnOff(GuiObject obj);
  9. // ------------------------------------------------------------------------------------
  10. // ------------------------------------------------------------------------------------
  11. // init
  12. // ------------------------------------------------------------------------------------
  13. System.onScriptLoaded() {
  14. target = getScriptGroup().findObject("skin.config.target");
  15. buck = getScriptGroup().findObject("my.bucket");
  16. // turn off all
  17. GuiObject o = NULL;
  18. turnAllOffExcept(o);
  19. }
  20. // ------------------------------------------------------------------------------------
  21. // save scroller position
  22. // ------------------------------------------------------------------------------------
  23. System.onScriptUnloading() {
  24. if (buck) {
  25. setPrivateInt("configmenu", "last_scroll", buck.getScroll());
  26. }
  27. }
  28. // ------------------------------------------------------------------------------------
  29. // turn on last open
  30. // ------------------------------------------------------------------------------------
  31. buck.onStartup() {
  32. setScroll(getPrivateInt("configmenu", "last_scroll", 0));
  33. Group g = buck.enumChildren(getPrivateInt("configmenu", "last_page", 0));
  34. if (!g) g = buck.enumChildren(0);
  35. if (!g) return;
  36. ToggleButton btn = g.getObject("btn");
  37. if (btn) btn.leftClick();
  38. }
  39. // ------------------------------------------------------------------------------------
  40. // this is called by the bucket button to switch to a new group
  41. // ------------------------------------------------------------------------------------
  42. target.onAction(String action, String param, int x, int y, int p1, int p2, GuiObject source) {
  43. if (getToken(action,";",0) == "switchto") {
  44. String grp = getToken(action, ";", 1);
  45. String is_subpage = getToken(action, ";", 2);
  46. target.setXmlParam("groupid", grp);
  47. if (is_subpage!="subpage") turnAllOffExcept(source.getParent()); // getParent because the source is the button itself, the parent is the whole group item in the bucket
  48. }
  49. }
  50. // ------------------------------------------------------------------------------------
  51. // turn off all buttons except for the parameter, also save last_page param based on param item
  52. // ------------------------------------------------------------------------------------
  53. turnAllOffExcept(GuiObject except) {
  54. if (!buck) return;
  55. int i=0;
  56. // enumerate all inserted groups, turn them off if they're not our exception
  57. while (i<buck.getNumChildren()) {
  58. GuiObject obj = buck.enumChildren(i);
  59. if (obj == except) { // otherwise record last page
  60. setPrivateInt("configmenu", "last_page", i);
  61. i++;
  62. continue;
  63. }
  64. if (obj == NULL) { break; } // shoundnt happen
  65. turnOff(obj);
  66. i++;
  67. }
  68. // turn on the clicked item
  69. if (except) turnOn(except);
  70. }
  71. // ------------------------------------------------------------------------------------
  72. turnOn(GuiObject obj) {
  73. Group gobj = obj;
  74. // otherwise we just need this :
  75. ToggleButton tg = gobj.getObject("btn");
  76. tg.setActivated(1);
  77. }
  78. // ------------------------------------------------------------------------------------
  79. turnOff(GuiObject obj) {
  80. Group gobj = obj;
  81. // otherwise we just need this :
  82. ToggleButton tg = gobj.getObject("btn");
  83. tg.setActivated(0);
  84. }