Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Scrolling menu

c# xna scrolling menu game

This topic has been archived. This means that you cannot reply to this topic.
No replies to this topic

#1 sonar87

sonar87

    CC Newcomer

  • Member
  • PipPip
  • 20 posts

Posted 19 August 2014 - 07:51 PM

I'm trying to make a scrolling menu for picking options in a dialog tree like:

 

(text bar:)

--------------------------------------------------------------------------------------------

> some option 1

> another option

> option 3

> fourth thing to do/say

--------------------------------------------------------------------------------------------

 

Bold, being the currently  selected thing. Then when you hit down again, it will scroll down one, and on to the end.

 

--------------------------------------------------------------------------------------------

> another option

> option 3

> fourth thing to do/say

> thing #5

--------------------------------------------------------------------------------------------

 

I just can't get it to work for some reason. I've been at this for hours, having an offset variable that was updated in the input section, then added to the y value of where to place text, tried doing stuff just in the draw section. The first thing worked half of the time the way I did it but... I'd post various things I tried in code, but I've done so many. Here's the code for drawing the selections and box they're in and the input section. If someone could tell what to do to make this work, or steer me onto the right path and help along the way, that would be great. It's driving me nuts because it seems like the simplest of things, but for some reason I guess I'm just not thinking bout it right today. :/

 

 

Drawn section:

            if (ShowingOptions)
            {
                spriteB.Draw(Game1.Blank, new Rectangle(boxstartx, boxstarty, boxwidth, boxheight), Color.Black);

                for (int i = 0, y = 0; i < CurrentDialogOptions.choices.Length; i++)
                {
                    if (Utilities.ScriptParser.CheckCondition(CurrentDialogOptions.choices[i].Condition))
                    {
                        Utilities.Text.DrawTextInRectangle(spriteB, spriteF["Pescadero12"], CurrentDialogOptions.choices[i].Text,
                            sbindex, new Rectangle(boxstartx, boxstarty + (int)spriteF["Pescadero12"].MeasureString("|").Y *
                                y,
                                boxwidth, boxheight), Utilities.Text.VariableTextColor(i, doptionchoice));

                        y++;
                    }

                }
            }

Input section:

            if (KeyCheck(Keys.Down) || KeyCheck(Keys.S))
            {
                counter = 1;

                if (Screens.GameScreen.doptionchoice < Screens.GameScreen.CurrentDialogOptions.choices.Length - 1)
                {
                    while (!Utilities.ScriptParser.CheckCondition(Screens.GameScreen.CurrentDialogOptions.choices[
                        Screens.GameScreen.doptionchoice + counter].Condition))
                    {
                        counter++;

                        if (Screens.GameScreen.doptionchoice + counter >= Screens.GameScreen.CurrentDialogOptions.choices.Length)
                        {
                            counter = 0;
                            break;
                        }
                    }

                    Screens.GameScreen.doptionchoice += counter;
                    counter = 0;
                }
 
            }
            else if (KeyCheck(Keys.Up) || KeyCheck(Keys.W))
            {
                counter = -1;

                if (Screens.GameScreen.doptionchoice > 0)
                {
                    while (!Utilities.ScriptParser.CheckCondition(Screens.GameScreen.CurrentDialogOptions.choices[
                        Screens.GameScreen.doptionchoice + counter].Condition))
                    {
                        counter--;

                        if (Screens.GameScreen.doptionchoice + counter < 0)
                        {
                            counter = 0;
                            break;
                        }
                    }

                    Screens.GameScreen.doptionchoice += counter;
                    counter = 0;
                }
            }