Example #1
0
        public static ColorRemap CreateFromSkin(SvgSkin skin)
        {
            var ret = new ColorRemap(true);

            ret.InitGroups(skin);
            ret.Name = "Default theme";

            // extract fills and strokes from skin
            foreach (var group in ret._groups)
            {
                foreach (var elem in group)
                {
                    // ensure element has an internal id which we can use to refer to it from our dict
                    if (string.IsNullOrEmpty(elem.ID))
                    {
                        elem.SetAndForceUniqueID(elem.ElementName, true, null);
                    }

                    Color fill   = Color.Empty;
                    Color stroke = Color.Empty;
                    if (elem.Fill is SvgColourServer cf)
                    {
                        fill = cf.Colour;
                    }
                    if (elem.Stroke is SvgColourServer cs)
                    {
                        stroke = cs.Colour;
                    }
                    ret.Elements[elem.ID] = Tuple.Create(fill, stroke);
                }
            }
            return(ret);
        }
Example #2
0
        public static ColorRemap LoadFrom(SvgElement xRemap)
        {
            ColorRemap ret = new ColorRemap();

            ret.Name = xRemap.CustomAttributes["name"];
            ret.UUID = Guid.Parse(xRemap.CustomAttributes["UUID"]);

            foreach (SvgElement x in xRemap.Children)
            {
                string id;
                if (x.CustomAttributes.ContainsKey("tgt-id"))
                {
                    id = x.CustomAttributes["tgt-id"];
                }
                else
                {
                    id = x.ID;                  // legacy thing
                }
                Color fill = new Color(), stroke = new Color();
                if (x.Fill is SvgColourServer cf)
                {
                    fill = cf.Colour;
                }
                if (x.Stroke is SvgColourServer cs)
                {
                    stroke = cs.Colour;
                }
                ret.Elements[id] = Tuple.Create(fill, stroke);
            }
            return(ret);
        }
Example #3
0
        public static ColorRemap LoadFrom(XmlNode xRemap)
        {
            ColorRemap ret = new ColorRemap();

            ret.Name = xRemap.Attributes["name"].Value;
            ret.UUID = Guid.Parse(xRemap.Attributes["UUID"].Value);

            foreach (XmlNode x in xRemap.ChildNodes)
            {
                string id;
                if (x.Attributes["tgt-id"] != null)
                {
                    id = x.Attributes["tgt-id"].Value;
                }
                else if (x.Attributes["id"] != null)
                {
                    id = x.Attributes["id"].Value;                                                  // legacy but can only contain one remap per skin if using id
                }
                else
                {
                    continue;
                }

                Color fill   = ColorTranslator.FromHtml(x.Attributes["fill"].Value);
                Color stroke = ColorTranslator.FromHtml(x.Attributes["stroke"].Value);

                ret.Elements[id] = Tuple.Create(fill, stroke);
            }
            return(ret);
        }
Example #4
0
        public ColorRemap Clone()
        {
            var ret = new ColorRemap(false);

            ret.Name = this.Name + " (copy)";

            foreach (var kvp in this.Elements)
            {
                ret.Elements[kvp.Key] = kvp.Value;
            }
            ret.IsSkinDefault = false;

            return(ret);
        }
Example #5
0
        public void Load(string svgPath)
        {
            try {
                Path        = svgPath;
                SvgDocument = SvgDocument.Open(svgPath);
                _dimensions = SvgDocument.GetDimensions();

                // load button/stick/trigger mapping from svg
                RecursiveGetElements(SvgDocument);

                DefaultRemap = ColorRemap.CreateFromSkin(this);
                EmbeddedRemaps.Insert(0, DefaultRemap);
                EmbeddedRemaps.ForEach(r => r.IsSkinDefault = true);

                LoadResult = Controllers.Any() ? SkinLoadResult.Ok : SkinLoadResult.Fail;
            }
            catch { LoadResult = SkinLoadResult.Fail; }
        }
Example #6
0
 public void ApplyRemap(ColorRemap remap)
 {
     if (remap == null)
     {
         remap = DefaultRemap;
     }
     foreach (var remapEntry in remap.Elements)
     {
         var elem = this.SvgDocument.GetElementById(remapEntry.Key);
         if (elem == null)
         {
             continue;
         }
         if (elem.Fill is SvgColourServer f)
         {
             f.Colour = remapEntry.Value.Item1;
         }
         if (elem.Stroke is SvgColourServer s)
         {
             s.Colour = remapEntry.Value.Item2;
         }
     }
 }
