private void ItemsAfterSelect(object sender, TreeViewEventArgs e) { // Disable OK button until we have a valid image. btnOK.Enabled = false; SelectedItemName = null; pgPreview.SelectedObject = null; // Do we have something new? if (e.Node == null) { return; } // See if the "none" entry is selected. if (e.Node.Name.Equals("")) { btnOK.Enabled = true; return; } // See if the item is valid. var itemPool = ItemPoolManager.GetItemPool(e.Node.Name); if (itemPool == null) { return; } // OK, allow selecting it. btnOK.Enabled = true; SelectedItemName = e.Node.Name; pgPreview.SelectedObject = itemPool; }
/// <summary> /// Scans for issues. /// </summary> public void ScanForIssues() { if (_isValidationEnabled > 0) { return; } // Clear old list. ClearIssues(); // Check settings. foreach (string project in DataEditorSettingsProxy.Default.ContentProjects) { if (!File.Exists(project)) { AddIssue("Path to content project is invalid: " + project, IssueType.Warning); } } // Check factories. foreach (var factory in FactoryManager.GetFactories()) { ScanForIssues(factory); } // Check item pools. foreach (var pool in ItemPoolManager.GetItemPools()) { ScanForIssues(pool); } }
private void SaveClick(object sender, EventArgs e) { FactoryManager.Save(); ItemPoolManager.Save(); AttributePoolManager.Save(); _changesSinceLastSave = 0; UpdateUndoMenu(); }
private void HandleCleared() { // Disable validation and tree updates (performance). ++_isValidationEnabled; tvData.BeginUpdate(); // Clear the nodes. tvData.Nodes.Clear(); // Create factory base type nodes in tree. foreach (var type in FactoryManager.GetFactoryTypes()) { var baseType = type.BaseType; if (baseType != null && baseType != typeof(object)) { if (!tvData.Nodes.ContainsKey(baseType.AssemblyQualifiedName)) { tvData.Nodes.Add(baseType.AssemblyQualifiedName, CleanFactoryName(baseType)); } tvData.Nodes[baseType.AssemblyQualifiedName].Nodes.Add(type.AssemblyQualifiedName, CleanFactoryName(type)); } else { tvData.Nodes.Add(type.AssemblyQualifiedName, CleanFactoryName(type)); } } // Create entries for pools. tvData.Nodes.Add(typeof(ItemPool).AssemblyQualifiedName, typeof(ItemPool).Name); tvData.Nodes.Add(typeof(AttributePool).AssemblyQualifiedName, typeof(AttributePool).Name); // Re-add existing data. foreach (var factory in FactoryManager.GetFactories()) { HandleFactoryAdded(factory); } foreach (var pool in ItemPoolManager.GetItemPools()) { HandleItemPoolAdded(pool); } foreach (var pool in AttributePoolManager.GetAttributePools()) { HandleAttributePoolAdded(pool); } // Reenable tree updating and validation. tvData.EndUpdate(); --_isValidationEnabled; // Rescan. ScanForIssues(); }
/// <summary> /// Loads all factories and so on found at the specified path. /// </summary> /// <param name="path">The path.</param> private void LoadData(string path) { // Disable validation and tree updates while loading, because // there will be a lot of changes (and redundant updates otherwise). ++_isValidationEnabled; tvData.BeginUpdate(); // Load stuff. FactoryManager.Load(path); ItemPoolManager.Load(path); AttributePoolManager.Load(path); // Reenable tree and validation. tvData.EndUpdate(); --_isValidationEnabled; // Done loading, see if there are any problem with what we got. ScanForIssues(); }
private void ItemInfoDialogLoad(object sender, EventArgs e) { tvItems.BeginUpdate(); tvItems.Nodes.Clear(); tvItems.Nodes.Add("", "None"); foreach (var itemPool in ItemPoolManager.GetItemPools()) { var typeName = itemPool.GetType().Name; if (!tvItems.Nodes.ContainsKey(typeName)) { var cleanTypeName = typeName; if (typeName.EndsWith("Factory")) { cleanTypeName = typeName.Substring(0, typeName.Length - "Factory".Length); } tvItems.Nodes.Add(typeName, cleanTypeName); } tvItems.Nodes[typeName].Nodes.Add(itemPool.Name, itemPool.Name); } tvItems.EndUpdate(); var select = tvItems.Nodes.Find(SelectedItemName, true); if (select.Length > 0) { tvItems.SelectedNode = select[0]; } else { tvItems.SelectedNode = null; } // Close directly if there are no items we can select. if (tvItems.Nodes.Count == 1) { MessageBox.Show("No slots remaining, or no items known that would fit the slots.", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); DialogResult = DialogResult.Cancel; } }
private void AddItemPoolClick(object sender, EventArgs e) { if (_itemPoolDialog.ShowDialog(this) == DialogResult.OK) { var name = _itemPoolDialog.ItemPoolName; try { // Create a new instance. var instance = new ItemPool { Name = name }; // Register it. ItemPoolManager.Add(instance); // And select it. SelectItemPool(instance); // Add undo command. PushUndo("add item pool", () => { if (MessageBox.Show(this, "Are you sure you wish to delete the item pool '" + instance.Name + "'?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { ItemPoolManager.Remove(instance); return(true); } return(false); }); } catch (Exception ex) { MessageBox.Show(this, "Failed creating new item pool:\n" + ex, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void NameChanged(object sender, EventArgs e) { btnOK.Enabled = !string.IsNullOrWhiteSpace(tbName.Text) && ItemPoolManager.GetItemPool(tbName.Text.Trim()) == null; }
private bool HandleObjectNameChanged(object oldValue, object newValue, GridItem changedItem) { // See if what we changed is the name of the selected object. if (ReferenceEquals(changedItem.PropertyDescriptor, TypeDescriptor.GetProperties(pgProperties.SelectedObject)["Name"])) { // Yes, get old and new value. var oldName = oldValue as string; var newName = newValue as string; // Adjust manager layout, this will throw as necessary. tvData.BeginUpdate(); try { if (pgProperties.SelectedObject is IFactory) { FactoryManager.Rename(oldName, newName); } else if (pgProperties.SelectedObject is ItemPool) { ItemPoolManager.Rename(oldName, newName); } else if (pgProperties.SelectedObject is AttributePool) { AttributePoolManager.Rename(oldName, newName); } } catch (ArgumentException ex) { // Revert to old name. if (pgProperties.SelectedObject is IFactory) { ((IFactory)pgProperties.SelectedObject).Name = oldName; } else if (pgProperties.SelectedObject is ItemPool) { ((ItemPool)pgProperties.SelectedObject).Name = oldName; } else if (pgProperties.SelectedObject is AttributePool) { ((AttributePool)pgProperties.SelectedObject).Name = oldName; } // Tell the user why. MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } finally { // Stop updating the tree. tvData.EndUpdate(); } if (pgProperties.SelectedObject is IFactory) { SelectFactory((IFactory)pgProperties.SelectedObject); } else if (pgProperties.SelectedObject is ItemPool) { SelectItemPool((ItemPool)pgProperties.SelectedObject); } else if (pgProperties.SelectedObject is AttributePool) { SelectAttributePool((AttributePool)pgProperties.SelectedObject); } SelectProperty("Name"); } else { // Rescan for issues related to this property. if (changedItem.PropertyDescriptor != null && changedItem.PropertyDescriptor.Attributes[typeof(TriggersFullValidationAttribute)] == null) { if (pgProperties.SelectedObject is IFactory) { ScanForIssues((IFactory)pgProperties.SelectedObject); } else if (pgProperties.SelectedObject is ItemPool) { ScanForIssues((ItemPool)pgProperties.SelectedObject); } // Done, avoid the full rescan. return(true); } } // Do a full scan when we come here. ScanForIssues(); return(true); }
private void RemoveClick(object sender, EventArgs e) { if (pgProperties.SelectedObject == null) { return; } if (tvData.Focused || (sender == miDelete && miDelete.Visible)) { if (pgProperties.SelectedObject is IFactory) { var factory = (IFactory)pgProperties.SelectedObject; if ((ModifierKeys & Keys.Shift) != 0 || MessageBox.Show(this, "Are you sure you wish to delete the factory '" + factory.Name + "'?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { FactoryManager.Remove(factory); // Add undo command. PushUndo("remove factory", () => { FactoryManager.Add(factory); return(true); }); } } else if (pgProperties.SelectedObject is ItemPool) { var itemPool = (ItemPool)pgProperties.SelectedObject; if ((ModifierKeys & Keys.Shift) != 0 || MessageBox.Show(this, "Are you sure you wish to delete the item pool '" + itemPool.Name + "'?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { ItemPoolManager.Remove(itemPool); // Add undo command. PushUndo("remove item pool", () => { ItemPoolManager.Add(itemPool); return(true); }); } } else if (pgProperties.SelectedObject is AttributePool) { var attributePool = (AttributePool)pgProperties.SelectedObject; if ((ModifierKeys & Keys.Shift) != 0 || MessageBox.Show(this, "Are you sure you wish to delete the attribute pool '" + attributePool.Name + "'?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { AttributePoolManager.Remove(attributePool); // Add undo command. PushUndo("remove attribute pool", () => { AttributePoolManager.Add(attributePool); return(true); }); } } } }
public override T Load <T>(string assetName) { var g = (IGraphicsDeviceService)ServiceProvider.GetService(typeof(IGraphicsDeviceService)); if (typeof(T) == typeof(Texture2D)) { if (_textures.ContainsKey(assetName)) { return((T)(object)_textures[assetName]); } using (var img = Image.FromFile(ContentProjectManager.GetTexturePath(assetName))) { var bmp = new Bitmap(img); var data = new uint[bmp.Width * bmp.Height]; for (var y = 0; y < bmp.Height; ++y) { for (var x = 0; x < bmp.Width; ++x) { var pixel = bmp.GetPixel(x, y); data[x + y * bmp.Width] = Microsoft.Xna.Framework.Color.FromNonPremultiplied(pixel.R, pixel.G, pixel.B, pixel.A). PackedValue; } } if (g != null) { var t = new Texture2D(g.GraphicsDevice, img.Width, img.Height); t.SetData(data); _textures.Add(assetName, t); return((T)(object)t); } else { throw new InvalidOperationException("Must wait with loading until graphics device is initialized."); } } } else if (typeof(T) == typeof(Effect)) { if (_shaders.ContainsKey(assetName)) { return((T)(object)_shaders[assetName]); } var shaderPath = ContentProjectManager.GetShaderPath(assetName); if (shaderPath != null) { using (var file = File.OpenText(shaderPath)) { var sourceCode = file.ReadToEnd(); var effectSource = new EffectContent { EffectCode = sourceCode, Identity = new ContentIdentity { SourceFilename = assetName } }; var processor = new EffectProcessor(); var compiledEffect = processor.Process(effectSource, new DummyProcessorContext()); var effect = new Effect(g.GraphicsDevice, compiledEffect.GetEffectCode()); _shaders.Add(assetName, effect); return((T)(object)effect); } } } else if (typeof(T) == typeof(ParticleEffect)) { using (var xmlReader = XmlReader.Create(ContentProjectManager.GetEffectPath(assetName))) { var effect = IntermediateSerializer.Deserialize <ParticleEffect>(xmlReader, null); effect.Initialise(); effect.LoadContent(this); return((T)(object)effect); } } else if (typeof(T) == typeof(IFactory[])) { return((T)(object)FactoryManager.GetFactoriesFromFile(assetName).ToArray()); } else if (typeof(T) == typeof(ItemPool[])) { return((T)(object)ItemPoolManager.GetItemPools().ToArray()); } else if (typeof(T) == typeof(AttributePool[])) { return((T)(object)AttributePoolManager.GetAttributePools().ToArray()); } return(default(T)); }
/// <summary> /// Check all known asset reference types for validity (i.e. whether the referenced object exists). /// </summary> /// <param name="main">The main object this relates to.</param> /// <param name="current">The current object being checked (that is some child of the main object).</param> /// <param name="prefix">The "path" to the current object in the main object, separated by dots ('.').</param> private void ScanReferences(object main, object current, string prefix = null) { // Skip null objects. if (main == null || current == null) { return; } // Adjust our prefix. prefix = string.IsNullOrWhiteSpace(prefix) ? "" : (prefix + "."); // Known checks: editor type to recognize the property, display name (in issue) and method to check validity. var checks = new[] { Tuple.Create <Type, string, Func <string, bool> >(typeof(TextureAssetEditor), "texture asset", ContentProjectManager.HasTextureAsset), Tuple.Create <Type, string, Func <string, bool> >(typeof(EffectAssetEditor), "effect asset", ContentProjectManager.HasEffectAsset), Tuple.Create <Type, string, Func <string, bool> >(typeof(ItemInfoEditor), "item", s => FactoryManager.GetFactory(s) as ItemFactory != null), Tuple.Create <Type, string, Func <string, bool> >(typeof(ItemPoolEditor), "item", s => FactoryManager.GetFactory(s) as ItemFactory != null), Tuple.Create <Type, string, Func <string, bool> >(typeof(ItemPoolChooserEditor), "item pool", s => ItemPoolManager.GetItemPool(s) != null), Tuple.Create <Type, string, Func <string, bool> >(typeof(PlanetEditor), "planet", s => FactoryManager.GetFactory(s) as PlanetFactory != null), Tuple.Create <Type, string, Func <string, bool> >(typeof(SunEditor), "sun", s => FactoryManager.GetFactory(s) as SunFactory != null) }; // Perform all checks. foreach (var check in checks) { // Get properties we can handle with this check. foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(current, new Attribute[] { new EditorAttribute(check.Item1, typeof(UITypeEditor)) })) { // See if the actual value is a string, which is the format we store the references in. if (property.PropertyType != typeof(string)) { AddIssue("Property marked as " + check.Item2 + " is not of type string.", main, prefix + property.Name, IssueType.Warning); } else { // Check if the reference is valid, ignore empty ones. var path = (string)property.GetValue(current); if (!string.IsNullOrWhiteSpace(path) && !check.Item3(path.Replace('\\', '/'))) { AddIssue("Invalid or unknown " + check.Item2 + " name.", main, prefix + property.Name, IssueType.Error); } } } } }