Beispiel #1
0
 private void Unload()
 {
     foreach (BasePlayer player in BasePlayer.activePlayerList)
     {
         GuiTracker.getGuiTracker(player).destroyAllGui();
     }
 }
Beispiel #2
0
            public void display(BasePlayer player)
            {
                if (this.Count == 0)
                {
                    return;
                }

                foreach (CuiElement element in this)
                {
                    if (!string.IsNullOrEmpty(element.Name))
                    {
                        element.Name = PluginInstance.prependContainerName(this, element.Name);
                    }
                    if (!string.IsNullOrEmpty(element.Parent) && !layers.Contains(element.Parent))
                    {
                        element.Parent = PluginInstance.prependContainerName(this, element.Parent);
                    }
                }

                GuiTracker.getGuiTracker(player).addGuiToTracker(plugin, this);

#if DEBUG
                PluginInstance.Puts(JsonConvert.SerializeObject(this));
                player.ConsoleMessage(JsonConvert.SerializeObject(this));
#endif

                CuiHelper.AddUi(player, CuiContainer);
            }
Beispiel #3
0
        private void listContainers(ConsoleSystem.Arg arg)
        {
            BasePlayer player = arg.Player();

            if (arg.Args != null)
            {
                player = BasePlayer.FindByID(ulong.Parse(arg.Args[0]));
            }
            if (player == null)
            {
                return;
            }
            GuiTracker tracker = GuiTracker.getGuiTracker(player);

            if (tracker.activeGuiContainers.Count == 0)
            {
                SendReply(arg, "you don't have any active guiContainers!");
                return;
            }
            foreach (GuiContainer container in tracker.activeGuiContainers)
            {
                SendReply(arg, $"Plugin: {container.plugin.Name}, Container: {container.name}, Parent: {container.parent}:");
                foreach (GuiElement element in container)
                {
                    SendReply(arg, $"- Element: {element.Name}, Parent: {element.Parent}, ParentElement: {element.ParentElement?.Name ?? "null"}");
                }
            }
        }
Beispiel #4
0
        public void closeBounty(BasePlayer player)
        {
            //for bounty and creator
#if DEBUG
            player.ChatMessage($"closeBounty");
#endif
            GuiTracker.getGuiTracker(player).destroyGui(this, "bountyPreview");
        }
Beispiel #5
0
 public void display(BasePlayer player)
 {
     if (this.Count == 0)
     {
         return;
     }
     GuiTracker.getGuiTracker(player).addGuiToTracker(plugin, this);
     CuiHelper.AddUi(player, this);
 }
Beispiel #6
0
        public void creatorButton(BasePlayer player, createErrorType error = createErrorType.none, BountyBP bp = null)
        {
            GuiContainer c         = new GuiContainer(this, "createButton", "bountyCreator");
            Rectangle    ButtonPos = new Rectangle(710, 856, 500, 100, resX, resY, true);

            List <GuiText> textOptions = new List <GuiText>
            {
                new GuiText("Create Bounty", guiCreator.getFontsizeByFramesize(13, ButtonPos), lightGreen),
                new GuiText("Target not found!", guiCreator.getFontsizeByFramesize(17, ButtonPos), lightRed),
                new GuiText("Invalid reward!", guiCreator.getFontsizeByFramesize(15, ButtonPos), lightRed),
                new GuiText("Can't afford reward!", guiCreator.getFontsizeByFramesize(20, ButtonPos), lightRed),
                new GuiText("Reason missing!", guiCreator.getFontsizeByFramesize(15, ButtonPos), lightRed)
            };

            Action <BasePlayer, string[]> cb = (p, a) =>
            {
                if (bp.target == null)
                {
                    Effect.server.Run(errorSound, player.transform.position);
                    creatorButton(player, createErrorType.missingTarget, bp);
                }
                else if (bp.reward == 0)
                {
                    Effect.server.Run(errorSound, player.transform.position);
                    creatorButton(player, createErrorType.badReward, bp);
                }
                else if (config.requireReason && string.IsNullOrEmpty(bp.reason))
                {
                    Effect.server.Run(errorSound, player.transform.position);
                    creatorButton(player, createErrorType.missingReason, bp);
                }
                else
                {
                    Effect.server.Run(successSound, player.transform.position);
                    bp.init(player);
                    GuiTracker.getGuiTracker(player).destroyGui(this, "bountyCreator");
                }
            };

            c.addPlainButton("button", ButtonPos, GuiContainer.Layer.hud, (error == createErrorType.none) ? darkGreen : darkRed, FadeIn, FadeOut, textOptions[(int)error], cb, blur: GuiContainer.Blur.medium);
            c.display(player);

            if (error != createErrorType.none)
            {
                PluginInstance.timer.Once(2f, () =>
                {
                    if (GuiTracker.getGuiTracker(player).getContainer(this, "bountyCreator") != null)
                    {
                        creatorButton(player, bp: bp);
                    }
                });
            }
        }
