Skip to content

Instantly share code, notes, and snippets.

@Mr00Anderson
Created October 2, 2020 20:30
Show Gist options
  • Save Mr00Anderson/c989f0e40621c977b4197dfa36c9180a to your computer and use it in GitHub Desktop.
Save Mr00Anderson/c989f0e40621c977b4197dfa36c9180a to your computer and use it in GitHub Desktop.
ScreenPlayExample
package com.virtual_hex.gdx.engine.scene2d.actions;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.virtual_hex.app.AppLauncher;
import com.virtual_hex.gdx.engine.Cleanup;
import com.virtual_hex.gdx.engine.app.GdxEngScreenManagerApp;
import com.virtual_hex.gdx.engine.assets.AssetList;
import com.virtual_hex.gdx.engine.screens.GdxEngAppScreen;
public interface ActorAsset {
void addAssets(AssetList assetList);
<APP extends GdxEngScreenManagerApp> Actor build(AppLauncher<APP> appLauncher, GdxEngAppScreen<APP> appGdxEngAppScreen, Stage stage, Cleanup cleanup);
Type getType();
enum Type {
IMAGE,
ANIMATION,
LABEL
}
}
package com.virtual_hex.gdx.engine.scene2d.actions;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.utils.Array;
import com.virtual_hex.app.AppLauncher;
import com.virtual_hex.gdx.engine.Cleanup;
import com.virtual_hex.gdx.engine.app.GdxEngScreenManagerApp;
import com.virtual_hex.gdx.engine.assets.AnAsset;
import com.virtual_hex.gdx.engine.assets.AssetList;
import com.virtual_hex.gdx.engine.assets.EngAssetManager;
import com.virtual_hex.gdx.engine.scene2d.AnimatedImage;
import com.virtual_hex.gdx.engine.scene2d.EngUiUtils;
import com.virtual_hex.gdx.engine.screens.GdxEngAppScreen;
import java.util.HashSet;
import java.util.Set;
/**
* If not using an atlas, the path must be
* to the base file name, then _# will be
* appended based on the fram number
*/
public class AnimationActorAsset extends VisualActorAsset {
public String name;
public String atlasPath;
public String nameOrPath;
public float frameDuration;
public int totalFrameCount;//
public boolean cacheAsset = false;
public Vector2 initialPosition;
// THIS CLASS WONT WORK THIS SECOND
public AnimationActorAsset() {
}
public AnimationActorAsset(String name, String nameOrPath, float frameDuration, int totalFrameCount, float startingAlpha) {
super(startingAlpha);
this.name = name;
this.nameOrPath = nameOrPath;
this.frameDuration = frameDuration;
this.totalFrameCount = totalFrameCount;
}
public AnimationActorAsset(String name, String nameOrPath, float frameDuration, int totalFrameCount, float startingAlpha, Vector2 initialPosition) {
super(startingAlpha);
this.name = name;
this.nameOrPath = nameOrPath;
this.frameDuration = frameDuration;
this.totalFrameCount = totalFrameCount;
this.initialPosition = initialPosition;
}
public void addAssets(AssetList assetList) {
if(atlasPath != null){
Set<AnAsset> assets;
if(cacheAsset){
assets = assetList.caching.computeIfAbsent(TextureAtlas.class, aClass -> new HashSet<>());
} else {
assets = assetList.noCaching.computeIfAbsent(TextureAtlas.class, aClass -> new HashSet<>());
}
assets.add(new AnAsset(name, atlasPath));
} else {
for (int i = 0; i < totalFrameCount; i++) {
Set<AnAsset> assets;
if(cacheAsset){
assets = assetList.caching.computeIfAbsent(Texture.class, aClass -> new HashSet<>());
} else {
assets = assetList.noCaching.computeIfAbsent(Texture.class, aClass -> new HashSet<>());
}
assets.add(new AnAsset(name, nameOrPath + "_" + i + ".png"));
}
}
}
@Override
public <APP extends GdxEngScreenManagerApp> Actor build(AppLauncher<APP> appLauncher, GdxEngAppScreen<APP> appGdxEngAppScreen, Stage stage, Cleanup cleanup) {
EngAssetManager assetManager = appGdxEngAppScreen.getParentApp().assetManager;
if(atlasPath != null){
TextureAtlas textureAtlas = assetManager.get(atlasPath, TextureAtlas.class);
Array<TextureAtlas.AtlasRegion> regions = textureAtlas.findRegions(nameOrPath);
Animation<TextureRegion> regionAnimation = new Animation<>(frameDuration, regions);
return new AnimatedImage(regionAnimation);
} else {
Array<TextureRegion> regions = new Array<>();
for (int i = 0; i < totalFrameCount; i++) {
Texture texture = assetManager.get(nameOrPath + "_" + i + ".png", Texture.class);
TextureRegion textureRegion = new TextureRegion(texture);
regions.add(textureRegion);
}
Animation<TextureRegion> atlasRegionAnimation = new Animation<>(frameDuration, regions);
AnimatedImage actor = new AnimatedImage(atlasRegionAnimation);
if(initialPosition != null) {
actor.setPosition(initialPosition.x, initialPosition.y);
} else {
EngUiUtils.centerActor(actor);
}
return actor;
}
}
@Override
public Type getType() {
return Type.ANIMATION;
}
}
package com.virtual_hex.gdx.engine.scene2d.actions;
import com.badlogic.gdx.scenes.scene2d.Action;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.virtual_hex.app.AppLauncher;
import com.virtual_hex.gdx.engine.Cleanup;
import com.virtual_hex.gdx.engine.app.GdxEngScreenManagerApp;
import com.virtual_hex.gdx.engine.assets.AssetList;
import com.virtual_hex.gdx.engine.screens.GdxEngAppScreen;
import com.virtual_hex.gdx.engine.state.StateRefIntWrapper;
public interface EngAction<T extends Action> {
T build(AppLauncher<? extends GdxEngScreenManagerApp> appLauncher, GdxEngAppScreen screen, Stage stage, Actor actor, Cleanup cleanup, StateRefIntWrapper volume);
void addAssets(AssetList assets);
}
package com.virtual_hex.gdx.engine.scene2d.actions;
import com.badlogic.gdx.utils.Json;
import com.badlogic.gdx.utils.JsonValue;
import com.badlogic.gdx.utils.reflect.ClassReflection;
public class EngActorAssetSerializer implements Json.Serializer<EngActorScreenPlayAsset> {
public static final String ACTOR_ASSET = "actorAsset";
public static final String TYPE = "type";
public static final String IMAGE_ACTOR = "imageActor";
public static final String ATLAS_PATH = "atlasPath";
public static final String NAME_OR_PATH = "nameOrPath";
public static final String ANIMATED_IMAGE_ACTOR = "animatedImageActor";
public static final String FRAME_DURATION = "frameDuration";
public static final String FRAME_COUNT = "frameCount";
@Override
public void write(Json json, EngActorScreenPlayAsset object, Class knownType) {
json.writeObjectStart();
if(ClassReflection.isInstance(ImageActorAsset.class, object.actorAsset)){
json.writeValue(TYPE, IMAGE_ACTOR);
ImageActorAsset imageActorAsset = (ImageActorAsset) object.actorAsset;
json.writeValue(ATLAS_PATH, imageActorAsset.atlasPath);
json.writeValue(NAME_OR_PATH, imageActorAsset.nameOrPath);
} else if (ClassReflection.isInstance(AnimationActorAsset.class, object.actorAsset)){
json.writeValue(TYPE, ANIMATED_IMAGE_ACTOR);
AnimationActorAsset animationActorAsset = (AnimationActorAsset) object.actorAsset;
json.writeValue(ATLAS_PATH, animationActorAsset.atlasPath);
json.writeValue(NAME_OR_PATH, animationActorAsset.nameOrPath);
json.writeValue(FRAME_DURATION, animationActorAsset.frameDuration);
json.writeValue(FRAME_COUNT, animationActorAsset.totalFrameCount);
}
json.writeObjectEnd();
}
@Override
public EngActorScreenPlayAsset read(Json json, JsonValue jsonData, Class type) {
EngActorScreenPlayAsset object = new EngActorScreenPlayAsset();
String typeString = json.readValue(TYPE, String.class, jsonData);
if(typeString.equals(IMAGE_ACTOR)){
ImageActorAsset actorAsset = new ImageActorAsset();
actorAsset.atlasPath = json.readValue(ATLAS_PATH, String.class, jsonData);
actorAsset.nameOrPath = json.readValue(NAME_OR_PATH, String.class, jsonData);
object.actorAsset = actorAsset;
} else if (typeString.equals(ANIMATED_IMAGE_ACTOR)){
AnimationActorAsset actorAsset = new AnimationActorAsset();
actorAsset.atlasPath = json.readValue(ATLAS_PATH, String.class, jsonData);
actorAsset.nameOrPath = json.readValue(NAME_OR_PATH, String.class, jsonData);
actorAsset.frameDuration = json.readValue(FRAME_DURATION, float.class, jsonData);
actorAsset.totalFrameCount = json.readValue(FRAME_COUNT, int.class, jsonData);
object.actorAsset = actorAsset;
}
return object;
}
}
package com.virtual_hex.gdx.engine.scene2d.actions;
import com.badlogic.gdx.scenes.scene2d.Action;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.virtual_hex.app.AppLauncher;
import com.virtual_hex.gdx.engine.Cleanup;
import com.virtual_hex.gdx.engine.app.GdxEngScreenManagerApp;
import com.virtual_hex.gdx.engine.assets.AssetList;
import com.virtual_hex.gdx.engine.screens.GdxEngAppScreen;
import com.virtual_hex.gdx.engine.state.StateRefIntWrapper;
/**
* This pairs a actor and its prebuilt actions
*
* Image can be represented by a Atlas or NonAtlas Image Actor Asset
* - Single image, find in atlas or not
*
* Animations the same as above but numbered and with keyfram settings
*/
public class EngActorScreenPlayAsset {
public ActorAsset actorAsset;
public EngAction<?> actions;
public EngActorScreenPlayAsset() {
}
public EngActorScreenPlayAsset(ActorAsset actorAsset, EngAction<?> actions) {
this.actorAsset = actorAsset;
this.actions = actions;
}
public void addAssets(AssetList assetList) {
actorAsset.addAssets(assetList);
}
public void build(AppLauncher<? extends GdxEngScreenManagerApp> appLauncher, GdxEngAppScreen appGdxEngAppScreen, Stage stage, Cleanup cleanup, StateRefIntWrapper volume) {
Actor actor = actorAsset.build(appLauncher, appGdxEngAppScreen, stage, cleanup);
if(actor != null){
Action action = actions.build(appLauncher, appGdxEngAppScreen, stage, actor, cleanup, volume);
actor.addAction(Actions.sequence(action));
stage.addActor(actor);
}
}
}
package com.virtual_hex.gdx.engine.scene2d.actions;
import com.badlogic.gdx.scenes.scene2d.Action;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.actions.RunnableAction;
import com.virtual_hex.app.AppLauncher;
import com.virtual_hex.gdx.engine.Cleanup;
import com.virtual_hex.gdx.engine.app.GdxEngScreenManagerApp;
import com.virtual_hex.gdx.engine.assets.AssetList;
import com.virtual_hex.gdx.engine.screens.GdxEngAppScreen;
import com.virtual_hex.gdx.engine.state.StateRefIntWrapper;
public class EngAddNewActorAction implements EngAction<RunnableAction> {
public final EngActorScreenPlayAsset screenPlayAsset;
public EngAddNewActorAction(EngActorScreenPlayAsset screenPlayAsset) {
this.screenPlayAsset = screenPlayAsset;
}
@Override
public RunnableAction build(AppLauncher<? extends GdxEngScreenManagerApp> appLauncher, GdxEngAppScreen screen, Stage stage, Actor actor, Cleanup cleanup, StateRefIntWrapper volume) {
Actor build = screenPlayAsset.actorAsset.build(appLauncher, screen, stage, cleanup);
Action action = screenPlayAsset.actions.build(appLauncher, screen, stage, build, cleanup, volume);
build.addAction(action);
return Actions.run(() -> stage.addActor(build));
}
@Override
public void addAssets(AssetList assets) {
screenPlayAsset.actorAsset.addAssets(assets);
screenPlayAsset.actions.addAssets(assets);
}
}
package com.virtual_hex.gdx.engine.scene2d.actions;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.actions.AlphaAction;
import com.virtual_hex.app.AppLauncher;
import com.virtual_hex.gdx.engine.Cleanup;
import com.virtual_hex.gdx.engine.app.GdxEngScreenManagerApp;
import com.virtual_hex.gdx.engine.assets.AssetList;
import com.virtual_hex.gdx.engine.screens.GdxEngAppScreen;
import com.virtual_hex.gdx.engine.state.StateRefIntWrapper;
public class EngAlphaAction implements EngAction<AlphaAction> {
public float alpha;
public float duration;
// This is a function
public Interpolation interpolation;
public EngAlphaAction() {
}
public EngAlphaAction(float alpha, float duration, Interpolation interpolation) {
this.alpha = alpha;
this.duration = duration;
this.interpolation = interpolation;
}
public EngAlphaAction(int alpha) {
this.alpha = alpha;
}
@Override
public AlphaAction build(AppLauncher<? extends GdxEngScreenManagerApp> appLauncher, GdxEngAppScreen screen, Stage stage, Actor actor, Cleanup cleanup, StateRefIntWrapper volume) {
return Actions.alpha(alpha, duration, interpolation);
}
@Override
public void addAssets(AssetList assets) {
// Nothing Intended
}
}
package com.virtual_hex.gdx.engine.scene2d.actions;
import com.badlogic.gdx.utils.Json;
import com.badlogic.gdx.utils.JsonValue;
public class EngAnimatedImageActorAssetSerializer implements Json.Serializer<AnimationActorAsset> {
public static final String ATLAS_PATH = "atlasPath";
public static final String NAME_OR_PATH = "nameOrPath";
public static final String FRAME_DURATION = "frameDuration";
public static final String TOTAL_FRAME_COUNT = "totalFrameCount";
@Override
public void write(Json json, AnimationActorAsset object, Class knownType) {
json.writeObjectStart("animatedImageActor", AnimationActorAsset.class, ActorAsset.class);
json.writeField(object, ATLAS_PATH);
json.writeField(object, NAME_OR_PATH);
json.writeField(object, FRAME_DURATION);
json.writeField(object, TOTAL_FRAME_COUNT);
json.writeObjectEnd();
}
@Override
public AnimationActorAsset read(Json json, JsonValue jsonData, Class type) {
AnimationActorAsset object = new AnimationActorAsset();
json.readField(object, ATLAS_PATH, jsonData);
json.readField(object, NAME_OR_PATH, jsonData);
json.readField(object, FRAME_DURATION, jsonData);
json.readField(object, TOTAL_FRAME_COUNT, jsonData);
return object;
}
}
package com.virtual_hex.gdx.engine.scene2d.actions;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.actions.ColorAction;
import com.virtual_hex.app.AppLauncher;
import com.virtual_hex.gdx.engine.Cleanup;
import com.virtual_hex.gdx.engine.app.GdxEngScreenManagerApp;
import com.virtual_hex.gdx.engine.assets.AssetList;
import com.virtual_hex.gdx.engine.screens.GdxEngAppScreen;
import com.virtual_hex.gdx.engine.state.StateRefIntWrapper;
public class EngColorAction implements EngAction<ColorAction>{
public Color color;
public float duration;
// This is a function
public Interpolation interpolation;
public EngColorAction() {
}
public EngColorAction(Color color, float duration, Interpolation interpolation) {
this.color = color;
this.duration = duration;
this.interpolation = interpolation;
}
@Override
public ColorAction build(AppLauncher<? extends GdxEngScreenManagerApp> appLauncher, GdxEngAppScreen screen, Stage stage, Actor actor, Cleanup cleanup, StateRefIntWrapper volume) {
return Actions.color(color, duration);
}
@Override
public void addAssets(AssetList assets) {
// Nothing Intended
}
}
package com.virtual_hex.gdx.engine.scene2d.actions;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.actions.DelayAction;
import com.virtual_hex.app.AppLauncher;
import com.virtual_hex.gdx.engine.Cleanup;
import com.virtual_hex.gdx.engine.app.GdxEngScreenManagerApp;
import com.virtual_hex.gdx.engine.assets.AssetList;
import com.virtual_hex.gdx.engine.screens.GdxEngAppScreen;
import com.virtual_hex.gdx.engine.state.StateRefIntWrapper;
public class EngDelayAction implements EngAction<DelayAction>{
public float duration;
public EngDelayAction() {
}
public EngDelayAction(float duration) {
this.duration = duration;
}
@Override
public DelayAction build(AppLauncher<? extends GdxEngScreenManagerApp> appLauncher, GdxEngAppScreen screen, Stage stage, Actor actor, Cleanup cleanup, StateRefIntWrapper volume) {
return Actions.delay(duration);
}
@Override
public void addAssets(AssetList assets) {
// Nothing Intended
}
}
package com.virtual_hex.gdx.engine.scene2d.actions;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.actions.AlphaAction;
import com.virtual_hex.app.AppLauncher;
import com.virtual_hex.gdx.engine.Cleanup;
import com.virtual_hex.gdx.engine.app.GdxEngScreenManagerApp;
import com.virtual_hex.gdx.engine.assets.AssetList;
import com.virtual_hex.gdx.engine.screens.GdxEngAppScreen;
import com.virtual_hex.gdx.engine.state.StateRefIntWrapper;
public class EngFadeInAction implements EngAction<AlphaAction>{
public int duration;
// This is a function
public Interpolation interpolation;
public EngFadeInAction() {
}
public EngFadeInAction(int duration) {
this.duration = duration;
}
public EngFadeInAction(int duration, Interpolation interpolation) {
this.duration = duration;
this.interpolation = interpolation;
}
@Override
public AlphaAction build(AppLauncher<? extends GdxEngScreenManagerApp> appLauncher, GdxEngAppScreen screen, Stage stage, Actor actor, Cleanup cleanup, StateRefIntWrapper volume) {
return Actions.fadeIn(duration, interpolation);
}
@Override
public void addAssets(AssetList assets) {
// Nothing Intended
}
}
package com.virtual_hex.gdx.engine.scene2d.actions;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.actions.AlphaAction;
import com.virtual_hex.app.AppLauncher;
import com.virtual_hex.gdx.engine.Cleanup;
import com.virtual_hex.gdx.engine.app.GdxEngScreenManagerApp;
import com.virtual_hex.gdx.engine.assets.AssetList;
import com.virtual_hex.gdx.engine.screens.GdxEngAppScreen;
import com.virtual_hex.gdx.engine.state.StateRefIntWrapper;
public class EngFadeOutAction implements EngAction<AlphaAction>{
public int duration;
// This is a function
public Interpolation interpolation;
public EngFadeOutAction() {
}
public EngFadeOutAction(int duration) {
this.duration = duration;
}
public EngFadeOutAction(int duration, Interpolation interpolation) {
this.duration = duration;
this.interpolation = interpolation;
}
@Override
public AlphaAction build(AppLauncher<? extends GdxEngScreenManagerApp> appLauncher, GdxEngAppScreen screen, Stage stage, Actor actor, Cleanup cleanup, StateRefIntWrapper volume) {
return Actions.fadeOut(duration, interpolation);
}
@Override
public void addAssets(AssetList assets) {
// Nothing Intended
}
}
package com.virtual_hex.gdx.engine.scene2d.actions;
import com.badlogic.gdx.utils.Json;
import com.badlogic.gdx.utils.JsonValue;
public class EngImageActorAssetSerializer implements Json.Serializer<ImageActorAsset> {
public static final String ATLAS_PATH = "atlasPath";
public static final String NAME_OR_PATH = "nameOrPath";
@Override
public void write(Json json, ImageActorAsset object, Class knownType) {
json.writeObjectStart("imageActor", ImageActorAsset.class, ActorAsset.class);
json.writeField(object, ATLAS_PATH);
json.writeField(object, NAME_OR_PATH);
json.writeObjectEnd();
}
@Override
public ImageActorAsset read(Json json, JsonValue jsonData, Class type) {
ImageActorAsset object = new ImageActorAsset();
json.readField(object, ATLAS_PATH, jsonData);
json.readField(object, NAME_OR_PATH, jsonData);
return object;
}
}
package com.virtual_hex.gdx.engine.scene2d.actions;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.actions.MoveByAction;
import com.virtual_hex.app.AppLauncher;
import com.virtual_hex.gdx.engine.Cleanup;
import com.virtual_hex.gdx.engine.app.GdxEngScreenManagerApp;
import com.virtual_hex.gdx.engine.assets.AssetList;
import com.virtual_hex.gdx.engine.screens.GdxEngAppScreen;
import com.virtual_hex.gdx.engine.state.StateRefIntWrapper;
public class EngMoveByAction implements EngAction<MoveByAction>{
public float amountX;
public float amountY;
public float duration;
// This is a function
public Interpolation interpolation;
public EngMoveByAction() {
}
public EngMoveByAction(float amountX, float amountY, float duration, Interpolation interpolation) {
this.amountX = amountX;
this.amountY = amountY;
this.duration = duration;
this.interpolation = interpolation;
}
public EngMoveByAction(float amountX, float amountY) {
this.amountX = amountX;
this.amountY = amountY;
}
@Override
public MoveByAction build(AppLauncher<? extends GdxEngScreenManagerApp> appLauncher, GdxEngAppScreen screen, Stage stage, Actor actor, Cleanup cleanup, StateRefIntWrapper volume) {
return Actions.moveBy(amountX, amountY, duration, interpolation);
}
@Override
public void addAssets(AssetList assets) {
// Nothing Intended
}
}
package com.virtual_hex.gdx.engine.scene2d.actions;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.actions.MoveToAction;
import com.virtual_hex.app.AppLauncher;
import com.virtual_hex.gdx.engine.Cleanup;
import com.virtual_hex.gdx.engine.app.GdxEngScreenManagerApp;
import com.virtual_hex.gdx.engine.assets.AssetList;
import com.virtual_hex.gdx.engine.screens.GdxEngAppScreen;
import com.virtual_hex.gdx.engine.state.StateRefIntWrapper;
public class EngMoveToAction implements EngAction<MoveToAction>{
public float x;
public float y;
public float duration;
// This is a function
public Interpolation interpolation;
public EngMoveToAction() {
}
public EngMoveToAction(int x, int y) {
this.x = x;
this.y = y;
}
public EngMoveToAction(int x, int y, float duration) {
this.x = x;
this.y = y;
this.duration = duration;
}
public EngMoveToAction(float x, float y, float duration, Interpolation interpolation) {
this.x = x;
this.y = y;
this.duration = duration;
this.interpolation = interpolation;
}
@Override
public MoveToAction build(AppLauncher<? extends GdxEngScreenManagerApp> appLauncher, GdxEngAppScreen screen, Stage stage, Actor actor, Cleanup cleanup, StateRefIntWrapper volume) {
return Actions.moveTo(x, y, duration, interpolation);
}
@Override
public void addAssets(AssetList assets) {
// Nothing Intended
}
}
package com.virtual_hex.gdx.engine.scene2d.actions;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.actions.MoveToAction;
import com.virtual_hex.app.AppLauncher;
import com.virtual_hex.gdx.engine.Cleanup;
import com.virtual_hex.gdx.engine.app.GdxEngScreenManagerApp;
import com.virtual_hex.gdx.engine.assets.AssetList;
import com.virtual_hex.gdx.engine.screens.GdxEngAppScreen;
import com.virtual_hex.gdx.engine.state.StateRefIntWrapper;
public class EngMoveToAlignedAction implements EngAction<MoveToAction>{
public float x;
public float y;
public int alignment;
public float duration;
public Interpolation interpolation;
public EngMoveToAlignedAction() {
}
public EngMoveToAlignedAction(float x, float y, int alignment, float duration, Interpolation interpolation) {
this.x = x;
this.y = y;
this.alignment = alignment;
this.duration = duration;
this.interpolation = interpolation;
}
@Override
public MoveToAction build(AppLauncher<? extends GdxEngScreenManagerApp> appLauncher, GdxEngAppScreen screen, Stage stage, Actor actor, Cleanup cleanup, StateRefIntWrapper volume) {
return Actions.moveToAligned(x, y, alignment, duration, interpolation);
}
@Override
public void addAssets(AssetList assets) {
// Nothing Intended
}
}
package com.virtual_hex.gdx.engine.scene2d.actions;
import com.badlogic.gdx.scenes.scene2d.Action;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.actions.ParallelAction;
import com.badlogic.gdx.utils.Array;
import com.virtual_hex.app.AppLauncher;
import com.virtual_hex.gdx.engine.Cleanup;
import com.virtual_hex.gdx.engine.app.GdxEngScreenManagerApp;
import com.virtual_hex.gdx.engine.assets.AssetList;
import com.virtual_hex.gdx.engine.screens.GdxEngAppScreen;
import com.virtual_hex.gdx.engine.state.StateRefIntWrapper;
public class EngParallelAction implements EngAction<ParallelAction>{
public Array<EngAction<?>> actions = new Array<>();
public EngParallelAction() {
}
public EngParallelAction(Array<EngAction<?>> actions) {
this.actions = actions;
}
public EngParallelAction add(EngAction<?> action) {
actions.add(action);
return this;
}
@Override
public ParallelAction build(AppLauncher<? extends GdxEngScreenManagerApp> appLauncher, GdxEngAppScreen screen, Stage stage, Actor actor, Cleanup cleanup, StateRefIntWrapper volume) {
Action[] actionsArray = new Action[actions.size];
for (int i = 0; i < actionsArray.length; i++) {
actionsArray[i] = actions.get(i).build(appLauncher, screen, stage, actor, cleanup, volume);
}
return Actions.parallel(actionsArray);
}
@Override
public void addAssets(AssetList assets) {
for (EngAction<?> action : actions) {
action.addAssets(assets);
}
}
}
package com.virtual_hex.gdx.engine.scene2d.actions;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.actions.SequenceAction;
import com.badlogic.gdx.utils.Disposable;
import com.virtual_hex.app.AppLauncher;
import com.virtual_hex.gdx.engine.Cleanup;
import com.virtual_hex.gdx.engine.app.GdxEngScreenManagerApp;
import com.virtual_hex.gdx.engine.assets.AnAsset;
import com.virtual_hex.gdx.engine.assets.AssetList;
import com.virtual_hex.gdx.engine.screens.GdxEngAppScreen;
import com.virtual_hex.gdx.engine.state.StateRefIntWrapper;
import com.virtual_hex.gdx.engine.state.StateReference;
import java.util.HashSet;
import java.util.Set;
public class EngPlaySoundAction implements EngAction<SequenceAction> {
public AnAsset anAsset;
public float volume = 1f;
public boolean cacheAsset;
public EngPlaySoundAction() {
}
public EngPlaySoundAction(AnAsset asset) {
this.anAsset = asset;
}
public EngPlaySoundAction(AnAsset asset, float volume) {
this.anAsset = asset;
this.volume = volume;
}
@Override
public SequenceAction build(AppLauncher<? extends GdxEngScreenManagerApp> appLauncher, GdxEngAppScreen screen, Stage stage, Actor actor, Cleanup cleanup, StateRefIntWrapper volume) {
AssetManager assetManager = appLauncher.getEngineApp().assetManager;
String path = anAsset.path;
if(!assetManager.contains(path)){
assetManager.load(path, Sound.class);
assetManager.finishLoading();
}
Sound sound = assetManager.get(path, Sound.class);
cleanup.setStoppable(new Cleanup.Stoppable() {
@Override
public void stop() {
sound.stop();
}
});
cleanup.setDisposable(new Disposable() {
@Override
public void dispose() {
sound.dispose();
}
});
return Actions.sequence(Actions.run(() -> {
long play = sound.play();
sound.setVolume(play, MathUtils.norm(0, 100, volume.get()));
// Make sure we update the volume if changes
StateReference.ChangedNotifierAdapter notifierAdapter = new StateReference.ChangedNotifierAdapter() {
@Override
public void changed(Object value) {
sound.setVolume(play, MathUtils.norm(0, 100, volume.get()));
}
};
// Clean up the handler
cleanup.setDisposable(new Disposable() {
@Override
public void dispose() {
notifierAdapter.shouldRemove = true;
}
});
volume.listenToChanges(notifierAdapter);
}));
}
@Override
public void addAssets(AssetList assetList) {
Set<AnAsset> assets;
if(cacheAsset){
assets = assetList.caching.computeIfAbsent(Sound.class, aClass -> new HashSet<>());
} else {
assets = assetList.noCaching.computeIfAbsent(Sound.class, aClass -> new HashSet<>());
}
assets.add(anAsset);
}
}
package com.virtual_hex.gdx.engine.scene2d.actions;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.actions.RemoveActorAction;
import com.virtual_hex.app.AppLauncher;
import com.virtual_hex.gdx.engine.Cleanup;
import com.virtual_hex.gdx.engine.app.GdxEngScreenManagerApp;
import com.virtual_hex.gdx.engine.assets.AssetList;
import com.virtual_hex.gdx.engine.screens.GdxEngAppScreen;
import com.virtual_hex.gdx.engine.state.StateRefIntWrapper;
public class EngRemoveActorAction implements EngAction<RemoveActorAction> {
public EngRemoveActorAction() {
}
@Override
public RemoveActorAction build(AppLauncher<? extends GdxEngScreenManagerApp> appLauncher, GdxEngAppScreen screen, Stage stage, Actor actor, Cleanup cleanup, StateRefIntWrapper volume) {
return Actions.removeActor(actor);
}
@Override
public void addAssets(AssetList assets) {
// Nothing Intended
}
}
package com.virtual_hex.gdx.engine.scene2d.actions;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.actions.RepeatAction;
import com.virtual_hex.app.AppLauncher;
import com.virtual_hex.gdx.engine.Cleanup;
import com.virtual_hex.gdx.engine.app.GdxEngScreenManagerApp;
import com.virtual_hex.gdx.engine.assets.AssetList;
import com.virtual_hex.gdx.engine.screens.GdxEngAppScreen;
import com.virtual_hex.gdx.engine.state.StateRefIntWrapper;
public class EngRepeatCountAction implements EngAction<RepeatAction>{
public int count;
public EngAction<?> action;
public EngRepeatCountAction() {
}
public EngRepeatCountAction(int count, EngAction<?> action) {
this.count = count;
this.action = action;
}
@Override
public RepeatAction build(AppLauncher<? extends GdxEngScreenManagerApp> appLauncher, GdxEngAppScreen screen, Stage stage, Actor actor, Cleanup cleanup, StateRefIntWrapper volume) {
return Actions.repeat(count, action.build(appLauncher, screen, stage, actor, cleanup, volume));
}
@Override
public void addAssets(AssetList assets) {
// Nothing Intended
}
}
package com.virtual_hex.gdx.engine.scene2d.actions;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.actions.RepeatAction;
import com.virtual_hex.app.AppLauncher;
import com.virtual_hex.gdx.engine.Cleanup;
import com.virtual_hex.gdx.engine.app.GdxEngScreenManagerApp;
import com.virtual_hex.gdx.engine.assets.AssetList;
import com.virtual_hex.gdx.engine.screens.GdxEngAppScreen;
import com.virtual_hex.gdx.engine.state.StateRefIntWrapper;
public class EngRepeatForeverAction implements EngAction<RepeatAction>{
public EngAction<?> action;
public EngRepeatForeverAction() {
}
public EngRepeatForeverAction(EngAction<?> action) {
this.action = action;
}
@Override
public RepeatAction build(AppLauncher<? extends GdxEngScreenManagerApp> appLauncher, GdxEngAppScreen screen, Stage stage, Actor actor, Cleanup cleanup, StateRefIntWrapper volume) {
return Actions.forever(action.build(appLauncher, screen, stage, actor, cleanup, volume));
}
@Override
public void addAssets(AssetList assets) {
// Nothing Intended
}
}
package com.virtual_hex.gdx.engine.scene2d.actions;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.actions.RotateToAction;
import com.virtual_hex.app.AppLauncher;
import com.virtual_hex.gdx.engine.Cleanup;
import com.virtual_hex.gdx.engine.app.GdxEngScreenManagerApp;
import com.virtual_hex.gdx.engine.assets.AssetList;
import com.virtual_hex.gdx.engine.screens.GdxEngAppScreen;
import com.virtual_hex.gdx.engine.state.StateRefIntWrapper;
public class EngRotateToAction implements EngAction<RotateToAction>{
public float rotationAmount;
public float duration;
public Interpolation interpolation;
public EngRotateToAction() {
}
public EngRotateToAction(int rotationAmount) {
this.rotationAmount = rotationAmount;
}
public EngRotateToAction(float rotationAmount, float duration, Interpolation interpolation) {
this.rotationAmount = rotationAmount;
this.duration = duration;
this.interpolation = interpolation;
}
public EngRotateToAction(int rotationAmount, int duration) {
this.rotationAmount = rotationAmount;
this.duration = duration;
}
@Override
public RotateToAction build(AppLauncher<? extends GdxEngScreenManagerApp> appLauncher, GdxEngAppScreen screen, Stage stage, Actor actor, Cleanup cleanup, StateRefIntWrapper volume) {
return Actions.rotateTo(rotationAmount, duration, interpolation);
}
@Override
public void addAssets(AssetList assets) {
// Nothing Intended
}
}
package com.virtual_hex.gdx.engine.scene2d.actions;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.actions.RunnableAction;
import com.virtual_hex.app.AppLauncher;
import com.virtual_hex.gdx.engine.Cleanup;
import com.virtual_hex.gdx.engine.app.GdxEngScreenManagerApp;
import com.virtual_hex.gdx.engine.assets.AssetList;
import com.virtual_hex.gdx.engine.screens.GdxEngAppScreen;
import com.virtual_hex.gdx.engine.state.StateRefIntWrapper;
public class EngRunnableAction implements EngAction<RunnableAction>{
public Runnable runnable;
public EngRunnableAction() {
}
public EngRunnableAction(Runnable runnable) {
this.runnable = runnable;
}
@Override
public RunnableAction build(AppLauncher<? extends GdxEngScreenManagerApp> appLauncher, GdxEngAppScreen screen, Stage stage, Actor actor, Cleanup cleanup, StateRefIntWrapper volume) {
return Actions.run(runnable);
}
@Override
public void addAssets(AssetList assets) {
// Nothing Intended
}
}
package com.virtual_hex.gdx.engine.scene2d.actions;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.actions.ScaleByAction;
import com.virtual_hex.app.AppLauncher;
import com.virtual_hex.gdx.engine.Cleanup;
import com.virtual_hex.gdx.engine.app.GdxEngScreenManagerApp;
import com.virtual_hex.gdx.engine.assets.AssetList;
import com.virtual_hex.gdx.engine.screens.GdxEngAppScreen;
import com.virtual_hex.gdx.engine.state.StateRefIntWrapper;
public class EngScaleByAction implements EngAction<ScaleByAction>{
public float amountX;
public float amountY;
public float duration;
public Interpolation interpolation;
public EngScaleByAction() {
}
public EngScaleByAction(float amountX, float amountY, float duration, Interpolation interpolation) {
this.amountX = amountX;
this.amountY = amountY;
this.duration = duration;
this.interpolation = interpolation;
}
@Override
public ScaleByAction build(AppLauncher<? extends GdxEngScreenManagerApp> appLauncher, GdxEngAppScreen screen, Stage stage, Actor actor, Cleanup cleanup, StateRefIntWrapper volume) {
return Actions.scaleBy(amountX, amountY, duration, interpolation);
}
@Override
public void addAssets(AssetList assets) {
// Nothing Intended
}
}
package com.virtual_hex.gdx.engine.scene2d.actions;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.actions.ScaleToAction;
import com.virtual_hex.app.AppLauncher;
import com.virtual_hex.gdx.engine.Cleanup;
import com.virtual_hex.gdx.engine.app.GdxEngScreenManagerApp;
import com.virtual_hex.gdx.engine.assets.AssetList;
import com.virtual_hex.gdx.engine.screens.GdxEngAppScreen;
import com.virtual_hex.gdx.engine.state.StateRefIntWrapper;
public class EngScaleToAction implements EngAction<ScaleToAction> {
public float x;
public float y;
public float duration;
public Interpolation interpolation;
public EngScaleToAction() {
}
public EngScaleToAction(float x, float y, float duration, Interpolation interpolation) {
this.x = x;
this.y = y;
this.duration = duration;
this.interpolation = interpolation;
}
@Override
public ScaleToAction build(AppLauncher<? extends GdxEngScreenManagerApp> appLauncher, GdxEngAppScreen screen, Stage stage, Actor actor, Cleanup cleanup, StateRefIntWrapper volume) {
return Actions.scaleTo(x, y, duration, interpolation);
}
@Override
public void addAssets(AssetList assets) {
// Nothing Intended
}
}
package com.virtual_hex.gdx.engine.scene2d.actions;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.actions.RunnableAction;
import com.virtual_hex.app.AppLauncher;
import com.virtual_hex.gdx.engine.Cleanup;
import com.virtual_hex.gdx.engine.app.GdxEngScreenManagerApp;
import com.virtual_hex.gdx.engine.assets.AssetList;
import com.virtual_hex.gdx.engine.screens.GdxEngAppScreen;
import com.virtual_hex.gdx.engine.state.StateRefIntWrapper;
public class EngScreenSetAction implements EngAction<RunnableAction> {
public String name;
public EngScreenSetAction() {
}
public EngScreenSetAction(String name) {
this.name = name;
}
@Override
public RunnableAction build(AppLauncher<? extends GdxEngScreenManagerApp> appLauncher, GdxEngAppScreen screen, Stage stage, Actor actor, Cleanup cleanup, StateRefIntWrapper volume) {
return Actions.run(() -> appLauncher.getEngineApp().setScreenByName(name));
}
@Override
public void addAssets(AssetList assets) {
}
}
package com.virtual_hex.gdx.engine.scene2d.actions;
import com.badlogic.gdx.scenes.scene2d.Action;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.actions.SequenceAction;
import com.badlogic.gdx.utils.Array;
import com.virtual_hex.app.AppLauncher;
import com.virtual_hex.gdx.engine.Cleanup;
import com.virtual_hex.gdx.engine.app.GdxEngScreenManagerApp;
import com.virtual_hex.gdx.engine.assets.AssetList;
import com.virtual_hex.gdx.engine.screens.GdxEngAppScreen;
import com.virtual_hex.gdx.engine.state.StateRefIntWrapper;
public class EngSequenceAction implements EngAction<SequenceAction>{
public Array<EngAction<?>> actions = new Array<>();
public EngSequenceAction() {
}
public EngSequenceAction(Array<EngAction<?>> actions) {
this.actions = actions;
}
public EngSequenceAction add(EngAction<?> action) {
actions.add(action);
return this;
}
@Override
public SequenceAction build(AppLauncher<? extends GdxEngScreenManagerApp> appLauncher, GdxEngAppScreen screen, Stage stage, Actor actor, Cleanup cleanup, StateRefIntWrapper volume) {
Action[] actionsArray = new Action[actions.size];
for (int i = 0; i < actionsArray.length; i++) {
actionsArray[i] = actions.get(i).build(appLauncher, screen, stage, actor, cleanup, volume);
}
return Actions.sequence(actionsArray);
}
@Override
public void addAssets(AssetList assetList) {
for (EngAction<?> action : actions) {
action.addAssets(assetList);
}
}
}
package com.virtual_hex.gdx.engine.scene2d.actions;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.actions.MoveToAction;
import com.virtual_hex.app.AppLauncher;
import com.virtual_hex.gdx.engine.Cleanup;
import com.virtual_hex.gdx.engine.app.GdxEngScreenManagerApp;
import com.virtual_hex.gdx.engine.assets.AssetList;
import com.virtual_hex.gdx.engine.screens.GdxEngAppScreen;
import com.virtual_hex.gdx.engine.state.StateRefIntWrapper;
public class EngSimplePositionAction implements EngAction<MoveToAction> {
public Position position;
public float duration;
public Interpolation interpolation;
public EngSimplePositionAction() {
this.position = Position.CENTER;
}
public EngSimplePositionAction(Position position) {
this.position = position;
}
public EngSimplePositionAction(Position position, float duration) {
this.position = position;
this.duration = duration;
}
public EngSimplePositionAction(Position position, float duration, Interpolation interpolation) {
this.position = position;
this.duration = duration;
this.interpolation = interpolation;
}
@Override
public MoveToAction build(AppLauncher<? extends GdxEngScreenManagerApp> appLauncher, GdxEngAppScreen screen, Stage stage, Actor actor, Cleanup cleanup, StateRefIntWrapper volume) {
float x = 0;
float y = 0;
switch (position) {
case BOTTOM_LEFT: {
float actorWidthHalved = actor.getWidth() / 2;
float actorHeightHalved = actor.getHeight() / 2;
x = 0 - actorWidthHalved;
y = 0 - actorHeightHalved;
break;
}
case BOTTOM_MIDDLE: {
float actorWidthHalved = actor.getWidth() / 2;
float actorHeightHalved = actor.getHeight() / 2;
int widthHalved = Gdx.graphics.getWidth() / 2;
x = widthHalved - actorWidthHalved;
y = 0 - actorHeightHalved;
break;
}
case BOTTOM_RIGHT: {
float actorWidthHalved = actor.getWidth() / 2;
float actorHeightHalved = actor.getHeight() / 2;
int widthHalved = Gdx.graphics.getWidth();
x = widthHalved - actorWidthHalved;
y = 0 - actorHeightHalved;
break;
}
case RIGHT_MIDDLE: {
float actorWidthHalved = actor.getWidth() / 2;
float actorHeightHalved = actor.getHeight() / 2;
int widthHalved = Gdx.graphics.getWidth();
int heightHalved = Gdx.graphics.getHeight() / 2;
x = widthHalved - actorWidthHalved;
y = heightHalved - actorHeightHalved;
break;
}
case TOP_RIGHT: {
float actorWidthHalved = actor.getWidth() / 2;
float actorHeightHalved = actor.getHeight() / 2;
int widthHalved = Gdx.graphics.getWidth();
int heightHalved = Gdx.graphics.getHeight();
x = widthHalved - actorWidthHalved;
y = heightHalved - actorHeightHalved;
break;
}
case TOP_MIDDLE: {
float actorWidthHalved = actor.getWidth() / 2;
float actorHeightHalved = actor.getHeight() / 2;
int widthHalved = Gdx.graphics.getWidth() / 2;
int heightHalved = Gdx.graphics.getHeight();
x = widthHalved - actorWidthHalved;
y = heightHalved - actorHeightHalved;
break;
}
case TOP_LEFT: {
float actorWidthHalved = actor.getWidth() / 2;
float actorHeightHalved = actor.getHeight() / 2;
int heightHalved = Gdx.graphics.getHeight();
x = 0 - actorWidthHalved;
y = heightHalved - actorHeightHalved;
break;
}
case LEFT_MIDDLE: {
float actorWidthHalved = actor.getWidth() / 2;
float actorHeightHalved = actor.getHeight();
int heightHalved = Gdx.graphics.getHeight();
x = 0 - actorWidthHalved;
y = heightHalved - actorHeightHalved;
break;
}
case CENTER: {
float actorWidthHalved = actor.getWidth() / 2;
float actorHeightHalved = actor.getHeight() / 2;
int widthHalved = Gdx.graphics.getWidth() / 2;
int heightHalved = Gdx.graphics.getHeight() / 2;
x = widthHalved - actorWidthHalved;
y = heightHalved - actorHeightHalved;
break;
}
}
return Actions.moveTo(x, y, duration, interpolation);
}
@Override
public void addAssets(AssetList assets) {
// Nothing Intended
}
/**@---@---@
* | | |
* @ @ @
* | | |
* @___@___@
*
*/
public enum Position {
BOTTOM_LEFT,
BOTTOM_MIDDLE,
BOTTOM_RIGHT,
RIGHT_MIDDLE,
TOP_RIGHT,
TOP_MIDDLE,
TOP_LEFT,
LEFT_MIDDLE,
CENTER,
}
}
package com.virtual_hex.gdx.engine.scene2d.actions;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.actions.SizeByAction;
import com.virtual_hex.app.AppLauncher;
import com.virtual_hex.gdx.engine.Cleanup;
import com.virtual_hex.gdx.engine.app.GdxEngScreenManagerApp;
import com.virtual_hex.gdx.engine.assets.AssetList;
import com.virtual_hex.gdx.engine.screens.GdxEngAppScreen;
import com.virtual_hex.gdx.engine.state.StateRefIntWrapper;
public class EngSizeByAction implements EngAction<SizeByAction>{
public float amountX;
public float amountY;
public float duration;
public Interpolation interpolation;
public EngSizeByAction() {
}
public EngSizeByAction(float amountX, float amountY, float duration, Interpolation interpolation) {
this.amountX = amountX;
this.amountY = amountY;
this.duration = duration;
this.interpolation = interpolation;
}
@Override
public SizeByAction build(AppLauncher<? extends GdxEngScreenManagerApp> appLauncher, GdxEngAppScreen screen, Stage stage, Actor actor, Cleanup cleanup, StateRefIntWrapper volume) {
return Actions.sizeBy(amountX, amountY, duration, interpolation);
}
@Override
public void addAssets(AssetList assets) {
// Nothing Intended
}
}
package com.virtual_hex.gdx.engine.scene2d.actions;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.actions.SizeToAction;
import com.virtual_hex.app.AppLauncher;
import com.virtual_hex.gdx.engine.Cleanup;
import com.virtual_hex.gdx.engine.app.GdxEngScreenManagerApp;
import com.virtual_hex.gdx.engine.assets.AssetList;
import com.virtual_hex.gdx.engine.screens.GdxEngAppScreen;
import com.virtual_hex.gdx.engine.state.StateRefIntWrapper;
public class EngSizeToAction implements EngAction<SizeToAction> {
public float x;
public float y;
public float duration;
public Interpolation interpolation;
public EngSizeToAction() {
}
public EngSizeToAction(float x, float y, float duration, Interpolation interpolation) {
this.x = x;
this.y = y;
this.duration = duration;
this.interpolation = interpolation;
}
@Override
public SizeToAction build(AppLauncher<? extends GdxEngScreenManagerApp> appLauncher, GdxEngAppScreen screen, Stage stage, Actor actor, Cleanup cleanup, StateRefIntWrapper volume) {
return Actions.sizeTo(x, y, duration, interpolation);
}
@Override
public void addAssets(AssetList assets) {
// Nothing Intended
}
}
package com.virtual_hex.gdx.engine.scene2d.actions;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.actions.VisibleAction;
import com.virtual_hex.app.AppLauncher;
import com.virtual_hex.gdx.engine.Cleanup;
import com.virtual_hex.gdx.engine.app.GdxEngScreenManagerApp;
import com.virtual_hex.gdx.engine.assets.AssetList;
import com.virtual_hex.gdx.engine.screens.GdxEngAppScreen;
import com.virtual_hex.gdx.engine.state.StateRefIntWrapper;
public class EngVisibleAction implements EngAction<VisibleAction> {
public boolean visible;
public EngVisibleAction() {
}
public EngVisibleAction(boolean visible) {
this.visible = visible;
}
@Override
public VisibleAction build(AppLauncher<? extends GdxEngScreenManagerApp> appLauncher, GdxEngAppScreen screen, Stage stage, Actor actor, Cleanup cleanup, StateRefIntWrapper volume) {
return Actions.visible(visible);
}
@Override
public void addAssets(AssetList assets) {
// Nothing Intended
}
}
package com.virtual_hex.gdx.engine.scene2d.actions;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.virtual_hex.app.AppLauncher;
import com.virtual_hex.gdx.engine.Cleanup;
import com.virtual_hex.gdx.engine.app.GdxEngScreenManagerApp;
import com.virtual_hex.gdx.engine.assets.AnAsset;
import com.virtual_hex.gdx.engine.assets.AssetList;
import com.virtual_hex.gdx.engine.assets.EngAssetManager;
import com.virtual_hex.gdx.engine.scene2d.EngUiUtils;
import com.virtual_hex.gdx.engine.screens.GdxEngAppScreen;
import java.util.HashSet;
import java.util.Set;
/**
* If this is a file in atlas then provide
*/
public class ImageActorAsset extends VisualActorAsset {
public String name;
public String atlasPath;
public String nameOrPath;
public boolean cacheAsset = false;
public Vector2 initialPosition;
public ImageActorAsset() {
}
public ImageActorAsset(String name, String nameOrPath, float startingAlpha) {
super(startingAlpha);
this.name = name;
this.nameOrPath = nameOrPath;
}
public ImageActorAsset(String name, String atlasPath, String nameOrPath, float startingAlpha) {
super(startingAlpha);
this.name = name;
this.atlasPath = atlasPath;
this.nameOrPath = nameOrPath;
}
@Override
public void addAssets(AssetList assetList) {
if(atlasPath != null){
Set<AnAsset> assets;
if(cacheAsset){
assets = assetList.caching.computeIfAbsent(TextureAtlas.class, aClass -> new HashSet<>());
} else {
assets = assetList.noCaching.computeIfAbsent(TextureAtlas.class, aClass -> new HashSet<>());
}
assets.add(new AnAsset(name, atlasPath));
} else {
Set<AnAsset> assets;
if(cacheAsset){
assets = assetList.caching.computeIfAbsent(Texture.class, aClass -> new HashSet<>());
} else {
assets = assetList.noCaching.computeIfAbsent(Texture.class, aClass -> new HashSet<>());
}
assets.add(new AnAsset(name, nameOrPath));
}
}
@Override
public <APP extends GdxEngScreenManagerApp> Actor build(AppLauncher<APP> appLauncher, GdxEngAppScreen<APP> appGdxEngAppScreen, Stage stage, Cleanup cleanup) {
EngAssetManager assetManager = appGdxEngAppScreen.getParentApp().assetManager;
Image actor;
if(atlasPath != null){
TextureAtlas textureAtlas = assetManager.get(atlasPath, TextureAtlas.class);
TextureAtlas.AtlasRegion region = textureAtlas.findRegion(nameOrPath);
actor = new Image(region);
} else {
Texture texture = assetManager.get(nameOrPath, Texture.class);
actor = new Image(texture);
}
actor.getColor().a = startingAlpha;
if(initialPosition != null) {
actor.setPosition(initialPosition.x, initialPosition.y);
} else {
EngUiUtils.centerActor(actor);
}
return actor;
}
@Override
public Type getType() {
return Type.IMAGE;
}
}
package com.virtual_hex.gdx.engine.scene2d.actions;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.virtual_hex.app.AppLauncher;
import com.virtual_hex.gdx.engine.Cleanup;
import com.virtual_hex.gdx.engine.app.GdxEngScreenManagerApp;
import com.virtual_hex.gdx.engine.assets.AssetList;
import com.virtual_hex.gdx.engine.scene2d.EngUiUtils;
import com.virtual_hex.gdx.engine.screens.GdxEngAppScreen;
public class LabelActorAsset extends VisualActorAsset{
public final String label;
public boolean cacheAsset = false;
public Vector2 initialPosition;
public LabelActorAsset(String labelString, float startingAlpha) {
super(startingAlpha);
this.label = labelString;
}
@Override
public void addAssets(AssetList assetList) {
}
@Override
public <APP extends GdxEngScreenManagerApp> Actor build(AppLauncher<APP> appLauncher, GdxEngAppScreen<APP> appGdxEngAppScreen, Stage stage, Cleanup cleanup) {
Skin skin = appLauncher.getEngineApp().getManagers().getSkinManager().getSelectedSkin();
Label actor = new Label(this.label, skin);
actor.getColor().a = startingAlpha;
if(initialPosition != null) {
actor.setPosition(initialPosition.x, initialPosition.y);
} else {
EngUiUtils.centerActor(actor);
}
return actor;
}
@Override
public Type getType() {
return Type.LABEL;
}
}
package com.virtual_hex.gdx.engine.scene2d.actions;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.utils.Array;
import com.virtual_hex.app.AppLauncher;
import com.virtual_hex.gdx.engine.Cleanup;
import com.virtual_hex.gdx.engine.app.GdxEngScreenManagerApp;
import com.virtual_hex.gdx.engine.assets.AnAsset;
import com.virtual_hex.gdx.engine.assets.AssetList;
import com.virtual_hex.gdx.engine.scene2d.EngStage;
import com.virtual_hex.gdx.engine.scene2d.VirtualHexSplashOneAssets;
import com.virtual_hex.gdx.engine.screens.GdxEngAppScreen;
import com.virtual_hex.gdx.engine.state.StateRefIntWrapper;
import java.util.HashMap;
public class ScreenPlayBuilder {
public Array<EngActorScreenPlayAsset> actors;
public AssetList assetList;
public int totalActors;
private transient StateRefIntWrapper volume;
// Make sure all are removed after
// Make sure we notify when complete
public ScreenPlayBuilder(Array<EngActorScreenPlayAsset> actors) {
this.actors = actors;
this.assetList = new AssetList(new HashMap<>(), new HashMap<>());
this.totalActors = 0;
}
public AssetList buildAssetList(){
int size = actors.size;
for (int i = 0; i < size; i++) {
EngActorScreenPlayAsset screenPlayAsset = actors.get(i);
screenPlayAsset.actorAsset.addAssets(assetList);
screenPlayAsset.actions.addAssets(assetList);
}
return assetList;
}
public <APP extends GdxEngScreenManagerApp> void setupAndStart(AppLauncher<APP> appLauncher, GdxEngAppScreen<APP> screen, EngStage stage, Cleanup cleanup, StateRefIntWrapper volume) {
this.volume = volume;
int size = actors.size;
for (int i = 0; i < size; i++) {
EngActorScreenPlayAsset playAsset = actors.get(i);
playAsset.build(appLauncher, screen, stage, cleanup, volume);
}
}
// Abstract away that we need to have a "screen play" so we can know when this whole one is finished
// and be ready for the new one
public static ScreenPlayBuilder getVirtualHexSplashOne(EngActorScreenPlayAsset appSpecific, String nextScreen) {
Array<EngActorScreenPlayAsset> actors = new Array<>();
ScreenPlayBuilder screenPlay = new ScreenPlayBuilder(actors);
AnimationActorAsset animationActorAsset =
new AnimationActorAsset("bad_logic", "images/logo/libgdx/libGDX_BadLogic_Logo_angle", 0.10f, 64, 1);
ImageActorAsset imageActorAsset = new ImageActorAsset("vhex", VirtualHexSplashOneAssets.TEXTURE, 0);
LabelActorAsset labelActorAsset = new LabelActorAsset(
"Virtual Hex Games\n\n" +
"Powered by libGDX", 0);
EngAction lastAction;
if(appSpecific == null){
lastAction = new EngScreenSetAction(nextScreen);
} else {
lastAction = new EngSequenceAction()
.add(new EngAddNewActorAction(appSpecific))
.add(new EngRemoveActorAction());
}
EngActorScreenPlayAsset labelAsset = new EngActorScreenPlayAsset();
labelAsset.actorAsset = labelActorAsset;
labelAsset.actions = new EngSequenceAction()
.add(new EngSizeByAction(200, 200, 0, Interpolation.linear))
.add(new EngAlphaAction(1))
.add(new EngPlaySoundAction(new AnAsset("splishSplosh", VirtualHexSplashOneAssets.SMASH_SPLOSH)))
.add(new EngDelayAction(3))
.add(new EngFadeOutAction(3))
.add(lastAction)
.add(new EngRemoveActorAction());
EngActorScreenPlayAsset badLogicAnimation = new EngActorScreenPlayAsset();
badLogicAnimation.actorAsset = animationActorAsset;
badLogicAnimation.actions = new EngSequenceAction()
.add(new EngDelayAction(7))
.add(new EngAddNewActorAction(labelAsset))
.add(new EngRemoveActorAction());
EngActorScreenPlayAsset engActorAsset = new EngActorScreenPlayAsset();
engActorAsset.actorAsset = imageActorAsset;
engActorAsset.actions = new EngSequenceAction()
.add(new EngDelayAction(1))
.add(new EngPlaySoundAction(new AnAsset("electric", VirtualHexSplashOneAssets.SOUND_INTRO_1_ELECTRIC), .5f))
.add(new EngFadeInAction(5, Interpolation.bounce))
.add(new EngDelayAction(1))
.add(new EngPlaySoundAction(new AnAsset("ping",VirtualHexSplashOneAssets.SOUND_INTRO_2_PING_OUT)))
.add(new EngFadeOutAction(2))
.add(new EngAddNewActorAction(badLogicAnimation))
.add(new EngRemoveActorAction());
// .add(new EngScreenSetAction("main"));
actors.add(engActorAsset);
return screenPlay;
}
public interface CompleteListener {
void completedSequence();
}
}
package com.virtual_hex.gdx.engine.scene2d.actions;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.rafaskoberg.gdx.typinglabel.TypingLabel;
import com.virtual_hex.app.AppLauncher;
import com.virtual_hex.gdx.engine.Cleanup;
import com.virtual_hex.gdx.engine.app.GdxEngScreenManagerApp;
import com.virtual_hex.gdx.engine.assets.AssetList;
import com.virtual_hex.gdx.engine.scene2d.EngUiUtils;
import com.virtual_hex.gdx.engine.screens.GdxEngAppScreen;
public class TypingLabelActorAsset extends VisualActorAsset{
public final String label;
public boolean cacheAsset = false;
public Vector2 initialPosition;
public TypingLabelActorAsset(String labelString, float startingAlpha) {
super(startingAlpha);
this.label = labelString;
}
@Override
public void addAssets(AssetList assetList) {
}
@Override
public <APP extends GdxEngScreenManagerApp> Actor build(AppLauncher<APP> appLauncher, GdxEngAppScreen<APP> appGdxEngAppScreen, Stage stage, Cleanup cleanup) {
Skin skin = appLauncher.getEngineApp().getManagers().getSkinManager().getSelectedSkin();
TypingLabel actor = new TypingLabel(this.label, skin);
actor.getColor().a = startingAlpha;
if(initialPosition != null) {
actor.setPosition(initialPosition.x, initialPosition.y);
} else {
EngUiUtils.centerActor(actor);
}
return actor;
}
@Override
public Type getType() {
return Type.LABEL;
}
}
package com.virtual_hex.gdx.engine.scene2d.actions;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.virtual_hex.app.AppLauncher;
import com.virtual_hex.gdx.engine.Cleanup;
import com.virtual_hex.gdx.engine.app.GdxEngScreenManagerApp;
import com.virtual_hex.gdx.engine.screens.GdxEngAppScreen;
public abstract class VisualActorAsset implements ActorAsset {
public float startingAlpha = 1;
public VisualActorAsset() {
}
public VisualActorAsset(float startingAlpha) {
this.startingAlpha = startingAlpha;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment