Ejemplo n.º 1
0
        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;
        }
Ejemplo n.º 2
0
 private void NameChanged(object sender, EventArgs e)
 {
     btnOK.Enabled = !string.IsNullOrWhiteSpace(tbName.Text) && ItemPoolManager.GetItemPool(tbName.Text.Trim()) == null;
 }
Ejemplo n.º 3
0
        /// <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);
                        }
                    }
                }
            }
        }