Example #1
0
        public MacroListWidget(EditMacrosWindow windowController)
        {
            this.windowController = windowController;

            linkButtonFactory.fontSize = 10;
            FlowLayoutWidget topToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom);

            topToBottom.AnchorAll();
            topToBottom.Padding = new BorderDouble(3, 0, 3, 5);

            FlowLayoutWidget headerRow = new FlowLayoutWidget(FlowDirection.LeftToRight);

            headerRow.HAnchor = HAnchor.ParentLeftRight;
            headerRow.Margin  = new BorderDouble(0, 3, 0, 0);
            headerRow.Padding = new BorderDouble(0, 3, 0, 3);

            {
                string     macroPresetsLabel     = LocalizedString.Get("Macro Presets");
                string     macroPresetsLabelFull = string.Format("{0}:", macroPresetsLabel);
                TextWidget elementHeader         = new TextWidget(macroPresetsLabelFull, pointSize: 14);
                elementHeader.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                elementHeader.HAnchor   = HAnchor.ParentLeftRight;
                elementHeader.VAnchor   = Agg.UI.VAnchor.ParentBottom;
                headerRow.AddChild(elementHeader);
            }

            topToBottom.AddChild(headerRow);

            FlowLayoutWidget presetsFormContainer = new FlowLayoutWidget(FlowDirection.TopToBottom);

            {
                presetsFormContainer.HAnchor         = HAnchor.ParentLeftRight;
                presetsFormContainer.VAnchor         = VAnchor.ParentBottomTop;
                presetsFormContainer.Padding         = new BorderDouble(3);
                presetsFormContainer.BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor;
            }

            topToBottom.AddChild(presetsFormContainer);

            foreach (CustomCommands currentCommand in MacroControlsWidget.GetMacros())
            {
                FlowLayoutWidget macroRow = new FlowLayoutWidget();
                macroRow.Margin          = new BorderDouble(3, 0, 3, 3);
                macroRow.HAnchor         = Agg.UI.HAnchor.ParentLeftRight;
                macroRow.Padding         = new BorderDouble(3);
                macroRow.BackgroundColor = RGBA_Bytes.White;

                TextWidget buttonLabel = new TextWidget(currentCommand.Name);
                macroRow.AddChild(buttonLabel);

                FlowLayoutWidget hSpacer = new FlowLayoutWidget();
                hSpacer.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
                macroRow.AddChild(hSpacer);

                Button editLink = linkButtonFactory.Generate(LocalizedString.Get("edit"));
                editLink.Margin = new BorderDouble(right: 5);
                // You can't pass a foreach variable into a link function or it wall always be the last item.
                // So we make a local variable copy of it and pass that. This will get the right one.
                CustomCommands currentCommandForLinkFunction = currentCommand;
                editLink.Click += (sender, e) =>
                {
                    windowController.ChangeToMacroDetail(currentCommandForLinkFunction);
                };
                macroRow.AddChild(editLink);

                Button removeLink = linkButtonFactory.Generate(LocalizedString.Get("remove"));
                removeLink.Click += (sender, e) =>
                {
                    currentCommandForLinkFunction.Delete();
                    windowController.functionToCallOnSave(this, null);
                    windowController.ChangeToMacroList();
                };
                macroRow.AddChild(removeLink);

                presetsFormContainer.AddChild(macroRow);
            }

            Button addMacroButton = textImageButtonFactory.Generate(LocalizedString.Get("Add"), "icon_circle_plus.png");

            addMacroButton.ToolTipText = "Add a new Macro".Localize();
            addMacroButton.Click      += new EventHandler(addMacro_Click);

            Button cancelPresetsButton = textImageButtonFactory.Generate(LocalizedString.Get("Close"));

            cancelPresetsButton.Click += (sender, e) =>
            {
                UiThread.RunOnIdle(() =>
                {
                    this.windowController.Close();
                });
            };

            FlowLayoutWidget buttonRow = new FlowLayoutWidget();

            buttonRow.HAnchor = HAnchor.ParentLeftRight;
            buttonRow.Padding = new BorderDouble(0, 3);

            GuiWidget hButtonSpacer = new GuiWidget();

            hButtonSpacer.HAnchor = HAnchor.ParentLeftRight;

            buttonRow.AddChild(addMacroButton);
            buttonRow.AddChild(hButtonSpacer);
            buttonRow.AddChild(cancelPresetsButton);

            topToBottom.AddChild(buttonRow);
            AddChild(topToBottom);
            this.AnchorAll();
        }
