Ejemplo n.º 1
0
        public void Save()
        {
            for (var i = 0; i < Controller.Instance.Quests.Length; i++)
            {
                if (Controller.Instance.Quests[i].GetId() == quest.GetId())
                {
                    Controller.Instance.Quests[i] = quest;
                }
            }

            QuestsController.Save(Controller.Instance.Quests, Controller.Instance.Options.jsonPrettyPrint);
        }
Ejemplo n.º 2
0
        public void OnGUI()
        {
            GUIHelper.Init();
            scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
            GUILayout.BeginVertical(GUIHelper.windowStyle);

            switch (state)
            {
            case State.None:
                Init(State.Close);
                break;

            case State.CreateEdit:
                // Set quest name.
                GUILayout.Label("Name: ");

                var questName = DictionariesHelper.ContainsKey(quest.Name, Controller.Instance.Options.currentLanguage);
                if (questName == null)
                {
                    quest.Name = ArrayHelper.Add(quest.Name, new LanguageDictionary(Controller.Instance.Options.currentLanguage, ""));
                }

                GUI.SetNextControlName("name");
                DictionariesHelper.ContainsKey(quest.Name, Controller.Instance.Options.currentLanguage).value =
                    EditorGUILayout.TextField(DictionariesHelper.ContainsKey(quest.Name, Controller.Instance.Options.currentLanguage).value);
                GUIHelper.Focus("name");
                EditorGUILayout.Space();

                EditorGUILayout.SelectableLabel(string.Format("Quest Unique ID: {0}", quest.GetId()));

                // Set label properties for quest states header.
                GUILayout.BeginHorizontal();
                if (EditorGUIUtility.isProSkin)
                {
                    GUIHelper.labelStyle.normal.textColor = Color.white;
                }
                GUIHelper.labelStyle.alignment = TextAnchor.MiddleLeft;
                GUILayout.Label("Quest states:", GUIHelper.labelStyle);
                GUILayout.EndHorizontal();
                GUIHelper.Separator();

                // Loop of the quest states.
                foreach (var questState in quest.questStates)
                {
                    GUILayout.BeginHorizontal();
                    var index = ArrayHelper.GetIndex(quest.questStates, questState);
                    GUILayout.Label(string.Format("{0}.", (index + 1).ToString()), GUILayout.Width(25));

                    // Descriptions.
                    EditorGUILayout.BeginVertical();



                    EditorGUILayout.LabelField("Short description:");

                    var questStateShortDescription = DictionariesHelper.ContainsKey(questState.ShortDescription, Controller.Instance.Options.currentLanguage);
                    if (questStateShortDescription == null)
                    {
                        questState.ShortDescription = ArrayHelper.Add(questState.ShortDescription, new LanguageDictionary(Controller.Instance.Options.currentLanguage, ""));
                    }

                    DictionariesHelper.ContainsKey(questState.ShortDescription, Controller.Instance.Options.currentLanguage).value =
                        EditorGUILayout.TextArea(DictionariesHelper
                                                 .ContainsKey(questState.ShortDescription, Controller.Instance.Options.currentLanguage).value);
                    EditorGUILayout.Space();

                    EditorGUILayout.LabelField("Long description:");

                    var questStateLongDescription = DictionariesHelper.ContainsKey(questState.LongDescription, Controller.Instance.Options.currentLanguage);
                    if (questStateLongDescription == null)
                    {
                        questState.LongDescription = ArrayHelper.Add(questState.LongDescription, new LanguageDictionary(Controller.Instance.Options.currentLanguage, ""));
                    }

                    DictionariesHelper.ContainsKey(questState.LongDescription, Controller.Instance.Options.currentLanguage).value =
                        EditorGUILayout.TextArea(DictionariesHelper
                                                 .ContainsKey(questState.LongDescription, Controller.Instance.Options.currentLanguage).value);
                    EditorGUILayout.Space();

                    EditorGUILayout.SelectableLabel(string.Format("Quest State Unique ID: {0}", questState.GetId()));

                    EditorGUILayout.BeginHorizontal();
                    if (GUILayout.Button("Up", GUILayout.Height(GUIHelper.BUTTON_HEIGHT_SMALL)))
                    {
                        if (index > 0)
                        {
                            quest.questStates = ArrayHelper.Swap(quest.questStates, index, index - 1);
                            QuestsController.Save(Controller.Instance.Quests, Controller.Instance.Options.jsonPrettyPrint);
                        }
                    }

                    if (GUILayout.Button("Down", GUILayout.Height(GUIHelper.BUTTON_HEIGHT_SMALL)))
                    {
                        if (index < quest.questStates.Length - 1)
                        {
                            quest.questStates = ArrayHelper.Swap(quest.questStates, index, index + 1);
                            QuestsController.Save(Controller.Instance.Quests, Controller.Instance.Options.jsonPrettyPrint);
                        }
                    }

                    if (GUILayout.Button("Delete", GUILayout.Height(GUIHelper.BUTTON_HEIGHT_SMALL)))
                    {
                        if (EditorUtility.DisplayDialog("Are you sure?",
                                                        "Do you really want to delete?\nThis data will be lost forever.", "Yes", "No"))
                        {
                            quest.questStates = ArrayHelper.Remove(quest.questStates, questState);
                            QuestsController.Save(Controller.Instance.Quests, Controller.Instance.Options.jsonPrettyPrint);
                        }
                    }

                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.EndVertical();
                    EditorGUILayout.EndHorizontal();
                    GUIHelper.Separator();
                }

                // Buttons.
                EditorGUILayout.Space();
                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Add quest state", GUILayout.Width(position.width / 2),
                                     GUILayout.Height(GUIHelper.BUTTON_HEIGHT_SMALL)))
                {
                    quest.AddState("Short description.", "Long description.");
                    Save();
                }

                GUILayout.EndHorizontal();
                EditorGUILayout.Separator();
                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Save and close", GUILayout.Height(GUIHelper.BUTTON_HEIGHT)))
                {
                    Save();
                    Close();
                }

                GUILayout.EndHorizontal();

                // Save and close on press Enter.
                if (focusedWindow != null)
                {
                    if (focusedWindow.ToString() == "(Diplomata.Editor.Windows.QuestEditor)")
                    {
                        if (Event.current.keyCode == KeyCode.Return)
                        {
                            Save();
                            Close();
                        }
                    }
                }

                break;
            }

            GUILayout.EndVertical();
            EditorGUILayout.EndScrollView();
        }