Beispiel #7
0
        private void Unload()
        {
            foreach (BasePlayer player in BasePlayer.activePlayerList)
            {
                GuiTracker.getGuiTracker(player).destroyAllGui();
            }

            PluginInstance      = null;
            GuiContainer.blurs  = null;
            GuiContainer.layers = null;
            _DownloadManager    = null;
        }
Beispiel #8
0
            public static GuiTracker getGuiTracker(BasePlayer player)
            {
                GuiTracker output = null;

                player.gameObject.TryGetComponent <GuiTracker>(out output);

                if (output == null)
                {
                    output        = player.gameObject.AddComponent <GuiTracker>();
                    output.player = player;
                }

                return(output);
            }
Beispiel #9
0
        private void SendEntry(BasePlayer player, KeyValuePair <BasePlayer, PlayerSummary> kvp, int count, int sizeEach, int gap, Action <BasePlayer> callback)
        {
            if (GuiTracker.getGuiTracker(player).getContainer(PluginInstance, "PlayerSearch") == null)
            {
                return;
            }

            GuiColor black60 = new GuiColor(0, 0, 0, 0.6f);
            GuiColor black40 = new GuiColor(0, 0, 0, 0.4f);
            GuiColor white70 = new GuiColor(1, 1, 1, 0.7f);

            GuiContainer c = new GuiContainer(PluginInstance, $"{count}ImageContainer", "PlayerSearch");

            //background
            Rectangle entryBgPos = new Rectangle(715, 360 + count * (sizeEach + gap), 490, 80, 1920, 1080, true);

            c.addPlainPanel($"{count}EntryBG", entryBgPos, GuiContainer.Layer.overall, black60, 0.2f, 0);

            //ID
            Rectangle idPos  = new Rectangle(795, 365 + count * (sizeEach + gap), 405, 35, 1920, 1080, true);
            GuiText   idText = new GuiText($"[{kvp.Key.userID}]", 14, white70);

            c.addText($"{count}id", idPos, GuiContainer.Layer.overall, idText, 0.2f, 0);

            //Name
            Rectangle namePos  = new Rectangle(795, 400 + count * (sizeEach + gap), 405, 35, 1920, 1080, true);
            GuiText   nameText = new GuiText($"{kvp.Key.displayName}", getFontsizeByFramesize(kvp.Key.displayName.Length, namePos), white70);

            c.addText($"{count}name", namePos, GuiContainer.Layer.overall, nameText, 0.2f, 0);

            //button
            Action <BasePlayer, string[]> buttonCb = (p2, a) =>
            {
                GuiTracker.getGuiTracker(player).destroyGui(PluginInstance, "PlayerSearch");
                callback(kvp.Key);
            };

            c.addPlainButton($"{count}btnOverlay", entryBgPos, GuiContainer.Layer.overall, new GuiColor(0, 0, 0, 0), 0.2f, 0, callback: buttonCb, CursorEnabled: true);

            Rectangle imgPos = new Rectangle(720, 365 + count * (sizeEach + gap), 70, 70, 1920, 1080, true);

            c.addButton($"{count}Image", imgPos, GuiContainer.Layer.overall, null, 0.2f, 0, callback: buttonCb, close: "PlayerSearch", imgName: kvp.Key.UserIDString);

            c.display(player);
        }
Beispiel #10
0
            private void SendButton()
            {
                GuiContainer c = new GuiContainer(PluginInstance, "Ok", nameof(ColorPicker));

                Rectangle pos   = new Rectangle(1160, 540, 150, 60, resX, resY, true);
                GuiColor  color = new GuiColor(0, 1, 0, 0.5f);
                GuiText   text  = new GuiText("OK", 30, GuiColor.White.withAlpha(0.7f));

                Action <BasePlayer, string[]> callback = (p, a) =>
                {
                    Callback?.Invoke(new GuiColor(Hue, Value, Saturation, 1));
                    GuiTracker.getGuiTracker(Player).destroyGui(PluginInstance, nameof(ColorPicker));
                };

                c.addPlainButton("button", pos, layer, color, fadeIn, fadeOut, text, callback);

                c.display(Player);
            }
