Plugin Development

From UBot Studio
(Difference between revisions)
Jump to: navigation, search
(IUBotCommand)
(Plugin Examples)
Line 113: Line 113:
 
=== Simple Commands and Functions ===
 
=== Simple Commands and Functions ===
  
==== Error Alert Command ====
+
==== Error Alert Command (Command with One Parameter) ====
  
 
<syntaxhighlight lang="csharp">
 
<syntaxhighlight lang="csharp">
Line 132: Line 132:
 
     {
 
     {
 
         // List to hold the parameters we define for our command.
 
         // List to hold the parameters we define for our command.
         private List<UBotParameter> _parameters = new List<UBotParameter>();
+
         private List<UBotParameterDefinition> _parameters = new List<UBotParameterDefinition>();
  
 
         public ErrorAlertCommand()
 
         public ErrorAlertCommand()
 
         {
 
         {
 
             // Add our parameter (Alert Text) with a String type since it is text.
 
             // Add our parameter (Alert Text) with a String type since it is text.
             _parameters.Add(new UBotParameter("Alert Text", UBotType.String));
+
             _parameters.Add(new UBotParameterDefinition("Alert Text", UBotType.String));
 
         }
 
         }
  
Line 153: Line 153:
 
         }
 
         }
  
         public void Execute(IUBotStudio ubotStudio, IEnumerable<UBotParameter> parameters)
+
         public void Execute(IUBotStudio ubotStudio, Dictionary<string, string> parameters)
 
         {
 
         {
             // Grab the first parameter and cast it as a string since our parameter is defined as a string.
+
             // Grab the value of the Alert Text parameter we defined.
            var firstParam = parameters.First();
+
             string value = parameters["Alert Text"];
             string value = (string)firstParam.Value;
+
  
 
             // Display the MessageBox with an error icon and the text given.
 
             // Display the MessageBox with an error icon and the text given.
Line 169: Line 168:
 
         }
 
         }
  
         public IEnumerable<UBotParameter> Parameters
+
         public IEnumerable<UBotParameterDefinition> ParameterDefinitions
 
         {
 
         {
 
             // We reference our parameter list we defined above here.
 
             // We reference our parameter list we defined above here.
Line 176: Line 175:
 
     }
 
     }
 
}
 
}
 
 
</syntaxhighlight>
 
</syntaxhighlight>

Revision as of 21:24, 16 October 2012

Contents

Getting Started

Plugin Interfaces

IUBotCommand

You should implement this interface when creating a new command for your plugin.

public interface IUBotCommand
{
    string CommandName { get; }
    string Category { get; }
    IEnumerable<UBotParameterDefinition> ParameterDefinitions { get; }
    void Execute(IUBotStudio ubotStudio, Dictionary<string, string> parameters);
    bool IsContainer { get; }
}

IUBotFunction

public interface IUBotFunction
{
    string FunctionName { get; }
    object ReturnValue { get; }
    UBotType ReturnValueType { get; }
    string Category { get; }
    IEnumerable<UBotParameterDefinition> ParameterDefinitions { get; }
    void Execute(IUBotStudio ubotStudio, Dictionary<string, string> parameters);
}

IUBotStudio

public interface IUBotStudio
{
    void RunScript(string script);
    void ChangeUserInterface(string name);
    IUBotCommand ContainerParent { get; set; }
    void RunContainerCommands();
    void SetVariable(string variableName, string value);
    void SetList(string listName, List<string> value);
    void SetTable(string tableName, string[,] value);
    string GetVariable(string variableName);
    List<string> GetList(string listName);
    string[,] GetTable(string tableName);
}

IEventEnabled

public interface IEventEnabled
{
    void StartEventListener();
    void StopEventListener();
}

IWizardEnabled

public interface IWizardEnabled
{
    IWizard GenerateWizard();
}

IWizard

public interface IWizard
{
    Window WizardWindow { get; }
    Dictionary<string, string> WizardValues { get; }
}

UBotParameterDefinition

public class UBotParameterDefinition
{
    public string Name { get; private set; }
    public UBotType Type { get; private set; }
    public IEnumerable<string> Options { get; set; }
    public object DefaultValue { get; set; }
 
    public UBotParameterDefinition(string name, UBotType type)
    {
        Name = name;
        Type = type;
    }
}

UBotType

public enum UBotType
{
    String,
    UBotVariable,
    UBotList,
    UBotTable
}

Plugin Examples

Simple Commands and Functions

Error Alert Command (Command with One Parameter)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UBotPlugin;
using System.Windows;
 
namespace SimpleCommands
{
    /// <summary>
    /// This command is an example of a command with one parameter. It will show a MessageBox with an error icon.
    /// Parameters: The MessageBox text to use for your error.
    /// </summary>
    public class ErrorAlertCommand : IUBotCommand
    {
        // List to hold the parameters we define for our command.
        private List<UBotParameterDefinition> _parameters = new List<UBotParameterDefinition>();
 
        public ErrorAlertCommand()
        {
            // Add our parameter (Alert Text) with a String type since it is text.
            _parameters.Add(new UBotParameterDefinition("Alert Text", UBotType.String));
        }
 
        public string Category
        {
            // This is what category our command is categorized as. 
            // If you choose something not already in the toolbox list, a new category will be created.
            get { return "Flow Commands"; }
        }
 
        public string CommandName
        {
            // The name of our node in UBot Studio.
            get { return "error alert"; }
        }
 
        public void Execute(IUBotStudio ubotStudio, Dictionary<string, string> parameters)
        {
            // Grab the value of the Alert Text parameter we defined.
            string value = parameters["Alert Text"];
 
            // Display the MessageBox with an error icon and the text given.
            MessageBox.Show(value, "Error Alert", MessageBoxButton.OK, MessageBoxImage.Error);
        }
 
        public bool IsContainer
        {
            // This command does not have any nested commands inside of it, so it is not a container command.
            get { return false; }
        }
 
        public IEnumerable<UBotParameterDefinition> ParameterDefinitions
        {
            // We reference our parameter list we defined above here.
            get { return _parameters; }
        }
    }
}
Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox