private void ItemsAfterSelect(object sender, TreeViewEventArgs e) { // Disable OK button until we have a valid image. btnOK.Enabled = false; SelectedAtributeName = 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 = AttributePoolManager.GetAttributePool(e.Node.Name); if (itemPool == null) { return; } // OK, allow selecting it. btnOK.Enabled = true; SelectedAtributeName = e.Node.Name; pgPreview.SelectedObject = itemPool; }
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 AttributePoolDialogLoad(object sender, EventArgs e) { tvItems.BeginUpdate(); tvItems.Nodes.Clear(); tvItems.Nodes.Add("", "None"); foreach (var itemPool in AttributePoolManager.GetAttributePools()) { 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(SelectedAtributeName, 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 AddAttributePoolClick(object sender, EventArgs e) { if (_attributePoolDialog.ShowDialog(this) == DialogResult.OK) { var name = _attributePoolDialog.AttributePoolName; try { // Create a new instance. var instance = new AttributePool { Name = name }; // Register it. AttributePoolManager.Add(instance); // And select it. SelectAttributePool(instance); // Add undo command. PushUndo("add attribute pool", () => { if (MessageBox.Show(this, "Are you sure you wish to delete the attribute pool '" + instance.Name + "'?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { AttributePoolManager.Remove(instance); return(true); } return(false); }); } catch (Exception ex) { MessageBox.Show(this, "Failed creating new attribute pool:\n" + ex, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
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)); }
private void NameChanged(object sender, EventArgs e) { btnOK.Enabled = !string.IsNullOrWhiteSpace(tbName.Text) && AttributePoolManager.GetAttributePool(tbName.Text.Trim()) == null; }