Example #7
0
        private void RecursiveGetElements(SvgElement e)
        {
            foreach (var c in e.Children)
            {
                if (c.ElementName == "info")
                {
                    if (c.CustomAttributes.ContainsKey("device-name"))
                    {
                        string devName = c.CustomAttributes["device-name"];
                        // match on name for compatibility reasons
                        if (devName == "NinHID SNES")
                        {
                            Controllers.Add(ControllerType.SNES);
                        }
                        else if (devName == "NinHID N64")
                        {
                            Controllers.Add(ControllerType.N64);
                        }
                        else if (devName == "NinHID NGC")
                        {
                            Controllers.Add(ControllerType.NGC);
                        }
                    }

                    if (c.CustomAttributes.ContainsKey("device-type"))
                    {
                        string         devType = c.CustomAttributes["device-type"];
                        ControllerType type;
                        if (Enum.TryParse(devType, true, out type))
                        {
                            Controllers.Add(type);
                        }
                    }

                    Name = c.CustomAttributes["skin-name"];
                }

                if (c.ContainsAttribute("stick-id"))
                {
                    var s     = c as SvgVisualElement;
                    var stick = new Stick {
                        Id             = int.Parse(c.CustomAttributes["stick-id"]),
                        HorizontalAxis = int.Parse(c.CustomAttributes["axis-h"]),
                        VerticalAxis   = int.Parse(c.CustomAttributes["axis-v"]),
                        OffsetScale    = float.Parse(c.CustomAttributes["offset-scale"], CultureInfo.InvariantCulture),
                        Z        = c.ContainsAttribute("z-index") ? int.Parse(c.CustomAttributes["z-index"]) : 1,
                        ButtonId = c.ContainsAttribute("button-id") ? int.Parse(c.CustomAttributes["button-id"]) : -1,
                    };

                    bool pressed = stick.ButtonId != -1 && c.ContainsAttribute("button-state") &&
                                   c.CustomAttributes["button-state"] == "pressed";
                    if (pressed)
                    {
                        stick.Pressed = s;
                    }
                    else
                    {
                        stick.Element = s;
                    }

                    stick.Deadzone = c.ContainsAttribute("deadzone") ? int.Parse(c.CustomAttributes["deadzone"]) : 0;

                    Sticks.Add(stick);
                }

                else if (c.ContainsAttribute("button-id"))
                {
                    var  b       = c as SvgVisualElement;
                    bool pressed = c.CustomAttributes["button-state"] == "pressed";
                    var  button  = new Button {
                        Id = int.Parse(c.CustomAttributes["button-id"])
                    };

                    if (c.ContainsAttribute("z-index"))
                    {
                        button.Z = int.Parse(c.CustomAttributes["z-index"]);
                    }

                    if (pressed)
                    {
                        button.Pressed = b;
                    }
                    else
                    {
                        button.Element = b;
                    }
                    Buttons.Add(button);
                }

                else if (c.ContainsAttribute("trigger-id"))
                {
                    var t = c as SvgVisualElement;

                    var trigger = new Trigger {
                        Id = int.Parse(c.CustomAttributes["trigger-id"])
                    };
                    trigger.Element = t;
                    trigger.Axis    = int.Parse(c.CustomAttributes["trigger-axis"]);

                    if (c.ContainsAttribute("offset-scale"))
                    {
                        trigger.OffsetScale = float.Parse(c.CustomAttributes["offset-scale"], CultureInfo.InvariantCulture);
                    }

                    if (c.ContainsAttribute("z-index"))
                    {
                        trigger.Z = int.Parse(c.CustomAttributes["z-index"]);
                    }

                    if (c.ContainsAttribute("trigger-orientation"))
                    {
                        trigger.Orientation = (TriggerOrientation)Enum.Parse(typeof(TriggerOrientation),
                                                                             c.CustomAttributes["trigger-orientation"], true);
                    }

                    if (c.ContainsAttribute("trigger-type"))
                    {
                        trigger.Type = (TriggerType)Enum.Parse(typeof(TriggerType),
                                                               c.CustomAttributes["trigger-type"], true);
                    }

                    if (c.ContainsAttribute("trigger-range"))
                    {
                        trigger.Range = Range.Parse(c.CustomAttributes["trigger-range"]);
                    }

                    if (c.ContainsAttribute("trigger-reverse"))
                    {
                        trigger.Reverse = IniFile.IniSection.TrueValues.Contains(c.CustomAttributes["trigger-reverse"].ToLowerInvariant());
                    }

                    if (c.ContainsAttribute("trigger-inverse"))
                    {
                        trigger.Inverse = IniFile.IniSection.TrueValues.Contains(c.CustomAttributes["trigger-inverse"].ToLowerInvariant());
                    }

                    Triggers.Add(trigger);
                }

                else if (c.ElementName == "remap")
                {
                    EmbeddedRemaps.Add(ColorRemap.LoadFrom(c));
                }
                RecursiveGetElements(c);
            }
        }