I've been using the single click cursor script from hedgefield (link (http://www.adventuregamestudio.co.uk/forums/index.php?topic=44421.0)) which works very nicely.
I would like to add the feature of closing the inventory automatically upon selecting an item. I know I have to use "gInventory.Visible = false;" but I have no idea where to place it. I've tried certain lines but none of them worked. Is it possible to do this within this script?
Here is the script for reference:
//MOUSE CLICKS
function on_mouse_click(MouseButton button) {
//Walk/Talk/Interact:
if ((button == eMouseLeft && SC_SwapLeftRight == false) || (button == eMouseRight && SC_SwapLeftRight == true)) {
if ((GetLocationType(mouse.x, mouse.y) == eLocationHotspot) || (GetLocationType(mouse.x, mouse.y) == eLocationObject)) {
if (mouse.Mode == eModeUseinv) ProcessClick(mouse.x,mouse.y, mouse.Mode);
else ProcessClick(mouse.x, mouse.y, eModeInteract);
}
else if (GetLocationType(mouse.x, mouse.y) == eLocationCharacter) {
if (mouse.Mode == eModeUseinv) ProcessClick(mouse.x, mouse.y, mouse.Mode);
else ProcessClick(mouse.x, mouse.y, eModeTalkto);
}
else ProcessClick(mouse.x, mouse.y, eModeWalkto);
}
//LookAt:
else if ((button == eMouseRight && SC_SwapLeftRight == false) || (button == eMouseLeft && SC_SwapLeftRight == true)) {
if (mouse.Mode == eModeUseinv) {
player.ActiveInventory = null;
mouse.Mode = eModePointer;
}
else if ((GetLocationType(mouse.x, mouse.y) == eLocationHotspot) || (GetLocationType(mouse.x, mouse.y) == eLocationCharacter) || (GetLocationType(mouse.x, mouse.y) == eLocationObject)) {
ProcessClick(mouse.x, mouse.y, eModeLookat);
}
}
//Inventory select/combine:
if (SC_CustomInvClicks == true) {
if ((button == eMouseLeftInv && SC_SwapLeftRight == false) || (button == eMouseRightInv && SC_SwapLeftRight == true)) {
if (inventory[game.inv_activated].IsInteractionAvailable(eModeUseinv) == 1 && mouse.Mode == eModeUseinv) {
inventory[game.inv_activated].RunInteraction(eModeUseinv);
}
else if (inventory[game.inv_activated].IsInteractionAvailable(eModeInteract) == 1) inventory[game.inv_activated].RunInteraction(eModeInteract);
else player.ActiveInventory = inventory[game.inv_activated];
}
}
}
//INVENTORY CLICKS
function on_event(EventType event, int data) {
GUI *theGUI = gInventory1.OwningGUI;
if (SC_CustomInvClicks == true) {
//deselect current inventory item:
if (event == eEventGUIMouseDown && player.ActiveInventory != null && data == theGUI.ID) {
if ((mouse.IsButtonDown(eMouseRight) && SC_SwapLeftRight == false) || (mouse.IsButtonDown(eMouseLeft) && SC_SwapLeftRight == true)) {
GUIControl *theControl = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
if (theControl==gInventory1) {
player.ActiveInventory = null;
}
}
}
//look at inventory item:
else if (event == eEventGUIMouseDown && player.ActiveInventory == null && data == theGUI.ID) {
if ((mouse.IsButtonDown(eMouseRight) && SC_SwapLeftRight == false) || (mouse.IsButtonDown(eMouseLeft) && SC_SwapLeftRight == true)) {
GUIControl *theControl = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
if (theControl==gInventory1) {
InventoryItem *i = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
if (i != null) i.RunInteraction(eModeLookat);
}
}
}
}
}
I can't test this right now, but line 32 is where the new active inventory item is set. Try this:
else
{
player.ActiveInventory = inventory[game.inv_activated];
gInventory.Visible = false;
}
Thanks for your reply! I've tested it out but unfortunately it doesn't change anything...
What's the visibility setting of your inventory GUI?
It was set to "Pause game when shown", I've just tested it with "Normal, initially off" as well but without change.
It seems the inventory is called gInventory1, not gInventory. Could that be the problem?
The inventory window is called gInventory1 which is placed on the GUI called gInventory.
It closes just fine when I click the button for it but somehow won't close when selecting an item ???
Is it maybe because the script to open the inventory window when the mouse hovers over it immediately runs again, thus reopening the GUI before the next game loop even happens?
If this is the case then you just have to correct/recode the GUI's popup function to not happen if the player's cursor has not moved below the popup zone after changing to the item graphic. (A simple bool to keep track of this should be cool)
This means the GUI should vanish when the player selects an item, and will only reappear if the cursor is moved down the screen and then back up to the top again.
No, I don't have a fancy hover animation or anything like that, didn't look into how that works yet. I just have the inventory opening with the press of a button that shows on the screen:
function btnOpenInventory_OnClick(GUIControl *control, MouseButton button)
{
show_inventory_window();
}
And then a button on the inventory GUI that closes it again:
function bCloseInventory_OnClick(GUIControl *control, MouseButton button)
{
gInventory.Visible = false;
mouse.UseDefaultGraphic();
if (player.ActiveInventory==null)
mouse.Mode = eModePointer;
}
When I click on the item, the cursor changes to reflect this properly, but the inventory GUI remains open.
The first order of debugging: add a Display command:
else
{
player.ActiveInventory = inventory[game.inv_activated];
Display("Hiding inventory now.");
gInventory.Visible = false;
}
What happens when you try this?
this may be a dumb question but your call to btnOpenInventory_OnClick calls a function called show_inventory_window.
Have you verified that "show_inventory_window" displays gInventory?
Alright it works now, thanks everyone for all your insights!
Khris' comment made me realize that the section didn't even trigger and I saw I didn't properly place a step in the setup of the script. Truly a beginner mistake :(
Step 3 was clearly written as: "Use the bool SC_SwapLeftRight and the function CustomInv(true or false) in your gamestart function to modify the controls." but I didn't write it properly there.
Just adding this fixed it:
function game_start() {
CustomInv(true);
Once again a huge thanks all! ;-D