Beispiel #11
0
        public void closeIndicators(BasePlayer player)
        {
#if DEBUG
            player.ChatMessage($"closeIndicators: {player.displayName}");
#endif
            try
            {
                GuiTracker.getGuiTracker(player).destroyGui(this, "hunterIndicator");
            }
            catch (Exception e)
            {
                Puts(e.Message);
            }
            try
            {
                GuiTracker.getGuiTracker(player).destroyGui(this, "targetIndicator");
            }
            catch (Exception e)
            {
                Puts(e.Message);
            }
        }
Beispiel #12
0
        public void customGameTip(BasePlayer player, string text, float duration = 0, gametipType type = gametipType.gametip)
        {
            GuiTracker.getGuiTracker(player).destroyGui(this, "gameTip");

            GuiContainer container = new GuiContainer(this, "gameTip");

            switch (type)
            {
            case gametipType.gametip:
                //container.addImage("gametip", new Rectangle(375, 844, 1170, 58, 1920, 1080, true), "bgTex", GuiContainer.Layer.overall, new GuiColor("#25639BF0"), 0.5f, 1);
                container.addPlainPanel("gametip", new Rectangle(375, 844, 1170, 58, 1920, 1080, true), GuiContainer.Layer.overall, new GuiColor("#25639BF4"), 0.5f, 1, GuiContainer.Blur.greyout);
                container.addText("gametip_txt", new Rectangle(433, 844, 1112, 58, 1920, 1080, true), GuiContainer.Layer.overall, new GuiText(text, 20, new GuiColor("#FFFFFFD9")), 0.5f, 1);
                container.addImage("gametip_icon", new Rectangle(375, 844, 58, 58, 1920, 1080, true), "gameTipIcon", GuiContainer.Layer.overall, new GuiColor("#FFFFFFD9"), 0.5f, 1);
                break;

            case gametipType.warning:
                container.addPlainPanel("gametip", new Rectangle(375, 844, 1170, 58, 1920, 1080, true), GuiContainer.Layer.overall, new GuiColor("#DED502F0"), 0.5f, 1);
                container.addText("gametip_txt", new Rectangle(433, 844, 1112, 58, 1920, 1080, true), GuiContainer.Layer.overall, new GuiText(text, 20, new GuiColor("#000000D9")), 0.5f, 1);
                container.addImage("gametip_icon", new Rectangle(375, 844, 58, 58, 1920, 1080, true), "warning_alpha", GuiContainer.Layer.overall, new GuiColor("#FFFFFFD9"), 0.5f, 1);
                break;

            case gametipType.error:
                //container.addImage("gametip", new Rectangle(375, 844, 1170, 58, 1920, 1080, true), "bgTex", GuiContainer.Layer.overall, new GuiColor("#BB0000F0"), 0.5f, 1);
                container.addPlainPanel("gametip", new Rectangle(375, 844, 1170, 58, 1920, 1080, true), GuiContainer.Layer.overall, new GuiColor("#BB0000F0"), 0.5f, 1, GuiContainer.Blur.greyout);
                container.addText("gametip_txt", new Rectangle(433, 844, 1112, 58, 1920, 1080, true), GuiContainer.Layer.overall, new GuiText(text, 20, new GuiColor("#FFFFFFD9")), 0.5f, 1);
                container.addImage("gametip_icon", new Rectangle(375, 844, 58, 58, 1920, 1080, true), "white_cross", GuiContainer.Layer.overall, new GuiColor("#FFFFFFD9"), 0.5f, 1);
                break;
            }

            if (duration != 0)
            {
                Timer closeTimer = timer.Once(duration, () =>
                {
                    GuiTracker.getGuiTracker(player).destroyGui(this, container);
                });
                container.timers.Add(closeTimer);
            }
            container.display(player);
        }
Beispiel #13
0
        private void dropdownAddNew(Plugin plugin, BasePlayer player, Rectangle rectangle, Action <string> callback, Predicate <string> predicate)
        {
            GuiContainer container = new GuiContainer(this, "dropdown_addNew", "dropdown_API");
            Action <BasePlayer, string[]> inputCallback = (bPlayer, input) =>
            {
                if (input.Length == 0)
                {
                    return;
                }
                GuiTracker.getGuiTracker(player).destroyGui(PluginInstance, "dropdown_addNew");
                StringBuilder newName = new StringBuilder();
                int           i       = 1;
                foreach (string s in input)
                {
                    newName.Append(s);
                    if (i != input.Length)
                    {
                        newName.Append(" ");
                    }
                    i++;
                }

                if (predicate != null)
                {
                    if (!predicate(newName.ToString()))
                    {
                        prompt(player, "Your input is invalid!", "INVALID INPUT");
                        dropdownAddNew(plugin, player, rectangle, callback, predicate);
                        return;
                    }
                }
                callback(newName.ToString());
                GuiTracker.getGuiTracker(player).destroyGui(PluginInstance, container);
            };

            container.addInput("dropdown_addNew_input", rectangle, inputCallback, GuiContainer.Layer.menu, null, new GuiColor("white"), 15, new GuiText("", color: new GuiColor("black")), 0, 0);
            container.display(player);
        }
