Example #1
0
    private void OnGUI()
    {
        GUIStyle buttonStyle = new GUIStyle(GUI.skin.button);

        buttonStyle.onHover.textColor = Color.green;


        GUILayoutOption[] buttonLayoutOptions = new GUILayoutOption[]
        {
            GUILayout.MinWidth(150),
            GUILayout.MaxWidth(150),
        };


        GUILayout.Height(100);


        HexTypeEnum prevHexType = hexType;

        GUILayout.Label("Select the type of hex and attibute you wish to add to the level.", EditorStyles.boldLabel);
        GUILayout.Space(20);

        hexType = (HexTypeEnum)EditorGUILayout.EnumPopup("Type of Hex", hexType);

        location = EditorGUILayout.Vector2Field("Hex Location", location);

        #region attribute
        GUILayout.BeginHorizontal();
        GUILayout.Label("Attribute");
        choiceIndex = EditorGUILayout.Popup(choiceIndex, attributeChoices);
        GUILayout.EndHorizontal();
        GUILayout.Space(40);
        #endregion

        switch (attributeChoices[choiceIndex])
        {
        case "None":
            break;

        case "DigitElementAttribute":
            if (attribute == null || attribute.GetType() != typeof(DigitElementAttribute))
            {
                attribute = new DigitElementAttribute(0);
            }
            ShowLayout_DigitAttribute();
            break;

        case "MenuButtonElementAttribute":
            if (attribute == null || attribute.GetType() != typeof(MenuButtonElementAttribute))
            {
                attribute = new MenuButtonElementAttribute(Command.NextMenu);
            }
            ShowLayout_MenuButtonAttribute();
            break;

        default:
            break;
        }

        GUILayout.FlexibleSpace();
        GUILayout.BeginHorizontal();
        if (GUILayout.Button("CloseWindow", buttonStyle, buttonLayoutOptions))
        {
            this.Close();
        }
        GUILayout.Space(this.position.width - 310);
        if (GUILayout.Button("Add Hex", buttonStyle, buttonLayoutOptions))
        {
            AddHexToLevel();
        }
        GUILayout.EndHorizontal();

        GUILayout.Space(40);


        UpdateAttributeChoices();


        // Refreshes the popup window in order to update options
        if (EditorApplication.isPlaying)
        {
            if (prevHexType != hexType)
            {
                UpdateAttributeChoices();
                Repaint();
            }
        }
    }
        /// <summary> Write a Element XML Element from attributes in a member. </summary>
        public virtual void WriteElement(System.Xml.XmlWriter writer, System.Reflection.MemberInfo member, ElementAttribute attribute, BaseAttribute parentAttribute, System.Type mappedClass)
        {
            writer.WriteStartElement( "element" );
            // Attribute: <column>
            if(attribute.Column != null)
            writer.WriteAttributeString("column", GetAttributeValue(attribute.Column, mappedClass));
            // Attribute: <node>
            if(attribute.Node != null)
            writer.WriteAttributeString("node", GetAttributeValue(attribute.Node, mappedClass));
            // Attribute: <formula>
            if(attribute.Formula != null)
            writer.WriteAttributeString("formula", GetAttributeValue(attribute.Formula, mappedClass));
            // Attribute: <type>
            if(attribute.Type != null)
            writer.WriteAttributeString("type", GetAttributeValue(attribute.Type, mappedClass));
            // Attribute: <length>
            if(attribute.Length != -1)
            writer.WriteAttributeString("length", attribute.Length.ToString());
            // Attribute: <precision>
            if(attribute.Precision != -1)
            writer.WriteAttributeString("precision", attribute.Precision.ToString());
            // Attribute: <scale>
            if(attribute.Scale != -1)
            writer.WriteAttributeString("scale", attribute.Scale.ToString());
            // Attribute: <not-null>
            if( attribute.NotNullSpecified )
            writer.WriteAttributeString("not-null", attribute.NotNull ? "true" : "false");
            // Attribute: <unique>
            if( attribute.UniqueSpecified )
            writer.WriteAttributeString("unique", attribute.Unique ? "true" : "false");

            WriteUserDefinedContent(writer, member, null, attribute);

            System.Collections.ArrayList memberAttribs = GetSortedAttributes(member);
            int attribPos; // Find the position of the ElementAttribute (its <sub-element>s must be after it)
            for(attribPos=0; attribPos<memberAttribs.Count; attribPos++)
                if( memberAttribs[attribPos] is ElementAttribute
                    && ((BaseAttribute)memberAttribs[attribPos]).Position == attribute.Position )
                    break; // found
            int i = attribPos + 1;

            // Element: <column>
            for(; i<memberAttribs.Count; i++)
            {
                BaseAttribute memberAttrib = memberAttribs[i] as BaseAttribute;
                if( IsNextElement(memberAttrib, parentAttribute, attribute.GetType())
                    || IsNextElement(memberAttrib, attribute, typeof(ColumnAttribute)) )
                    break; // next attributes are 'elements' of the same level OR for 'sub-elements'
                else
                {
                    if( memberAttrib is ElementAttribute )
                        break; // Following attributes are for this Element
                    if( memberAttrib is ColumnAttribute )
                        WriteColumn(writer, member, memberAttrib as ColumnAttribute, attribute, mappedClass);
                }
            }
            WriteUserDefinedContent(writer, member, typeof(ColumnAttribute), attribute);
            // Element: <formula>
            for(; i<memberAttribs.Count; i++)
            {
                BaseAttribute memberAttrib = memberAttribs[i] as BaseAttribute;
                if( IsNextElement(memberAttrib, parentAttribute, attribute.GetType())
                    || IsNextElement(memberAttrib, attribute, typeof(FormulaAttribute)) )
                    break; // next attributes are 'elements' of the same level OR for 'sub-elements'
                else
                {
                    if( memberAttrib is ElementAttribute )
                        break; // Following attributes are for this Element
                    if( memberAttrib is FormulaAttribute )
                        WriteFormula(writer, member, memberAttrib as FormulaAttribute, attribute, mappedClass);
                }
            }
            WriteUserDefinedContent(writer, member, typeof(FormulaAttribute), attribute);
            // Element: <type>
            for(; i<memberAttribs.Count; i++)
            {
                BaseAttribute memberAttrib = memberAttribs[i] as BaseAttribute;
                if( IsNextElement(memberAttrib, parentAttribute, attribute.GetType())
                    || IsNextElement(memberAttrib, attribute, typeof(TypeAttribute)) )
                    break; // next attributes are 'elements' of the same level OR for 'sub-elements'
                else
                {
                    if( memberAttrib is ElementAttribute )
                        break; // Following attributes are for this Element
                    if( memberAttrib is TypeAttribute )
                        WriteType(writer, member, memberAttrib as TypeAttribute, attribute, mappedClass);
                }
            }
            WriteUserDefinedContent(writer, member, typeof(TypeAttribute), attribute);

            writer.WriteEndElement();
        }
