popupitem.m 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #include <lib/std.mi>
  2. #define MARGIN 2
  3. #define MARGIN_PRE 2
  4. #define MARGIN_POST 6
  5. #define CHECKMARK_WIDTH 10
  6. #define ARROW_WIDTH 10
  7. Function setArrow(int want);
  8. Function setCheckmark(int want);
  9. Function updatePos();
  10. Global Group mgrp;
  11. Global GuiObject background;
  12. Class GuiObject ItemSwitcher;
  13. Global int id;
  14. Global int want_checkmark;
  15. Global int want_arrow;
  16. Global ItemSwitcher a, b, c, d;
  17. Global GuiObject _a, _b, _c;
  18. System.onScriptLoaded() {
  19. mgrp = getScriptGroup();
  20. if (mgrp == NULL) {
  21. messagebox("popupitem.maki: cannot run outside a group", "Error", 0, "");
  22. return;
  23. }
  24. _a = mgrp.getObject("popup.item.checkmark"); a = _a;
  25. _b = mgrp.getObject("popup.item.text"); b = _b;
  26. _c = mgrp.getObject("popup.item.submenuarrow"); c = _c;
  27. background = mgrp.getObject("popup.background"); d = background;
  28. want_checkmark = -1;
  29. want_arrow = -1;
  30. }
  31. mgrp.onNotify(String command, String param, int a, int b) {
  32. if (command == "id") id = StringToInteger(param);
  33. if (command == "arrow") setArrow(StringToInteger(param));
  34. if (command == "checkmark") setCheckMark(StringToInteger(param));
  35. }
  36. ItemSwitcher.onEnterArea() {
  37. background.cancelTarget();
  38. background.setAlpha(255);
  39. }
  40. ItemSwitcher.onLeaveArea() {
  41. background.setTargetA(0);
  42. background.setTargetSpeed(0.25);
  43. background.gotoTarget();
  44. }
  45. ItemSwitcher.onLeftButtonDown(int x, int y) {
  46. mgrp.endModal(id);
  47. }
  48. setArrow(int want) {
  49. if (want_arrow == want) return;
  50. want_arrow = want;
  51. updatePos();
  52. }
  53. setCheckmark(int want) {
  54. if (want_checkmark == want) return;
  55. want_checkmark = want;
  56. updatePos();
  57. }
  58. updatePos() {
  59. int x = MARGIN;
  60. int mx = MARGIN;
  61. if (!want_checkmark) {
  62. if (_a != NULL) {
  63. _a.hide();
  64. }
  65. } else {
  66. if (_a != NULL) {
  67. _a.show();
  68. }
  69. x += CHECKMARK_WIDTH + MARGIN_PRE;
  70. mx += CHECKMARK_WIDTH + MARGIN_PRE;
  71. }
  72. if (!want_arrow) {
  73. if (_c != NULL) {
  74. _c.hide();
  75. }
  76. } else {
  77. if (_c != NULL) {
  78. _c.show();
  79. }
  80. mx += ARROW_WIDTH + MARGIN_POST;
  81. }
  82. mx += MARGIN;
  83. if (_b != NULL) {
  84. _b.setXmlParam("x", IntegerToString(x));
  85. _b.setXmlParam("w", "-" + IntegerToString(mx));
  86. }
  87. }