コード例 #1
0
ファイル: BlockEditor.cs プロジェクト: zeyap/DatingStart
        protected virtual void ShowCommandMenu()
        {
            var block = target as Block;

            var flowchart = (Flowchart)block.GetFlowchart();

            GenericMenu commandMenu = new GenericMenu();

            // Build menu list
            var filteredAttributes = GetFilteredSupportedCommands(flowchart);

            foreach (var keyPair in filteredAttributes)
            {
                AddCommandOperation commandOperation = new AddCommandOperation();

                commandOperation.commandType = keyPair.Key;

                GUIContent menuItem;
                if (keyPair.Value.Category == "")
                {
                    menuItem = new GUIContent(keyPair.Value.CommandName);
                }
                else
                {
                    menuItem = new GUIContent(keyPair.Value.Category + "/" + keyPair.Value.CommandName);
                }

                commandMenu.AddItem(menuItem, false, AddCommandCallback, commandOperation);
            }

            commandMenu.ShowAsContext();
        }
コード例 #2
0
        protected static void AddCommandCallback(object obj)
        {
            AddCommandOperation commandOperation = obj as AddCommandOperation;

            Block block = commandOperation.block;

            if (block == null)
            {
                return;
            }

            Flowchart flowchart = block.GetFlowchart();

            flowchart.ClearSelectedCommands();

            Command newCommand = Undo.AddComponent(block.gameObject, commandOperation.commandType) as Command;

            block.GetFlowchart().AddSelectedCommand(newCommand);
            newCommand.parentBlock = block;
            newCommand.itemId      = flowchart.NextItemId();

            // Let command know it has just been added to the block
            newCommand.OnCommandAdded(block);

            Undo.RecordObject(block, "Set command type");
            if (commandOperation.index < block.commandList.Count - 1)
            {
                block.commandList.Insert(commandOperation.index, newCommand);
            }
            else
            {
                block.commandList.Add(newCommand);
            }
        }
コード例 #3
0
        void AddCommandCallback(object obj)
        {
            AddCommandOperation commandOperation = obj as AddCommandOperation;

            Sequence sequence = commandOperation.sequence;

            if (sequence == null)
            {
                return;
            }

            sequence.GetFungusScript().ClearSelectedCommands();

            Command newCommand = Undo.AddComponent(sequence.gameObject, commandOperation.commandType) as Command;

            sequence.GetFungusScript().AddSelectedCommand(newCommand);
            newCommand.parentSequence = sequence;

            // Let command know it has just been added to the sequence
            newCommand.OnCommandAdded(sequence);

            Undo.RecordObject(sequence, "Set command type");
            if (commandOperation.index < sequence.commandList.Count - 1)
            {
                sequence.commandList[commandOperation.index] = newCommand;
            }
            else
            {
                sequence.commandList.Add(newCommand);
            }
        }
コード例 #4
0
        protected virtual void ShowCommandMenu()
        {
            var block = target as Block;

            var flowchart = (Flowchart)block.GetFlowchart();

            // Use index of last selected command in list, or end of list if nothing selected.
            int index = -1;

            foreach (var command in flowchart.SelectedCommands)
            {
                if (command.CommandIndex + 1 > index)
                {
                    index = command.CommandIndex + 1;
                }
            }
            if (index == -1)
            {
                index = block.CommandList.Count;
            }

            GenericMenu commandMenu = new GenericMenu();

            // Build menu list
            List <System.Type> menuTypes = EditorExtensions.FindDerivedTypes(typeof(Command)).ToList();
            List <KeyValuePair <System.Type, CommandInfoAttribute> > filteredAttributes = GetFilteredCommandInfoAttribute(menuTypes);

            filteredAttributes.Sort(CompareCommandAttributes);

            foreach (var keyPair in filteredAttributes)
            {
                // Skip command type if the Flowchart doesn't support it
                if (!flowchart.IsCommandSupported(keyPair.Value))
                {
                    continue;
                }

                AddCommandOperation commandOperation = new AddCommandOperation();

                commandOperation.block       = block;
                commandOperation.commandType = keyPair.Key;
                commandOperation.index       = index;

                GUIContent menuItem;
                if (keyPair.Value.Category == "")
                {
                    menuItem = new GUIContent(keyPair.Value.CommandName);
                }
                else
                {
                    menuItem = new GUIContent(keyPair.Value.Category + "/" + keyPair.Value.CommandName);
                }

                commandMenu.AddItem(menuItem, false, AddCommandCallback, commandOperation);
            }

            commandMenu.ShowAsContext();
        }
コード例 #5
0
ファイル: BlockEditor.cs プロジェクト: zeyap/DatingStart
        //Used by GenericMenu Delegate
        protected void AddCommandCallback(object obj)
        {
            AddCommandOperation commandOperation = obj as AddCommandOperation;

            if (commandOperation != null)
            {
                AddCommandCallback(commandOperation.commandType);
            }
        }
コード例 #6
0
        protected override async Task <HttpResponse> HandleInternal(HttpRequest request)
        {
            var addCommand = await request.Body.FromJsonAsync <AddCommandRequest>();

            var addCommandOperation = new AddCommandOperation(addCommand.CommandName, addCommand.ExecutorApiKey);

            _operationApplier.EnqueueOperation(addCommandOperation);
            var result = await addCommandOperation.WaitForCompletion();

            return(result.GetResponseFromResult());
        }
コード例 #7
0
        public void NotSaveCommand_WhenUserIsNotModerator()
        {
            var mockRepo    = new Mock <IRepository>();
            var botCommands = new List <IBotCommand>();

            var addCommandOperation = new AddCommandOperation(mockRepo.Object, botCommands);

            var message = addCommandOperation.TryToExecute(GetTestEventArgs("commandWord", "response", "role", UserRole.Everyone));

            mockRepo.Verify(x => x.Create(It.IsAny <SimpleCommand>()), Times.Never);
            message.Should().Be("You need to be a moderator to add a command.");
        }