Example #3
0
    void DisplayHexAttributeOptions()
    {
        GUIStyle buttonStyle = new GUIStyle(GUI.skin.button);

        buttonStyle.onHover.textColor = Color.green;


        GUILayoutOption[] buttonLayoutOptions = new GUILayoutOption[]
        {
            GUILayout.MinWidth(150),
            GUILayout.MaxWidth(150),
        };


        GUILayout.Height(100);


        HexTypeEnum prevHexType = hexType;

        GUILayout.Label("Select the type of hex and attibute you wish to add to the level.", EditorStyles.boldLabel);
        GUILayout.Space(20);

        hexType = (HexTypeEnum)EditorGUILayout.EnumPopup("Type of Hex", hexType);

        //location = EditorGUILayout.Vector2Field("Hex Location", location);
        EditorGUILayout.Vector2Field("Hex Location", gridLoc);

        #region attribute
        GUILayout.BeginHorizontal();
        GUILayout.Label("Attribute");
        choiceIndex = EditorGUILayout.Popup(choiceIndex, attributeChoices);
        GUILayout.EndHorizontal();
        GUILayout.Space(40);
        #endregion


        switch (attributeChoices[choiceIndex])
        {
        case "None":
            break;

        case "DigitElementAttribute":
            if (attribute == null || attribute.GetType() != typeof(DigitElementAttribute))
            {
                attribute = new DigitElementAttribute(0);
            }
            ShowLayout_DigitAttribute();
            break;

        case "MenuButtonElementAttribute":
            if (attribute == null || attribute.GetType() != typeof(MenuButtonElementAttribute))
            {
                attribute = new MenuButtonElementAttribute(Command.NextMenu);
            }
            ShowLayout_MenuButtonAttribute();
            break;

        default:
            break;
        }

        GUILayout.FlexibleSpace();
        GUILayout.BeginHorizontal();
        if (GUILayout.Button("Save Level", buttonStyle, buttonLayoutOptions))
        {
            SaveLevel();
        }
        if (GUILayout.Button("Load Level", buttonStyle, buttonLayoutOptions))
        {
            LoadLevel();
        }
        if (GUILayout.Button("New Level", buttonStyle, buttonLayoutOptions))
        {
            NewLevel();
        }

        //GUILayout.Space(this.position.width - 310);


        GUILayout.EndHorizontal();

        GUILayout.Space(40);


        UpdateAttributeChoices();
        if (prevHexType != hexType)
        {
            UpdateHexCursorObject();
        }
        Repaint();
    }