<commit_before>/* Copyright (c) 2015 "Naftoreiclag" https://github.com/Naftoreiclag
 *
 * Distributed under the Apache License Version 2.0 (http://www.apache.org/licenses/)
 * See accompanying file LICENSE
 */

package naftoreiclag.villagefive;

import com.jme3.app.Application;
import com.jme3.app.state.AbstractAppState;
import com.jme3.app.state.AppStateManager;
import com.jme3.niftygui.NiftyJmeDisplay;
import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.NiftyEventSubscriber;
import de.lessvoid.nifty.builder.PanelBuilder;
import de.lessvoid.nifty.controls.Label;
import de.lessvoid.nifty.controls.ListBox;
import de.lessvoid.nifty.controls.TextField;
import de.lessvoid.nifty.controls.TextFieldChangedEvent;
import de.lessvoid.nifty.controls.label.builder.LabelBuilder;
import de.lessvoid.nifty.elements.Element;
import de.lessvoid.nifty.input.NiftyInputEvent;
import de.lessvoid.nifty.input.NiftyInputMapping;
import de.lessvoid.nifty.input.keyboard.KeyboardInputEvent;
import de.lessvoid.nifty.screen.KeyInputHandler;
import de.lessvoid.nifty.screen.Screen;
import de.lessvoid.nifty.screen.ScreenController;
import naftoreiclag.villagefive.util.KeyKeys;

public class DevConsoleAppState extends AbstractAppState implements ScreenController, KeyInputHandler {
    
    private Main app;
    NiftyJmeDisplay niftyDisplay;
    Nifty nifty;
    
    TextField textField;
    Element outputBox;
    
    String input;
    Screen screen;
    
    NiftyInputMapping mapping = new NiftyInputMapping() {
        @Override
        public NiftyInputEvent convert(KeyboardInputEvent inputEvent) {
            
            boolean pressed = inputEvent.isKeyDown();
            int key = inputEvent.getKey();
            
            if(pressed) {
                if(key == KeyKeys.consoleKey) {
                    return NiftyInputEvent.ConsoleToggle;
                } else if(key == KeyboardInputEvent.KEY_RETURN) {
                    return NiftyInputEvent.Activate;
                } else if(key == KeyboardInputEvent.KEY_TAB) {
                    if(inputEvent.isShiftDown()) {
                        return NiftyInputEvent.PrevInputElement;
                    } else {
                        return NiftyInputEvent.NextInputElement;
                    }
                }
            }
            
            return null;
        }
    };
    
    @Override
    public void initialize(AppStateManager stateManager, Application application) {
        super.initialize(stateManager, application);
        
        app = (Main) application;
        
        niftyDisplay = new NiftyJmeDisplay(app.getAssetManager(), app.getInputManager(), app.getAudioRenderer(), app.getGuiViewPort());
        nifty = niftyDisplay.getNifty();
        nifty.fromXml("Interface/DeveloperConsole.xml", "hide", this);
        app.getGuiViewPort().addProcessor(niftyDisplay);
    }

    @Override
    public void bind(Nifty nifty, Screen screen) {
        screen.addPreKeyboardInputHandler(mapping, this);
        this.screen = screen;
        textField = screen.findNiftyControl("input", TextField.class);
        outputBox = screen.findElementByName("output");
    }
    
    private void sendInput() {
        if(input.equals("") || input == null) { return; }

        
        new ConsoleOutputEntry(input);
        
        textField.setText("");
        input = "";
    }
    
    private class ConsoleOutputEntry
    {
        final Element associatedPanel;
        final String message;
        
        ConsoleOutputEntry(String text) {
            this.message = text;
            
            associatedPanel = new PanelBuilder() {{
                childLayoutHorizontal();
                control(new LabelBuilder() {{
                    label(message);
                }});
            }}.build(nifty, screen, outputBox);
            
            
        }
    }
    
