public static void ShowColorDropDown(DropDownButtonWidget color, Session.Client client,
			OrderManager orderManager, ColorPickerPaletteModifier preview)
        {
            Action<ColorRamp> onSelect = c =>
            {
                if (client.Bot == null)
                {
                    Game.Settings.Player.ColorRamp = c;
                    Game.Settings.Save();
                }

                color.RemovePanel();
                orderManager.IssueOrder(Order.Command("color {0} {1}".F(client.Index, c)));
            };

            Action<ColorRamp> onChange = c => preview.Ramp = c;

            var colorChooser = Game.LoadWidget(orderManager.world, "COLOR_CHOOSER", null, new WidgetArgs()
            {
                { "onSelect", onSelect },
                { "onChange", onChange },
                { "initialRamp", client.ColorRamp }
            });

            color.AttachPanel(colorChooser);
        }
示例#2
0
        public static void ShowColorDropDown(DropDownButtonWidget color, Session.Client client,
                                             OrderManager orderManager, ColorPickerPaletteModifier preview)
        {
            Action <ColorRamp> onSelect = c =>
            {
                if (client.Bot == null)
                {
                    Game.Settings.Player.ColorRamp = c;
                    Game.Settings.Save();
                }

                color.RemovePanel();
                orderManager.IssueOrder(Order.Command("color {0} {1}".F(client.Index, c)));
            };

            Action <ColorRamp> onChange = c => preview.Ramp = c;

            var colorChooser = Game.LoadWidget(orderManager.world, "COLOR_CHOOSER", null, new WidgetArgs()
            {
                { "onSelect", onSelect },
                { "onChange", onChange },
                { "initialRamp", client.ColorRamp }
            });

            color.AttachPanel(colorChooser);
        }
        internal LobbyLogic(Widget widget, World world, OrderManager orderManager,
			Action onExit, Action onStart, bool addBots)
        {
            var lobby = widget;
            this.orderManager = orderManager;
            this.OnGameStart = () => { CloseWindow(); onStart(); };
            this.onExit = onExit;

            Game.LobbyInfoChanged += UpdateCurrentMap;
            Game.LobbyInfoChanged += UpdatePlayerList;
            Game.BeforeGameStart += OnGameStart;
            Game.AddChatLine += AddChatLine;
            Game.ConnectionStateChanged += ConnectionStateChanged;

            UpdateCurrentMap();
            PlayerPalettePreview = world.WorldActor.Trait<ColorPickerPaletteModifier>();
            PlayerPalettePreview.Ramp = Game.Settings.Player.ColorRamp;
            Players = lobby.Get<ScrollPanelWidget>("PLAYERS");
            EditablePlayerTemplate = Players.Get("TEMPLATE_EDITABLE_PLAYER");
            NonEditablePlayerTemplate = Players.Get("TEMPLATE_NONEDITABLE_PLAYER");
            EmptySlotTemplate = Players.Get("TEMPLATE_EMPTY");
            EditableSpectatorTemplate = Players.Get("TEMPLATE_EDITABLE_SPECTATOR");
            NonEditableSpectatorTemplate = Players.Get("TEMPLATE_NONEDITABLE_SPECTATOR");
            NewSpectatorTemplate = Players.Get("TEMPLATE_NEW_SPECTATOR");

            var mapPreview = lobby.Get<MapPreviewWidget>("MAP_PREVIEW");
            mapPreview.IsVisible = () => Map != null;
            mapPreview.Map = () => Map;
            mapPreview.OnMouseDown = mi => LobbyUtils.SelectSpawnPoint( orderManager, mapPreview, Map, mi );
            mapPreview.SpawnColors = () => LobbyUtils.GetSpawnColors( orderManager, Map );

            var mapTitle = lobby.GetOrNull<LabelWidget>("MAP_TITLE");
            if (mapTitle != null)
            {
                mapTitle.IsVisible = () => Map != null;
                mapTitle.GetText = () => Map.Title;
            }

            CountryNames = Rules.Info["world"].Traits.WithInterface<CountryInfo>()
                .Where(c => c.Selectable)
                .ToDictionary(a => a.Race, a => a.Name);
            CountryNames.Add("random", "Any");

            var mapButton = lobby.Get<ButtonWidget>("CHANGEMAP_BUTTON");
            mapButton.OnClick = () =>
            {
                var onSelect = new Action<Map>(m =>
                {
                    orderManager.IssueOrder(Order.Command("map " + m.Uid));
                    Game.Settings.Server.Map = m.Uid;
                    Game.Settings.Save();
                });

                Ui.OpenWindow("MAPCHOOSER_PANEL", new WidgetArgs()
                {
                    { "initialMap", Map.Uid },
                    { "onExit", () => {} },
                    { "onSelect", onSelect }
                });
            };
            mapButton.IsVisible = () => mapButton.Visible && Game.IsHost;

            var disconnectButton = lobby.Get<ButtonWidget>("DISCONNECT_BUTTON");
            disconnectButton.OnClick = () => { CloseWindow(); onExit(); };

            var gameStarting = false;

            var allowCheats = lobby.Get<CheckboxWidget>("ALLOWCHEATS_CHECKBOX");
            allowCheats.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.AllowCheats;
            allowCheats.IsDisabled = () => !Game.IsHost || gameStarting || orderManager.LocalClient == null
                || orderManager.LocalClient.IsReady;
            allowCheats.OnClick = () =>	orderManager.IssueOrder(Order.Command(
                        "allowcheats {0}".F(!orderManager.LobbyInfo.GlobalSettings.AllowCheats)));

            var startGameButton = lobby.Get<ButtonWidget>("START_GAME_BUTTON");
            startGameButton.IsVisible = () => Game.IsHost;
            startGameButton.IsDisabled = () => gameStarting;
            startGameButton.OnClick = () =>
            {
                gameStarting = true;
                orderManager.IssueOrder(Order.Command("startgame"));
            };

            bool teamChat = false;
            var chatLabel = lobby.Get<LabelWidget>("LABEL_CHATTYPE");
            var chatTextField = lobby.Get<TextFieldWidget>("CHAT_TEXTFIELD");

            chatTextField.OnEnterKey = () =>
            {
                if (chatTextField.Text.Length == 0)
                    return true;

                orderManager.IssueOrder(Order.Chat(teamChat, chatTextField.Text));
                chatTextField.Text = "";
                return true;
            };

            chatTextField.OnTabKey = () =>
            {
                teamChat ^= true;
                chatLabel.Text = (teamChat) ? "Team:" : "Chat:";
                return true;
            };

            chatPanel = lobby.Get<ScrollPanelWidget>("CHAT_DISPLAY");
            chatTemplate = chatPanel.Get("CHAT_TEMPLATE");
            chatPanel.RemoveChildren();

            var musicButton = lobby.GetOrNull<ButtonWidget>("MUSIC_BUTTON");
            if (musicButton != null)
                musicButton.OnClick = () => Ui.OpenWindow("MUSIC_PANEL", new WidgetArgs
                    { { "onExit", () => {} } });

            // Add a bot on the first lobbyinfo update
            if (addBots)
                Game.LobbyInfoChanged += WidgetUtils.Once(() =>
                {
                    var slot = orderManager.LobbyInfo.FirstEmptySlot();
                    var bot = Rules.Info["player"].Traits.WithInterface<IBotInfo>().Select(t => t.Name).FirstOrDefault();
                    if (slot != null && bot != null)
                        orderManager.IssueOrder(Order.Command("slot_bot {0} {1}".F(slot, bot)));
                });
        }
