Right click cycles through cursors in custom GUI (Finished!)

Started by BerserkerTails, Wed 03/12/2003 17:59:54

Previous topic - Next topic

BerserkerTails

Okay okay... I'm back here... AGAIN.

I'm trying to hammer out my engine until I like it completely before moving on with my game (Which will also make life easier when it comes time to release the demo), so I need your help, AGAIN.

Thing is, with my custom inventory GUI, the cursors don't like to cycle when I press the RIGHT mouse button. So I tried working through the problem, but it didn't work. This is what I came up with:

 if (interface == 2) {
   SetGameOption (OPT_PIXELPERFECT, 0);
   ChangeCursorGraphic (6, 2057);
   ChangeCursorGraphic (2, 2061);
   DisableCursorMode (0);
   DisableCursorMode (3);
     if (button==RIGHT) {
       SetNextCursorMode ();
       }
   if (button == 3) {
     GUIOn (1);
     GUIOff (2);
     EnableCursorMode (0);
     EnableCursorMode (3);
     ChangeCursorGraphic (6, 2061);
     ChangeCursorGraphic (2, 2057);
   SetGameOption (OPT_PIXELPERFECT, 1); }
   if (button == 1) {
   SetCursorMode (6); }
   if (button == 2) {
   SetCursorMode (2); }
}
}

Now if anyone can see any problems with this, It'd be much appriciated!
I make music.

Ishmael

RIGHT is a predefined variable, 2 if I remember right... and if you have a if (button==RIGHT) in a GUI script (interface_click) it checks if button number 2 is clicked.

You need to put the code in this form:

in start of Global Script:

int rmbdn;

and in rep_ex:

if ((IsButtonDown(RIGHT)) && (rmbdn == 0)) {
SetNextCursorMode();
rmbdn = 1;
} else rmbdn = 0;
I used to make games but then I took an IRC in the knee.

<Calin> Ishmael looks awesome all the time
\( Ö)/ ¬(Ö ) | Ja minähän en keskellä kirkasta päivää lähden minnekään juoksentelemaan ilman housuja.

BerserkerTails

First of all, what's rep_ex? I figured it was Replace of example, meaning you wanted me to replace the code I had in my example with the code you wrote.

If that's correct, I tried your code, but it didn't work. Thanks for the help anyway TK.

Also, I should mention... Currently pressing the RIGHT button in the GUI is exactly the same as clicking the LEFT button.
I make music.

quintaros (at work)


BerserkerTails

Well... It works now, but it's made right clicking through icons difficult and buggy looking inside and outside the GUI.

Is there any other way to do this?
I make music.

Scorpiorus

function on_mouse_click(int button) {
 // called when a mouse button is clicked. button is either LEFT or RIGHT
 if (IsGamePaused() == 1) {
   // Game is paused, so do nothing (ie. don't allow mouse click)
 }
 else if (button==LEFT) {
   ProcessClick(mouse.x, mouse.y, GetCursorMode() );
 }
 else {   // right-click, so cycle cursor
//    SetNextCursorMode();  <-remove it
 }


~Cheers
}

BerserkerTails

Now whenever I hit the right mouse button, it skips through two icons!

EX: On the walk icon, hit the right mouse button, look icon is displayed for a split second, then i'm on the hand icon.

:-\ This is never going to work...
I make music.

Scorpiorus

Make the second condition to be nested, this way:

repeat_exec:

 if (IsButtonDown(RIGHT)) {
   if (rmbdn == 0) { SetNextCursorMode(); rmbdn = 1;}
 } else rmbdn = 0;


btw, have you commented out the line I pointed to?

BerserkerTails

#8
Yes I did, and now this is starting to work... Unfortunatley a couple more problems have sprung up...

First of all, one which will be easy to fix, hopefully. The cursors cycle in the inventory menu, but they don't pay attention to which cursors have been enabled/disabled. Which means the talk cursor will come up while cycling in the inventory GUI, yet the pointer cursor will not.

Secondly, pressing the right mouse button still acts like pressing the left WHILE cycling through the icons in the inventory GUI. Which means if you click the right mouse button while your cursor is over an inventory item, you'll get a message AND the cursor will change.

-_-;;;;

EDIT: Also, is there a Repeatedly Execute in the global script, or do I have to put the Rep_Ex code in every single room's repeatedly execute?
I make music.

Scorpiorus

QuoteFirst of all, one which will be easy to fix, hopefully. The cursors cycle in the inventory menu, but they don't pay attention to which cursors have been enabled/disabled. Which means the talk cursor will come up while cycling in the inventory GUI, yet the pointer cursor will not.
Yes, because they are actually enabled. Just previously you wasn't able to cycle through them. As about a pointer cursor it is the MODE_USE in fact but for the inventory GUI provided along with AGS its picture is set to a pointer.
When showing an inventory GUI you could either disable these modes or the cycling feature itself.

