Changing mouse action with right-click in Inventory? [SOLVED]

Started by LeChuck, Thu 03/02/2005 01:19:11

Previous topic - Next topic

LeChuck

Almost all AGS games uses buttons within the inventory GUI to change the mouse cursor's looks and behaviour. What I've tried for quite some time is to have the mouse cursor change the same way by right-clicking the mouse inside the custom GUI as when right-clicking inside the gaming part, a task I have yet to succeed in.


Let's take a look at parts of the global script:

In repeatedly execute:
Code: ags

// Script that changes icon of the mouse whenever there's something you can interact with underneath.

string name;
GetLocationName(mouse.x, mouse.y, name);	// Get the name of what's under the cursor	
if (StrComp(name,"")==0) SetDefaultCursor();	// if blank ( or hotspot with no name ) do nothing	
else {	
   if (GetCursorMode()==1) {
      if (GetLocationType(mouse.x,mouse.y)>0) SetMouseCursor(8);
   else SetDefaultCursor(); 
   }
   if (GetCursorMode()==2) {
      if (GetLocationType(mouse.x,mouse.y)>0) SetMouseCursor(9); 
   else SetDefaultCursor(); 
   }
   if (GetCursorMode()==3) {
      if (GetLocationType(mouse.x,mouse.y)==2) SetMouseCursor(10);
   else SetDefaultCursor(); 
   }
}


// This snippet just turns the inventory off if clicked outside of it before entering, or if the cursor has entered - and then moves out of it.

if (IsGUIOn(INVENTORY)){
    // Checks if mouse has moved onto GUI...
    if (((mouse.x > 50) && (mouse.x < 270)) && ((mouse.y > 35) && (mouse.y < 165))) {
    SetGlobalInt(1, 1); // Mouse HAS entered GUI!
    }
  
    // Checks if the mouse has entered the GUI...
    if (GetGlobalInt(1)==1) {
       // Checks if mouse is still over the GUI...
       if ((mouse.x < 50) || (mouse.x > 270) || (mouse.y < 35) || (mouse.y > 165)) {
          //If not:
          GUIOff(INVENTORY);
          SetGlobalInt(1, 0);
          }
       }
    }
  
    // Closes GUI if clicked outside GUI before entering it
    if (GetGlobalInt(1)==0) {
      if ((IsButtonDown(RIGHT)) || (IsButtonDown(LEFT))) {
        GUIOff(INVENTORY);
        SetGlobalInt(1, 0);
      }
    }


No need to change anything here, is it?


function show_inventory_window()
Code: ags

function show_inventory_window() {
  
  GUIOn (INVENTORY);
  
  SetMouseCursor(6);
  SetCursorMode(2);
  
}


I guess this is the part where I have to add new code? The problem is whenever I try to program something when the "handle inventory clicks in script" box is checked, I can't make anything work. It has to be checked in order to add this kind of "advanced" feature, no?

I haven't been able to find an answer to this "right-click to change mouse actions inside custom inventory GUI" riddle anywhere on the forums, which I think is kind of strange. Is it possible to implement this feature into the game?

strazer

Try this:

Code: ags

function on_event(int event, int data) {
  //...
  
  if (event == GUI_MDOWN) { // if mouse button pressed when over a GUI
    if (IsButtonDown(RIGHT)) { // if right mouse button pressed
      on_mouse_click(RIGHT); // call on-mouse-click function for default right mouse button action
    }
  }

  //...
}


and make sure on_event is located after the on_mouse_click function in the script so it can call it.

LeChuck

Quote from: strazer on Thu 03/02/2005 01:57:06
Try this:

Code: ags

function on_event(int event, int data) {
Ã,  //...
Ã,  
Ã,  if (event == GUI_MDOWN) { // if mouse button pressed when over a GUI
Ã,  Ã,  if (IsButtonDown(RIGHT)) { // if right mouse button pressed
Ã,  Ã,  Ã,  on_mouse_click(RIGHT); // call on-mouse-click function for default right mouse button action
Ã,  Ã,  }
Ã,  }

Ã,  //...
}


