A different kind of custom inventory (SOLVED)

Started by alkis21, Sat 22/04/2006 17:35:56

Previous topic - Next topic

alkis21

I feel a little embarrased asking a question in the Beginners' section, after having made a full length game... But the thing is, in my previous game, I used the built-in interface with just a few changes. This time, I'm trying to create my own interface, and I can't get it to work. The fact that I'm using AGS v2.71 while I made my previous game on 2.55 does not help either, as I'm still trying to figure out all the changes.

What I want to do is create a custom inventory GUI, with the following features:

-Pop-up bar when the mouse is placed on the top of the screen, displaying the first inventory items.
-Left and right arrows will be placed on either side of the bar, which will scroll the bar to display the remaining items.
-I don't want any buttons in it; I want the player to be able to click on the inventory item right away. Therefore, I don't want the mouse cursor mode to change when accessing the bar; if the current mode is Look, clicking on the item will examine it, if it's Use, clicking on the item will pick it up etc.

My problems so far:

-No matter how I try to alter the script, whenever the bar pops up the cursor changes to an arrow. Clicking on the item will still give the correct result, ie: if the cursor mode *before* accessing the inventory was Look, clicking on an item will examine it, but how do I prevent the cursor from changing?
-Clicking on an item always closes the pop-up bar, while I want it to remain open (in case the player wants to examine more items, or use one item on another) until the mouse is moved out of the area.
-I want the game to do NOTHING if the right mouse button is clicked on the inventory bar. I don't know how to do that.  :-[

Note that all of the above is *without* checking the "Handle inventory clicks in script" option... If I check it, I can't get anything to work.  :-[
As for the left & right arrows, I haven't even tried them yet, as I want to get the above right first.
I've read plenty of tutorials and previous threads on custom inventories, but they all require the use of buttons, which I'm trying to avoid.
Any help would be very much appreciated.

Ashen

#1
Well, the buttons should be easy enough - just use the InvWindow.ScrollUp/Down functions. The rest, are you using the 'Mouse Ypos' GUI visibility option? I think those 'problems' (cursor change, GUI close on click) are just the way it's coded. If you want it to behave differently, you'll need to code it yourself (use a Normal or Popup Modal GUI, check mouse.y in repeatedly_execute(_always) and turn the GUI on/off as needed).

QuoteI want the game to do NOTHING if the right mouse button is clicked on the inventory bar. I don't know how to do that.
What's the problem here, currently - I guess that right-clicks are being dealt with as left-clicks?

EDIT: Or was this just something for the future?
AFAIK, 'Handle Inv clicks in script' needs to be on for right-clicking the items to do anything. For the arrow buttons, you can disable right clicks in their control functions by requiring the left button to have been used, e.g.:
Code: ags

function btnInvUp_Click(GUIControl *control, MouseButton button) {
  if (button == eMouseLeft) invCustomInv.ScrollUp();
}
I know what you're thinking ... Don't think that.

alkis21

#2
Quote from: Ashen on Sat 22/04/2006 17:50:17
Well, the buttons should be easy enough - just use the InvWindow.ScrollUp/Down functions.

Yes, I don't think they will be a problem either.

QuoteThe rest, are you using the 'Mouse Ypos' GUI visibility option? I think those 'problems' (cursor change, GUI close on click) are just the way it's coded. If you want it to behave differently, you'll need to code it yourself (use a Normal or Popup Modal GUI, check mouse.y in repeatedly_execute(_always) and turn the GUI on/off as needed).

Thank you, you were absolutely right. As soon as I switched from "Mouse Ypos" to "Popup Modal", everything worked.
The (very basic) code I have so far is:

Code: ags

function repeatedly_execute() {
  if (mouse.y<=10) {
  DisableCursorMode(0);  
  InterfaceOn(5);
  }
  else if (mouse.y>30) {
  EnableCursorMode(0);
  InterfaceOff(5);
  }
}


I know, I'm using obsolete functions but I'm still learning the new ones... I'll make a cleaner code as soon as I get everything working (and worked out).

With the above, I can use the current mouse mode (except the Walk mode of course, which I disable) without problems, and the GUI remains open until I move the mouse cursor below it. But the right mouse button problems continue:

QuoteWhat's the problem here, currently - I guess that right-clicks are being dealt with as left-clicks?

No. For some reason, no matter which cursor mode I have, right clicking on an item executes the 'Look' option and returns a description.
Ideally, I would like to be able to cycle through the available cursor modes by repeatedly clicking on the right mouse button (just like when the GUI is off). Do I need to have the 'Handle Inv clicks in script' option on for that? Because when I turn it on, nothing else works, probably because I have to define every inventory interaction from scratch, which I do not know how to do.

Thank you for your help.

Ashen

QuoteNo. For some reason, no matter which cursor mode I have, right clicking on an item executes the 'Look' option and returns a description.

Right, yes. Now that you mention it, I that's the standard, hard-coded AGS behaviour - eModeInteract on items sets them as active, right-click (whatever the m,ode) looks at them. (Ignore what I said before - I was testing it with items with no 'Look at' interaction, so obviously it didn't do anything. What can I say? I'm a lazy tester.)

In which case, it looks like you might have to go the 'Handle clicks in script' route. Don't worry though, it's not actually that hard. First, check the box. Then, open the global script to on_mouse_click and paste in this code:
Code: ags

  if (button == eMouseLeftInv) {
    InventoryItem *temp = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
    if (mouse.Mode == eModeInteract) player.ActiveInventory = temp;
    else temp.RunInteraction(mouse.Mode);
  }


Since you're using a Popup Modal GUI for your inventory, it'll need to go before the if (IsGamePaused() == 1) condtion (otherwise - since modal GUIs block the script - it won't work), and that'll need to become else if (IsGamePaused() == 1).

And that should be it. 'Use'-ing the item will set it as active, just like default and without having to code it for every item, any other mode will trigger the appropriate interaction, and right-clicks won't do anything.
I know what you're thinking ... Don't think that.

alkis21

#4
Wow, I don't understand anything in the code you just wrote (and I work as a programmer for a living; I guess I should study my AGS more), but IT WORKED! Thank you so very much.
I'm probably abusing your kindness here, but what if I wanted the right mouse button to cycle through the available cursor modes by repeatedly clicking on it (just like when the GUI is off) instead of doing nothing, could that be done? If you answer that I promise not to bother you again for at least a week.  :)

--EDIT--
Never mind, I got it. I just needed to add

Code: ags
else if (button == eMouseRightInv) SetNextCursorMode();


in on_mouse_click. For some reason it only works when the cursor is above an inventory item, but that's good enough.

Ashen

You could also try adding an if (button == eMouseRight) mouse.SelectNextMode(); condition to the Inventory GUI's control function (in the editor, double click on any part of the GUI that's not a control to open the Script Editor the the right place) - but that only works for right-clicks on blank parts of the GUI (i.e. if you click a part of the InvWindow object that's not an item, it won't work). I'm sure there's a fairly easy way to get it to work wherever you click, it's just that I can't think of it right now as I'm about to fall asleep.


QuoteI don't understand anything in the code you just wrote (and I work as a programmer for a living; I guess I should study my AGS more)

Don't worry - it will just be a case of re-familiarising yourself with AGS (and familiarising yourself with the new OO scripting methods). The code is fairly self explanatory - probably the least obvious bit is creating the temp pointer (and here's a bit about pointers in AGS, if you need it).
I know what you're thinking ... Don't think that.

alkis21

Yes, I noticed the bit about pointers in the manual, I just haven't studied it yet. Sleep well!

SMF spam blocked by CleanTalk