Beispiel #14
0
        public void sendCreator(BasePlayer player)
        {
#if DEBUG
            player.ChatMessage($"sendCreator");
#endif
            BountyBP     bp = new BountyBP();
            GuiContainer c  = new GuiContainer(this, "bountyCreator");

            //template
            Rectangle templatePos = new Rectangle(623, 26, 673, 854, resX, resY, true);
            c.addImage("template", templatePos, "bounty_template", GuiContainer.Layer.hud, FadeIn: FadeIn, FadeOut: FadeOut);

            //targetName
            Rectangle targetNamePos      = new Rectangle(680, 250, 100, 53, resX, resY, true);
            Rectangle targetNamePosInput = new Rectangle(780, 250, 460, 53, resX, resY, true);
            c.addText("targetNameHeader", targetNamePos, GuiContainer.Layer.hud, new GuiText("Target:", 20), FadeIn, FadeOut);
            Action <BasePlayer, string[]> targetNameCB = (p, a) =>
            {
                if (a.Length < 1)
                {
                    return;
                }
                BasePlayer target = findPlayer(a[0], player);
                if (target == null)
                {
                    Effect.server.Run(errorSound, player.transform.position);
                    creatorButton(player, createErrorType.missingTarget, bp);
                    return;
                }
                bp.target = target;
                GuiTracker.getGuiTracker(player).destroyGui(this, c, "targetName");
                int          fontsize       = guiCreator.getFontsizeByFramesize(target.displayName.Length, targetNamePosInput);
                GuiText      targetNameText = new GuiText(target.displayName, fontsize);
                GuiContainer c2             = new GuiContainer(this, "tfound", "bountyCreator");
                c2.addText("targetName", targetNamePosInput, GuiContainer.Layer.hud, targetNameText, FadeIn, FadeOut);
                c2.display(player);
                Effect.server.Run(successSound, player.transform.position);

                //image
                if (config.showSteamImage)
                {
                    GetSteamUserData(target.userID, (ps) =>
                    {
                        guiCreator.registerImage(this, target.userID.ToString(), ps.avatarfull, () =>
                        {
                            Rectangle imagePos = new Rectangle(828, 315, 264, 264, resX, resY, true);
                            GuiContainer c3    = new GuiContainer(this, "image", "bountyCreator");
                            c3.addImage("image", imagePos, target.userID.ToString(), GuiContainer.Layer.hud, FadeIn: FadeIn, FadeOut: FadeOut);
                            c3.display(player);
                            player.ChatMessage("sent image");
                        });
                    });
                }
            };
            c.addInput("targetName", targetNamePosInput, targetNameCB, GuiContainer.Layer.hud, panelColor: new GuiColor("white"), text: new GuiText("", 20, new GuiColor("black")), FadeOut: FadeOut, FadeIn: FadeIn);

            //reward
            ItemDefinition itemDefinition          = ItemManager.FindItemDefinition(config.currency);
            Rectangle      rewardPosInput          = new Rectangle(828, 579, 132, 53, resX, resY, true);
            Rectangle      rewardPosCurrency       = new Rectangle(970, 579, 122, 53, resX, resY, true);
            Action <BasePlayer, string[]> rewardCB = (p, a) =>
            {
                if (a.Length < 1)
                {
                    return;
                }
                int reward = 0;
                if (!int.TryParse(a[0], out reward))
                {
                    Effect.server.Run(errorSound, player.transform.position);
                    creatorButton(player, createErrorType.badReward, bp);
                    return;
                }
                if (reward < config.minReward)
                {
                    Effect.server.Run(errorSound, player.transform.position);
                    creatorButton(player, createErrorType.badReward, bp);
                    return;
                }
                if (player.inventory.GetAmount(itemDefinition.itemid) < reward)
                {
                    Effect.server.Run(errorSound, player.transform.position);
                    creatorButton(player, createErrorType.cantAfford, bp);
                    return;
                }
                bp.reward = reward;
                GuiTracker.getGuiTracker(player).destroyGui(this, c, "reward");
                GuiContainer c2 = new GuiContainer(this, "rewardok", "bountyCreator");
                c2.addText("reward", rewardPosInput, GuiContainer.Layer.hud, new GuiText(reward.ToString(), 24, align: TextAnchor.MiddleRight), FadeIn, FadeOut);
                c2.display(player);
                Effect.server.Run(successSound, player.transform.position);
            };
            c.addInput("reward", rewardPosInput, rewardCB, GuiContainer.Layer.hud, panelColor: new GuiColor("white"), text: new GuiText("", 22, new GuiColor("black")), FadeOut: FadeOut, FadeIn: FadeIn);
            c.addText("rewardCurrency", rewardPosCurrency, GuiContainer.Layer.hud, new GuiText(itemDefinition.displayName.english, 24, new GuiColor("black"), TextAnchor.MiddleLeft), FadeIn, FadeOut);

            //reason
            Rectangle reasonPos      = new Rectangle(680, 681, 100, 53, resX, resY, true);
            Rectangle reasonPosInput = new Rectangle(780, 681, 460, 53, resX, resY, true);
            c.addText("reasonHeader", reasonPos, GuiContainer.Layer.hud, new GuiText("Reason:", 20), FadeIn, FadeOut);
            Action <BasePlayer, string[]> reasonCB = (p, a) =>
            {
                if (a.Length < 1)
                {
                    return;
                }
                StringBuilder sb = new StringBuilder();
                foreach (string s in a)
                {
                    sb.Append($"{s} ");
                }
                bp.reason = sb.ToString().Trim();
            };
            c.addInput("reason", reasonPosInput, reasonCB, GuiContainer.Layer.hud, panelColor: new GuiColor("white"), text: new GuiText("", 14, new GuiColor("black")), FadeOut: FadeOut, FadeIn: FadeIn);

            //placerName
            Rectangle placerNamePos  = new Rectangle(680, 771, 560, 36, resX, resY, true);
            GuiText   placerNameText = new GuiText(player.displayName, guiCreator.getFontsizeByFramesize(player.displayName.Length, placerNamePos));
            c.addText("placerName", placerNamePos, GuiContainer.Layer.hud, placerNameText, FadeIn, FadeOut);

            //exitButton
            Rectangle closeButtonPos = new Rectangle(1296, 52, 60, 60, resX, resY, true);
            c.addButton("close", closeButtonPos, GuiContainer.Layer.hud, darkRed, FadeIn, FadeOut, new GuiText("X", 24, lightRed), blur: GuiContainer.Blur.medium);

            c.display(player);

            //button
            creatorButton(player, bp: bp);
        }
Beispiel #15
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 #16
0
 private object OnPlayerWound(BasePlayer player)
 {
     GuiTracker.getGuiTracker(player).destroyAllGui();
     return(null);
 }
Beispiel #17
0
 private void closeUi(ConsoleSystem.Arg arg)
 {
     GuiTracker.getGuiTracker(arg.Player()).destroyAllGui();
 }
Beispiel #18
0
 private void OnPlayerDisconnected(BasePlayer player, string reason)
 {
     GuiTracker.getGuiTracker(player).destroyAllGui();
 }
Beispiel #19
0
 private object OnPlayerDeath(BasePlayer player, HitInfo info)
 {
     GuiTracker.getGuiTracker(player).destroyAllGui();
     return(null);
 }
