Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: x_traveler_x on Mon 21/03/2005 04:29:41

Title: Small nuisance with ChangeCursorGraphic (SOLVED)
Post by: x_traveler_x on Mon 21/03/2005 04:29:41
I recently put something in my script which changes the cursor's graphic for each item (rather than just using the item for the cursor).   Here's the code:


// ##### INVENTORY ITEM CURSORS #####

  if (character[EGO].activeinv == 1) ChangeCursorGraphic (4,66);
  if (character[EGO].activeinv == 2) ChangeCursorGraphic (4,69);


... and so on for each item I add.  I put this script in the repeatedly_execute() section of my global.

This script does work nicely.  The problem, albeit a very small one, is when an item is selected, and its corresponding item cursor is active, it overrides all SetCursorMode(6) commands.   For example, I placed a SetCursorMode(6) at the beginning of all my GUIs so that a blank arrow cursor would be active.  This always works unless the item cursor is active. 

Am I taking the right approach to this?
Title: Re: Small nuisance with ChangeCursorGraphic
Post by: Pumaman on Mon 21/03/2005 20:24:01
ChangeCursorGraphic should only alter the current mouse cursor if the current mode is the same as the mode you're changing.

Are you sure you don't have a SetCursorMode(4) with your ChangeCursorGraphic code?
Title: Re: Small nuisance with ChangeCursorGraphic
Post by: x_traveler_x on Tue 22/03/2005 02:39:43
Okay, I had to read your post again because I misunderstood what you were asking.  Sorry :)

Yes, I have tripple-checked my global and I'm certain that that there are no SetCursorMode(4) commands with my ChangeCursorGraphic code.  The only place where SetCursorMode(4)  can be found is on the ICONBAR GUI, where it is by default.

I'll try to rephrase my problem.  At the top of all my GUIs' codes, I placed a SetMouseCursor (6) so that the cursor turns to an arrow every time a GUI is accessed.  It works all the time, except for when an inventory item is selected and its corresponding cursor is on screen-- that's when the item's cursor stays on screen and SetMouseCursor(6) seems to be ignored.  Now if I cycle-through to another cursor, and then access a GUI again, the problem goes away and the normal arrow comes back.

I'm absolutely baffled by this, because according to the logic in my code...


if (character[EGO].activeinv == 1) ChangeCursorGraphic (4,66);


... only Mouse Cursor #4 should have its image changed.  However, it seems to affect Mouse Cursor #6, too as long as it is the current cursor.

-=-=-=-=-

Just tested it with SetCursorMode (6) instead of SetMouseCursor (6)... no dice.
Title: Re: Small nuisance with ChangeCursorGraphic
Post by: Pumaman on Tue 22/03/2005 20:19:35
Quote from: x_traveler_x on Tue 22/03/2005 02:39:43
I'll try to rephrase my problem. At the top of all my GUIs' codes, I placed a SetMouseCursor (6) so that the cursor turns to an arrow every time a GUI is accessed.

That would explain it, since SetMouseCursor(6) still leaves the cursor mode as whatever it was before.

Quote
Just tested it with SetCursorMode (6) instead of SetMouseCursor (6)... no dice.

That on the other hand is rather strange ... perhaps you could use GetCursorMode to display the current cursor mode before you do your ChangeCursorGraphic lines, just for debugging to check that it is indeed 6.
Title: Re: Small nuisance with ChangeCursorGraphic
Post by: x_traveler_x on Tue 22/03/2005 21:53:26
Just tried your suggestion.Ã,  Unfortunately, it didn't seem to have any effect.

Here's what I did:

Ã,  if (character[EGO].activeinv == 1) {
Ã,  Ã,  if (GetCursorMode() == 4){
Ã,  Ã,  Ã,  ChangeCursorGraphic (4,66);
Ã,  Ã,  }
Ã,  }


Could it maybe be incorrect to put this in the repeatedly_execute() section of my global?
Title: Re: Small nuisance with ChangeCursorGraphic
Post by: Pumaman on Wed 23/03/2005 18:26:27
What I meant was something like this:

