コード例 #1
0
ファイル: CookingRulesEditor.cs プロジェクト: klenin/Citrus
 private ParticularCookingRules RulesForActiveTarget(CookingRules CookingRules)
 {
     return(RulesForTarget(CookingRules, activeTarget));
 }
コード例 #2
0
ファイル: CookingRulesEditor.cs プロジェクト: klenin/Citrus
 private static ParticularCookingRules RulesForTarget(CookingRules CookingRules, Target target)
 {
     return(target == null ? CookingRules.CommonRules : CookingRules.TargetRules[target]);
 }
コード例 #3
0
ファイル: CookingRulesEditor.cs プロジェクト: klenin/Citrus
        private void CreateOverridesWidgets(CookingRulesCollection crc, string key, Target target, Meta.Item yi, CookingRules rules, Widget overridesWidget)
        {
            Widget innerContainer;
            var    sourceFilenameText = string.IsNullOrEmpty(rules.SourceFilename)
                                ? "Default"
                                : rules.SourceFilename.Substring(The.Workspace.AssetsDirectory.Length);
            var targetName = target == null ? "" : $" ({target.Name})";
            var container  = new Widget {
                Padding = new Thickness {
                    Right = 30
                },
                Nodes =
                {
                    (innerContainer    = new Widget {
                        Layout         = new HBoxLayout(),
                    }),
                    new ThemedSimpleText(sourceFilenameText + targetName)
                    {
                        FontHeight     = 16,
                        ForceUncutText = false,
                        OverflowMode   = TextOverflowMode.Ellipsis,
                        HAlignment     = HAlignment.Right,
                        VAlignment     = VAlignment.Center,
                        MinSize        = new Vector2(100, RowHeight),
                        MaxSize        = new Vector2(500, RowHeight)
                    },
                    (new ToolbarButton {
                        Texture        = IconPool.GetTexture("Filesystem.ArrowRight"),
                        Padding        = Thickness.Zero,
                        Size           = RowHeight * Vector2.One,
                        MinMaxSize     = RowHeight * Vector2.One,
                        Clicked        = () => navigateAndSelect(rules.SourceFilename),
                    })
                },
                Layout = new HBoxLayout(),
            };

            container.CompoundPostPresenter.Add(new DelegatePresenter <Widget>((w) => {
                var topmostOverride = crc[key];
                while (
                    topmostOverride.Parent != null &&
                    !(topmostOverride.CommonRules.FieldOverrides.Contains(yi) ||
                      RulesForActiveTarget(topmostOverride).FieldOverrides.Contains(yi))
                    )
                {
                    topmostOverride = topmostOverride.Parent;
                }
                w.PrepareRendererState();
                if (target != activeTarget || rules != topmostOverride)
                {
                    Renderer.DrawLine(10.0f - 30.0f, w.Height * 0.6f, w.Width - 10.0f, w.Height * 0.6f, Color4.Black.Transparentify(0.5f), 1.0f);
                }
                else
                {
                    Renderer.DrawRect(Vector2.Right * -20.0f, w.Size, Color4.Green.Lighten(0.5f).Transparentify(0.5f));
                }
            }));
            container.Components.Add(new PropertyOverrideComponent {
                Rules    = rules,
                YuzuItem = yi,
            });
            overridesWidget.Nodes.Add(container);
            var targetRuels  = RulesForTarget(rules, target);
            var editorParams = new PropertyEditorParams(innerContainer, targetRuels, yi.Name)
            {
                ShowLabel      = false,
                PropertySetter = (owner, name, value) => {
                    yi.SetValue(owner, value);
                    targetRuels.Override(name);
                    rules.DeduceEffectiveRules(target);
                    rules.Save();
                },
                NumericEditBoxFactory = () => {
                    var r = new ThemedNumericEditBox();
                    r.MinMaxHeight           = r.Height = RowHeight;
                    r.TextWidget.VAlignment  = VAlignment.Center;
                    r.TextWidget.Padding.Top = r.TextWidget.Padding.Bottom = 0.0f;
                    return(r);
                },
                DropDownListFactory = () => {
                    var r = new ThemedDropDownList();
                    r.MinMaxHeight = r.Height = RowHeight;
                    return(r);
                },
                EditBoxFactory = () => {
                    var r = new ThemedEditBox();
                    r.MinMaxHeight           = r.Height = RowHeight;
                    r.TextWidget.Padding.Top = r.TextWidget.Padding.Bottom = 0.0f;
                    return(r);
                },
            };

            CreatePropertyEditorForType(yi, editorParams);
        }
