Please login or register.

Login with username, password and session length
Advanced search  

News:

For WME related articles and tutorials visit WME Resource Center.

Author Topic: Context sensitive menu actions  (Read 6829 times)

0 Members and 1 Guest are viewing this topic.

DocBass

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 136
    • View Profile
Context sensitive menu actions
« on: August 22, 2006, 01:27:59 AM »

I'm looking to create a context sensitive menu button. The graphic would always be the same but if I tried to do an action on a fence a subtitle that says "Climb" would appear. And let's say I highlighted the action over a door it would show the subtitle "Open" or something similar. The graphic would always be something like a hand or whatnot and would light up when hovered over of course. Is this possible? I'm searching through documentation and am trying to figure this out. Thanks!
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Context sensitive menu actions
« Reply #1 on: August 22, 2006, 07:23:56 PM »

It's entirely possible. When you're opening the action menu, check if the object being manipulated supports the action, such as:

  if(ActObj.CanHandleEvent("LookAt")) ...

And then enable or disable some the action buttons. Do you need a more detailed description?
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

DocBass

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 136
    • View Profile
Re: Context sensitive menu actions
« Reply #2 on: August 23, 2006, 06:09:00 AM »

It's entirely possible. When you're opening the action menu, check if the object being manipulated supports the action, such as:

  if(ActObj.CanHandleEvent("LookAt")) ...

And then enable or disable some the action buttons. Do you need a more detailed description?

I'm not sure. I could probably figure it out if I plugged away at it like most of what I'm doing but I'm trying to strike a balance between doing things myself and not bugging you, and not getting caught up in something that could most likely be answered quickly. So it depends on if you want to take the time for a further explanation. If you can give one I would certainly appreciate it. :-)

My main confusion I suppose is that the window for the menu appears to have "static" buttons. For a caption I see you use the string that is entered in the scene editor for an object, and I thought if I could do something similar for the action button where the subtitle would display a string each object stored it would work but I had not figured out how to do that as of yet.
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Context sensitive menu actions
« Reply #3 on: August 24, 2006, 07:30:04 PM »

Ok, so... let's assume you're building your game on the default WME template.

If you look into the script\game.script, you'll find the on "RightClick" event handler. It's executed whenever the player right-clicks some some object. Notice that the script stores the clicked object in a global variable called MenuObject.

Code: [Select]
      ...
      // store the clicked object in a global variable MenuObject
      MenuObject = Game.ActiveObject;
      ...

It's convenient, because we'll need this information later.



Still in scripts\game.script, inside the on "RightClick" handler. There's a piece of code displaying the menu:

Code: [Select]
      ...
      // and show the right-click menu
      WinMenu.Visible = true;
      ...

We'll modify it to call a method inside the menu window first:

Code: [Select]
      ...
      // tell the window to disable/enable action buttons
      WinMenu.SetState();
      // and show the right-click menu
      WinMenu.Visible = true;
      ...

We added a SetState() method call. Now we'll add said method to the action window. Its script is located in interface\menu\menu.script.
Edit the script and add the following code:

Code: [Select]
method SetState()
{
var Btn;

// handle the LookAt button
Btn = this.GetControl("LookAt");
if(MenuObject.CanHandleEvent("LookAt")) Btn.Disabled = false;
else Btn.Disabled = true;

// handle the Take button
Btn = this.GetControl("Take");
if(MenuObject.CanHandleEvent("Take")) Btn.Disabled = false;
else Btn.Disabled = true;

// handle the Talk button
Btn = this.GetControl("Talk");
if(MenuObject.CanHandleEvent("Talk")) Btn.Disabled = false;
else Btn.Disabled = true;
}

This new method checks if the MenuObject (i.e. the right-clicked one) can handle certain events, and it enables or disables the menu buttons appropriately.

Whether a scene object "can handle" events is determined by the fact if their script contains even handlers such as

Code: [Select]
on "LookAt"
{
  actor.Talk("What a nice thing. I wonder what it is.");
}

And that's it. Of course, you can define your own set of "verbs", such as "climb" etc.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Context sensitive menu actions
« Reply #4 on: August 24, 2006, 07:31:19 PM »

And once you know the clicked object inside the action window script, you can use similar approach to change action buttons captions etc.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

