private void DrawExport()
        {
            db = EditorGUILayout.ObjectField("Faction Database", db, typeof(FactionDatabase), true) as FactionDatabase;
            EditorGUILayout.BeginHorizontal();
            prefs.folder = EditorGUILayout.TextField("Export To", prefs.folder);
            if (GUILayout.Button("...", EditorStyles.miniButtonRight, GUILayout.Width(22)))
            {
                prefs.folder = EditorUtility.OpenFolderPanel("Destination for CSV files", prefs.folder, "");
                GUIUtility.keyboardControl = 0;
            }
            EditorGUILayout.EndHorizontal();
            prefs.encoding = (EncodingType)EditorGUILayout.EnumPopup("Encoding", prefs.encoding);

            var isFolderValid = !string.IsNullOrEmpty(prefs.folder) && Directory.Exists(prefs.folder);

            if (isFolderValid)
            {
                EditorGUILayout.HelpBox("Destination CSV files:\n" +
                                        prefs.folder + "/PersonalityTraits.csv\n" +
                                        prefs.folder + "/RelationshipTraits.csv\n" +
                                        prefs.folder + "/Factions.csv\n" +
                                        prefs.folder + "/Relationships_*.csv", MessageType.None);
            }
            else
            {
                EditorGUILayout.HelpBox("Specify a folder to export the CSV files.", MessageType.Info);
            }
            EditorGUI.BeginDisabledGroup(db == null || !isFolderValid);
            if (GUILayout.Button("Export"))
            {
                Export();
            }
            EditorGUI.EndDisabledGroup();
        }
 private void OnEnable()
 {
     //m_deedOverrides = target as DeedEvaluationOverrides;
     m_factionDatabase = (target as MonoBehaviour).GetComponent <FactionMember>().factionDatabase;
     SetupDeedOverridesList();
     UpdateFactionList();
 }
 private void ResetSettings()
 {
     if (EditorUtility.DisplayDialog("Reset Settings", "Reset the Love/Hate CSV export/import window settings?", "OK", "Cancel"))
     {
         prefs = new Prefs();
         db    = null;
     }
 }
Ejemplo n.º 4
0
        private static List <InheritedRelationship> GetInheritedRelationships(FactionDatabase database, int factionID, List <int> visited)
        {
            var list       = new List <InheritedRelationship>();
            var subjectIDs = new List <int>();

            AddInheritedRelationships(database, factionID, new List <int>(), list, subjectIDs);
            AddAveragedRelationships(database, factionID, list, subjectIDs);
            list.Sort();
            return(list);
        }
 private void OnEnable()
 {
     prefs = EditorPrefs.HasKey(EditorPrefsKey) ? JsonUtility.FromJson <Prefs>(EditorPrefs.GetString(EditorPrefsKey)) : null;
     if (prefs == null)
     {
         prefs = new Prefs();
     }
     if (prefs.dbInstanceID != 0)
     {
         db = EditorUtility.InstanceIDToObject(prefs.dbInstanceID) as FactionDatabase;
     }
 }