コード例 #4
0
ファイル: CookingRulesEditor.cs プロジェクト: klenin/Citrus
        private void CreateHeaderWidgets(CookingRulesCollection crc, string path, Meta.Item yi,
                                         Widget headerWidget, Widget overridesWidget, CookingRules rules)
        {
            SimpleText computedValueText;
            Button     createOrDestroyOverride = null;

            headerWidget.HitTestTarget = true;
            headerWidget.CompoundPostPresenter.Add(new DelegatePresenter <Widget>((widget) => {
                if (widget.IsMouseOver())
                {
                    widget.PrepareRendererState();
                    Renderer.DrawRect(
                        Vector2.Zero,
                        widget.Size,
                        Theme.Colors.SelectedBackground.Transparentify(0.8f));
                }
            }));
            Func <ITexture> btnTexture = () => IsOverridedByAssociatedCookingRules(crc, path, yi) ? IconPool.GetTexture("Filesystem.Cross") : IconPool.GetTexture("Filesystem.Plus");
            Widget          foldButton;

            headerWidget.Nodes.AddRange(
                (foldButton = CreateFoldButton(overridesWidget)),
                (new ThemedSimpleText {
                ForceUncutText = false,
                VAlignment = VAlignment.Center,
                HAlignment = HAlignment.Left,
                OverflowMode = TextOverflowMode.Ellipsis,
                LayoutCell = new LayoutCell {
                    StretchX = 1
                },
                Size = new Vector2(150, RowHeight),
                MinSize = new Vector2(100, RowHeight),
                MaxSize = new Vector2(200, RowHeight),
                Text = yi.Name,
            }),
                (computedValueText = new ThemedSimpleText {
                LayoutCell = new LayoutCell {
                    StretchX = 3
                },
                ForceUncutText = false,
                HAlignment = HAlignment.Left,
                Size = new Vector2(150, RowHeight),
                MinSize = new Vector2(50, RowHeight),
                MaxSize = new Vector2(300, RowHeight),
            }),
                (createOrDestroyOverride = new ToolbarButton {
                Texture = btnTexture(),
                Clicked = () => CreateOrDestroyFieldOverride(crc, path, yi, overridesWidget, createOrDestroyOverride),
            })
                );
            headerWidget.Clicked            = foldButton.Clicked;
            createOrDestroyOverride.Padding = Thickness.Zero;
            createOrDestroyOverride.Size    = createOrDestroyOverride.MinMaxSize = RowHeight * Vector2.One;
            if (IsCookingRulesFileItself(path))
            {
                rules = GetAssociatedCookingRules(crc, path);
            }
            computedValueText.AddChangeWatcher(() => yi.GetValue(rules.EffectiveRules),
                                               (o) => computedValueText.Text = rules.FieldValueToString(yi, yi.GetValue(rules.EffectiveRules)));
        }
コード例 #5
0
ファイル: CookingRulesEditor.cs プロジェクト: klenin/Citrus
        private static CookingRules GetAssociatedCookingRules(CookingRulesCollection crc, string path, bool createIfNotExists = false)
        {
            Action <string, CookingRules> ignoreRules = (p, r) => {
                r        = r.InheritClone();
                r.Ignore = true;
                crc[NormalizePath(p)] = r;
            };

            path = AssetPath.CorrectSlashes(path);
            string       key = NormalizePath(path);
            CookingRules cr  = null;

            if (File.GetAttributes(path) == FileAttributes.Directory)
            {
                // Directory
                var crPath = AssetPath.Combine(path, Orange.CookingRulesBuilder.CookingRulesFilename);
                if (crc.ContainsKey(key))
                {
                    cr = crc[key];
                    if (cr.SourceFilename != crPath)
                    {
                        if (createIfNotExists)
                        {
                            cr       = cr.InheritClone();
                            crc[key] = cr;
                            ignoreRules(crPath, cr);
                        }
                        else
                        {
                            return(null);
                        }
                    }
                }
                else
                {
                    throw new Lime.Exception("CookingRule record for directory should already be present in collection");
                }
                cr.SourceFilename = crPath;
            }
            else
            {
                bool   isPerDirectory = Path.GetFileName(path) == CookingRulesBuilder.CookingRulesFilename;
                bool   isPerFile      = path.EndsWith(".txt") && File.Exists(path.Remove(path.Length - 4));
                string filename       = isPerFile ? path.Remove(path.Length - 4) : path;
                if (isPerDirectory || isPerFile)
                {
                    // Cooking Rules File itself
                    if (crc.ContainsKey(key))
                    {
                        cr = crc[key].Parent;
                    }
                    else
                    {
                        throw new Lime.Exception("CookingRule record for cooking rules file itself should already be present in collection");
                    }
                }
                else
                {
                    // Regular File
                    var crPath = path + ".txt";
                    var crKey  = NormalizePath(crPath);
                    if (crc.ContainsKey(crKey))
                    {
                        cr = crc[crKey].Parent;
                    }
                    else if (!createIfNotExists)
                    {
                        return(null);
                    }
                    else if (crc.ContainsKey(NormalizePath(path)))
                    {
                        cr = crc[NormalizePath(path)].InheritClone();
                        cr.SourceFilename = crPath;
                        ignoreRules(crPath, cr);
                        crc[key] = cr;
                    }
                    else
                    {
                        throw new Lime.Exception("CookingRule record for any regular file should already be present in collection");
                    }
                }
            }
            return(cr);
        }