and make sure on_event is located after the on_mouse_click function in the script so it can call it.

I'm afraid I don't follow you... Where in the global script am I supposed to put this? I tried putting it "after" the on_mouse_click function, but I have a feeling I really don't know what I'm doing... (How) does this correspod with the show_inventory_window() function?

Do I need a show_inventory_window() function if I want AGS to handle inventory clicks in script? Do I want AGS to handle inventory clicks in script?? *Sigh*, I've got so many questions inside my head right now...

Here's the entire global script, hoping for further directions... : global.txt


strazer

QuoteWhere in the global script am I supposed to put this?

It's just important that you put this on_event function after the on_mouse_click function into the global script because the former one calls the latter in my example.
Since you don't have an on_event function in your global script already, you can just add the above code to the end of your global script, after everything else.

Quote(How) does this correspod with the show_inventory_window() function?

It doesn't.
Your show_inventory_window function displays your customized inventory gui. That's it.

QuoteDo I need a show_inventory_window() function if I want AGS to handle inventory clicks in script?

As the manual states (Tutorial -> Setting up the game -> Game options), you can't use "Handle inventory clicks in script" with the built-in inventory gui.
Since you use a custom one (called INVENTORY), there shouldn't be a problem.

QuoteDo I want AGS to handle inventory clicks in script??

It depends.
If you want to change the default behaviour of clicking on inventory items, yes. If you're okay with it, no.

If you decide to handle the clicks yourself, change your on_mouse_click function to this:

Code: ags

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 if (button == LEFTINV) { // if left-clicked on an inventory item
    // Do your stuff here, activate the clicked item, look at, use, whatever
    // For example:
    // SetActiveInventory(game.inv_activated); // pick inv item
  }
  else if (button == RIGHTINV) { // if right-clicked on an inventory item
    // Do your stuff here, activate the clicked item, look at, use, whatever
    // For example:
    // RunInventoryInteraction(game.inv_actived, MODE_LOOK); // look at inv item
  }

  else {   // right-click, so cycle cursor
    SetNextCursorMode();
  }
}

LeChuck

Alright, things are starting to shape up thanks to strazer! However, I've still got a few issues with the inventory interface ...


Here's the on_mouse_click code:
Code: ags

 function on_mouse_click(int button) {
Ã,  // called when a mouse button is clicked. button is either LEFT or RIGHT
Ã,  
Ã,  
Ã,  if (button==LEFT) {
Ã,  Ã,  if (IsGUIOn(INVENTORY)) {
Ã,  Ã,  Ã,  
Ã,  Ã,  Ã,  
Ã,  Ã,  Ã,  
Ã,  Ã,  Ã,  // Add command for removing item from hand.
Ã,  Ã,  Ã,  
Ã,  Ã,  Ã,  
Ã,  Ã,  Ã,  }
Ã,  Ã,  else {
Ã,  Ã,  ProcessClick(mouse.x, mouse.y, GetCursorMode() );
Ã,  Ã,  }
Ã,  }

Ã,  if (button == LEFTINV) { // if left-clicked on an inventory item

Ã,  Ã, if (GetCursorMode()==1) {
Ã,  Ã,  Ã,  Ã, RunInventoryInteraction(game.inv_activated, MODE_LOOK);
Ã,  Ã,  Ã,  Ã, }

Ã,  Ã, if (GetCursorMode()==2) {
Ã,  Ã,  Ã,  SetActiveInventory(game.inv_activated);
Ã,  Ã,  Ã,  
Ã,  Ã,  Ã,  
Ã,  Ã,  Ã,  // Add command for removing item from inventory.
Ã,  Ã,  Ã,  
Ã,  Ã,  Ã,  
Ã,  Ã,  Ã,  }
 
Ã,  Ã,  if (GetCursorMode()==3) {
Ã,  Ã,  Ã,  Ã, RunInventoryInteraction(game.inv_activated, MODE_TALK);
Ã,  Ã,  Ã,  Ã, }

Ã,  Ã,  if (GetCursorMode()==4) {
Ã,  Ã,  Ã,  Ã, RunInventoryInteraction(game.inv_activated, MODE_USEINV);
Ã,  Ã,  Ã,  Ã, }
Ã,  }

Ã,  else if (button == RIGHTINV) { // if right-clicked on an inventory item
Ã,  Ã,  // Do nothing
Ã,  }

Ã,  else if (button == RIGHT) {Ã,  Ã, // right-click, so cycle cursor
Ã,  Ã,  SetNextCursorMode();
Ã,  }
}


