Advertisement
Chronos_Ouroboros

Untitled

Jan 22nd, 2018
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.59 KB | None | 0 0
  1. virtual bool MenuEvent (int mkey, bool fromcontroller)
  2. {
  3. int startedAt = mDesc.mSelectedItem;
  4.  
  5. switch (mkey)
  6. {
  7. case MKEY_Up:
  8. if (mDesc.mSelectedItem == -1)
  9. {
  10. mDesc.mSelectedItem = FirstSelectable();
  11. break;
  12. }
  13. do
  14. {
  15. --mDesc.mSelectedItem;
  16.  
  17. if (mDesc.mScrollPos > 0 &&
  18. mDesc.mSelectedItem <= mDesc.mScrollTop + mDesc.mScrollPos)
  19. {
  20. mDesc.mScrollPos = MAX(mDesc.mSelectedItem - mDesc.mScrollTop - 1, 0);
  21. }
  22.  
  23. if (mDesc.mSelectedItem < 0)
  24. {
  25. // Figure out how many lines of text fit on the menu
  26. int y = mDesc.mPosition;
  27.  
  28. if (y <= 0)
  29. {
  30. if (BigFont && mDesc.mTitle.Length() > 0)
  31. {
  32. y = -y + BigFont.GetHeight();
  33. }
  34. else
  35. {
  36. y = -y;
  37. }
  38. }
  39. y *= CleanYfac_1;
  40. int rowheight = OptionMenuSettings.mLinespacing * CleanYfac_1;
  41. int maxitems = (screen.GetHeight() - rowheight - y) / rowheight + 1;
  42.  
  43. mDesc.mScrollPos = MAX (0, mDesc.mItems.Size() - maxitems + mDesc.mScrollTop);
  44. mDesc.mSelectedItem = mDesc.mItems.Size()-1;
  45. }
  46. }
  47. while (!mDesc.mItems[mDesc.mSelectedItem].Selectable() && mDesc.mSelectedItem != startedAt);
  48. break;
  49.  
  50. case MKEY_Down:
  51. if (mDesc.mSelectedItem == -1)
  52. {
  53. mDesc.mSelectedItem = FirstSelectable();
  54. break;
  55. }
  56. do
  57. {
  58. ++mDesc.mSelectedItem;
  59.  
  60. if (CanScrollDown && mDesc.mSelectedItem == VisBottom)
  61. {
  62. mDesc.mScrollPos++;
  63. VisBottom++;
  64. }
  65. if (mDesc.mSelectedItem >= mDesc.mItems.Size())
  66. {
  67. if (startedAt == -1)
  68. {
  69. mDesc.mSelectedItem = -1;
  70. mDesc.mScrollPos = -1;
  71. break;
  72. }
  73. else
  74. {
  75. mDesc.mSelectedItem = 0;
  76. mDesc.mScrollPos = 0;
  77. }
  78. }
  79. }
  80. while (!mDesc.mItems[mDesc.mSelectedItem].Selectable() && mDesc.mSelectedItem != startedAt);
  81. break;
  82.  
  83. case MKEY_PageUp:
  84. if (mDesc.mScrollPos > 0)
  85. {
  86. mDesc.mScrollPos -= VisBottom - mDesc.mScrollPos - mDesc.mScrollTop;
  87. if (mDesc.mScrollPos < 0)
  88. {
  89. mDesc.mScrollPos = 0;
  90. }
  91. if (mDesc.mSelectedItem != -1)
  92. {
  93. mDesc.mSelectedItem = mDesc.mScrollTop + mDesc.mScrollPos + 1;
  94. while (!mDesc.mItems[mDesc.mSelectedItem].Selectable())
  95. {
  96. if (++mDesc.mSelectedItem >= mDesc.mItems.Size())
  97. {
  98. mDesc.mSelectedItem = 0;
  99. }
  100. }
  101. if (mDesc.mScrollPos > mDesc.mSelectedItem)
  102. {
  103. mDesc.mScrollPos = mDesc.mSelectedItem;
  104. }
  105. }
  106. }
  107. break;
  108.  
  109. case MKEY_PageDown:
  110. if (CanScrollDown)
  111. {
  112. int pagesize = VisBottom - mDesc.mScrollPos - mDesc.mScrollTop;
  113. mDesc.mScrollPos += pagesize;
  114. if (mDesc.mScrollPos + mDesc.mScrollTop + pagesize > mDesc.mItems.Size())
  115. {
  116. mDesc.mScrollPos = mDesc.mItems.Size() - mDesc.mScrollTop - pagesize;
  117. }
  118. if (mDesc.mSelectedItem != -1)
  119. {
  120. mDesc.mSelectedItem = mDesc.mScrollTop + mDesc.mScrollPos;
  121. while (!mDesc.mItems[mDesc.mSelectedItem].Selectable())
  122. {
  123. if (++mDesc.mSelectedItem >= mDesc.mItems.Size())
  124. {
  125. mDesc.mSelectedItem = 0;
  126. }
  127. }
  128. if (mDesc.mScrollPos > mDesc.mSelectedItem)
  129. {
  130. mDesc.mScrollPos = mDesc.mSelectedItem;
  131. }
  132. }
  133. }
  134. break;
  135. case MKEY_Back:
  136. // call your netevent code here
  137. Close();
  138. MenuSound (GetCurrentMenu() != null? "menu/backup" : "menu/clear");
  139. break;
  140.  
  141. case MKEY_Enter:
  142. if (mDesc.mSelectedItem >= 0 && mDesc.mItems[mDesc.mSelectedItem].Activate())
  143. {
  144. return true;
  145. }
  146. // fall through to default
  147. default:
  148. if (mDesc.mSelectedItem >= 0 &&
  149. mDesc.mItems[mDesc.mSelectedItem].MenuEvent(mkey, fromcontroller)) return true;
  150. return Super.MenuEvent(mkey, fromcontroller);
  151. }
  152.  
  153. if (mDesc.mSelectedItem != startedAt)
  154. {
  155. MenuSound ("menu/cursor");
  156. }
  157. return true;
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement