示例#1
0
文件: Menu.cs 项目: Gevil/Projects
        public void AddMenuItem(string theText, bool isDisabled, bool isSelected, EventHandler theEvent)
        {
            MenuItem aMenuItem = new MenuItem(mContent, theText, Vector2.Zero, theEvent);

            //Center menu item in screen
            Vector2 aLength = aMenuItem.Length();
            mYPosition = (int)(mYPosition - aLength.Y - 10);

            aMenuItem.Position = new Vector2((mViewport.Width / 2) - (aLength.X / 2), mYPosition);

            if (isSelected == true)
            {
                mCurrentMenuItem = mMenuItems.Count;

                foreach (MenuItem aMenu in mMenuItems.Values)
                {
                    aMenu.Selected = false;
                }
            }

            aMenuItem.Selected = isSelected;
            aMenuItem.Disabled = isDisabled;

            mMenuItems.Add(mMenuItems.Count, aMenuItem);
        }
示例#2
0
文件: Menu.cs 项目: Gevil/Projects
        public void Update(GameTime theGameTime)
        {
            mInput.BeginUpdate();

            if (mMenuItems.Count != 0)
            {

                if (mInput.AWithRelease())
                {
                    mSelect.Play();

                    SelectedItem = mMenuItems[mCurrentMenuItem];
                    if (mMenuItems[mCurrentMenuItem].Event != null)
                    {
                        //SelectedItem = null;
                        mMenuItems[mCurrentMenuItem].Event.Invoke(this, new EventArgs());
                        SelectedItem = null;
                    }
                }

                if (SelectedItem == null)
                {
                    int aPreviousMenuItem = mCurrentMenuItem;
                    mMenuItems[mCurrentMenuItem].Selected = false;

                    if (mInput.DownWithRelease())
                    {
                        do
                        {
                            mCurrentMenuItem -= 1;
                            if (mCurrentMenuItem < 0)
                            {
                                mCurrentMenuItem = aPreviousMenuItem;
                                break;
                            }
                        } while (mMenuItems[mCurrentMenuItem].Disabled == true);

                    }

                    if (mInput.UpWithRelease())
                    {
                        do
                        {
                            mCurrentMenuItem += 1;
                            if (mCurrentMenuItem > mMenuItems.Count - 1)
                            {
                                mCurrentMenuItem = aPreviousMenuItem;
                                break;
                            }
                        } while (mMenuItems[mCurrentMenuItem].Disabled == true);
                    }

                    mCurrentMenuItem = (int)MathHelper.Clamp(mCurrentMenuItem, 0, mMenuItems.Count - 1);
                    mMenuItems[mCurrentMenuItem].Selected = true;

                    if (mCurrentMenuItem != aPreviousMenuItem)
                    {
                        //if (mMenuSelect.IsCreated == false)
                        //{
                        //    mMenuSelect = mSoundBank.GetCue("MenuSelect");
                        //}
                        mMenuSelect.Play();
                    }
                }
            }

            foreach (MenuItem aMenuItem in mMenuItems.Values)
            {
                aMenuItem.Update(theGameTime);
            }

            mInput.EndUpdate();
        }