示例#4
0
        internal LobbyLogic(Widget widget, World world, OrderManager orderManager,
                            Action onExit, Action onStart, bool addBots)
        {
            var lobby = widget;

            this.orderManager = orderManager;
            this.OnGameStart  = () => { CloseWindow(); onStart(); };
            this.onExit       = onExit;

            Game.LobbyInfoChanged       += UpdateCurrentMap;
            Game.LobbyInfoChanged       += UpdatePlayerList;
            Game.BeforeGameStart        += OnGameStart;
            Game.AddChatLine            += AddChatLine;
            Game.ConnectionStateChanged += ConnectionStateChanged;

            UpdateCurrentMap();
            PlayerPalettePreview      = world.WorldActor.Trait <ColorPickerPaletteModifier>();
            PlayerPalettePreview.Ramp = Game.Settings.Player.ColorRamp;
            Players = lobby.GetWidget <ScrollPanelWidget>("PLAYERS");
            EditablePlayerTemplate       = Players.GetWidget("TEMPLATE_EDITABLE_PLAYER");
            NonEditablePlayerTemplate    = Players.GetWidget("TEMPLATE_NONEDITABLE_PLAYER");
            EmptySlotTemplate            = Players.GetWidget("TEMPLATE_EMPTY");
            EditableSpectatorTemplate    = Players.GetWidget("TEMPLATE_EDITABLE_SPECTATOR");
            NonEditableSpectatorTemplate = Players.GetWidget("TEMPLATE_NONEDITABLE_SPECTATOR");
            NewSpectatorTemplate         = Players.GetWidget("TEMPLATE_NEW_SPECTATOR");

            var mapPreview = lobby.GetWidget <MapPreviewWidget>("MAP_PREVIEW");

            mapPreview.IsVisible   = () => Map != null;
            mapPreview.Map         = () => Map;
            mapPreview.OnMouseDown = mi => LobbyUtils.SelectSpawnPoint(orderManager, mapPreview, Map, mi);
            mapPreview.SpawnColors = () => LobbyUtils.GetSpawnColors(orderManager, Map);

            var mapTitle = lobby.GetWidget <LabelWidget>("MAP_TITLE");

            if (mapTitle != null)
            {
                mapTitle.IsVisible = () => Map != null;
                mapTitle.GetText   = () => Map.Title;
            }

            CountryNames = Rules.Info["world"].Traits.WithInterface <CountryInfo>()
                           .Where(c => c.Selectable)
                           .ToDictionary(a => a.Race, a => a.Name);
            CountryNames.Add("random", "Any");

            var mapButton = lobby.GetWidget <ButtonWidget>("CHANGEMAP_BUTTON");

            mapButton.OnClick = () =>
            {
                var onSelect = new Action <Map>(m =>
                {
                    orderManager.IssueOrder(Order.Command("map " + m.Uid));
                    Game.Settings.Server.Map = m.Uid;
                    Game.Settings.Save();
                });

                Ui.OpenWindow("MAPCHOOSER_PANEL", new WidgetArgs()
                {
                    { "initialMap", Map.Uid },
                    { "onExit", () => {} },
                    { "onSelect", onSelect }
                });
            };
            mapButton.IsVisible = () => mapButton.Visible && Game.IsHost;

            var disconnectButton = lobby.GetWidget <ButtonWidget>("DISCONNECT_BUTTON");

            disconnectButton.OnClick = () => { CloseWindow(); onExit(); };

            var gameStarting = false;

            var allowCheats = lobby.GetWidget <CheckboxWidget>("ALLOWCHEATS_CHECKBOX");

            allowCheats.IsChecked  = () => orderManager.LobbyInfo.GlobalSettings.AllowCheats;
            allowCheats.IsDisabled = () => !Game.IsHost || gameStarting || orderManager.LocalClient == null ||
                                     orderManager.LocalClient.IsReady;
            allowCheats.OnClick = () => orderManager.IssueOrder(Order.Command(
                                                                    "allowcheats {0}".F(!orderManager.LobbyInfo.GlobalSettings.AllowCheats)));

            var startGameButton = lobby.GetWidget <ButtonWidget>("START_GAME_BUTTON");

            startGameButton.IsVisible  = () => Game.IsHost;
            startGameButton.IsDisabled = () => gameStarting;
            startGameButton.OnClick    = () =>
            {
                gameStarting = true;
                orderManager.IssueOrder(Order.Command("startgame"));
            };

            bool teamChat      = false;
            var  chatLabel     = lobby.GetWidget <LabelWidget>("LABEL_CHATTYPE");
            var  chatTextField = lobby.GetWidget <TextFieldWidget>("CHAT_TEXTFIELD");

            chatTextField.OnEnterKey = () =>
            {
                if (chatTextField.Text.Length == 0)
                {
                    return(true);
                }

                orderManager.IssueOrder(Order.Chat(teamChat, chatTextField.Text));
                chatTextField.Text = "";
                return(true);
            };

            chatTextField.OnTabKey = () =>
            {
                teamChat      ^= true;
                chatLabel.Text = (teamChat) ? "Team:" : "Chat:";
                return(true);
            };

            chatPanel    = lobby.GetWidget <ScrollPanelWidget>("CHAT_DISPLAY");
            chatTemplate = chatPanel.GetWidget("CHAT_TEMPLATE");
            chatPanel.RemoveChildren();

            var musicButton = lobby.GetWidget <ButtonWidget>("MUSIC_BUTTON");

            if (musicButton != null)
            {
                musicButton.OnClick = () => Ui.OpenWindow("MUSIC_PANEL", new WidgetArgs
                {
                    { "onExit", () => {} }
                });
            }

            // Add a bot on the first lobbyinfo update
            if (addBots)
            {
                Game.LobbyInfoChanged += WidgetUtils.Once(() =>
                {
                    var slot = orderManager.LobbyInfo.FirstEmptySlot();
                    var bot  = Rules.Info["player"].Traits.WithInterface <IBotInfo>().Select(t => t.Name).FirstOrDefault();
                    if (slot != null && bot != null)
                    {
                        orderManager.IssueOrder(Order.Command("slot_bot {0} {1}".F(slot, bot)));
                    }
                });
            }
        }
