Пример #1
0
        public static void AddElement(DatabaseQuestsEditor databaseQuestsEditor)
        {
            List <int> selections = new List <int> {
                databaseQuestsEditor.editorRoot.target.GetInstanceID()
            };
            List <int> nextSelections = new List <int>();

            if (databaseQuestsEditor.questsTree.HasSelection())
            {
                selections = new List <int>(databaseQuestsEditor.questsTree.GetSelection());
            }

            int selectionID = QuestsTreeView.ROOT_ID;

            if (selections.Count == 1)
            {
                selectionID = selections[0];
            }
            IQuest instance = databaseQuestsEditor.InstanceIDToObject(selectionID);

            Quest itemInstance = databaseQuestsEditor.CreateItem <Quest>();

            nextSelections = new List <int>()
            {
                itemInstance.GetInstanceID()
            };

            if (instance != null && instance.GetType() == typeof(Quest))
            {
                databaseQuestsEditor.questsEditors[instance.GetInstanceID()].AddSibling(
                    itemInstance,
                    (IQuest)instance,
                    selectionID
                    );
            }
            else
            {
                Quests rootInstance = databaseQuestsEditor.databaseQuests.quests;
                databaseQuestsEditor.editorRoot.AddChild(
                    itemInstance,
                    rootInstance
                    );
            }

            databaseQuestsEditor.questsEditors.Add(
                itemInstance.GetInstanceID(),
                IQuestEditor.CreateEditor(itemInstance)
                );

            databaseQuestsEditor.questsTree.Reload();

            databaseQuestsEditor.serializedObject.ApplyModifiedPropertiesWithoutUndo();
            databaseQuestsEditor.serializedObject.Update();

            databaseQuestsEditor.questsTree.SetFocusAndEnsureSelectedItem();
            databaseQuestsEditor.questsTree.SetSelection(
                nextSelections,
                TreeViewSelectionOptions.RevealAndFrame
                );
        }
Пример #2
0
        private void BuildTree(ref TreeViewItem parentTree, IQuest parentAsset)
        {
            this.treeItems.Add(parentAsset.GetInstanceID(), parentTree);

            IQuestEditor editor = this.databaseQuestsEditor.questsEditors[parentAsset.GetInstanceID()];

            parentTree.displayName = editor.GetInternalName();
            parentTree.icon        = editor.GetIcon();

            IQuest[] childrenAssets = parentAsset.children.ToArray();
            for (int i = 0; i < childrenAssets.Length; ++i)
            {
                IQuest childAsset = childrenAssets[i];
                if (childAsset == null)
                {
                    continue;
                }

                int          childAssetID = childAsset.GetInstanceID();
                int          depth        = parentTree.depth + 1;
                TreeViewItem childTree    = new TreeViewItem(childAssetID, depth, "Loading...");

                if (!this.databaseQuestsEditor.questsEditors.ContainsKey(childAssetID))
                {
                    Debug.LogError("No IQuest Editor found with instanceID: " + childAssetID);
                    continue;
                }

                this.BuildTree(ref childTree, childAsset);
                parentTree.AddChild(childTree);
            }
        }
