Right mouse click on inventory Gui

Started by foz, Thu 15/05/2003 19:07:27

Previous topic - Next topic

foz

Can any one point me in the right direction regarding changing the global script to allow the cursor to cycle to the next mode when the mouse is over a customized gui/inventory window.....???
In the game i am working on i use the right mouse click  to cycle..eg look /walk / talk etc.
but when the mouse cursor is over my inventory gui it won`t function until i move it out of the gui int to the game area...

Ishmael

I have been wondering the same thing, never tried anything though, but this could work:

in the on_mouse_click:

if ((button==RIGHT) && (GetGuiAt(mouse.x,mouse.y)==x)) {
 SetNextCursorMode();
}

and replace x with the custom inv gui number.
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.

foz

tried script did`nt work but has given me a few idea to play with....cheers

ps if you can think of anything else let me know ..

Scorpiorus

It's because if you have a script-only GUI the game become paused when that GUI is on. If you look at the on_mouse_click() function you see that you can't cycle modes if the game is being paused:

function on_mouse_click(int button) {
 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();
 }
}


so you need to rewrite it a bit:


function on_mouse_click(int button) {
 if (IsGamePaused() == 1) {
   // Game is paused, so do nothing
 }
 else if (button==LEFT) {
     ProcessClick(mouse.x, mouse.y, GetCursorMode() );
 }

 if (button==RIGHT) SetNextCursorMode();

}

now it should work

-Cheers

foz

Still not working....
the setup i have is cursors that are cycled by a right click and they also change when over items ..objects..hotspots....eg closed eye opens when over hotspot....
i have a custom GUI with 2 buttons to scroll inventory and a inventory box....which is on all the time....it would make my game slicker if the
cursor did`nt need to be moved out of the gui to change MODE_....
also if the cursor changed when over inventory items...
if anyone can help, it would be much appriciated
cheers  

Dorcan

#5
I have a little tutorial on my (unfinished) website :

http://host.deluxnetwork.com/~dorcan/script.php?id=1&page=1&langue=en

Add also this code in the repeatedly_execute function:

if (GetInvAt (mouse.x, mouse.y)!=-1)
   SetCursorMode(CURSORMODE);


Scorpiorus

Hmm, yes seems like on_mouse_click() isn't get called at all provided you click on any GUI element except inventory window (if handle inv clicks is checked). Then you could use on_event() function with GUI_MDOWN, GUI_MUP events, as Dorcan correctly pointed out. Or handle right click inside the repeatedly_execute() function, example:


int rbutton_pressed = 0;
function repeatedly_execute() {


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


}


The rbutton_pressed is needed to avoid repeatedly cycling when you hold the right button.

Also don't forget to remove the SetNextCursorMode(); line inside on_mouse_click() or you'll jump over the two cursor modes instead.


Btw, Dorcan, why the interface_click() name is changed? I mean capital letters. I had heard you said it isn't get called properly or something. Just curious. :P

-Cheers

Dorcan

Scorpiorus : I don't know if it's still the case, but the problem with an older version is that interface_click wasn't allways called when using the on_event() function with GUI_MDOWN or GUI_MUP. I don't really know why, but it was annoying to click and that sometimes nothing happened.
Oh and I think there was another reason, but I wrote this script weeks ago and I don't remember what it was.  ::)

Spyros

In order to use the button while on inv guis you have to check the 'handle inventory clicks in script' nad use the 'LEFTINV' and 'RIGHTINV' buttons in the script

Scorpiorus

Dorcan: Aha, thanks for letting me know. Maybe such effect because it's called two times. One inside the on_event() function and another by AGS internally.

QuoteIn order to use the button while on inv guis you have to check the 'handle inventory clicks in script' nad use the 'LEFTINV' and 'RIGHTINV' buttons in the script
Spyros: That is, but the on_mouse_click() is called (with LEFT/RIGHTINV values) only if you have clicked some inventory item inside the inv window.

-Cheers

foz

thanks everyone i`ll try and get it working....
cheers

foz

Got it working.....this is what i used..:-

function repeatedly_execute() {

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


if (IsGamePaused()==0){
if (GetInvAt (mouse.x, mouse.y)!=-1){
  if (GetCursorMode()==1)SetMouseCursor(8);
   if (GetCursorMode()==2)SetMouseCursor(5);
   if (GetCursorMode()==3)SetMouseCursor(9);

   }
if (GetInvAt (mouse.x, mouse.y)==-1){
   if (GetCursorMode()==1)SetMouseCursor(1);
   if (GetCursorMode()==2)SetMouseCursor(2);
   if (GetCursorMode()==3)SetMouseCursor(3);
}
   }
}

//  and i changed the on mouse click to this....

