Пример #1
0
        public AnchorBasedActionView(LabelDescr lbl, string title = null)
        {
            if (lbl.Label == null && lbl.PreLabelIcon == null)
            {
                throw new Exception("cannot have labelless and icon less in the same time");
            }

            _a = new HTMLAnchorElement {
                Href      = "#",
                ClassName = GetType().FullNameWithoutGenerics(),
                Title     = title ?? ""
            };

            var preLabel = Document.CreateElement("div");

            _a.AppendChild(preLabel);

            if (lbl.PreLabelIcon != null)
            {
                preLabel.AddClasses(lbl.PreLabelIcon.Item1.ToCssClassName());
                preLabel.TextContent = lbl.PreLabelIcon.Item2;
            }

            var label = Document.CreateElement("div");

            _a.AppendChild(label);

            label.TextContent = lbl.Label ?? "";

            Enabled = true; //initialize css class

            _a.OnClick += ev => {
                Logger.Debug(GetType(), "handling onclick");

                if (OnClickPreventsDefault)
                {
                    ev.PreventDefault();
                }

                if (ev.HasHtmlTarget() && !ShouldTriggerOnTarget(ev.HtmlTarget()))
                {
                    return;
                }

                if (!Enabled || State.Type == ActionViewStateType.OperationRunning)
                {
                    return;
                }

                Triggered?.Invoke();
            };
        }
Пример #2
0
        public void NormalizeRemovesEmptyTextNodesNested()
        {
            var div = new HTMLDivElement();
            var a   = new HTMLAnchorElement();

            a.AppendChild(new TextNode());
            a.AppendChild(new TextNode("Not empty."));
            div.AppendChild(a);
            div.AppendChild(new TextNode());
            div.AppendChild(new HTMLDivElement());
            div.AppendChild(new TextNode("Certainly not empty!"));
            div.AppendChild(new HTMLImageElement());
            div.Normalize();
            Assert.AreEqual(a.ChildNodes.Length, 1);
        }
Пример #3
0
        public void NormalizeMergeTextNodes()
        {
            var div = new HTMLDivElement();
            var a   = new HTMLAnchorElement();

            a.AppendChild(new TextNode());
            a.AppendChild(new TextNode("Not empty."));
            div.AppendChild(a);
            div.AppendChild(new TextNode());
            div.AppendChild(new HTMLDivElement());
            div.AppendChild(new TextNode("Certainly not empty!"));
            div.AppendChild(new TextNode("Certainly not empty!"));
            div.AppendChild(new TextNode("Certainly not empty!"));
            div.AppendChild(new TextNode("Certainly not empty!"));
            div.AppendChild(new HTMLImageElement());
            div.Normalize();
            Assert.AreEqual(div.ChildNodes.Length, 4);
        }
Пример #4
0
        private HTMLAnchorElement GetAnchorElement(HTMLDocument htmlDocument, string buttonText)
        {
            HTMLAnchorElement anchorElement = (HTMLAnchorElement)htmlDocument.CreateElement("a");

            Text backwardText = htmlDocument.CreateTextNode(buttonText);

            anchorElement.SetAttribute("class", "button");
            anchorElement.AppendChild(backwardText);
            return(anchorElement);
        }