Example #2
0
        private void HandleCommand(string text, string sender, string fromChannel, CommandOutput output, bool isTrustedUser)
        {
            string command    = text.Split(' ')[0].Substring(1);
            string parameters = "";

            if (text.IndexOf(' ') > 0)
            {
                parameters = text.Substring(text.IndexOf(' ')).Trim();
            }

            var matchedCommand = MatchCommand(command);

            // I want to keep "!add" as a command.
            if (matchedCommand.Count > 1 && matchedCommand.Contains("add"))
            {
                matchedCommand.Clear();
                matchedCommand.Add("add");
            }

            if (matchedCommand.Count == 1)
            {
                output.MatchedCommand = true;
                switch (matchedCommand[0])
                {
                case "add":
                    if (sender == "dessyreqt")
                    {
                        var newCommand = parameters.Substring(0, parameters.IndexOf(' ')).Trim();
                        var newText    = parameters.Substring(parameters.IndexOf(' ')).Trim();

                        CustomCommands.Add(newCommand, newText);
                    }
                    break;

                case "delete":
                    if (sender == "dessyreqt")
                    {
                        CustomCommands.Delete(parameters);
                    }
                    break;

                case "drops":
                    if (parameters.Length > 2)
                    {
                        output.Text.AddRange(OutputDrops(parameters));
                    }
                    break;

                case "summon":
                    var channel = SummonToChannel(parameters);

                    if (channel != "")
                    {
                        output.Text.Add(SummonToChannel(parameters));
                        output.Type = CommandType.JoinChannel;
                    }
                    break;

                case "randnum":
                case "randomnumber":
                    output.Text.Add(GetRandomNumber(parameters).ToString());
                    break;

                case "randlist":
                case "randomlist":
                case "randomizelist":
                    output.Text.Add(GetRandomList(parameters));
                    break;

                case "fight":
                    output.Text.AddRange(GetFightInfo(parameters));
                    break;

                case "addquote":
                    if (isTrustedUser && Quotes.Validate(parameters))
                    {
                        Quotes.Add(parameters);
                        output.Text.Add(string.Format("Quote added! {0} quotes in the database.", Quotes.GetCount()));
                    }
                    break;

                case "quote":
                    var quote = Quotes.GetRandom();
                    int quoteId;

                    if (parameters.Length > 0 && int.TryParse(parameters, out quoteId))
                    {
                        var tempQuote = new Quote {
                            QuoteId = quoteId, QuoteText = Quotes.Get(quoteId)
                        };
                        if (tempQuote.QuoteText != null)
                        {
                            quote = tempQuote;
                        }
                    }

                    lastQuote[fromChannel] = quote.QuoteId;
                    output.Text.Add(FormatQuote(quote));
                    break;

                case "delquote":
                    if (isTrustedUser)
                    {
                        if (parameters.Length > 0 && int.TryParse(parameters, out quoteId))
                        {
                            Quotes.Delete(quoteId);
                            output.Text.Add("That terrible quote has been deleted. Good riddance!");
                        }
                        else if (lastQuote.ContainsKey(fromChannel))
                        {
                            Quotes.Delete(lastQuote[fromChannel]);
                            output.Text.Add("That terrible quote has been deleted. Good riddance!");
                        }
                    }
                    break;

                case "insult":
                    var insultTo = GetInsultTarget(sender, fromChannel, parameters);
                    var insult   = Insults.Get();
                    output.Text.Add(string.Format("{0}, you're nothing but {1}", insultTo, insult));
                    break;

                case "compliment":
                    var complimentTo = GetInsultTarget(sender, fromChannel, parameters);
                    var compliment   = Insults.Get();
                    output.Text.Add(string.Format("{0}, you're decent for {1}", complimentTo, compliment));
                    break;

                case "listquotes":
                    if (isTrustedUser)
                    {
                        output.Text.Add(ListQuotes());
                    }
                    break;

                case "addc":
                    if (isTrustedUser)
                    {
                        var newCommand = string.Format("{0}+{1}", parameters.Substring(0, parameters.IndexOf(' ')).Trim().Replace("+", ""), fromChannel);
                        var newText    = parameters.Substring(parameters.IndexOf(' ')).Trim();

                        CustomCommands.Add(newCommand, newText);
                    }
                    break;

                case "delc":
                    if (isTrustedUser)
                    {
                        var commandName = string.Format("{0}+{1}", parameters, fromChannel);
                        CustomCommands.Delete(commandName);
                    }
                    break;
                }
            }
            else if (matchedCommand.Count == 0)
            {
                var commandOutput = CustomCommands.Get(string.Format("{0}+{1}", command, fromChannel));

                if (commandOutput != null)
                {
                    commandOutput = commandOutput.Replace("{sender}", sender);
                    commandOutput = commandOutput.Replace("{streamer}", fromChannel.Remove(0, 1));
                    commandOutput = commandOutput.Replace("{oatsavgceres}", OatsCeres.GetAvgTime());

                    output.Text.Add(commandOutput);
                }
                else if ((commandOutput = CustomCommands.Get(command)) != null)
                {
                    commandOutput = commandOutput.Replace("{sender}", sender);
                    commandOutput = commandOutput.Replace("{streamer}", fromChannel.Remove(0, 1));

                    output.Text.Add(commandOutput);
                }
            }
        }