Ejemplo n.º 1
0
 void Awake()
 {
     manager = new GroupManager(caseSensitive);
     GroupManager.Group firstState = null;
     if (states != null)
     {
         foreach (string name in states)
         {
             if (!StringExt.IsNullOrWhitespace(name))
             {
                 GroupManager.Group s;
                 s = manager.Add(name);
                 if (firstState == null)
                 {
                     firstState = s;
                 }
             }
         }
     }
     if (main)
     {
         GroupManager.main = manager;
         if (firstState != null)
         {
             manager.activeGroup = firstState;
         }
     }
 }
Ejemplo n.º 2
0
    public static DialogueMap Open(DialogueManager manager, TextReader reader)
    {
        DialogueMap map = new DialogueMap(manager);

        map._instances = new Dictionary <string, DialogueInstance>();
        int    lnum = 0;
        string line;
        string currentDialogue = null;
        List <DialogueEntry> currentEntries = null;
        Author currentAuthor = null;

        while ((line = reader.ReadLine()) != null)
        {
            ++lnum;
            line = line.TrimStart();
            bool escape = false;
            if (line.StartsWith(EscapeChar))
            {
                line   = line.Substring(1);
                escape = true;
            }
            if (!escape && (line.StartsWith(CommentChar) || StringExt.IsNullOrWhitespace(line)))
            {
                continue;
            }
            else if (!escape && line.StartsWith(InstanceChar))
            {
                if (currentEntries != null)
                {
                    map._instances[currentDialogue] = new DialogueInstance(currentEntries, manager.GetComponent <UnityEngine.AudioSource>());
                }
                currentAuthor   = null;
                currentDialogue = line.Substring(1).Trim();
                currentEntries  = new List <DialogueEntry>();
            }
            else if (!escape && line.StartsWith(AuthorChar))
            {
                if (currentEntries == null)
                {
                    throw new IOException(string.Format("Invalid dialogue format at line {0}", lnum));
                }
                string author = line.Substring(1).Trim();
                currentAuthor = manager.GetAuthor(author);
            }
            else
            {
                if (currentEntries == null || currentAuthor == null)
                {
                    throw new IOException(string.Format("Invalid dialogue format at line {0}", lnum));
                }
                currentEntries.Add(new DialogueEntry(currentAuthor, line));
            }
        }
        if (currentEntries != null)
        {
            map._instances[currentDialogue] = new DialogueInstance(currentEntries, manager.GetComponent <UnityEngine.AudioSource>());
        }

        return(map);
    }
Ejemplo n.º 3
0
    void Refresh()
    {
        var files = (System.IO.File.ReadAllLines(LevelFile));

        levelData.Clear();
        foreach (var file in files)
        {
            if (!StringExt.IsNullOrWhitespace(file))
            {
                levelData.Add(new LevelEntry()
                {
                    Name = file.Trim()
                });
            }
        }
        foreach (var entry in levelData)
        {
            string dir = LevelPath + entry.Name + ".xml";
            //if (File.Exists(dir)) {
            entry.File = new FileInfo(dir);
            //}
            string dialDir = DialoguePath + entry.Name + ".txt";
            //if (entry.HasDialogue = File.Exists(dialDir)) {
            entry.Dialogue = new FileInfo(dialDir);
            //}
        }
        int pages;

        if (levelData.Count > 0)
        {
            pages = levelData.Count / LevelsPerPage + 1;
        }
        else
        {
            pages = 0;
        }

        while (pageToggles.Count < pages)
        {
            pageToggles.Add(true);
        }

        //_saveDirty = false;
        this.Repaint();
    }
Ejemplo n.º 4
0
    private LevelManager()
    {
        //_instance = this;
        Level = PlayerPrefs.GetInt("Level", 0) - 1;

        loader = new LevelLoader();

        tileMaps  = new Dictionary <int, TmxMap>();
        dialogues = new Dictionary <int, DialogueMap>();
        settings  = new LevelSettings();

        var asset = Resources.Load <TextAsset>("Levels");

        levels = new List <string>();

        using (var reader = new StringReader(asset.text)) {
            //var d = new Deserializer();
            //levels = d.Deserialize<string[]>(reader);
            string line;
            while ((line = reader.ReadLine()) != null)
            {
                if (!StringExt.IsNullOrWhitespace(line))
                {
                    levels.Add(line.Trim());
                }
            }
        }

        scores = new int[levels.Count];
        //Debug.Log("Loaded levels: " + levels.Count);
        for (int i = 0; i < scores.Length; ++i)
        {
            scores[i] = GetScore(i);
            //Debug.Log(scores[i]);
        }

        //totalStars = 0;
        //for (int i = 0; i < scores.Length; ++i) {
        //		totalStars += scores[i];
        //}
        RecalculateTotal();
    }
