Skip to content

Commit

Permalink
style: MS coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
yapetrichka committed Oct 22, 2022
1 parent 5e0512b commit e902adb
Show file tree
Hide file tree
Showing 16 changed files with 348 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Editor/Assets.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Editor/Assets/Layouts.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions Editor/Assets/Layouts/KeystoreWindow.uxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../../../UIElementsSchema/UIElements.xsd" editor-extension-mode="True">
<Style src="project://database/Packages/com.dreamcode.mobile.android-keystore/Editor/Assets/Styles/KeystoreWindow.uss?fileID=7433441132597879392&amp;guid=4c0697299499c2746bd838d8d7bc9c29&amp;type=3#KeystoreWindow" />
<ui:VisualElement name="Container" style="height: 100%; color: rgb(255, 255, 255); background-color: rgb(255, 255, 255); justify-content: space-around; flex-grow: 0; align-items: stretch;">
<ui:Label text="Project Keystore" display-tooltip-when-elided="true" name="KeystoreLabel" style="color: rgb(118, 118, 118); -unity-font-style: bold; -unity-text-align: upper-center; font-size: 24px; padding-right: 0; padding-left: 0; padding-top: 0; width: auto; white-space: normal;" />
<ui:TextField picking-mode="Ignore" label="Path .keystore" text="path.keystore" multiline="false" name="KeystorePath" class="keystore-text-field" style="padding-top: 0; font-size: 18px;" />
<ui:TextField picking-mode="Ignore" label="Password" text="password" multiline="false" name="KeystorePass" class="keystore-text-field" style="flex-direction: column; flex-wrap: nowrap; justify-content: flex-start; font-size: 18px; color: rgb(255, 255, 255); background-color: rgb(255, 255, 255); -unity-font-style: bold; -unity-text-align: upper-left; width: auto; padding-left: 10%; padding-right: 10%; padding-top: 0;" />
<ui:Label text="Project Key" display-tooltip-when-elided="true" name="KeyLabel" style="color: rgb(118, 118, 118); -unity-font-style: bold; -unity-text-align: upper-center; font-size: 24px; padding-right: 0; padding-left: 0; padding-top: 0; white-space: normal;" />
<ui:TextField picking-mode="Ignore" label="Alias" text="alias" multiline="false" name="KeyaliasName" class="keystore-text-field" style="flex-direction: column; flex-wrap: nowrap; justify-content: flex-start; font-size: 18px; color: rgb(255, 255, 255); background-color: rgb(255, 255, 255); -unity-font-style: bold; -unity-text-align: upper-left; width: auto; padding-left: 10%; padding-right: 10%; padding-top: 0;" />
<ui:TextField picking-mode="Ignore" label="Password" text="password" multiline="false" name="KeyaliasPass" class="keystore-text-field" style="flex-direction: column; flex-wrap: nowrap; justify-content: flex-start; font-size: 18px; color: rgb(255, 255, 255); background-color: rgb(255, 255, 255); -unity-font-style: bold; -unity-text-align: upper-left; width: auto; padding-left: 10%; padding-right: 10%; padding-top: 0;" />
<ui:Button text="Save" display-tooltip-when-elided="true" name="SaveBtn" class="save save-button" style="border-left-width: 0; border-right-width: 0; border-top-width: 0; border-bottom-width: 0; margin-top: 0; margin-bottom: 0; -unity-font-style: bold; bottom: auto; top: auto; flex-shrink: 0; flex-grow: 0;" />
</ui:VisualElement>
</ui:UXML>
10 changes: 10 additions & 0 deletions Editor/Assets/Layouts/KeystoreWindow.uxml.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Editor/Assets/Styles.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions Editor/Assets/Styles/KeystoreWindow.uss
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
.save-button {
background-color: rgb(26, 115, 232);
color: rgb(255, 255, 255);
margin-right: 20%;
margin-left: 20%;
margin-bottom: 0;
margin-top: 4%;
height: 12%;
border-top-left-radius: 16px;
border-bottom-left-radius: 16px;
border-top-right-radius: 16px;
border-bottom-right-radius: 16px;
font-size: 18px;
}

.save-button:hover {
background-color: rgb(73, 153, 231);
}

.keystore-text-field {
flex-direction: column;
flex-wrap: nowrap;
justify-content: flex-start;
font-size: 14px;
color: rgb(255, 255, 255);
background-color: rgb(255, 255, 255);
-unity-font-style: bold;
-unity-text-align: upper-left;
width: auto;
padding-left: 10%;
padding-right: 10%;
padding-top: 20px;
}

.keystore-text-field > .unity-base-field__label {
color: rgb(118, 118, 118);
}

.keystore-text-field > .unity-base-field__input {
background-color: rgb(232, 232, 232);
color: rgb(32, 33, 36);
border-left-color: rgb(204, 204, 204);
border-right-color: rgb(204, 204, 204);
border-top-color: rgb(204, 204, 204);
border-bottom-color: rgb(204, 204, 204);
}
11 changes: 11 additions & 0 deletions Editor/Assets/Styles/KeystoreWindow.uss.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions Editor/AutoKeystore.Editor.asmdef
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "DreamCode.AutoKeystore.Editor",
"rootNamespace": "",
"references": [],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}
7 changes: 7 additions & 0 deletions Editor/AutoKeystore.Editor.asmdef.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Editor/Configuration.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions Editor/Configuration/KeystorePreprocess.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using UnityEditor.Build;
using UnityEditor.Build.Reporting;

namespace DreamCode.AutoKeystore.Editor.Configuration
{
internal class KeystorePreprocess : IPreprocessBuildWithReport
{
public int callbackOrder => 0;

public void OnPreprocessBuild(BuildReport report)
{
KeystoreSettings.Load();
}
}
}
11 changes: 11 additions & 0 deletions Editor/Configuration/KeystorePreprocess.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 52 additions & 0 deletions Editor/KeystoreSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using UnityEditor;
using UnityEngine;

namespace DreamCode.AutoKeystore.Editor
{
internal static class KeystoreSettings
{
public static string Name;
public static string Password;
public static string AliasName;
public static string AliasPassword;
private const string KeystoreExt = ".keystore";

public static void Load()
{
Name = EditorPrefs.GetString(
$"{PlayerSettings.applicationIdentifier}-{nameof(KeystoreSettings)}-{nameof(Name)}");
Password = EditorPrefs.GetString(
$"{PlayerSettings.applicationIdentifier}-{nameof(KeystoreSettings)}-{nameof(Password)}");
AliasName = EditorPrefs.GetString(
$"{PlayerSettings.applicationIdentifier}-{nameof(KeystoreSettings)}-{nameof(AliasName)}");
AliasPassword =
EditorPrefs.GetString(
$"{PlayerSettings.applicationIdentifier}-{nameof(KeystoreSettings)}-{nameof(AliasPassword)}");
if (EditorUserBuildSettings.activeBuildTarget != BuildTarget.Android)
return;
PlayerSettings.Android.keystoreName = Name + KeystoreExt;
PlayerSettings.Android.keystorePass = Password;
PlayerSettings.Android.keyaliasName = AliasName;
PlayerSettings.Android.keyaliasPass = AliasPassword;
}

public static void Save(string name, string password, string aliasName, string aliasPassword)
{
EditorPrefs.SetString($"{PlayerSettings.applicationIdentifier}-{nameof(KeystoreSettings)}-{nameof(Name)}",
name);
EditorPrefs.SetString(
$"{PlayerSettings.applicationIdentifier}-{nameof(KeystoreSettings)}-{nameof(Password)}", password);
EditorPrefs.SetString(
$"{PlayerSettings.applicationIdentifier}-{nameof(KeystoreSettings)}-{nameof(AliasName)}", aliasName);
EditorPrefs.SetString(
$"{PlayerSettings.applicationIdentifier}-{nameof(KeystoreSettings)}-{nameof(AliasPassword)}",
aliasPassword);
if (EditorUserBuildSettings.activeBuildTarget != BuildTarget.Android)
return;
PlayerSettings.Android.keystoreName = name + KeystoreExt;
PlayerSettings.Android.keystorePass = password;
PlayerSettings.Android.keyaliasName = aliasName;
PlayerSettings.Android.keyaliasPass = aliasPassword;
}
}
}
11 changes: 11 additions & 0 deletions Editor/KeystoreSettings.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

