Hello,
In order to enhance XRemote and allowing a better control of buttons, I created a small plugin.
Probably that some of you may find it usefull, so I post it.
http://france.xlobby.com/plugins/XVirtualEvents.zip
This plugin allows to create conditional events (working like a switch/case) called "Virtual Events"
these events will call another Xlobby event depending on the result of a condition
One example of use is the stop button in the media player, if you are playing music, or video, you want that the button trigger a different event (either stopping music, either stopping video). Using the states feature is a possibility but I found it quite boring when you have many buttons (or if you want to use a remote)
As an extend,using plugin's variables, it allows also to show text or image in a textbox depending of a condition (Virtual Strings).
1/What are Virtual Events :
The principle is quite simple
Each Virtual event contains a "condition" and a list of possible results each associated with a xlobby event to call.
The condition is a string containing some basic functions provided by the plugin (see below)
Once the virtal event is triggered (as any event in xlobby), the plugin will evaluate the condition and will compare the result against the list of results and, if one is matching, it will call the corresponding event.
For easier use, these virtual events are stored in the XVirtualEvents events group (in the skin folder). This group is automatically created by the plugin so do not edit it . But you can also call them using the execute method of the plugin (with the virtual event name as parameter)
2/How creating Virtual events :
- Open the configuration dialog of the plugin (F2/plugins/configuration)
- on the left side, you have the list of existing virtual events.
- for creating a new one, type the name in the edit box et click "create", it will appear in the list.
- select it on the list.
- In the condition box, you can call one or several functions (see the list below). You can try to evaluate the condition (click evaluate)
- in the grid below the condition, right click to add a new result (or remove the selected)
- double click on the Result column to edit the value. This value is similar to a "case of" in a switch
- double click in the event column to show the event tree and select the event you want to call if the result matches
The event will be available next time you restart xlobby (unfortunately, there is no way to dynamicaly add an event from a plugin )
note : If there is no matching result, no event are called except if you create a special result that you must call : default
3/The conditions:
Condition can be any combination of functions, each function has the prototype :
XL.Function([ListofArgs])
You can use a function as argument of another : XL.IsEqual(XL.Screen(),menu) will return true if the current screen is menu
Note that the plugin replaces the function by its computed value, so, if you have 2 functions separated by a space, you will get a new string with the result of each function separated by a space
i.e. if you are in the music screen and you are coming from menu :
calling : XL.Screen() XL.OldScreen()
will return : music menu
4/Virtual strings:
Using the same principle you can create variable (called with plugin>XVirtualEvents>VariableName), it works the same way except that if the result matches, it is not an event that is called, but another string that is displayed (the string is stored in the second column, double click to edit it).
This string is also evaluated like the condition, so you can use the same set of functions + specific to this fiels (images and result, see below).
To configure them, simply select the string radio button on the upper right side
5/List of functions you can use in conditions or virtual strings
There are two kinds of functions : literal or boolean.
- LITERALS functions return a string (like the screen, the content of a variable,...)
XL.Variable(XlobbyVar) : returns the value of XlobbyVar (xlobbyvar must be written the same as in the skin editor)
XL.Screen() : returns the current screen
XL.OldScreen() : returns the previous screen
- BOOLEAN : returning True or False
XL.IsEqual(Arg1,Arg2) : returns True if Arg1=Arg2
XL.Or(Args1, Args2,...) : returns True if any of the args (separated by a comma) is true
XL.And(Args1, Args2,...) : returns True if all args are True
XL.Screen(name) : returns True is the current screen is "name"
Note : If you append a ! in front of a boolean functions, you invert the result :
if XL.Screen(menu) is True : !XL.Screen(menu) is False
-Specific for Virtual strings :
XL.Image(Path) : display the image found in path in the textbox (you can use absolute path or skin://)
XL.Result() : is replaced by the computed result of the condition
Hope it will be usefull.
If you have some ideas to extend this plugin(i.e. new functions), don't hesitate