예제 #1
0
        internal void saveSettings()
        {
            // Written, 17.10.2020

            SaveLoad.SerializeSaveFile(MoControlsMod.instance, this, fileName + fileExtention);
            MoControlsMod.print("saved mo'controls data.", Debugging.DebugTypeEnum.full);
        }
예제 #2
0
        /// <summary>
        /// Loads provided control list to cInput.
        /// </summary>
        /// <param name="inControlMode">The control mode.</param>
        private void loadControlModeToCInput(PlayerModeEnum?inPlayerMode, string[,] inControlMode)
        {
            // Written, 31.08.2018

            string controlListName = "game control";

            try
            {
                controlListName = inPlayerMode.Equals(PlayerModeEnum.OnFoot) ? "foot control" : "driving control";
                for (int i = 0; i < inControlMode.GetLength(0); i++)
                {
                    cInput.ChangeKey(inControlMode[i, 0], inControlMode[i, 1], inControlMode[i, 2]);
                }
                MoControlsMod.print(String.Format("<b><color=green>Successfully</color></b> loaded {0} inputs to cInput.", controlListName), DebugTypeEnum.full);
            }
            catch (NullReferenceException)
            {
                MoControlsMod.print(String.Format("control inputs was null; setting {0} inputs to current control settings.", controlListName), DebugTypeEnum.full);
                if (inPlayerMode == PlayerModeEnum.Driving)
                {
                    drivingControls = loadControlInputsFromCInput();
                }
                else
                {
                    footControls = loadControlInputsFromCInput();
                }
            }
            catch
            {
                MoControlsMod.print(String.Format("<b><color=red>Unsuccessfully</color></b> loaded {0} inputs to cInput.", controlListName), DebugTypeEnum.full);
                throw;
            }
        }
예제 #3
0
        /// <summary>
        /// Changes the input for a control defined in <see cref="changeInputResult"/> to the provided input string, <paramref name="inInput"/>.
        /// </summary>
        /// <param name="inInput">The input to assign.</param>
        internal void changeInput(string inInput)
        {
            // Written, 09.07.2018

            if (!changeInputResult.isModKeybind)
            {
                // Treat as a game control.

                PlayerModeEnum?playerMode = changeInputResult?.mode;

                if (playerMode == null)
                {
                    bool mistake = true;
                    ModUI.ShowYesNoMessage("Player Mode was null, is that right?", "Mistake?", delegate()
                    {
                        mistake = false;
                    });
                    if (!mistake)
                    {
                        if (changeInputResult.index == 1)
                        {
                            cInput.ChangeKey(changeInputResult.controlName, inInput, cInput.GetText(changeInputResult.controlName, 2));
                        }
                        else
                        {
                            cInput.ChangeKey(changeInputResult.controlName, cInput.GetText(changeInputResult.controlName, 1), inInput);
                        }
                        currentControls = loadControlInputsFromCInput();
                    }
                    MoControlsMod.print("Player mode wasa null while attempting to change input..", DebugTypeEnum.full);
                }
                else
                {
                    setGameControl((PlayerModeEnum)playerMode, changeInputResult.controlName, changeInputResult.index, inInput);
                    MoControlsMod.print("Player mode was equal to <b>" + changeInputResult.mode + "</b> whiling setting '" + changeInputResult.controlName + "' to '" + inInput + "'.", DebugTypeEnum.full);
                    MoControlsSaveData.loadedSaveData.saveSettings();
                }
            }
            else
            {
                // Treat as a mod keybind.

                Keybind modKeybind = Keybind.Get(changeInputResult.mod).Where(kb => kb.ID == changeInputResult.controlName).First();
                if (changeInputResult.index == 1)
                {
                    modKeybind.Modifier = (KeyCode)Enum.Parse(typeof(KeyCode), inInput);
                }
                else
                {
                    modKeybind.Key = (KeyCode)Enum.Parse(typeof(KeyCode), inInput);
                }
                ModSettings_menu.SaveModBinds(changeInputResult.mod);
                MoControlsMod.print("saved <i>" + modKeybind.Mod.Name + "</i> mod keybinds.", DebugTypeEnum.full);
            }
            setChangeInput();
        }