Display("Cursor mode %d.", GetCursorMode());

so that you can check for sure whether the cursor mode is 4 or 6.
Title: Re: Small nuisance with ChangeCursorGraphic
Post by: x_traveler_x on Thu 24/03/2005 01:21:54
My fault.. how silly of meÃ,  :-\

I tried it.Ã,  Here's a screengrab showing the results:

(http://fallingpeople.constructivechaos.net/troubleshoot.png)

Cursor Mode 4 seems to be active at the time.
Title: Re: Small nuisance with ChangeCursorGraphic
Post by: Pumaman on Thu 24/03/2005 14:40:40
Try searching your script for "SetCursorMode" to see if you might be inadvertently setting it elsewhere.
Title: Re: Small nuisance with ChangeCursorGraphic
Post by: x_traveler_x on Thu 24/03/2005 20:59:47
SetCursorMode(4) only appears in this part of my global:


// ##### ICONBAR #####

Ã,  if (interface == 1) {
Ã,  Ã,  SetMouseCursor (6);
Ã,  Ã,  if (button == 4) {Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  // Show INVENTORY
Ã,  Ã,  Ã,  show_inventory_window ();
Ã,  Ã,  }
Ã,  Ã,  else if (button == 5) {Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  // Use selected ITEM
Ã,  Ã,  Ã,  if (character[ GetPlayerCharacter() ].activeinv >= 0)
Ã,  Ã,  Ã,  Ã,  SetCursorMode(4);
Ã,  Ã,  }
Ã,  Ã,  Ã,  if (button == 6) {Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  // Show CONTROLPANEL
Ã,  Ã,  Ã,  Ã,  GUIOff(1);Ã,  Ã,  Ã, 
Ã,  Ã,  Ã,  Ã,  GUIOn(4);
Ã,  Ã,  }
Ã,  }


I don't have any SetCursorMode(6)'s anywhere.
Title: Re: Small nuisance with ChangeCursorGraphic
Post by: Pumaman on Fri 25/03/2005 12:36:24
Quote from: x_traveler_x on Thu 24/03/2005 20:59:47
I don't have any SetCursorMode(6)'s anywhere.

In that case, that would explain why the cursor mode is still 4. You'd need to use SetCursorMode(6) to change it.
Title: Re: Small nuisance with ChangeCursorGraphic
Post by: x_traveler_x on Fri 25/03/2005 17:20:15
I did try that.  Remember when I said earlier that I put SetMouseCursor(6) at the beginning of the GUI scripts to change it?  Then I changed it to SetCursorMode(6) instead, but that didn't work either.
Title: Re: Small nuisance with ChangeCursorGraphic
Post by: Ashen on Fri 25/03/2005 18:10:44
Looking at your code, the cursor mode would only be changed when a button was pushed not when the GUI opened, so of course mode 4 would be active. You need to put the SetCursorMode(6)/SetMouseCursor(6) wherever in the script you open the GUI.
Title: Re: Small nuisance with ChangeCursorGraphic
Post by: x_traveler_x on Fri 25/03/2005 23:23:40
Unfortunately, I tried that too, but it makes no difference where I put the code.Ã,  Usually everything works fine with the way the code is now, but when any selected item is active and the item cursor is changed, THEN the problem occurs.Ã,  Based on that, I can only assume that I did something wrong when I added the ChangeCursorGraphic code.Ã,  At any rate, it continues to boggle me.

???

I do appreciate your help, guys, really.

Title: Re: Small nuisance with ChangeCursorGraphic
Post by: Ashen on Fri 25/03/2005 23:33:47
OK, what about:

// ##### INVENTORY ITEM CURSORS #####
if (GetGUIAt (mouse.x, mouse.y) == -1) { // mouse not over a GUI, make mode 4 look like item
  if (character[EGO].activeinv == 1) ChangeCursorGraphic (4,66);
  if (character[EGO].activeinv == 2) ChangeCursorGraphic (4,69);
  // etc for other items
}
else ChangeCursorGraphic (4, ARROWGRAPHIC); // mouse over GUI, use arrow graphic
Title: Re: Small nuisance with ChangeCursorGraphic
Post by: x_traveler_x on Fri 25/03/2005 23:47:24
Interesting idea, but it has a problematic side effect.  Now the cursor's graphic doesn't change when the player chooses an item (unless you move it off the GUI).

I'll play around wih it some more.  Maybe I'll come up with something.

Thanks again!
Title: Re: Small nuisance with ChangeCursorGraphic
Post by: Ashen on Sat 26/03/2005 00:03:30
That's not so much a 'problematic side effect', as exactly what it was meant to do. I must've missunderstood what you wanted, sorry about that.

What exactly DO you want to happen? You said:
Quote
It works all the time, except for when an inventory item is selected and its corresponding cursor is on screen-- that's when the item's cursor stays on screen and SetMouseCursor(6) seems to be ignored.
And yet now when the graphic doesn't change you call it a problem. I don't mean to sound rude, or irritated, it'd just be easier for me to help, if I actually understood what I'm helping you do.
Title: Re: Small nuisance with ChangeCursorGraphic
Post by: x_traveler_x on Sat 26/03/2005 00:05:07
SOLVED!

I modified the idea you gave me, Ashen, and came up with this:



// ##### "ARROW" CURSOR MAINTANENCE #####
 
  if (GetGUIAt (mouse.x, mouse.y) == 1) SetMouseCursor(6);
  if (GetGUIAt (mouse.x, mouse.y) == 3) SetMouseCursor(6);



... and so on for every GUI where I want the cursor to be an arrow!  It seems so obvious now :)

