public void OnGUI()
    {
        using (new EditorGUILayout.VerticalScope("box"))
        {
            tab = GUILayout.Toolbar(tab, new string[] { "GIT", "ARE", "IFO" });

            switch (tab)
            {
            case 0:
                curData = AuroraEngine.Resources.data.module.git;
                break;

            case 1:
                curData = AuroraEngine.Resources.data.module.are;
                break;

            case 2:
                curData = AuroraEngine.Resources.data.module.ifo;
                break;
            }

            if (curData != null)
            {
                using (var scroll = new EditorGUILayout.ScrollViewScope(scrollPos))
                {
                    scrollPos = scroll.scrollPosition;
                    GFFEditor.DrawStruct(curData);
                }
            }
        }
    }
示例#2
0
    public static void DrawListItem(IList list, AuroraStruct obj, int idx)
    {
        using (new EditorGUILayout.HorizontalScope("box"))
        {
            // Buttons
            using (new EditorGUILayout.VerticalScope("box"))
            {
                EditorGUILayout.LabelField(idx.ToString(), GUILayout.Width(20));

                if (GUILayout.Button("-", GUILayout.Width(30)))
                {
                    list.RemoveAt(idx);
                    return;
                }

                if (GUILayout.Button("↑", GUILayout.Width(30)))
                {
                    // Move item up
                    return;
                }

                if (GUILayout.Button("↓", GUILayout.Width(30)))
                {
                    // Move item down
                    return;
                }
            }

            // List item
            using (new EditorGUILayout.VerticalScope("box"))
            {
                CreateInspector(null, obj, "");
            }
        }
    }
示例#3
0
    public static void DrawExoLoc(FieldInfo f, AuroraStruct owner)
    {
        GFFObject.CExoLocString cur = (GFFObject.CExoLocString)f.GetValue(owner);

        if (cur == null)
        {
            cur = new GFFObject.CExoLocString();
            f.SetValue(owner, cur);
        }

        using (new EditorGUILayout.VerticalScope())
        {
            // Show the resref

            string newRef = Draw(f.Name + " (resref)", cur.stringref.ToString());
            cur.stringref = uint.Parse(newRef);

            if (cur.strings == null)
            {
                return;
            }

            if (GUILayout.Button("Add String"))
            {
                cur.strings.Add(new GFFObject.CExoLocString.SubString());
            }

            // Show the list of strings
            for (int i = 0; i < cur.strings.Count; i++)
            {
                GFFObject.CExoLocString.SubString sub = cur.strings[i];

                using (new EditorGUILayout.VerticalScope("box"))
                {
                    try
                    {
                        if (GUILayout.Button("Delete"))
                        {
                            cur.strings.RemoveAt(i);
                            continue;
                        }
                        EditorGUILayout.LabelField("String " + i);
                        string newID    = Draw("ID" + i, sub.strid.ToString());
                        string newValue = Draw("String", sub.str);

                        int idVal = int.Parse(newID);
                        GFFObject.CExoLocString.SubString newSub = new GFFObject.CExoLocString.SubString();
                        newSub.strid = idVal;
                        newSub.str   = newValue;

                        cur.strings[i] = newSub;
                    }
                    catch { }
                }
            }
        }
    }
示例#4
0
    public static void DrawList(FieldInfo listField, AuroraStruct owner)
    {
        // Assumption: All lists used here are of type List<AuroraStruct>
        // (This is how the GFF structure is defined so it should work fine here,
        // but for other situations it might cause issus)

        Type   listType = listField.FieldType.GetGenericArguments()[0];
        object listObj  = listField.GetValue(owner);

        if (listObj == null)
        {
            Type genericType = typeof(List <>).MakeGenericType(new Type[] { listType });
            listObj = Activator.CreateInstance(genericType);

            listField.SetValue(owner, listObj);
        }

        if (!isOpen.ContainsKey(listObj))
        {
            isOpen[listObj] = false;
        }

        IList list = (IList)listObj;

        using (new EditorGUILayout.VerticalScope("box"))
        {
            using (new EditorGUILayout.HorizontalScope())
            {
                EditorGUILayout.LabelField("List " + listField.Name);

                if (GUILayout.Button("Toggle"))
                {
                    // Toggle whether list is open
                    isOpen[listObj] = !isOpen[listObj];
                }

                if (GUILayout.Button("+"))
                {
                    // Add to list
                    object newValue = Activator.CreateInstance(listType);
                    list.Add(newValue);
                }
            }

            if (!isOpen[listObj])
            {
                return;
            }

            int i = 0;
            foreach (AuroraStruct val in list)
            {
                DrawListItem(list, val, i);
                i++;
            }
        }
    }