114 changes: 114 additions & 0 deletions Editor/UI/KeystoreEditorWindow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;

namespace DreamCode.AutoKeystore.Editor.UI
{
internal class KeystoreEditorWindow : EditorWindow
{
private static readonly Vector2 s_windowMinSize = new(200, 380);
private const string PackagePath = "Packages/com.dreamcode.mobile.android-keystore";
private const string AssetsPath = PackagePath + "/Editor/Assets";
private const string LayoutsPath = AssetsPath + "/Layouts";
private const string StylesPath = AssetsPath + "/Styles";
private const string WindowLayoutPath = LayoutsPath + "/KeystoreWindow.uxml";
private TextField _keystoreName;
private TextField _keystorePass;
private TextField _keyaliasName;
private TextField _keyaliasPass;

[MenuItem("DreamCode/Android/AutoKeystore")]
internal static void ShowWindow()
{
var window = GetWindow<KeystoreEditorWindow>();
window.titleContent.text = nameof(AutoKeystore);
window.minSize = s_windowMinSize;
}

private void CreateGUI()
{
var visualTree = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(WindowLayoutPath);
visualTree.CloneTree(rootVisualElement);
SetupWindowLayout();
LoadSettings();
RegisterListeners();
}

private void OnDisable()
{
RemoveListeners();
}

private void RegisterListeners()
{
rootVisualElement.Q<Button>("SaveBtn").clicked += OnSaveBtnClicked;
_keystorePass.RegisterCallback<FocusInEvent>(OnKeystorePassFocusIn);
_keystorePass.RegisterCallback<FocusOutEvent>(OnKeystorePassFocusOut);
_keyaliasPass.RegisterCallback<FocusInEvent>(OnKeyaliasPassFocusIn);
_keyaliasPass.RegisterCallback<FocusOutEvent>(OnKeyaliasPassFocusOut);
}

private void RemoveListeners()
{
rootVisualElement.Q<Button>("SaveBtn").clicked -= OnSaveBtnClicked;
_keystorePass.UnregisterCallback<FocusInEvent>(OnKeystorePassFocusIn);
_keystorePass.UnregisterCallback<FocusOutEvent>(OnKeystorePassFocusOut);
_keyaliasPass.UnregisterCallback<FocusInEvent>(OnKeyaliasPassFocusIn);
_keyaliasPass.UnregisterCallback<FocusOutEvent>(OnKeyaliasPassFocusOut);
}

private void OnSaveBtnClicked()
{
SaveSettings();
Close();
}

private void OnKeystorePassFocusIn(FocusInEvent e)
{
_keystorePass.isPasswordField = false;
}

private void OnKeystorePassFocusOut(FocusOutEvent evt)
{
_keystorePass.isPasswordField = true;
}

private void OnKeyaliasPassFocusIn(FocusInEvent evt)
{
_keyaliasPass.isPasswordField = false;
}

private void OnKeyaliasPassFocusOut(FocusOutEvent evt)
{
_keyaliasPass.isPasswordField = true;
}

private void SetupWindowLayout()
{
_keystoreName = rootVisualElement.Q<TextField>("KeystorePath");
_keystorePass = rootVisualElement.Q<TextField>("KeystorePass");
_keystorePass.isPasswordField = true;
_keyaliasName = rootVisualElement.Q<TextField>("KeyaliasName");
_keyaliasPass = rootVisualElement.Q<TextField>("KeyaliasPass");
_keyaliasPass.isPasswordField = true;
}

private void LoadSettings()
{
KeystoreSettings.Load();
_keystoreName.value = KeystoreSettings.Name;
_keystorePass.value = KeystoreSettings.Password;
_keyaliasName.value = KeystoreSettings.AliasName;
_keyaliasPass.value = KeystoreSettings.AliasPassword;
}

private void SaveSettings()
{
var keystoreName = _keystoreName.value;
var keystorePass = _keystorePass.value;
var keyaliasName = _keyaliasName.value;
var keyaliasPass = _keyaliasPass.value;
KeystoreSettings.Save(keystoreName, keystorePass, keyaliasName, keyaliasPass);
}
}
}
11 changes: 11 additions & 0 deletions Editor/UI/KeystoreEditorWindow.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e902adb

Please sign in to comment.