Package transientlibs.preui.agents.factories

Source Code of transientlibs.preui.agents.factories.ElementFactory

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

import transientlibs.preui.objects.gui.elements.TextInfo;
import transientlibs.preui.objects.gui.elements.TextMarker;
import transientlibs.preui.objects.gui.elements.TextBox;
import transientlibs.preui.objects.gui.elements.AnimationMarker;
import transientlibs.preui.objects.gui.elements.ButtonGroup;
import transientlibs.preui.objects.gui.elements.Marker;
import transientlibs.preui.objects.gui.elements.InfoGroup;

import transientlibs.processors.misc.Detonator;
import transientlibs.preui.objects.gui.interfaces.IFont;
import transientlibs.preui.objects.gui.interfaces.IImage;
import transientlibs.preui.objects.gui.interfaces.IMarker;
import transientlibs.slick2d.util.Log;

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

    public static int MarkerType;
    public static int TextMarkerType;
    public static int AnimationMarkerType;
    public static int InfoGroupType;
    public static int ButtonGroupType;
    public static int TextBoxType;
    public static int TextInfoType;

    public IMarker spawnMarker(int byTypeCode, int setX, int setY) {
        return spawnMarker(byTypeCode, setX, setY, null, -1);
    }

    public IMarker spawnMarker(int byTypeCode, int setX, int setY, IFont setFont, int setImage) {
        return spawnMarker(byTypeCode, setX, setY, setFont, setImage, setImage);
    }

    public IMarker spawnMarker(int byTypeCode, int setX, int setY, IFont setFont, int setImage, int setHoveredImage) {


        IMarker result = null;


        //Marker
        if (byTypeCode == MarkerType) {
           
            Log.info("Spawn marker");
           
            IImage assignImage = Detonator.INSTANCE.imageProvider.getImage(setImage);
            result = new Marker(assignImage, assignImage, setX, setY);
        }

        //AnimationMarker
        if (byTypeCode == AnimationMarkerType) {

            Log.notImplemented();
            //AnimationMarker preresult = new AnimationMarker(setX, setY, Animations.getAnimationByID(setImage));
            //preresult.animation = Animations.getAnimationByID(setImage).animation;
            //result = preresult;
        }


        //ButtonGroup
        if (byTypeCode == ButtonGroupType) {
            IImage assignImage;
            if (setImage != -1) {
                assignImage = Detonator.INSTANCE.imageProvider.getImage(setImage);
            } else {
                assignImage = null;
            }

        }


        //TextMarker
        if (byTypeCode == TextMarkerType) {

            Log.info("Spawn textmarker");
           
            IImage assignImage;
            if (setImage != -1) {
                assignImage = Detonator.INSTANCE.imageProvider.getImage(setImage);
            } else {
                assignImage = null;
            }

            IImage assignHoveredImage;
            if (setHoveredImage != -1) {
                assignHoveredImage = Detonator.INSTANCE.imageProvider.getImage(setHoveredImage);
            } else {
                assignHoveredImage = assignImage;
            }
           
            //if (assignImage == null) {
            //    Log.warn("Creating TextMarker with no image");
            //}
           
           
            result = new TextMarker(assignImage, assignHoveredImage, setX, setY, -1);


            ((TextMarker) result).originalImage = Detonator.INSTANCE.imageProvider.getImage(setImage);

            if (((TextMarker) result).originalImage == null) {
                ((TextMarker) result).maxWidth = 200;
            }
            ((TextMarker) result).setText("");

            if (setFont != null) {
                ((TextMarker) result).setFont(setFont);
                //((TextMarker) result).fontReference = setFont;
            } else {
                ((TextMarker) result).setFont(Detonator.INSTANCE.fontProvider.getDefaultFont());
                //((TextMarker) result).fontReference = Detonator.INSTANCE.fontProvider.defaultFont;

            }


        }


        //Text Info
        if (byTypeCode == TextInfoType) {
            if (setFont != null) {
                result = new TextInfo(setX, setY, "Text", -1, setFont);
                ((TextInfo) result).font = setFont;
                ((TextInfo) result).canBeClicked = true;
            } else {

                result = new TextInfo(setX, setY, "Text", -1, Detonator.INSTANCE.fontProvider.getDefaultFont());
                ((TextInfo) result).font = Detonator.INSTANCE.fontProvider.getDefaultFont();
                ((TextInfo) result).canBeClicked = true;
            }

        }



        if (byTypeCode == TextBoxType) {
            result = new TextBox(setX, setY, null, " ", setFont);
        }

        if (byTypeCode == ButtonGroupType) {
            result = new ButtonGroup(setX, setY, setFont, null);
            //Log.info("image: "+setImage);
            if (setImage != -1) {
                result.setImage(Detonator.INSTANCE.imageProvider.getImage(setImage));
            }
        }

        if (byTypeCode == InfoGroupType) {
            result = new InfoGroup(setX, setY, setFont, null);
            if (setImage != -1) {
                result.setImage(Detonator.INSTANCE.imageProvider.getImage(setImage));
            }
        }


        ((Marker) result).originalImage = Detonator.INSTANCE.imageProvider.getImage(setImage);

        if (setImage != -1) {
            ((Marker) result).maxWidth = ((Marker) result).imageWidth;
        }


        return result;
    }
}
TOP

Related Classes of transientlibs.preui.agents.factories.ElementFactory

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.