AnvilGUI icon indicating copy to clipboard operation
AnvilGUI copied to clipboard

Title response?

Open UsainSrht opened this issue 2 years ago • 2 comments

It would be good if we can response with title of the GUI too.

UsainSrht avatar Jul 21 '22 03:07 UsainSrht

What do you mean with response? The error messages?

Sytm avatar Jul 22 '22 15:07 Sytm

What do you mean with response? The error messages?

I mean an alternative to AnvilGUI.Response.text("invalid number") that changes title of anvilGUI.

UsainSrht avatar Jul 22 '22 15:07 UsainSrht

Definitely a feature that we should add. Perhaps requires a bit more thought than just adding a Response, because ideally a developer should be able to change the title and the text in a Response. Marking this as help wanted as I don't have time to implement it.

WesJD avatar Nov 27 '22 23:11 WesJD

With the change to ResponseActions (#243), this is actually now very possible. Adding a ResponseAction.replaceTitle(String) would require some implementation from the VersionWrapper side though, since titles are only supported in certain versions. Additionally, I am unsure if simply setting the inventory title in the NMS Container will actually update it on the client - we may need to send additional packets for a title update.

WesJD avatar Dec 18 '22 00:12 WesJD

With the change to ResponseActions (#243), this is actually now very possible. Adding a ResponseAction.replaceTitle(String) would require some implementation from the VersionWrapper side though, since titles are only supported in certain versions. Additionally, I am unsure if simply setting the inventory title in the NMS Container will actually update it on the client - we may need to send additional packets for a title update.

Yes, to update the title you need to send the packet for opening the window again. Its problematic for this purpose since it will reset the anvil input to the name of the item in the left slot, so entirely discarding the user input.

To avoid this, the left item's display name needs to be updated to the previous anvil input, which can be obtained by using the PrepareAnvilEvent which is the rename item packet. But this will cause another problem, because both the anvil input and the left item's names are the same; resulting into an empty result slot. I've explained this in #232.

So either you don't care about having the user input cleared on a title update (for example if you just want to inform the user that the input is entirely wrong) or you do care (suggestions etc. coming up in the title as you type). The latter will always require the second slot filled with an enchantment book, I can't think of another way for preserving the user input and still having an item in the result slot while updating the title.

I think we should go with option 1 first, so just sending the window open packet again, and then see if it resolves this issue.

mastercake10 avatar Dec 20 '22 23:12 mastercake10