void Update()
    {
        if (Input.GetKey(KeyCode.Escape))
        {
            ModalDialog.ShowSimpleModal(ModalDialog.Mode.ConfirmCancel,
                                        headerText: "Quit?",
                                        bodyText: "Are you sure you want to quit?",
                                        callback: (ModalDialog.Response response) =>
            {
                switch (response)
                {
                case ModalDialog.Response.Confirm:
                    Application.Quit();
                    break;

                case ModalDialog.Response.Cancel:
                    //Do Nothing
                    break;

                case ModalDialog.Response.Accept:
                default:
                    Debug.LogError($"Unexpected ModalDialog.Response: {response}");
                    break;
                }
            });
        }
    }
        string IStringParameterTemplate.GetValue(int stepNumber)
        {
            try
            {
                return(scriptObject.ExecuteFunction <string>("GetValue", context, stepNumber));
            }
            catch (ScriptRuntimeException excp)
            {
                UnityEngine.Debug.LogError($"Runtime Error: \"GetValue\" failed with error: {excp.Message}.");

                ModalDialog.ShowSimpleModal(ModalDialog.Mode.Accept,
                                            headerText: "Runtime Error",
                                            bodyText: $"Runtime Error: \"GetValue\" failed with error: {excp.Message}.");
            }
            catch (Exception excp)
            {
                UnityEngine.Debug.LogError($"Error: \"GetValue\" failed with error: {excp.Message}.");

                ModalDialog.ShowSimpleModal(ModalDialog.Mode.Accept,
                                            headerText: "Error",
                                            bodyText: $"Error: \"GetValue\" failed with error: {excp.Message}.");
            }

            return("");
        }
        double ISimpleDoubleStepTemplate.GetPartialValue(double stepNumber)
        {
            try
            {
                return(scriptObject.ExecuteFunction <double>("CalculateThreshold", context, stepNumber));
            }
            catch (ScriptRuntimeException excp)
            {
                UnityEngine.Debug.LogError($"Runtime Error: \"CalculateThreshold\" failed with error: {excp.Message}.");

                ModalDialog.ShowSimpleModal(ModalDialog.Mode.Accept,
                                            headerText: "Runtime Error",
                                            bodyText: $"Runtime Error: \"CalculateThreshold\" failed with error: {excp.Message}.");
            }
            catch (Exception excp)
            {
                UnityEngine.Debug.LogError($"Error: \"CalculateThreshold\" failed with error: {excp.Message}.");

                ModalDialog.ShowSimpleModal(ModalDialog.Mode.Accept,
                                            headerText: "Error",
                                            bodyText: $"Error: \"CalculateThreshold\" failed with error: {excp.Message}.");
            }

            return(0.0);
        }
Exemplo n.º 4
0
    private bool TestNameValid(string newName)
    {
        if (string.IsNullOrEmpty(newName))
        {
            ModalDialog.ShowSimpleModal(ModalDialog.Mode.Accept,
                                        headerText: "Invalid User Name",
                                        bodyText: "You cannot add a user with an empty name.");
            return(false);
        }

        if (newName.Contains("/") || newName.Contains(".") || newName.Contains("\\"))
        {
            ModalDialog.ShowSimpleModal(ModalDialog.Mode.Accept,
                                        headerText: "Invalid User Name",
                                        bodyText: "Name is invalid. Cannot contain characters:'/', '.', or '\\'.");
            return(false);
        }

        //Check if user name is available
        if (PlayerData.UserExists(newName))
        {
            ModalDialog.ShowSimpleModal(ModalDialog.Mode.Accept,
                                        headerText: "Invalid User Name",
                                        bodyText: "User already exists.  Users must have unique names.");
            return(false);
        }

        return(true);
    }
