コード例 #1
0
ファイル: CanvasMenu.cs プロジェクト: tzachshabtay/MonoAGS
 private void setDefaults(string name, Dictionary <string, object> overrideDefaults)
 {
     var(x, y)              = _editor.ToGameResolution(_topMenu.OriginalPosition.x, _topMenu.OriginalPosition.y, null);
     overrideDefaults["x"]  = x;
     overrideDefaults["y"]  = y;
     overrideDefaults["id"] = $"{name}{++_lastId}";
 }
コード例 #2
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);
        }