示例#5
0
    public static void DrawField(FieldInfo field, AuroraStruct owner)
    {
        object value = field.GetValue(owner);
        string str   = "";

        if (value != null)
        {
            str = value.ToString();
        }

        if (field.FieldType == typeof(GFFObject.CExoLocString))
        {
            // We deal with CExoLocString separately
            DrawExoLoc(field, owner);
            return;
        }

        string newValue = Draw(field.Name, str);

        // Check if str has changed
        if (newValue == str)
        {
            return;
        }

        if (field.FieldType == typeof(string))
        {
            field.SetValue(owner, newValue);
            return;
        }

        // Update the value of the field to the new given value
        MethodInfo parser = field.FieldType.GetMethod("Parse", new Type[] { typeof(string) });

        if (parser == null)
        {
            Debug.LogWarning("Could not find parser for type " + field.FieldType);
            return;
        }

        object newObj = parser.Invoke(null, new object[] { newValue });

        field.SetValue(owner, newObj);
    }
示例#6
0
    public static void DrawStruct(AuroraStruct owner)
    {
        // This is an AuroraStruct object
        foreach (FieldInfo f in owner.GetType().GetFields())
        {
            if (f.FieldType.IsSubclassOf(typeof(AuroraStruct)))
            {
                CreateInspector(null, (AuroraStruct)f.GetValue(owner), f.Name);
                continue;
            }

            if (f.FieldType.IsGenericType && f.FieldType.GetGenericTypeDefinition() == typeof(List <>))
            {
                DrawList(f, owner);
                continue;
            }

            DrawField(f, owner);
        }
    }
示例#7
0
    public static void CreateInspector(AuroraObject obj, AuroraStruct owner, string name)
    {
        if (owner == null)
        {
            //Debug.LogWarning("Owner for " + name + " was null");
            return;
        }
        using (new EditorGUILayout.VerticalScope("box"))
        {
            if (name != "")
            {
                EditorGUILayout.LabelField(name);
            }

            // Draw some debug information for this object
            if (obj != null)
            {
                EditorGUILayout.TextField("Actions:");
                int i = 0;
                foreach (AuroraAction action in obj.actions)
                {
                    EditorGUILayout.LabelField(i + ": " + action);
                    i++;
                }
                EditorGUILayout.Space();

                EditorGUILayout.TextField("Effects: ");
                i = 0;
                foreach (AuroraEffect effect in obj.effects)
                {
                    EditorGUILayout.LabelField(i + ": " + effect);
                    i++;
                }

                EditorGUILayout.Space();
            }

            DrawStruct(owner);
        }
    }
示例#8
0
    public AuroraStruct DeepCopy()
    {
        Type         myType = GetType();
        AuroraStruct copy   = (AuroraStruct)Activator.CreateInstance(myType);

        foreach (FieldInfo f in myType.GetFields())
        {
            if (f.FieldType.IsSubclassOf(typeof(AuroraStruct)))
            {
                AuroraStruct fCopy = ((AuroraStruct)f.GetValue(this)).DeepCopy();
                f.SetValue(copy, fCopy);
            }
            else if (f.FieldType == typeof(Vector3))
            {
                Vector3 v     = (Vector3)f.GetValue(this);
                Vector3 vCopy = new Vector3(v.x, v.y, v.z);
                f.SetValue(copy, vCopy);
            }
            else if (f.FieldType == typeof(Quaternion))
            {
                Quaternion q     = (Quaternion)f.GetValue(this);
                Quaternion qCopy = new Quaternion(q.x, q.y, q.z, q.w);
                f.SetValue(copy, qCopy);
            }
            else if (f.GetValue(this) == null)
            {
                f.SetValue(copy, null);
            }
            else
            {
                // Use the DeepClone method
                object fClone = DeepClone(f.GetValue(this));
                f.SetValue(copy, fClone);
            }
        }

        return(copy);
    }
示例#9
0
 void SelectedReply(AuroraDLG.AReply reply)
 {
     // The user selected a reply, so show all relevant entries
     curEditing = reply;
 }
示例#10
0
 void SelectedEntry(AuroraDLG.AEntry entry)
 {
     // The user selected an entry, so show all relevant replies
     curEditing = entry;
 }
示例#11
0
 void SelectedStart(AuroraDLG.AStarting start)
 {
     curEditingLink = start;
     curEditing     = GetEntry((int)start.Index);
 }
示例#12
0
 public void Initialize(AuroraStruct gitData)
 {
     this.gitData = gitData;
 }