Пример #5
0
        public static async Task <LevelEditorReference> CreateReference(GameObject gameObject, HTMLTableElement table, int indent = 0)
        {
            if (gameObject.Name == null)
            {
                return(null);
            }
            HTMLTableRowElement row = new HTMLTableRowElement();

            row.Indent(indent);
            var cell = new HTMLTableDataCellElement();

            cell.Style.BorderBottom = "1px solid black";
            cell.AppendChild(new HTMLAnchorElement
            {
                InnerHTML = gameObject.Name,
                Href      = "javascript:void(0)",
                OnClick   = v => Select(gameObject)
            });
            cell.AppendChild(new Text(" "));
            var cross = new HTMLAnchorElement
            {
                OnClick = v => Remove(gameObject),
                Href    = "javascript:void(0)"
            };

            cross.AppendChild(LevelEditor.cross = LevelEditor.cross.CloneNode().As <HTMLImageElement>());
            cell.AppendChild(cross);
            row.AppendChild(cell);
            table.AppendChild(row);
            LevelEditorReference result = new LevelEditorReference
            {
                gameObject = gameObject,
                cells      = new Dictionary <string, HTMLElement>(),
                members    = new Dictionary <string, MemberInfo>()
            };
            string type;

            if (gameObject is Character)
            {
                type = "Character";
            }
            else if (gameObject is Shot)
            {
                type = "Shot";
            }
            else if (gameObject is RealGameObject)
            {
                type = "Real Thing";
            }
            else if (gameObject is DrawnGameObject)
            {
                type = "Illusion";
            }
            else if (gameObject is Movement)
            {
                type = "Movement by User";
            }
            else if (gameObject is Shoot_OnKey)
            {
                type = "Shooting by User";
            }
            else if (gameObject is Level)
            {
                type = "Level";
            }
            else
            {
                throw new Exception($"Type not allowed: {gameObject.GetType().FullName}");
            }
            row = new HTMLTableRowElement();
            row.Indent(indent);
            cell = new HTMLTableDataCellElement
            {
                InnerHTML = "Type"
            };
            HTMLTableDataCellElement cell2 = new HTMLTableDataCellElement
            {
                InnerHTML = type
            };

            result.cells.Add("Type", cell2);
            row.AppendChild(cell);
            row.AppendChild(cell2);
            table.AppendChild(row);
            List <MemberInfo> fields = new List <MemberInfo>(gameObject.GetType().GetFields());

            fields.AddRange(gameObject.GetType().GetProperties());
            foreach (var field in fields)
            {
                if (field.IsStatic)
                {
                    continue;
                }
                Type memberType;
                if (field is FieldInfo)
                {
                    memberType = ((FieldInfo)field).FieldType;
                }
                else if (field is PropertyInfo)
                {
                    memberType = ((PropertyInfo)field).PropertyType;
                }
                else
                {
                    throw new Exception();
                }
                var        customAttributes2 = (ObjectCreatorAttribute[])field.GetCustomAttributes(typeof(ObjectCreatorAttribute));
                string     s;
                GameObject o;
                if (allowed.Contains(memberType) || customAttributes2.Length == 1)
                {
                    object value;
                    if (field is FieldInfo)
                    {
                        value = ((FieldInfo)field).GetValue(gameObject);
                    }
                    else if (field is PropertyInfo)
                    {
                        value = ((PropertyInfo)field).GetValue(gameObject);
                    }
                    else
                    {
                        throw new Exception();
                    }
                    if (value == null)
                    {
                        continue;
                    }
                    if (customAttributes2.Length == 1)
                    {
                        value = await GameObject.Create(value);
                    }
                    row = new HTMLTableRowElement();
                    row.Indent(indent);
                    var    contentEditable = ContentEditable.True;
                    string valueString;
                    s = value as string;
                    if (s != null)
                    {
                        valueString = s;
                    }
                    else if (value is double)
                    {
                        valueString = ((double)value).ToString();
                    }
                    else
                    {
                        contentEditable = ContentEditable.False;
                        if (value is List <GameObject> )
                        {
                            valueString = "List of Objects";
                        }
                        else if (value is List <OnKeyEvent> )
                        {
                            valueString = "List of Key Press Actions";
                        }
                        else if (value is GameObject)
                        {
                            valueString = "Object";
                        }
                        else
                        {
                            throw new Exception();
                        }
                    }
                    string name             = field.Name;
                    var    customAttributes = (LevelEditorNameAttribute[])field.GetCustomAttributes(typeof(LevelEditorNameAttribute));
                    if (customAttributes.Length == 1)
                    {
                        name = customAttributes[0].LevelEditorName;
                    }
                    cell = new HTMLTableDataCellElement
                    {
                        InnerHTML = name
                    };
                    cell2 = new HTMLTableDataCellElement
                    {
                        ContentEditable = contentEditable,
                        InnerHTML       = valueString
                    };
                    result.cells.Add(field.Name, cell2);
                    result.members.Add(field.Name, field);
                    row.AppendChild(cell);
                    row.AppendChild(cell2);
                    table.AppendChild(row);
                    if (value is List <GameObject> || value is List <OnKeyEvent> )
                    {
                        foreach (GameObject _gameObject in (System.Collections.IList)(value as List <GameObject>) ?? (System.Collections.IList)(value as List <OnKeyEvent>))
                        {
                            await CreateReference(_gameObject, table, indent + 1);
                        }
                    }
                    o = value as GameObject;
                    if (o != null)
                    {
                        await CreateReference(o, table, indent + 1);
                    }
                }
            }
            row = new HTMLTableRowElement();
            row.Indent(indent);
            cell = new HTMLTableDataCellElement();
            cell.AppendChild(new HTMLButtonElement
            {
                InnerHTML = "Save Changes",
                OnClick   = e => SaveChanges(result)
            });
            row.AppendChild(cell);
            table.AppendChild(row);
            return(result);
        }