A-hem...
Okey, I started with something similar but then I found much simpler way to do it, but I still have one problem which, as I can say just by looking at it, would remain if I used your code.
In game.script I define a variable DePressed which has the same function as yours ClickStarted, and then on LeftClick:
on "LeftClick"
{
DePressed = true;
// what did we click?
var ActObj = Game.ActiveObject;
if(ActObj!=null)
{
// clicking an inventory item
if(ActObj.Type=="item" && Game.SelectedItem==null)
{
Game.SelectedItem = ActObj;
}
// using an inventory item on another object
else if(Game.SelectedItem != null && Game.SelectedItem!=ActObj)
{
var Item = Game.SelectedItem;
if(ActObj.CanHandleEvent(Item.Name)) ActObj.ApplyEvent(Item.Name);
else if(Item.CanHandleEvent("default-use")) Item.ApplyEvent("default-use");
else if(ActObj.CanHandleEvent("default-use")) ActObj.ApplyEvent("default-use");
else actor.Talk("Ne mogu to uciniti!");
}
else if(ActObj.CanHandleEvent("Take") || ActObj.CanHandleEvent("Talk") || ActObj.CanHandleEvent("LookAt"))
{
// THIS IS THE IMPORTANT STUFF!
MenuObject = Game.ActiveObject;
var Caption = WinMenu.GetWidget("caption");
Caption.Text = MenuObject.Caption;
Sleep(300);
if (DePressed == true)
{
// adjust menu's position
WinMenu.X = Game.MouseX - WinMenu.Width / 2;
if(WinMenu.X < 0) WinMenu.X = 0;
if(WinMenu.X+WinMenu.Width>Game.ScreenWidth) WinMenu.X = Game.ScreenWidth-WinMenu.Width;
WinMenu.Y = Game.MouseY - WinMenu.Height / 2;
if(WinMenu.Y<0) WinMenu.Y = 0;
if(WinMenu.Y+WinMenu.Height>Game.ScreenHeight) WinMenu.Y = Game.ScreenHeight-WinMenu.Height;
WinMenu.Visible = true;
actor.Reset();
}
else
{
actor.GoToObject(ActObj);
}
}
// just a simple click
else ActObj.ApplyEvent("LeftClick");
}
// else propagate the LeftClick event to a scene
else
{
Scene.ApplyEvent("LeftClick");
}
if(Game.InventoryVisible == true) Game.InventoryVisible = false;
}
As you can see, everything is practicaly template stuff, except that if I see that the active object can handle verbs, I do a Sleep, and then check if DePressed is still true. If it is I show the verb bar. Now, I am wondering if that is safe to do. The test project I am working on is very simple so I don't want for this to back fire on me in more complicated scenes. I am afraid that doing a Sleep in such a shortlived event such as LeftClick could screw something up with rest of the stuff going on at the same time.
Here is the LeftRelease:
on "LeftRelease"
{
DePressed = false;
}
Now, with this I managed to get the verb bar to show. However, the player still needs to actualy CLICK on the verb. In Project Joe, however, one has to RELEASE the button over the verb and then stuff happens. I tried to do this...
DePressed = false;
if (WinMenu.Visible==true)
{
WinMenu.ApplyEvent("LeftClick");
WinMenu.Visible=false;
}
If WinMenu is visible, I tried to simulate the LeftClick on what ever verb has the focus, but this doesn't work.
Now, if I am way off track tell me, but if not, I think this is a very simple way to do this kind of thing, if I could just wrap it up with correct Release handling.
What I am looking for, I guess, is a way to reference a focused button on a Window and then ApplyEvent it on a active object...