Ejemplo n.º 1
0
        public static void Push(Action <bool> OnPushed = null)
        {
            var address = Resources.Load <PaymentsAppSettings>("PaymentsAppSettings").ServiceURL;

            HTTPEditor.SendPost(address + "/SetApp/" + CurrentConfig.AppId, JsonUtility.ToJson(CurrentConfig),
                                (isSuccess, responseBody) => {
                if (!isSuccess)
                {
                    lastMessage = "HTTP Error.";
                    OnPushed?.Invoke(false);
                    return;
                }

                var response = JsonUtility.FromJson <GeneralResponse>(responseBody);
                if (response == null || response.error > 0)
                {
                    appIdDoesntExist = true;
                    lastMessage      = response != null ? response.message : "HTTP Error";
                    OnPushed?.Invoke(false);
                }
                else
                {
                    appIdDoesntExist = false;
                    lastMessage      = response.message;
                    OnPushed?.Invoke(true);
                }
            });
        }
        private void UpdateTemplate()
        {
            Debug.Log("Updating template " + CurrentTemplateId);

            var config  = PaymentsManager.CurrentConfig;
            var address = Resources.Load <PaymentsAppSettings>("PaymentsAppSettings").ServiceURL;

            var templateData = JsonUtility.ToJson(CurrentTemplate, true);

            HTTPEditor.SendPost(address + "/SetApp/" + config.AppId + "/" + CurrentTemplateId, templateData, (isSuccess, responseData) => {
                if (!isSuccess)
                {
                    Debug.LogError("Failed to update template.");
                }
                else
                {
                    Debug.Log(responseData);
                }
            });
        }
Ejemplo n.º 3
0
        private void OnGUI()
        {
            GUILayout.Label("Templates");

            GUILayout.Label(lastMessage);

            if (newTemplateCreator)
            {
                if (duplicationList.Length > 0)
                {
                    GUILayout.Label("You can select a template from the currents to duplicate.");
                    templateIndex = EditorGUILayout.Popup(templateIndex, duplicationList);
                }

                newTemplateName = GUILayout.TextField(newTemplateName);
                if (GUILayout.Button("Create template"))
                {
                    newTemplateCreator = false;
                    // Send this new template to the service.

                    var address = Resources.Load <PaymentsAppSettings>("PaymentsAppSettings").ServiceURL;

                    if (templateIndex >= 1)
                    { // duplication is required.
                        if (templateIndex < duplicationList.Length)
                        {
                            // First download the target template.

                            HTTPEditor.SendGet(address + "/GetApp/" + paymentsConfig.AppId + "/" + duplicationList[templateIndex],
                                               (isError, responseBody) =>
                            {
                                Debug.Log(responseBody);

                                // Save the new template.
                                HTTPEditor.SendPost(address + "/SetApp/" + paymentsConfig.AppId + "/" + newTemplateName, responseBody,
                                                    (_isSuccess, _responseBody) =>
                                {
                                    if (!!!_isSuccess)
                                    {
                                        lastMessage = "HTTP Error";
                                    }
                                    else
                                    {
                                        RefreshWithResponse(_responseBody);
                                    }
                                });
                            });
                        }
                    }
                    else
                    {
                        var body = "{ }";
                        // Create empty template.
                        // Save the new template.
                        HTTPEditor.SendPost(address + "/SetApp/" + paymentsConfig.AppId + "/" + newTemplateName, body,
                                            (_isSuccess, _responseBody) =>
                        {
                            Debug.Log(_responseBody);

                            if (!!!_isSuccess)
                            {
                                lastMessage = "HTTP Error";
                            }
                            else
                            {
                                RefreshWithResponse(_responseBody);
                            }
                        });
                    }
                }
                return;
            }

            if (paymentsConfig.IsUpdateAvailable)
            {
                // Show update button.
                if (GUILayout.Button("Save config."))
                {
                    paymentsConfig.IsUpdateAvailable = false;

                    File.WriteAllText(PaymentsManager.ConfigPath, JsonUtility.ToJson(paymentsConfig, true));

                    // Load asset database again.
                    AssetDatabase.Refresh();
                }
            }

            // Template selection enabled.
            if (paymentsConfig.Templates != null && paymentsConfig.Templates.Length > 0)
            {
                templateIndex = EditorGUILayout.Popup(templateIndex, paymentsConfig.Templates);
            }
            else
            {
                GUILayout.Label("No templates on this app yet.");
            }

            if (templateIndex >= 0)
            {
                // template options.
                if (GUILayout.Button("Edit Template"))
                {
                    TemplateEditor.Init(paymentsConfig.Templates[templateIndex], (isSuccess, Message) => {
                        lastMessage = "Edit Template Result  => " + isSuccess + " Message: " + Message;
                        Debug.Log(lastMessage);
                    });
                }

                if (GUILayout.Button("Set as default"))
                {
                    if (EditorUtility.DisplayDialog("Beware!", "Are you sure you want to assign this template as defauşt?", "Yes", "Cancel"))
                    {
                        paymentsConfig.Template = paymentsConfig.Templates[templateIndex];
                        // Update on server.
                        PaymentsManager.Push((isPushed) => {
                            lastMessage = "Pushed => " + isPushed;
                            Debug.Log(lastMessage);
                        });
                    }
                }

                if (GUILayout.Button("DeleteTemplate"))
                {
                    if (EditorUtility.DisplayDialog("Beware!", "You are about to remove this template. Cannot be undo.", "Go ahead", "Cancel"))
                    {
                        var address = Resources.Load <PaymentsAppSettings>("PaymentsAppSettings").ServiceURL;

                        HTTPEditor.SendGet(address + "/RemoveTemplate/" + paymentsConfig.AppId + "/" + paymentsConfig.Templates[templateIndex],
                                           (isSuccess, _responseBody) => {
                            lastMessage = _responseBody;
                            Debug.Log(lastMessage);
                            if (isSuccess)
                            {
                                RefreshWithResponse(_responseBody);
                            }
                        }
                                           );
                    }
                }
            }

            GUILayout.Space(20);
            if (GUILayout.Button("Create new template"))
            {
                newTemplateName = "NewTemplate";
                if (paymentsConfig.Templates != null && paymentsConfig.Templates.ToList().Find(x => x.Equals(newTemplateName)) != null)
                {
                    int i = 1;
                    while (i < 99)
                    {
                        var targetName = newTemplateName + "(" + i + ")";
                        if (paymentsConfig.Templates.ToList().Find(x => x.Equals(targetName)) == null)
                        {
                            newTemplateName = targetName;
                            break;
                        }

                        i++;
                    }
                }

                if (paymentsConfig.Templates == null || paymentsConfig.Templates.Length == 0)
                {
                    duplicationList = new string[0];
                }
                else
                {
                    var tList = paymentsConfig.Templates.ToList();
                    tList.Insert(0, "Select a template.");
                    duplicationList = tList.ToArray();
                }


                newTemplateCreator = true;
            }
        }
