Package transientlibs.preui.objects.states

Source Code of transientlibs.preui.objects.states.UIHub

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

import transientlibs.preui.objects.gui.elements.TextInfo;
import transientlibs.preui.objects.gui.elements.TextMarker;
import transientlibs.preui.objects.gui.elements.AnimationMarker;
import transientlibs.preui.objects.gui.elements.ParallaxMarker;
import transientlibs.preui.objects.gui.elements.ButtonGroup;
import transientlibs.preui.objects.gui.elements.Marker;
import transientlibs.preui.objects.gui.elements.InfoGroup;
import transientlibs.preui.objects.gui.elements.TextField;
import java.util.ArrayList;
import transientlibs.slick2d.util.Log;
import transientlibs.bindedobjects.core.Tex;
import transientlibs.processors.misc.Detonator;
import transientlibs.preui.gdx.gui.MarkerList;
import transientlibs.preui.objects.gui.interfaces.IMarker;
import transientlibs.objects.primitives.Coords;
import transientlibs.preui.objects.gui.interfaces.IImage;
import transientlibs.preui.objects.gui.misc.ButtonEffect;
import transientlibs.preui.objects.gui.misc.RenderList;

import transientlibs.tex.Branch;

/**
*
* @author kibertoad
*/
public class UIHub {

    public boolean isEnabled = true;
    public String GUIFile = "-";

    public IState masterState;

    public MarkerList interfaceElements = new MarkerList();
    public RenderList renderList = new RenderList();
   
    public RenderList inRenderList = null;


    public IState getCurrentState () {
        return (IState) Detonator.INSTANCE.currentGenericGame.getCurrentState();
    }

    public IImage getImage (String byID) {
        return Detonator.INSTANCE.imageProvider.getImage(byID);
    }
   
    public void replaceMarker (Marker original, Marker replacement) {
        int storedIndex;

        if (masterState.getHoverStorage().contains(original)) {
        storedIndex = masterState.getHoverStorage().indexOf(original);
        masterState.getHoverStorage().remove(original);
        masterState.getHoverStorage().add(storedIndex, replacement);
        }

        if (masterState.getDrawStorage().contains(original)) {
        storedIndex = masterState.getDrawStorage().indexOf(original);
        masterState.getDrawStorage().remove(original);
        masterState.getDrawStorage().add(storedIndex, replacement);
        }
       
        if (original.inRenderList != null) {
            //storedIndex = original.inRenderList.getIndex();
            original.inRenderList.add(replacement);
           
            Log.info("REPLACED");
        }
       
        original.inRenderList.remove(original);

        replacement.moveMarker(original.screenCoords.getIntX(), original.screenCoords.getIntY());
        //replacement.screenCoords.copyFrom (original.screenCoords);

    }

    public void load (String fromFile) {

        interfaceElements.clear();
        renderList.markers.clear();
        renderList.menus.clear();

        Detonator.INSTANCE.interfaceElementList.clear();
        Detonator.INSTANCE.interfaceElements.clear();

        Branch initBranch = new Branch();
        Tex.loadText("gui/" + fromFile);
        initBranch.processSilently();

        //Log.info("currently loaded: " + Detonator.INSTANCE.interfaceElements.values().size());
        for (IMarker m : Detonator.INSTANCE.interfaceElementList) {
            interfaceElements.add(m);
            renderList.add(m);
            masterState.passMarker(m);
        }


    }


    public void bindToState (IState toState) {
        for (IMarker m : interfaceElements) {
            toState.passMarker(m);
        }
    }

    public void init (IState toState, String fromFile){
        GUIFile = fromFile;
        masterState = toState;

        if (!"-".equals(GUIFile)) {executeLoading();}
        bindElements();
        bindElementLogic();       
    }
   
    public void init (IState toState){
        masterState = toState;

        if (!"-".equals(GUIFile)) {executeLoading();}
        bindElements();
        bindElementLogic();
    }

    public IMarker get (String byCode) {
        return Detonator.INSTANCE.interfaceElements.get(byCode);
    }


    public InfoGroup getInfoGroup (String byCode) {
        TextMarker temp = getTextMarker (byCode);

        InfoGroup ig = new InfoGroup (temp, masterState);
        replaceMarker (temp, ig);

        return ig;       
    }
   
    public ButtonGroup getButtonGroup (String byCode) {
        TextMarker temp = getTextMarker (byCode);

        ButtonGroup bg = new ButtonGroup (temp, masterState);
        replaceMarker (temp, bg);

        return bg;
    }


    public ParallaxMarker getParallaxMarker (String byCode) {
        TextMarker temp = getTextMarker (byCode);

        ParallaxMarker pm = new ParallaxMarker (0, 0, temp.getImage());
        replaceMarker (temp, pm);

        return pm;
    }

    public TextInfo getTextInfo (String byCode) {
        return (TextInfo)getTextMarker(byCode);
    }
   
   
    public TextField getTextField (String byCode) {
       
        TextField result;
       
          TextMarker temp = getTextMarker(byCode);
          result = new TextField (temp);

          replaceMarker(temp, result);

          result.addPayload(new ButtonEffect (result, this));
          //result.textCapsule.highlightedColour = result.textCapsule.colour;
        
        return result;
    }
   

    public TextMarker getTextMarker (String byCode) {
        TextMarker result;
        result = (TextMarker)Detonator.INSTANCE.interfaceElements.get(byCode.toLowerCase());

        if (result == null) {Log.error("No element "+byCode.toLowerCase());
        }
       
        //masterState.passMarker(result); unneeded
        //result.textCapsule.highlightedColour = result.textCapsule.colour;

        return result;
    }


    public Coords getWaypoint (String byCode) {
         TextMarker result;
        result = (TextMarker)Detonator.INSTANCE.interfaceElements.get(byCode);

        if (result == null) {Log.error("No element "+byCode);
        return null;
        }

        return new Coords (result.screenCoords.getIntX(), result.screenCoords.getIntY());

    }

public AnimationMarker getAnimationMarker (String byCode) {
        AnimationMarker result;
        result = (AnimationMarker)Detonator.INSTANCE.interfaceElements.get(byCode);

        if (result == null) {Log.error("No element "+byCode);
        }

        return result;
    }

    public void executeLoading (){
        load(GUIFile);
    }

    public void bindElements (){

    }

   public void bindElementLogic(){
      }

   public void disable (){
       isEnabled = false;
       renderList.disableList();
   }

   public void enable(){
       isEnabled = true;
       renderList.enableList();
   }


   public void toggle() {
       if (isEnabled) {
           disable();
       } else
       {
           enable();
       }
   }

    public void setRenderList(RenderList aThis) {
        inRenderList = aThis;
    }

}
TOP

Related Classes of transientlibs.preui.objects.states.UIHub

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.