Ejemplo n.º 3
0
 public void OnDisable()
 {
     QuestsController.Save(Controller.Instance.Quests, Controller.Instance.Options.jsonPrettyPrint);
 }
Ejemplo n.º 4
0
        public void OnGUI()
        {
            GUIHelper.Init();
            scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
            GUILayout.BeginVertical(GUIHelper.windowStyle);

            // If empty show this message.
            if (Controller.Instance.Quests.Length <= 0)
            {
                EditorGUILayout.HelpBox("No quests yet.", MessageType.Info);
            }

            // Quests loop to list.
            foreach (Quest quest in Controller.Instance.Quests)
            {
                GUILayout.BeginHorizontal();

                // Set label properties.
                GUILayout.BeginHorizontal();
                if (EditorGUIUtility.isProSkin)
                {
                    GUIHelper.labelStyle.normal.textColor = Color.white;
                }
                GUIHelper.labelStyle.alignment = TextAnchor.MiddleLeft;
                var questName = DictionariesHelper.ContainsKey(quest.Name, Controller.Instance.Options.currentLanguage);
                if (questName != null)
                {
                    GUILayout.Label(questName.value, GUIHelper.labelStyle);
                }
                GUILayout.EndHorizontal();

                GUILayout.Space(10.0f);

                // Setting buttons.
                GUILayout.BeginHorizontal(GUILayout.MaxWidth(position.width / 2));
                if (GUILayout.Button("Edit", GUILayout.Height(GUIHelper.BUTTON_HEIGHT_SMALL)))
                {
                    QuestEditor.Open(quest);
                }
                if (GUILayout.Button("Delete", GUILayout.Height(GUIHelper.BUTTON_HEIGHT_SMALL)))
                {
                    if (EditorUtility.DisplayDialog("Are you sure?", "Do you really want to delete?\nThis data will be lost forever.", "Yes", "No"))
                    {
                        QuestEditor.Init(QuestEditor.State.Close);
                        Controller.Instance.Quests = ArrayHelper.Remove(Controller.Instance.Quests, quest);
                        QuestsController.Save(Controller.Instance.Quests, Controller.Instance.Options.jsonPrettyPrint);
                    }
                }
                GUILayout.EndHorizontal();
                GUILayout.EndHorizontal();
            }

            // Add button.
            if (GUILayout.Button("Add Quest", GUILayout.Height(GUIHelper.BUTTON_HEIGHT)))
            {
                var quest = new Quest();
                Controller.Instance.Quests = ArrayHelper.Add(Controller.Instance.Quests, quest);
                quest.questStates          = ArrayHelper.Add(quest.questStates, new QuestState());

                foreach (var language in Controller.Instance.Options.languagesList)
                {
                    quest.questStates[0].ShortDescription =
                        ArrayHelper.Add(quest.questStates[0].ShortDescription, new LanguageDictionary(language, "in progress."));
                    quest.questStates[0].LongDescription =
                        ArrayHelper.Add(quest.questStates[0].LongDescription, new LanguageDictionary(language, ""));
                }

                QuestsController.Save(Controller.Instance.Quests, Controller.Instance.Options.jsonPrettyPrint);
                QuestEditor.Open(quest);
            }

            GUILayout.EndVertical();
            EditorGUILayout.EndScrollView();
        }