It now allows right-clicking inside the interface, changing cursors there as in the game itself. Cool!


1. Cursor

This bit is in the repeatedly execute part of the global script:

Code: ags

if (IsGUIOn(INVENTORY)) { 

Ã,  Ã, if (GetCursorMode()==0) {// Changes the walk cursor to the Use cursor. 
Ã,  Ã,  Ã,  Ã, SetCursorMode(1);Ã,  Ã,  Ã,  Ã,  // This code doesn't work properly, 
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã, //and has to be changed
Ã,  Ã, }
Ã,  Ã, if (GetCursorMode()==1) { // Changes the appearance of the Use cursor to an open eye instead of a closed one
Ã,  Ã,  Ã,  Ã, SetMouseCursor(8);
Ã,  Ã, }
Ã,  Ã, if (GetCursorMode()==2) { // Similar as above
Ã,  Ã,  Ã,  Ã, SetMouseCursor(9);
Ã,  Ã, }
Ã,  Ã, if (GetCursorMode()==3) { // Similar as above
Ã,  Ã,  Ã,  Ã, SetMouseCursor(10);
Ã,  Ã, }
}


The thing is, it keeps showing the walk cursor (cursor mode 0) inside the inventory window, which it really isn't supposed to do. I've tried to do a if (GetCursorMode()==0){SetCursorMode(1);}, but it still shows the walk cursor for a brief moment, making it look ... well, stupid.

Is there a way of simply disabling some cursors in certain situations, instead of skipping over them as I've tried?


2. Making the item disappear from Inventory when it's activated

We've all seen it in Lucasarts games; you active an inventory item, it becomes the mouse cursor, and disappears from the inventory GUI, giving the illusion of "lifting" it out of the inventory. In AGS, however, you "duplicate" the inventory item. Is there a workaround here?

If you look at the code part at the top, you'll see where I've planned to implement this kind of behaviour, if possible, as a start. Any tips or examples in this situation?

My guess here is that I have to use that other kind of Inventory system, where it indexes the position of the item, and moving the item out of sight (without the possibility of scrolling down to it) whenever the item is selected with the cursor?


strazer

1.) DisableCursorMode

2.) You could set the item to a blank sprite with SetInvItemPic while it's activated.

With AGS v2.7 you will be able to add an item to a specified position in the inventory so you could store its position, remove it from the inventory and add it back to the old position once the user changes the cursor mode.

I've noticed you don't use "else" much:

  if (GetCursorMode()==0) {
    SetCursorMode(1);
  }
  // use "else, otherwise the following will also be executed if cursor mode is 0 because you set the cursor mode to 1 in the part above:
  else if (GetCursorMode()==1) {
    SetMouseCursor(8 );
  }

LeChuck

Quote from: strazer on Sat 05/02/2005 05:12:20
1.) DisableCursorMode

2.) You could set the item to a blank sprite with SetInvItemPic while it's activated.

With AGS v2.7 you will be able to add an item to a specified position in the inventory so you could store its position, remove it from the inventory and add it back to the old position once the user changes the cursor mode.

I've noticed you don't use "else" much:

