Example of MVVM View Model
Inheritance: ViewModelBase
コード例 #1
0
ファイル: Game1.cs プロジェクト: EmptyKeys/UI_Examples
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            this.IsMouseVisible = true;

            SpriteFont font = Content.Load<SpriteFont>("Segoe_UI_10_Regular");
            FontManager.DefaultFont = Engine.Instance.Renderer.CreateFont(font);
            Viewport viewport = GraphicsDevice.Viewport;
            basicUI = new BasicUI(viewport.Width, viewport.Height);
            viewModel = new BasicUIViewModel();
            viewModel.Tetris = new TetrisController(basicUI.TetrisContainer, basicUI.TetrisNextContainer);
            basicUI.DataContext = viewModel;
            debug = new DebugViewModel(basicUI);

            FontManager.Instance.LoadFonts(Content);
            ImageManager.Instance.LoadImages(Content);
            SoundManager.Instance.LoadSounds(Content);

            RelayCommand command = new RelayCommand(new Action<object>(ExitEvent));

            KeyBinding keyBinding = new KeyBinding(command, KeyCode.Escape, ModifierKeys.None);
            basicUI.InputBindings.Add(keyBinding);

            RelayCommand tetrisLeft = new RelayCommand(new Action<object>(OnLeft));
            KeyBinding left = new KeyBinding(tetrisLeft, KeyCode.A, ModifierKeys.None);
            basicUI.InputBindings.Add(left);

            RelayCommand tetrisRight = new RelayCommand(new Action<object>(OnRight));
            KeyBinding right = new KeyBinding(tetrisRight, KeyCode.D, ModifierKeys.None);
            basicUI.InputBindings.Add(right);

            RelayCommand tetrisDown = new RelayCommand(new Action<object>(OnDown));
            KeyBinding down = new KeyBinding(tetrisDown, KeyCode.S, ModifierKeys.None);
            basicUI.InputBindings.Add(down);

            RelayCommand tetrisRotate = new RelayCommand(new Action<object>(OnRotate));
            KeyBinding rotate = new KeyBinding(tetrisRotate, KeyCode.W, ModifierKeys.None);
            basicUI.InputBindings.Add(rotate);
        }
コード例 #2
0
ファイル: Game1.cs プロジェクト: EmptyKeys/UI_Examples
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            this.IsMouseVisible = true;

            SpriteFont font = Content.Load<SpriteFont>("Segoe_UI_10_Regular");
            FontManager.DefaultFont = Engine.Instance.Renderer.CreateFont(font);
            Viewport viewport = GraphicsDevice.Viewport;
            basicUI = new BasicUI(viewport.Width, viewport.Height);
            viewModel = new BasicUIViewModel();
            viewModel.Tetris = new TetrisController(basicUI.TetrisContainer, basicUI.TetrisNextContainer);
            basicUI.DataContext = viewModel;
            debug = new DebugViewModel(basicUI);

            FontManager.Instance.LoadFonts(Content);
            ImageManager.Instance.LoadImages(Content);
            SoundManager.Instance.LoadSounds(Content);
            EffectManager.Instance.LoadEffects(Content);

            RelayCommand command = new RelayCommand(new Action<object>(ExitEvent));

            KeyBinding keyBinding = new KeyBinding(command, KeyCode.Escape, ModifierKeys.None);
            basicUI.InputBindings.Add(keyBinding);

            RelayCommand tetrisLeft = new RelayCommand(new Action<object>(OnLeft));
            KeyBinding left = new KeyBinding(tetrisLeft, KeyCode.A, ModifierKeys.None);
            basicUI.InputBindings.Add(left);

            RelayCommand tetrisRight = new RelayCommand(new Action<object>(OnRight));
            KeyBinding right = new KeyBinding(tetrisRight, KeyCode.D, ModifierKeys.None);
            basicUI.InputBindings.Add(right);

            RelayCommand tetrisDown = new RelayCommand(new Action<object>(OnDown));
            KeyBinding down = new KeyBinding(tetrisDown, KeyCode.S, ModifierKeys.None);
            basicUI.InputBindings.Add(down);

            RelayCommand tetrisRotate = new RelayCommand(new Action<object>(OnRotate));
            KeyBinding rotate = new KeyBinding(tetrisRotate, KeyCode.W, ModifierKeys.None);
            basicUI.InputBindings.Add(rotate);

            RelayCommand resizeCommand = new RelayCommand(new Action<object>(OnResize));
            KeyBinding resizeBinding = new KeyBinding(resizeCommand, KeyCode.R, ModifierKeys.Control);
            basicUI.InputBindings.Add(resizeBinding);

            renderTarget = new RenderTarget2D(GraphicsDevice,
                100,
                100,
                false,
                GraphicsDevice.PresentationParameters.BackBufferFormat,
                DepthFormat.Depth24Stencil8);

            viewModel.RenderTargetSource = new BitmapImage();
            var texture = Engine.Instance.Renderer.CreateTexture(renderTarget);
            viewModel.RenderTargetSource.Texture = texture;
        }