Пример #3
0
        public static void AddElement(DatabaseQuestsEditor databaseQuestsEditor)
        {
            List <int> selections = new List <int> {
                databaseQuestsEditor.editorRoot.target.GetInstanceID()
            };
            List <int> nextSelections = new List <int>();

            if (databaseQuestsEditor.questsTree.HasSelection())
            {
                selections = new List <int>(databaseQuestsEditor.questsTree.GetSelection());
            }

            for (int i = 0; i < selections.Count; ++i)
            {
                int    selectionID = selections[i];
                IQuest instance    = databaseQuestsEditor.InstanceIDToObject(selectionID);

                Task itemInstance = databaseQuestsEditor.CreateItem <Task>();
                nextSelections.Add(itemInstance.GetInstanceID());

                if (instance != null && instance.GetType() == typeof(Quest) &&
                    databaseQuestsEditor.questsEditors.ContainsKey(instance.GetInstanceID()))
                {
                    databaseQuestsEditor.questsEditors[instance.GetInstanceID()].AddChild(
                        itemInstance,
                        (IQuest)instance
                        );
                }
                else if (instance != null && instance.GetType() == typeof(Task) &&
                         databaseQuestsEditor.questsEditors.ContainsKey(instance.GetInstanceID()))
                {
                    databaseQuestsEditor.questsEditors[instance.GetInstanceID()].AddChild(
                        itemInstance,
                        (IQuest)instance
                        );
                }
                else
                {
                    Debug.LogError("Unknown type: " + instance.GetType());
                }

                databaseQuestsEditor.questsEditors.Add(
                    itemInstance.GetInstanceID(),
                    IQuestEditor.CreateEditor(itemInstance)
                    );

                databaseQuestsEditor.questsTree.Reload();

                databaseQuestsEditor.serializedObject.ApplyModifiedProperties();
                databaseQuestsEditor.serializedObject.Update();
            }

            databaseQuestsEditor.questsTree.SetFocusAndEnsureSelectedItem();
            databaseQuestsEditor.questsTree.SetSelection(nextSelections, TreeViewSelectionOptions.RevealAndFrame);
        }
Пример #4
0
        // INITIALIZERS: --------------------------------------------------------------------------

        public static void Open(IQuestEditor questEditor)
        {
            if (QuestConfigWindow.Instance != null)
            {
                QuestConfigWindow.Instance.Close();
            }

            Rect windowRect = new Rect(0, 0, WINDOW_W, WINDOW_H);

            QuestConfigWindow.Instance = EditorWindow.GetWindowWithRect <QuestConfigWindow>(
                windowRect, true, questEditor.GetInternalName(), true
                );

            QuestConfigWindow.Instance.questEditor = questEditor;
            QuestConfigWindow.Instance.Show();
        }
        // INITIALIZE: ----------------------------------------------------------------------------

        private void OnEnable()
        {
            if (target == null || serializedObject == null)
            {
                return;
            }

            this.databaseQuests = (DatabaseQuests)this.target;
            this.spQuests       = serializedObject.FindProperty(PROP_QUESTS);
            this.spList         = serializedObject.FindProperty(PROP_LIST);
            this.spSettings     = serializedObject.FindProperty(PROP_SETTINGS);

            if (this.spQuests.objectReferenceValue == null)
            {
                this.spQuests.objectReferenceValue = QuestUtilities.GetQuestsRoot();
                serializedObject.ApplyModifiedPropertiesWithoutUndo();
                serializedObject.Update();
            }

            Quests quests = (Quests)this.spQuests.objectReferenceValue;

            this.questsInstances = new Dictionary <int, IQuest>();
            this.questsInstances.Add(QuestsTreeView.ROOT_ID, quests);

            this.editorRoot    = IQuestEditor.CreateEditor(quests);
            this.questsEditors = new Dictionary <int, IQuestEditor>();
            this.questsEditors.Add(quests.GetInstanceID(), this.editorRoot);

            for (int i = 0; i < this.databaseQuests.list.Count; ++i)
            {
                IQuest item = this.databaseQuests.list[i];
                if (!this.questsInstances.ContainsKey(item.GetInstanceID()))
                {
                    this.questsInstances.Add(item.GetInstanceID(), item);
                }

                IQuestEditor editor = IQuestEditor.CreateEditor(item);
                this.questsEditors.Add(item.GetInstanceID(), editor);
            }

            this.questsTree = new QuestsTreeView(this.databaseQuests.questsTreeState, this);

            this.searchField = new SearchField();
            this.searchField.downOrUpArrowKeyPressed += this.questsTree.SetFocusAndEnsureSelectedItem;
        }