Ejemplo n.º 6
0
 private static void AddAveragedRelationships(FactionDatabase database, int factionID, List <InheritedRelationship> list, List <int> subjectIDs)
 {
     if (database == null || list == null || subjectIDs == null)
     {
         return;
     }
     for (int i = 0; i < subjectIDs.Count; i++)
     {
         var subject = database.GetFaction(subjectIDs[i]);
         if (subject != null)
         {
             var affinity = database.GetAffinity(factionID, subject.id);
             list.Add(new InheritedRelationship(subject.name + " [inherited]", affinity));
         }
     }
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Finds a faction database if it's unassigned, first looking on a
 /// FactionManager and failing that the first FactionDatabase it finds.
 /// </summary>
 public void FindResources()
 {
     if (factionDatabase == null)
     {
         var factionManager = FindObjectOfType <FactionManager>();
         if (factionManager != null && factionManager.factionDatabase != null)
         {
             factionDatabase = factionManager.factionDatabase;
         }
         else
         {
             var databases = Resources.FindObjectsOfTypeAll <FactionDatabase>();
             if (databases.Length > 0)
             {
                 factionDatabase = databases[0];
             }
         }
     }
 }
Ejemplo n.º 8
0
 private void Initialize()
 {
     if (factionDatabase == null)
     {
         return;
     }
     factionDatabase = Instantiate(factionDatabase) as FactionDatabase;
     m_factions.Clear();
     for (int f = 0; f < factionDatabase.factions.Length; f++)
     {
         var faction = factionDatabase.factions[f];
         m_factions.Add(faction.id, faction);
     }
     m_members.Clear();
     m_witnessQueue.Clear();
     if (!Debug.isDebugBuild)
     {
         debug = false;
     }
 }
Ejemplo n.º 9
0
        private static void AddInheritedRelationships(FactionDatabase database, int factionID, List <int> visited, List <InheritedRelationship> list, List <int> subjectIDs)
        {
            if (database == null || visited.Contains(factionID))
            {
                return;
            }
            visited.Add(factionID);
            var faction = database.GetFaction(factionID);

            if (faction != null)
            {
                for (int p = 0; p < faction.parents.Length; p++)
                {
                    var parentID = faction.parents[p];
                    var parent   = database.GetFaction(parentID);
                    if (parent != null)
                    {
                        for (int r = 0; r < parent.relationships.Count; r++)
                        {
                            var relationship = parent.relationships[r];
                            if (relationship.inheritable)
                            {
                                var subject = database.GetFaction(relationship.factionID);
                                if (subject != null)
                                {
                                    list.Add(new InheritedRelationship(subject.name + " (" + parent.name + ")", relationship.affinity));
                                    if (!subjectIDs.Contains(subject.id))
                                    {
                                        subjectIDs.Add(subject.id);
                                    }
                                }
                            }
                        }
                        AddInheritedRelationships(database, parentID, visited, list, subjectIDs);
                    }
                }
            }
        }
Ejemplo n.º 10
0
 public static List <InheritedRelationship> GetInheritedRelationships(FactionDatabase database, int factionID)
 {
     return(GetInheritedRelationships(database, factionID, new List <int>()));
 }
 public void SetDatabase(FactionDatabase db)
 {
     this.db = db;
 }
        private void DrawImport()
        {
            db = EditorGUILayout.ObjectField("Faction Database", db, typeof(FactionDatabase), false) as FactionDatabase;
            EditorGUILayout.BeginHorizontal();
            prefs.folder = EditorGUILayout.TextField("Import From", prefs.folder);
            if (GUILayout.Button("...", EditorStyles.miniButtonRight, GUILayout.Width(22)))
            {
                prefs.folder = EditorUtility.OpenFolderPanel("Location of CSV files", prefs.folder, "");
                GUIUtility.keyboardControl = 0;
            }
            EditorGUILayout.EndHorizontal();
            prefs.encoding = (EncodingType)EditorGUILayout.EnumPopup("Encoding", prefs.encoding);

            var isFolderValid = !string.IsNullOrEmpty(prefs.folder) && Directory.Exists(prefs.folder);

            if (isFolderValid)
            {
                EditorGUILayout.HelpBox("Attempt to import these CSV files:\n" +
                                        prefs.folder + "/PersonalityTraits.csv\n" +
                                        prefs.folder + "/RelationshipTraits.csv\n" +
                                        prefs.folder + "/Factions.csv\n" +
                                        prefs.folder + "/Relationships_*.csv", MessageType.None);
                EditorGUILayout.LabelField("Faction Spreadsheet Configuration", EditorStyles.boldLabel);
                EditorGUILayout.HelpBox("If you're importing from CSV files that were exported from this window, you can use the default import settings. " +
                                        "If you're importing from a different spreadsheet format, specify the format of the Factions spreadsheet below.", MessageType.None);
                prefs.autoID = EditorGUILayout.Toggle(new GUIContent("Auto-assign IDs", "If ticked, auto-assign IDs. Otherwise use the ID Column."), prefs.autoID);
                if (!prefs.autoID)
                {
                    prefs.idColumn = EditorGUILayout.IntField("ID (" + GetColumnAlpha(prefs.idColumn) + ")", prefs.idColumn);
                }
                prefs.nameColumn        = EditorGUILayout.IntField("Name (" + GetColumnAlpha(prefs.nameColumn) + ")", prefs.nameColumn);
                prefs.descriptionColumn = EditorGUILayout.IntField("Description (" + GetColumnAlpha(prefs.descriptionColumn) + ")", prefs.descriptionColumn);
                prefs.hasPresets        = EditorGUILayout.Toggle(new GUIContent("Includes Presets", "If ticked, spreadsheet also includes rows for presets."), prefs.hasPresets);
                if (prefs.hasPresets)
                {
                    prefs.presetColumn = EditorGUILayout.IntField("Preset (" + GetColumnAlpha(prefs.presetColumn) + ")", prefs.presetColumn);
                }
                prefs.colorColumn = EditorGUILayout.IntField("Color (" + GetColumnAlpha(prefs.colorColumn) + ")", prefs.colorColumn);
                prefs.percentJudgeParentsColumn     = EditorGUILayout.IntField("% Judge Parents (" + GetColumnAlpha(prefs.percentJudgeParentsColumn) + ")", prefs.percentJudgeParentsColumn);
                prefs.firstPersonalityTraitColumn   = EditorGUILayout.IntField("First Personality Trait (" + GetColumnAlpha(prefs.firstPersonalityTraitColumn) + ")", prefs.firstPersonalityTraitColumn);
                prefs.parentsAfterPersonalityTraits = EditorGUILayout.Toggle(new GUIContent("Parents After Personality", "Parents immediately follow personality trait values."), prefs.parentsAfterPersonalityTraits);
                if (!prefs.parentsAfterPersonalityTraits)
                {
                    prefs.firstParentsColumn = EditorGUILayout.IntField("First Parent (" + GetColumnAlpha(prefs.firstParentsColumn) + ")", prefs.firstParentsColumn);
                    prefs.lastParentsColumn  = EditorGUILayout.IntField("Last Parent (" + GetColumnAlpha(prefs.lastParentsColumn) + ")", prefs.lastParentsColumn);
                }
            }
            else
            {
                EditorGUILayout.HelpBox("Specify a folder containing the CSV files.", MessageType.Info);
            }
            EditorGUILayout.HelpBox("Importing will overwrite the contents of your faction database.", MessageType.Warning);
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Reset", GUILayout.Width(64)))
            {
                ResetSettings();
            }
            EditorGUI.BeginDisabledGroup(db == null || !isFolderValid);
            var importNow = GUILayout.Button("Import");

            EditorGUI.EndDisabledGroup();
            EditorGUILayout.EndHorizontal();
            if (importNow)
            {
                Import();
            }
        }