Description

Just like PlayOn Plugins, PlayOn Scripts may have user configurable options. These options are loaded and stored by PlayOn and are editable by the user through PlayOn Settings using the controls the script creates.

The Lua code to create the options controls relies on the functionality of LuaInterface to access .NET Framework System.Windows.Forms.

--[[Options

--Lua code using System.Windows.Forms controls.

EndOptions]]--

Global Objects and Methods

  Name Description
Public method string Options_Properties:Get(string name); Gets the property name and returns its value. (Note: Options_Properties:Get may also be used in the main script to retrieve the set options.)
Public method nil Options_Properties:Set(string name, string value); Sets the property name to value.
Public method nil Options_ChangeHandler:Invoke(object sender, EventArgs e); Invokes the change delegate so the options set in Options_Properties can get saved by the user by enabling the Apply button.

Example

--this will prompt our user to enter their Zipcode.
--[[Options
        --Options_Properties is a NameValueCollection of strings where you can store all your
        --options by name - notable methods are Get and Set
        --Options_ChangeHandler is the delegate you must Invoke when your options change so the
        --apply button can get enabled and they can get properly saved when clicked.

       function txtZip_TextChanged(sender, eventArgs)
               Options_Properties:Set("zipcode", txtZip.Text);
               Options_ChangeHandler:Invoke(control, EventArgs());
       end;

       --load the assemblies
       luanet.load_assembly "System.Windows.Forms"
       luanet.load_assembly "System.Drawing"

       --assign the objects (#include controls can supplant this)
       NameValueCollection = luanet.import_type "System.Collections.Specialized.NameValueCollection"
       UserControl = luanet.import_type "System.Windows.Forms.UserControl"
       TextBox = luanet.import_type "System.Windows.Forms.TextBox"
       Label = luanet.import_type "System.Windows.Forms.Label"
       Point = luanet.import_type "System.Drawing.Point"
       EventArgs = luanet.import_type "System.EventArgs"

       --create the objects
       control = UserControl();
       txtZip = TextBox();
       lblZip = Label();

       lblZip.Text = "Enter your Zipcode:";
       lblZip.Location = Point(8,8);
       lblZip.Width = 280;

       s = Options_Properties:Get("zipcode");
       if not s or s == "" then s = "90210" end
       txtZip.Text = s;
       txtZip.Location = Point(8,28);
       txtZip.Width = 280;
       txtZip.TextChanged:Add(txtZip_TextChanged);

       control.Controls:Add(txtZip);
       control.Controls:Add(lblZip);

       return control;
EndOptions]]--
			  

See Also