Please login or register.

Login with username, password and session length
Advanced search  

News:

This forum provides RSS feed. To query recent posts use this url. More...


Author Topic: Project Joe GUI  (Read 4189 times)

0 Members and 1 Guest are viewing this topic.

vatre

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 9
  • vatre the unavoidable
    • View Profile
Project Joe GUI
« on: November 04, 2004, 08:57:51 PM »

OK, I guess everybody tried Project Joe. My artist insists that we should use the same principle for displaying the verb bar and inventory (hold left-click = verb bar, right-click = inv). Now, I don't really like it, but whatever. How can I do the verb bar part? I guess I still don't have a grasp on how those game.script and game_deamon.script work and interact together, and where should I start with this, but I think that solving this would really help me. I know I should do something with the timer, but where and how, beats the hell out of me... :(
Logged
• VatrE •

deadworm222

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 197
  • Wintermute Army
    • View Profile
Re: Project Joe GUI
« Reply #1 on: November 04, 2004, 09:27:27 PM »

Nope, no need to use the timer, I think. The basis of this is the "LeftClick" and "LeftRelease" events - the "LeftClick" event actually just works as a "left mouse button pressed" event.
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Project Joe GUI
« Reply #2 on: November 04, 2004, 10:10:58 PM »

Nope, no need to use the timer, I think. The basis of this is the "LeftClick" and "LeftRelease" events - the "LeftClick" event actually just works as a "left mouse button pressed" event.
Yes, exactly.


Ok, here's the code. Untested, mind you, but it should give you the idea. Basically you handle left-click and right-click in game.script and game_daemon.script is counting the time since the player left-clicked and displays the verbs window if the mouse button is being held for a specified amount of time.


game.script
Code: [Select]
#include "scripts\base.inc"

global ClickStarted;
global ClickStartTime;
global ClickObject;
global WinVerbs = Game.LoadWindow("whatever.window");

////////////////////////////////////////////////////////////////////////////////
on "LeftClick"
{
  // no object selected, apply click to scene
  if(Game.ActiveObject==null)
  {
    Scene.ApplyEvent("LeftClick");
    return;
  }

  // perform click start
  ClickObject = Game.ActiveObject;


  // do we need to show the verb window at all?   
  if(!ClickObject.CanHandleEvent("LookAt") &&
     !ClickObject.CanHandleEvent("TalkTo") &&
     !ClickObject.CanHandleEvent("Take") )
  {
  // nah, just click it
    ClickObject.ApplyEvent("LeftClick");
    ClickStarted = false;
    ClickObject = null;
  }
  else
  {
  // mark click start and remember the time
    ClickStarted = true;
    ClickStartTime = Game.CurrentTime;
  }
}



////////////////////////////////////////////////////////////////////////////////
on "LeftRelease"
{
// 'obj' is actually the verb button the mouse was over when we released the left button
  var obj = Game.ActiveObject;
  ClickStarted = false;
 
  // we are leaving the verbs window, handle the selected verb
  if(WinVerbs.Visible)
  {
  // hide the window
    WinVerbs.Visible = false;
   
    // this is necessary, because we can left-click earlier than this stuff finishes
    var TempClickObj = ClickObject;
    ClickObject = null;

    // apply the verb if the object can handle it
    if(TempClickObj.CanHandleEvent(obj.Name)) TempClickObj.ApplyEvent(obj.Name);
    else
    {
      // otherwise use default event handling
      if(obj.Name=="LookAt")
      {
        actor.Talk("Looks nice.");
      }
      else if(obj.Name=="TalkTo")
      {
        actor.Talk("Hello...");
      }
      else if (obj.Name=="Take")
      {
         actor.Talk("I won't pick that up.");
      }
    }
  }
 
  // verbcoin is NOT visible, i.e. we go for a normal click
  else if(Game.ValidObject(ClickObject))
  {
    // did we click using an inventory item?
    if(Game.SelectedItem != null && Game.SelectedItem!=ClickObject)
    {
      var item = Game.SelectedItem;
      if(ClickObject.CanHandleEvent(item.Name)) ClickObject.ApplyEvent(item.Name);
      else
      {
        // default use handlers, same as in WME demo
        if(item.CanHandleEvent("default-use")) item.ApplyEvent("default-use");
        else if (ClickObject.CanHandleEvent("default-use")) ClickObject.ApplyEvent("default-use");
        else
        {
          ClickObject = null;
          actor.Talk("I can't use these things together.");
        }
      }
    }
    // perform normal click
    else ClickObject.ApplyEvent("LeftClick");
    ClickObject = null;
  }
}


game_daemon.script
Code: [Select]

#include "scripts\base.inc"

global ClickStarted;
global ClickStartTime;
global ClickObject;
global WinVerbs;


var VerbHoldTime = 200; // in milliseconds

while(true)
{
  // handle verb coin if the the required time has passed
  if(ClickStarted && !WinVerbs.Visible && Game.CurrentTime - ClickStartTime >= VerbHoldTime && Game.Interactive && Game.SelectedItem == null)
  {
    // position the verbs window
    WinVerbs.X = Game.MouseX - 100;
    if(WinVerbs.X < 0) WinVerbs.X = 0;
    if(WinVerbs.X + WinVerbs.Width>Game.ScreenWidth) WinVerbs.X = Game.ScreenWidth - WinVerbs.Width;

    WinVerbs.Y = Game.MouseY - 100;
    if(WinVerbs.Y < 0) WinVerbs.Y = 0;
    if(WinVerbs.Y + WinVerbs.Height>Game.ScreenHeight) WinVerbs.Y = Game.ScreenHeight - WinVerbs.Height;
   
    // and display it
    WinVerbs.Visible = true;

    // if we are about to show the verbs, we tell the actor to cancel
    // whatever he was going to do
    actor.Reset();
  }
 
  // other stuff here, such as caption, inventory handling etc.


  // and go to sleep not to kill the framerate
  Sleep(20);
}
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

vatre

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 9
  • vatre the unavoidable
    • View Profile
Re: Project Joe GUI
« Reply #3 on: November 04, 2004, 10:39:43 PM »

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:

Code: [Select]
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:

Code: [Select]
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...

Code: [Select]
  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...

« Last Edit: November 04, 2004, 10:41:53 PM by vatre »
Logged
• VatrE •

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Project Joe GUI
« Reply #4 on: November 04, 2004, 11:09:22 PM »

You will need to handle the action in the release event, because that's the time when you can actually check which action button is "selected" (the mouse pointer is over it) before you hide the verbs window. Other than that, I think it should work. You eliminated the while loop using the sleep comand, but the LeftClick and LeftRelease handlers should be fairly similar to my code.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave
 

Page created in 0.047 seconds with 24 queries.