I'm looking to achieve an inventory that appears when the mouse moves to the top of the screen, and disappear when mouse is moved off (i have this, using Mouse YPos) It has no buttons besides btnInvUp and Down.
So, when the player (right) clicks on an inventory item it needs to turn into the cursor, and when the player (left) clicks it will perform "look at inventory item".
I've tried a few things and nothing works, as the mouse modes don't accomadate for this and they seem to be messing up in the inventory anyway.
Does anyone have a simple solution to making this posssible?
Thanks in advance.
The AGS default behaviour is pretty much backwards of what you want - Left-Click in interact mode sets as active, Right-Click will always run the 'Look' interaction. If you can live with that, then you shouldn't have to do anything. Otherwise, you're going to have to check the 'Handle invenotry clicks in script' option on the 'General Setting' window and script the clicks yourself (a forum search should turn up more details). Or, you could force the mouse to change Mode over the Inventory GUI to something other than interact, use
that as 'Look at', and have
eModeLookAt (right-click) set the active inventory ...
Could you clear up what you mean by:
Quote
the mouse modes don't accomadate for this and they seem to be messing up in the inventory anyway.
I guess it's related to the above suggestion - unless you click that option, the normal mouse interactions (that is,
on_mouse_click) aren't run on Inventory Items (and of course
eModeInteract doesn't really work at all).
Quote from: Ashen on Fri 16/02/2007 12:44:49
Could you clear up what you mean by:
Quote
the mouse modes don't accomadate for this and they seem to be messing up in the inventory anyway.
When in the inventory the right click does look, however left click does nothing at all. It should select that inventroy item as you say.
Also:
in on_mouse_click I've put
if (IsGamePaused() == 1) {
// Game is paused, so do nothing (ie. don't allow mouse click)
}
else if (button == eMouseLeft) { //left click will walk to and look at
ProcessClick(mouse.x, mouse.y, eModeWalkto);
ProcessClick(mouse.x, mouse.y, eModeLookat);
}
else if (button == eMouseRight) { //right click will walk to interact, talk and use current inv item
ProcessClick(mouse.x, mouse.y, eModeInteract);
ProcessClick(mouse.x, mouse.y, eModeWalkto);
ProcessClick(mouse.x, mouse.y, eModeTalkto);
ProcessClick(mouse.x, mouse.y, eModeUseinv);
}
This accomadates for my left and right mouse clicks when not in the inventory. It works fine, but could it be causing a problem?
Obvious question, but is the mouse set to Interact? Left-Click will only set the item as active in eModeInteract, otherwise it'll try to run whatever mode's interaction it's set to. You could try an 'Any click on item' interaction that'll set it as active if anything other that 'Look at'. (YPos visible GUIs change the mouse cursor, but not the actual mode - if you open the GUI in Walk to mode, it'll still be in Walk to when you click an item even though the graphic has changed. Also, AFAIK, 'Walk to' won't trigger the 'Any Click' interaction by defualt.)
That on_mouse_clcik code is a little confusing to me (why are you running so many different interactions at once?) but I'm not sure if it's your problem. If you haven't checked the 'Handle inventory clicks in script' option, on_mouse_click isn't run at all when you click an Item. If you have checked it, it'll be looking for eMouseLeftInv/RightInv conditions - so those ones still wouldn't be running.
(show_inventory_window() function sets the mouse to Interact, yes)
else if (button == eMouseLeftInv) {
ProcessClick(mouse.x, mouse.y, eModeLookat);
}
else if (button == eMouseRightInv) {
ProcessClick(mouse.x, mouse.y, eModeInteract);
}
I've added this in on_mouse_click and checkeed the "handle inventory clicks in script".
It still doesn't work. Walk mode still seems to be on instead, as the player moves to the edge of the screen when you click on the inventory item.
Quote from: markbilly on Fri 16/02/2007 14:24:02
(show_inventory_window() function sets the mouse to Interact, yes)
Yes, but in order for it to actually set the
Interact mode the show_inventory_window() function itself must be invoked, but it is not; that's because you use Mouse YPos popup style to show the GUI.
I would suggest to change its Visible property to Popup Modal and then manually script its appearance, triggering it up from
repeatedly_execute, effectively simulating the Mouse YPos popup behaviour:
function repeatedly_execute( ) {
Ã, Ã, if (gInventory.Visible == false)
Ã, Ã, {
Ã, Ã, Ã, Ã, if (mouse.y < 10)
Ã, Ã, Ã, Ã, {
Ã, Ã, Ã, Ã, Ã, Ã, gInventory.Visible = true;Ã, Ã,Â
Ã, Ã, Ã, Ã, Ã, Ã, mouse.Mode = eModeInteract; // you can change the mode on popup
Ã, Ã, Ã, Ã, }
Ã, Ã, }
Ã, Ã, else if ( GUI.GetAtScreenXY(mouse.x, mouse.y) != gInventory )
Ã, Ã, {
Ã, Ã, Ã, Ã, gInventory.Visible = false;
Ã, Ã, }
}
This way you will have a greater control over how and when it appears and can do additional work, such as changing the cursor mode.
Quoteelse if (button == eMouseLeftInv) {
Ã, Ã, ProcessClick(mouse.x, mouse.y, eModeLookat);
}
Unfortunately, you cannot use ProcessClick() to trigger inventory item events, since this function "clicks" behind any GUI.
An alternative would be to manually run the event:
...
else if (button == eMouseLeftInv)
{
inventory[ game.inv_activated ].RunInteraction( eModeLookat );
}
...
Here,
game.inv_activated represents the number of inventory item the player has just clicked over.
To turn an inventory item into the cursor set up player
active inventory item accordingly:
...
else if (button == eMouseRightInv)
{
player.ActiveInventory = inventory[ game.inv_activated ];
}
...
Edited to add [ code ] [ /code ] tags.
The PopupModal simulation of YPos is a great help thanks, this means I can tell it it has to be at a certain x position too. Meaning the inventory will appear when the player hovers over a particular point(sort of button) on a persistent GUI.
This will work, yes? :P
Oh and the rest should be great too thanks!
In theory, it should work fine. In theory...
If you were actually going to use a Button (even an unclickable one) to mark the location, it might be easier to use GUIControl.GetAtScreenXY, than to directly check the mouse coords, i.e:
if(GUIControl.GetAtScreenXY(mouse.x, mouse.y) == btnShiny) ....
As opposed to:
if (mouse.x > 35 && mouse.x < 50 && mouse.y > 5 && mouse.y < 20) ...
If nothing else, it'd mean you could move the 'button' around without having to change the code everytime.
That's much neater.
Thanks.
As you know, I'm using this script stuff (below) to handle my inventory clicks.
However, if I use a conditional 'if inv item used' on another inv item. In other words, if I use inventory item on another inv item, it does not work. It just changes the cursor to the item I click on with the other instead.
Is there a limitation in the script?
else if (button == eMouseLeftInv) {
inventory[ game.inv_activated ].RunInteraction( eModeLookat );
}
else if (button == eMouseRightInv) {
player.ActiveInventory = inventory[ game.inv_activated ];
}
Thanks again.
The script of course doesn't handle that.
The script code below only sets active inventory item if it hasn't been set yet. Otherwise it runs the Use inventory on this item interaction. Left-clicking will cancel active item if there is one, or will run the Look At interaction otherwise:
within on_mouse_click:
...
else if (button == eMouseLeft)
{
Ã, Ã, // handles a situation when left-clicking is over anything but GUI
Ã, Ã, if (player.ActiveInventory != null)
Ã, Ã, {
Ã, Ã, Ã, Ã, player.ActiveInventory = null;
Ã, Ã, }
Ã, Ã, else
Ã, Ã, {
Ã, Ã, Ã, Ã, // some other stuff may go here
Ã, Ã, }
}
else if (button == eMouseLeftInv)
{
Ã, Ã, if (player.ActiveInventory == null)
Ã, Ã, {
Ã, Ã, Ã, Ã, inventory[ game.inv_activated ].RunInteraction( eModeLookat );
Ã, Ã, }
}
else if (button == eMouseRightInv)
{
Ã, Ã, if (player.ActiveInventory == null)
Ã, Ã, {
Ã, Ã, Ã, Ã, player.ActiveInventory = inventory[ game.inv_activated ];
Ã, Ã, }
Ã, Ã, else
Ã, Ã, {
Ã, Ã, Ã, Ã, inventory[ game.inv_activated ].RunInteraction( eModeUseinv );
Ã, Ã, }
}
...
the on_event() function:
function on_event(EventType event, int data) {
Ã, Ã, // handles a situation when left-clicking is over GUI
Ã, Ã, // actually duplicates eMouseLeft script in on_mouse_click to work over GUIs
Ã, Ã, if (event == eEventGUIMouseDown)
Ã, Ã, {
Ã, Ã, Ã, Ã, if ( mouse.IsButtonDown( eMouseLeft ) )
Ã, Ã, Ã, Ã, {
Ã, Ã, Ã, Ã, Ã, Ã, Ã, if (player.ActiveInventory != null)
Ã, Ã, Ã, Ã, Ã, Ã, Ã, {
Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, player.ActiveInventory = null;
Ã, Ã, Ã, Ã, Ã, Ã, Ã, }
Ã, Ã, Ã, Ã, Ã, }
Ã, Ã, }
}
Quote
within on_mouse_click:
Code:
...
else if (button == eMouseLeft)
{
// handles a situation when left-clicking is over anything but GUI
if (player.ActiveInventory != null)
{
player.ActiveInventory = null;
}
else
{
// some other stuff may go here
}
}
else if (button == eMouseLeftInv)
{
if (player.ActiveInventory == null)
{
inventory[ game.inv_activated ].RunInteraction( eModeLookat );
}
}
else if (button == eMouseRightInv)
{
if (player.ActiveInventory == null)
{
player.ActiveInventory = inventory[ game.inv_activated ];
}
else
{
inventory[ game.inv_activated ].RunInteraction( eModeUseinv );
}
}
...
Is this as well as, or instead of what I already have?
thanks
EDIT:
Don't worry, I've worked it out. Works perfectly, thanks again.
My Inventory GUI however, how do I get it to disappear when the mouse moves out of it?
I hope all these questions are helping someone else too, because there are a lot of them :P This should be the last thing though, and then everything should work fine.
Please, don't double post.
Scorpiorus' repeatedly_execute code a few posts back (dated 17th Feb) should do that already. If it's not working, try moving it to repeatedly_execute_always instead - if gInventory is Popup Modal, rep_ex won't run.
Quote from: Ashen on Tue 27/02/2007 17:27:27
Please, don't double post.
Scorpiorus' repeatedly_execute code a few posts back (dated 17th Feb) should do that already. If it's not working, try moving it to repeatedly_execute_always instead - if gInventory is Popup Modal, rep_ex won't run.
I'm sorry, I forgot about it as I didn't use it in the end. Now however I need it.
By the way, it should even work in repeatedly_execute as there is normally no check for IsGamePaused(), unlike with on_mouse_click.
However, putting it into repeatedly_execute_always would help trigger it when the script is being blocked, if you need or want so.