Ã,  if (GetCursorMode()==0) {
Ã,  Ã,  SetCursorMode(1);
Ã,  }
Ã,  // use "else, otherwise the following will also be executed if cursor mode is 0 because you set the cursor mode to 1 in the part above:
Ã,  else if (GetCursorMode()==1) {
Ã,  Ã,  SetMouseCursor(8 );
Ã,  }


1. Ah, excellent! :D

2. Alright, I've tried for almost four hours now, but I cannot for the life of me make it work.

Code: ags

Ã,  if (button==LEFT) {
Ã,  Ã,  Ã,  if (GetCursorMode()==2) { // The use command
Ã, 
Ã,  Ã,  Ã,  // Commands for removing item from inventory
Ã,  Ã,  Ã,  SetInvItemPic(game.inv_activated, 0); // O is a transparent sprite
Ã,  Ã,  Ã,  SetActiveInventory(game.inv_activated); // Activates the item
Ã,  Ã,  Ã,  currentItem = character[GetPlayerCharacter()].activeinv; // Stores the item number in the currentItem variable... not that it does much good here
Ã,  Ã,  Ã,  ChangeCursorGraphic(4, 31); // Changes the cursors appearance, since SetInvItemPic makes it transparent... :(
Ã,  Ã,  Ã,  }
}


The main problem here is that SetInvItemPic doesn't just change the inventory icon, but also the cursor mode. I've tried solving this by changing the cursors appearance as you can see in the code above, but this leads to a new problem; when circulating the icons, upon the items next showing, it is again the transparent texture - NOT the new cursor I want it to have.


About the else-thing: You're absolutely right...Ã,  :-\

strazer

2.) Since you have to store the inv item's old sprite slot number in a variable anyway (for restoring it later, use GetInvGraphic), you could modify your on_mouse_click RIGHT mouse button cycling to change the cursor graphic to the slot number stored in variable when you cycle to the UseInv cursor mode.

LeChuck

I've tried some more, but really can't make it work:

Code: ags