コード例 #8
0
        public void SaveCommand_GivenValidArguments()
        {
            var newCommandword = "commandWord";
            var mockRepo       = new Mock <IRepository>();
            var botCommands    = new List <IBotCommand>();

            var addCommandOperation = new AddCommandOperation(mockRepo.Object, botCommands);

            var message = addCommandOperation.TryToExecute(GetTestEventArgs(newCommandword, "response", "role", UserRole.Mod));

            mockRepo.Verify(x => x.Create(It.IsAny <SimpleCommand>()), Times.Once);
            message.Should().Contain(newCommandword);
        }
コード例 #9
0
        public void NotSaveCommand_GivenAlreadyRegisteredCommandText()
        {
            var commandResponse = "responseText";
            var commandWord     = "commandWord";
            var mockRepo        = new Mock <IRepository>();

            mockRepo.Setup(repo => repo.Single(It.IsAny <SimpleCommandPolicy>()))
            .Returns(new SimpleCommand(commandWord, commandResponse));
            var botCommands = new List <IBotCommand>();

            var addCommandOperation = new AddCommandOperation(mockRepo.Object, botCommands);

            var message = addCommandOperation.TryToExecute(GetTestEventArgs(commandWord, commandResponse, "role", UserRole.Mod));

            mockRepo.Verify(x => x.Create(It.IsAny <SimpleCommand>()), Times.Never);
            message.Should().Contain(commandWord);
        }
コード例 #10
0
        protected static void AddCommandCallback(object obj)
        {
            AddCommandOperation commandOperation = obj as AddCommandOperation;

            var block = commandOperation.block;

            if (block == null)
            {
                return;
            }

            var flowchart = (Flowchart)block.GetFlowchart();

            flowchart.ClearSelectedCommands();

            var newCommand = Undo.AddComponent(block.gameObject, commandOperation.commandType) as Command;

            block.GetFlowchart().AddSelectedCommand(newCommand);
            newCommand.ParentBlock = block;
            newCommand.ItemId      = flowchart.NextItemId();

            // Let command know it has just been added to the block
            newCommand.OnCommandAdded(block);

            Undo.RecordObject(block, "Set command type");
            if (commandOperation.index < block.CommandList.Count - 1)
            {
                block.CommandList.Insert(commandOperation.index, newCommand);
            }
            else
            {
                block.CommandList.Add(newCommand);
            }

            // Because this is an async call, we need to force prefab instances to record changes
            PrefabUtility.RecordPrefabInstancePropertyModifications(block);
        }
コード例 #11
0
        void ShowCommandMenu()
        {
            Sequence sequence = target as Sequence;
            int      index    = sequence.commandList.Count;

            GenericMenu commandMenu = new GenericMenu();

            // Build menu list
            List <System.Type> menuTypes = EditorExtensions.FindDerivedTypes(typeof(Command)).ToList();
            List <KeyValuePair <System.Type, CommandInfoAttribute> > filteredAttributes = GetFilteredCommandInfoAttribute(menuTypes);

            filteredAttributes.Sort(CompareCommandAttributes);

            foreach (var keyPair in filteredAttributes)
            {
                AddCommandOperation commandOperation = new AddCommandOperation();

                commandOperation.sequence    = sequence;
                commandOperation.commandType = keyPair.Key;
                commandOperation.index       = index;

                GUIContent menuItem;
                if (keyPair.Value.Category == "")
                {
                    menuItem = new GUIContent(keyPair.Value.CommandName);
                }
                else
                {
                    menuItem = new GUIContent(keyPair.Value.Category + "/" + keyPair.Value.CommandName);
                }

                commandMenu.AddItem(menuItem, false, AddCommandCallback, commandOperation);
            }

            commandMenu.ShowAsContext();
        }
コード例 #12
0
ファイル: BlockEditor.cs プロジェクト: nullsquid/Diviner
        protected virtual void ShowCommandMenu()
        {
            Block block = target as Block;

            Flowchart flowchart = block.GetFlowchart();

            // Use index of last selected command in list, or end of list if nothing selected.
            int index = -1;
            foreach (Command command in flowchart.selectedCommands)
            {
                if (command.commandIndex + 1 > index)
                {
                    index = command.commandIndex + 1;
                }
            }
            if (index == -1)
            {
                index = block.commandList.Count;
            }

            GenericMenu commandMenu = new GenericMenu();

            // Build menu list
            List<System.Type> menuTypes = EditorExtensions.FindDerivedTypes(typeof(Command)).ToList();
            List<KeyValuePair<System.Type, CommandInfoAttribute>> filteredAttributes = GetFilteredCommandInfoAttribute(menuTypes);

            filteredAttributes.Sort( CompareCommandAttributes );

            foreach(var keyPair in filteredAttributes)
            {
                // Skip command type if the Flowchart doesn't support it
                if (!flowchart.IsCommandSupported(keyPair.Value))
                {
                    continue;
                }

                AddCommandOperation commandOperation = new AddCommandOperation();

                commandOperation.block = block;
                commandOperation.commandType = keyPair.Key;
                commandOperation.index = index;

                GUIContent menuItem;
                if (keyPair.Value.Category == "")
                {
                    menuItem = new GUIContent(keyPair.Value.CommandName);
                }
                else
                {
                    menuItem = new GUIContent (keyPair.Value.Category + "/" + keyPair.Value.CommandName);
                }

                commandMenu.AddItem(menuItem, false, AddCommandCallback, commandOperation);
            }

            commandMenu.ShowAsContext();
        }