Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ShowCommands"/> class with the specified
        /// <see cref="History"/>.</summary>
        /// <param name="history">
        /// The <see cref="History"/> whose <see cref="History.Commands"/> to show.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="history"/> is a null reference.</exception>

        public ShowCommands(History history)
        {
            if (history == null)
            {
                ThrowHelper.ThrowArgumentNullException("history");
            }

            InitializeComponent();

            // adjust column widths of Command list view
            DependencyPropertyDescriptor.FromProperty(
                ListView.ActualWidthProperty, typeof(ListView))
            .AddValueChanged(CommandList, OnCommandWidthChanged);

            // add history commands to list view
            var items = new List <CommandListItem>(history.Commands.Count);

            foreach (Command command in history.Commands)
            {
                CommandListItem item = new CommandListItem();

                // show one-based turn index
                item.Turn = (command.Turn + 1).ToString(ApplicationInfo.Culture);

                // show faction name or identifier
                item.Faction = command.Faction.Name;

                // show command text if present
                item.CommandText = StringUtility.Validate(command, "—"); // em dash

                // count command's message events
                int messages = 0;
                foreach (Instruction instruction in command.Program)
                {
                    if (instruction is MessageInstruction)
                    {
                        ++messages;
                    }
                }

                // show message event count if positive
                item.Events = "—"; // em dash
                if (messages > 0)
                {
                    item.Events = messages.ToString(ApplicationInfo.Culture);
                }

                // store command reference
                item.Command = command;
                items.Add(item);
            }

            // use ItemsSource to enable virtualization
            CommandList.ItemsSource = items;

            // select last command, if any
            int count = CommandList.Items.Count;

            CommandList.SelectAndShow(count - 1);
        }
Esempio n. 2
0
        /// <summary>
        /// Handles the <see cref="Selector.SelectionChanged"/> event for the "Command" <see
        /// cref="ListView"/>.</summary>
        /// <param name="sender">
        /// The <see cref="Object"/> where the event handler is attached.</param>
        /// <param name="args">
        /// A <see cref="SelectionChangedEventArgs"/> object containing event data.</param>
        /// <remarks>
        /// <b>OnCommandSelected</b> updates the text box to reflect the selected command.</remarks>

        private void OnCommandSelected(object sender, SelectionChangedEventArgs args)
        {
            // clear command text box
            CommandInfo.Text = "";

            // retrieve selected command, if any
            CommandListItem item = CommandList.SelectedItem as CommandListItem;

            if (item == null)
            {
                return;
            }

            // show command text
            CommandInfo.Text = item.Command.ToString();
            CommandInfo.AppendText(Environment.NewLine);

            // show message events but suppress dialogs
            foreach (Instruction instruction in item.Command.Program)
            {
                MessageInstruction message = instruction as MessageInstruction;
                if (message != null)
                {
                    SessionExecutor.ShowMessageEvent(message, CommandInfo, false);
                }
            }
        }
Esempio n. 3
0
 public DrawCommandListItemEventArgs(Graphics graphics, CommandListItem item)
 {
     Graphics = graphics;
     Item     = item;
 }
Esempio n. 4
0
 public DrawCommandListItemEventArgs(Graphics graphics, CommandListItem item)
 {
     Graphics = graphics;
     Item = item;                
 }
Esempio n. 5
0
        public async Task CommandList(string type = "all")
        {
            EmbedBuilder hlpMag = GetMsg("MeetUp Commands", "Here are the list of commands you asked for");
            // Get All the Modules..
            List <CommandListItem> cmds = new List <CommandListItem>();

            List <Type> tps   = Assembly.GetEntryAssembly().GetTypes().ToList();
            List <Type> types = new List <Type>();

            foreach (Type t in tps)
            {
                if (typeof(CommandModuleBase).IsAssignableFrom(t))
                {
                    types.Add(t);
                }
            }

            // Now get all the commads from them :)
            foreach (Type t in types)
            {
                MemberInfo[] members = t.GetMembers();
                foreach (MemberInfo member in members)
                {
                    if (Attribute.IsDefined(member, typeof(CommandAttribute)))
                    {
                        CommandListItem cmd = new CommandListItem();
                        cmd.command  = member.GetCustomAttribute <CommandAttribute>().Text;
                        cmd.aliasmap = member.GetCustomAttribute <AliasAttribute>() != null?string.Join(',', member.GetCustomAttribute <AliasAttribute>().Aliases) : "[No alias(s)]";

                        List <RequireUserPermissionAttribute> attributes = member.GetCustomAttributes <RequireUserPermissionAttribute>().ToList();
                        foreach (RequireUserPermissionAttribute rupa in attributes)
                        {
                            if (rupa.GuildPermission == GuildPermission.Administrator)
                            {
                                cmd.isAdmin = true;
                                break;
                            }
                        }

                        cmd.summary = member.GetCustomAttribute <SummaryAttribute>() != null?member.GetCustomAttribute <SummaryAttribute>().Text : "No idea what this does...";

                        cmds.Add(cmd);
                    }
                }
            }
            //List<CommandModuleBase> types = Assembly.GetEntryAssembly().GetTypes().Where(t => t.BaseType == typeof(CommandModuleBase)).Cast<CommandModuleBase>().ToList();

            // ORder them alphabetically...
            cmds = cmds.OrderBy(c => c.command).ToList();
            if (cmds.Count > 0)
            {
                foreach (CommandListItem cmd in cmds)
                {
                    string data = $"Summary:\n{cmd.summary}\nAlias(s):\n{cmd.aliasmap}";
                    string name = "!" + cmd.command;

                    if (cmd.isAdmin)
                    {
                        name = $"{name} - [Admin Only]";
                    }

                    bool userIsAdmin = false;

                    userIsAdmin = ((IGuildUser)((SocketGuildUser)Context.User)).GuildPermissions.Administrator;

                    if (cmd.isAdmin && !userIsAdmin)
                    {
                        continue;
                    }

                    hlpMag.AddInlineField(name, data);
                }
            }

            await Context.Channel.SendMessageAsync("", false, hlpMag);
        }