コード例 #1
0
 private void ClearSelected()
 {
     for (int i = selectedAisList.Items.Count - 1; i >= 0; i--)
     {
         AiAtIndexRemoved?.Invoke(i);
     }
     selectedAisList.Items.Clear();
 }
コード例 #2
0
        public StartGameConfigPanel()
        {
            var mapsListLabel = new Label
            {
                Dock = DockStyle.Top,
                Text = "Maps list. Click to select."
            };

            mapsList = new ListBox
            {
                Dock = DockStyle.Fill
            };
            mapsList.SelectedValueChanged += (sender, args) =>
            {
                if (mapsList.SelectedItem != null)
                {
                    MapChanged?.Invoke((NamedMap)mapsList.SelectedItem);
                }
            };
            var allAisListLabel = new Label
            {
                Dock = DockStyle.Bottom,
                Text = "AIs list. Double click to add AI."
            };

            allAisList = new ListBox
            {
                Dock   = DockStyle.Bottom,
                Height = 200
            };
            allAisList.DoubleClick += (sender, args) =>
            {
                if (allAisList.SelectedItem != null)
                {
                    AiSelected?.Invoke((AiFactory)allAisList.SelectedItem);
                }
            };
            var selectedAisListLabel = new Label
            {
                Dock = DockStyle.Bottom,
                Text = "Selected AIs list. Double click to remove."
            };

            selectedAisList = new ListBox
            {
                Dock   = DockStyle.Bottom,
                Height = 100
            };
            var enableFutures = new CheckBox
            {
                Text       = "ENABLE FUTURES",
                Dock       = DockStyle.Bottom,
                CheckState = CheckState.Checked
            };
            var enablSplurges = new CheckBox
            {
                Text       = "ENABLE SPLURGES",
                Dock       = DockStyle.Bottom,
                CheckState = CheckState.Checked
            };
            var enablOptions = new CheckBox
            {
                Text       = "ENABLE OPTIONS",
                Dock       = DockStyle.Bottom,
                CheckState = CheckState.Checked
            };

            enableFutures.CheckStateChanged += (sender, args) =>
            {
                EnableFuturesChanged?.Invoke(enableFutures.Checked);
            };
            enablSplurges.CheckStateChanged += (sender, args) =>
            {
                EnableSplurgesChanged?.Invoke(enablSplurges.Checked);
            };
            enablOptions.CheckStateChanged += (sender, args) =>
            {
                EnableOptionsChanged?.Invoke(enablOptions.Checked);
            };
            selectedAisList.DoubleClick += (sender, args) =>
            {
                AiAtIndexRemoved?.Invoke(selectedAisList.SelectedIndex);
            };
            EnableFuturesChanged += enable =>
            {
                Settings.futures = enable;
            };
            EnableSplurgesChanged += enable =>
            {
                Settings.splurges = enable;
            };
            EnableOptionsChanged += enable =>
            {
                Settings.options = enable;
            };
            AiSelected += factory =>
            {
                var ai = factory.Create();
                SelectedAis.Add(ai);
                selectedAisList.Items.Add($"{ai.Name}:{ai.Version}");
            };
            AiAtIndexRemoved += index =>
            {
                selectedAisList.Items.RemoveAt(index);
                SelectedAis.RemoveAt(index);
            };
            MapChanged += map => { SelectedMap = map; };

            var fastAiSelectors = new TableLayoutPanel
            {
                Dock     = DockStyle.Bottom,
                AutoSize = true
            };

            for (var i = 1; i < 5; i++)
            {
                var cnt    = (int)Math.Pow(2, i);
                var button = new Button
                {
                    Text  = cnt.ToString(),
                    Dock  = DockStyle.Left,
                    Width = 30
                };
                button.Click += (_, __) => AddRandomAis(cnt);
                fastAiSelectors.Controls.Add(button, i, 0);
            }

            Controls.Add(mapsList);
            Controls.Add(mapsListLabel);
            Controls.Add(allAisListLabel);
            Controls.Add(fastAiSelectors);
            Controls.Add(allAisList);
            Controls.Add(selectedAisListLabel);
            Controls.Add(selectedAisList);
            Controls.Add(enableFutures);
            Controls.Add(enablSplurges);
            Controls.Add(enablOptions);
        }