Пример #1
0
    static void saveScreens(TerminalData t)
    {
        string screenOptionsPath = SAVE_PATH + t.id + SCREEN_OPTIONS_POSTFIX;

        checkSaveDirectory();
        createScreenFiles(t);

        Debug.Log("Writing screens to file for terminal " + t.id);

        StreamWriter optionWriter = new StreamWriter(screenOptionsPath, true);

        for (int i = 0; i < t.screens.Count; i++)
        {
            // Create screen file and write to it
            TScreen      screen = t.screens[i];
            StreamWriter writer = new StreamWriter(getScreenFileName(i, t.id));
            writer.WriteLine(screen.id);
            writer.Write(screen.text);
            writer.Close();

            // Write option line for this screen
            optionWriter.WriteLine(screen.getOptionsFileLine());
        }

        optionWriter.Close();
    }
Пример #2
0
        public TScreen CreateScreen <TScreen>() where TScreen : ScreenBase
        {
            TScreen screen = (TScreen)Activator
                             .CreateInstance(typeof(TScreen), Aggregator);

            GetOperationsFor(screen).Initialize();

            return(screen);
        }
Пример #3
0
    void addNewOption(TScreen s)
    {
        int     newIndex  = s.options.Count;
        SOption newOption = new SOption(newIndex, s);

        s.options.Add(newOption);

        // Select newly created option
        optionIndex = newIndex;
    }
Пример #4
0
    void onTerminalGUI()
    {
        scrollPos = GUILayout.BeginScrollView(scrollPos, false, false, GUIStyle.none, GUI.skin.verticalScrollbar);

        GUILayout.Label("Edit Screen", EditorStyles.boldLabel);
        EditorGUILayout.BeginHorizontal();

        string[] screenSelect = terminalData.screens.Select(s => s.id).ToArray();

        screenIndex = EditorGUILayout.Popup("Select screen to edit:", screenIndex, screenSelect);
        if (GUILayout.Button("+"))
        {
            state = windowState.creatingScreen;
        }
        EditorGUILayout.EndHorizontal();

        onScreenCreateGUI();

        TScreen screenEdit = terminalData.screens.Find(s => s.index == screenIndex);

        onScreenEditGUI(screenEdit);

        GUILayout.EndScrollView();

        if (state == windowState.loaded)
        {
            GUILayout.Space(30);

            if (screenEdit != null)
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("Generate Game Objects for screen " + screenEdit.id))
                {
                    screenEdit.buildGameObjects(screenPrefabPath, optionPrefabPath);
                }
                GUILayout.FlexibleSpace();
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.Space();
            }

            if (GUILayout.Button("Generate all Game Objects for terminal " + terminalData.id))
            {
                terminalData.generateGameScreens(screenPrefabPath, optionPrefabPath);
            }


            if (GUILayout.Button("Generate all VRCTriggers for terminal " + terminalData.id))
            {
                terminalData.generateGameTriggers();
            }
            GUI.enabled = true;
        }
    }
Пример #5
0
    void addNewScreen(string id, TerminalData t)
    {
        EditorGUILayout.Space();

        // Create new screen
        int     newIndex  = t.screens.Count;
        TScreen newScreen = new TScreen(t, "", newIndex, id);

        terminalData.screens.Add(newScreen);

        // Select newly created screen
        screenIndex = newIndex;

        resetNewScreen();
    }
