Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- virtual bool MenuEvent (int mkey, bool fromcontroller)
- {
- int startedAt = mDesc.mSelectedItem;
- switch (mkey)
- {
- case MKEY_Up:
- if (mDesc.mSelectedItem == -1)
- {
- mDesc.mSelectedItem = FirstSelectable();
- break;
- }
- do
- {
- --mDesc.mSelectedItem;
- if (mDesc.mScrollPos > 0 &&
- mDesc.mSelectedItem <= mDesc.mScrollTop + mDesc.mScrollPos)
- {
- mDesc.mScrollPos = MAX(mDesc.mSelectedItem - mDesc.mScrollTop - 1, 0);
- }
- if (mDesc.mSelectedItem < 0)
- {
- // Figure out how many lines of text fit on the menu
- int y = mDesc.mPosition;
- if (y <= 0)
- {
- if (BigFont && mDesc.mTitle.Length() > 0)
- {
- y = -y + BigFont.GetHeight();
- }
- else
- {
- y = -y;
- }
- }
- y *= CleanYfac_1;
- int rowheight = OptionMenuSettings.mLinespacing * CleanYfac_1;
- int maxitems = (screen.GetHeight() - rowheight - y) / rowheight + 1;
- mDesc.mScrollPos = MAX (0, mDesc.mItems.Size() - maxitems + mDesc.mScrollTop);
- mDesc.mSelectedItem = mDesc.mItems.Size()-1;
- }
- }
- while (!mDesc.mItems[mDesc.mSelectedItem].Selectable() && mDesc.mSelectedItem != startedAt);
- break;
- case MKEY_Down:
- if (mDesc.mSelectedItem == -1)
- {
- mDesc.mSelectedItem = FirstSelectable();
- break;
- }
- do
- {
- ++mDesc.mSelectedItem;
- if (CanScrollDown && mDesc.mSelectedItem == VisBottom)
- {
- mDesc.mScrollPos++;
- VisBottom++;
- }
- if (mDesc.mSelectedItem >= mDesc.mItems.Size())
- {
- if (startedAt == -1)
- {
- mDesc.mSelectedItem = -1;
- mDesc.mScrollPos = -1;
- break;
- }
- else
- {
- mDesc.mSelectedItem = 0;
- mDesc.mScrollPos = 0;
- }
- }
- }
- while (!mDesc.mItems[mDesc.mSelectedItem].Selectable() && mDesc.mSelectedItem != startedAt);
- break;
- case MKEY_PageUp:
- if (mDesc.mScrollPos > 0)
- {
- mDesc.mScrollPos -= VisBottom - mDesc.mScrollPos - mDesc.mScrollTop;
- if (mDesc.mScrollPos < 0)
- {
- mDesc.mScrollPos = 0;
- }
- if (mDesc.mSelectedItem != -1)
- {
- mDesc.mSelectedItem = mDesc.mScrollTop + mDesc.mScrollPos + 1;
- while (!mDesc.mItems[mDesc.mSelectedItem].Selectable())
- {
- if (++mDesc.mSelectedItem >= mDesc.mItems.Size())
- {
- mDesc.mSelectedItem = 0;
- }
- }
- if (mDesc.mScrollPos > mDesc.mSelectedItem)
- {
- mDesc.mScrollPos = mDesc.mSelectedItem;
- }
- }
- }
- break;
- case MKEY_PageDown:
- if (CanScrollDown)
- {
- int pagesize = VisBottom - mDesc.mScrollPos - mDesc.mScrollTop;
- mDesc.mScrollPos += pagesize;
- if (mDesc.mScrollPos + mDesc.mScrollTop + pagesize > mDesc.mItems.Size())
- {
- mDesc.mScrollPos = mDesc.mItems.Size() - mDesc.mScrollTop - pagesize;
- }
- if (mDesc.mSelectedItem != -1)
- {
- mDesc.mSelectedItem = mDesc.mScrollTop + mDesc.mScrollPos;
- while (!mDesc.mItems[mDesc.mSelectedItem].Selectable())
- {
- if (++mDesc.mSelectedItem >= mDesc.mItems.Size())
- {
- mDesc.mSelectedItem = 0;
- }
- }
- if (mDesc.mScrollPos > mDesc.mSelectedItem)
- {
- mDesc.mScrollPos = mDesc.mSelectedItem;
- }
- }
- }
- break;
- case MKEY_Back:
- // call your netevent code here
- Close();
- MenuSound (GetCurrentMenu() != null? "menu/backup" : "menu/clear");
- break;
- case MKEY_Enter:
- if (mDesc.mSelectedItem >= 0 && mDesc.mItems[mDesc.mSelectedItem].Activate())
- {
- return true;
- }
- // fall through to default
- default:
- if (mDesc.mSelectedItem >= 0 &&
- mDesc.mItems[mDesc.mSelectedItem].MenuEvent(mkey, fromcontroller)) return true;
- return Super.MenuEvent(mkey, fromcontroller);
- }
- if (mDesc.mSelectedItem != startedAt)
- {
- MenuSound ("menu/cursor");
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement