use of com.bladecoder.engine.model.SpriteActor in project bladecoder-adventure-engine by bladecoder.
the class ScnWidget method draw.
@Override
public void draw(Batch batch, float parentAlpha) {
validate();
Color tmp = batch.getColor();
batch.setColor(Color.WHITE);
if (scn != null && !loading && !loadingError) {
// BACKGROUND
batch.disableBlending();
tile.draw(batch, getX(), getY(), getWidth(), getHeight());
batch.enableBlending();
Vector3 v = new Vector3(getX(), getY(), 0);
v = v.prj(batch.getTransformMatrix());
batch.end();
HdpiUtils.glViewport((int) v.x, (int) v.y, (int) getWidth(), (int) (getHeight()));
getStage().calculateScissors(bounds, scissors);
if (ScissorStack.pushScissors(scissors)) {
// WORLD CAMERA
sceneBatch.setProjectionMatrix(camera.combined);
sceneBatch.begin();
Array<AtlasRegion> scnBackground = scn.getBackground();
if (scnBackground != null) {
sceneBatch.disableBlending();
float x = 0;
for (AtlasRegion tile : scnBackground) {
sceneBatch.draw(tile, x, 0f);
x += tile.getRegionWidth();
}
sceneBatch.enableBlending();
}
// draw layers from bottom to top
List<SceneLayer> layers = scn.getLayers();
for (int i = layers.size() - 1; i >= 0; i--) {
SceneLayer layer = layers.get(i);
if (!layer.isVisible())
continue;
List<InteractiveActor> actors = layer.getActors();
for (InteractiveActor a : actors) {
if (a instanceof SpriteActor) {
boolean visibility = a.isVisible();
a.setVisible(true);
((SpriteActor) a).draw(sceneBatch);
a.setVisible(visibility);
}
}
}
sceneBatch.end();
ScissorStack.popScissors();
}
drawer.drawBGBounds();
if (showWalkZone && scn.getPolygonalNavGraph() != null) {
drawer.drawBBoxWalkZone(scn, false);
drawer.drawPolygonVertices(scn.getPolygonalNavGraph().getWalkZone(), Color.GREEN);
}
drawer.drawBBoxActors(scn);
if (selectedActor != null) {
drawer.drawSelectedActor(selectedActor);
}
getStage().getViewport().apply();
// SCREEN CAMERA
batch.begin();
drawFakeDepthMarkers((SpriteBatch) batch);
if (!inScene) {
faRenderer.draw((SpriteBatch) batch);
}
// DRAW COORDS
Vector2 coords = new Vector2(Gdx.input.getX(), Gdx.input.getY());
screenToWorldCoords(coords);
String str = MessageFormat.format("({0}, {1})", (int) coords.x, (int) coords.y);
textLayout.setText(defaultFont, str);
RectangleRenderer.draw((SpriteBatch) batch, 0f, getY() + getHeight() - textLayout.height - 15, textLayout.width + 10, textLayout.height + 10, BLACK_TRANSPARENT);
defaultFont.draw(batch, textLayout, 5, getHeight() + getY() - 10);
batch.setColor(tmp);
} else {
background.draw(batch, getX(), getY(), getWidth(), getHeight());
String s;
if (loading) {
s = "LOADING...";
Timer.post(new Task() {
@Override
public void run() {
loading = false;
try {
EngineAssetManager.getInstance().finishLoading();
scn.retrieveAssets();
// disable Spine events
for (BaseActor a : scn.getActors().values()) {
if (a instanceof SpriteActor && ((SpriteActor) a).getRenderer() instanceof SpineRenderer) {
((SpineRenderer) ((SpriteActor) a).getRenderer()).enableEvents(false);
}
}
drawer.setCamera(camera);
invalidate();
} catch (Exception e) {
Message.showMsg(getStage(), "Could not load assets for scene", 4);
EditorLogger.printStackTrace(e);
loadingError = true;
loading = false;
}
}
});
} else if (loadingError) {
s = "ERROR IN SCENE DATA. CANNOT DISPLAY SCENE";
} else if (Ctx.project.getProjectDir() == null) {
s = "CREATE OR LOAD A PROJECT";
} else {
s = "THERE ARE NO SCENES IN THIS CHAPTER YET";
}
textLayout.setText(bigFont, s);
bigFont.draw(batch, textLayout, (getWidth() - textLayout.width) / 2, getHeight() / 2 + bigFont.getLineHeight() * 3);
}
}
use of com.bladecoder.engine.model.SpriteActor in project bladecoder-adventure-engine by bladecoder.
the class ScnWidgetInputListener method touchDown.
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
super.touchDown(event, x, y, pointer, button);
// EditorLogger.debug("Touch Down - X: " + x + " Y: " + y);
Scene scn = scnWidget.getScene();
if (scn == null)
return false;
Vector2 p = new Vector2(Gdx.input.getX(), Gdx.input.getY());
scnWidget.screenToWorldCoords(p);
org.set(p);
if (button == Buttons.LEFT) {
selActor = scnWidget.getSelectedActor();
if (scn.getPolygonalNavGraph() != null && scnWidget.getShowWalkZone()) {
// Check
// WALKZONE
// CHECK WALKZONE VERTEXS
Polygon wzPoly = scn.getPolygonalNavGraph().getWalkZone();
float[] verts = wzPoly.getTransformedVertices();
for (int i = 0; i < verts.length; i += 2) {
if (p.dst(verts[i], verts[i + 1]) < CanvasDrawer.CORNER_DIST) {
draggingMode = DraggingModes.DRAGGING_WALKZONE_POINT;
vertIndex = i;
float[] v = wzPoly.getVertices();
undoOrg.set(v[i], v[i + 1]);
return true;
}
}
// CHECK FOR WALKZONE DRAGGING
if (wzPoly.contains(p.x, p.y)) {
draggingMode = DraggingModes.DRAGGING_WALKZONE;
undoOrg.set(wzPoly.getX(), wzPoly.getY());
return true;
}
}
// SELACTOR ORIGIN DRAGGING
if (selActor != null && selActor instanceof InteractiveActor) {
Vector2 refPoint = ((InteractiveActor) selActor).getRefPoint();
float orgX = selActor.getX() + refPoint.x;
float orgY = selActor.getY() + refPoint.y;
float dst = Vector2.dst(p.x, p.y, orgX, orgY);
if (dst < Scene.ANCHOR_RADIUS) {
draggingMode = DraggingModes.DRAGGING_REFPOINT;
undoOrg.set(refPoint.x, refPoint.y);
return true;
}
}
// SELACTOR VERTEXs DRAGGING
if (selActor != null && (!(selActor instanceof SpriteActor) || !((SpriteActor) selActor).isBboxFromRenderer()) && !(scnWidget.getSelectedActor() instanceof AnchorActor)) {
Polygon bbox = selActor.getBBox();
float[] verts = bbox.getTransformedVertices();
for (int i = 0; i < verts.length; i += 2) {
if (p.dst(verts[i], verts[i + 1]) < CanvasDrawer.CORNER_DIST) {
draggingMode = DraggingModes.DRAGGING_BBOX_POINT;
vertIndex = i;
float[] v = bbox.getVertices();
undoOrg.set(v[i], v[i + 1]);
return true;
}
}
}
// CHECK FOR ACTORS
BaseActor a = scn.getActorAt(p.x, p.y);
if (a != null && a != selActor) {
selActor = a;
BaseActor da = Ctx.project.getActor(selActor.getId());
Ctx.project.setSelectedActor(da);
return true;
}
if (a != null) {
draggingMode = DraggingModes.DRAGGING_ACTOR;
undoOrg.set(selActor.getX(), selActor.getY());
return true;
}
// CHECK FOR DRAGGING DEPTH MARKERS
Vector2 depthVector = scnWidget.getScene().getDepthVector();
if (depthVector != null) {
p.set(0, depthVector.x);
scnWidget.worldToScreenCoords(p);
if (Vector2.dst(p.x - 40, p.y, x, y) < 50) {
draggingMode = DraggingModes.DRAGGING_MARKER_0;
Vector2 dv = scnWidget.getScene().getDepthVector();
undoOrg.set(dv.x, dv.y);
return true;
}
p.set(0, depthVector.y);
scnWidget.worldToScreenCoords(p);
if (Vector2.dst(p.x - 40, p.y, x, y) < 50) {
draggingMode = DraggingModes.DRAGGING_MARKER_100;
Vector2 dv = scnWidget.getScene().getDepthVector();
undoOrg.set(dv.x, dv.y);
return true;
}
}
}
return true;
}
use of com.bladecoder.engine.model.SpriteActor in project bladecoder-adventure-engine by bladecoder.
the class ScnWidgetInputListener method clicked.
@Override
public void clicked(InputEvent event, float x, float y) {
Scene scn = scnWidget.getScene();
if (scn == null)
return;
Vector2 p = new Vector2(Gdx.input.getX(), Gdx.input.getY());
scnWidget.screenToWorldCoords(p);
// DOUBLE CLICK TO CREATE OR DELETE POINTS
if (getTapCount() == 2) {
// Check WALKZONE
if (scn.getPolygonalNavGraph() != null && scnWidget.getShowWalkZone()) {
Polygon poly = scn.getPolygonalNavGraph().getWalkZone();
if (UIUtils.ctrl()) {
// Delete the point if selected
boolean deleted = PolygonUtils.deletePoint(poly, p.x, p.y, CanvasDrawer.CORNER_DIST);
if (deleted) {
Ctx.project.setModified();
return;
}
} else {
boolean created = PolygonUtils.addClampPointIfTolerance(poly, p.x, p.y, CanvasDrawer.CORNER_DIST);
if (created) {
Ctx.project.setModified();
return;
}
}
}
if (scnWidget.getSelectedActor() != null) {
Polygon poly = scnWidget.getSelectedActor().getBBox();
if ((!(scnWidget.getSelectedActor() instanceof SpriteActor) || !((SpriteActor) scnWidget.getSelectedActor()).isBboxFromRenderer()) && !(scnWidget.getSelectedActor() instanceof AnchorActor)) {
if (UIUtils.ctrl()) {
// Delete the point if selected
boolean deleted = PolygonUtils.deletePoint(poly, p.x, p.y, CanvasDrawer.CORNER_DIST);
if (deleted) {
Ctx.project.setModified();
return;
}
} else {
boolean created = PolygonUtils.addClampPointIfTolerance(poly, p.x, p.y, CanvasDrawer.CORNER_DIST);
if (created) {
Ctx.project.setModified();
return;
}
}
}
}
}
}
use of com.bladecoder.engine.model.SpriteActor in project bladecoder-adventure-engine by bladecoder.
the class CheckInteractionVerbs method visit.
@Override
public void visit(BaseActor a) {
if (a instanceof InteractiveActor) {
ia = (InteractiveActor) a;
hasLookat = false;
hasPickup = false;
hasTalkto = false;
hasLeave = false;
hasEnterExit = false;
hasUse = false;
if (ia.getInteraction()) {
HashMap<String, Verb> verbs = ia.getVerbManager().getVerbs();
for (Verb v : verbs.values()) checkVerb(v);
if (hasLeave || hasEnterExit)
return;
// discard inventory actors
if (hasLookat) {
if (ia instanceof SpriteActor) {
SpriteActor sa = (SpriteActor) ia;
if (sa.getRenderer() instanceof AtlasRenderer) {
AtlasRenderer r = (AtlasRenderer) sa.getRenderer();
HashMap<String, AnimationDesc> animations = r.getAnimations();
if (animations.size() == 0) {
EditorLogger.error("CheckInteractionVerbs: Actor with no animations! - " + sa.getScene().getId() + "." + sa.getId());
}
if (animations.get(r.getInitAnimation()).source.contains("inventory")) {
if (!hasUse)
EditorLogger.msg("CheckInteractionVerbs: Inventory item should has default 'use' - " + sa.getScene().getId() + "." + sa.getId());
return;
}
}
}
}
// check for lookat and pickup/talk verbs
if (!hasLookat || (!hasPickup && !hasTalkto)) {
String msg = "CheckInteractionVerbs: " + a.getScene().getId() + "." + a.getId();
if (!hasLookat)
EditorLogger.error(msg);
else
EditorLogger.msg(msg);
}
}
}
}
use of com.bladecoder.engine.model.SpriteActor in project bladecoder-adventure-engine by bladecoder.
the class SceneActorInputPanel method getActorValues.
private String[] getActorValues(Scene scn) {
Map<String, BaseActor> actors = scn.getActors();
ArrayList<BaseActor> filteredActors = new ArrayList<BaseActor>();
for (BaseActor a : actors.values()) {
if (type == Param.Type.SCENE_CHARACTER_ACTOR) {
if (a instanceof CharacterActor)
filteredActors.add(a);
} else if (type == Param.Type.SCENE_INTERACTIVE_ACTOR) {
if (a instanceof InteractiveActor)
filteredActors.add(a);
} else if (type == Param.Type.SCENE_SPRITE_ACTOR) {
if (a instanceof SpriteActor)
filteredActors.add(a);
} else {
filteredActors.add(a);
}
}
String[] result = new String[isMandatory() ? filteredActors.size() + 1 : filteredActors.size() + 2];
// Add player variable to the list
result[0] = Scene.VAR_PLAYER;
if (!isMandatory())
result[filteredActors.size() + 1] = "";
for (int i = 0; i < filteredActors.size(); i++) {
result[i + 1] = filteredActors.get(i).getId();
}
Arrays.sort(result);
return result;
}
Aggregations