Shoutbox

a GUI for this - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: a GUI for this (/showthread.php?tid=94826)

a GUI for this by Barathrum on 06-20-2010 at 08:24 AM

code:
function OnEvent_ChatWndSendMessage(ChatWnd, Message){
  return "< " + Message + " >"
}


I would like someone to make me a GUI so you can quicky enable or disable it.


Thank you.
RE: a GUI for this by NanaFreak on 06-20-2010 at 08:58 AM

Just make a script menu toggle button? I would do it but, you should get some experience by looking it up in the documentation or in other peoples scripts (NOTE: if you do use other peoples scripts, don't just copy and paste and wonder why its not working... have a look at what they do and recode it to make it your own style).

If you still need help after you have tried doing this, post your code back up here and we will help you out [=


RE: a GUI for this by Barathrum on 06-20-2010 at 09:11 AM

I have no idea about scripting or it's documentation, I hardly even put that script together.


RE: a GUI for this by whiz on 06-20-2010 at 10:11 AM

I would have linked to the scripting documentation page, but the site seems to be down for maintenance.

quote:
Source: Scripting Documentation > Events Reference > Messenger Plus! Events > OnGetScriptMenu


The OnGetScriptMenu event is fired when some of the Messenger Plus! menus are displayed. It allows scripts to return their own menu to be added to Messenger Plus!'s one.


Syntax
Javascript code:
[string] OnGetScriptMenu(
    [enum] Location
);



Parameters

Location
[enum] A number specifying the location of the menu that triggered the event. You can use this parameter to display a different menu depending on what the current user is currently doing.  It can be one of the following values:
code:
MENULOC_CONTACTLIST (1)   Contact List
MENULOC_CHATWND (2)       Messenger Chat Window
MENULOC_MOBILEWND (3)     Mobile Device Chat Window


Return Value

An XML data string defining the script's menu. If no menu is required, return an empty string. For more information about the way to define the menu's data, see the ScriptInfo's schema documentation.


Remarks

The script's menu can be defined statically in the ScriptInfo.xml file or returned by this function is its content needs changes at runtime. If a menu is returned by this handler, it gets priority over the menu defined in ScriptInfo.xml.

If an item of the script's menu is selected by the current user, an OnEvent_MenuClicked is fired.

Messenger Plus! 4.23 and earlier: enumeration names are not available, numbers must be used instead.

Messenger Plus! 4.50 and earlier: MENULOC_MOBILEWND is not supported.


Example

Event handler generating a simple menu for the script:
Javascript code:
function OnGetScriptMenu(Location)
{
    var ScriptMenu = "<ScriptMenu>";
    ScriptMenu    +=     "<MenuEntry Id=\"MnuFeat1\">Feature 1</MenuEntry>";
    ScriptMenu    +=     "<MenuEntry Id=\"MnuFeat2\">Feature 2</MenuEntry>";
    ScriptMenu    +=     "<Separator/>";
    ScriptMenu    +=     "<MenuEntry Id=\"MnuAbout\">About...</MenuEntry>";
    ScriptMenu    += "</ScriptMenu>";
   
    return ScriptMenu;
}



RE: a GUI for this by Barathrum on 06-20-2010 at 12:06 PM

And now I'm just suposed to understand anything of this?


RE: a GUI for this by Menthix on 06-20-2010 at 12:27 PM

quote:
Originally posted by Barathrum
And now I'm just suposed to understand anything of this?
Preferably :)
RE: a GUI for this by whiz on 06-20-2010 at 12:39 PM

So far, you have your ChatWnd function:

Javascript code:
function OnEvent_ChatWndSendMessage(ChatWnd, Message)
{
    return "< " + Message + " >";
}


Firstly, we need a variable to store whether the script is enabled or not.
Javascript code:
var Enabled = false; // disabled by default

This should be global (outside of any function), so put it at the top.

We then need to modify the message function so it only occurs if the variable is true (enabled).
Javascript code:
function OnEvent_ChatWndSendMessage(ChatWnd, Message)
{
    if (Enabled)
    {
        return "< " + Message + " >";
    }
}


The script menu is written in XML, and Plus! calls the event OnGetScriptMenu() when it is opened.
Javascript code:
function OnGetScriptMenu()
{
    // return the menu
}


The script menu should take this format:
XML code:
<ScriptMenu>
    <MenuEntry Id="ItemID1">Displayed name...</MenuEntry>
    <MenuEntry Id="ItemID2" Enabled="false">Disabled item...</MenuEntry>
    <Separator/>
    <SubMenu Label="I'm a sub-menu!">
        <MenuEntry Id="ItemID3">Another item...</MenuEntry>
    </SubMenu>
</ScriptMenu>


To make the menu, we return this as a string.  Your menu will need one option, to enable or disable the script.  We can change the text based on whether the script is enabled or not.
Javascript code:
function OnGetScriptMenu()
{
    var ScriptMenu = "<ScriptMenu>";
    if (Enabled)
    {
        ScriptMenu += "<MenuEntry Id=\"Toggle\">Disable</MenuEntry>";
    }
    else
    {
        ScriptMenu += "<MenuEntry Id=\"Toggle\">Enable</MenuEntry>";
        // note the use of the same ID
    }
    ScriptMenu += "</ScriptMenu>";
    return ScriptMenu;
}


To check and process menu clicks, use the OnEvent_MenuClicked() function:
Javascript code:
function OnEvent_MenuClicked(MenuEntryId, Location, OriginWnd)
{
    if (MenuEntryId === "Toggle")
    {
        Enabled = !Enabled; // invert the value
    }
}




And so, the finished script:
Javascript code:
var Enabled = false;
 
function OnGetScriptMenu()
{
    var ScriptMenu = "<ScriptMenu>";
    if (Enabled)
    {
        ScriptMenu += "<MenuEntry Id=\"Toggle\">Disable</MenuEntry>";
    }
    else
    {
        ScriptMenu += "<MenuEntry Id=\"Toggle\">Enable</MenuEntry>";
    }
    ScriptMenu += "</ScriptMenu>";
    return ScriptMenu;
}
 
function OnEvent_MenuClicked(MenuEntryId, Location, OriginWnd)
{
    if (MenuEntryId === "Toggle")
    {
        Enabled = !Enabled;
    }
}
 
function OnEvent_ChatWndSendMessage(ChatWnd, Message)
{
    if (Enabled)
    {
        return "< " + Message + " >";
    }
}


RE: a GUI for this by Barathrum on 06-20-2010 at 12:45 PM

Oh, awesome! Thank you!