SOLVED: Changing Mouse Mode graphic from Gui

Started by Slasher, Sun 08/12/2013 17:12:47

Previous topic - Next topic

Slasher

Hi,

I am in the middle of something and looking for a hand.

I have a gui that changes mouse to pointer. On this gui image buttons appear when conditions are met.

What I am looking for is a way to determine which button has been pressed (like IsKeyPressed) so that events will run depending on which gui image has been clicked.

Example: you click on an object in the room, that object image shows up on the gui, you click that gui image and the mouse mode changes to TalkTo with that image graphic sprite. Clicking on an object (npc) with that graphic causes events to run relating to the graphic button selected. When these events have finished the mouse mode returns to normal default graphic.

Hope you can understand this.

can you help please?

EDIT: 100% working so far, more to do, fingers crossed (nod)






monkey0506

Quote from: slasher on Sun 08/12/2013 17:12:47EDIT: 100% working so far, more to do, fingers crossed (nod)

I have no idea whether this means that the issue has been solved or not. You can't just say "working so far, more to do" without telling what it is that you have done to try and remedy the situation. At least, if you did just say that (and only that), then you can't reasonably expect us to have any idea what it is you're going on about. I'm posting on the assumption that you haven't figured out the solution to your question. That said, I don't even know what the question was to begin with.

You said that you are clicking on a GUI and trying to determine which "button" was pressed, so I'll assume you mean either Button (a GUIControl) or MouseButton (an enum of the mouse buttons).

Every GUIControl (including Button controls) have event handlers that are registered the same way as character/hotspot/object/etc. event handlers, from the Events pane (lightning icon when the item is selected in the Properties pane). By default, the editor attempts to create a unique event handler for each GUIControl based on its name (e.g., when there is no existing event handler and you click the ellipses (...) button). You have the option of supplying your own event handler, which can be used to pass several events to the same handler (say if you want a single function to handle all the events for a certain group of GUIControls).

The latter of those is less common, but for what it's worth, GUIControl event handlers all take a GUIControl* as the first parameter, which is the control activating/triggering the event. GUIControl click handlers (e.g., for a Button control) take a MouseButton as the second parameter, which tells you which button was used to click on the control (eMouseLeft or eMouseRight).

The quite probably patronizing explanations out of the way, you can tell "which button has been pressed" by examining the GUIControl* and MouseButton parameters in the event handler. The handler itself may also be leading, but your question is somewhat ambiguous.

monkey0506

Double posting intentionally for some hope of clarity and distinction between this and my last post, but upon re-reading the OP several times, it seems that I might have an idea of what you're trying to do.

Quote from: slasher on Sun 08/12/2013 17:12:47you click that gui image and the mouse mode changes to TalkTo with that image graphic sprite

This seriously sounds like all you want to do is have the GUI Button set the cursor mode instead of running a script event. There's an option for how clicking the Button should be handled in its Properties.

Slasher

#3
Hi Monkey,

The reason I did not declare as solved is because I did not want to jump the gun before I was 100% satisfied with the results of my efforts.

Here is a brief example (working) explanation:

Clicking on the selected button changes not only the mouse mode to Talkto but also its image:


When the Talkto cursor image is clicked on an npc / object it runs Talkto events relating to the cursor image selected:


When a Talkto event is over the cursor returns to default Talkto image until button image is again selected.

There could of course be 6 / 8 different buttons to choose from.

Hope this explains my post better and that there is a 'cleaner' script that could be adopted.

cheers ;)


EDIT:

Thought I would add scripts that I have as they all seem to work ok.

All the below are 'examples' only.

It all starts when you start looking at Hotspots.
Code: ags

function hHotspot3_Look()  // Wine Bottle
{
 LookAtThings();
 cnico.Say("That's a bottle of Chablis. That's the best wine there is.");

 if(cnico.Room==7 && Bmm.Visible==true)
 {
  Bwine.NormalGraphic=931; // Button Image added to gBottom
  Bwine.Visible=true;
  } 
  else if(cnico.Room==7 && Bmm.Visible==false)
  {
  Bmm.NormalGraphic=931; // Button Image added to gBottom
  Bmm.Visible=true;
  }
  }


function hHotspot4_Look() // Marilyn Monroe
{
 LookAtThings();
 cnico.Say("That's Marilyn Monroe.");

 if(cnico.Room==7 && Bmm.Visible==true)
 {
 Bwine.NormalGraphic=857; // Button Image added to gBottom
 Bwine.Visible=true;
 } 
 else if(cnico.Room==7 && Bmm.Visible==false)
 {
 Bmm.NormalGraphic=857; // Button Image added to gBottom
 Bmm.Visible=true;
 }
 }


When clicking on a Button Image of gBottom:
Code: ags

