Ejemplo n.º 1
0
        private void DrawPersistence()
        {
            PlayerStore currentPlayer     = _persistenceService.CurrentPlayer;
            string      currentPlayerName = currentPlayer?.Name;

            EditorGUI.indentLevel++;

            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(TAB_SIZE * EditorGUI.indentLevel);
            if (EditorGUILayout.DropdownButton(EditorGUIUtility.TrTextContent("Active player: " + currentPlayerName), FocusType.Keyboard))
            {
                GenericMenu playerMenu = new GenericMenu();
                foreach (PlayerStore playerStore in _persistenceService.Players)
                {
                    playerMenu.AddItem(EditorGUIUtility.TrTextContent(playerStore.Name), playerStore.Name == currentPlayerName,
                                       () => {
                        _persistenceService.ChangeActivePlayer(playerStore);
                    });
                }
                playerMenu.ShowAsContext();
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(TAB_SIZE * EditorGUI.indentLevel);
            if (GUILayout.Button("Save current player"))
            {
                _persistenceService.SaveCurrentPlayer();
            }
            if (GUILayout.Button("Delete current player"))
            {
                _persistenceService.DeleteCurrentPlayer();
            }
            EditorGUILayout.EndHorizontal();

            if (currentPlayer != null)
            {
                EditorGUILayout.LabelField("Inventory", "");
                EditorGUI.indentLevel++;
                if (currentPlayer.ItemInventory == null)
                {
                    EditorGUILayout.LabelField("Not initialized", "");
                }
                else
                {
                    UnityAction action = () => { };
                    foreach (KeyValuePair <ItemData, int> keyValuePair in currentPlayer.ItemInventory)
                    {
                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.LabelField(keyValuePair.Key.itemName, keyValuePair.Value + "");
                        if (GUILayout.Button("+"))
                        {
                            action = () => currentPlayer.AddItems(keyValuePair.Key, 1);
                        }

                        if (GUILayout.Button("-"))
                        {
                            action = () => currentPlayer.RemoveItems(keyValuePair.Key, 1);
                        }
                        EditorGUILayout.EndHorizontal();
                    }

                    action();
                }

                EditorGUI.indentLevel--;

                EditorGUILayout.LabelField("Known Songs", string.Join(", ", currentPlayer.KnownSongs));
                _learnSongToolsEnabled = EditorGUILayout.Foldout(_learnSongToolsEnabled, "Learn songs", true);
                if (_learnSongToolsEnabled)
                {
                    EditorGUI.indentLevel++;
                    foreach (string songName in _songService.GetAvailableSongNames())
                    {
                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Space(TAB_SIZE * EditorGUI.indentLevel);
                        if (GUILayout.Button("Learn " + songName + " song"))
                        {
                            currentPlayer.LearnSong(songName);
                        }

                        EditorGUILayout.EndHorizontal();
                    }
                    EditorGUI.indentLevel--;
                }

                EditorGUILayout.LabelField("Known Items", string.Join(", ", currentPlayer.KnownItems));
            }
            EditorGUI.indentLevel--;
        }