示例#5
0
        public CncSettingsLogic(Widget widget, World world, Action onExit)
        {
            this.world = world;
            var panel = widget.GetWidget("SETTINGS_PANEL");

            // General pane
            var generalButton = panel.GetWidget <ButtonWidget>("GENERAL_BUTTON");

            generalButton.OnClick    = () => Settings = PanelType.General;
            generalButton.IsDisabled = () => Settings == PanelType.General;

            var generalPane = panel.GetWidget("GENERAL_CONTROLS");

            generalPane.IsVisible = () => Settings == PanelType.General;

            var gameSettings     = Game.Settings.Game;
            var playerSettings   = Game.Settings.Player;
            var debugSettings    = Game.Settings.Debug;
            var graphicsSettings = Game.Settings.Graphics;
            var soundSettings    = Game.Settings.Sound;

            // Player profile
            var nameTextfield = generalPane.GetWidget <TextFieldWidget>("NAME_TEXTFIELD");

            nameTextfield.Text = playerSettings.Name;

            playerPalettePreview      = world.WorldActor.Trait <ColorPickerPaletteModifier>();
            playerPalettePreview.Ramp = playerSettings.ColorRamp;

            var colorDropdown = generalPane.GetWidget <DropDownButtonWidget>("COLOR_DROPDOWN");

            colorDropdown.OnMouseDown = _ => ShowColorPicker(colorDropdown, playerSettings);
            colorDropdown.GetWidget <ColorBlockWidget>("COLORBLOCK").GetColor = () => playerSettings.ColorRamp.GetColor(0);

            // Debug
            var perftextCheckbox = generalPane.GetWidget <CheckboxWidget>("PERFTEXT_CHECKBOX");

            perftextCheckbox.IsChecked = () => debugSettings.PerfText;
            perftextCheckbox.OnClick   = () => debugSettings.PerfText ^= true;

            var perfgraphCheckbox = generalPane.GetWidget <CheckboxWidget>("PERFGRAPH_CHECKBOX");

            perfgraphCheckbox.IsChecked = () => debugSettings.PerfGraph;
            perfgraphCheckbox.OnClick   = () => debugSettings.PerfGraph ^= true;

            var checkunsyncedCheckbox = generalPane.GetWidget <CheckboxWidget>("CHECKUNSYNCED_CHECKBOX");

            checkunsyncedCheckbox.IsChecked = () => debugSettings.SanityCheckUnsyncedCode;
            checkunsyncedCheckbox.OnClick   = () => debugSettings.SanityCheckUnsyncedCode ^= true;

            // Video
            var windowModeDropdown = generalPane.GetWidget <DropDownButtonWidget>("MODE_DROPDOWN");

            windowModeDropdown.OnMouseDown = _ => SettingsMenuLogic.ShowWindowModeDropdown(windowModeDropdown, graphicsSettings);
            windowModeDropdown.GetText     = () => graphicsSettings.Mode == WindowMode.Windowed ?
                                             "Windowed" : graphicsSettings.Mode == WindowMode.Fullscreen ? "Fullscreen" : "Pseudo-Fullscreen";

            var pixelDoubleCheckbox = generalPane.GetWidget <CheckboxWidget>("PIXELDOUBLE_CHECKBOX");

            pixelDoubleCheckbox.IsChecked = () => graphicsSettings.PixelDouble;
            pixelDoubleCheckbox.OnClick   = () =>
            {
                graphicsSettings.PixelDouble ^= true;
                Game.viewport.Zoom            = graphicsSettings.PixelDouble ? 2 : 1;
            };

            generalPane.GetWidget("WINDOW_RESOLUTION").IsVisible = () => graphicsSettings.Mode == WindowMode.Windowed;
            var windowWidth = generalPane.GetWidget <TextFieldWidget>("WINDOW_WIDTH");

            windowWidth.Text = graphicsSettings.WindowedSize.X.ToString();

            var windowHeight = generalPane.GetWidget <TextFieldWidget>("WINDOW_HEIGHT");

            windowHeight.Text = graphicsSettings.WindowedSize.Y.ToString();

            // Audio
            var soundSlider = generalPane.GetWidget <SliderWidget>("SOUND_SLIDER");

            soundSlider.OnChange += x => { soundSettings.SoundVolume = x; Sound.SoundVolume = x; };
            soundSlider.Value     = soundSettings.SoundVolume;

            var musicSlider = generalPane.GetWidget <SliderWidget>("MUSIC_SLIDER");

            musicSlider.OnChange += x => { soundSettings.MusicVolume = x; Sound.MusicVolume = x; };
            musicSlider.Value     = soundSettings.MusicVolume;

            var shellmapMusicCheckbox = generalPane.GetWidget <CheckboxWidget>("SHELLMAP_MUSIC");

            shellmapMusicCheckbox.IsChecked = () => soundSettings.ShellmapMusic;
            shellmapMusicCheckbox.OnClick   = () => soundSettings.ShellmapMusic ^= true;

            // Input pane
            var inputPane = panel.GetWidget("INPUT_CONTROLS");

            inputPane.IsVisible = () => Settings == PanelType.Input;

            var inputButton = panel.GetWidget <ButtonWidget>("INPUT_BUTTON");

            inputButton.OnClick    = () => Settings = PanelType.Input;
            inputButton.IsDisabled = () => Settings == PanelType.Input;

            inputPane.GetWidget <CheckboxWidget>("CLASSICORDERS_CHECKBOX").IsDisabled = () => true;

            var scrollSlider = inputPane.GetWidget <SliderWidget>("SCROLLSPEED_SLIDER");

            scrollSlider.Value     = gameSettings.ViewportEdgeScrollStep;
            scrollSlider.OnChange += x => gameSettings.ViewportEdgeScrollStep = x;

            var edgescrollCheckbox = inputPane.GetWidget <CheckboxWidget>("EDGESCROLL_CHECKBOX");

            edgescrollCheckbox.IsChecked = () => gameSettings.ViewportEdgeScroll;
            edgescrollCheckbox.OnClick   = () => gameSettings.ViewportEdgeScroll ^= true;

            var mouseScrollDropdown = inputPane.GetWidget <DropDownButtonWidget>("MOUSE_SCROLL");

            mouseScrollDropdown.OnMouseDown = _ => ShowMouseScrollDropdown(mouseScrollDropdown, gameSettings);
            mouseScrollDropdown.GetText     = () => gameSettings.MouseScroll.ToString();

            var teamchatCheckbox = inputPane.GetWidget <CheckboxWidget>("TEAMCHAT_CHECKBOX");

            teamchatCheckbox.IsChecked = () => gameSettings.TeamChatToggle;
            teamchatCheckbox.OnClick   = () => gameSettings.TeamChatToggle ^= true;

            panel.GetWidget <ButtonWidget>("BACK_BUTTON").OnClick = () =>
            {
                playerSettings.Name = nameTextfield.Text;
                int x, y;
                int.TryParse(windowWidth.Text, out x);
                int.TryParse(windowHeight.Text, out y);
                graphicsSettings.WindowedSize = new int2(x, y);
                Game.Settings.Save();
                Ui.CloseWindow();
                onExit();
            };
        }