Jump to content
  • Advertisement
Sign in to follow this  
Pedro Alves

I Can´t Draw I New Gui

This topic is 825 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i can´t put draw a gui in new gamestat i using monogame with empty keys librarys

is my code

when i exute don´t draw the any thing

SplashScreen class

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


namespace CatRockets
{
   
    public class SplashScreen : GameScreen
    {

       
        public Image Image;
    
        private UIRoot root;

        private BasicUIViewModel viewModel;
        public override void LoadContent()
        {
            base.LoadContent();
            root = new Root();
            // root.MaxHeight = 500;
            //root.MaxWidth = 600;

            // root.VerticalAlignment = VerticalAlignment.Bottom;
            viewModel = new BasicUIViewModel();
            root.DataContext = viewModel;
            Image.LoadContent();
        }

        public override void UnloadContent()
        {
            base.UnloadContent();
          Image.UnloadContent();
        }

        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
           Image.Update(gameTime);
            root.UpdateInput(gameTime.ElapsedGameTime.TotalMilliseconds);
            root.UpdateLayout(gameTime.ElapsedGameTime.TotalMilliseconds);
            if (InputManager.Instance.KeyPressed(Keys.Enter,Keys.Z))
                ScreenManager.Instance.ChangeScreens("TitleScreen");
            

        }

        public override void Draw(SpriteBatch spriteBatch)
        {
            Image.Draw(spriteBatch);
          

        }
    }
}

my game class

sing 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;

        private UIRoot root;
        
        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()
        {
            
            SpriteFont font = Content.Load<SpriteFont>("Segoe_UI_15_Bold");
            FontManager.DefaultFont = Engine.Instance.Renderer.CreateFont(font);
            Viewport viewport = GraphicsDevice.Viewport;
            root = new Root();
         // root.MaxHeight = 500;
            //root.MaxWidth = 600;
           
           // root.VerticalAlignment = VerticalAlignment.Bottom;
            viewModel = new BasicUIViewModel();



            viewModel.ButtonCommand = new RelayCommand(new Action<object>(Login));
            //  object login = viewModel.ButtonCommand;
            //lo
            viewModel.Options = new RelayCommand(new Action<object>(Options));
            viewModel.Exit = new RelayCommand(new Action<object>(ExitGame));

            //root.RenderPosition(200,300);



            root.DataContext = viewModel;
           
            FontManager.Instance.LoadFonts(Content);
         


            spriteBatch = new SpriteBatch(GraphicsDevice);
             ScreenManager.Instance.GraphicsDevice = GraphicsDevice;
             ScreenManager.Instance.SpriteBatch = spriteBatch;
             ScreenManager.Instance.LoadContent(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)
        {
           

            //          
            ScreenManager.Instance.Update(gameTime);
            // TODO: Add your update logic here
           root.UpdateInput(gameTime.ElapsedGameTime.TotalMilliseconds);
            root.UpdateLayout(gameTime.ElapsedGameTime.TotalMilliseconds);
            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);
           
               
            
            root.Draw(gameTime.ElapsedGameTime.TotalMilliseconds);

            if (result == true)
            {
                GraphicsDevice.Clear(Color.CornflowerBlue);
                spriteBatch.Begin();
                ScreenManager.Instance.Draw(spriteBatch);
              //  root.Unloaded+=root.Unloaded;
                // TODO: Add your drawing code here
                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;
            

                        }

              
        }
        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)


            //   Password.ToString();
            if (obj == null)
            {
         
               root = new options();
               
        
            }


        }
        
    }
}

Edited by Landi20

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!