private bool LoadProfiles()
 {
     profileDefs = ProfileDef.GetAll();
     if (profileDefs.Length > 0)
     {
         // Sort the loaded profiledefs so the current profile is at index 0;
         var index = GetIndexOfCurrent();
         Debug.Log($"Index is {index}");
         if (index != -1)
         {
             var p = new ProfileDef[profileDefs.Length];
             p[0] = profileDefs[index];
             for (int i = 0; i < profileDefs.Length; i++)
             {
                 if (i < index)
                 {
                     p[i + 1] = profileDefs[i];
                 }
                 else if (i > index)
                 {
                     p[i + 1] = profileDefs[i - 1];
                 }
             }
             profileDefs = p;
         }
     }
     return(profileDefs.Length > 0);
 }
 private void SetProfile(ProfileDef profileDef, Profile profile)
 {
     Debug.Log("Set profile");
     currentDef     = profileDef;
     currentProfile = profile;
     localName      = currentDef.Name;
     localNote      = currentDef.Note;
     CheckProfileExists(currentDef);
 }
 private void UpdateDataModel()
 {
     ProfileDef.GetActive((s, def, profile) =>
     {
         SetProfile(def, profile);
         LoadProfiles();
         ready = true;
     });
 }
 private void CheckProfileExists(ProfileDef profileDef)
 {
     profileExists = ProfileExistState.INDETERMINATE;
     profileDef.CheckExists((b =>
     {
         if (b)
         {
             profileExists = ProfileExistState.EXISTS;
             profileDef.Save();
         }
         else
         {
             profileExists = ProfileExistState.DOES_NOT_EXIST;
         }
         ready = true;
     }));
 }
        private void ProfileGui(ProfileDef profileDef)
        {
            SetWindowSizeVars();

            using (var h = new EditorGUILayout.HorizontalScope())
            {
                EditorGUILayout.LabelField("Profile", EditorStyles.boldLabel);
                DrawSpriteForProfileExistState();
            }

            // how to deal w/ the checkexists event...
            using (var h = new EditorGUILayout.HorizontalScope())
            {
                EditorGUILayout.LabelField($"Public key: ", EditorStyles.miniLabel, GUILayout.Width(Normalize(96)));
                EditorGUILayout.SelectableLabel(profileDef.PublicKey, EditorStyles.miniTextField);
            };

            using (var h = new EditorGUILayout.HorizontalScope())
            {
                showPrivateKey = EditorGUILayout.Toggle(showPrivateKey, GUILayout.Width(Normalize(26)));
                EditorGUILayout.LabelField($"Private key: ", EditorStyles.miniLabel, GUILayout.Width(Normalize(70)));
                if (showPrivateKey)
                {
                    EditorGUILayout.SelectableLabel(profileDef.PrivateKey, EditorStyles.miniTextField);
                }
                else
                {
                    EditorGUILayout.SelectableLabel("(hidden)", EditorStyles.miniTextField);
                }
            };
            using (var h = new EditorGUILayout.HorizontalScope())
            {
                EditorGUILayout.LabelField("Address: ", EditorStyles.miniBoldLabel, GUILayout.Width(Normalize(96)));
                EditorGUILayout.SelectableLabel(profileDef.Address, EditorStyles.miniTextField);
            };
            using (var h = new EditorGUILayout.HorizontalScope())
            {
                EditorGUILayout.LabelField("Name: ", EditorStyles.miniBoldLabel, GUILayout.Width(Normalize(96)));
                //if (profileExists == ProfileExistState.DOES_NOT_EXIST) nameInput = EditorGUILayout.TextField(nameInput, EditorStyles.miniTextField);
                //else EditorGUILayout.SelectableLabel(profileDef.Name, EditorStyles.miniTextField);
                localName = EditorGUILayout.TextField(localName);
            };

            using (var h = new EditorGUILayout.HorizontalScope())
            {
                EditorGUILayout.LabelField("Notes: ", EditorStyles.miniBoldLabel, GUILayout.Width(Normalize(96)));
                localNote = EditorGUILayout.TextArea(localNote);
            }

            if (localName != profileDef.Name || localNote != profileDef.Note)
            {
                if (GUILayout.Button("Save", GUILayout.Width(Normalize(24))))
                {
                    var index  = GetIndexOfCurrent();
                    var newDef = new ProfileDef(currentDef.PrivateKey, currentDef.PublicKey, localName, currentDef.Address, localNote);
                    currentDef.Delete();
                    newDef.Save();
                    profileDefs[index] = newDef;
                    SetProfile(newDef, currentProfile);
                }
            }

            if (profileExists == ProfileExistState.DOES_NOT_EXIST)
            {
                if (GUILayout.Button("Register profile"))
                {
                    profileExists = ProfileExistState.INDETERMINATE;
                    PylonsService.instance.RegisterProfile(nameInput, (s, e) => {
                        UpdateDataModel();
                    });
                }
            }

            if (currentProfile != null)
            {
                EditorGUILayout.LabelField($"Pylons: {currentProfile.GetCoin("pylon")}", EditorStyles.miniBoldLabel);

                using (var v = new EditorGUILayout.VerticalScope())
                {
                    EditorGUILayout.LabelField("Other coins", EditorStyles.miniBoldLabel);
                    foreach (var coin in currentProfile.Coins)
                    {
                        if (coin.Denom != "pylon")
                        {
                            EditorGUILayout.LabelField($"{coin.Denom}: {coin.Amount}", EditorStyles.miniLabel);
                        }
                    }
                }
                //TODO: also display items
            }
        }
 private void SetProfile(ProfileDef profileDef) => SetProfile(profileDef, null);