Пример #6
0
    void onScreenEditGUI(TScreen screen)
    {
        // Default view for editing screens

        if (screen == null || state != windowState.loaded)
        {
            return;
        }

        EditorGUILayout.BeginHorizontal();
        GUILayout.Space(30);
        EditorGUILayout.PrefixLabel("screen text:");
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.BeginHorizontal();
        GUILayout.Space(50);
        screen.text = EditorGUILayout.TextArea(screen.text, GUILayout.Height(64), GUILayout.Width(position.width - 75));
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        GUILayout.Space(30);
        Color origcolor = GUI.backgroundColor;

        GUI.backgroundColor = new Color(0.8f, 0.4f, 0.4f);
        if (GUILayout.Button("Delete " + screen.id))
        {
            terminalData.screens.Remove(screen);
        }
        GUI.backgroundColor = origcolor;
        GUILayout.FlexibleSpace();
        EditorGUILayout.EndHorizontal();

        string[] optionSelect = screen.options.Select(o => o.index.ToString()).ToArray();

        EditorGUILayout.Space();
        GUILayout.Label("Edit Option", EditorStyles.boldLabel);

        EditorGUILayout.BeginHorizontal();
        optionIndex = EditorGUILayout.Popup("Select option to edit:", optionIndex, optionSelect);
        if (GUILayout.Button("+"))
        {
            addNewOption(screen);
        }
        EditorGUILayout.EndHorizontal();

        SOption optionEdit = screen.options.Find(o => o.index == optionIndex);

        onOptionEditGUI(optionEdit);
    }
Пример #7
0
        public TScreen GetScreen <TScreen>() where TScreen : IScreen, new()
        {
            Type screenType = typeof(TScreen);

            TScreen screen;

            if (!_screens.ContainsKey(screenType))
            {
                screen = new TScreen()
                {
                    ScreenManager = this
                };
                _screens.Add(screenType, screen);
                screen.Data.transform.SetParent(Container.ScreensContainer);
                screen.Init();
            }
            else
            {
                screen = (TScreen)_screens[screenType];
            }
            return(screen);
        }
Пример #8
0
    public static TerminalData loadTerminalFromFile(TerminalObject gameTerminal)
    {
        if (gameTerminal == null || gameTerminal.id == null)
        {
            return(null);
        }

        TerminalData tData = terminals.Find(t => t.id == gameTerminal.id);

        if (tData == null)
        {
            tData = new TerminalData(gameTerminal);
        }

        // No need to check if the right directory exists because that's where the class files are stored

        // Load Screens from file
        int i = 0;

        while (File.Exists(getScreenFileName(i, gameTerminal.id)))
        {
            StreamReader reader = new StreamReader(getScreenFileName(i, gameTerminal.id));
            string       line;
            string       id;
            string       text = "";
            id = reader.ReadLine();             // ID is first line of save file
            while ((line = reader.ReadLine()) != null)
            {
                text += line + System.Environment.NewLine;
            }

            // Create screen
            TScreen screen = new TScreen(tData, text, i, id);
            // Add screen to terminal
            TScreen oldScreen = tData.screens.Find(s => s.index == i);
            if (oldScreen == null)
            {
                // if screen doesn't exist, add it to screens
                tData.screens.Add(screen);
            }
            else
            {
                // if screen already exists, replace it with file screen
                oldScreen = screen;
            }

            reader.Close();
            i++;
        }

        // load all options for screens
        string screenOptionsPath = SAVE_PATH + gameTerminal.id + SCREEN_OPTIONS_POSTFIX;

        if (File.Exists(screenOptionsPath))
        {
            StreamReader optionReader = new StreamReader(screenOptionsPath);
            string       line;
            i = 0;
            while ((line = optionReader.ReadLine()) != null)
            {
                TScreen  screen = tData.screens[i];
                string[] ops    = line.Split('|');
                int      j      = 0;
                int      n      = 0;
                while (j < ops.Length - 1)
                {
                    SOption newOption = new SOption(n++, screen);
                    newOption.text = ops [j];
                    int.TryParse(ops [j + 1], out newOption.destination);

                    // Check for old version of option
                    SOption oldOption = screen.options.Find(o => o.index == newOption.index);
                    if (oldOption == null)
                    {
                        screen.options.Add(newOption);
                    }
                    else
                    {
                        oldOption = newOption;
                    }

                    j += 2;
                }
                i++;
            }
        }

        return(tData);
    }
Пример #9
0
 public SOption(int index, TScreen s)
 {
     this.index  = index;
     this.screen = s;
 }