예제 #1
0
 protected void LoadControls()
 {
     #region Main menu
     MnuMain   = new Menu();
     BtnCreate = new Button(Programs[ProgramID.Button],
                            new Vector3(Width / 2 - 64, Height - 128, 0.0f), Vector3.Zero, Vector3.One,
                            Controls, Models, MnuMain,
                            128, 32, 2, Width, Height, Matrix4.Identity,
                            new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.7f, 0.7f, 0.0f, 0.8f),
                            new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.0f, 0.6f, 0.7f, 0.8f),
                            () =>
     {
         MnuMain.HideAll();
         MnuNetwork.ShowAll();
         LblNetAddress.HideAll();
         TxtNetAddress.HideAll();
         BtnNetJoin.HideAll();
         return(Task.Delay(0));
     }, "Create game");
     BtnJoin = new Button(Programs[ProgramID.Button],
                          new Vector3(Width / 2 - 64, Height - 192, 0.0f), Vector3.Zero, Vector3.One,
                          Controls, Models, MnuMain,
                          128, 32, 2, Width, Height, Matrix4.Identity,
                          new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.7f, 0.7f, 0.0f, 0.8f),
                          new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.0f, 0.6f, 0.7f, 0.8f),
                          () =>
     {
         MnuMain.HideAll();
         MnuNetwork.ShowAll();
         BtnNetCreate.HideAll();
         return(Task.Delay(0));
     }, "Join game");
     BtnExit = new Button(Programs[ProgramID.Button],
                          new Vector3(Width / 2 - 64, Height - 256, 0.0f), Vector3.Zero, Vector3.One,
                          Controls, Models, MnuMain,
                          128, 32, 2, Width, Height, Matrix4.Identity,
                          new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.7f, 0.7f, 0.0f, 0.8f),
                          new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.0f, 0.6f, 0.7f, 0.8f),
                          () =>
     {
         Exit();
         return(Task.Delay(0));
     }, "Exit");
     MnuMain.CreateBuffers();
     #endregion
     #region Test menu
     MnuTest = new Menu();
     LblTest = new Label(Programs[ProgramID.Label],
                         Vector3.Zero, Vector3.Zero, Vector3.One,
                         Controls, Models, MnuTest,
                         92, 18, 2, Width, Height, Matrix4.Identity, new Color4(0.1f, 0.1f, 0.1f, 0.6f), "X:0 Y:0");
     BtnTest = new Button(Programs[ProgramID.Button],
                          new Vector3(8.0f, 40.0f, 0.0f), Vector3.Zero, Vector3.One,
                          Controls, Models, MnuTest,
                          128, 32, 2, Width, Height, Matrix4.Identity,
                          new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.7f, 0.7f, 0.0f, 0.8f),
                          new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.0f, 0.6f, 0.7f, 0.8f),
                          () =>
     {
         Polymono.Print("Hello");
         return(Task.Delay(0));
     }, "Test button");
     TxtTest = new Textbox(Programs[ProgramID.Label],
                           new Vector3(8.0f, 80.0f, 0.0f), Vector3.Zero, Vector3.One,
                           Controls, Models, MnuTest,
                           128, 32, 2, Width, Height, Matrix4.Identity,
                           new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.7f, 0.7f, 0.0f, 0.8f),
                           new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.0f, 0.6f, 0.7f, 0.8f),
                           "Test Textbox");
     MnuTest.CreateBuffers();
     #endregion
     #region Server creation menu
     MnuNetwork = new Menu();
     LblNetName = new Label(Programs[ProgramID.Label],
                            new Vector3((Width / 2) - 64, Height - (64 * 2) + 24, 0.0f), Vector3.Zero, Vector3.One,
                            Controls, Models, MnuNetwork,
                            92, 18, 2, Width, Height, Matrix4.Identity, new Color4(0.1f, 0.1f, 0.1f, 0.6f),
                            "Enter name:");
     TxtNetName = new Textbox(Programs[ProgramID.Label],
                              new Vector3((Width / 2) - 64, Height - (64 * 2), 0.0f), Vector3.Zero, Vector3.One,
                              Controls, Models, MnuNetwork,
                              128, 32, 2, Width, Height, Matrix4.Identity,
                              new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.7f, 0.7f, 0.0f, 0.8f),
                              new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.0f, 0.6f, 0.7f, 0.8f),
                              "");
     LblNetAddress = new Label(Programs[ProgramID.Label],
                               new Vector3((Width / 2) - 160, Height - (64 * 3) + 24, 0.0f), Vector3.Zero, Vector3.One,
                               Controls, Models, MnuNetwork,
                               108, 18, 2, Width, Height, Matrix4.Identity, new Color4(0.1f, 0.1f, 0.1f, 0.6f),
                               "Network address:");
     TxtNetAddress = new Textbox(Programs[ProgramID.Label],
                                 new Vector3((Width / 2) - 160, Height - (64 * 3), 0.0f), Vector3.Zero, Vector3.One,
                                 Controls, Models, MnuNetwork,
                                 128, 32, 2, Width, Height, Matrix4.Identity,
                                 new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.7f, 0.7f, 0.0f, 0.8f),
                                 new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.0f, 0.6f, 0.7f, 0.8f),
                                 "");
     ChkNetType = new Checkbox(Programs[ProgramID.Button],
                               new Vector3((Width / 2) - 160 + 128 + 8, Height - (64 * 3), 0.0f), Vector3.Zero, Vector3.One,
                               Controls, Models, MnuNetwork,
                               32, 32, 2, Width, Height, Matrix4.Identity,
                               new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.7f, 0.7f, 0.0f, 0.8f),
                               new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.0f, 0.6f, 0.7f, 0.8f));
     LblNetPort = new Label(Programs[ProgramID.Label],
                            new Vector3((Width / 2) + 32, Height - (64 * 3) + 24, 0.0f), Vector3.Zero, Vector3.One,
                            Controls, Models, MnuNetwork,
                            92, 18, 2, Width, Height, Matrix4.Identity, new Color4(0.1f, 0.1f, 0.1f, 0.6f),
                            "Network port:");
     TxtNetPort = new Textbox(Programs[ProgramID.Label],
                              new Vector3((Width / 2) + 32, Height - (64 * 3), 0.0f), Vector3.Zero, Vector3.One,
                              Controls, Models, MnuNetwork,
                              128, 32, 2, Width, Height, Matrix4.Identity,
                              new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.7f, 0.7f, 0.0f, 0.8f),
                              new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.0f, 0.6f, 0.7f, 0.8f),
                              "");
     BtnNetCreate = new Button(Programs[ProgramID.Button],
                               new Vector3((Width / 2) - 64, Height - (64 * 4), 0.0f), Vector3.Zero, Vector3.One,
                               Controls, Models, MnuNetwork,
                               128, 32, 2, Width, Height, Matrix4.Identity,
                               new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.7f, 0.7f, 0.0f, 0.8f), // Default model
                               new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.0f, 0.6f, 0.7f, 0.8f), // Clicked model
                               () =>
     {
         try
         {
             bool v6;
             if (ChkNetType.State == ControlState.Clicked)
             {
                 v6 = true;
             }
             else
             {
                 v6 = false;
             }
             Server server = new Server(this, TxtNetName.Text, v6);
             int port      = Convert.ToInt32(TxtNetPort.Text);
             server.LocalHandler().Bind(port);
             server.LocalHandler().Listen(10);
             server.Start();
             Network = server;
             State   = GameState.Lobby;
             MnuNetwork.HideAll();
             MnuMessage.ShowAll();
             MnuGame.ShowAll();
         }
         catch (SocketException se)
         {
             Polymono.Error(se.Message);
             Polymono.ErrorF(se.StackTrace);
         }
         catch (FormatException fe)
         {
             Polymono.Error("Port is not a readable number.");
             Polymono.Error(fe.Message);
             Polymono.ErrorF(fe.StackTrace);
         }
         return(Task.Delay(0));
     }, "Create Server");
     BtnNetJoin = new Button(Programs[ProgramID.Button],
                             new Vector3((Width / 2) - 64, Height - (64 * 4), 0.0f), Vector3.Zero, Vector3.One,
                             Controls, Models, MnuNetwork,
                             128, 32, 2, Width, Height, Matrix4.Identity,
                             new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.7f, 0.7f, 0.0f, 0.8f), // Default model
                             new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.0f, 0.6f, 0.7f, 0.8f), // Clicked model
                             () =>
     {
         try
         {
             bool v6;
             if (ChkNetType.State == ControlState.Clicked)
             {
                 v6 = true;
             }
             else
             {
                 v6 = false;
             }
             Client client  = new Client(this, v6);
             string address = TxtNetAddress.Text;
             int port       = Convert.ToInt32(TxtNetPort.Text);
             string name    = TxtNetName.Text;
             client.ConnectAsync(address, port, name);
             Network = client;
             State   = GameState.Lobby;
             MnuNetwork.HideAll();
             MnuMessage.ShowAll();
         }
         catch (SocketException se)
         {
             Polymono.Error(se.Message);
             Polymono.ErrorF(se.StackTrace);
         }
         catch (FormatException fe)
         {
             Polymono.Error("Port is not a readable number.");
             Polymono.Error(fe.Message);
             Polymono.ErrorF(fe.StackTrace);
         }
         return(Task.Delay(0));
     }, "Join server");
     BtnNetBack = new Button(Programs[ProgramID.Button],
                             new Vector3((Width / 2) - 64, Height - (64 * 6), 0.0f), Vector3.Zero, Vector3.One,
                             Controls, Models, MnuNetwork,
                             128, 32, 2, Width, Height, Matrix4.Identity,
                             new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.7f, 0.7f, 0.0f, 0.8f),
                             new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.0f, 0.6f, 0.7f, 0.8f),
                             () =>
     {
         MnuNetwork.HideAll();
         MnuMain.ShowAll();
         return(Task.Delay(0));
     }, "Back");
     MnuNetwork.CreateBuffers();
     #endregion
     #region Message menu
     MnuMessage = new Menu();
     LblMsgBox  = new Label(Programs[ProgramID.Label],
                            new Vector3(32, Height / 2, 0.0f), Vector3.Zero, Vector3.One,
                            Controls, Models, MnuMessage,
                            256, 256, 2, Width, Height, Matrix4.Identity, new Color4(0.1f, 0.1f, 0.1f, 0.6f), "Chat room text" + Environment.NewLine + "Chat room text2");
     TxtMsgInput = new Textbox(Programs[ProgramID.Label],
                               new Vector3(32, Height / 2 - 256, 0.0f), Vector3.Zero, Vector3.One,
                               Controls, Models, MnuMessage,
                               192, 32, 2, Width, Height, Matrix4.Identity,
                               new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.7f, 0.7f, 0.0f, 0.8f),
                               new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.0f, 0.6f, 0.7f, 0.8f),
                               "");
     BtnMsgSend = new Button(Programs[ProgramID.Button],
                             new Vector3(32 + 192, Height / 2 - 256, 0.0f), Vector3.Zero, Vector3.One,
                             Controls, Models, MnuMessage,
                             64, 32, 2, Width, Height, Matrix4.Identity,
                             new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.7f, 0.7f, 0.0f, 0.8f),
                             new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.0f, 0.6f, 0.7f, 0.8f),
                             () =>
     {
         string text      = TxtMsgInput.Text.Trim();
         TxtMsgInput.Text = "";
         LblMsgBox.Text  += Environment.NewLine + text;
         Network.SendAsync(PacketHandler.Create(PacketType.Message,
                                                Protocol.Chat.EncodeMessage(text)));
         return(Task.Delay(0));
     }, "Send");
     MnuMessage.CreateBuffers();
     #endregion
     #region Game menu
     MnuGame      = new Menu();
     BtnGameStart = new Button(Programs[ProgramID.Button],
                               new Vector3((Width / 2) - 64, Height - (64 * 4), 0.0f), Vector3.Zero, Vector3.One,
                               Controls, Models, MnuGame,
                               128, 32, 2, Width, Height, Matrix4.Identity,
                               new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.7f, 0.7f, 0.0f, 0.8f),
                               new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.0f, 0.6f, 0.7f, 0.8f),
                               () =>
     {
         if (IsServer && Board.GetPlayers().Count > 1)
         {
             // Start game.
             ((Server)Network).AcceptClients = false;
             Network.SendAsync(PacketHandler.Create(PacketType.StartGame,
                                                    Protocol.Game.EncodeStartGame(Board.CurrentPlayerID)));
             State = GameState.LobbyRoll;
             MnuGame.HideAll();
             BtnRollDice.ShowAll();
             Polymono.Debug("Starting game.");
         }
         else
         {
             // Not enough players, not server.
             Polymono.Debug($"Cannot start game: [Is server:{IsServer}] [Players: {Board.GetPlayers().Count}]");
             Polymono.Debug("Needs to be server and have more than 1 player in lobby.");
         }
         // Starts game
         return(Task.Delay(0));
     }, "Start Game");
     BtnGameExit = new Button(Programs[ProgramID.Button],
                              new Vector3((Width / 2) - 64, Height - (64 * 6), 0.0f), Vector3.Zero, Vector3.One,
                              Controls, Models, MnuGame,
                              128, 32, 2, Width, Height, Matrix4.Identity,
                              new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.7f, 0.7f, 0.0f, 0.8f),
                              new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.0f, 0.6f, 0.7f, 0.8f),
                              async() =>
     {
         await Network.SendAsync(PacketHandler.Create(PacketType.Disconnect,
                                                      Protocol.Connection.EncodeDisconnect(Board.CurrentPlayerID, "Exit lobby")));
         Network = null;
         Polymono.Debug("Exiting game.");
         // Exits game
     }, "Exit Game");
     MnuPlayerOptions = new Menu();
     BtnRollDice      = new Button(Programs[ProgramID.Button],
                                   new Vector3((Width / 2) - 64, (64 * 2), 0.0f), Vector3.Zero, Vector3.One,
                                   Controls, Models, MnuPlayerOptions,
                                   128, 32, 2, Width, Height, Matrix4.Identity,
                                   new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.7f, 0.7f, 0.0f, 0.8f),
                                   new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.0f, 0.6f, 0.7f, 0.8f),
                                   () =>
     {
         int rollOne = DiceOne.GetNumber();
         int rollTwo = DiceTwo.GetNumber();
         Network.SendAsync(PacketHandler.Create(PacketType.DiceRoll,
                                                Protocol.Game.EncodeDiceRoll(rollOne, rollTwo,
                                                                             Board.CurrentPlayerID)));
         if (State == GameState.LobbyRoll)
         {
             BtnRollDice.HideAll();
             Board.EndCurrentTurn(Board.CurrentPlayerID);
             Network.SendAsync(PacketHandler.Create(PacketType.EndTurn,
                                                    Protocol.Game.EncodeEndTurn(Board.CurrentPlayerID)));
         }
         else if (State == GameState.PlayerOptions)
         {
             MnuPlayerOptions.HideAll();
             Board.MoveSpaces(rollOne + rollTwo, Board.CurrentPlayerID);
             State = GameState.Moving;
         }
         return(Task.Delay(0));
     }, "Roll Dice");
     BtnPurchaseProperty = new Button(Programs[ProgramID.Button],
                                      new Vector3((Width / 2) - 256, (64 * 2), 0.0f), Vector3.Zero, Vector3.One,
                                      Controls, Models, MnuPlayerOptions,
                                      128, 32, 2, Width, Height, Matrix4.Identity,
                                      new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.7f, 0.7f, 0.0f, 0.8f),
                                      new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.0f, 0.6f, 0.7f, 0.8f),
                                      () =>
     {
         // Purchase current property.
         return(Task.Delay(0));
     }, "Purchase");
     BtnTrade = new Button(Programs[ProgramID.Button],
                           new Vector3((Width / 2) + 192, (64 * 2), 0.0f), Vector3.Zero, Vector3.One,
                           Controls, Models, MnuPlayerOptions,
                           128, 32, 2, Width, Height, Matrix4.Identity,
                           new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.7f, 0.7f, 0.0f, 0.8f),
                           new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.0f, 0.6f, 0.7f, 0.8f),
                           () =>
     {
         // Trade screen.
         return(Task.Delay(0));
     }, "Trade");
     BtnEndTurn = new Button(Programs[ProgramID.Button],
                             new Vector3((Width / 2) - 64, (64 * 2), 0.0f), Vector3.Zero, Vector3.One,
                             Controls, Models, MnuPlayerOptions,
                             128, 32, 2, Width, Height, Matrix4.Identity,
                             new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.7f, 0.7f, 0.0f, 0.8f),
                             new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.0f, 0.6f, 0.7f, 0.8f),
                             () =>
     {
         MnuPlayerOptions.HideAll();
         // Trade screen.
         Board.EndCurrentTurn(Board.CurrentPlayerID);
         Network.SendAsync(PacketHandler.Create(PacketType.EndTurn,
                                                Protocol.Game.EncodeEndTurn(Board.CurrentPlayerID)));
         return(Task.Delay(0));
     }, "End Turn");
     MnuGame.CreateBuffers();
     MnuPlayerOptions.CreateBuffers();
     #endregion
     #region Game menu
     MnuPlayerJailOptions = new Menu();
     BtnPayJail           = new Button(Programs[ProgramID.Button],
                                       new Vector3(), Vector3.Zero, Vector3.One,
                                       Controls, Models, MnuPlayerJailOptions,
                                       128, 32, 2, Width, Height, Matrix4.Identity,
                                       new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.7f, 0.7f, 0.0f, 0.8f),
                                       new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.0f, 0.6f, 0.7f, 0.8f),
                                       () =>
     {
         // Pay Jail
         return(Task.Delay(0));
     }, "Roll Dice");
     BtnUseCard = new Button(Programs[ProgramID.Button],
                             new Vector3(), Vector3.Zero, Vector3.One,
                             Controls, Models, MnuPlayerJailOptions,
                             128, 32, 2, Width, Height, Matrix4.Identity,
                             new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.7f, 0.7f, 0.0f, 0.8f),
                             new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.0f, 0.6f, 0.7f, 0.8f),
                             () =>
     {
         // Use card
         return(Task.Delay(0));
     }, "Purchase");
     MnuPlayerJailOptions.CreateBuffers();
     #endregion
 }