private void OnRemoveMission(object sender, ItemRemovingEventArgs args)
        {
            GenericClassListAdaptor <Mission> listAdaptor = args.adaptor as GenericClassListAdaptor <Mission>;
            Mission mission = listAdaptor[args.itemIndex];

            if (listAdaptor != null)
            {
                if (EditorUtility.DisplayDialog("Confirm to delete",
                                                "Confirm to delete mission [" + mission.ID + "]?", "OK", "Cancel"))
                {
                    args.Cancel = false;
                    GameKit.Config.UpdateMapsAndTree();
                    GameKitEditorWindow.GetInstance().Repaint();

                    MissionTreeExplorer missionTreeExplorer = GameKitEditorWindow.GetInstance().GetTreeExplorer(
                        GameKitEditorWindow.TabType.Missions) as MissionTreeExplorer;
                    if (missionTreeExplorer.CurrentSelectedItem == mission)
                    {
                        missionTreeExplorer.SelectItem(null);
                    }
                }
                else
                {
                    args.Cancel = true;
                }
            }
        }
        protected override void DoOnExplorerSelectionChange(IItem item)
        {
            World world = item as World;

            if (world == null)
            {
                return;
            }

            _gateView.UpdateDisplayItem(world.Gate);

            world.RefreshSubWorlds();
            _subWorldListAdaptor = new GenericClassListAdaptor <World>(world.SubWorlds, 20,
                                                                       () => { return(new World()); },
                                                                       (position, theItem, index) =>
            {
                var size = GUI.skin.GetStyle("label").CalcSize(new GUIContent(theItem.ID));
                GUI.Label(new Rect(position.x, position.y, size.x, position.height), theItem.ID);
                if (GUI.Button(new Rect(position.x + size.x + 10, position.y, 50, position.height), "Edit"))
                {
                    _treeExplorer.SelectItem(theItem);
                }
                return(theItem);
            });
            _scoreListAdaptor = new GenericClassListAdaptor <Score>(world.Scores, 20,
                                                                    () => { return(new Score()); },
                                                                    (position, theItem, index) =>
            {
                var size = GUI.skin.GetStyle("label").CalcSize(new GUIContent(theItem.ID));
                GUI.Label(new Rect(position.x, position.y, size.x, position.height), theItem.ID);
                if (GUI.Button(new Rect(position.x + size.x + 10, position.y, 50, position.height), "Edit"))
                {
                    ScoreTreeExplorer scoreTreeExplorer = (GameKitEditorWindow.GetInstance().GetTreeExplorer(
                                                               GameKitEditorWindow.TabType.Scores) as ScoreTreeExplorer);
                    GameKitEditorWindow.GetInstance().SelectTab(GameKitEditorWindow.TabType.Scores);
                    scoreTreeExplorer.SelectItem(theItem);
                }
                return(theItem);
            });
            _missionListAdaptor = new GenericClassListAdaptor <Mission>(world.Missions, 20,
                                                                        () => { return(new Mission()); },
                                                                        (position, theItem, index) =>
            {
                var size = GUI.skin.GetStyle("label").CalcSize(new GUIContent(theItem.ID));
                GUI.Label(new Rect(position.x, position.y, size.x, position.height), theItem.ID);
                if (GUI.Button(new Rect(position.x + size.x + 10, position.y, 50, position.height), "Edit"))
                {
                    MissionTreeExplorer missionTreeExplorer = (GameKitEditorWindow.GetInstance().GetTreeExplorer(
                                                                   GameKitEditorWindow.TabType.Missions) as MissionTreeExplorer);
                    GameKitEditorWindow.GetInstance().SelectTab(GameKitEditorWindow.TabType.Missions);
                    missionTreeExplorer.SelectItem(theItem);
                }
                return(theItem);
            });
        }
        private void OnInsertSubworld(object sender, ItemInsertedEventArgs args)
        {
            GenericClassListAdaptor <World> listAdaptor = args.adaptor as GenericClassListAdaptor <World>;
            World world = listAdaptor[args.itemIndex];

            (_currentDisplayItem as World).SubWorldsID.Add(world.ID);
            GameKit.Config.Worlds.Add(world);
            GameKit.Config.UpdateMapsAndTree();
            (_treeExplorer as WorldTreeExplorer).AddWorld(world);
            ScoreTreeExplorer scoreTreeExplorer = (GameKitEditorWindow.GetInstance().GetTreeExplorer(
                                                       GameKitEditorWindow.TabType.Scores) as ScoreTreeExplorer);

            scoreTreeExplorer.AddWorld(world);
        }
        private void UpdateItemIDFromTextField(IItem item, System.Action <string> OnGetNewID = null)
        {
            _currentItemID = _currentItemID.Trim();
            if (string.IsNullOrEmpty(_currentItemID))
            {
                EditorUtility.DisplayDialog("Invlid ID", "ID couldn't be empty.", "OK");
                _currentItemID = item.ID;
                GUI.FocusControl(IDInputControlName);
                return;
            }

            IItem itemWithID = GetItemWithConflictingID(item, _currentItemID);

            if (itemWithID != null && itemWithID != item)
            {
                GUIUtility.keyboardControl = 0;
                EditorUtility.DisplayDialog("Duplicate ID", "A " + item.GetType().ToString() + " with ID[" +
                                            _currentItemID + "] already exists!!!", "OK");
                _currentItemID = item.ID;
            }
            else
            {
                IItem[] affectedItems = GetAffectedItems(item.ID);
                if (affectedItems.Length == 0 ||
                    EditorUtility.DisplayDialog("Renaming ID will affect the following items, are you sure to change?",
                                                "Affected items: " + GetAffectedItemsWarningString(affectedItems), "OK", "Cancel"))
                {
                    if (OnGetNewID != null)
                    {
                        OnGetNewID(_currentItemID);
                    }
                    UpdateRelatedIDOfItems(affectedItems, item.ID, _currentItemID);
                    item.ID = _currentItemID;
                    GameKit.Config.UpdateMapsAndTree();
                }
                else
                {
                    _currentItemID = item.ID;
                }
            }
            GameKitEditorWindow.GetInstance().Repaint();
        }
        private void OnItemInsert <T>(object sender, ItemInsertedEventArgs args) where T : SerializableItem
        {
            GenericClassListAdaptor <T> listAdaptor = args.adaptor as GenericClassListAdaptor <T>;

            if (listAdaptor != null)
            {
                if (listAdaptor[args.itemIndex] is UpgradeItem)
                {
                    int    upgradeIndex = args.itemIndex + 1;
                    string suffix       = upgradeIndex < 10 ? "00" + upgradeIndex :
                                          upgradeIndex < 100 ? "0" + upgradeIndex : upgradeIndex.ToString();
                    UpgradeItem upgradeItem = (listAdaptor[args.itemIndex] as UpgradeItem);
                    upgradeItem.RelatedItemID = (listAdaptor[0] as UpgradeItem).RelatedItemID;
                    upgradeItem.ID            = string.Format("{0}-upgrade{1}", upgradeItem.RelatedItemID, suffix);
                    GameKit.Config.Upgrades.Add(upgradeItem);
                }
                SelectItem(listAdaptor[args.itemIndex]);
                GameKitEditorWindow.GetInstance().Repaint();
            }
        }
