Beispiel #1
0
        //+ INITIALIZATION
        internal static void Init()
        {
            // Register All Commands
            RegisterCommand(new PrintCommand());
            RegisterCommand(new AddButtonCommand());
            RegisterCommand(new RemoveButtonCommand());
            RegisterCommand(new EditButtonCommand());

            // Register Console Buttons
            RegisterButton(new ConsoleButton("clear", "Clear Console", "clear"));
            RegisterButton(new ConsoleButton("help", "Command List", "help"));
            RegisterButton(new ConsoleButton("mods", "Mods List", "mods"));
            RegisterButton(new ConsoleButton("reload", "Reload Mods", "reload"));
            RegisterButton(new ConsoleButton("dump", "Dump Info", "dump"));
            RegisterButton(new ConsoleButton("noclip", "No Clip", "noclip"));

            ConsoleBinder.ReadBinds();
        }
Beispiel #2
0
        //+ MANIPULATION
        /// <summary>
        /// Removes a button from the console
        /// </summary>
        /// <param name="id">The id of the button to be removed</param>
        /// <param name="custom">Is it a custom button?</param>
        /// <returns>True if the button was removed, false otherwise</returns>
        public static bool RemoveButton(string id, bool custom = false)
        {
            if ((custom && !customButtons.ContainsKey(id)) || (!custom && !buttons.ContainsKey(id)))
            {
                return(false);
            }

            if (custom)
            {
                ConsoleBinder.RemoveBind(id);
                customButtons.Remove(id);
            }
            else
            {
                buttons.Remove(id);
            }

            return(true);
        }
Beispiel #3
0
        /// <summary>
        /// Registers a new button to the console
        /// </summary>
        /// <param name="button">The button to register</param>
        /// <param name="replace">Set to true to replace the button if it already exists</param>
        /// <returns>True if registered, false otherwise</returns>
        public static bool RegisterButton(ConsoleButton button, bool replace = false)
        {
            string id = button.ID.ToLowerInvariant();

            if (id.Equals(string.Empty))
            {
                GuuCore.LOGGER.LogWarning($"Trying to register a button with an empty id, such if not possible!");
                return(false);
            }

            if (id.Equals("all"))
            {
                (Loader.ModLoader.Context == null ? GuuCore.LOGGER : Loader.ModLoader.Context.Logger)
                .LogWarning("Trying to register command button with id '<color=white>all</color>' but '<color=white>all</color>' is not a valid id!");
                return(false);
            }

            if (button.Custom)
            {
                if (customButtons.ContainsKey(id) && !replace)
                {
                    GuuCore.LOGGER?.LogWarning($"Trying to register custom command button with id '<color=white>{id}</color>' but the ID is already registered!");
                    return(false);
                }

                if (replace)
                {
                    if (!button.NoBinder)
                    {
                        ConsoleBinder.EditBind(button);
                    }
                    customButtons[id] = button;
                }
                else
                {
                    if (!button.NoBinder)
                    {
                        ConsoleBinder.RegisterBind(button);
                    }
                    customButtons.Add(id, button);
                }

                return(true);
            }

            if (buttons.ContainsKey(id) && !replace)
            {
                (Loader.ModLoader.Context == null ? GuuCore.LOGGER : Loader.ModLoader.Context.Logger)
                .LogWarning($"Trying to register command button with id '<color=white>{id}</color>' but the ID is already registered!");
                return(false);
            }

            if (replace)
            {
                buttons[id] = button;
            }
            else
            {
                buttons.Add(id, button);
            }

            return(true);
        }