(SOLVED) change to pointer mode over Inventory window

Started by Nixxon, Tue 20/10/2015 12:12:10

Previous topic - Next topic

Nixxon

Hey all,

I've searched this and seems to be a few threads, but all are over my head. They seem a little more complex than what I'm looking to achieve.

I'm using a Sierra based UI. However, I've decided to make this a persistent bar in the bottom of the screen (which works for the most part).

I wanted to 'do away' with the inventory button/ui completely and simply use the inventory window contained within the gIconbar GUI for all of my inventory shenanigans.

I have posted an image below to explain fully what I'm trying to achieve.



I'm starting to feel sheepish about asking such rudimentary questions on the forums. I'm honestly happy to donate or contribute a couple of bucks if needed.

Many thanks in advance.




MiteWiseacreLives!

#1
this is what I would do....

In the Global Script,
Code: ags

bool overmenubar; //declare at top of script

function repeatedly_execute() 
{
  
  if (GUI.GetAtScreenXY(mouse.x, mouse.y) == gInventory)
  {
    if (overmenubar == false)
    {
      mouse.Mode = eModePointer;
      overmenubar = true;
      mouse.DisableMode(eModeLookat);
      mouse.DisableMode(eModeTalkto);
      //etc...
    }
  }
  else
  {
    if (overmenubar == true)
    {
      overmenubar = false;
      mouse.EnableMode(eModeLookat);
      mouse.EnableMode(eModeLookat);
      //etc...
    }    
  }
}


If you want this behaviour regardless of cutscenes, or any other blocking scripts use: function repeatedly_execute_always()
but I don't think you'll really want that...
Give it a try  :)

Vincent

Here there's an error :

Code: ags

    if (overmenubar= false) //here
    {
    }
  else
  {
    if (overmenubar= true) //and here too
    {
    }    
}


Nixxon

Thank guys, I will apply this tonight.

Is there a particular spot in the Global script that this should go?

Retro Wolf

Never be afraid to ask questions, that's what the AGS community is all about!

MiteWiseacreLives!

#5
Quote from: Vincent on Tue 20/10/2015 18:20:18
Here there's an error :

Code: ags

    if (overmenubar= false) //here
    {
    }
  else
  {
    if (overmenubar= true) //and here too
    {
    }    
}


-sorry. See fix above
-put it in your global script, the repeatedly_execute function should already exist, just place it inside there as in the example. Just make sure you declare the Bool at the top of the global script.

Vincent

Quote from: MiteWiseacreLives! on Wed 21/10/2015 07:27:25
-sorry. See fix above

I Think that's okay :)

Quote from: Nixxon on Tue 20/10/2015 12:12:10
I wanted to 'do away' with the inventory button/ui completely and simply use the inventory window

I think it can be useful to have a look at this section too in the manual.
GetAtScreenXY (GUI control)
Checks whether there is a GUI control at screen co-ordinates(X,Y). Returns the control object if there is, or null if there is not.
You probably want to use this in conjunction with GUI.GetAtScreenXY(mouse.x, mouse.y);
Code: ags

GuiControl *theControl = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
if (theControl == invCustomInv)
{
  Display("The mouse is over the Inventory window.");
}
else if (theControl == null)
{
  Display("The mouse is not over a control.");
}
else
{
  GUI *onGui = theControl.OwningGUI;
  Display("The mouse is over control %d on GUI %d", theControl.ID, onGui.ID);
} 

Nixxon

Sorry guys,

Is there a specific place to paste the bool line of code?

MiteWiseacreLives!

Quote from: MiteWiseacreLives! on Wed 21/10/2015 07:27:25
Quote from: Vincent on Tue 20/10/2015 18:20:18

-put it in your global script, the repeatedly_execute function should already exist, just place it inside there as in the example. Just make sure you declare the Bool at the top of the global script.

Nixxon

#9
Think I've cracked this....

Works OK so far. However, is there a way to make the mouse resume the previous mouse mode if nothing is clicked or selected?

This would be GOLD.

MiteWiseacreLives!

For this, declare
int old_mouse_mode;
Again at the top of the global script.
Then just before we set the cursor to pointer:
old_mouse_mode = mouse.Mode;
Then just after enabling all the mouse modes again do:
mouse.Mode = old_mouse_mode;

I'm not able to test this right now, but you should be able to get it to work. If not maybe one of the über_scripters can chime in here... :)

Slasher

Yes,

Something along these lines (old code using int old_mode):

Code: ags

