Package transientlibs.preui.agents.misc

Source Code of transientlibs.preui.agents.misc.StoryAgent

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

import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import transientlibs.processors.misc.Detonator;
import transientlibs.preui.objects.gui.overlays.StoryAgentOverlay;
import java.util.ArrayList;
import transientlibs.slick2d.util.Log;
import transientlibs.bindedobjects.core.Binding;
import transientlibs.preui.gdx.gui.MarkerList;
import transientlibs.objects.primitives.Int;
import transientlibs.preui.objects.gui.elements.ButtonGroup;
import transientlibs.preui.objects.gui.interfaces.IMarker;
import transientlibs.preui.objects.gui.elements.InfoGroup;
import transientlibs.preui.objects.gui.elements.TextMarker;
import transientlibs.preui.objects.gui.interfaces.IFont;
import transientlibs.preui.objects.states.IState;

import transientlibs.preui.utils.layout.HorizontalAlign;
import transientlibs.preui.utils.layout.VerticalAlign;
import transientlibs.tex.Story;
import transientlibs.tex.StoryList;
import transientlibs.tex.StoryPoint;

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

    public boolean isEnabled = true;
    public IState state;
    public Story nowStory;
    int storyID;
    int branchID;
    public boolean isInterrupted = false;
    public TextMarker background = null;
    public InfoGroup textBox;
    public static ArrayList<Int> branchHistory = new ArrayList<Int>();
    public static MarkerList imagePoints = new MarkerList();
    public ButtonGroup actionButtons = null;
    public IFont textFont;
    public MarkerList storyUI = new MarkerList();
    //public UIHub ui;
    public StoryAgentOverlay ui;

    public StoryAgent(IState setState, String guiName) {
        state = setState;

        ui = new StoryAgentOverlay();
        ui.init(setState);

        textBox = ui.textBox;
        actionButtons = ui.buttons;
        background = ui.back;

        if (actionButtons == null) {
            Log.error("NOOOOOOOOOOOOOO");
        }

        textBox.colour = Detonator.INSTANCE.colourFactory.defaultButtonColour;
        textBox.highlightedColour = Detonator.INSTANCE.colourFactory.defaultButtonColour;

        actionButtons.colour = Detonator.INSTANCE.colourFactory.defaultButtonColour;
        actionButtons.highlightedColour = Detonator.INSTANCE.colourFactory.defaultHoveredButtonColour;

        /*
         state.removeFromDrawStorage(textBox);
         state.removeFromDrawStorage(background);
         if (actionButtons != null) {
         state.removeFromDrawStorage(actionButtons);
         }
   
         */

        state.removeFromDrawStorage(ui.renderList);

        //textBox.relocate(setState, storyUI);
        //ui.back.relocate(setState, storyUI);

        disable();
    }

    public StoryAgent(IState setState) {
        //textFont = Fonts.Droid_Sans_24_Outline;
        textFont = Detonator.INSTANCE.fontProvider.getDefaultFont();
        state = setState;


//textBox = (InfoGroup) Detonator.INSTANCE.interfaceElements.get("maintext");

        //textBox = new InfoGroup (50, 100, Detonator.INSTANCE.fontProvider.produceFontCopy(Detonator.INSTANCE.fontProvider.Droid_Sans_24_Outline), state);
        textBox = new InfoGroup(50, 100, Detonator.INSTANCE.fontProvider.getDefaultFont(), state);


        //((TransientGDXFont) textBox.textFont).font

        //passInfoGroup(textBox);
        textBox.isDrawn = true;



        //textBox.setFont(textFont);

        textBox.runningText = Detonator.INSTANCE.runningText;

        textBox.ButtonStartXOffset = Detonator.INSTANCE.getBindedValue("textoffsetx").value;
        textBox.ButtonStartYOffset = Detonator.INSTANCE.getBindedValue("textoffsety").value;

        textBox.maxWidth = textBox.maxWidth - textBox.ButtonStartXOffset;
        textBox.maxWidth = textBox.maxWidth - textBox.ButtonStartXOffset;
        textBox.maxWidth = textBox.maxWidth - textBox.ButtonStartXOffset;
        textBox.maxWidth = textBox.maxWidth - textBox.ButtonStartXOffset;

        //textBox.colour = TextCapsule.transientGray;
        //textBox.highlightedColour = TextCapsule.transientGray;

        textBox.colour = Detonator.INSTANCE.colourFactory.defaultButtonColour;
        textBox.highlightedColour = Detonator.INSTANCE.colourFactory.defaultButtonColour;


        //actionButtons = (ButtonGroup) Detonator.INSTANCE.interfaceElements.get("mainchoices");
        //passGroup(actionButtons);

        actionButtons = new ButtonGroup(100, 500, Detonator.INSTANCE.fontProvider.getDjvu_16_Bold_Outline(), state);

        actionButtons.ButtonStartXOffset = Detonator.INSTANCE.getBindedValue("choicesoffsetx").value;
        actionButtons.ButtonStartYOffset = Detonator.INSTANCE.getBindedValue("choicesoffsety").value;


        actionButtons.highlightedColour = Detonator.INSTANCE.colourFactory.defaultHoveredButtonColour;
        //actionButtons.ButtonYOffset = 20;
        actionButtons.textHAlign = HorizontalAlign.left;
        actionButtons.textVAlign = VerticalAlign.top;


        Log.info("Start relocating");
        //actionButtons.relocateElements(drawStorage, storyUI);
        //textBox.relocateElements(drawStorage, storyUI);
    }

    public void resetBranchCounters() {
        nowStory.branches.currentBranch.resetBranchCounters();
    }

    public static IMarker getImagePoint(int byCode) {
        for (IMarker m : imagePoints) {
            if (m.getID() == byCode) {
                return m;
            }
        }

        return null;

    }

    public static IMarker getImagePoint(String byCode) {
        return getImagePoint(Binding.getBinding(Binding.interfaceElementBinding, byCode));
    }

    public void drawAllImagePoints(SpriteBatch spriteBatch) {
        for (IMarker m : imagePoints) {
            if ((m.getImage() != null) && (m.isDrawn())) {
                //Log.info("B: "+m.isDrawn);
                m.draw(spriteBatch);
            }
        }
    }

    public void drawUI(SpriteBatch spriteBatch) {
        for (IMarker m : storyUI) {

            if (m.isDrawn()) {
                m.draw(spriteBatch);
            }
        }
    }

    public void drawAllImagePoints() {
        for (IMarker m : imagePoints) {
            if ((m.getImage() != null) && (m.isDrawn())) {
                //Log.info("B: "+m.isDrawn);
                m.draw();
            }
        }
    }

    public void drawUI() {
        for (IMarker m : storyUI) {

            if (m.isDrawn()) {
                m.draw();
            }
        }
    }

    public void render() {
        if (isEnabled) {

            //Log.info("Render STORY");

            textBox.draw();
            textBox.drawChildren();

            drawAllImagePoints();
            drawUI();


            if (actionButtons != null) {
                //Log.info("ACTIONS ARE DRAWN");
                actionButtons.draw();
            }
        }
    }

    //Note that this is not needed if you are already rendering selected elements from DrawAgent
    public void render(SpriteBatch spriteBatch) {
        if (isEnabled) {
            //Log.info("Render STORY");

           
             textBox.draw(spriteBatch);
             textBox.drawChildren(spriteBatch);
            
             if (actionButtons != null) {
             //Log.info("ACTIONS ARE DRAWN");
             actionButtons.draw(spriteBatch);
             actionButtons.drawChildren(spriteBatch);
             }
             drawAllImagePoints(spriteBatch);
             drawUI(spriteBatch);
            

            this.ui.portrait1.draw(spriteBatch);
        }
    }

    public void processClickAnywhere() {

        //Log.info("Processed clickAnywhere");

        if ((textBox.runningText == false) || (textBox.currentRunningElement.textCapsule.fullyRevealed)) {

            if (nowStory != null) {
                nowStory.processIteration(actionButtons, textBox);
                state.removeChildrenFromDrawStorage(textBox);
            }

        } else {
            while (!textBox.currentRunningElement.textCapsule.fullyRevealed) {
                textBox.currentRunningElement.textCapsule.revealAllSymbols();
            }
        }


    }

    public void processClickedMarker(IMarker clickedMarker) {

        //Log.info("Process click");
        //state.checkClickEffect(clickedMarker);

        //nowStory.play(actionButtons, infoWindow);

        if (Detonator.INSTANCE.switchStoryDetonator != -1) {
            Detonator.INSTANCE.switchStoryDetonator = -1;

            Log.info("Time to switch story");

            readCurrentStory();
            startPlayingStory();
        }


        if ((Detonator.INSTANCE.switchBranchDetonator != -1)
                && (Detonator.INSTANCE.switchBranchDetonator != Detonator.INSTANCE.zeroBranch)) {


            //what is it for?..
            //state.input.isMousePressed(Input.MOUSE_LEFT_BUTTON);

            //Log.info("Button-branch-switch!");
            //Log.info("Detonator branch: "+Detonator.instance.switchBranchDetonator);

            nowStory.play(actionButtons, textBox);


        }




        if (Detonator.INSTANCE.switchBranchDetonator == Detonator.INSTANCE.zeroBranch) {
            isInterrupted = true;

            disable();

            /*
             if ((isInterrupted) && (Detonator.INSTANCE.switchStoryDetonator == 0)) {
             System.exit(0);
             }
             */

            if (!(Detonator.INSTANCE.switchStoryDetonator == 0)) {
                isInterrupted = false;

            }

        }

    }

    public void readCurrentStory() {

        if (StoryPoint.currentPoint == null) {
            Log.error("no story selected!");
        }

        storyID = StoryPoint.currentPoint.ID;

        Log.info("nowStory = " + storyID);

        if (storyID != -1) {
            nowStory = StoryList.globalStoryList.returnStory(storyID);
        }

    }

    public void startPlayingStory() {
        if (storyID != -1) {

            resetBranchCounters();
            nowStory.startPlaying(actionButtons, textBox);
            state.removeChildrenFromDrawStorage(textBox);
        }
    }

    public void processPhase() {
        readCurrentStory();
        startPlayingStory();
    }

    public void queueStory(String byCode) {
        StoryPoint.queueStory(byCode);
        processPhase();
    }

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

    public final void enable() {
        ui.enable();
        isEnabled = true;
    }

    public final void disable() {
        ui.disable();
        isEnabled = false;
    }
}
TOP

Related Classes of transientlibs.preui.agents.misc.StoryAgent

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.