Skip to content

Commit

Permalink
Ability to set and persist screen resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
noescape00 committed Feb 1, 2022
1 parent 8865c43 commit c57f98b
Show file tree
Hide file tree
Showing 5 changed files with 500 additions and 16 deletions.
55 changes: 53 additions & 2 deletions Src/NFTWallet/Assets/Code/NFTWallet/Windows/LoginWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public class LoginWindow : WindowBase
{
public InputField MnemonicInputField, PassphraseInputField;
public Button GenerateNewMnemonicButton, LogInButton, RemovePlayerPrefsButton;
public Button GenerateNewMnemonicButton, LogInButton, RemovePlayerPrefsButton, SizeUpButton, SizeDownButton;
public Text NewMnemonicWarningText;

public Text MnemonicInputFieldPlaceholderText;
Expand All @@ -18,10 +18,26 @@ public class LoginWindow : WindowBase

private const string MnemonicKey = "MnemonicST";

private const string ResolutionKey = "ResolutionST";

private List<TargetNetwork> targetNetworks = new List<TargetNetwork>();

private TargetNetwork selectedNetwork;

private readonly List<Vector2> SupportedResolutions = new List<Vector2>()
{
new Vector2(960 ,540),
new Vector2(1024, 576),
new Vector2(1280, 720),
new Vector2(1366, 768),
new Vector2(1600, 900),
new Vector2(1920, 1080),
new Vector2(2560, 1440),
new Vector2(3840, 2160)
};

private int currentResolutionIndex = -1;

void Start()
{
targetNetworks.Add(NFTWallet.Instance.DefaultNetwork);
Expand All @@ -36,6 +52,17 @@ void Start()
NetworkDropDown.ClearOptions();
List<string> options = targetNetworks.Select(x => x.ToString()).ToList();
NetworkDropDown.AddOptions(options);

if (PlayerPrefs.HasKey(ResolutionKey))
{
currentResolutionIndex = PlayerPrefs.GetInt(ResolutionKey);
}
else
{
currentResolutionIndex = 4;
}

SetResolutionFromIndex();
}

async void Awake()
Expand All @@ -46,6 +73,24 @@ async void Awake()
this.MnemonicInputField.text = mnemonic.ToString();
});

this.SizeUpButton.onClick.AddListener(async delegate
{
if (currentResolutionIndex < SupportedResolutions.Count - 1)
{
currentResolutionIndex++;
SetResolutionFromIndex();
}
});

this.SizeDownButton.onClick.AddListener(async delegate
{
if (currentResolutionIndex > 0)
{
currentResolutionIndex--;
SetResolutionFromIndex();
}
});

NetworkDropDown.onValueChanged.AddListener(delegate (int optionNumber)
{
selectedNetwork = targetNetworks[optionNumber];
Expand All @@ -56,6 +101,7 @@ async void Awake()
bool presavedMnemonicExists = PlayerPrefs.HasKey(MnemonicKey);
bool mnemonicEntered = !string.IsNullOrEmpty(MnemonicInputField.text);

PlayerPrefs.SetInt(ResolutionKey, currentResolutionIndex);

if (!presavedMnemonicExists && !mnemonicEntered)
{
Expand Down Expand Up @@ -94,7 +140,7 @@ async void Awake()

await NFTWallet.Instance.AddKnownContractsIfMissingAsync();

MnemonicInputField.text = string.Empty;
MnemonicInputField.text = string.Empty;
});

RemovePlayerPrefsButton.onClick.AddListener(delegate
Expand All @@ -117,4 +163,9 @@ public override UniTask ShowAsync(bool hideOtherWindows = true)

return base.ShowAsync(hideOtherWindows);
}

private void SetResolutionFromIndex()
{
Screen.SetResolution((int)SupportedResolutions[currentResolutionIndex].x, (int)SupportedResolutions[currentResolutionIndex].y, false);
}
}
Loading

0 comments on commit c57f98b

Please sign in to comment.