Example #1
0
        /// <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);
            }
        }
Example #2
0
        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();
        }
Example #3
0
        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;
            }
        }
Example #4
0
        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));
        }