Plugin Development

From UBot Studio
(Difference between revisions)
Jump to: navigation, search
(Created page with "== Getting Started == == Plugin Interfaces == === IUBotCommand === <syntaxhighlight lang="csharp"> public interface IUBotCommand { string CommandName { get; } strin...")
 
Line 110: Line 110:
  
 
=== Simple Commands and Functions ===
 
=== Simple Commands and Functions ===
 +
 +
==== Error Alert Command ====
 +
 +
<syntaxhighlight lang="csharp">
 +
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<UBotParameter> _parameters = new List<UBotParameter>();
 +
 +
        public ErrorAlertCommand()
 +
        {
 +
            // Add our parameter (Alert Text) with a String type since it is text.
 +
            _parameters.Add(new UBotParameter("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, IEnumerable<UBotParameter> parameters)
 +
        {
 +
            // Grab the first parameter and cast it as a string since our parameter is defined as a string.
 +
            var firstParam = parameters.First();
 +
            string value = (string)firstParam.Value;
 +
 +
            // 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<UBotParameter> Parameters
 +
        {
 +
            // We reference our parameter list we defined above here.
 +
            get { return _parameters; }
 +
        }
 +
    }
 +
}
 +
 +
</syntaxhighlight>

Revision as of 16:39, 15 October 2012

Contents

Getting Started

Plugin Interfaces

IUBotCommand

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

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<UBotParameter> _parameters = new List<UBotParameter>();
 
        public ErrorAlertCommand()
        {
            // Add our parameter (Alert Text) with a String type since it is text.
            _parameters.Add(new UBotParameter("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, IEnumerable<UBotParameter> parameters)
        {
            // Grab the first parameter and cast it as a string since our parameter is defined as a string.
            var firstParam = parameters.First();
            string value = (string)firstParam.Value;
 
            // 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<UBotParameter> Parameters
        {
            // We reference our parameter list we defined above here.
            get { return _parameters; }
        }
    }
}
Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox