Game Development Reference
In-Depth Information
2. Next, we add a method about the output text to the console from external sources.
We call it outputToConsole , and it takes a string as an input. It then calls
console.output to display the message.
3. Another new method is toggleConsole() . It should check whether con-
sole.getElement() is visible or not and then hide or show it accordingly.
4. Then, we add a subscriber method that will receive anything entered in the
console. It needs the @NiftyEventSubscriber annotation with the console
as its ID. It also needs a method declaration that looks like the following code:
public void onConsoleCommand(final String id, final
ConsoleExecuteCommandEvent command)
5. Define a new class called HideCommand that implements ConsoleCommand .
6. Add a field NiftyController controller together with a setter method to the
HideCommand class.
7. In the implemented execute method, we call control-
ler.toggleConsole() .
8. Going back to NiftyController , we instantiate a new HideCommand
method and set the controller.
9. We then create a new ConsoleCommands instance and call registerCom-
mand ; thereafter, we supply/hide the instance and call commandText , and
HideCommand as ConsoleCommand .
10. Finally, we call enableCommandCompletion(true) in the Con-
soleCommands instance.
Search WWH ::




Custom Search