예제 #4
0
        /// <summary>
        /// Occurs when game starts.
        /// </summary>
        private void Awake()
        {
            // Written, 18.10.2020

            xboxControllerManager = gameObject.AddComponent <XboxControllerManager>();
            controlManager        = gameObject.AddComponent <ControlManager>();
            mouseEmulator         = gameObject.AddComponent <MouseEmulator>();
            moControlsGui         = gameObject.AddComponent <MoControlsGUI>();
            XboxControllerManager.ControllerConnected    += xboxControllerManager_ControllerConnected;
            XboxControllerManager.ControllerDisconnected += xboxControllerManager_ControllerDisconnected;
            MoControlsMod.print(nameof(MoControlsGO) + ": Started", Debugging.DebugTypeEnum.full);
        }
예제 #5
0
        /// <summary>
        /// Sets and initializes hold input mono
        /// </summary>
        /// <param name="inName">The name to set the hold input</param>
        /// <param name="inKeyName">The Xbox Button to assign the hold</param>
        /// <param name="inHoldTime">How long the xbox button needs to be held down for before action execution.</param>
        /// <param name="inAction">The action to perform.</param>
        internal void setData(string inName, XboxButtonEnum inKeyName, float inHoldTime, Action inAction)
        {
            // Written, 19.12.2018

            holdTime = inHoldTime;
            keyName  = inKeyName;
            action   = inAction;
            hiName   = inName;
            id       = ("hld_inpt_" + hiName.ToLower().Replace(" ", "") + "_K" + inKeyName).ToLower().Trim();

            MoControlsMod.print("hld_inpt: " + hiName + " initiliazed as '" + id + "'.", Debugging.DebugTypeEnum.full);
        }
예제 #6
0
        internal static MoControlsSaveData loadSettings()
        {
            // Written, 17.10.2020

            bool createNewSaveFile  = false;
            MoControlsSaveData mcsd = null;

            try
            {
                mcsd = SaveLoad.DeserializeSaveFile <MoControlsSaveData>(MoControlsMod.instance, fileName + fileExtention);
                if (mcsd == null)
                {
                    throw new NullReferenceException();
                }

                if (mcsd.moControlsVersion != MoControlsMod.instance.Version)
                {
                    if (mcsd.oldNewVersionAccepted != mcsd.moControlsVersion)
                    {
                        oldSaveException = new OldSaveDataException(mcsd);
                        throw oldSaveException;
                    }
                }
            }
            catch (NullReferenceException)
            {
                createNewSaveFile = true;
                MoControlsMod.print("Save file does not exist, make any change to a setting to save.", Debugging.DebugTypeEnum.none);
            }
            catch (OldSaveDataException e)
            {
                createNewSaveFile = true;
                ModUI.ShowYesNoMessage(string.Format("A{1} save detected (v{0}).. Would you like to still load this save file? NOTE: you may need to change various settings",
                                                     e.oldSaveData.moControlsVersion,
                                                     MoControlsMod.determineIsVersionOldCurrentOrNew(mcsd.moControlsVersion) < 0 ? "n Older" : " Newer"),
                                       "[Mo'Controls] - Different save version detected", keepSaveFile);
            }
            catch (Exception e)
            {
                createNewSaveFile = true;
                MoControlsMod.print("An error occured while loading the save file..make any change to a setting to save.\nERROR: " + e.Message, Debugging.DebugTypeEnum.none);
            }
            if (createNewSaveFile)
            {
                mcsd = defaultSave;
                mcsd.saveSettings();
            }
            loadedSaveData = mcsd;
            MoControlsMod.print("loaded mo'controls data.", Debugging.DebugTypeEnum.full);
            return(mcsd);
        }
예제 #7
0
        /// <summary>
        /// Occurs on update.
        /// </summary>
        private void Update()
        {
            // Written, 31.08.2018

            if (currentPlayerMode != getCurrentPlayerMode)
            {
                currentPlayerMode = getCurrentPlayerMode;
                loadControlModeToCInput(currentPlayerMode, currentControls);
                MoControlsMod.print("Control Mode changed: " + currentPlayerMode, DebugTypeEnum.full);
            }
            // Enable scroll only if player is on foot and in tool mode (2) OR when player is holding an item while on foot and in hand mode.
            toolModeScroll.enabled = currentPlayerMode == PlayerModeEnum.OnFoot && (isInToolMode || (!isInToolMode && !isPlayerHandEmpty()));
            // Handling xbox controller force feedback rumble events.
            if (setFfbForVehicle())
            {
                handleFfbOnXboxController();
            }
        }
예제 #8
0
        /// <summary>
        /// Sets the provided game control in provided mode.
        /// </summary>
        /// <param name="inMode"></param>
        private void setGameControl(PlayerModeEnum inMode, string inControlName, int inIndex, string inInput)
        {
            // Written, 02.09.2018

            if (inIndex != 1 && inIndex != 2)
            {
                MoControlsMod.print("<b>C285 PControlManager</b>\r\nIndex out of range for game control editing...", DebugTypeEnum.full);
                throw new IndexOutOfRangeException();
            }
            switch (inMode)
            {
            case PlayerModeEnum.Driving:
                for (int i = 0; i < drivingControls.GetLength(0); i++)
                {
                    string _controlName = drivingControls[i, 0];
                    if (inControlName == _controlName)
                    {
                        drivingControls[i, inIndex] = inInput;
                        break;
                    }
                }
                if (currentPlayerMode == inMode)
                {
                    loadControlModeToCInput(inMode, drivingControls);
                }
                break;

            case PlayerModeEnum.OnFoot:
                for (int i = 0; i < footControls.GetLength(0); i++)
                {
                    string _controlName = footControls[i, 0];
                    if (inControlName == _controlName)
                    {
                        footControls[i, inIndex] = inInput;
                        break;
                    }
                }
                if (currentPlayerMode == inMode)
                {
                    loadControlModeToCInput(inMode, footControls);
                }
                break;
            }
        }
예제 #9
0
        private void loadCInputAxisSettings()
        {
            // Written, 23.10.2020

            // setting cInput axis deadzones//
            /*external cinput control names = PlayerVertical*PlayerHorizontal*Horizontal*Vertical*/
            cInput.SetAxisDeadzone("PlayerHorizontal", MoControlsSaveData.loadedSaveData.playerHorzDeadzone);
            cInput.SetAxisSensitivity("PlayerHorizontal", MoControlsSaveData.loadedSaveData.playerHorzSensitivity);
            cInput.SetAxisGravity("PlayerHorizontal", MoControlsSaveData.loadedSaveData.playerHorzGravity);
            cInput.SetAxisDeadzone("PlayerVertical", MoControlsSaveData.loadedSaveData.playerVertDeadzone);
            cInput.SetAxisSensitivity("PlayerVertical", MoControlsSaveData.loadedSaveData.playerVertSensitivity);
            cInput.SetAxisGravity("PlayerVertical", MoControlsSaveData.loadedSaveData.playerVertGravity);
            cInput.SetAxisDeadzone("Horizontal", MoControlsSaveData.loadedSaveData.horzDeadzone);
            cInput.SetAxisSensitivity("Horizontal", MoControlsSaveData.loadedSaveData.horzSensitivity);
            cInput.SetAxisGravity("Horizontal", MoControlsSaveData.loadedSaveData.horzGravity);
            cInput.SetAxisDeadzone("Vertical", MoControlsSaveData.loadedSaveData.vertDeadzone);
            cInput.SetAxisSensitivity("Vertical", MoControlsSaveData.loadedSaveData.vertSensitivity);
            cInput.SetAxisGravity("Vertical", MoControlsSaveData.loadedSaveData.vertGravity);
            MoControlsMod.print("loaded cinput axis settings (grav, dead, sens).. hold <i>Left-Ctrl</i> through Mo'Controls' second pass loading sequ to disable", DebugTypeEnum.none);//.full);
        }
