void AllValuesAreOfSameType() { if (!Objects.All(dv => dv.Value.ObjectType == ObjectTypes.Object)) { throw new Exception("some fields are not direct values"); } }
private IAction GetUpdateVisgroupsAction() { var states = VisgroupPanel.GetAllCheckStates(); var add = states.Where(x => x.Value == CheckState.Checked).Select(x => x.Key).ToList(); var rem = states.Where(x => x.Value == CheckState.Unchecked).Select(x => x.Key).ToList(); // If all the objects are in the add groups and none are in the remove groups, nothing needs to be changed if (Objects.All(x => add.All(y => x.IsInVisgroup(y, false)) && !rem.Any(y => x.IsInVisgroup(y, false)))) { return(null); } return(new EditObjectVisgroups(Objects, add, rem)); }
private void RefreshData() { if (!Objects.Any()) { Tabs.TabPages.Clear(); return; } UpdateVisgroups(false); var beforeTabs = Tabs.TabPages.OfType <TabPage>().ToArray(); if (!Tabs.TabPages.Contains(VisgroupTab)) { Tabs.TabPages.Add(VisgroupTab); } if (!Objects.All(x => x is Entity || x is World)) { Tabs.TabPages.Remove(ClassInfoTab); Tabs.TabPages.Remove(InputsTab); Tabs.TabPages.Remove(OutputsTab); Tabs.TabPages.Remove(FlagsTab); return; } if (!Tabs.TabPages.Contains(ClassInfoTab)) { Tabs.TabPages.Insert(0, ClassInfoTab); } if (!Tabs.TabPages.Contains(FlagsTab)) { Tabs.TabPages.Insert(Tabs.TabPages.Count - 1, FlagsTab); } if (Document.Game.Engine == Engine.Goldsource) { // Goldsource Tabs.TabPages.Remove(InputsTab); Tabs.TabPages.Remove(OutputsTab); } else { // Source if (!Tabs.TabPages.Contains(InputsTab)) { Tabs.TabPages.Insert(1, InputsTab); } if (!Tabs.TabPages.Contains(OutputsTab)) { Tabs.TabPages.Insert(2, OutputsTab); } } var afterTabs = Tabs.TabPages.OfType <TabPage>().ToArray(); // If the tabs changed, we want to reset to the first tab if (beforeTabs.Length != afterTabs.Length || beforeTabs.Except(afterTabs).Any()) { Tabs.SelectedIndex = 0; } _populating = true; Class.Items.Clear(); var allowWorldspawn = Objects.Any(x => x is World); Class.Items.AddRange(Document.GameData.Classes .Where(x => x.ClassType != ClassType.Base && (allowWorldspawn || x.Name != "worldspawn")) .Select(x => x.Name).OrderBy(x => x.ToLower()).OfType <object>().ToArray()); if (!Objects.Any()) { return; } var classes = Objects.Where(x => x is Entity || x is World).Select(x => x.GetEntityData().Name.ToLower()).Distinct().ToList(); var cls = classes.Count > 1 ? "" : classes[0]; if (classes.Count > 1) { Class.Text = @"<multiple types> - " + String.Join(", ", classes); SmartEditButton.Checked = SmartEditButton.Enabled = false; } else { var idx = Class.Items.IndexOf(cls); if (idx >= 0) { Class.SelectedIndex = idx; SmartEditButton.Checked = SmartEditButton.Enabled = true; } else { Class.Text = cls; SmartEditButton.Checked = SmartEditButton.Enabled = false; } } _values = TableValue.Create(Document.GameData, cls, Objects.Where(x => x is Entity || x is World).SelectMany(x => x.GetEntityData().Properties).Where(x => x.Key != "spawnflags").ToList()); _prevClass = cls; PopulateFlags(cls, Objects.Where(x => x is Entity || x is World).Select(x => x.GetEntityData().Flags).ToList()); _populating = false; UpdateKeyValues(); }