Ejemplo n.º 4
0
        void OnGUI()
        {
            if (CurrentConfig == null)
            {
                Init(); // Code refresh probably. Redo.
                return;
            }

            GUILayout.Label("Base Settings", EditorStyles.boldLabel);
            CurrentConfig._AppId = EditorGUILayout.TextField("AppId", CurrentConfig._AppId);

            if (!dataPulled)
            {
                // pull the latest.
                if (GUILayout.Button("Pull the latest config"))
                {
                    Pull();
                }
            }
            else
            {
                // pull the latest.
                if (GUILayout.Button("Push latest config."))
                {
                    // HTTPRequester Download.
                }
            }

            GUILayout.Label(lastMessage);

            if (appIdDoesntExist)
            {
                if (GUILayout.Button("Create new app with this ID"))
                {
                    var address = Resources.Load <PaymentsAppSettings>("PaymentsAppSettings").ServiceURL;

                    var appId = CurrentConfig.AppId;
                    CurrentConfig       = new PaymentsConfig();
                    CurrentConfig.AppId = appId;

                    HTTPEditor.SendPost(address + "/SetApp/" + CurrentConfig.AppId, JsonUtility.ToJson(CurrentConfig),
                                        (isSuccess, responseBody) => {
                        if (!isSuccess)
                        {
                            lastMessage = "HTTP Error.";
                            return;
                        }

                        var response = JsonUtility.FromJson <GeneralResponse>(responseBody);
                        if (response == null || response.error > 0)
                        {
                            appIdDoesntExist = true;

                            lastMessage = response != null ? response.message : "HTTP Error";
                        }
                        else
                        {
                            appIdDoesntExist = false;
                            lastMessage      = response.message;
                        }
                    });
                }
            }

            if (templatesEnabled)
            {
                if (GUILayout.Button("Open templates window"))
                {
                    TemplateManager.Init(CurrentConfig);
                }
            }
        }