1 Replies - 1092 Views - Last Post: 23 July 2016 - 04:34 PM

#1 Lancha  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 31-July 13

can draw new gui

Posted 18 July 2016 - 09:47 AM

when i change the gamestat i can put my game draw a new gui when i click in login i can´t find the problem
this is my code gameclass
using System;
using EmptyKeys.UserInterface;
using EmptyKeys.UserInterface.Controls;
using EmptyKeys.UserInterface.Generated;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using EmptyKeys.UserInterface.Input;
using GameLibrary;
using Microsoft.Xna.Framework.Storage;
using GameLibrary.Views;


namespace CatRockets
{
    /// <summary>
    /// This is the main type for your game.
    /// </summary>
    public class Game1 : Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        private int nativeScreenWidth;
        private int nativeScreenHeight;
        private bool result;
        int _total_frames = 0;
        float _elapsed_time = 0.0f;
        int _fps = 0;
        private UIRoot root;
        private UserControl p;
       
        
        SpriteFont font;
        private BasicUIViewModel viewModel;
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
          graphics.DeviceCreated += graphics_DeviceCreated;
            graphics.PreparingDeviceSettings += graphics_PreparingDeviceSettings;
            Content.RootDirectory = "Content";
            IsMouseVisible = true;
        }

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
           graphics.PreferredBackBufferWidth = (int)ScreenManager.Instance.Dimension.X;
           graphics.PreferredBackBufferHeight = (int)ScreenManager.Instance.Dimension.Y;
            graphics.ApplyChanges();
            // TODO: Add your initialization logic here

            base.Initialize();
        }
        void graphics_DeviceCreated(object sender, EventArgs e)
        {
            Engine engine = new MonoGameEngine(GraphicsDevice, nativeScreenWidth, nativeScreenHeight);
        }
        private void graphics_PreparingDeviceSettings(object sender, PreparingDeviceSettingsEventArgs e)
        {
            nativeScreenWidth = graphics.PreferredBackBufferWidth;
            nativeScreenHeight = graphics.PreferredBackBufferHeight;

            graphics.PreferredBackBufferWidth = 800;
            graphics.PreferredBackBufferHeight = 600;
            graphics.PreferMultiSampling = true;
            graphics.GraphicsProfile = GraphicsProfile.HiDef;
            graphics.SynchronizeWithVerticalRetrace = true;
            graphics.PreferredDepthStencilFormat = DepthFormat.Depth24Stencil8;
            e.GraphicsDeviceInformation.PresentationParameters.MultiSampleCount = 16;
        }
       
       /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
             spriteBatch = new SpriteBatch(GraphicsDevice);
             ScreenManager.Instance.GraphicsDevice = GraphicsDevice;
             ScreenManager.Instance.SpriteBatch = spriteBatch;
             ScreenManager.Instance.LoadContent(Content);
          font = Content.Load<SpriteFont>("Segoe_UI_15_Bold");
            FontManager.DefaultFont = Engine.Instance.Renderer.CreateFont(font);
            Viewport viewport = GraphicsDevice.Viewport;
            root = new Root();
            p = new Options();
            viewModel = new BasicUIViewModel();
         

            viewModel.ButtonCommand = new RelayCommand(new Action<object>(Login));
          viewModel.Options = new RelayCommand(new Action<object>(Options));
            viewModel.Exit = new RelayCommand(new Action<object>(ExitGame));
            root.DataContext = viewModel;
           
            FontManager.Instance.LoadFonts(Content);
         


           
           

            // TODO: use this.Content to load your game content here
        }
       
        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// game-specific content.
        /// </summary>
        protected override void UnloadContent()

        {
         ScreenManager.Instance.UnloadContent();            // TODO: Unload any non ContentManager content here
        }

        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {

            _elapsed_time += (float)gameTime.ElapsedGameTime.TotalMilliseconds;

            // 1 Second has passed
            if (_elapsed_time >= 1000.0f)
            {
                _fps = _total_frames;
                _total_frames = 0;
                _elapsed_time = 0;
            }

            // 
            root.UpdateInput(gameTime.ElapsedGameTime.TotalMilliseconds);
            root.UpdateLayout(gameTime.ElapsedGameTime.TotalMilliseconds);
            ScreenManager.Instance.Update(gameTime);
            // TODO: Add your update logic here
         
            base.Update(gameTime);
        }

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
           GraphicsDevice.Clear(Color.CornflowerBlue);

            _total_frames++;

            spriteBatch.Begin();
            spriteBatch.DrawString(font, string.Format("FPS={0}", _fps),
                new Vector2(10.0f, 20.0f), Color.White);
           
            spriteBatch.End();
            root.Draw(gameTime.ElapsedGameTime.TotalMilliseconds);
            
            if (result == true)
            {
                GraphicsDevice.Clear(Color.CornflowerBlue);
                spriteBatch.Begin();
                ScreenManager.Instance.Draw(spriteBatch);
            
             
                spriteBatch.End();
            }
            /*  */
            base.Draw(gameTime);
        }
        private void Login(object obj)
        {

           // System.Console.Write("object " + obj);

            // if(obj !=null)

            string username = viewModel.TextBoxText.ToString();
            string password = viewModel.Password.ToString();

           // System.Console.Write("Username: " + username + " " + "password " + password + "\n");

            if (username == string.Empty && password == string.Empty)
            {
                MessageBox.Show("Utilizador e Senha estao vazios ", null, false);
                viewModel.TextBoxText = string.Empty;
                viewModel.Password = string.Empty;
            }
          else if (username == string.Empty)
            {
                MessageBox.Show("Utilizador esta vazio", null, false);
                viewModel.TextBoxText = string.Empty;
                viewModel.Password = string.Empty;

            }
            else if (password == string.Empty)
            {
                MessageBox.Show("Senha esta vazio", null, false);
                viewModel.TextBoxText = string.Empty;
                viewModel.Password = string.Empty;

            }
           
            else 
             {
        
                result = true;
                viewModel.TextBoxText = string.Empty;
                viewModel.Password = string.Empty;


            }

              
        }
        private void ExitGame(object obj)

        {
            
            System.Windows.Forms.DialogResult resultado =System.Windows.Forms.MessageBox.Show("Quer Sair do Jogo", "Aviso", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Information);

            switch (resultado)

            {
                case System.Windows.Forms.DialogResult.No:

                    break;

             
              

                case System.Windows.Forms.DialogResult.Yes: Exit();

                    break;

     

            }


          


        }
   private void Options(object obj)

        {

            System.Console.Write("object " + obj);

         //   if (obj == null)
           // {
                GraphicsDevice.Clear(Color.CornflowerBlue);
            //   viewModel.user
            //
            //MessageBox.Show("OPções", null, false);
            p = new UserControl();
            p.Visibility = Visibility.Visible;
           
         //   }


        }
       
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using EmptyKeys.UserInterface.Generated;
using GameLibrary.Views;
using EmptyKeys.UserInterface.Controls;

