Beispiel #1
0
        private void OnGuiInput(ConsoleSystem.Arg arg)
        {
            //gui.input pluginName containerName inputName --close elementNames... --input text...
            if (arg.Args.Length < 3)
            {
                SendReply(arg, "OnGuiInput: not enough arguments given!");
                return;
            }

            BasePlayer player = arg.Player();

            if (player == null)
            {
                return;
            }

#if DEBUG2
            SendReply(arg, $"OnGuiInput: gui.input {arg.FullString}");
            player.ChatMessage($"OnGuiInput: gui.input {arg.FullString}");
#endif

            GuiTracker tracker = GuiTracker.getGuiTracker(player);

            #region parsing

            Command cmd = new Command("gui.input " + arg.FullString);
#if DEBUG
            player.ChatMessage(cmd.ToString());
#endif
            Plugin plugin = Manager.GetPlugin(cmd.args[0]);
            if (plugin == null)
            {
                SendReply(arg, "OnGuiInput: Plugin not found!");
                return;
            }

            GuiContainer container = tracker.getContainer(plugin, cmd.args[1]);
            if (container == null)
            {
                SendReply(arg, "OnGuiInput: Container not found!");
                return;
            }

            string inputName = cmd.args[2];

            bool closeContainer = false;
            if (inputName == "close" || inputName == "close_btn")
            {
                closeContainer = true;
            }
            #endregion

            #region execution
            string[] input = null;
            if (cmd.flags.ContainsKey("-input"))
            {
                input = cmd.flags["-input"].ToArray();
            }

            if (!container.runCallback(inputName, player, input))
            {
#if DEBUG
                SendReply(arg, $"OnGuiInput: Callback for {plugin.Name} {container.name} {inputName} wasn't found");
#endif
            }

            if (cmd.flags.ContainsKey("-close"))
            {
                foreach (string name in cmd.flags["-close"])
                {
                    if (name == container.name)
                    {
                        tracker.destroyGui(plugin, container);
                    }
                    else
                    {
                        tracker.destroyGui(plugin, container, name);
                    }
                }
            }

            if (closeContainer)
            {
                tracker.destroyGui(plugin, container);
            }

            #endregion
        }
Beispiel #2
0
        private void OnGuiInput(ConsoleSystem.Arg arg)
        {
            //gui.input pluginName containerName inputName --close elementNames... --input text...
            if (arg.Args.Length < 3)
            {
                SendReply(arg, "OnGuiInput: not enough arguments given!");
                return;
            }

            BasePlayer player = arg.Player();

            if (player == null)
            {
                return;
            }

#if DEBUG
            player.ChatMessage($"OnGuiInput: gui.input {arg.FullString}");
#endif

            GuiTracker tracker = GuiTracker.getGuiTracker(player);

            #region parsing
            Stack <string> args = new Stack <string>(arg.Args.Reverse <string>());

            Plugin plugin = Manager.GetPlugin(args.Pop());
            if (plugin == null)
            {
                SendReply(arg, "OnGuiInput: Plugin not found!");
                return;
            }

            GuiContainer container = tracker.getContainer(plugin, args.Pop());
            if (container == null)
            {
                SendReply(arg, "OnGuiInput: Container not found!");
                return;
            }

            string inputName = args.Pop();

            bool closeContainer = false;
            if (inputName == encodeName(container, "close") || inputName == encodeName(container, "close_btn"))
            {
                closeContainer = true;
            }

            List <string> close  = new List <string>();
            List <string> input  = new List <string>();
            List <string> select = null;
            string        next;

            while (args.TryPop(out next))
            {
                if (next == "--close")
                {
                    select = close;
                }
                else if (next == "--input")
                {
                    select = input;
                }
                else
                {
                    if (select == null)
                    {
                        SendReply(arg, $"OnGuiInput: Couldn't interpret {next}");
                        continue;
                    }
                    else
                    {
                        select.Add(next);
                    }
                }
            }
            #endregion

            #region execution

            if (!container.runCallback(inputName, player, input.ToArray()))
            {
#if DEBUG
                SendReply(arg, $"OnGuiInput: Callback for {plugin.Name} {container.name} {inputName} wasn't found");
#endif
            }

            if (close.Count != 0)
            {
                foreach (string name in close)
                {
                    tracker.destroyGui(plugin, container, name);
                }
            }

            if (closeContainer)
            {
                tracker.destroyGui(plugin, container);
            }

            #endregion
        }