コード例 #3
0
ファイル: Game1.cs プロジェクト: HarkerGameDev/TheGame
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            Content.RootDirectory = "Content";
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO figure out why multiple songs do not work well with muting
            // Load the songs
            //songs = new List<Song>();
            //songs.Add(Content.Load<Song>("Music/Air Skate"));
            //songs.Add(Content.Load<Song>("Music/Main Menu"));
            //songs.Add(Content.Load<Song>("Music/Character Select"));
            Song song = Content.Load<Song>("Music/Air Skate");
            MediaPlayer.Play(song);
            MediaPlayer.IsRepeating = true;
            MediaPlayer.Volume = GameData.VOLUME;
            MediaPlayer.IsMuted = GameData.MUTED;

            // Set up user interface
            SpriteFont font = Content.Load<SpriteFont>("Fonts/Segoe_UI_15_Bold");
            FontManager.DefaultFont = Engine.Instance.Renderer.CreateFont(font);
            viewModel = new BasicUIViewModel();
            FontManager.Instance.LoadFonts(Content, "Fonts");

            StringBuilder builder = new StringBuilder();
            for (int i = 0; i < playerControls.Count; i++)
            {
                builder.Append("Player ").AppendLine((i + 1).ToString())
                    .AppendLine(playerControls[i].ToString());
            }
            viewModel.ControlsText = builder.ToString();
            Console.WriteLine(builder.ToString());
            //viewModel.ControlsText = "Hello!\nWhoo!!";

            viewModel.MaxPlayers = GameData.MAX_PLAYERS;
            viewModel.LevelValue = GameData.LEVEL_FILE;
            viewModel.PlayerValue = GameData.DEFAULT_PLAYERS;

            LoadUI(Menu.Main);

            //InitializePlayers();

            // Use this to draw any rectangles
            whiteRect = new Texture2D(GraphicsDevice, 1, 1);
            whiteRect.SetData(new[] { Color.White });

            smear = Content.Load<Texture2D>("Art/smear");

            // Load assets in the Content Manager
            //background = Content.Load<Texture2D>("Art/skyscrapers");
            LoadBackground(2);
            fontSmall = Content.Load<SpriteFont>("Fonts/Score");
            fontBig = Content.Load<SpriteFont>("Fonts/ScoreBig");

            // Create objects
            platforms = new List<Platform>();
            particles = new List<Particle>();
            obstacles = new List<Obstacle>();
            drops = new List<Drop>();
            world = new World(this);

            // Initialize camera
            int width = graphics.GraphicsDevice.Viewport.Width;
            int height = graphics.GraphicsDevice.Viewport.Height;
            cameraBounds = new Rectangle((int)(width * GameData.SCREEN_LEFT), (int)(height * GameData.SCREEN_TOP),
                (int)(width * (GameData.SCREEN_RIGHT - GameData.SCREEN_LEFT)), (int)(height * (1 - 2 * GameData.SCREEN_TOP)));
            screenCenter = cameraBounds.Center.ToVector2();

            // Define particles
            List<Texture2D> particleTextures = new List<Texture2D>();
            particleTextures.Add(Content.Load<Texture2D>("Particles/circle"));
            particleTextures.Add(Content.Load<Texture2D>("Particles/star"));
            particleTextures.Add(Content.Load<Texture2D>("Particles/diamond"));

            particleEmitter = new ParticleEmitter(particleTextures, GameData.PLAYER_START, 1f);
            particleEmitter.VelVarX = particleEmitter.VelVarY = 5f;
            particleEmitter.LiveTime = 8f;

            GameData.SLIDE_TEXTURES = new List<Texture2D>();
            GameData.SLIDE_TEXTURES.Add(Content.Load<Texture2D>("Particles/smoke"));

            GameData.JETPACK_TEXTURES = new List<Texture2D>();
            GameData.JETPACK_TEXTURES.Add(Content.Load<Texture2D>("Particles/gradient"));

            GameData.ROCKET_TEXTURES = new List<Texture2D>();
            GameData.ROCKET_TEXTURES.Add(Content.Load<Texture2D>("Particles/gradient"));
        }