#sectionstart on_mouse_clickÃ,  // DO NOT EDIT OR REMOVE THIS LINE

 function on_mouse_click(int button) {
Ã,  
 int currentItem; // used to store the current item
 int oldItemGraphic; // used for loading the old sprite back when item is deactivated
 
Ã,  // called when a mouse button is clicked. button is either LEFT or RIGHT
Ã,  
Ã,  if (button==LEFT) {
Ã,  Ã,  if (IsGUIOn(INVENTORY)) {
Ã,  Ã,  Ã,  
Ã,  Ã,  Ã,  
Ã,  Ã,  Ã,  // Add command for removing item from hand, adding it back into the inventory

Ã,  Ã,  }Ã,  Ã,  
Ã,  Ã,  else {
Ã,  Ã,  ProcessClick(mouse.x, mouse.y, GetCursorMode() );
Ã,  Ã,  }
Ã,  }




Ã,  else if (button == LEFTINV) { // if left-clicked on an inventory item
Ã,  
Ã,  Ã, if (GetCursorMode()==1) {
Ã,  Ã,  Ã,  Ã, RunInventoryInteraction(game.inv_activated, MODE_LOOK);
Ã,  Ã,  Ã,  Ã, }

Ã,  Ã, else if (GetCursorMode()==2) {
Ã,  Ã,  Ã, 
Ã,  Ã,  Ã,  // Commands for removing item from inventory / loading new cursor sprite
Ã,  Ã,  Ã,  
Ã,  Ã,  Ã,  SetActiveInventory(game.inv_activated); // activates the clicked item
Ã,  Ã,  Ã,  currentItem = character[GetPlayerCharacter()].activeinv; // stores the current item number
Ã,  Ã,  Ã,  oldItemGraphic = GetInvGraphic(currentItem); // stores items graphic slot, used for loading later
Ã,  Ã,  Ã,  SetInvItemPic(game.inv_activated, 0); // removes the sprite from inventory
Ã,  Ã,  Ã,  ChangeCursorGraphic(currentItem, 31); // loads the new cursor
Ã,  Ã,  Ã,  }
 
 
Ã,  Ã,  else if (GetCursorMode()==3) {
Ã,  Ã,  Ã,  Ã, RunInventoryInteraction(game.inv_activated, MODE_TALK);
Ã,  Ã,  Ã,  Ã, }

Ã,  Ã,  else if (GetCursorMode()==4) {
Ã,  Ã,  Ã,  Ã, RunInventoryInteraction(game.inv_activated, MODE_USEINV);
Ã,  Ã,  Ã,  Ã, }
Ã,  }




Ã,  else if (button == RIGHTINV) { // if right-clicked on an inventory item
Ã,  Ã,  // Do nothing
Ã,  }



Ã,  else if (button == RIGHT) {Ã,  Ã, // right-click, so cycle cursor
Ã,  Ã,  Ã, if (currentItem > 0) {Ã,  Ã,  // if an item is active
Ã,  Ã,  Ã,  Ã,  if (GetCursorMode()==3) { // if the next cursorMode is the active inventory item
Ã,  Ã,  Ã,  Ã,  Ã,  SetNextCursorMode();
Ã,  Ã,  Ã,  Ã,  Ã,  ChangeCursorGraphic(currentItem, 31);
Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã, }
Ã,  Ã, 
Ã,  Ã,  Ã, else if (currentItem == 0) { // if NO item is active
Ã,  Ã,  Ã,  Ã,  SetNextCursorMode();
Ã,  Ã,  Ã, }
Ã,  }
}


The problem is still that it won't load the sprite when cycling...

strazer

Try changing
  ChangeCursorGraphic(currentItem, 31);
to
  ChangeCursorGraphic(3, GetInvGraphic(currentItem));

LeChuck

Crap, that didn't work either, I still get an empty sprite when cycling. Funny thing is, I can make the talk cursor change appearance this way, but not the active intentory item.

Has this never been done before? Aren't there any examples on how to do this? I haven't been able to find any.

strazer

Ah, stupid me!

Try
  ChangeCursorGraphic(3, oldItemGraphic);

LeChuck

I tried that too, it does nothing.

There must be some major flaw in the code, or AGS doesn't like changing the active inventory cursor. I tried breaking the code up into two parts:

Code: ags

Ã,  else if ((button == RIGHT) && (GetCursorMode()==3) && (currentItem > 0)) {Ã,  Ã, // If right mouse button is down, cursorMode is 3 and an inventory item is active
Ã,  Ã,  Ã,  Ã,  Ã,  SetNextCursorMode();
Ã,  Ã,  Ã,  Ã,  Ã,  ChangeCursorGraphic(4, oldItemGraphic);
Ã,  }
Ã,  

Ã,  else if ((button == RIGHT) && (currentItem==0)) {Ã,  Ã, // right-click, so cycle cursor
Ã,  Ã,  Ã,  Ã,  SetNextCursorMode();
Ã,  }


The active inventory still remains transparent.

Damn, when did you say 2.7 was due? I am a millimetre away from giving up here...


strazer

According to the manual, ChangeCursorGraphic should permanently change the mouse cursor's graphic, but it does seem to try to use the activated inv item's graphic again if you cycle to it.
Ok, I did it like this, and it works:

Code: ags

  else if (button == LEFTINV) { // if left-clicked on an inventory item

    if (GetCursorMode() == MODE_USE) {
      if (character[GetPlayerCharacter()].activeinv != -1) SetInvItemPic(character[GetPlayerCharacter()].activeinv, oldItemGraphic); // if another item is already active, reset its sprite to its old sprite slot
      SetActiveInventory(game.inv_activated); // activate the clicked item
      oldItemGraphic = GetInvGraphic(game.inv_activated); // save clicked item's old sprite slot
      SetInvItemPic(game.inv_activated, 0); // remove clicked item's sprite
      ChangeCursorGraphic(MODE_USEINV, oldItemGraphic); // set mouse cursor to item's old sprite
    }

  }

  else if (button == RIGHT) {
    SetNextCursorMode(); // cycle to next cursor mode
    if (GetCursorMode() == MODE_USEINV) ChangeCursorGraphic(MODE_USEINV, oldItemGraphic); // if new mode is an activated inv item, set mouse cursor to item's old sprite
  }

LeChuck

#14
Now it works! I really, really appreciate you've helped me strazer, I really do. The problem probably wasn't in the on_mouse_click script, it was in the repeatedly execute script, where I changed this:

Code: ags

//MOUSE CURSOR
string name;
GetLocationName(mouse.x, mouse.y, name);// Get the name of what's under the cursor
if (StrComp(name,"")==0) SetDefaultCursor();// if blank ( or hotspot with no name ) do nothing
else {
Ã,  Ã, if (GetCursorMode()==1) {
Ã,  Ã,  Ã,  if (GetLocationType(mouse.x,mouse.y)>0) SetMouseCursor(8);
Ã,  Ã, else SetDefaultCursor(); 
Ã,  Ã, }
Ã,  Ã, if (GetCursorMode()==2) {
Ã,  Ã,  Ã,  if (GetLocationType(mouse.x,mouse.y)>0) SetMouseCursor(9); 
Ã,  Ã, else SetDefaultCursor(); 
Ã,  Ã, }
Ã,  Ã, if (GetCursorMode()==3) {
Ã,  Ã,  Ã,  if (GetLocationType(mouse.x,mouse.y)==2) SetMouseCursor(10);
Ã,  Ã, else SetDefaultCursor(); 
Ã,  Ã, }
}


... into this:

Code: ags

string name;
GetLocationName(mouse.x, mouse.y, name);	// Get the name of what's under the cursor	
if (StrComp(name,"")==0) { // Nothing underneath
Ã,  if (GetCursorMode()==4) { // Nothing underneath, so show custom cursor
Ã,  Ã,  Ã,  if (character[SELF].activeinv==3) {
Ã,  Ã,  Ã,  Ã,  Ã, SetMouseCursor(13);
Ã,  Ã,  Ã, }
Ã,  Ã, }
Ã,  else {
Ã,  SetDefaultCursor();
Ã,  }
}

else { // object underneath
Ã,  Ã,  Ã,  if (GetCursorMode()==1) {
Ã,  Ã,  Ã,  Ã,  Ã, if (GetLocationType(mouse.x,mouse.y)>0) SetMouseCursor(8);
Ã,  Ã,  Ã,  else SetDefaultCursor(); 
Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  else if (GetCursorMode()==2) {
Ã,  Ã,  Ã,  Ã,  Ã, if (GetLocationType(mouse.x,mouse.y)>0) SetMouseCursor(9); 
Ã,  Ã,  Ã,  else SetDefaultCursor(); 
Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  else if (GetCursorMode()==3) {
Ã,  Ã,  Ã,  Ã,  Ã, if (GetLocationType(mouse.x,mouse.y)==2) SetMouseCursor(10);
Ã,  Ã,  Ã,  else SetDefaultCursor(); 
Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  else if (GetCursorMode()==4) { 
Ã,  Ã,  Ã,  Ã,  Ã, if (character[SELF].activeinv==3) {
Ã,  Ã,  Ã,  Ã,  Ã,  Ã, SetMouseCursor(11);
Ã,  Ã,  Ã, }
Ã,  Ã, }
}


The problem was in summary that the code in repeatedly execute was overriding the on_mouse_click script, setting it back to DefaultCursor every time the mouse wasn't hovering over something.


Who would've thought cursors changing when hovering over objects, custom GUI's, cycling the active inventory and implementing a "remove item from inventory" illusion (instead of "duplicating item") would be such a pain in the ass combined???Ã, 

I hope others can find my shoddy code useful, and thanks again to strazer. I'VE certainly learned something! I would've used parts of your code, but that's how it was when I got it working, the fear of vomiting all over my keyboard keeps me from changing it. ;)

Edit: Hm, it just occured to me maybe this doesn't belong in "Beginners Technical Quesions"... ?

TerranRich

QuoteIt just occured to me maybe this doesn't belong in "Beginners Technical Questions"... ?

It's too late now, buddy! Thanks A LOT! You ruined the order of things!

j/k by the way ;)
Status: Trying to come up with some ideas...

LeChuck

Perhaps I can squeeze another helpful answer out of you guys without creating a new thread?

Everything's working fine and dandy now, with an interface pretty much spot on like the one in Sam & Max in terms of functionality. There's just one catch: Whenever I right-click on the tiny inventory shortcut icon in the bottom right corner, in addition to cycling the mouse cursors like it's supposed to, it also opens the inventory window. I have not been able to stop this behaviour (not opening inv. window), after countless tries implementing the IsButtonDown(RIGHT) pretty much all over the place where I found it appropriate. In this case, it cycles the icons just fine when clicking the right mouse button over the GUI, but does not react when I left click / try to open it.

Here are the parts I suspect has to be changed:

Code: ags


function interface_click(int interface, int button) {

Ã,  if (interface == LUGGAGE) { //LUGGAGE is the GUIObject that opens the inventory
Ã,  Ã,  Ã, 
Ã,  Ã,  Ã, if ((button == 0) && (GetCursorMode()!=4)) {Ã,  // cursor is NOT useinv
Ã,  Ã,  Ã,  Ã,  Ã, SetCursorMode(MODE_LOOK);
Ã,  Ã,  Ã,  Ã,  Ã, GUIOn(INVENTORY);
Ã,  Ã,  Ã,  Ã,  Ã, GUIOff(LUGGAGE);
Ã,  Ã,  Ã, }
Ã,  Ã, 
Ã,  Ã,  Ã, else if ((button == 0) && (GetCursorMode()==4)) {Ã,  // cursor IS useinv
Ã,  Ã,  Ã,  Ã,  if (character[SELF].activeinv==3) {
Ã,  Ã,  Ã,  Ã,  SetInvItemPic(3, 31);
Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  Ã,  if (character[SELF].activeinv==4) {
Ã,  Ã,  Ã,  Ã,  SetInvItemPic(4, 32);
Ã,  Ã,  Ã,  Ã,  }
 
Ã,  Ã,  Ã,  Ã,  SetActiveInventory (-1);
Ã,  Ã,  Ã,  Ã,  SetCursorMode(MODE_WALK);
Ã,  Ã,  Ã,  Ã,  
Ã,  Ã,  Ã, }
Ã,  }Ã,  // end if interface LUGGAGE

This is the part where I've tried the most, using IsButtonDown, but alas, no cigars were handed out.

Oh no, not this part again! :(
Code: ags

function on_mouse_click(int button) {

int oldItemGraphic; // used for loading the old sprite back when item is deactivated
int currentItem;

Ã,  // called when a mouse button is clicked. button is either LEFT or RIGHT
Ã,  
Ã,  if (button==LEFT) {
Ã,  Ã,  if (IsGUIOn(INVENTORY)) {
Ã,  Ã,  // Do nothing
Ã,  Ã,  }
Ã,  Ã,  else {
Ã,  Ã,  ProcessClick(mouse.x, mouse.y, GetCursorMode() );
Ã,  Ã,  }
Ã,  }


Ã,  else if (button == LEFTINV) { // if left-clicked on an inventory item
Ã,  
Ã,  Ã, if (GetCursorMode()==1) {
Ã,  Ã,  Ã,  Ã, RunInventoryInteraction(game.inv_activated, MODE_LOOK);
Ã,  Ã,  Ã,  Ã, }

Ã,  Ã, else if (GetCursorMode()==2) {
Ã,  Ã,  Ã, 
Ã,  Ã,  Ã,  // Commands for removing item from inventory / loading new cursor sprite
Ã,  Ã,  Ã,  
Ã,  Ã,  Ã,  SetActiveInventory(game.inv_activated); // activates the clicked item
Ã,  Ã,  Ã,  currentItem = character[GetPlayerCharacter()].activeinv; // stores the current item number
Ã,  Ã,  Ã,  oldItemGraphic = GetInvGraphic(currentItem); // stores items graphic slot, used for loading later
Ã,  Ã,  Ã,  SetInvItemPic(game.inv_activated, 0); // removes the sprite from inventory
Ã,  Ã,  Ã,  if (character[SELF].activeinv==3) {
Ã,  Ã,  Ã,  Ã,  Ã, SetMouseCursor(13); // loads the new cursor
Ã,  Ã,  Ã,  Ã,  Ã, }
Ã,  Ã,  
Ã,  Ã,  Ã,  else if (character[SELF].activeinv==4) {
Ã,  Ã,  Ã,  Ã,  Ã, SetMouseCursor(14); // loads the new cursor
Ã,  Ã,  Ã,  Ã,  Ã, }
Ã,  Ã,  Ã,  }

Ã,  Ã,  else if (GetCursorMode()==3) {
Ã,  Ã,  Ã,  Ã, RunInventoryInteraction(game.inv_activated, MODE_TALK);
Ã,  Ã,  Ã,  Ã, }

Ã,  Ã,  else if (GetCursorMode()==4) {
Ã,  Ã,  Ã,  Ã, RunInventoryInteraction(game.inv_activated, MODE_USEINV);
Ã,  Ã,  Ã,  Ã, }
Ã,  }



Ã,  else if (button == RIGHTINV) { // if right-clicked on an inventory item
Ã,  Ã,  // Do nothing
Ã,  }


Ã,  else if (button == RIGHT) {Ã,  Ã, // right-click, so cycle cursor
Ã,  Ã,  Ã,  Ã,  SetNextCursorMode();
Ã,  }
}


The whole global script: global2.txt
The game so far, really just an interface test: Frankenstein.exe


In conclusion, I could need some help in making the game IGNORE right-clicks on an interface, but without interfering with the cursor cycle. What's the way to do this?

strazer

Glad I could help. :)

As for the GUI mouse clicks, I did it like this:

Code: ags

// main global script file

int guimb; // stores mouse button clicked on gui

function on_event(int event, int data) {
  //...

  if (event == GUI_MDOWN) { // if mouse clicked over a gui
    if (IsButtonDown(LEFT)) guimb = LEFT; // if left mouse button pressed, store it in variable
    else if (IsButtonDown(RIGHT)) guimb = RIGHT; // if right mouse button pressed, store it in variable
    // and so on...
  }

  //...
}

function interface_click(int interface, int button) {
  //...

  if (interface == GUI1) {
    if (button == 0) {
      // do stuff
    }
  }

  if (guimb != LEFT) return; // only allow left mouse click on the following guis:

  if (interface == GUI2) {
    if (button == 0) {
      // do stuff
    }
  }

  //...
}


Edit: Minor syntax corrections.

strazer

#18
Quote from: Pumaman on Tue 08/02/2005 20:19:22
Quote
mouse.ChangeModeGraphic doesn't work properly with the UseInv mouse cursor.
It works if it is the current cursor mode, but each time you cycle to it with mouse.SelectNextCursorMode, it resets to the active inv item's sprite.

Use SetGameOption with OPT_FIXEDINVCURSOR to stop this behaviour.


Or check "Don't use inventory graphics as cursors" in General settings.
However, doing it this way, it doesn't use the inv item's custom hotspot location, so it's probably better to use the workaround above.

SMF spam blocked by CleanTalk