Example #1
0
 /**
  * <summary>
  * Adds all stuff to GUI switches
  * </summary>
  */
 private void SetButtons(ToggleSwitch2 ts, EventHandler e)
 {
     EntityManager.Add(ts);
     ts.Toggled += e;
     //Behaviors for distinguish between GUI and play field
     ts.Entity.AddComponent(new MouseEnterBehavior());
 }
Example #2
0
        /**
         * <summary>
         * We get the identifier in the server.
         * Create the player
         * </summary>
         */
        private void HostNewPlayer(object sender, IncomingMessage receivedMessage)
        {
            if (ids.Count == 0)
            {
                maxPlayersLabel = new TextBlock("maxPlayersLabel")
                {
                    HorizontalAlignment = HorizontalAlignment.Right, Text = "Max Players", Margin = new Thickness(0, 70, 200, 0)
                };
                maxPlayersSelector = new Slider("maxPlayers")
                {
                    Value = 2, Minimum = 2, Maximum = 4, HorizontalAlignment = HorizontalAlignment.Right, Margin = new Thickness(0, 70, 80, 0)
                };
                maxPlayersSelector.ValueChanged += ChangeMaxPlayers;
                maxPlayers = 2;
                networkedScene.EntityManager.Add(maxPlayersLabel);
                networkedScene.EntityManager.Add(maxPlayersSelector);

                fieldLabel = new TextBlock("fieldLabel")
                {
                    Text = "Map size", HorizontalAlignment = HorizontalAlignment.Right, Margin = new Thickness(0, 0, 200, 0)
                };
                fieldSelector = new ToggleSwitch2("fieldSelector")
                {
                    IsOn = false, OnText = "Big", OffText = "Small", HorizontalAlignment = HorizontalAlignment.Right, Margin = new Thickness(0, 0, 100, 0)
                };
                networkedScene.EntityManager.Add(fieldLabel);
                networkedScene.EntityManager.Add(fieldSelector);
            }
            string playerIdentifier = receivedMessage.ReadString();
            string playerName       = receivedMessage.ReadString();

            if (ids.Count < maxPlayers)
            {
                networkedScene.state.Text = "player identified";

                ids.Add(playerIdentifier);
                names.Add(playerName);
                for (int i = 0; i < ids.Count; i++)
                {
                    NotifyNewPlayerToClients(ids[i], names[i]);
                }
            }
            else
            {
                //reached the limit, kick
                Kick(playerIdentifier);
            }
        }
