Example #1
0
        /// <summary>
        /// Updates the current key bind configuration.
        /// </summary>
        public static bool TryUpdateConfig(BindsConfig cfg)
        {
            Binds newBinds = new Binds();

            KeyBindData[] bindData  = cfg.bindData;
            bool          bindError = false;

            if (bindData != null && bindData.Length > 0)
            {
                foreach (KeyBindData bind in bindData)
                {
                    if (!newBinds.TryUpdateBind(bind.name, bind.controlNames, true))
                    {
                        bindError = true;
                        break;
                    }
                }

                if (bindError)
                {
                    BvMain.Instance.SendChatMessage("One or more keybinds in the given configuration were invalid.");
                    return(false);
                }
                else
                {
                    Instance = newBinds;
                    return(true);
                }
            }
            else
            {
                BvMain.Instance.SendChatMessage("Bind data cannot be null or empty.");
                return(false);
            }
        }
Example #2
0
        /// <summary>
        /// Mod main loop. This mod will not work if this isn't being called regularly.
        /// </summary>
        public void Update()
        {
            if (initStart)
            {
                Log.Update();
                Config.Update();
            }

            if (init)
            {
                Binds.Update();

                if (menuOpen)
                {
                    Menu.Update(Cfg.forceFallbackHud);
                }

                if (Binds.open.IsNewPressed)
                {
                    TryOpenMenu();
                }

                if (Binds.close.IsNewPressed || !CanAccessTargetBlock())
                {
                    TryCloseMenu();
                }
            }
        }
Example #3
0
        private List<HudUtilities.IMenuElement> GetBindSettings()
        {
            List<HudUtilities.IMenuElement> bindSettings = new List<HudUtilities.IMenuElement>(Binds.Count + 2);

            foreach (IKeyBind bind in Binds.KeyBinds)
            {
                bindSettings.Add(new HudUtilities.MenuTextInput(bind.Name, "Enter Control Names", 
                    (string input) =>
                    {
                        string[] args;
                        input = input.ToLower();

                        if (Cmd.TryParseCommand($"{bind.Name} {input}", out args))
                            Binds.TryUpdateBind(bind.Name, args);
                    }));
            }

            bindSettings.Add(new HudUtilities.MenuButton(() => "Open Bind Help Menu",
                () => Main.ShowMissionScreen("Bind Help", Cmd.GetBindHelpMessage())));

            bindSettings.Add(new HudUtilities.MenuButton(() => "Reset Binds",
                () => Binds.TryUpdateConfig(BindsConfig.Defaults)));

            return bindSettings;
        }
Example #4
0
 /// <summary>
 /// Updates current configuration with given config data.
 /// </summary>
 public void UpdateConfig(ConfigData cfg)
 {
     if (init && cfg != null)
     {
         cfg.Validate();
         Cfg = cfg.general;
         Binds.TryUpdateConfig(cfg.binds);
         Menu.Cfg          = cfg.menu;
         PropertyBlock.Cfg = cfg.propertyBlock;
     }
 }
Example #5
0
        /// <summary>
        /// Returns the current instance or creates one if necessary.
        /// </summary>
        public static void Init(BindsConfig cfg)
        {
            if (Instance == null)
            {
                Instance = new Binds();

                if (!TryUpdateConfig(cfg))
                {
                    TryUpdateConfig(BindsConfig.Defaults);
                }
            }
        }
Example #6
0
        /// <summary>
        /// Finishes initialization upon retrieval of configuration information.
        /// </summary>
        private void InitFinish(ConfigData cfg)
        {
            if (!init && initStart)
            {
                Cfg = cfg.general;
                Binds.Init(cfg.binds);
                ChatCommands.Init(cmdPrefix);
                HudUtilities.Init();
                SettingsMenu.Init();
                PropertiesMenu.Init(cfg.menu);
                PropertyBlock.Cfg = cfg.propertyBlock;

                init = true;
                MyAPIGateway.Utilities.ShowMessage("Build Vision 2", $"Type {cmdPrefix} help for help. All settings are now available through the Mod Menu.");
            }
        }
Example #7
0
        /// <summary>
        /// Instantiates commands and regex
        /// </summary>
        private ChatCommands(string prefix)
        {
            this.prefix = prefix;
            cmdParser   = new Regex(@"((\s*?[\s,;|]\s*?)(\w+))+");

            commands = new Command[]
            {
                new Command("help",
                            () => Main.ShowMissionScreen("Help", GetHelpMessage())),
                new Command("bindHelp",
                            () => Main.ShowMissionScreen("Bind Help", GetBindHelpMessage())),
                new Command("printBinds",
                            () => Main.SendChatMessage(GetPrintBindsMessage())),
                new Command("bind",
                            (string[] args) => Binds.TryUpdateBind(args[0], Utilities.GetSubarray(args, 1))),
                new Command("resetBinds",
                            () => Binds.TryUpdateConfig(BindsConfig.Defaults)),
                new Command("save",
                            () => Main.SaveConfig()),
                new Command("load",
                            () => Main.LoadConfig()),
                new Command("resetConfig",
                            () => Main.ResetConfig()),
                new Command("toggleApi",
                            () => Main.Cfg.forceFallbackHud = !Main.Cfg.forceFallbackHud),
                new Command("toggleAutoclose",
                            () => Main.Cfg.closeIfNotInView = !Main.Cfg.closeIfNotInView),
                new Command("toggleOpenWhileHolding",
                            () => Main.Cfg.canOpenIfHolding = !Main.Cfg.canOpenIfHolding),

                // Debug/Testing
                new Command("open",
                            () => Main.TryOpenMenu()),
                new Command("close",
                            () => Main.TryCloseMenu()),
                new Command("toggleTestPattern",
                            () => Hud.TestPattern.Toggle()),
                new Command("reload",
                            () => Main.Close())
            };

            controlList = Binds.GetControlListString();
            MyAPIGateway.Utilities.MessageEntered += MessageHandler;
        }
Example #8
0
        /// <summary>
        /// Unloads all mod data.
        /// </summary>
        public void Close()
        {
            if (init)
            {
                TryCloseMenu();
                Config.Save(GetConfig());
            }

            init      = false;
            initStart = false;

            Binds?.Close();
            Cmd?.Close();
            Menu?.Close();
            Config?.Close();
            Log?.Close();
            HudElements?.Close();
            Settings?.Close();
            Instance = null;
        }