abluescarab / tModLoader-WingSlot

This mod adds a dedicated wing slot to the inventory.
GNU General Public License v3.0
16 stars 9 forks source link

WingSlot forces wings onto the slot with no way of controlling behaviour #25

Closed Jofairden closed 5 years ago

Jofairden commented 6 years ago

I'll get straight to the point.

Problem: I have a UI that players can place their item in by right clicking it and holding left control. The problem is that this causes the items to duplicate, as they are also force placed into WingSlot's slot for wings, and I haven't found a way to have WingSlot not do this behaviour. The class is also internal.

Im fine with anything, setting a bool to force it to go away for example, or having the class be public and clear the slot myself. Either way, it has become a mod conflict that is quite annoying as it allows duplication of items.

For now, I have disabled the functionality for wings in EMM itself so that it can not trigger the issue.

abluescarab commented 6 years ago

I added an option to the mod config a few versions ago to allow equipping the wings in normal accessory slots. It's found in the tModLoader "Mod Configs" folder. Would this be what you're looking for?

Jofairden commented 6 years ago

No not at all. There needs to be an option to disable the item from ending up in the wing slot, as I'm basically performing behaviour supposed to put the item somewhere else (UI in this case)

abluescarab commented 6 years ago

I've made the class and some of its private methods public. Can you please try out the version on the emm branch and let me know if that works for you?

Jofairden commented 5 years ago

Hey, sorry for the late reply. Busy these days. If the class there is made public, and the slot there is as well (it seems to be), then I can indeed clear it. However, think of this use-case: what if a player already has an item in their wingslot? What will happen is, their slot gets replaced by the item being consumed, their equipped item put into the inventory. (right?) This would be an unusual, annoying side-effect. (Your wingslot will clear when putting one into my UI). Ideally, I can force stop putting the item in the wingslot with the right click feature, on my own command. If you want to add support for this, there is a few things you could do.

One possibility, is to allow me to intercept Slot_Conditions. The easiest solution here is allowing me to set a flag to false which forcibly stops the action, and then put it back to true when I'm done (or reset it yourself to true every update). Another possibility is opening a collection of functions that return a bool, that are invoked and checked on Slot_Conditions, which then any mod can add their function to.

Of course I can use reflection and do finicky stuff, but I'd rather stay away from that. I hope you understand.

abluescarab commented 5 years ago

Of course I can use reflection and do finicky stuff, but I'd rather stay away from that. I hope you understand.

Of course I do! I'm just trying to work with you to figure out the best way to implement this functionality. I've updated the emm branch to use the Call() function to implement a list of override functions like your second suggestion.

To override equipping:

wingSlot.Call(/* "add" or "remove" */, /* func<bool> that returns true to equip/false to cancel */);

I'd feel more comfortable making WingSlotPlayer internal again, if this works and you feel it's okay with this implementation.

Jofairden commented 5 years ago

Yes, this should work. Feel free to make them internal again if you want. Thanks

abluescarab commented 5 years ago

v1.6.0 is pushed out with the changes.

Jofairden commented 5 years ago

Hey, it doesn't seem to work:

WingSlotLoaded = wingSlotMod != null && wingSlotMod.Version >= new Version(1, 6, 1);

if (WingSlotLoaded)
{
    wingSlotMod.Call("add", (Func<bool>)(
        () => 
            !CubeInterface.IsVisible));
}

WingSlotLoaded is true, the Call correctly returns null. However, my function is never being called. (it still ends up in both your slot and my UI)

Jofairden commented 5 years ago

So I tried debugging your mod, and Slot_Conditions is never called (I put a breakpoint on it) So it makes sense that my function is never called either

Jofairden commented 5 years ago

Ah, now I see. It only triggers when I manually press the slot, not on right click. Right click is the functionality I needed.

Jofairden commented 5 years ago

So, there will need to be changes. The actual problem is that I added a right click functionality to my UI, which if used would put it in my UI and also yours. What I need this to be able to do is not have it put it in your UI on right click. Manually putting it in the slot is of no concern.

abluescarab commented 5 years ago

Whoops, that would be my bad. I'll get right on it.

Edit: I've uploaded a new emm branch. Before I push these changes, would you test it thoroughly and ensure it works to your satisfaction?

Jofairden commented 5 years ago

Thanks, I'll be able to test it later.

Jofairden commented 5 years ago

Alright, I tested it and it doesn't work. I tried reversing my logic as well, but both ways it still ends up in your slot as well.

abluescarab commented 5 years ago

Please let me know when you finish adding this functionality to your mod so I can safely close this issue.

Jofairden commented 5 years ago

You can safely close the issue.