namespace CatRockets
{
   public class TitleScreen :GameScreen
    {
        MenuManager menuManager;
        public GameTime gametime;
        private double ola;
        private UIRoot root;
        Viewport viewport;
        private BasicUIViewModel viewModel;
        public TitleScreen()
        {
           // ola = gametime.ElapsedGameTime.Milliseconds;
            menuManager = new MenuManager();
       
        }
        public override void LoadContent()
        {
            base.LoadContent();
            root = new Root();
            viewModel = new BasicUIViewModel();
            root.DataContext = viewModel;
            root.Visibility.Equals(true);
            menuManager.LoadContent("Load/Menu/TitleMenu.xml");
        }
        public override void UnloadContent()
        {
            base.UnloadContent();
            menuManager.UnloadContent();
        }
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
            menuManager.Update(gameTime);
            root.UpdateInput(gameTime.ElapsedGameTime.TotalMilliseconds);
            root.UpdateLayout(gameTime.ElapsedGameTime.TotalMilliseconds);
        }
        public override void Draw(SpriteBatch spriteBatch)
        {
            base.Draw(spriteBatch);
            menuManager.Draw(spriteBatch);
            root.Draw(ola);
           
        }
    }
}



Is This A Good Question/Topic? 0
  • +

Replies To: can draw new gui

#2 basteagui  Icon User is offline

  • D.I.C Head

Reputation: 14
  • View blog
  • Posts: 60
  • Joined: 08-September 13

Re: can draw new gui

Posted 23 July 2016 - 04:34 PM

i'm sorry but i don't really understand what problem you're having so i cannot really help you.

could you explain to me a little bit more clear what you want to make happen and how you're trying to do it?

it's hard to get that from looking at code unless i reaally look at it you know?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1