Thanks again!
Title: Re: Small nuisance with ChangeCursorGraphic
Post by: x_traveler_x on Sat 26/03/2005 00:17:28
Quote
And yet now when the graphic doesn't change you call it a problem. I don't mean to sound rude, or irritated, it'd just be easier for me to help, if I actually understood what I'm helping you do.

I realize it sounded very confusing the way I was describing it.  And I am truely sorry about that.  So I understand and sympathize with any frustration. 

What I wanted was to change the mouse cursor into arrow-shaped-pointer which displayed the inventory item, because I strongly dislike using the item itself with a hotspot as the cursor.  When I used your suggestion, the cursor was still in the INVENTORY GUI when the player selected it, therefore preventing the arrow changing into the item cursor.

That should hopefully clear up any confusion.  I am pleased to say that I was able to solve this (as I mentioned in my previous post) by modifying the suggestion you gave me.  See above.

Again, thanks Ashen and Pumaman, for all the help and support.  It helped, and I learned from it!

Peace!

Title: Re: Small nuisance with ChangeCursorGraphic
Post by: Ashen on Sat 26/03/2005 00:18:45
No problem, glad it's sorted.
However, if there's only one GUI (i.e. the inventory) you don't want it on, you could try:

if (GetGUIAt (mouse.x, mouse.y) == -1) { // mouse not over a GUI, make mode 4 look like item
  if (character[EGO].activeinv == 1) ChangeCursorGraphic (4,66);
  if (character[EGO].activeinv == 2) ChangeCursorGraphic (4,69);
  // etc for other items
}
// ##### "ARROW" CURSOR MAINTANENCE #####
else if (GetGUIAt (mouse.x, mouse.y) != INVGUI) SetMouseCursor(6);

Or something similar, anyway, to cut down the number of lines needed.

On a similar theme - couldn't you give each inventory item a 'cursor' property, set to the sprite number you want it to have, and just use one:

if (character[EGO].activeinv != -1) ChangeCursorGraphic (4, GetInvProperty(player.activeinv, "cursor"));

Instead of having a line for each item.
Title: Re: Small nuisance with ChangeCursorGraphic
Post by: x_traveler_x on Sat 26/03/2005 00:24:31
Good points.  I suppose I could give those suggestions a try.

I'll experiment with them and see how they turn out.

Thanks again!