示例#13
0
    public string ToXML(string gffType, bool isRecursive = false, string structLabel = "")
    {
        // Writes this object in GFF format

        // Convert the object to XML
        string xml         = !isRecursive ? "<gff3 type=\"" + gffType + "\">" : "";
        bool   hasStructID = false;
        uint   structid    = 0;

        List <string> values = new List <string>();

        foreach (FieldInfo f in GetType().GetFields())
        {
            GFFAttribute attr = f.GetCustomAttribute <GFFAttribute>();

            string        label    = attr.name;
            Compatibility compat   = attr.compatibility;
            ExistsIn      existsIn = attr.existsIn;

            //Debug.Log("Compat: " + compat + "; exists: " + existsIn);

            // Make sure we only write fields compatible with the target game
            if (compat == Compatibility.KotOR && AuroraPrefs.TargetGame() == Game.TSL)
            {
                continue;
            }
            if (compat == Compatibility.TSL && AuroraPrefs.TargetGame() == Game.KotOR)
            {
                continue;
            }

            // Don't write save-only fields when writing modules
            // TODO: Allow an override for this in case mods need it?
            if (existsIn == ExistsIn.SAVE)
            {
                continue;
            }

            object value = f.GetValue(this);
            if (value == null)
            {
                continue;
            }

            if (label == "structid")
            {
                // The struct ID should be dealt with separately
                structid    = (uint)f.GetValue(this);
                hasStructID = true;
                continue;
            }

            if (f.FieldType.IsSubclassOf(typeof(AuroraStruct)))
            {
                AuroraStruct structVal = (AuroraStruct)value;
                // This is a nested AuroraStruct
                values.Add(structVal.ToXML(gffType, true, label));
            }
            else if (f.FieldType.IsGenericType && (f.FieldType.GetGenericTypeDefinition() == typeof(List <>)))
            {
                // This is a list
                string listXML = "<list label=\"" + label + "\"";
                IList  list    = (IList)value;

                if (list == null)
                {
                    continue;
                }

                if (list.Count == 0)
                {
                    listXML += "/>";
                }
                else
                {
                    listXML += ">";

                    foreach (AuroraStruct item in list)
                    {
                        listXML += item.ToXML(gffType, true);
                    }

                    listXML += "</list>";
                }

                values.Add(listXML);
            }
            else if (f.FieldType == typeof(GFFObject.CExoLocString))
            {
                values.Add(((GFFObject.CExoLocString)value).ToXML(f.Name));
            }
            else if (f.FieldType == typeof(GFFObject.CExoString))
            {
                values.Add(((GFFObject.CExoString)value).ToXML(f.Name));
            }
            else if (f.FieldType == typeof(Quaternion))
            {
                Quaternion q       = (Quaternion)value;
                string     quatXML = "<orientation label=\"" + f.Name + "\">";

                quatXML += "<double>" + q.x + "</double>";
                quatXML += "<double>" + q.y + "</double>";
                quatXML += "<double>" + q.z + "</double>";
                quatXML += "<double>" + q.w + "</double>";

                quatXML += "</orientation>";
                values.Add(quatXML);
            }
            else if (f.FieldType == typeof(Vector3))
            {
                Vector3 v      = (Vector3)value;
                string  vecXML = "<vector label=\"" + f.Name + "\">";

                vecXML += "<double>" + v.x + "</double>";
                vecXML += "<double>" + v.y + "</double>";
                vecXML += "<double>" + v.z + "</double>";

                vecXML += "</vector>";
                values.Add(vecXML);
            }
            else if (f.FieldType == typeof(Byte[]))
            {
                // Source: https://stackoverflow.com/questions/311165/how-do-you-convert-a-byte-array-to-a-hexadecimal-string-and-vice-versa
                string b64 = Convert.ToBase64String((byte[])value, Base64FormattingOptions.InsertLineBreaks);

                values.Add("<data label=\"" + label + "\">" + b64 + "</data>");
            }
            else if (f.FieldType == typeof(Byte))
            {
                byte   b       = (byte)f.GetValue(this);
                string byteXML = "<" + TypeNames[f.FieldType];

                if (label != null)
                {
                    byteXML += " label=\"" + label + "\"";
                }
                byteXML += ">" + b.ToString() + "</" + TypeNames[f.FieldType] + ">";

                values.Add(byteXML);
            }
            else if (f.FieldType == typeof(Char))
            {
                char   c       = (char)f.GetValue(this);
                string charXML = "<" + TypeNames[f.FieldType];

                if (label != null)
                {
                    charXML += " label=\"" + label + "\"";
                }

                if ((int)c == 0)
                {
                    charXML += "/>";
                }
                else
                {
                    charXML += ">" + c.ToString() + "</" + TypeNames[f.FieldType] + ">";
                }

                values.Add(charXML);
            }
            else
            {
                if (!TypeNames.ContainsKey(f.FieldType))
                {
                    Debug.Log("Could not find field type" + f.FieldType);
                }

                string valXML = "<" + TypeNames[f.FieldType];

                if (label != null)
                {
                    valXML += " label=\"" + label + "\"";
                }

                valXML += ">" + value.ToString() + "</" + TypeNames[f.FieldType] + ">";

                values.Add(valXML);
            }
        }

        string structLabelXML = "";

        if (structLabel != null && structLabel != "")
        {
            structLabelXML = " label=\"" + structLabel + "\"";
        }

        if (!isRecursive)
        {
            xml += "<struct id=\"4294967295\"" + structLabelXML + ">";
        }
        else if (hasStructID)
        {
            xml += "<struct id=\"" + structid + "\"" + structLabelXML + ">";
        }
        else
        {
            xml += "<struct id = \"0\"" + structLabelXML + ">";
        }

        foreach (string s in values)
        {
            xml += s;
        }

        xml += "</struct>";

        if (!isRecursive)
        {
            xml += "</gff3>";
        }

        return(xml);
    }