예제 #1
0
    private void OnGUI()
    {
        EditorGUILayout.BeginHorizontal();
        {
            EditorGUILayout.LabelField(_currentFileTitle, EditorStyles.boldLabel);

            if (GUILayout.Button("Reload"))
            {
                SetFile(_file);
            }

            if (GUILayout.Button("Save"))
            {
                if (_dirty)
                {
                    string assetPath = AssetDatabase.GetAssetPath(_file);
                    File.WriteAllText(assetPath, _game.Save());
                    AssetDatabase.Refresh();

                    SetFile(_file);
                }
            }
        }
        EditorGUILayout.EndHorizontal();

        TextAsset newFile = EditorGUILayout.ObjectField("File", _file, typeof(TextAsset), false) as TextAsset;

        if (newFile != _file)
        {
            SetFile(newFile);
        }

        if (string.IsNullOrEmpty(_error) == false)
        {
            EditorGUILayout.HelpBox(_error, MessageType.Error);
        }

        if (_game == null)
        {
            return;
        }

        EditorGUILayout.Space();

        EditorGUILayout.BeginHorizontal();
        {
            if (GUILayout.Button("Delete All"))
            {
                if (EditorUtility.DisplayDialog("Delete all round", "Are you sure you want to delete all rounds?", "Delete", "Cancel"))
                {
                    _game.GameRounds = new List <Round>();
                    _game.SerializedRoundQuestions = new List <string>();

                    SetGameDirty();
                }
            }

            if (GUILayout.Button("Collapse All"))
            {
                for (int i = 0; i < _game.GameRounds.Count; i++)
                {
                    _roundCollapsed[i] = true;

                    Question[] questions = _game.GetQuestionsForRound <Question>(i);

                    _questionCollapsed[i] = new Dictionary <int, bool>();

                    if (questions == null)
                    {
                        continue;
                    }

                    for (int j = 0; j < questions.Length; j++)
                    {
                        _questionCollapsed[i][j] = true;
                    }
                }
            }

            if (GUILayout.Button("Open All"))
            {
                for (int i = 0; i < _game.GameRounds.Count; i++)
                {
                    _roundCollapsed[i] = false;

                    Question[] questions = _game.GetQuestionsForRound <Question>(i);

                    _questionCollapsed[i] = new Dictionary <int, bool>();

                    if (questions == null)
                    {
                        continue;
                    }

                    for (int j = 0; j < questions.Length; j++)
                    {
                        _questionCollapsed[i][j] = false;
                    }
                }
            }
        }
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.Space();

        EditorGUILayout.BeginHorizontal(GUI.skin.box);
        {
            _scrollPosition = EditorGUILayout.BeginScrollView(_scrollPosition, false, true);

            for (int i = 0; i < _game.GameRounds.Count; i++)
            {
                switch (_game.GetRound(i))
                {
                case Round.ThreeSixNine:
                    DrawThreeSixNine(i);
                    break;

                case Round.Puzzle:
                    DrawPuzzle(i);
                    break;

                case Round.OpenDoor:
                    DrawOpenDoor(i);
                    break;

                case Round.Gallery:
                    DrawGallery(i);
                    break;

                case Round.CollectiveMemory:
                    DrawCollectiveMemory(i);
                    break;

                case Round.Finale:
                    DrawFinale(i);
                    break;

                case Round.Bonus:
                    DrawBonus(i);
                    break;

                case Round.Done:
                    DrawDone(i);
                    break;
                }
            }

            EditorGUILayout.EndScrollView();
        }
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.Space();

        EditorGUILayout.BeginHorizontal();
        {
            _roundToAdd = (Round)EditorGUILayout.EnumPopup(_roundToAdd);

            if (GUILayout.Button("Add Round"))
            {
                SetGameDirty();

                switch (_roundToAdd)
                {
                case Round.ThreeSixNine:
                    ThreeSixNineQuestion[] threeSixNineQuestions = new ThreeSixNineQuestion[15];
                    for (int i = 0; i < threeSixNineQuestions.Length; i++)
                    {
                        threeSixNineQuestions[i] = new ThreeSixNineQuestion();
                    }

                    QuestionContainer <ThreeSixNineQuestion> threeSixNineContainer = new QuestionContainer <ThreeSixNineQuestion>();
                    threeSixNineContainer.Questions = threeSixNineQuestions;

                    _game.AddRound(_roundToAdd, threeSixNineContainer);
                    break;

                case Round.Puzzle:
                    PuzzleQuestion[] puzzleQuestions = new PuzzleQuestion[3];
                    for (int i = 0; i < puzzleQuestions.Length; i++)
                    {
                        puzzleQuestions[i]         = new PuzzleQuestion();
                        puzzleQuestions[i].Answers = new PuzzleAnswer[3];

                        for (int j = 0; j < puzzleQuestions[i].Answers.Length; j++)
                        {
                            puzzleQuestions[i].Answers[j]       = new PuzzleAnswer();
                            puzzleQuestions[i].Answers[j].Words = new[] { "", "", "", "" };
                        }
                    }

                    QuestionContainer <PuzzleQuestion> puzzleContainer = new QuestionContainer <PuzzleQuestion>();
                    puzzleContainer.Questions = puzzleQuestions;

                    _game.AddRound(_roundToAdd, puzzleContainer);
                    break;

                case Round.OpenDoor:
                    OpenDoorQuestion[] openDoorQuestions = new OpenDoorQuestion[3];
                    for (int i = 0; i < openDoorQuestions.Length; i++)
                    {
                        openDoorQuestions[i]         = new OpenDoorQuestion();
                        openDoorQuestions[i].Answers = new OpenDoorAnswer[4];

                        for (int j = 0; j < openDoorQuestions[i].Answers.Length; j++)
                        {
                            openDoorQuestions[i].Answers[j] = new OpenDoorAnswer();
                        }
                    }

                    QuestionContainer <OpenDoorQuestion> openDoorContainer = new QuestionContainer <OpenDoorQuestion>();
                    openDoorContainer.Questions = openDoorQuestions;

                    _game.AddRound(_roundToAdd, openDoorContainer);
                    break;

                case Round.Gallery:
                    GalleryQuestion[] galleryQuestions = new GalleryQuestion[3];
                    for (int i = 0; i < galleryQuestions.Length; i++)
                    {
                        galleryQuestions[i]         = new GalleryQuestion();
                        galleryQuestions[i].Answers = new GalleryAnswer[10];

                        for (int j = 0; j < galleryQuestions[i].Answers.Length; j++)
                        {
                            galleryQuestions[i].Answers[j] = new GalleryAnswer();
                        }
                    }

                    QuestionContainer <GalleryQuestion> galleryContainer = new QuestionContainer <GalleryQuestion>();
                    galleryContainer.Questions = galleryQuestions;

                    _game.AddRound(_roundToAdd, galleryContainer);
                    break;

                case Round.Bonus:
                    _game.AddRound <Question>(_roundToAdd, null);
                    break;

                case Round.Done:
                    _game.AddRound <Question>(_roundToAdd, null);
                    break;

                case Round.CollectiveMemory:
                    CollectiveMemoryQuestion[] collectiveMemoryQuestions = new CollectiveMemoryQuestion[3];
                    for (int i = 0; i < collectiveMemoryQuestions.Length; i++)
                    {
                        collectiveMemoryQuestions[i]             = new CollectiveMemoryQuestion();
                        collectiveMemoryQuestions[i].Answers     = new string[5];
                        collectiveMemoryQuestions[i].TimeRewards = new int[5];

                        for (int j = 0; j < collectiveMemoryQuestions[i].Answers.Length; j++)
                        {
                            collectiveMemoryQuestions[i].Answers[j]     = "Antwoord " + (i + 1);
                            collectiveMemoryQuestions[i].TimeRewards[j] = 0;
                        }
                    }

                    QuestionContainer <CollectiveMemoryQuestion> collectiveMemoryContainer = new QuestionContainer <CollectiveMemoryQuestion>();
                    collectiveMemoryContainer.Questions = collectiveMemoryQuestions;

                    _game.AddRound(_roundToAdd, collectiveMemoryContainer);
                    break;

                case Round.Finale:
                    FinaleQuestion[] finaleQuestions = new FinaleQuestion[12];
                    for (int i = 0; i < finaleQuestions.Length; i++)
                    {
                        finaleQuestions[i]         = new FinaleQuestion();
                        finaleQuestions[i].Answers = new FinaleAnswer[5];

                        for (int j = 0; j < finaleQuestions[i].Answers.Length; j++)
                        {
                            finaleQuestions[i].Answers[j] = new FinaleAnswer();
                        }
                    }

                    QuestionContainer <FinaleQuestion> finaleContainer = new QuestionContainer <FinaleQuestion>();
                    finaleContainer.Questions = finaleQuestions;

                    _game.AddRound(_roundToAdd, finaleContainer);
                    break;
                }
            }
        }
        EditorGUILayout.EndHorizontal();

        if (_roundIndexToRemove != -1)
        {
            _game.RemoveRound(_roundIndexToRemove);
            SetGameDirty();
            _roundIndexToRemove = -1;
        }
    }
