Beispiel #1
0
        private async void showWizard(string name, Target target, object factory, string methodName)
        {
            var(method, methodAttribute) = getMethod(factory, methodName);
            HashSet <string>            hideProperties   = new HashSet <string>();
            Dictionary <string, object> overrideDefaults = new Dictionary <string, object>();

            foreach (var param in method.GetParameters())
            {
                var attr = param.GetCustomAttribute <MethodParamAttribute>();
                if (attr == null)
                {
                    continue;
                }
                if (!attr.Browsable)
                {
                    hideProperties.Add(param.Name);
                }
                if (attr.DefaultProvider != null)
                {
                    var resolver = _editor.GameResolver;
                    var provider = factory.GetType().GetMethod(attr.DefaultProvider);
                    if (provider == null)
                    {
                        throw new NullReferenceException($"Failed to find method with name: {attr.DefaultProvider ?? "null"}");
                    }
                    overrideDefaults[param.Name] = provider.Invoke(null, new[] { resolver });
                }
                else if (attr.Default != null)
                {
                    overrideDefaults[param.Name] = attr.Default;
                }
            }

            _topMenu.Visible = false;

            var(x, y)              = _editor.ToGameResolution(_topMenu.OriginalPosition.x, _topMenu.OriginalPosition.y, null);
            overrideDefaults["x"]  = x;
            overrideDefaults["y"]  = y;
            overrideDefaults["id"] = $"{name}{++_lastId}";
            var wizard = new MethodWizard(method, hideProperties, overrideDefaults, panel => addTargetUIForCreate(panel, target), _editor, validate);

            wizard.Load();
            var parameters = await wizard.ShowAsync();

            if (parameters == null)
            {
                return;
            }
            foreach (var param in overrideDefaults.Keys)
            {
                parameters[param] = get(param, parameters) ?? overrideDefaults[param];
            }
            (object result, MethodModel model) = runMethod(method, factory, parameters);
            List <object> entities = getEntities(factory, result, methodAttribute);

            addNewEntities(entities, model);
        }
Beispiel #2
0
        private async Task <(object result, MethodModel model, MethodWizardAttribute attr)> run(object factory, Type factoryType, string methodName)
        {
            var(method, methodAttribute) = getMethod(factoryType, methodName);
            HashSet <string>            hideProperties   = new HashSet <string>();
            Dictionary <string, object> overrideDefaults = new Dictionary <string, object>();

            foreach (var param in method.GetParameters())
            {
                var attr = param.GetCustomAttribute <MethodParamAttribute>();
                if (attr == null)
                {
                    continue;
                }
                if (!attr.Browsable)
                {
                    hideProperties.Add(param.Name);
                }
                if (attr.DefaultProvider != null)
                {
                    var resolver = _editor.GameResolver;
                    var provider = factoryType.GetMethod(attr.DefaultProvider);
                    if (provider == null)
                    {
                        throw new NullReferenceException($"Failed to find method with name: {attr.DefaultProvider ?? "null"}");
                    }
                    overrideDefaults[param.Name] = provider.Invoke(null, new object[] { resolver });
                }
                else if (attr.Default != null)
                {
                    overrideDefaults[param.Name] = attr.Default;
                }
            }

            _setDefaults?.Invoke(overrideDefaults);
            var wizard = new MethodWizard(_parentForm, _title, method, hideProperties, overrideDefaults, _addUiExternal, _editor, _validate);

            wizard.Load();
            var parameters = await wizard.ShowAsync();

            if (parameters == null)
            {
                return(null, null, null);
            }
            foreach (var param in overrideDefaults.Keys)
            {
                if (!parameters.ContainsKey(param))
                {
                    parameters[param] = new ValueModel(overrideDefaults[param]);
                }
            }
            (object result, MethodModel model) = runMethod(method, factory, parameters);
            return(result, model, methodAttribute);
        }