Ejemplo n.º 5
0
    public override void OnInspectorGUI()
    {
        var detTarget = (GroupWizard)target;
        var all       = GameObject.FindObjectsOfType <GroupWizard>();

        if (all.Length > 1)
        {
            EditorGUILayout.HelpBox("There are more than one group managers in this scene. Only one will be used.", MessageType.Warning);
            bool isMain = detTarget.main;
            if (isMain)
            {
                GUI.enabled = false;
                EditorGUILayout.ToggleLeft("This is the main group manager", true);
                GUI.enabled = true;
            }
            else
            {
                detTarget.main    = EditorGUILayout.ToggleLeft("This is the main group manager", detTarget.main);
                GroupManager.main = detTarget.manager;
            }
            if (detTarget.main)
            {
                foreach (var gw in all)
                {
                    if (gw != detTarget)
                    {
                        gw.main = false;
                    }
                }
            }
        }

        if (Application.isPlaying)
        {
            EditorGUILayout.HelpBox("Cannot edit groups while in-game", MessageType.Info);
            foreach (var group in detTarget.manager.enumerate)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField(group.name);
                if (detTarget.manager.activeGroup == group)
                {
                    GUI.enabled = false;
                }
                if (GUILayout.Button("Activate"))
                {
                    detTarget.manager.activeGroup = group;
                }
                GUI.enabled = true;
                EditorGUILayout.EndHorizontal();
            }
            return;
        }


        detTarget.caseSensitive = EditorGUILayout.ToggleLeft("Case-sensitive", detTarget.caseSensitive);
        HashSet <string> check;

        if (detTarget.caseSensitive)
        {
            check = new HashSet <string>();
        }
        else
        {
            check = new HashSet <string>(StringComparer.InvariantCultureIgnoreCase);
        }

        EditorGUILayout.LabelField("Groups");
        int toDelete = -1;
        int toUp     = -1;
        int toDown   = -1;

        for (int i = 0; i < detTarget.states.Count; ++i)
        {
            string name = detTarget.states[i];

            if (!StringExt.IsNullOrWhitespace(name) && check.Contains(name))
            {
                //detTarget.states[i] = null;
                EditorGUILayout.HelpBox(
                    string.Format("'{0}' is already a group", name),
                    MessageType.Warning);
            }
            EditorGUILayout.BeginHorizontal();
            {
                string newName = EditorGUILayout.TextField(name);
                if (newName != null)
                {
                    newName = newName.Trim();
                }
                detTarget.states[i] = newName;
                check.Add(newName);

                if (i == 0)
                {
                    GUI.enabled = false;
                }
                if (GUILayout.Button('\u25B2'.ToString()))
                {
                    GUI.FocusControl(null);
                    toUp = i;
                }
                GUI.enabled = true;
                if (i == detTarget.states.Count - 1)
                {
                    GUI.enabled = false;
                }
                if (GUILayout.Button('\u25BC'.ToString()))
                {
                    GUI.FocusControl(null);
                    toDown = i;
                }
                GUI.enabled = true;
                if (GUILayout.Button("Delete"))
                {
                    GUI.FocusControl(null);
                    toDelete = i;
                }
            }
            EditorGUILayout.EndHorizontal();
        }

        EditorGUILayout.BeginHorizontal();
        {
            if (GUILayout.Button("Add"))
            {
                detTarget.states.Add("");
            }
            if (detTarget.states.Count == 0)
            {
                GUI.enabled = false;
            }
            if (GUILayout.Button("Clear"))
            {
                if (EditorUtility.DisplayDialog(
                        "Confirm", "Are you sure you want to remove all the groups?", "Yes", "No"))
                {
                    detTarget.states.Clear();
                }
            }
            GUI.enabled = true;
        }
        EditorGUILayout.EndHorizontal();
        if (toDelete != -1)
        {
            detTarget.states.RemoveAt(toDelete);
        }
        if (toUp != -1)
        {
            string temp = detTarget.states[toUp];
            detTarget.states[toUp]     = detTarget.states[toUp - 1];
            detTarget.states[toUp - 1] = temp;
        }
        if (toDown != -1)
        {
            string temp = detTarget.states[toDown];
            detTarget.states[toDown]     = detTarget.states[toDown + 1];
            detTarget.states[toDown + 1] = temp;
        }
    }
Ejemplo n.º 6
0
 IEnumerable <FileInfo> FilterDelegate()
 {
     return(File.ReadAllLines(LevelFile).Where(
                _ => !StringExt.IsNullOrWhitespace(_)).Select(
                _ => new FileInfo(LevelPath + _ + ".xml")));
 }