Forum rules - please read before posting.

Autoselect the first item in the inventory?

edited May 2016 in Technical Q&A
Sorry, I've been away from the PC with my project for the past 2 days or so. I'll get you the screen shots you asked in the other post when I have the time. 

As you probably already know, I'm working on a menu system that looks similar to Persona 3 or 4 or most console JRPGs. Today, I just tried to deal with the issue of showing the item image and description automatically and the fact that to show them without much hassle, you have to click the item once to get it selected (and once more to get it deselected). I tried to simulate clicks to get it done (onSelect and onDeselect, and on Start), which worked in part (although it's turned a little bit more confusing than I though, lol). Still, got it to work perfectly whenever I tab left and right, but somehow I can't get the thing to autoclick the first slot when the menu starts...

So, here I am half defeated, lol. 

Anyways, is there a way to get AC to autoselect the first item in the inventory? Or a way to get it to show the currently selected description and image without having to click the item? (what methods could I call from my script that would have the same effect as when you click the item slot?)...

Also, more related to your forums that anything else... is there a way to post code so that it shows, well, nice? I don't see an insert code snippet button in the forum toolbar... and I kind'a wanted to show you the code, but without the snippet thing I feel it just becomes rather tough to read... 

Anyway, I know AC wasn't made originally for the stuff I'm trying it to do, so I'm sorry for all the bombarding of questions...

EDIT: here's the script, if you want to take a look - InventorySlotController.cs

Comments

  • edited May 2016
    A menu element can be "clicked" through script by calling it's ProcessClick function.  The first item in the inventory will be slot 0, unless you're shifting the elements.  If you are (this is necessary when you have more items than the inventory has UI space for), you can get the shift offset with GetOffset ().

    I have tried to get a good format option for code, but haven't found one that plays well with the existing toolbar.
  • edited June 2016
    Thanks, I'm back, finally, I think, I've been kinda busy... anyways, I'll give this stuff a try.

    By the way, how would I get a reference of the length of the item's array currently in an inventory-box? I ask because I'd like to make empty slots unreachable when empty (remove them from navigation). 

    Also, I'm sorry, but could you give me a better example of how to use the GetOffset() function to manage the slots?  I still don't have clear how AC manages the slots so it confuses me a bit, does it simply clone a slot when there's more items to be shown?
  • edited June 2016
    umm.. Also, In the processClick function, what in the world am I supposed to put in the mouseState parameter? I googled Unity mouseStates and I don't get anything...

    again, I'm sorry, as I've said before, I'm still new to programming, and even newer to programming C# in unity... so, some simple examples would be greatly appreciated... 
  • Have you seen the scripting guide for the MenuInventoryBox class?

    The number of inventory items in an inventory box element can be found with:

    myInventoryBox.items.Count;

    The GetOffset() function returns the number of slots that the first item is from the first slot.  If you use a Button element to shift the items left or right, you're changing the offset value.  The item that appears in a given slot index is calculated as:

    myInventoryBox.items [slotIndex + offset];

    The MouseState parameter is AC's own method of tracking mouse states.  To simulate a single left-click, you want MouseState.SingleClick.
  • edited June 2016
    Hi, thanks, I'll give these new stuff a try. 

    By the way, I do check the scripting guide a lot... but, as I said, I'm not much of a programmer... many stuff in there just seem to mock me, and plenty of times, I just end up fumbling in the dark (concepts like typecasting elements, name spaces, referencing objects, are things I don't intermediately infer as I look over a single line of code)... The usual drill is: I try stuff I find in there, then get errors, then try to figure out what I've done wrong, or what I haven't done, until: A. I get it right, or B. I get tired and leave it alone... :-< That's why I usually try to avoid scripting whenever I can, but the Inventory system I envision is the exception, I simply can't make it work the way I want unless I do some scripting... for a beginner like me, and as a one man team, it's specially hard, because I'm trying to make these stuff as reusable as possible, and that means avoiding hard coding object names into scripts and other things like that... It's important for me to be able to reuse the scripts in future games to shorten development time in the long run #:-S
  • Umm... I've been busy with some personal stuff recently and haven't been able to work much. But this allowed me some time to think and overview what I was doing with my inventory. And I'm starting to foresee there's going to be complications as long as AC enforces it's own click functionality on the menu elements. i.e.: whenever the player actually presses the button to use the item, it may cause the item to get deselected instead of using it, because it's already been preselected by the scripts, and even if I overwrite the buttons onClick and something actually happens when the button is pressed, AC is till going to run it's own stuff in the background. 

    I considered asking how to comment out or change this functionality, but then I realized this could potentially break a lot of other stuff in AC, so I'm starting to think it may not be my best option to use the AC inventory for my regular item's inventory... But I'm still thinking. I've heard of override functions, but I've never used them, do you think I could manage something?

    Ah, I also think it's better if I explain exactly how the inventory is supposed to work, all the features I want to achieve, I'm not sure if I ever explained it properly before.

    Features:

    1. Tabbed categories - Done

    2. Highlighted item shows its description and image as long as it remains highlighted, no extra clicks or button presses necessary - WIP (only works after tabbing left or right...)

    3. player cannot scroll down to empty slots (when there's few items in the list). - Pending (but I think pretty doable, by just checking the item count and changing button navigation).

    4. Pressing the main interaction button brings a small prompt with the options: "Use" or "Cancel". If the player selects "Use" the item's Action List Should run. - Pending (doable, but may conflict with AC's click -- after closing the prompt the players may find themselves with a deselected item...).

    5. Below the item's image area, there will be 3 icons, which will represent the 3 item properties used in the game (Make, Quality, cleanliness, which in turn each have various "levels"). The icon's UI image will be replaced depending on the highlighted item's properties (if an item has "Good Quality" in the quality field, then the icon should change to reflect that), and if an item doesn't have a property, it should show a grayed-out icon in its place (i.e: food won't have cleanliness, so the cleanliness icon should gray-out). Properties differ by category only, all items in the same category share the same property types. WIP (I think doable by using toggles/bools, per tab/invBox, to tell the script which properties it should check on each item, the rest would be enabling and disabling UI images) 

    Then, what the main inventory menu should not do: no dragging and dropping items (that includes not dragging items outside of the menu) and no combining items.  

    Still, my main concern is the click functionality, which AC runs automatically and the fact you have to select and item to show its image and description...

    Anyways, any advice or ideas to overcome the obstacles would be highly appreciated.
  • If need be, you'll always have the option of writing your own inventory menu script.  AC's own InventoryBox element doesn't do much more than display the items that the player is carrying - what those items are, and what happens when they're interacted with, is stored in the RuntimeInventory script, which you can access with:

    AC.KickStarter.runtimeInventory

    You can then read its localItems variable to get a list of the items the player is carried.

    Since you're making use of inventory properties, at least some custom scripting will be required - as properties are designed to be accessed through scripts.

    Regarding the showing of these properties, it would be useful to have an "OnHoverOverElement" event, which you can listen for when the mouse hovers over your inventory box.  I can see if such an event can be added in the next release.  (For more on events and how they are useful, see this tutorial).

    Click functionality can be disabled completely if you set the Inventory box type to Custom Script.  This'll mean AC does nothing when you click on the box, but you can make use of the OnMenuElementClick event to control what happens through script (this event already exists).
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.