Hopson97 / open-builder

Open "Minecraft-like" game with multiplayer support and Lua scripting support for the both client and server
https://github.com/Hopson97/open-builder/projects/3
GNU General Public License v3.0
703 stars 80 forks source link

GUI textbox API allows to limit which characters can be added to it #182

Closed gml16 closed 4 years ago

gml16 commented 4 years ago

This addresses #180 . I have added to the Lua API textBox:limitChars("123456789") (which in this case would only allow digits from 1 to 9 to be entered) as well as textBox:allowAllChars() (which resets the chars that had been previously prevented). I store the authorised chars in std::string m_charsAuthorised and, this may not be a good design choice, if the field is an empty string it considers all chars to be authorised. Thus, textBox:allowAllChars() is basically calling textBox:limitChars("") . Tell me what you think.

Hopson97 commented 4 years ago

I see your point, but in my opinion I think that is a decent way of handling it.

The alternative ways would have been to create an additional boolean member, or have a separate const string somewhere for defining the default available characters. (There might be other ways too, this is all I can think of for now though).

Happy to merge this, thanks for the contribution! :)