예제 #10
0
        /// <summary>
        /// Occurs after game starts.
        /// </summary>
        private void Start()
        {
            // Written, 08.10.2018

            MoControlsGO.controlManager.setControls(MoControlsSaveData.loadedSaveData.footControls, MoControlsSaveData.loadedSaveData.drivingControls);
            // Setting up toolmode stuff
            toolModeGameObject = GameObject.Find(toolModeLocation);
            handModeGameObject = GameObject.Find(handModeLocation);
            // Tool mode hold button set up
            HoldInputMono him = gameObject.AddComponent <HoldInputMono>();

            him.setData("Toggle Tool Mode", XboxButtonEnum.Start, 0.3f, requestedModeChange);
            // Setting up guiNav "toolMode MouseScroll".
            toolModeScroll = gameObject.AddComponent <GuiNav>();
            toolModeScroll.setControls(XboxAxisEnum.rightTrigger, XboxButtonEnum.NULL,
                                       XboxAxisEnum.leftTrigger, XboxButtonEnum.NULL,
                                       XboxAxisEnum.NULL, XboxButtonEnum.RB,
                                       XboxAxisEnum.NULL, XboxButtonEnum.LB);
            MoControlsMod.print(nameof(ControlManager) + ": Started", DebugTypeEnum.full);
        }
예제 #11
0
        /// <summary>
        /// Loads control inputs (defined in <see cref="inputNames"/>) from the class, <see cref="cInput"/> and adds each one to <see cref="controlInputs"/> with it's primary
        /// and secondary input.
        /// </summary>
        internal static string[,] loadControlInputsFromCInput()
        {
            // Written, 31.08.2018

            try
            {
                string[,] controls = new string[inputNames.Length, 3];
                for (int i = 0; i < inputNames.Length; i++)
                {
                    controls[i, 0] = cInput.GetText(inputNames[i], 0);
                    controls[i, 1] = cInput.GetText(inputNames[i], 1);
                    controls[i, 2] = cInput.GetText(inputNames[i], 2);
                }
                MoControlsMod.print("<b><color=green>Successfully</color></b> loaded game control inputs from cInput.", DebugTypeEnum.full);
                return(controls);
            }
            catch (Exception ex)
            {
                MoControlsMod.print("<b><color=red>Unsuccessfully</color></b> loaded game control inputs from cInput.", DebugTypeEnum.full);
                ModConsole.Error(ex.ToString());
                throw;
            }
        }
예제 #12
0
        private void xboxControllerManager_ControllerConnected(object inSender, ControllerConnectionEventArgs inE)
        {
            // Written, 08.10.2018

            MoControlsMod.print("<color=grey><i>Controller " + inE.xboxController.index + "</i></color> <color=green>Connected</color>", Debugging.DebugTypeEnum.none);
        }
예제 #13
0
        private void xboxControllerManager_ControllerDisconnected(object sender, ControllerConnectionEventArgs e)
        {
            // Written, 08.10.2018

            MoControlsMod.print("<color=grey><i>Controller: " + e.xboxController.index + "</i></color> <color=red>Disconnected</color>", Debugging.DebugTypeEnum.none);
        }
