Changing UseInv cursor when over icon bar

Started by Akril15, Sat 19/03/2011 23:11:38

Previous topic - Next topic

Akril15

I'm still tweaking my game's interface in the hopes of improving it. So far, I've accomplished quite a bit, but I've come across a small problem that (as usual) is proving very difficult to solve.

I'm using the Sierra-style icon bar, and I've just noticed that if I have an inventory item selected and the UseInv (use inventory) cursor is active, the cursor won't change to an arrow cursor like it does with every other mouse mode. This looked a little sloppy, so I tried entering this code in repeatedly_execute in the hopes of correcting this problem:

Code: ags
GUI *thegui = GUI.GetAtScreenXY(mouse.x, mouse.y);
if (thegui == gIcons)  {
mouse.SaveCursorUntilItLeaves();
mouse.Mode=eModePointer;
}


As it turned out, this was a bad idea. When I tried running the game and selected an inventory item, the cursor did change to an arrow when I moved the cursor over the icon bar, but several other problems popped up in its place. When I opened the inventory GUI, the items wouldn't respond when I clicked on them with arrow cursor. When selecting other icons from the icon bar (look, talk, etc.), if I've already selected an inventory item, the cursor will turn into the UseInv cursor (both looking AND behaving like it) when it moves over a hotspot* and then stays that way (this doesn't happen if I right-click to cycle through the cursors). If I haven't selected an inventory item when I select one of the icons, however, however, the cursor will turn into the arrow cursor when it moves over a hotspot.

Any idea how I can get around this problem without causing any others?

Thanks in advance!

*I'm using a set of cursors that highlight when they are over a hotspot -- they're set to animate when they're over a hotspot, but they just use a single frame of a different view.

monkey0506

#1
Instead of using mouse.SaveCursorUntilItLeaves, I'd suggest simply using mouse.UseModeGraphic:

Code: ags
GUI *thegui = GUI.GetAtScreenXY(mouse.x, mouse.y);
if (thegui == gIcons) mouse.UseModeGraphic(eModePointer);
else mouse.UseDefaultGraphic();


This is very, very similar to a recent thread..to which I supplied an answer I believe..yesterday was it..

Hmm..anyway, as I mentioned there, this particular method would not play nicely if you're using UseModeGraphic elsewhere in your game, but that's easy enough to deal with if you need to.

Edit: I actually finished reading your post (:P) and you might want to add another condition to the if statement:

Code: ags
if ((thegui == gIcons) && (mouse.Mode == eModeUseInv)) {


Also, what would the expected behaviour for eModePointer on an inventory item be? And why would you be against using inventory items on other inventory items..?

Akril15

Quote from: monkey_05_06 on Sun 20/03/2011 00:53:33
This is very, very similar to a recent thread..to which I supplied an answer I believe..yesterday was it..
I'm sorry -- I search the forum whenever I have a problem that I can't solve, but I guess I didn't search hard enough here.

I tried using your code, but it didn't change the shape of the cursor. To answer your comment about UseModeGraphic, I use it various other times in the script, usually when a GUI is opened or closed. Is that part of the reason why the code isn't working?

QuoteAlso, what would the expected behaviour for eModePointer on an inventory item be? And why would you be against using inventory items on other inventory items..?
When the inventory window is open, eModePointer will select an inventory item.

I don't quite understand your second question -- do you mean that selecting an inventory item, closing the inventory window, then going to the icon bar and opening it again will effectively deselect that item so that it can't be used on another item? I don't have anything against using inventory items on other inventory items, I just think my interface would be a bit neater if the cursor didn't remain as an inventory item when it moves over the icons.

mordo

hi,
I thought this is the right thread for my problem...
I'm trying to reduce my mouse cursors to "walk to" "interact" and "look".
in the inventory which is on the bottom of the screen, there is no need for the "walk to" so I want to dismiss it, while the player is on the GUI gInventoryNEW.

I couldn't set a mouse over action to the GUI, so I tried to solve it whith a hotspot that covers the inventory GUI and put this code in it's mouse over action:
function hMenu_MouseMove()
{
//mouse.SaveCursorUntilItLeaves();
mouse.DisableMode (eModeWalkto);
}

(I don't know what the CurseUntilitleaves actually does, so I commented it out, because it's the same with or without).

Result is: I got rid of the "Walk to" cursor but it stays forever, even if I take the mouse off the hotspot.

Thanks for your help

Khris

What you need is

Code: ags
  if (GUI.GetAtScreenXY(mouse.x, mouse.y) == gInventory) mouse.DisableMode(eModeWalkto);
  else mouse.EnableMode(eModeWalkto);

mordo

Thanks for your answer. I just realized, however, that my real problem is not being able to change the cursors in the inventory bar at all. The cursor function, despite the icon changing to the normal mouse symbol, stays the same as in the room and is not changeable while the mouse is in the inventory GUI.

I decided to have the mouse use left-click as "Use" and right-click as "Look at", but I still need to set the left-click function to default "Use" when hovering over the inventory. I added mouse.Mode = eModeInteract; to your code, but it did nothing at all.

Where do I have to insert this kind of code to make it work?

Khris

I can be tricky; to detect mouse clicks over GUIs, you can use:
Code: ags
MouseButton last_button;

function on_event(EventType event, int data) {
  if (event == eEventGUIMouseDown && data == gInventory.ID) {
    int i = eMouseLeft;
    while (i <= eMouseMiddle) {
      if (mouse.isButtonDown(i)) last_button = i;
      i++;
    } 
  }

  if (event == eEventGUIMouseUp && data == gInventory.ID) {
    if (last_button == eMouseLeft) {
      // left click over gInventory
    }
    else if (last_button == eMouseRight) {
      // right click over gInventory
    }
  }
}


Just put this anywhere in your global script.

To detect clicks on inventory items, use eMouseLeftInv and eMouseRightInv in on_mouse_click. You have to turn the "handle inv clicks in script" option in General Settings though.

SMF spam blocked by CleanTalk