sharpdx / SharpDX-Samples

Official repository for all SharpDX Samples
346 stars 222 forks source link

change screen #16

Closed PedroAlvesq closed 9 years ago

PedroAlvesq commented 9 years ago

i some issuos when i try change my screen the graphics is very poor and have somelag maybe my change screen method is not correctly to do it this is my code

using System;
using SharpDX;
using SharpDX.Toolkit;
using System.Collections.Generic;
using SharpDX.Toolkit.Input;
using TomShane.Neoforce.Controls;
using SharpDX.Direct3D;
using SharpDX.Direct3D11;
using SharpDX.Toolkit.Content;

namespace TomShane.Neoforce.Central
{
    using SharpDX.Toolkit.Graphics;

    /// <summary>
    /// Simple MiniCube application using SharpDX.Toolkit.
    /// The purpose of this application is to show a rotating cube using <see cref="BasicEffect"/>.
    /// </summary>
    public class Gamer : Game
    {
        private Manager NeoManager;
       private GraphicsDeviceManager graphicsDeviceManager;

        private readonly Login _Login;

        public Gamer()
        {
            // Creates a graphics manager. This is mandatory.

            graphicsDeviceManager = new GraphicsDeviceManager(this);
            graphicsDeviceManager.PreferredBackBufferWidth = 1280;
            graphicsDeviceManager.PreferredBackBufferHeight = 800;
            NeoManager = new Manager(this);
            IsMouseVisible = true;
            _Login = new Login(this, NeoManager,graphicsDeviceManager);//this how i change the screen
            _Login.Visible = true;
           // graphicsDeviceManager.IsFullScreen = true;
           // graphicsDeviceManager.re

            Content.RootDirectory = "Content";

        }

        protected override void LoadContent()
        {

            base.LoadContent();
        }

        protected override void Initialize()
        {

            NeoManager.Initialize();
            base.Initialize();

            Window.Title = "Firstgame";
        }

        protected override void Update(GameTime gameTime)
        {
            NeoManager.Update(gameTime);
            base.Update(gameTime);

        }

        protected override void Draw(GameTime gameTime)
        {

            base.Draw(gameTime);     
        }
    }
}
using SharpDX.Toolkit.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using TomShane.Neoforce.Controls;
using SharpDX.XInput;

namespace TomShane.Neoforce.Central
{

    internal sealed class Login : GameSystem
    {
        private Manager NeoManager;
        private Window window;
        private LoginClient cliente;
        string user = null;
        string userPassword = null;
        private Button virtualkeyboard = null;
        public Button LoginButton { get { return btnApply; } }
        public Button ExitButton { get { return btnExit; } }
        public string Username { get { return txusername.Text; } }
        public string Password { get { return txpassword.Text; } }
        private Button options { get { return option; } }
        private SideBarPanel pnlRes = null;
        private Button btnApply = null;
        private Button btnExit = null;
        private Button option = null;
        private TextBox txusername = null;
        private TextBox txpassword = null;
        private Label lbusername = null;
        private Label lbpassword = null;
        private GraphicsDeviceManager graphic;
        public Login(Game game,Manager neo, GraphicsDeviceManager gra)
            : base(game)
        {
            Game _game = game;
            NeoManager = neo;
            graphic = gra;
            cliente = new LoginClient();

            // this game system has something to draw - enable drawing by default
            // this can be disabled to make objects drawn by this system disappear
            Visible = true;

            // this game system has logic that needs to be updated - enable update by default
            // this can be disabled to simulate a "pause" in logic update
            Enabled = true;

            // add the system itself to the systems list, so that it will get initialized and processed properly
            // this can be done after game initialization - the Game class supports adding and removing of game systems dynamically
            _game.GameSystems.Add(this);
        }

        /// <summary>
        /// Initialize here anything that depends on other services
        /// </summary>
        public override void Initialize()
        {

          //  NeoManager.Initialize();

            base.Initialize();

            // get the camera service from service registry

        }