예제 #14
0
        public AssetHolder(UnityEngine.Object[] inAssets)
        {
            // Written, 15.10.2018

            if (inAssets.Count() == 25)
            {
                Texture2D[] textures = new Texture2D[inAssets.Length];
                for (int i = 0; i < inAssets.Length; i++)
                {
                    if (inAssets[i] is Texture2D)
                    {
                        textures[i] = inAssets[i] as Texture2D;
                        if (textures[i] is null)
                        {
                            MoControlsMod.print("<color=red>Unsuccessfully</color> loaded texture, texure is null" + textures[i].name, DebugTypeEnum.full);
                        }
                        else
                        {
                            MoControlsMod.print("<color=green>successfully</color> loaded texture, " + textures[i].name, DebugTypeEnum.full);
                        }
                    }
                    else
                    {
                        MoControlsMod.print("<color=red>Error loading texture</color>, <color=grey><b><i>" + (inAssets[i]?.name ?? "[Asset name null]") + ".</i></b></color>", DebugTypeEnum.full);
                    }
                }
                this.textures = textures;

                try
                {
                    // setting textures.
                    a       = this.textures.First(_texture => _texture.name == "xc_a");
                    b       = this.textures.First(_texture => _texture.name == "xc_b");
                    x       = this.textures.First(_texture => _texture.name == "xc_x");
                    y       = this.textures.First(_texture => _texture.name == "xc_y");
                    back    = this.textures.First(_texture => _texture.name == "xc_back");
                    start   = this.textures.First(_texture => _texture.name == "xc_start");
                    lb      = this.textures.First(_texture => _texture.name == "xc_lb");
                    rb      = this.textures.First(_texture => _texture.name == "xc_rb");
                    lt      = this.textures.First(_texture => _texture.name == "xc_lt");
                    rt      = this.textures.First(_texture => _texture.name == "xc_rt");
                    dp      = this.textures.First(_texture => _texture.name == "xc_dp");
                    dpup    = this.textures.First(_texture => _texture.name == "xc_dpu");
                    dpdown  = this.textures.First(_texture => _texture.name == "xc_dpd");
                    dpleft  = this.textures.First(_texture => _texture.name == "xc_dpl");
                    dpright = this.textures.First(_texture => _texture.name == "xc_dpr");
                    ls      = this.textures.First(_texture => _texture.name == "xc_ls");
                    lsup    = this.textures.First(_texture => _texture.name == "xc_lsu");
                    lsdown  = this.textures.First(_texture => _texture.name == "xc_lsd");
                    lsleft  = this.textures.First(_texture => _texture.name == "xc_lsl");
                    lsright = this.textures.First(_texture => _texture.name == "xc_lsr");
                    rs      = this.textures.First(_texture => _texture.name == "xc_rs");
                    rsup    = this.textures.First(_texture => _texture.name == "xc_rsu");
                    rsdown  = this.textures.First(_texture => _texture.name == "xc_rsd");
                    rsleft  = this.textures.First(_texture => _texture.name == "xc_rsl");
                    rsright = this.textures.First(_texture => _texture.name == "xc_rsr");

                    if (a is null || b is null || x is null || y is null || lb is null ||
                        rb is null || back is null || start is null || ls is null ||
                        rs is null || lt is null || rt is null || dp is null ||
                        dpdown is null || dpup is null || dpleft is null || dpright is null ||
                        lsup is null || lsdown is null || lsleft is null || lsright is null ||
                        rsdown is null || rsup is null || rsleft is null || rsright is null)
                    {
                        throw new NullReferenceException("One or more assets are null..");
                    }
                }
                catch (NullReferenceException ex)
                {
                    result = false;
                    MoControlsMod.print("<color=red>Error occured when setting asset textures...</color>.\r\n<b>Message:</b>" + ex.Message + "\r\nStacktrace:\r\n" + ex.StackTrace, DebugTypeEnum.full);
                    throw;
                }
            }
            else
            {
                result = false;
                MoControlsMod.print("<color=red>Error not all assets could be found..</color>.", DebugTypeEnum.full);
            }
            result = true;
        }