示例#1
0
    private static void RenderFileList(IDialogEditorContext context)
    {
        var buttonSkin = new GUIStyle(GUI.skin.button);

        EditorGUILayout.BeginVertical();

        buttonSkin.alignment = TextAnchor.MiddleLeft;
        buttonSkin.padding   = new RectOffset(10, 10, 10, 10);

        _scrollPosition = EditorGUILayout.BeginScrollView(_scrollPosition, false, false);
        var selected = GUILayout.SelectionGrid(
            _selectedItem,
            context.FileList.Files.Select(f => new GUIContent(f.Name)).ToArray(),
            6,
            buttonSkin,
            GUILayout.MaxWidth(500),
            GUILayout.ExpandWidth(true));

        EditorGUILayout.EndScrollView();

        if (_selectedItem != selected)
        {
            _selectedItem     = selected;
            context.ExcelFile = GetExcelFile(context);
            context.ViewState = DialogViewState.FileGridDataView;
        }

        EditorGUILayout.EndVertical();
    }
示例#2
0
 private static void RenderButtons(IDialogEditorContext context)
 {
     EditorGUILayout.BeginHorizontal();
     SaveButton(context);
     UpdateButton(context);
     EditorGUILayout.EndHorizontal();
 }
示例#3
0
 private static void RenderFilesNotLoaded(IDialogEditorContext context)
 {
     EditorGUILayout.BeginVertical();
     EditorGUILayout.LabelField("No files loaded, possibly you need to connect to the service");
     if (GUILayout.Button("Go to service connection"))
     {
         context.ViewState = DialogViewState.ConnectView;
     }
     EditorGUILayout.EndVertical();
 }
示例#4
0
 private static void RenderNoFileSelected(IDialogEditorContext context)
 {
     EditorGUILayout.BeginVertical();
     EditorGUILayout.LabelField("No file selected, select one file before trying to check its content");
     if (GUILayout.Button("Go to file selection"))
     {
         context.ViewState = DialogViewState.FileSelectionView;
     }
     EditorGUILayout.EndVertical();
 }
示例#5
0
 private static bool CanSetCode(IDialogEditorContext context)
 {
     if (
         string.IsNullOrEmpty(context.Code) ||
         string.IsNullOrEmpty(context.ClientId) ||
         string.IsNullOrEmpty(context.ClientSecret))
     {
         return(false);
     }
     return(true);
 }
示例#6
0
 public static void OnGui(IDialogEditorContext context)
 {
     if (context.ExcelFile == null)
     {
         RenderNoFileSelected(context);
     }
     else
     {
         RenderSheetList(context.ExcelFile);
         RenderTable(context.ExcelFile.Sheets[_selectedSheet]);
         RenderButtons(context);
     }
 }
示例#7
0
 private static void UpdateButton(IDialogEditorContext context)
 {
     GUI.enabled = Selection.activeObject is LocalizedTexts;
     if (GUILayout.Button("Update"))
     {
         var sheet         = context.ExcelFile.Sheets[_selectedSheet];
         var localizedText = Selection.activeObject as LocalizedTexts;
         PopulateLocalizedTexts(localizedText, sheet);
         EditorUtility.SetDirty(localizedText);
         AssetDatabase.SaveAssets();
     }
     GUI.enabled = true;
 }
示例#8
0
 public static void OnGui(IDialogEditorContext context)
 {
     if (context.FileList == null)
     {
         RenderFilesNotLoaded(context);
     }
     else if (context.FileList.Files.Length == 0)
     {
         RenderEmptyFileList(context);
     }
     else
     {
         RenderFileList(context);
     }
 }
    public static void OnGui(IDialogEditorContext context)
    {
        EditorGUILayout.BeginVertical();

        context.ClientId = EditorGUILayout.TextField("Client ID", context.ClientId);

        GUI.enabled = !string.IsNullOrEmpty(context.ClientId);
        if (GUILayout.Button("Connect"))
        {
            GoogleApi.RequestCodeOnBrowser(context.ClientId);
            context.ViewState = DialogViewState.CodeRequestView;
        }
        GUI.enabled = true;

        EditorGUILayout.EndVertical();
    }
示例#10
0
    public static void OnGui(IDialogEditorContext context)
    {
        EditorGUILayout.BeginVertical();

        context.Code         = EditorGUILayout.TextField("Code", context.Code);
        context.ClientId     = EditorGUILayout.TextField("Client Id", context.ClientId);
        context.ClientSecret = EditorGUILayout.TextField("Client secret", context.ClientSecret);

        GUI.enabled = CanSetCode(context);
        if (GUILayout.Button("Set code"))
        {
            context.Token     = GoogleApi.GetToken(context.Code, context.ClientId, context.ClientSecret);
            context.FileList  = GetFileList(context.Token);
            context.ViewState = DialogViewState.FileSelectionView;
        }
        GUI.enabled = true;

        EditorGUILayout.EndVertical();
    }
示例#11
0
    private static ExcelFile GetExcelFile(IDialogEditorContext context)
    {
        var fileId = context.FileList.Files[_selectedItem].Id;
        var model  = GoogleApi.GetSheets(context.Token, fileId);

        return(new ExcelFile()
        {
            Sheets = model.sheets.Select(sheet =>
            {
                var sheetName = sheet.properties.title;
                var sheetValues = GoogleApi.GetValuesInSheet(context.Token, fileId, sheetName);
                return new ExcelSheet()
                {
                    Name = sheet.properties.title,
                    Data = sheetValues
                };
            })
                     .ToArray()
        });
    }
示例#12
0
    private static void SaveButton(IDialogEditorContext context)
    {
        GUI.enabled = false;
        var path = default(string);

        if (Selection.activeObject != null)
        {
            path        = AssetDatabase.GetAssetPath(Selection.activeObject);
            GUI.enabled = Directory.Exists(path);
        }

        if (GUILayout.Button("Save"))
        {
            var localized = ScriptableObject.CreateInstance <LocalizedTexts>();
            var sheet     = context.ExcelFile.Sheets[_selectedSheet];
            PopulateLocalizedTexts(localized, sheet);
            AssetDatabase.CreateAsset(localized, path + "/Localized Texts.asset");
        }
        GUI.enabled = true;
    }
示例#13
0
 private static void RenderEmptyFileList(IDialogEditorContext context)
 {
     EditorGUILayout.BeginVertical();
     EditorGUILayout.LabelField("No files found, create some dialog files and try again");
     EditorGUILayout.EndVertical();
 }