        /// <summary>
        /// Load all graphics content here.
        /// </summary>
        protected override void LoadContent()
        {
            base.LoadContent();
            window = new Window(NeoManager);
            window.Init();
            window.Text = "Login";
            window.Width = 420;
            window.Height = 243;
            window.Center();
            window.Visible = true;
            window.CloseButtonVisible = false;
            window.Resizable = false;
            window.Movable = false;
            NeoManager.Add(window);
            window.IconVisible = false;
            InitRes();
            // initialize the basic effect (shader) to draw the geometry, the BasicEffect class is similar to one from XNA

        }

        /// <summary>
        /// Draw the scene content.
        /// </summary>
        /// <param name="gameTime">Structure containing information about elapsed game time.</param>

        /// <summary>
        /// Update the scene logic.
        /// </summary>
        /// <param name="gameTime">Structure containing information about elapsed game time.</param>
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
          //  NeoManager.Update(gameTime);

            // get the total elapsed seconds since the start of the game

        }
        public override void Draw(GameTime gameTime)
        {

          NeoManager.BeginDraw(gameTime);
         SharpDX.Toolkit.Graphics.BlendState graphics = GraphicsDevice.BlendStates.Opaque;
           SharpDX.Toolkit.Graphics.DepthStencilState graphics1 = GraphicsDevice.DepthStencilStates.Default;
         // GraphicsDevice.Clear(SharpDX.Color.CornflowerBlue);
           // GraphicsDevice.BlendStates = BlendStateCollection.;
            //GraphicsDevice.BlendStates = BlendingMode.Default;
           // GraphicsDevice.DepthStencilStates = DepthStencilState.Default;
           // device.Clear(Color.CornflowerBlue);
          //  GraphicsDevice.SamplerStates[0] = new(GraphicsDevice, SamplerState);
        NeoManager.EndDraw();
            base.Draw(gameTime);

            //NeoManager.EndDraw();
            // set the parameters for cube drawing and draw it using the basic effect

        }
        private void InitRes()
        {

            pnlRes = new SideBarPanel(NeoManager);
            pnlRes.Init();
            pnlRes.Passive = true;
            pnlRes.Parent = window;
            pnlRes.Left = 0;
            pnlRes.Top = 0;
            pnlRes.Width = 410;
            pnlRes.Height = 210;
            pnlRes.CanFocus = false;
        //    pnlRes.Color = new Color(12,12,13);

            //   Manager.Add(pnlRes);
            virtualkeyboard = new Button(NeoManager);
            virtualkeyboard.Init();
            virtualkeyboard.Width = 40;
            virtualkeyboard.Height = 30;
            virtualkeyboard.Parent = pnlRes;
            virtualkeyboard.Top = pnlRes.Left + 10;
            virtualkeyboard.Left = pnlRes.Top + 283;
         //   virtualkeyboard.Draw(new Vector2(12, 13));
            //virtualkeyboard.TextColor = new SharpDX.Color(20, 22, 23);
            //  virtualkeyboard.Text = "Teclado";

            //    virtualkeyboard.Glyph = new Glyph()
            virtualkeyboard.Glyph = new Glyph(NeoManager.Content.Load<SharpDX.Toolkit.Graphics.Texture2D>("Content\\Images\\teclado"));
            lbusername = new Label(NeoManager);
            lbusername.Init();

            lbusername.Width = 100;
            lbusername.Parent = pnlRes;
            lbusername.Top = pnlRes.Left + 10;
            lbusername.Left = pnlRes.Top + 8;

            lbusername.Text = "USERNAME";
            lbusername.TextColor = new SharpDX.Color(250, 250, 250);

            //  Manager.Graphics.ApplyChanges();
            //
            //  Manager.Add(lbusername);

            txusername = new TextBox(NeoManager);
            txusername.Init();
            txusername.Width = 200;
            txusername.Parent = pnlRes;
            txusername.Top = pnlRes.Left + 8;
            txusername.Left = pnlRes.Top + 80;
            txusername.Text.Trim();
            txusername.TextColor = new SharpDX.Color(250, 250, 250);
            lbpassword = new Label(NeoManager);
            lbpassword.Init();
            lbpassword.Width = 100;
            lbpassword.Parent = pnlRes;
            lbpassword.Top = pnlRes.Left + 30;
            lbpassword.Left = pnlRes.Top + 8;

            lbpassword.Text = "PASSWORD";
            lbpassword.TextColor = new SharpDX.Color(250, 250, 250);
            txpassword = new TextBox(NeoManager);
            txpassword.Init();
            txpassword.Width = 200;
            txpassword.Parent = pnlRes;
            txpassword.Top = pnlRes.Left + 30;
            txpassword.Left = pnlRes.Top + 80;
            txpassword.Mode = TextBoxMode.Password;

            txpassword.PasswordChar = '*';

            txpassword.Text.Trim();
            txpassword.TextColor = new SharpDX.Color(250, 250, 250);

            btnApply = new Button(NeoManager);
            btnApply.Init();
            btnApply.Width = 80;
            btnApply.Parent = pnlRes;
            btnApply.Left = pnlRes.Left + 50;
            btnApply.Top = pnlRes.Top + 80;
            btnApply.Text = "Login";
            btnApply.TextColor = new SharpDX.Color(250, 250, 250);
            btnApply.Click += new Controls.EventHandler(btnApply_Click);
            option = new Button(NeoManager);
            option.Init();
            option.Width = 80;
            option.Parent = pnlRes;
            option.Left = btnApply.Left + btnApply.Width + 8;
            option.Top = pnlRes.Top + 80;
            option.Text = "Options";
            option.TextColor = new SharpDX.Color(250, 250, 250);
            option.Click += new Controls.EventHandler(options_click);
            btnExit = new Button(NeoManager);
            btnExit.Init();
            btnExit.Width = 80;
            btnExit.Parent = pnlRes;
            btnExit.Left = option.Left + option.Width + 8;
            btnExit.Top = pnlRes.Top + 80;
            btnExit.Text = "Exit";
            btnExit.TextColor = new SharpDX.Color(250, 250, 250);
           // btnExit.Color = new SharpDX.Color(10, 10, 10);
          //  btnExit.ToolTip.Color = new SharpDX.Color(250, 250, 250);

            btnExit.Click += new Controls.EventHandler(btnExit_Click1);

        }
        ////////////////////////////////////////////////////////////////////////////