Beispiel #20
0
        public void huntButton(BasePlayer player, Bounty bounty, huntErrorType error = huntErrorType.none)
        {
            GuiContainer c         = new GuiContainer(this, "huntButton", "bountyPreview");
            Rectangle    ButtonPos = new Rectangle(710, 856, 500, 100, resX, resY, true);

            List <GuiText> textOptions = new List <GuiText>
            {
                new GuiText("Start Hunting", guiCreator.getFontsizeByFramesize(13, ButtonPos), lightGreen),
                new GuiText("You are already hunting", guiCreator.getFontsizeByFramesize(23, ButtonPos), lightRed),
                new GuiText("Target is already being hunted", guiCreator.getFontsizeByFramesize(30, ButtonPos), lightRed),
                new GuiText("Target can't be hunted yet", guiCreator.getFontsizeByFramesize(26, ButtonPos), lightRed),
                new GuiText("Hunt Active", guiCreator.getFontsizeByFramesize(11, ButtonPos), lightRed),
                new GuiText("You can't hunt yourself!", guiCreator.getFontsizeByFramesize(24, ButtonPos), lightRed),
                new GuiText("Target is offline", guiCreator.getFontsizeByFramesize(17, ButtonPos), lightRed),
                new GuiText("Too close to the target!", guiCreator.getFontsizeByFramesize(24, ButtonPos), lightRed),
            };

            Action <BasePlayer, string[]> cb = (p, a) =>
            {
                TimeSpan targetCooldown   = TimeSpan.Zero;
                TimeSpan creationCooldown = new TimeSpan(0, 0, config.creationCooldown - (int)bounty.timeSinceCreation.TotalSeconds);
                if (error == huntErrorType.huntActive)
                {
                    return;
                }
                else if (bounty.target == null)
                {
                    Effect.server.Run(errorSound, player.transform.position);
                    huntButton(player, bounty, huntErrorType.offline);
                }
                else if (bounty.target.IsSleeping())
                {
                    Effect.server.Run(errorSound, player.transform.position);
                    huntButton(player, bounty, huntErrorType.offline);
                }
                else if (bounty.hunt != null || HuntData.getHuntByHunter(p) != null)
                {
                    Effect.server.Run(errorSound, player.transform.position);
                    huntButton(player, bounty, huntErrorType.hunterAlreadyHunting);
                }
                else if (HuntData.getHuntByTarget(bounty.target) != null)
                {
                    Effect.server.Run(errorSound, player.transform.position);
                    huntButton(player, bounty, huntErrorType.targetAlreadyHunted);
                }
                else if ((bounty.timeSinceCreation.TotalSeconds < config.creationCooldown || CooldownData.isOnCooldown(bounty.target, out targetCooldown)) && !hasPermission(player, permissions.admin))
                {
                    Effect.server.Run(errorSound, player.transform.position);
                    huntButton(player, bounty, huntErrorType.targetCooldown);
                    TimeSpan select = creationCooldown;
                    if (targetCooldown > creationCooldown)
                    {
                        select = targetCooldown;
                    }
                    player.ChatMessage($"Cooldown: {select.ToString(@"hh\:mm\:ss")}");
                }
                else if (bounty.target == player && !hasPermission(player, permissions.admin))
                {
                    Effect.server.Run(errorSound, player.transform.position);
                    huntButton(player, bounty, huntErrorType.selfHunt);
                }
                else if (Vector3.Distance(player.transform.position, bounty.target.transform.position) < config.safeDistance && !hasPermission(player, permissions.admin))
                {
                    Effect.server.Run(errorSound, player.transform.position);
                    huntButton(player, bounty, huntErrorType.tooClose);
                }
                else
                {
                    Effect.server.Run(successSound, player.transform.position);
                    bounty.startHunt(p);
                    BountyData.removeBounty(bounty.noteUid);
                    player.GetActiveItem()?.Remove();
                    closeBounty(player);
                }
            };

            c.addPlainButton("button", ButtonPos, GuiContainer.Layer.hud, (error == huntErrorType.none)?darkGreen:darkRed, FadeIn, FadeOut, textOptions[(int)error], cb, blur: GuiContainer.Blur.medium);
            c.display(player);

            if (error != huntErrorType.none && error != huntErrorType.huntActive)
            {
                PluginInstance.timer.Once(2f, () =>
                {
                    if (GuiTracker.getGuiTracker(player).getContainer(this, "bountyPreview") != null)
                    {
                        huntButton(player, bounty);
                    }
                });
            }
        }
Beispiel #21
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
        }
Beispiel #22
0
 public void destroy(BasePlayer player)
 {
     GuiTracker.getGuiTracker(player).destroyGui(plugin, this);
 }