Hi all,
I've been trying to program my own "broken sword" like inventory window. I thought it was working, but it's now a complete mess.
My GUI works with no icons. Essentially, you left-click to walk and interact, and you right click to look at something. Outside of the inventory, that works perfectly.
The inventory GUI is called by moving the mouse to the top of the screen, and the inventory items are displayed. Right-clicking on the items gives you a description. No surprises there. Left-clicking selects the item, and the cursor turns into a graphic of the inventory item. Fine.
However, when I move the cursor out of the inventory GUI, then move it back in, the cursor turns back into the standard cursor! But it still reacts like the inventory item is still selected (i.e., you have a locked box and a key. You left-click the key, the cursor turns into the key, you move the cursor out of the inventory window, then move it back in. The cursor turns back into the default arrow cursor, but you can still click it on the locked box and it works).
Another thing, the cursor spontaneously changes into the AGS "look" or "walk" cursors for seemingly no reason. Right-clicking fixes the problem, but I don't know why that's happening.
I've posted my code below. Any light shedding appreciated!
Thanks,
-Dave
function on_mouse_click(int button) // called when a mouse button is clicked. button is either LEFT or RIGHT
{
GetGlobalInt(284);
if(GetGlobalInt(284)==0)
{
if (button==LEFT) // LEFT CLICK
{
GUIOff(2);
if(GetGlobalInt(1)==0)
{
ProcessClick(mouse.x, mouse.y, MODE_USE);
ProcessClick(mouse.x, mouse.y, MODE_WALK);
}
else if(GetGlobalInt(1)==1)
{
ProcessClick(mouse.x, mouse.y, MODE_USEINV);
SetGlobalInt(1,1);
}
else if (GetGlobalInt(1) ==2)
{
character[INVIS].room=character[EGO].room;
SetPlayerCharacter(INVIS);
Display("Active Inventory is %d", game.inv_activated);
SetActiveInventory(game.inv_activated);
ProcessClick(mouse.x, mouse.y, MODE_USEINV);
SetPlayerCharacter(EGO);
character[INVIS].room=-1;
SetGlobalInt(1,2);
}
}
else if (button==RIGHT) // RIGHT CLICK
{
GUIOff(2);
SetCursorMode(6);
ProcessClick(mouse.x, mouse.y, MODE_LOOK ); // SINGLE-CLICK RIGHT
SetGlobalInt(1,0);
}
else if (button==LEFTINV) // LEFT CLICK ON INV
{
if(GetGlobalInt(1)==0) {
if (game.inv_activated == 4) //IF PLAYER SELECTS NOTEBOOK, OPEN NOTEBOOK INVENTORY
{
GUIOff(3);
SetInvDimensions(115,10);
GUIOn(4);
character[INVIS].room = character[EGO].room;
character[INVIS].x = character[EGO].x;
character[INVIS].y = character[EGO].y;
// if you are in a scrolling room, so the viewpoint doesn't suddently shift
SetPlayerCharacter(INVIS);
}
else
{
SetActiveInventory(game.inv_activated);
SetGlobalInt(1,1);
if (notebook ==1) SetGlobalInt(1,2);
}
}
else if(GetGlobalInt(1)==1)
{
if (GetCursorMode() == 4)
{
RunInventoryInteraction (game.inv_activated, 4);
}
else
{
RunInventoryInteraction (game.inv_activated, MODE_USE);
}
}
else if (GetGlobalInt(1) ==2)
{
character[INVIS].room=character[EGO].room;
SetPlayerCharacter(INVIS);
if (GetCursorMode() == 4)
RunInventoryInteraction (game.inv_activated, 4);
else
RunInventoryInteraction (game.inv_activated, MODE_USE);
SetPlayerCharacter(EGO);
character[INVIS].room=-1;
SetCursorMode(6);
SetGlobalInt(1,0);
}
}
else if (button==RIGHTINV) // RIGHT CLICK ON INV
{
RunInventoryInteraction (game.inv_activated, MODE_LOOK); // SINGLE-CLICK RIGHT
}
}
else if (GetGlobalInt(284)==1)
{
if (button==LEFT) // LEFT CLICK
{
if (WaitMouseKey(10)==1)
{
QuitGame(0);
}
else if (WaitMouseKey(10)==0)
{
QuitGame(0);
}
}
}
}
Have you got any code in repeatedly_execute that changes the mouse cursor?
Actually... yes. :o
I have another GUI that follows the cursor around and displays each hotspot's name when the cursor passes over it. When a hotspot is detected, the cursor turns red.
Here it is:
function repeatedly_execute()
{
// put anything you want to happen every game cycle here
if ( (GetLocationType (mouse.x, mouse.y) ) ==0)
{
GUIOff(2);
if (GetGlobalInt(2)==1)
{
SetMouseCursor(6);
SetGlobalInt(2,0);
}
}
else
{
if ( GetGlobalInt(1) == 0)
{
SetMouseCursor(8);
SetGlobalInt(2,1);
}
GetLocationName(mouse.x,mouse.y,buffer);
int px= mouse.x;
int py = mouse.y-17;
SetGUIPosition(2, px,py);
GUIOn(2);
SetLabelText(2,0,buffer);
}
if (IsKeyPressed(17) == 1)
QuitGame(0);
}
Try replacing this:
if (GetGlobalInt(2)==1)
with this:
if ((GetGlobalInt(2)==1) && (IsGUIOn(INVENTORYGUI) == 0))
what's probably happening is that GetLocationType is returning 0 when you move over the GUI, and it is then running the SetMouseCursor(6) code.
Dave, I will personally give you a big pile of
Spoiler
respect, which is nearly as good as
money if you release your BS interface as a template!
Heh. If I can get it to work, I will! :-)