        ////////////////////////////////////////////////////////////////////////////    

        void btnExit_Click1(object sender, Controls.EventArgs e)
        {

            System.Windows.Forms.DialogResult dialogResult = System.Windows.Forms.MessageBox.Show("Do you really want to exit ", "", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question);
            if (dialogResult == System.Windows.Forms.DialogResult.Yes)
            {

                System.Windows.Forms.Application.Exit();
            }

        }

        void options_click(object sender, Controls.EventArgs e)
        {

            Options ola = new Options(Game,NeoManager);
            ola.Visible = true;
          // ola.EndDraw();

             }

        public void ProcessComplete1(Headers header, Rank rank)
        {
            string msg = "";
            //  System.Diagnostics.Debug.Write(Erro);
            if (header != Headers.Rank)
            {

                return;
            }

            else if (rank == Rank.Administrador)
            {

                txusername.Text = "";
                txpassword.Text = "";
                msg = "Entrou como Admiministrador";
                System.Windows.Forms.MessageBox.Show(msg, "", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
            }

            else if (rank == Rank.player)
            {
                msg = "Entrou com Player";
                System.Windows.Forms.MessageBox.Show(msg, "", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
            }

            else if (rank == Rank.Moderador)
            {
                msg = "Entrou Como Moderador";
                System.Windows.Forms.MessageBox.Show(msg, "", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
            }
            else if (rank == Rank.Vip)
            {

                msg = "Entrou Como VIP";
                System.Windows.Forms.MessageBox.Show(msg, "", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);

            }
            //else if (rank == Rank.Banned)
            //{
            //    // txusername.Text = "";
            //    //txpassword.Text = "";
            //    msg = "Jogador Banido";
            //    System.Windows.Forms.MessageBox.Show(msg, "", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);

            //}

        }

        public void ProcessComplete(Headers header, ErrorCodes Erro)
        {
            string msg = "";
            System.Diagnostics.Debug.Write(Erro);
            if (header != Headers.Login)
            {

                return;
            }

            else if (Erro == ErrorCodes.Sucess)
            {

                txusername.Text = "";
                txpassword.Text = "";
                window.Hide();

                Server ser = new Server(Game, NeoManager,user,graphic);
                cliente.Nivel(user, ProcessComplete1);

            }

            else if (Erro == ErrorCodes.InvalidLogin)
            {
                msg = "Password ou username is incorret";
                System.Windows.Forms.MessageBox.Show(msg, "", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                txusername.Text = "";
                txpassword.Text = "";

            }

            else if (Erro == ErrorCodes.Error)
            {
                txusername.Text = "";
                txpassword.Text = "";
                msg = "Server Is Offline";
                System.Windows.Forms.MessageBox.Show(msg, "", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);

            }

        }

        public static String Create(String passwd)
        {
            var rnd = new Random();
            var saltBuf = new StringBuilder();
            const string seedList = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

            for (int i = 0; i < 32; i++)
            {
                int rndIndex = rnd.Next(62);
                saltBuf.Append(seedList.Substring(rndIndex, 1));
            }

            String salt = saltBuf.ToString();

            return CreateMd5Hash(passwd);
        }

        private static String CreateMd5Hash(String data)
        {
            byte[] bdata = new byte[data.Length];
            byte[] hash;
            for (int i = 0; i < data.Length; i++)
            {
                bdata[i] = (byte)(data[i] & 0xff);
            }
            try
            {
                MD5CryptoServiceProvider md5Provider = new MD5CryptoServiceProvider();
                hash = md5Provider.ComputeHash(bdata);
            }
            catch (SecurityException e)
            {
                throw new ApplicationException("A security encryption error occured.", e);
            }
            var result = new StringBuilder(32);
            foreach (byte t in hash)
            {
                String x = (t & 0xff).ToString("X").ToLowerInvariant();
                if (x.Length < 2)
                {
                    result.Append("0");
                }
                result.Append(x);
            }
            System.Console.WriteLine(result);
            return result.ToString();
        }
        private static String CalculateHash(string password, string salt)
        {
            byte[] data = System.Text.Encoding.ASCII.GetBytes(salt + password);
            data = System.Security.Cryptography.MD5.Create().ComputeHash(data);

            return BitConverter.ToString(data).Replace("-", "") + ":" + salt;
        }

        void btnApply_Click(object sender, Controls.EventArgs e)
        {

            user = txusername.Text.Trim();
            userPassword = txpassword.Text.Trim();

            if ((user.Equals(String.Empty)) || (userPassword.Equals(String.Empty)))
            {
                System.Windows.Forms.MessageBox.Show("Username Ou Password is empty ", "", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);

            }
            else
            {

                window.Hide();
               World ser = new World(Game, NeoManager, user,graphic);
               ser.Visible = true;
               this.Visible = false;

                 //   cliente.Login(user, userPassword, ProcessComplete);

            }
            ////////////////////////////////////////////////////////////////////////////

            ////////////////////////////////////////////////////////////////////////////    

        }

    }
}
xoofx commented 9 years ago

We really cannot provide this kind of support for your code. We don't have time to read your code (unless there is a proven bug in SharpDX). Please consider using MonoGame if you are looking for XNA compatibility.