    @Override
    public void setEnabled(boolean enable) {
        super.setEnabled(enable);
        <commit_msg>Something more<commit_after>/* Copyright (c) 2015 "Naftoreiclag" https://github.com/Naftoreiclag
 *
 * Distributed under the Apache License Version 2.0 (http://www.apache.org/licenses/)
 * See accompanying file LICENSE
 */

package naftoreiclag.villagefive;

import com.jme3.app.Application;
import com.jme3.app.state.AbstractAppState;
import com.jme3.app.state.AppStateManager;
import com.jme3.niftygui.NiftyJmeDisplay;
import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.NiftyEventSubscriber;
import de.lessvoid.nifty.builder.PanelBuilder;
import de.lessvoid.nifty.controls.Label;
import de.lessvoid.nifty.controls.ListBox;
import de.lessvoid.nifty.controls.TextField;
import de.lessvoid.nifty.controls.TextFieldChangedEvent;
import de.lessvoid.nifty.controls.label.builder.LabelBuilder;
import de.lessvoid.nifty.elements.Element;
import de.lessvoid.nifty.input.NiftyInputEvent;
import de.lessvoid.nifty.input.NiftyInputMapping;
import de.lessvoid.nifty.input.keyboard.KeyboardInputEvent;
import de.lessvoid.nifty.screen.KeyInputHandler;
import de.lessvoid.nifty.screen.Screen;
import de.lessvoid.nifty.screen.ScreenController;
import java.util.ArrayList;
import java.util.List;
import naftoreiclag.villagefive.util.KeyKeys;

public class DevConsoleAppState extends AbstractAppState implements ScreenController, KeyInputHandler {
    
    private Main app;
    NiftyJmeDisplay niftyDisplay;
    Nifty nifty;
    
    TextField textField;
    Element outputBox;
    
    String input;
    Screen screen;
    
    NiftyInputMapping mapping = new NiftyInputMapping() {
        @Override
        public NiftyInputEvent convert(KeyboardInputEvent inputEvent) {
            
            boolean pressed = inputEvent.isKeyDown();
            int key = inputEvent.getKey();
            
            if(pressed) {
                if(key == KeyKeys.consoleKey) {
                    return NiftyInputEvent.ConsoleToggle;
                } else if(key == KeyboardInputEvent.KEY_RETURN) {
                    return NiftyInputEvent.Activate;
                } else if(key == KeyboardInputEvent.KEY_TAB) {
                    if(inputEvent.isShiftDown()) {
                        return NiftyInputEvent.PrevInputElement;
                    } else {
                        return NiftyInputEvent.NextInputElement;
                    }
                }
            }
            
            return null;
        }
    };
    
    @Override
    public void initialize(AppStateManager stateManager, Application application) {
        super.initialize(stateManager, application);
        
        app = (Main) application;
        
        niftyDisplay = new NiftyJmeDisplay(app.getAssetManager(), app.getInputManager(), app.getAudioRenderer(), app.getGuiViewPort());
        nifty = niftyDisplay.getNifty();
        nifty.fromXml("Interface/DeveloperConsole.xml", "hide", this);
        app.getGuiViewPort().addProcessor(niftyDisplay);
    }

    @Override
    public void bind(Nifty nifty, Screen screen) {
        screen.addPreKeyboardInputHandler(mapping, this);
        this.screen = screen;
        textField = screen.findNiftyControl("input", TextField.class);
        outputBox = screen.findElementByName("output");
    }
    
    private void sendInput() {
        if(input.equals("") || input == null) { return; }
        
        ConsoleOutputEntry e = new ConsoleOutputEntry(input);
        entries.add(e);
        
        textField.setText("");
        input = "";
    }
    
    List<ConsoleOutputEntry> entries = new ArrayList<ConsoleOutputEntry>();
    private class ConsoleOutputEntry
    {
        final Element associatedPanel;
        final String message;
        
        ConsoleOutputEntry(String text) {
            this.message = text;
            
            associatedPanel = new PanelBuilder() {{
                childLayoutHorizontal();
                control(new LabelBuilder() {{
                    label(message);
                }});
            }}.build(nifty, screen, outputBox);
        }
        
        void register() {
            
        }
        
        void delete() {
            
        }
    }
    
    @Override
    public void setEnabled(boolean enable) {
        super.setEnabled(enable);
        
{'fraction_non_alphanumeric': 0.0926195678562758, 'fraction_numerical': 0.0024277737314882253, 'mean_word_length': 2.3181635118807895, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6099185', 'n_tokens_mistral': 2351, 'n_tokens_neox': 2303, 'n_words': 414}