Exemple #6
0
        public string FindScorePropertyPath(Score score)
        {
            World world = GameKit.Config.FindWorldThatScoreBelongsTo(score);

            if (world == null)
            {
                return(string.Empty);
            }

            string path = GameKitEditorWindow.GetInstance().FindWorldPropertyPath(world);

            for (int i = 0; i < world.Scores.Count; i++)
            {
                if (world.Scores[i] == score)
                {
                    return(path + string.Format(".Scores.Array.data[{0}]", i));
                }
            }

            Debug.LogError("FindScorePropertyPath::Code shoul never run here.");
            return(string.Empty);
        }
        private void OnRemoveScore(object sender, ItemRemovingEventArgs args)
        {
            GenericClassListAdaptor <Score> listAdaptor = args.adaptor as GenericClassListAdaptor <Score>;
            Score score = listAdaptor[args.itemIndex];

            if (listAdaptor != null)
            {
                ScorePropertyInspector scoreInspector = GameKitEditorWindow.GetInstance().GetPropertyInsepctor(
                    GameKitEditorWindow.TabType.Scores) as ScorePropertyInspector;
                IItem[] items = scoreInspector.GetAffectedItems(score.ID);
                if (items.Length > 0)
                {
                    EditorUtility.DisplayDialog("Warning", "Not allowed to delete becase the item is still used by following items: " +
                                                scoreInspector.GetAffectedItemsWarningString(items), "OK");
                    args.Cancel = true;
                }
                else
                {
                    if (EditorUtility.DisplayDialog("Confirm to delete",
                                                    "Confirm to delete score [" + score.ID + "]?", "OK", "Cancel"))
                    {
                        args.Cancel = false;
                        GameKit.Config.UpdateMapsAndTree();
                        GameKitEditorWindow.GetInstance().Repaint();

                        ScoreTreeExplorer scoreTreeExplorer = GameKitEditorWindow.GetInstance().GetTreeExplorer(
                            GameKitEditorWindow.TabType.Scores) as ScoreTreeExplorer;
                        if (scoreTreeExplorer.CurrentSelectedItem == score)
                        {
                            scoreTreeExplorer.SelectItem(null);
                        }
                    }
                    else
                    {
                        args.Cancel = true;
                    }
                }
            }
        }
        private void OnItemRemoving <T>(object sender, ItemRemovingEventArgs args) where T : SerializableItem
        {
            GenericClassListAdaptor <T> listAdaptor = args.adaptor as GenericClassListAdaptor <T>;
            T item = listAdaptor[args.itemIndex];

            if (listAdaptor != null)
            {
                VirtualItemsPropertyInspector virtualItemInspector = GameKitEditorWindow.GetInstance().GetPropertyInsepctor(
                    GameKitEditorWindow.TabType.VirtualItems) as VirtualItemsPropertyInspector;
                IItem[] items = virtualItemInspector.GetAffectedItems(item.ID);
                if (items.Length > 0)
                {
                    EditorUtility.DisplayDialog("Warning", "Not allowed to delete becase the item is still used by following items: " +
                                                virtualItemInspector.GetAffectedItemsWarningString(items), "OK");
                    args.Cancel = true;
                }
                else
                {
                    if (EditorUtility.DisplayDialog("Confirm to delete",
                                                    "Confirm to delete item [" + item.ID + "]?", "OK", "Cancel"))
                    {
                        args.Cancel = false;

                        if (item is UpgradeItem)
                        {
                            GameKit.Config.Upgrades.Remove((item as UpgradeItem));
                        }

                        SelectItem(null);
                        GameKitEditorWindow.GetInstance().Repaint();
                    }
                    else
                    {
                        args.Cancel = true;
                    }
                }
            }
        }
        private void OnRemoveSubworld(object sender, ItemRemovingEventArgs args)
        {
            GenericClassListAdaptor <World> listAdaptor = args.adaptor as GenericClassListAdaptor <World>;
            World world = listAdaptor[args.itemIndex];

            if (listAdaptor != null)
            {
                IItem[] items = GetAffectedItems(world.ID);
                if (items.Length > 0)
                {
                    EditorUtility.DisplayDialog("Warning", "Not allowed to delete becase the item is still used by following items: " +
                                                GetAffectedItemsWarningString(items), "OK");
                    args.Cancel = true;
                }
                else
                {
                    if (EditorUtility.DisplayDialog("Confirm to delete",
                                                    "Confirm to delete world [" + world.ID + "]?", "OK", "Cancel"))
                    {
                        args.Cancel = false;

                        (_currentDisplayItem as World).SubWorldsID.Remove(world.ID);
                        RemoveSubWorldAndSubGateRecursivity(world);

                        (_treeExplorer as WorldTreeExplorer).RemoveWorld(world);
                        ScoreTreeExplorer scoreTreeExplorer = (GameKitEditorWindow.GetInstance().GetTreeExplorer(
                                                                   GameKitEditorWindow.TabType.Scores) as ScoreTreeExplorer);
                        scoreTreeExplorer.RemoveWorld(world);
                        GameKit.Config.UpdateMapsAndTree();
                        GameKitEditorWindow.GetInstance().Repaint();
                    }
                    else
                    {
                        args.Cancel = true;
                    }
                }
            }
        }