DocBass

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 136
    • View Profile
Re: Context sensitive menu actions
« Reply #5 on: August 24, 2006, 09:57:56 PM »

Thank you so much. Your time and kindness is greatly appreciated.
Logged

DocBass

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 136
    • View Profile
Re: Context sensitive menu actions
« Reply #6 on: August 26, 2006, 07:56:27 AM »

I tried implementing this tonight and I'm not sure if I am missing something. This appears to just be how if I want to handle new buttons depending on the item. What I am thinking here is that we want to take the "take" button and display a caption that relates to the item we are interacting with. So if I hovered (and preferably only when I hover) over the "take" icon while a piece of glass is selected "Break" would appear but if I hovered over the take button with an apple it would display "pick up." Things of that nature. Did I just get it wrong?

I don't want to create a new button per se but change the caption of the take (in our case "action" button) depending on what is the selected item.
« Last Edit: August 26, 2006, 07:58:22 AM by DocBass »
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Context sensitive menu actions
« Reply #7 on: August 27, 2006, 11:38:30 AM »

It's a similar principle, really. The menu window could check if the clicked objects provides a method for setting custom action captions, and if it does, the menu window calls the method and sets the captions appropriately. Otherwise it would set some default captions. The above SetState() method would then look something like:

Code: [Select]
method SetState()
{
var Btn;

// handle the LookAt button
Btn = this.GetControl("LookAt");
if(MenuObject.CanHandleEvent("LookAt")) Btn.Disabled = false;
else Btn.Disabled = true;

if(MenuObject.CanHandleMethod("GetCaption")) Btn.Caption = MenuObject.GetCaption("LookAt");
else Btn.Caption = "Look at";

// handle the Take button
Btn = this.GetControl("Take");
if(MenuObject.CanHandleEvent("Take")) Btn.Disabled = false;
else Btn.Disabled = true;

if(MenuObject.CanHandleMethod("GetCaption")) Btn.Caption = MenuObject.GetCaption("Take");
else Btn.Caption = "Take";


// handle the Talk button
Btn = this.GetControl("Talk");
if(MenuObject.CanHandleEvent("Talk")) Btn.Disabled = false;
else Btn.Disabled = true;

if(MenuObject.CanHandleMethod("GetCaption")) Btn.Caption = MenuObject.GetCaption("Talk");
else Btn.Caption = "Talk to";
}

Notice the use of MenuObject.CanHandleMethod() to check if the object does provide such method.


In your game objects' scripts you would then include the GetCaption() method to override default action captions. For example, I put the following code to the script of the infamous Old Guy from WME demo:

Code: [Select]
method GetCaption(CaptionType)
{
switch(CaptionType)
{
case "LookAt": return "Look at Old Guy";
case "Take": return "Touch Old Guy";
case "Talk": return "Chat with Old Guy";
}
}
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

grayman

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 3
    • View Profile
Re: Context sensitive menu actions
« Reply #8 on: June 21, 2007, 12:26:20 AM »

I think what he want to do is more like this

In a scene there is a Thing, so you want to interact with this thing, so you rightclick and the menu say

takeimage lookatimage talktoimage

--------------Thing--------------

So what he want is to change the caption of the Thing and light the image

Lighting the image is done with in interface/menu/menu.window in the IMAGE_HOVER

Changing the caption could be done with the Thing.script if....
---------------------------------------------------------------------
#include "scripts\base.inc"

on "LookAt" //when we hover LookAt
{
  this.Caption= "Look at this Thing closely!"; // this was working realtime... but no, so.......
  actor.GoToObject(this);
  actor.Talk("Blah");
}

----------------------------------------------------------------------

so the cuestion is instead of ...
on "LookAt"
is there a...
hover "LookAt"

or something like that?
Logged

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Re: Context sensitive menu actions
« Reply #9 on: June 21, 2007, 07:38:53 AM »

actually caption handling is done entirely dynamical in game_daemon.script. It should be easy to change it this way. You can see my tutorial about the script here (second part of the tutorial):

http://wiki.dead-code.org/wakka.php?wakka=BasicScripts&v=2wz
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet
 

Page created in 0.101 seconds with 24 queries.