Exemplo n.º 5
0
    private void Submit(string newName)
    {
        newName = newName.Trim();

        //Abort and warn if the name is bad or not unique
        if (!TestNameValid(newName))
        {
            return;
        }

        //Check if user addition was successful
        if (PlayerData.AddUser(newName) == false)
        {
            ModalDialog.ShowSimpleModal(ModalDialog.Mode.Accept,
                                        headerText: "Invalid User Name",
                                        bodyText: "There was a problem creating user name.");
            return;
        }

        if (LoadUser(newName) == false)
        {
            ModalDialog.ShowSimpleModal(ModalDialog.Mode.Accept,
                                        headerText: "Error",
                                        bodyText: $"Unable to log into user {newName}.");

            return;
        }

        SettingsMenu.PullPushableSettings();

        //Switch to main menu
        menuManager.SetWindowState(MenuManager.WindowState.Title);
    }
Exemplo n.º 6
0
        public void Initialize(double taskGuessRate)
        {
            stepScheme = StepScheme;

            try
            {
                currentStep = scriptObject.ExecuteFunction <int>("Initialize", context);
            }
            catch (ScriptRuntimeException excp)
            {
                UnityEngine.Debug.LogError($"Runtime Error: \"Initialize\" failed with error: {excp.Message}.");

                ModalDialog.ShowSimpleModal(ModalDialog.Mode.Accept,
                                            headerText: "Runtime Error",
                                            bodyText: $"Runtime Error: \"Initialize\" failed with error: {excp.Message}.");
            }
            catch (Exception excp)
            {
                UnityEngine.Debug.LogError($"Error: \"Initialize\" failed with error: {excp.Message}.");

                ModalDialog.ShowSimpleModal(ModalDialog.Mode.Accept,
                                            headerText: "Error",
                                            bodyText: $"Error: \"Initialize\" failed with error: {excp.Message}.");
            }
        }