function Bwine_OnClick(GUIControl *control, MouseButton button)
{

  if(cnico.Room==7 && Bwine.Visible==true && Bwine.NormalGraphic==931)
  {
  
  mouse.ChangeModeGraphic(3, 931);
  mouse.Mode=eModeTalkto; 
  } 
  else if(cnico.Room==7 && Bwine.Visible==true && Bwine.NormalGraphic==857)
  {
  mouse.ChangeModeGraphic(3, 857);
  mouse.Mode=eModeTalkto;
  }
  }


function Bmm_OnClick(GUIControl *control, MouseButton button)
{
 if(cnico.Room==7 && Bmm.NormalGraphic==857)
 {
  mouse.ChangeModeGraphic(3, 857);
  mouse.Mode=eModeTalkto;
 }
 
 else if(cnico.Room==7 && Bmm.NormalGraphic==931)
 {
  mouse.ChangeModeGraphic(3, 931);
  mouse.Mode=eModeTalkto;
  }
  }


When Talking to NPC (Object). There is 3 in all.
Code: ags

function ofandigo_Talk()
{
  
 if(cnico.Room==7 && mouse.GetModeGraphic(eModeTalkto) == 857) // Button/cursor Image of Marilyn Monroe
 {
 
 cnico.Loop=1;
 cnico.Say("Excuse me.");
 ofandigo.SetView(13);
 ofandigo.Animate(3, 4, eRepeat, eNoBlock);
 cFrankm.SayAt(308, 229, 250, "What do you want lady?");
 ofandigo.SetView(13, 4, 0);
 cnico.Say("Em, do you like Marilyn Monroe?");
 ofandigo.Animate(3, 4, eRepeat, eNoBlock);
 cFrankm.SayAt(308, 229, 250, "No!");
 ofandigo.SetView(13, 0, 0);
 mouse.ChangeModeGraphic(3, 361);
 mouse.Mode=eModeTalkto;
 }
 
 else if(cnico.Room==7 &&  mouse.GetModeGraphic(eModeTalkto) == 931)// Button/cursor Image of Wine
 {
   
 cnico.Loop=1;
 cnico.Say("Excuse me.");
 ofandigo.SetView(13);
 ofandigo.Animate(3, 4, eRepeat, eNoBlock);
 cFrankm.SayAt(308, 229, 250, "What do you want lady?");
 ofandigo.SetView(13, 4, 0);
 cnico.Say("Em, do you like Chablis?");
 ofandigo.Animate(3, 4, eRepeat, eNoBlock);
 cFrankm.SayAt(308, 229, 250, "Absolutely!");
 ofandigo.SetView(13, 0, 0);
 mouse.ChangeModeGraphic(3, 361);
 mouse.Mode=eModeTalkto;
 }
 else // Cursor normal default 361
 {
   
 cnico.Loop=1;
 cnico.Say("Excuse me.");
 ofandigo.SetView(13);
 ofandigo.Animate(3, 4, eRepeat, eNoBlock);
 cFrankm.SayAt(308, 229, 250, "What do you want lady?");
 ofandigo.SetView(13, 4, 0);
 cnico.Say("Em, do you have a cigarette?");
 ofandigo.Animate(3, 4, eRepeat, eNoBlock);
 cFrankm.SayAt(308, 229, 250, "No!");
 ofandigo.SetView(13, 0, 0);
 }
 }


I'm sure there is a more appropriate and less messy way of achieving this objective.

cheers



Khris

As a general hint, you should really start to nest your conditions, it'd make everything much more readable:

Code: ags
  if (conditional_A = value) {

    if (conditional_B = value) {
      // some code
    }
    else if (conditional_B = other_value) {
      // some more code
    }
    else {
      // even more code
    }
  }
  else if (conditional_A = other_value) {
    // still more code
  }
  ...


Not only is it much less error-prone and easier to debug, it will also make it easier to change things and save you lots of duplicate code.

Slasher

Hi Khris,

Yes, that makes more sense.

cheers

monkey0506

I'm still confused to no end what the original problem and question was, but it's marked as solved now so I guess that's that. Really from the pictures (and the vague, omnidirectional descriptions) I really can't help but think that this is as simple as changing the GUI Button's interaction to "Set cursor mode". But as long as this code works for you, that's generally the most important bit.

Quote from: Khris on Tue 10/12/2013 16:56:26As a general hint, you should really start to nest your conditions, it'd make everything much more readable.

Not only is it much less error-prone and easier to debug, it will also make it easier to change things and save you lots of duplicate code.

Absolutely agreed with this. Duplicate code (like checking the same condition multiple times within the same function (or what's more, the same if-else clause) without it having had any opportunity to change) is almost always an indication that you're doing something wrong.

SMF spam blocked by CleanTalk