Beispiel #1
0
        public void AddChild(MenuItem menuItem)
        {
            menuItem.level = level + 1;
            menuItem.parent = this;
            menuItem.position = position;

            menuItem.menuFont = menuFont;
            menuItem.markedMenuTexture = markedMenuTexture;
            menuItem.menuTexture = menuTexture;

            menuItem.position.Y = position.Y + ((children.Count+1) * (menuTexture.Height*1.5f));
            menuItem.position.X = position.X;

            children.Add(menuItem);
            if (children.Count == 1)
            {
                menuItem.currentlyMarked = true;
            }
        }
Beispiel #2
0
        public void HandleInput(InputState inputState)
        {
            if (!showingDescription)
            {
                if (currentlySelected && childSelected == null && children.Count >= 0)
                {

                    if (inputState.IsKeyNewPressed(Keys.Up) && index > 0)
                    {
                        children[index].currentlyMarked = false;
                        index--;
                        children[index].currentlyMarked = true;
                        childMarked = children[index];
                        if (scrollable && !firstIndexSeen && index == 1)
                        {
                            scrollIndex--;
                        }
                    }
                    else if (inputState.IsKeyNewPressed(Keys.Down) && index + 1 < children.Count)
                    {
                        children[index].currentlyMarked = false;
                        index++;
                        children[index].currentlyMarked = true;
                        childMarked = children[index];
                        if (scrollable && !lastIndexSeen && lastDrawnIndex == index)
                        {
                            scrollIndex++;
                        }
                    }
                    else if (inputState.IsKeyNewPressed(Keys.Z))
                    {
                        if (level > 0)
                        {
                            currentlySelected = false;
                            currentlyMarked = true;
                            if (children.Count() > 0)
                            {
                                childMarked.currentlyMarked = false;
                                childSelected = null;
                            }
                            if (parent != null)
                            {
                                parent.childSelected = null;
                                parent.childMarked = parent.children[parent.index];
                            }

                        }
                    }
                    else if (inputState.IsKeyNewPressed(Keys.X) && children.Count() > 0 && !children[index].locked)
                    {
                        currentlySelected = true;
                        currentlyMarked = false;
                        children[index].currentlySelected = true;
                        childSelected = children[index];
                        if (parent != null)
                        {
                            parent.childMarked = null;
                        }
                        childMarked.currentlyMarked = false;
                        childMarked = null;
                        currentLevel++;
                    }
                    else if (inputState.IsKeyNewPressed(Keys.H) && childMarked != null)
                    {
                        showingDescription = true;
                    }
                }
                else if (childSelected != null)
                {
                    childSelected.HandleInput(inputState);
                }
            }
            else
            {
                showingDescription = false;
            }
        }
Beispiel #3
0
 public void Reset()
 {
     index = 0;
     childSelected = null;
     childMarked = null;
     currentlySelected = false;
     currentlyMarked = false;
     foreach (MenuItem child in children)
     {
         child.Reset();
     }
     if (level == 0)
     {
         currentlySelected = true;
         if (children.Count() > 0)
         {
             children[0].currentlyMarked = true;
         }
     }
 }
Beispiel #4
0
 public void DrawChildren(SpriteBatch spriteBatch)
 {
     if (scrollIndex == 0)
     {
         firstIndexSeen = true;
     }
     else if (scrollIndex >0)
     {
         firstIndexSeen = false;
     }
     for (int i = scrollIndex; i < children.Count; i++)
     {
         if (!scrollable)
         {
             if (i == 0 && childMarked == null)
             {
                 children[0].currentlyMarked = true;
                 childMarked = children[0];
             }
             if (children[i].currentlyMarked)
             {
                 spriteBatch.Draw(markedMenuTexture, children[i].position, Color.White);
             }
             else if (children[i].currentlySelected)
             {
                 spriteBatch.Draw(menuTexture, children[i].position, Color.White);
             }
             spriteBatch.DrawString(menuFont, children[i].text, children[i].position, Color.White);
         }
         else
         {
             lastDrawnIndex = i - 1;
             lastIndexSeen = false;
             break;
         }
         lastIndexSeen = true;
         if (scrollIndex > 0)
         {
             firstIndexSeen = false;
         }
     }
     if (childSelected != null)
     {
         childSelected.DrawChildren(spriteBatch);
     }
 }