Exemplo n.º 7
0
        public override void PopulateScriptContext(GlobalRuntimeContext scriptContext)
        {
            List <double> stepValues = null;

            try
            {
                stepValues = scriptObject.ExecuteFunction <List <double> >("CalculateThreshold", context);
            }
            catch (ScriptRuntimeException excp)
            {
                UnityEngine.Debug.LogError($"Runtime Error: \"CalculateThreshold\" failed with error: {excp.Message}.");

                ModalDialog.ShowSimpleModal(ModalDialog.Mode.Accept,
                                            headerText: "Runtime Error",
                                            bodyText: $"Runtime Error: \"CalculateThreshold\" failed with error: {excp.Message}.");
            }
            catch (Exception excp)
            {
                UnityEngine.Debug.LogError($"Error: \"CalculateThreshold\" failed with error: {excp.Message}.");

                ModalDialog.ShowSimpleModal(ModalDialog.Mode.Accept,
                                            headerText: "Error",
                                            bodyText: $"Error: \"CalculateThreshold\" failed with error: {excp.Message}.");
            }

            foreach (ControlledParameterTemplate template in controlledParameters)
            {
                double stepValue;

                if (stepValues is null || stepValues.Count <= template.ControllerParameter)
                {
                    stepValue = 0.0;
                }
Exemplo n.º 8
0
        public void TryCancelChanges()
        {
            if (settingDirty)
            {
                ModalDialog.ShowSimpleModal(ModalDialog.Mode.ConfirmCancel,
                                            "Discard Changes?",
                                            "Are you sure you want to discard your changes and return to the Menu?",
                                            (ModalDialog.Response response) =>
                {
                    switch (response)
                    {
                    case ModalDialog.Response.Confirm:
                        CancelChanges();
                        break;

                    case ModalDialog.Response.Cancel:
                        //Do Nothing
                        break;

                    default:
                        Debug.LogError($"Unexpected ModalDialog.Response: {response}");
                        break;
                    }
                });
            }
            else
            {
                CancelChanges();
            }
        }
Exemplo n.º 9
0
        public void Initialize(double taskGuessRate)
        {
            stepScheme   = StepScheme;
            currentSteps = null;

            try
            {
                //Clone list so we don't risk modifying script memory
                currentSteps = scriptObject.ExecuteFunction <List <int> >("Initialize", context, ParameterCount).ToList();
            }
            catch (ScriptRuntimeException excp)
            {
                UnityEngine.Debug.LogError($"Runtime Error: \"Initialize\" failed with error: {excp.Message}.");

                ModalDialog.ShowSimpleModal(ModalDialog.Mode.Accept,
                                            headerText: "Runtime Error",
                                            bodyText: $"Runtime Error: \"Initialize\" failed with error: {excp.Message}.");
            }
            catch (Exception excp)
            {
                UnityEngine.Debug.LogError($"Error: \"Initialize\" failed with error: {excp.Message}.");

                ModalDialog.ShowSimpleModal(ModalDialog.Mode.Accept,
                                            headerText: "Error",
                                            bodyText: $"Error: \"Initialize\" failed with error: {excp.Message}.");
            }
        }
Exemplo n.º 10
0
        public override bool IsDone()
        {
            try
            {
                return(scriptObject.ExecuteFunction <bool>("End", context));
            }
            catch (ScriptRuntimeException excp)
            {
                UnityEngine.Debug.LogError($"Runtime Error: \"End\" failed with error: {excp.Message}.");

                ModalDialog.ShowSimpleModal(ModalDialog.Mode.Accept,
                                            headerText: "Runtime Error",
                                            bodyText: $"Runtime Error: \"End\" failed with error: {excp.Message}.");
            }
            catch (Exception excp)
            {
                UnityEngine.Debug.LogError($"Error: \"End\" failed with error: {excp.Message}.");

                ModalDialog.ShowSimpleModal(ModalDialog.Mode.Accept,
                                            headerText: "Error",
                                            bodyText: $"Error: \"End\" failed with error: {excp.Message}.");
            }

            return(true);
        }
Exemplo n.º 11
0
        public override void PopulateScriptContext(GlobalRuntimeContext scriptContext)
        {
            double stepValue = 0.0;

            try
            {
                stepValue = scriptObject.ExecuteFunction <double>("CalculateThreshold", context);
            }
            catch (ScriptRuntimeException excp)
            {
                UnityEngine.Debug.LogError($"Runtime Error: \"CalculateThreshold\" failed with error: {excp.Message}.");

                ModalDialog.ShowSimpleModal(ModalDialog.Mode.Accept,
                                            headerText: "Runtime Error",
                                            bodyText: $"Runtime Error: \"CalculateThreshold\" failed with error: {excp.Message}.");
            }
            catch (Exception excp)
            {
                UnityEngine.Debug.LogError($"Error: \"CalculateThreshold\" failed with error: {excp.Message}.");

                ModalDialog.ShowSimpleModal(ModalDialog.Mode.Accept,
                                            headerText: "Error",
                                            bodyText: $"Error: \"CalculateThreshold\" failed with error: {excp.Message}.");
            }

            foreach (ControlledParameterTemplate template in controlledParameters)
            {
                template.FinalizeParameters(stepValue);
                template.PopulateScriptContextOutputs(scriptContext);
            }
        }
        public override void FinalizeParameters(double thresholdStepValue)
        {
            try
            {
                Output = scriptObject.ExecuteFunction <string>("CalculateOutput", context, thresholdStepValue);
            }
            catch (ScriptRuntimeException excp)
            {
                UnityEngine.Debug.LogError($"Runtime Error: \"CalculateOutput\" failed with error: {excp.Message}.");

                Output = "";

                ModalDialog.ShowSimpleModal(ModalDialog.Mode.Accept,
                                            headerText: "Runtime Error",
                                            bodyText: $"Runtime Error: \"CalculateOutput\" failed with error: {excp.Message}.");
            }
            catch (Exception excp)
            {
                UnityEngine.Debug.LogError($"Error: \"CalculateOutput\" failed with error: {excp.Message}.");

                Output = "";

                ModalDialog.ShowSimpleModal(ModalDialog.Mode.Accept,
                                            headerText: "Error",
                                            bodyText: $"Error: \"CalculateOutput\" failed with error: {excp.Message}.");
            }
        }
        bool ISimpleDoubleStepTemplate.CouldStepTo(int stepNumber)
        {
            try
            {
                return(scriptObject.ExecuteFunction <bool>("CouldStepTo", context, stepNumber));
            }
            catch (ScriptRuntimeException excp)
            {
                UnityEngine.Debug.LogError($"Runtime Error: \"CouldStepTo\" failed with error: {excp.Message}.");

                ModalDialog.ShowSimpleModal(ModalDialog.Mode.Accept,
                                            headerText: "Runtime Error",
                                            bodyText: $"Runtime Error: \"CouldStepTo\" failed with error: {excp.Message}.");
            }
            catch (Exception excp)
            {
                UnityEngine.Debug.LogError($"Error: \"CouldStepTo\" failed with error: {excp.Message}.");

                ModalDialog.ShowSimpleModal(ModalDialog.Mode.Accept,
                                            headerText: "Error",
                                            bodyText: $"Error: \"CouldStepTo\" failed with error: {excp.Message}.");
            }

            return(false);
        }
Exemplo n.º 14
0
        public void SubmitTrialResult(bool correct)
        {
            List <int> newSteps = null;

            try
            {
                newSteps = scriptObject.ExecuteFunction <List <int> >("Step", context, correct);
            }
            catch (ScriptRuntimeException excp)
            {
                UnityEngine.Debug.LogError($"Runtime Error: \"Step\" failed with error: {excp.Message}.");

                ModalDialog.ShowSimpleModal(ModalDialog.Mode.Accept,
                                            headerText: "Runtime Error",
                                            bodyText: $"Runtime Error: \"Step\" failed with error: {excp.Message}.");
            }
            catch (Exception excp)
            {
                UnityEngine.Debug.LogError($"Error: \"Step\" failed with error: {excp.Message}.");

                ModalDialog.ShowSimpleModal(ModalDialog.Mode.Accept,
                                            headerText: "Error",
                                            bodyText: $"Error: \"Step\" failed with error: {excp.Message}.");
            }

            for (int i = 0; i < ParameterCount; i++)
            {
                if (newSteps is null || newSteps.Count >= i)
                {
                    continue;
                }

                int newStep;

                switch (stepScheme)
                {
                case StepScheme.Relative:
                    newStep = currentSteps[i] + newSteps[i];
                    break;

                case StepScheme.Absolute:
                    newStep = newSteps[i];
                    break;

                default:
                    UnityEngine.Debug.LogError($"Unexpected StepScheme: {stepScheme}");
                    goto case StepScheme.Relative;
                }

                if (currentSteps[i] != newStep)
                {
                    //Only call SetStepValue on change
                    if (SetStepValue(i, newStep) == StepStatus.Success)
                    {
                        currentSteps[i] = newStep;
                    }
                }
            }
        }
Exemplo n.º 15
0
        public void SubmitTrialResult(bool correct)
        {
            int step = 0;

            try
            {
                step = scriptObject.ExecuteFunction <int>("Step", context, correct);
            }
            catch (ScriptRuntimeException excp)
            {
                UnityEngine.Debug.LogError($"Runtime Error: \"Step\" failed with error: {excp.Message}.");

                ModalDialog.ShowSimpleModal(ModalDialog.Mode.Accept,
                                            headerText: "Runtime Error",
                                            bodyText: $"Runtime Error: \"Step\" failed with error: {excp.Message}.");
            }
            catch (Exception excp)
            {
                UnityEngine.Debug.LogError($"Error: \"Step\" failed with error: {excp.Message}.");

                ModalDialog.ShowSimpleModal(ModalDialog.Mode.Accept,
                                            headerText: "Error",
                                            bodyText: $"Error: \"Step\" failed with error: {excp.Message}.");
            }

            int oldStep = currentStep;

            switch (stepScheme)
            {
            case StepScheme.Relative:
                currentStep += step;
                break;

            case StepScheme.Absolute:
                currentStep = step;
                break;

            default:
                UnityEngine.Debug.LogError($"Unexpected StepScheme: {stepScheme}");
                goto case StepScheme.Relative;
            }

            if (oldStep != currentStep)
            {
                //Only call SetStepValue on change
                SetStepValue(0, currentStep);
            }
        }
Exemplo n.º 16
0
    /// <summary>
    /// Set current user.  Returns success.
    /// </summary>
    private bool LoadUser(string userName)
    {
        bool loggedIn = PlayerData.LogIn(
            userName: userName,
            userChangingCallback: LogManager.ClearAllLogs);

        if (!loggedIn)
        {
            ModalDialog.ShowSimpleModal(
                mode: ModalDialog.Mode.Accept,
                headerText: "Load Failed",
                bodyText: $"Unable to load user {userName}");

            return(false);
        }

        return(true);
    }
Exemplo n.º 17
0
    protected void LockSubmit(ModalDialog.Response response, string input)
    {
        switch (response)
        {
        case ModalDialog.Response.Confirm:
            if (input == "3141")
            {
                PlayerData.GlobalData.IsLocked = false;
            }
            else
            {
                ModalDialog.ShowSimpleModal(
                    mode: ModalDialog.Mode.Accept,
                    headerText: "Incorrect Code",
                    bodyText: "The entered code was incorrect.");
            }
            break;

        case ModalDialog.Response.Cancel:
            //Do nothing
            break;

        default:
            Debug.LogError($"Unexpected ModalDialog.Response: {response}");
            break;
        }

        switch (currentMode)
        {
        case SettingPanelMode.General:
            generalSettingsMenu.LockStateChanged();
            break;

        case SettingPanelMode.UserSelect:
            userIDMenu.LockStateChanged();
            break;

        default:
            Debug.LogError($"Unexpected mode: {currentMode}");
            break;
        }

        UpdateUIForMode(currentMode);
    }
        public void SubmitTrialResult(int stepValue)
        {
            try
            {
                scriptObject.ExecuteFunction("SubmitResult", context, stepValue);
            }
            catch (ScriptRuntimeException excp)
            {
                UnityEngine.Debug.LogError($"Runtime Error: \"Step\" failed with error: {excp.Message}.");

                ModalDialog.ShowSimpleModal(ModalDialog.Mode.Accept,
                                            headerText: "Runtime Error",
                                            bodyText: $"Runtime Error: \"Step\" failed with error: {excp.Message}.");
            }
            catch (Exception excp)
            {
                UnityEngine.Debug.LogError($"Error: \"Step\" failed with error: {excp.Message}.");

                ModalDialog.ShowSimpleModal(ModalDialog.Mode.Accept,
                                            headerText: "Error",
                                            bodyText: $"Error: \"Step\" failed with error: {excp.Message}.");
            }
        }
        void ISimpleDoubleStepTemplate.Initialize()
        {
            try
            {
                scriptObject.ExecuteFunction("Initialize", context);
            }
            catch (ScriptRuntimeException excp)
            {
                UnityEngine.Debug.LogError($"Runtime Error: \"Initialize\" failed with error: {excp.Message}.");

                ModalDialog.ShowSimpleModal(ModalDialog.Mode.Accept,
                                            headerText: "Runtime Error",
                                            bodyText: $"Runtime Error: \"Initialize\" failed with error: {excp.Message}.");
            }
            catch (Exception excp)
            {
                UnityEngine.Debug.LogError($"Error: \"Initialize\" failed with error: {excp.Message}.");

                ModalDialog.ShowSimpleModal(ModalDialog.Mode.Accept,
                                            headerText: "Error",
                                            bodyText: $"Error: \"Initialize\" failed with error: {excp.Message}.");
            }
        }
Exemplo n.º 20
0
    /// <summary>
    /// Spawn user delete confirmation
    /// </summary>
    public void RequestDeleteUser(string userName)
    {
        ModalDialog.ShowSimpleModal(ModalDialog.Mode.ConfirmCancel,
                                    headerText: "Confirm Delete",
                                    bodyText: $"Are you sure you want to delete user \"{userName}\"?",
                                    callback: (response) =>
        {
            switch (response)
            {
            case ModalDialog.Response.Confirm:
                DeleteUser(userName);
                break;

            case ModalDialog.Response.Cancel:
                //Do Nothing
                break;

            default:
                Debug.LogError($"Unrecognized ModalDialog.Response: {response}");
                break;
            }
        });
    }