예제 #2
0
    private void DrawThreeSixNine(int roundIndex)
    {
        bool collapsed;

        _roundCollapsed.TryGetValue(roundIndex, out collapsed);

        ThreeSixNineQuestion[] questions = _game.GetQuestionsForRound <ThreeSixNineQuestion>(roundIndex);

        EditorGUILayout.BeginHorizontal();
        {
            if (GUILayout.Button("x", GUILayout.Width(20)))
            {
                if (EditorUtility.DisplayDialog("Delete round", "Are you sure you want to delete this round?", "Delete", "Cancel"))
                {
                    _roundIndexToRemove = roundIndex;
                }
            }

            if (GUILayout.Button(collapsed ? "▼" : "▲", GUILayout.Width(20)))
            {
                _roundCollapsed[roundIndex] = !collapsed;
            }

            EditorGUILayout.LabelField("Three Six Nine" + (collapsed ? string.Format(" ({0})", questions.Length) : ""), EditorStyles.boldLabel);
        }
        EditorGUILayout.EndHorizontal();

        if (collapsed)
        {
            return;
        }

        EditorGUILayout.BeginHorizontal();
        {
            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.Space();

            EditorGUILayout.BeginVertical();
            {
                EditorGUILayout.BeginHorizontal();
                {
                    EditorGUILayout.LabelField("Question");
                    EditorGUILayout.LabelField("Player Question");
                    EditorGUILayout.LabelField("Answer");
                    EditorGUILayout.LabelField("Time Reward", GUILayout.Width(80));
                }
                EditorGUILayout.EndHorizontal();

                EditorGUI.BeginChangeCheck();

                for (int i = 0; i < questions.Length; i++)
                {
                    ThreeSixNineQuestion question = questions[i];

                    EditorGUILayout.BeginHorizontal();
                    {
                        question.Question       = EditorGUILayout.TextField(question.Question);
                        question.PlayerQuestion = EditorGUILayout.TextField(question.PlayerQuestion);
                        question.Answer         = EditorGUILayout.TextField(question.Answer);
                        question.TimeReward     = EditorGUILayout.IntField(question.TimeReward, GUILayout.Width(80));
                    }
                    EditorGUILayout.EndHorizontal();
                }

                if (EditorGUI.EndChangeCheck())
                {
                    SetGameDirty();
                }
            }
            EditorGUILayout.EndVertical();
        }
        EditorGUILayout.EndHorizontal();
    }