function on_mouse_click(int button) {

 if (IsGamePaused() == 1) {
   // Game is paused, so do nothing
 }
else if (button==LEFT) {
     ProcessClick(mouse.x, mouse.y, GetCursorMode() );
}

Thanks for helping me head in the right direction....
cheers
foz


foz

sorted out all problems now and works perfectly....here is code for anyone interested....

function repeatedly_execute() {

if ((IsButtonDown(RIGHT)==0) && (rbutton_pressed == 1)){rbutton_pressed = 0;}
if (IsGamePaused()==0){

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

if (IsGamePaused()==0){
if (GetInvAt (mouse.x, mouse.y)!=-1){
   if (GetCursorMode()==1) SetMouseCursor(8);
   if (GetCursorMode()==2)SetMouseCursor(5);
   if (GetCursorMode()==3)SetMouseCursor(9);
   }
}
if (IsGamePaused()==0){
if (GetInvAt (mouse.x, mouse.y)==-1){
   if ((GetCursorMode()==1) && (IsGamePaused()==0))SetMouseCursor(1);
   if (GetCursorMode()==2)SetMouseCursor(2);
   if (GetCursorMode()==3)SetMouseCursor(3);
}
}
//this part allows player to use look for each inventory item ....DON`T use Inventory items interaction for look the rest should be okay to use..

if ((GetInvAt (mouse.x, mouse.y)==1)&& (IsButtonDown(LEFT)==1) && (GetCursorMode()==1)){DisplayMessage(500);}
if ((GetInvAt (mouse.x, mouse.y)==2)&& (IsButtonDown(LEFT)==1) && (GetCursorMode()==1)){DisplayMessage(501);}
if ((GetInvAt (mouse.x, mouse.y)==3)&& (IsButtonDown(LEFT)==1) && (GetCursorMode()==1)){DisplayMessage(502);}
if ((GetInvAt (mouse.x, mouse.y)==4)&& (IsButtonDown(LEFT)==1) && (GetCursorMode()==1)){DisplayMessage(503);}
if ((GetInvAt (mouse.x, mouse.y)==5)&& (IsButtonDown(LEFT)==1) && (GetCursorMode()==1)){DisplayMessage(504);}
if ((GetInvAt (mouse.x, mouse.y)==6)&& (IsButtonDown(LEFT)==1) && (GetCursorMode()==1)){DisplayMessage(505);}
if ((GetInvAt (mouse.x, mouse.y)==7)&& (IsButtonDown(LEFT)==1) && (GetCursorMode()==1)){DisplayMessage(506);}
if ((GetInvAt (mouse.x, mouse.y)==8)&& (IsButtonDown(LEFT)==1) && (GetCursorMode()==1)){DisplayMessage(507);}
if ((GetInvAt (mouse.x, mouse.y)==9)&& (IsButtonDown(LEFT)==1) && (GetCursorMode()==1)){DisplayMessage(508);}
if ((GetInvAt (mouse.x, mouse.y)==10)&& (IsButtonDown(LEFT)==1) && (GetCursorMode()==1)){DisplayMessage(509);}
if ((GetInvAt (mouse.x, mouse.y)==11)&& (IsButtonDown(LEFT)==1) && (GetCursorMode()==1)){LoseInventory(11);NewRoom(8);}
}
 



function on_mouse_click(int button) {

 if (IsGamePaused() == 0) {
   // Game is paused, so do nothing
 if (button==LEFT) {
     ProcessClick(mouse.x, mouse.y, GetCursorMode() );}

}
}

Proskrito

Quote
//this part allows player to use look for each inventory item ....DON`T use Inventory items interaction for look the rest should be okay to use..

if ((GetInvAt (mouse.x, mouse.y)==1)&& (IsButtonDown(LEFT)==1) && (GetCursorMode()==1)){DisplayMessage(500);}
if ((GetInvAt (mouse.x, mouse.y)==2)&& (IsButtonDown(LEFT)==1) && (GetCursorMode()==1)){DisplayMessage(501);}
if ((GetInvAt (mouse.x, mouse.y)==3)&& (IsButtonDown(LEFT)==1) && (GetCursorMode()==1)){DisplayMessage(502);}
if ((GetInvAt (mouse.x, mouse.y)==4)&& (IsButtonDown(LEFT)==1) && (GetCursorMode()==1)){DisplayMessage(503);}
if ((GetInvAt (mouse.x, mouse.y)==5)&& (IsButtonDown(LEFT)==1) && (GetCursorMode()==1)){DisplayMessage(504);}
if ((GetInvAt (mouse.x, mouse.y)==6)&& (IsButtonDown(LEFT)==1) && (GetCursorMode()==1)){DisplayMessage(505);}
if ((GetInvAt (mouse.x, mouse.y)==7)&& (IsButtonDown(LEFT)==1) && (GetCursorMode()==1)){DisplayMessage(506);}
if ((GetInvAt (mouse.x, mouse.y)==8)&& (IsButtonDown(LEFT)==1) && (GetCursorMode()==1)){DisplayMessage(507);}
if ((GetInvAt (mouse.x, mouse.y)==9)&& (IsButtonDown(LEFT)==1) && (GetCursorMode()==1)){DisplayMessage(508);}
if ((GetInvAt (mouse.x, mouse.y)==10)&& (IsButtonDown(LEFT)==1) && (GetCursorMode()==1)){DisplayMessage(509);}
if ((GetInvAt (mouse.x, mouse.y)==11)&& (IsButtonDown(LEFT)==1) && (GetCursorMode()==1)){LoseInventory(11);NewRoom(8);}
}

Nothing new, just that I thought it could be a bit cleaner, and easier to edit and to add new inv. interactions this way:

//this part allows player to use look for each inventory item ....DON`T use Inventory items interaction for look the rest should be okay to use..

int invitem;
invitem=(GetInvAt (mouse.x, mouse.y);
if ((IsButtonDown(LEFT)==1) && (GetCursorMode()==1)){
if (invitem==1) {DisplayMessage(500);}
else if (invitem==2) {DisplayMessage(501);}
else if (invitem==3) {DisplayMessage(502);}
else if (invitem==4) {DisplayMessage(503);}
else if (invitem==5) {DisplayMessage(504);}
else if (invitem==6) {DisplayMessage(505);}
else if (invitem==7) {DisplayMessage(506);}
else if (invitem==8) {DisplayMessage(507);}
else if (invitem==9) {DisplayMessage(508);}
else if (invitem==10) {DisplayMessage(509);}
else if (invitem==11) {LoseInventory(11);NewRoom(8);}
}
}
 

Just if it works the same.



SMF spam blocked by CleanTalk