Exemple #10
0
        protected override void DoOnExplorerSelectionChange(IItem item)
        {
            if (item == null)
            {
                _currentWorldOfScore          = null;
                _relatedVirtualItemIDProperty = null;
            }
            else
            {
                _currentWorldOfScore = GameKit.Config.FindWorldThatScoreBelongsTo(item as Score);

                string             path          = GameKitEditorWindow.GetInstance().FindScorePropertyPath(item as Score);
                SerializedProperty scoreProperty = GameKitEditorWindow.SerializedConfig.FindProperty(path);
                if (scoreProperty != null)
                {
                    _relatedVirtualItemIDProperty = scoreProperty.FindPropertyRelative("RelatedVirtualItemID");
                }
                else
                {
                    _relatedVirtualItemIDProperty = null;
                    Debug.LogError("Couldn't find score property from config [" + path + "], maybe the change is not applied yet.");
                }
            }
        }
Exemple #11
0
 private static void OpenVirutalItemEditorWindow()
 {
     GameKitEditorWindow.GetInstance();
 }
Exemple #12
0
        protected override float DoDrawItem(Rect rect, IItem item)
        {
            float yOffset = 0;
            float width   = rect.width;
            Score score   = item as Score;

            _isBasicPropertiesExpanded = EditorGUI.Foldout(new Rect(0, 0, width, 20),
                                                           _isBasicPropertiesExpanded, "Item");
            yOffset += 20;
            if (_isBasicPropertiesExpanded)
            {
                DrawIDField(new Rect(0, yOffset, width, 20), score, true, true);
                yOffset   += 20;
                score.Name = EditorGUI.TextField(new Rect(0, yOffset, width, 20), "Name", score.Name);
                yOffset   += 20;
            }
            yOffset += 20;

            EditorGUI.LabelField(new Rect(0, yOffset, 250, 20), "Belong to World",
                                 _currentWorldOfScore == null ? "NULL" : _currentWorldOfScore.ID);
            if (_currentWorldOfScore != null)
            {
                if (GUI.Button(new Rect(255, yOffset, 50, 20), "Edit"))
                {
                    WorldTreeExplorer worldTreeExplorer = (GameKitEditorWindow.GetInstance().GetTreeExplorer(
                                                               GameKitEditorWindow.TabType.Worlds) as WorldTreeExplorer);
                    GameKitEditorWindow.GetInstance().SelectTab(GameKitEditorWindow.TabType.Worlds);
                    worldTreeExplorer.SelectItem(_currentWorldOfScore);
                }
                yOffset += 20;
            }
            yOffset += 20;

            _isScorePropertiesExpanded = EditorGUI.Foldout(new Rect(0, yOffset, width, 20),
                                                           _isScorePropertiesExpanded, "Score Property");
            yOffset += 20;
            if (_isScorePropertiesExpanded)
            {
                score.EnableClamp = EditorGUI.Toggle(new Rect(0, yOffset, width, 20),
                                                     "Clamp Score", score.EnableClamp);
                yOffset += 20;
                if (score.EnableClamp)
                {
                    score.Min = EditorGUI.FloatField(new Rect(10, yOffset, width, 20),
                                                     "Mininum Value", score.Min);
                    yOffset  += 20;
                    score.Max = EditorGUI.FloatField(new Rect(10, yOffset, width, 20),
                                                     "Maximum Value", score.Max);
                    yOffset           += 20;
                    score.DefaultValue = EditorGUI.Slider(new Rect(0, yOffset, width, 20),
                                                          "Default Score", score.DefaultValue, score.Min, score.Max);
                }
                else
                {
                    score.DefaultValue = EditorGUI.FloatField(new Rect(0, yOffset, width, 20),
                                                              "Default Score", score.DefaultValue);
                }
                yOffset += 20;
                score.IsHigherBetter = EditorGUI.Toggle(new Rect(0, yOffset, width, 20),
                                                        "Is Higher Better", score.IsHigherBetter);
                yOffset += 20;
                bool isVirtualItemScore = !string.IsNullOrEmpty(score.RelatedVirtualItemID);
                isVirtualItemScore = EditorGUI.Toggle(new Rect(0, yOffset, width, 20), "Is Virtual Item Score", isVirtualItemScore);
                yOffset           += 20;
                if (isVirtualItemScore)
                {
                    if (_relatedVirtualItemIDProperty != null)
                    {
                        EditorGUI.PropertyField(new Rect(0, yOffset, width, 20), _relatedVirtualItemIDProperty,
                                                new GUIContent("Related Virtual Item"));
                        score.RelatedVirtualItemID = _relatedVirtualItemIDProperty.stringValue;
                    }
                    else
                    {
                        EditorGUI.LabelField(new Rect(0, yOffset, width, 20), "ERROR");
                    }
                    yOffset += 20;
                }
                else
                {
                    score.RelatedVirtualItemID = string.Empty;
                }
                //EditorGUI.LabelField(new Rect(0, yOffset, width, 20), "Related Virtual Item ID", score.RelatedVirtualItemID);
            }

            return(yOffset);
        }
        protected override float DoDrawItem(Rect rect, IItem item)
        {
            float   yOffset = 0;
            float   width   = rect.width;
            Mission mission = item as Mission;

            _isBasicPropertiesExpanded = EditorGUI.Foldout(new Rect(0, 0, width, 20),
                                                           _isBasicPropertiesExpanded, "Item");
            yOffset += 20;
            if (_isBasicPropertiesExpanded)
            {
                DrawIDField(new Rect(0, yOffset, width, 20), mission, true, true);
                yOffset            += 20;
                mission.Name        = EditorGUI.TextField(new Rect(0, yOffset, width, 20), "Name", mission.Name);
                yOffset            += 20;
                mission.Description = EditorGUI.TextField(new Rect(0, yOffset, width, 20), "Desription", mission.Description);
                yOffset            += 20;
                mission.BadgeIcon   = EditorGUI.ObjectField(new Rect(0, yOffset, width, 50), "Badge Icon",
                                                            mission.BadgeIcon, typeof(Texture2D), false) as Texture2D;
                yOffset += 55;
            }
            yOffset += 20;

            if (_currentWorldOfMission != null)
            {
                EditorGUI.LabelField(new Rect(0, yOffset, 250, 20), "Belong to World",
                                     _currentWorldOfMission == null ? "NULL" : _currentWorldOfMission.ID);
                if (GUI.Button(new Rect(255, yOffset, 50, 20), "Edit"))
                {
                    WorldTreeExplorer worldTreeExplorer = (GameKitEditorWindow.GetInstance().GetTreeExplorer(
                                                               GameKitEditorWindow.TabType.Worlds) as WorldTreeExplorer);
                    GameKitEditorWindow.GetInstance().SelectTab(GameKitEditorWindow.TabType.Worlds);
                    worldTreeExplorer.SelectItem(_currentWorldOfMission);
                }
                yOffset += 20;
            }
            yOffset += 20;

            UpdateGateID(mission.Gate);
            _isGatePropertiesExpanded = EditorGUI.Foldout(new Rect(0, yOffset, width, 20),
                                                          _isGatePropertiesExpanded, "Gate");
            yOffset += 20;
            if (_isGatePropertiesExpanded)
            {
                float height = _gateDrawer.CalculateHeight(mission.Gate);
                yOffset += _gateDrawer.Draw(new Rect(0, yOffset, width, height), mission.Gate);
                yOffset += 20;
            }

            UpdateRewardsID();
            _isRewardsExpanded = EditorGUI.Foldout(new Rect(0, yOffset, width, 20),
                                                   _isRewardsExpanded, "Rewards");
            yOffset += 20;
            if (_isRewardsExpanded)
            {
                float height = _listControl.CalculateListHeight(_listAdaptor);
                _listControl.Draw(new Rect(0, yOffset, width, height), _listAdaptor);
                yOffset += height;
            }

            return(yOffset);
        }