QuoteSecondly, pressing the right mouse button still acts like pressing the left WHILE cycling through the icons in the inventory GUI. Which means if you click the right mouse button while your cursor is over an inventory item, you'll get a message AND the cursor will change.
AGS uses internal mechanism to handle inventory clicks unless you ticked handle inventory clicks in script option, so next another modification checks an inventory item under the cursor:

if (IsButtonDown(RIGHT) && GetInvAt(mouse.x, mouse.y)==-1) {
   if (rmbdn == 0) { SetNextCursorMode(); rmbdn = 1;}
 } else rmbdn = 0;


QuoteEDIT: Also, is there a Repeatedly Execute in the global script, or do I have to put the Rep_Ex code in every single room's repeatedly execute?
just put it once inside the global repeatedly execute.

~Cheers

BerserkerTails

First of all, thanks a million for all the help you've giving me Scorpiorus and the rest. Now, back onto the problems!

QuoteYes, because they are actually enabled. Just previously you wasn't able to cycle through them. As about a pointer cursor it is the MODE_USE in fact but for the inventory GUI provided along with AGS its picture is set to a pointer.
When showing an inventory GUI you could either disable these modes or the cycling feature itself.
Done, got this working. Thanks a million, getting closer to finishing this beast all the time!

QuoteAGS uses internal mechanism to handle inventory clicks unless you ticked handle inventory clicks in script option, so next another modification checks an inventory item under the cursor:

if (IsButtonDown(RIGHT) && GetInvAt(mouse.x, mouse.y)==-1) {
if (rmbdn == 0) { SetNextCursorMode(); rmbdn = 1;}
} else rmbdn = 0;
This doesn't work for me. With the code and handle inventory clicks in script optionturned on, it stops the problem of messages being deplayed when the cursor is over an inventory item, but it also stops the cycling of the cursors and stops all interaction with inventory items period (Can't look at them, can't select them etc).

Quotejust put it once inside the global repeatedly execute.
Errr.... How do I do this?
I make music.

Scorpiorus

QuoteThis doesn't work for me. With the code and handle inventory clicks in script optionturned on, it stops the problem of messages being deplayed when the cursor is over an inventory item, but it also stops the cycling of the cursors and stops all interaction with inventory items period (Can't look at them, can't select them etc).
Once you ticked handle inventory clicks in script option AGS no longer controls mouse clicks on inventory items and you need to handle them via script. I wasn't clearer enough and you thought this option has to be turned on... Anyway it's even better that you have enabled it. I just took a look and made a test game so next is the way it should work, most already done though (just to summarize):

1. At the top of the main global script:

int rmbdn;

2. Inside the main global script repeatedly execute function:

QuoteErrr.... How do I do this?
That way:

function repeatedly_execute() {
 // put anything you want to happen every game cycle here
 
 if (IsButtonDown(RIGHT)) {
 if (rmbdn == 0) { SetNextCursorMode(); rmbdn = 1;}
 } else rmbdn = 0;

//NOTE: I removed the 2nd condition, so you can cycle with the left when over an inv item


}

3. Modify on_mouse_click() function (Now it handles on-item-clicks):

function on_mouse_click(int button) {
 // called when a mouse button is clicked. button is either LEFT or RIGHT
 if (IsGamePaused() == 1) {
   // Game is paused, so do nothing (ie. don't allow mouse click)

   if      (button == LEFTINV)  { // left inventory click
     if (GetCursorMode() == MODE_USE) SetActiveInventory(game.inv_activated); //select item
     else RunInventoryInteraction(game.inv_activated, GetCursorMode()); //look at item, etc...
   }
   else if (button == RIGHTINV) {}// do nothing here on right click (we cycle modes instead)


 }
 else if (button==LEFT) {
   ProcessClick(mouse.x, mouse.y, GetCursorMode() );
 }
 else {   // right-click, so cycle cursor
   //SetNextCursorMode(); <--- that is commented out
 }
}


4. Enable the handle inventory clicks in script option



Well, that's all. Should work acceptably now. Is it ok?

BerserkerTails

"Error in Main Script. Variable repeatedley_execute is already defined."

Sooooo close...
I make music.

Gilbert

If the repeatedly_execute() script is already there, just put the content there, no need to make a new one.

For example, the originally rep_exe function may look like this:

function repeatedly_execute() {
// put anything you want to happen every game cycle here
//Blargh blah blah bla...
}

just add the required contents:

function repeatedly_execute() {
// put anything you want to happen every game cycle here
//Blargh blah blah bla
if (IsButtonDown(RIGHT)) {
if (rmbdn == 0) { SetNextCursorMode(); rmbdn = 1;}
} else rmbdn = 0;
//NOTE: I removed the 2nd condition, so you can cycle with the left when over an inv item

}

BerserkerTails

Didn't even notice that...

IT WORKS! IT FINALLY WORKS!

Thanks you Scorpius, Gilbot, TK and Quintaros!!

Now, to valliantly go forward in the making of my game!
I make music.

SMF spam blocked by CleanTalk