Skip to content

Commit

Permalink
feat: settings window updates
Browse files Browse the repository at this point in the history
  • Loading branch information
saszer committed May 26, 2022
1 parent e0b460c commit 6fc2e9a
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 5 deletions.
52 changes: 48 additions & 4 deletions Editor/NFTPortSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class NFTPortSettings : EditorWindow
private static bool windowopen = false;
private bool ranLatestrel = false;
PkgJson releasedPkgJson = null;
static private bool NFTPortStarted;
[MenuItem("NFTPort/Home")]
public static void ShowWindow()
{
Expand All @@ -38,6 +39,25 @@ static void RegisteredPackagesEventHandler(PackageRegistrationEventArgs packageR
ReadFromUserPrefs();
}

[InitializeOnLoad]
public class Startup
{
static Startup()
{
EditorApplication.update += AfterLoad;
}

static void AfterLoad()
{
NFTPortStarted = SessionState.GetBool("NFTPortStarted", false);
if(!NFTPortStarted)
{
ReadFromUserPrefs();
SessionState.SetBool("NFTPortStarted", true);
}
}
}

void OnGUI()
{
Texture banner = Resources.Load<Texture>("banner");
Expand Down Expand Up @@ -116,12 +136,27 @@ void OnGUI()

}

private bool firstload = true;

void OnEnable()
{
if(!windowopen)
ReadFromUserPrefs();
if (!windowopen)
{
if (!firstload)
{
firstload = false;
return;

}
else
{
ReadFromUserPrefs();
}

}
windowopen = true;
ranLatestrel = false;

}

private void OnDisable()
Expand All @@ -137,7 +172,7 @@ public override void SaveChanges()

static void ShowHomeWindow()
{
if(myAPIString != PortConstants.DefaultAPIKey || windowopen)
if(windowopen)
return;

NFTPortSettings win = GetWindow(WindowType, false, PortConstants.HomeWindowName, true) as NFTPortSettings;
Expand Down Expand Up @@ -201,12 +236,21 @@ static void UserStats()
userModel = null;
User_Settings
.Initialize(true)
.OnError(usermodel=> StatsErrore())
.OnComplete(usermodel=> userModel = usermodel)
.Run();
}

static void StatsErrore()
{
if (!windowopen && !APIkeyOk())
{
ShowHomeWindow();
}
}


bool APIkeyOk()
static bool APIkeyOk()
{
if (userModel == null)
{
Expand Down
8 changes: 7 additions & 1 deletion Runtime/Internal/User_Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,13 @@ private void OnEnable()
/// <param name="destroyAtEnd"> Optional bool parameter can set to false to avoid Spawned GameObject being destroyed after the Api process is complete. </param>
public static User_Settings Initialize(bool destroyAtEnd = true)
{
var _this = new GameObject("Port Initialize | Delete:" + destroyAtEnd).AddComponent<User_Settings>();
string name = "Port Initialize | Delete:";
var existing = (GameObject.Find(name + destroyAtEnd));
if (existing != null)
{
return existing.GetComponent<User_Settings>();
}
var _this = new GameObject(name + destroyAtEnd).AddComponent<User_Settings>();
_this.destroyAtEnd = destroyAtEnd;
_this.onEnable = false;
_this.debugErrorLog = false;
Expand Down

0 comments on commit 6fc2e9a

Please sign in to comment.