Package transientlibs.preui.objects.gui.elements

Source Code of transientlibs.preui.objects.gui.elements.TextField$EnteredNumber

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package transientlibs.preui.objects.gui.elements;

import com.badlogic.gdx.Input;
import java.util.ArrayList;
import transientlibs.slick2d.util.Log;
import transientlibs.processors.misc.ClickProcessor;
import transientlibs.processors.misc.Detonator;
import transientlibs.preui.objects.gui.misc.ButtonEffect;
import transientlibs.preui.objects.gui.misc.KeyboardCatcher;
import transientlibs.preui.objects.states.UIHub;
import transientlibs.objects.primitives.IntSlot;
import transientlibs.preui.gdx.game.TransientInput;
import transientlibs.preui.objects.gui.interfaces.IImage;

/**
*
* @author kibertoad
*/
public class TextField extends TextMarker implements KeyboardCatcher {

    public IntSlot relatedValue = new IntSlot();
    public boolean isConfirmed = false;
    public ArrayList<ClickProcessor> finishProcessors = new ArrayList<ClickProcessor>();

    public TextField(IImage setImage, IImage setHoveredImage, int setx, int sety, int setID) {
        super(setImage, setHoveredImage, setx, sety, setID);

        setFont(Detonator.INSTANCE.fontProvider.getDefaultFont());
    }

    @Override
    public void addPayload (ClickProcessor cp) {
        finishProcessors.add(cp);
    }
   
    public TextField(TextMarker fromSource) {
        super(fromSource.getImage(), fromSource.getHoveredImage(), fromSource.screenCoords.getIntX(), fromSource.screenCoords.getIntY(), fromSource.ID);

        setFont(Detonator.INSTANCE.fontProvider.getDefaultFont());
    }

    public boolean isPressedShift() {
        return (Detonator.INSTANCE.inputProvider.isPressedShift());
    }

    @Override
    public void processFinish() {
        for (ClickProcessor cp : finishProcessors) {
            cp.process();
            Log.warn("Processed finish processor");
        }
       
    }

    /*
    @Override
    public void drawCatcherBorders(Graphics gr, Color clr) {
        this.drawBorders(gr, clr);
    }
    */

    @Override
    public void drawCatcherBorders() {
        Log.notImplemented();
    }
   
   
    @Override
    public void catchText() {
        //this.setText(textCapsule.text+Detonator.INSTANCE.currentState.getKeyString());
        //String c = Detonator.INSTANCE.currentState.getKeyString();
       
        String c = Detonator.INSTANCE.inputProvider.getKeyLetter();
        String n = Detonator.INSTANCE.inputProvider.getKeyNumber();
        String s = Detonator.INSTANCE.inputProvider.getKeyString();
       
        if (n != null){
        Log.info("n = "+n);
        }

        if (Detonator.INSTANCE.inputProvider.isPressedBackspace()) {
           
            if (textCapsule.text.length() > 0) {
                this.setText(textCapsule.text.subSequence(0, textCapsule.text.length() - 1).toString());
            }
        }

        if (Detonator.INSTANCE.inputProvider.isPressedEnter()) {
            Log.info("Enter OK");
            isConfirmed = true;
            processFinish();
        }

        if ((c != null) && (!(c.isEmpty()))) {
            //Log.info("char: "+c);
            if (!s.isEmpty()){
            Log.info("string: " + s);
            }

            //if (!c.isEmpty()) {
            Log.info("c: " + c);



            //Log.info("l: " +c.length());
            if ((isPressedShift())) {
                this.setText(textCapsule.text + c);
            } else {
                this.setText(textCapsule.text + c.toLowerCase());
            }
        }
            else {
            if ((n != null) && (!(isPressedShift()))) {
                Log.info("n: "+n);
                this.setText(textCapsule.text + n);
            }
        }

        if ((isPressedShift())
                && ((s.equals("MINUS")))) {
            this.setText(textCapsule.text + "_");
        } else if (s.equals("MINUS")) {
            this.setText(textCapsule.text + "-");
        }

        if (s.equals("SPACE")) {
            this.setText(textCapsule.text + " ");
        }

        if (s.equals("PERIOD")) {
            this.setText(textCapsule.text + ".");
        }

        if ((isPressedShift())
                && ((s.equals("1")))) {
            this.setText(textCapsule.text + "!");
        }

        //RSHIFT
        //MINUS
        //PERIOD



    }

    @Override
    public boolean isFinished() {
        return isConfirmed;
    }

    @Override
    public void reset() {
        isConfirmed = false;
        textCapsule.text = "";
    }

    public void addNumberPayload(UIHub inHub) {
        finishProcessors.add(new EnteredNumber(this));
        finishProcessors.add(new ButtonEffect (ButtonEffect.EffectType.resetCatcher, inHub));
    }
   

    public void addFocusPayload(UIHub setHub) {
    addPayload(new ButtonEffect (this, setHub));
    }
   
   
public class EnteredNumber implements ClickProcessor {

     public TextField relatedField;
    
    
      public EnteredNumber (TextField setField) {
          relatedField = setField;
      }

        @Override
        public void process() {
           
            int value;
           
            try {value = Integer.parseInt(relatedField.textCapsule.text);}
           
            catch (NumberFormatException x)  {
                value = -1;
            }
           
            if (value != -1) {
                relatedField.relatedValue.referencedInt.value = value;
                relatedField.setText(Integer.toString(relatedField.relatedValue.referencedInt.value));
            }
           
        }
    }   
}
TOP

Related Classes of transientlibs.preui.objects.gui.elements.TextField$EnteredNumber

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.