示例#1
0
        public void LoadFromFile(ContentManager content, string menusDefinitionFile)
        {
            using (StreamReader reader = new StreamReader(menusDefinitionFile))
            {
                while (!reader.EndOfStream)
                {
                    string line = reader.ReadLine().Trim();

                    if (string.IsNullOrEmpty(line))
                    {
                        continue;
                    }

                    if (line.Contains("[SplashScreen]"))
                    {
                        MenuScreen splash      = new MenuScreen();
                        string     textureName = reader.ReadLine().Trim();
                        splash.LoadContent(content, textureName);
                        string delay = reader.ReadLine().Trim();
                        if (!string.IsNullOrEmpty(delay))
                        {
                            splash.Delay = (int.Parse(delay) > 0) ? (int.Parse(delay)) : -1;
                        }
                        splash.ScreenType = ScreenType.SplashScreen;
                        AddMenuScreen(splash);
                    }
                    else if (line.Contains("[ControlsScreen]"))
                    {
                        MenuScreen control     = new MenuScreen();
                        string     textureName = reader.ReadLine().Trim();
                        control.LoadContent(content, textureName);
                        string delay = reader.ReadLine().Trim();
                        if (!string.IsNullOrEmpty(delay))
                        {
                            control.Delay = (int.Parse(delay) > 0) ? (int.Parse(delay)) : -1;
                        }
                        control.ScreenType = ScreenType.ControlsScreen;
                        AddMenuScreen(control);
                    }
                    else if (line.Contains("[WinScreen]"))
                    {
                        MenuScreen win         = new MenuScreen();
                        string     textureName = reader.ReadLine().Trim();
                        win.LoadContent(content, textureName);
                        string delay = reader.ReadLine().Trim();
                        if (!string.IsNullOrEmpty(delay))
                        {
                            win.Delay = (int.Parse(delay) > 0) ? (int.Parse(delay)) : -1;
                        }
                        win.ScreenType = ScreenType.WinScreen;
                        AddMenuScreen(win);
                    }
                    else if (line.Contains("[LooseScreen]"))
                    {
                        MenuScreen loose       = new MenuScreen();
                        string     textureName = reader.ReadLine().Trim();
                        loose.LoadContent(content, textureName);
                        string delay = reader.ReadLine().Trim();
                        if (!string.IsNullOrEmpty(delay))
                        {
                            loose.Delay = (int.Parse(delay) > 0) ? (int.Parse(delay)) : -1;
                        }
                        loose.ScreenType = ScreenType.LooseScreen;
                        AddMenuScreen(loose);
                    }
                    else if (line.Contains("[None]"))
                    {
                        MenuScreen none        = new MenuScreen();
                        string     textureName = reader.ReadLine().Trim();
                        none.LoadContent(content, textureName);
                        string delay = reader.ReadLine().Trim();
                        if (!string.IsNullOrEmpty(delay))
                        {
                            none.Delay = (int.Parse(delay) > 0) ? (int.Parse(delay)) : -1;
                        }
                        none.ScreenType = ScreenType.None;
                        AddMenuScreen(none);
                    }
                }
            }
        }
示例#2
0
 public void AddMenuScreen(MenuScreen screen)
 {
     menus.Add(screen);
 }