Пример #6
0
        protected override void RowGUI(TreeView.RowGUIArgs args)
        {
            base.RowGUI(args);
            if (args.isRenaming)
            {
                return;
            }

            if (this.CanRename(args.item) && args.selected)
            {
                if (Event.current.type == EventType.ContextClick)
                {
                    this.BeginRename(args.item);
                    Event.current.Use();
                    return;
                }
            }

            Rect rectActionsFail = new Rect(
                args.rowRect.x + args.rowRect.width - ICON_INFO_WIDTH,
                args.rowRect.y,
                ICON_INFO_WIDTH,
                args.rowRect.height
                );

            Rect rectActionsComplete = new Rect(
                rectActionsFail.x - ICON_INFO_WIDTH,
                args.rowRect.y,
                ICON_INFO_WIDTH,
                args.rowRect.height
                );

            Rect rectConditions = new Rect(
                rectActionsComplete.x - ICON_INFO_WIDTH,
                args.rowRect.y,
                SETTINGS_BTN_WIDTH,
                args.rowRect.height
                );

            if (!this.databaseQuestsEditor.questsEditors.ContainsKey(args.item.id))
            {
                return;
            }
            IQuestEditor iquestEditor = this.databaseQuestsEditor.questsEditors[args.item.id];

            QuestReaction reaction = iquestEditor.iquest.reactions;

            if (reaction == null)
            {
                return;
            }

            GUIContent contentFail = QuestTreeUtils.GetIcon((
                                                                reaction.onFail != null && reaction.onFail.actions.Length > 0
                ? QuestTreeUtils.Icon.OnFail
                : QuestTreeUtils.Icon.OffFail
                                                                ));

            GUIContent contentComplete = QuestTreeUtils.GetIcon((
                                                                    reaction.onComplete != null && reaction.onComplete.actions.Length > 0
                                ? QuestTreeUtils.Icon.OnComplete
                                : QuestTreeUtils.Icon.OffComplete
                                                                    ));

            GUIContent contentConditions = QuestTreeUtils.GetIcon((
                                                                      reaction.conditions != null && reaction.conditions.conditions.Length > 0
                                ? QuestTreeUtils.Icon.OnConditions
                                : QuestTreeUtils.Icon.OffConditions
                                                                      ));

            EditorGUI.LabelField(rectActionsFail, contentFail);
            EditorGUI.LabelField(rectActionsComplete, contentComplete);
            EditorGUI.LabelField(rectConditions, contentConditions);

            if (EditorApplication.isPlaying)
            {
                args.item.icon = iquestEditor.GetIcon();
            }

            Rect rectSettings = new Rect(
                rectConditions.x - SETTINGS_BTN_WIDTH - 5f,
                args.rowRect.y,
                SETTINGS_BTN_WIDTH,
                args.rowRect.height
                );

            if (!EditorApplication.isPlaying && this.IsSelected(args.item.id))
            {
                if (GUI.Button(rectSettings, GUICONTENT_EDIT, EditorStyles.miniButton))
                {
                    QuestConfigWindow.Open(iquestEditor);
                }
            }
            else if (iquestEditor.ShowProgress())
            {
                float progress = iquestEditor.GetProgress();
                Rect  rectBkg  = new Rect(
                    rectSettings.x + PROG_PADDING,
                    rectSettings.y + (rectSettings.height / 2.0f - PROG_HEIGHT / 2.0f),
                    rectSettings.width - (2f * PROG_PADDING),
                    PROG_HEIGHT
                    );
                Rect rectBar = new Rect(
                    rectBkg.x,
                    rectBkg.y,
                    rectBkg.width * progress,
                    rectBkg.height
                    );

                EditorGUI.DrawRect(rectBkg, EditorApplication.isPlaying ? PROG_BCK_R : PROG_BCK_E);
                EditorGUI.DrawRect(rectBar, EditorApplication.isPlaying ? PROG_BAR_R : PROG_BAR_E);
            }
        }