function repeatedly_execute_always() {


 GUI* theGui = GUI.GetAtScreenXY(mouse.x, mouse.y);
    
 
  if (theGui == gRestoreGame && mouse.Mode != eModePointer){
   old_mode=mouse.Mode;
   mouse.ChangeModeGraphic (eModePointer, 6);//2061
   mouse.Mode = eModeInteract; 
  }
   if (theGui == gInventory){
   old_mode=mouse.Mode;
   mouse.GetModeGraphic(eModeUseinv);
   
   } 
 
  if (theGui != gRestoreGame && mouse.Mode == eModePointer && mouse.GetModeGraphic(eModePointer) == 6)
  if (theGui != gPanel && mouse.Mode == eModePointer && mouse.GetModeGraphic(eModePointer) == 6)
  
  
{
  mouse.Mode=old_mode;  // Reverts to previous mode
}
}





Nixxon

#12
Hey guys,

Works with the below code. However it works over the whole GUI (which makes it impossible to select any modes to use on the screen walk/look etc.), is there a way to make the return function work only on the inventory window, not the whole GUI?

EDIT - I could probably make a single UI just for the inventory window and put it on top of the menu bar, this might be the best option?



Code: ags
function repeatedly_execute() {
  
  // Put here anything you want to happen every game cycle, even when
  // the game is paused. This will not run when the game is blocked
  // inside a command like a blocking Walk()
    if (GUI.GetAtScreenXY(mouse.x, mouse.y) == gIconbar)
  {
    if (overmenubar == false)
    {
      old_mouse_mode = mouse.Mode;
      mouse.Mode = eModeInteract;
      overmenubar = true;
      mouse.DisableMode(eModeTalkto);

      //etc...
    }
  }
  else
  {
    if (overmenubar == true)
    {
      mouse.Mode = eModeInteract;
      overmenubar = false;
      mouse.Mode = old_mouse_mode;
      mouse.EnableMode(eModeLookat);
      mouse.EnableMode(eModeTalkto);
      //etc...
    }    
  }
}

MiteWiseacreLives!

Maybe try
Code: AGS
GUIControl.GetAtScreenXY() == [insert name of your inventory window]

Instead of checking for the entire GUI

Nixxon

#14
Tried that one initially but it posted an error, something about not a valid GUI.

EDIT - I've made a new GUI with an inventory window using the above code. Now when I select and inventory item, as soon as I leave the GUI it goes back to the previous mode mode. Is there a way I can make it not return to previous mouse mode If I've selected an inventory item?


MiteWiseacreLives!

This is because of the mouse.Mode = old_mouse_mode
You want to add an if statement before this:
Code: ags

If(mouse.Mode != eModeUseInv)  {
   mouse.Mode = old_mouse_mode;
   }


Check my syntax, type it in instead of copy paste.. It will make more sense to you and AGS' nice auto correct will take care of any typos and show you a list of options.

Snarky

I get that you're not the most experienced coder, but doesn't this question sort of answer itself?

Yes, you just write a line of code to check whether there's an inventory item selected, and if so you skip the chunk of code that returns to previous mouse mode.

Nixxon

#17
It's complete hieroglyphs at this point. I already have an if statement, am I able to have two following each other?

Error - undefined token 'IF".

If I could just see where to put the code, I know it would make sense. (Invention via necessity).

Code: ags
function repeatedly_execute() {
  
  // Put here anything you want to happen every game cycle, even when
  // the game is paused. This will not run when the game is blocked
  // inside a command like a blocking Walk()
    if (GUI.GetAtScreenXY(mouse.x, mouse.y) == ginvwindow)
  {
    if (overmenubar == false)
    {
      old_mouse_mode = mouse.Mode;
      mouse.Mode = eModeInteract;
      overmenubar = true;
      mouse.DisableMode(eModeTalkto);

      //etc...
    }
  }
  else
  {
    if (overmenubar == true)
    {
      mouse.Mode = eModeInteract;
      overmenubar = false;
      mouse.Mode = old_mouse_mode;
      mouse.EnableMode(eModeLookat);
     
      //etc...
    }    
  }
}

MiteWiseacreLives!

Yes you can have if statement inside of another.
Not to be insulting, but are you actually reading my replies?
The code goes where I indicated, inside of the (overmenubar == true) block of code, you want to intercept the mouse.Mode = old_mouse_mode
If this is still not clicking for you I can get on my computer and type up the code for you later.

Nixxon

Quote from: MiteWiseacreLives! on Wed 28/10/2015 02:16:52
Yes you can have if statement inside of another.
Not to be insulting, but are you actually reading my replies?
The code goes where I indicated, inside of the (overmenubar == true) block of code, you want to intercept the mouse.Mode = old_mouse_mode
If this is still not clicking for you I can get on my computer and type up the code for you later.

No insult taken at all, I did try the code provided 5-6 different which ways before resorting to the boards, I always do.

I'll give it a go when I get home, thanks again for the patience and assistance.

SMF spam blocked by CleanTalk