Example #3
0
        public void SetUI()
        {
            buildingCreationButtons = new Dictionary <CommandEnum, RadioButton>();
            woCreationButtons       = new Dictionary <CommandEnum, RadioButton>();

            CommandEnum[] commands = WorldObjectData.buildings;
            for (int i = 0; i < commands.Length; i++)
            {
                buildingCreationButtons.Add(commands[i], CreateCreationButton(commands[i], i + 1));
            }

            CommandEnum[] commands2 = WorldObjectData.notBuildings;
            for (int i = 0; i < commands2.Length; i++)
            {
                woCreationButtons.Add(commands2[i], CreateCreationButton(commands2[i], i + 1 + commands.Length));
            }

            menuButton = new ToggleSwitch2 {
                IsOn = false, IsBorder = true, Width = 110, VerticalAlignment = VerticalAlignment.Bottom, HorizontalAlignment = HorizontalAlignment.Right, OnText = "Close Menu", OffText = "Open Menu", Margin = new Thickness(0, 0, 0, 0), TextColor = Color.Black
            };
            reloadButton = new Button {
                Width = 150, BackgroundImage = WaveContent.Assets.uibackground_png, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center, Foreground = Color.Black, Text = "Reload", Margin = new Thickness(0, 0, 0, 0), IsVisible = false
            };
            changeSceneButton = new Button {
                Width = 150, BackgroundImage = WaveContent.Assets.uibackground_png, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center, Foreground = Color.Black, Text = "Change Scene", Margin = new Thickness(0, 0, 0, 50), IsVisible = false
            };
            exitButton = new Button {
                Width = 150, BackgroundImage = WaveContent.Assets.uibackground_png, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center, Foreground = Color.Black, Text = "Close Game", Margin = new Thickness(0, 50, 0, 0), IsVisible = false
            };
            keysButton = new Button {
                Width = 150, BackgroundImage = WaveContent.Assets.uibackground_png, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center, Foreground = Color.Black, Text = "Keys", Margin = new Thickness(0, 100, 0, 0), IsVisible = false
            };

            debugSwitch = new ToggleSwitch2 {
                Width = 120, IsBorder = true, VerticalAlignment = VerticalAlignment.Bottom, TextColor = Color.Black, HorizontalAlignment = HorizontalAlignment.Right, OnText = "Debugging", OffText = "Playing", IsOn = true, Margin = new Thickness(0, 0, 120, 0)
            };
            creationSwitch = new ToggleSwitch2 {
                Width = 120, IsBorder = true, HorizontalAlignment = HorizontalAlignment.Right, TextColor = Color.Black, OnText = "Hide create", OffText = "Create", IsOn = true, Margin = new Thickness(0, 0, 0, 0)
            };
            playerSwitch = new ToggleSwitch2 {
                Width = 120, IsBorder = true, VerticalAlignment = VerticalAlignment.Bottom, HorizontalAlignment = HorizontalAlignment.Left, TextColor = Color.Black, OnText = "Hide players", OffText = "Change player", IsOn = true, Margin = new Thickness(0, 0, 0, 0)
            };

            SetButtons(changeSceneButton, ChangeScene);
            SetButtons(reloadButton, Reload);
            SetButtons(menuButton, HandleMenu);
            SetButtons(exitButton, Exit);
            SetButtons(keysButton, ChangeKeys);

            SetButtons(debugSwitch, ShowDebugCreationButtons);
            SetButtons(creationSwitch, ShowCreationButtons);
            SetButtons(playerSwitch, ShowPlayerSwitch);



            //Cottage info: This is the maximum number of units a cottage can shelter
            int maxCottageOccupation = Cottage.MAX_OCCUPATION;

            cottageList = new TextBlock[maxCottageOccupation];
            //we will make a grid of 2x3
            int width  = 2;
            int height = maxCottageOccupation / width;

            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    int pos = i + (j * width);
                    cottageList[pos] = new TextBlock {
                        VerticalAlignment = VerticalAlignment.Bottom, HorizontalAlignment = HorizontalAlignment.Center, Foreground = Color.Black, Text = "Unit", Margin = new Thickness(50 * (width - i - 1), 0, 150 * i, 30 * j)
                    };
                    cottageList[pos].IsVisible = false;
                    Owner.Scene.EntityManager.Add(cottageList[pos]);
                }
            }

            //Now, we add the generic info, coordinates, health, etc.
            woodText       = CreateInfoBlock(0);
            coordinateText = CreateInfoBlock(1);
            woNameText     = CreateInfoBlock(2);
            healthText     = CreateInfoBlock(3);

            //Person info
            buildSkill = CreateInfoBlock(4);
            fightSkill = CreateInfoBlock(5);
            healSkill  = CreateInfoBlock(6);
            chopSkill  = CreateInfoBlock(7);

            //you know, this slider is only for integer. buff.
            //So we do a trick by using 1 unit as 0.1 speed
            //Being the minimum 0.1f and the maximum, 6f
            speedSlider = new Slider {
                Value = 2, Minimum = 2, Maximum = 60, Margin = new Thickness(10, 170, 0, 0)
            };
            speedSlider.RealTimeValueChanged += ChangeWOSpeed;
            speedSlider.IsVisible             = false;
            Owner.Scene.EntityManager.Add(speedSlider);
            speedSlider.Entity.AddComponent(new MouseEnterBehavior());

            //The same with the scene speed
            gameSpeedSlider = new Slider {
                VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Center, Minimum = 1, Maximum = 20, Margin = new Thickness(0, 20, 0, 0)
            };
            gameSpeedSlider.RealTimeValueChanged += ChangeSceneSpeed;
            Owner.Scene.EntityManager.Add(gameSpeedSlider);
            gameSpeedSlider.Value = 10;
            gameSpeedSlider.Entity.AddComponent(new MouseEnterBehavior());

            //The stop button so we can stop the button
            stopButton = new Button {
                Width = 100, BackgroundImage = WaveContent.Assets.uibackground_png, Foreground = Color.Black, Text = "Stop", Margin = new Thickness(10, 200, 0, 0)
            };
            stopButton.Click    += StopWO;
            stopButton.IsVisible = false;
            Owner.Scene.EntityManager.Add(stopButton);
            stopButton.Entity.AddComponent(new MouseEnterBehavior());

            //The attack button so we can toggle the attack status
            attackButton = new Button {
                Width = 150, BackgroundImage = WaveContent.Assets.uibackground_png, Foreground = Color.Black, Text = "Change Status", Margin = new Thickness(120, 200, 0, 0)
            };
            attackButton.Click    += AttackWO;
            attackButton.IsVisible = false;
            Owner.Scene.EntityManager.Add(attackButton);
            attackButton.Entity.AddComponent(new MouseEnterBehavior());
        }