mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-02-21 20:18:14 +07:00
Added hacky entity interaction support on mobile
Added hacky entity interaction support on mobile Repurposing automap button for interact button until suitable replacement found
This commit is contained in:
parent
92c5c2e53f
commit
f55ecf6b75
@ -172,6 +172,7 @@ public class Entity {
|
||||
|
||||
// TODO: LabelStyle should be made static
|
||||
label = new Label(Diablo.fonts.font16);
|
||||
label.setUserObject(this);
|
||||
label.setAlignment(Align.center);
|
||||
label.getStyle().background = new PaletteIndexedColorDrawable(Diablo.colors.modal75) {{
|
||||
final float padding = 2;
|
||||
|
@ -122,6 +122,7 @@ public class MapRenderer {
|
||||
final Bits popped = new Bits();
|
||||
|
||||
IntMap<? extends Entity> entities;
|
||||
final Array<Entity> nearbyEntities = new Array<>();
|
||||
|
||||
public MapRenderer(PaletteIndexedBatch batch) {
|
||||
this.batch = batch;
|
||||
@ -161,6 +162,10 @@ public class MapRenderer {
|
||||
this.entities = entities;
|
||||
}
|
||||
|
||||
public Array<Entity> getNearbyEntities() {
|
||||
return nearbyEntities;
|
||||
}
|
||||
|
||||
public float zoom() {
|
||||
return camera.zoom;
|
||||
}
|
||||
@ -424,6 +429,16 @@ public class MapRenderer {
|
||||
startX2--;
|
||||
}
|
||||
}
|
||||
|
||||
nearbyEntities.size = 0;
|
||||
for (y = 0; y < viewBuffer.length; y++) {
|
||||
int size = viewBuffer[y];
|
||||
for (x = 0; x < size; x++) {
|
||||
nearbyEntities.addAll(cache[y][x][0]);
|
||||
nearbyEntities.addAll(cache[y][x][1]);
|
||||
nearbyEntities.addAll(cache[y][x][2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void buildCache(Array<Entity>[] cache, Map.Zone zone, int stx, int sty) {
|
||||
|
@ -11,6 +11,7 @@ import com.badlogic.gdx.utils.Disposable;
|
||||
|
||||
import gdx.diablo.Diablo;
|
||||
import gdx.diablo.codec.DC6;
|
||||
import gdx.diablo.entity.Entity;
|
||||
import gdx.diablo.screen.GameScreen;
|
||||
import gdx.diablo.widget.Button;
|
||||
|
||||
@ -45,7 +46,16 @@ public class MobilePanel extends Table implements Disposable {
|
||||
} else if (actor == btnParty) {
|
||||
|
||||
} else if (actor == btnMap) {
|
||||
|
||||
if (!gameScreen.labels.isEmpty()) {
|
||||
for (Actor label : gameScreen.labels) {
|
||||
Object obj = label.getUserObject();
|
||||
if (obj instanceof Entity) {
|
||||
Entity entity = (Entity) obj;
|
||||
if (entity.isSelectable()) entity.interact(gameScreen);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (actor == btnMessages) {
|
||||
gameScreen.input.setVisible(!gameScreen.input.isVisible());
|
||||
gameScreen.input.getStage().setKeyboardFocus(gameScreen.input);
|
||||
@ -105,6 +115,7 @@ public class MobilePanel extends Table implements Disposable {
|
||||
add(btnMessages).size(size);
|
||||
//add(btnQuests).size(size);
|
||||
add(btnEscapeMenu).size(size);
|
||||
add(btnMap).size(size);
|
||||
pack();
|
||||
setTouchable(Touchable.enabled);
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ import gdx.diablo.widget.TextArea;
|
||||
public class GameScreen extends ScreenAdapter implements LoadingScreen.Loadable {
|
||||
private static final String TAG = "GameScreen";
|
||||
private static final boolean DEBUG = true;
|
||||
private static final boolean DEBUG_TOUCHPAD = !true;
|
||||
private static final boolean DEBUG_TOUCHPAD = true;
|
||||
private static final boolean DEBUG_MOBILE = true;
|
||||
private static final boolean DEBUG_HIT = DEBUG && !true;
|
||||
|
||||
@ -98,7 +98,7 @@ public class GameScreen extends ScreenAdapter implements LoadingScreen.Loadable
|
||||
MapRenderer mapRenderer;
|
||||
MapListener mapListener;
|
||||
InputProcessor inputProcessorTest;
|
||||
final Array<Actor> labels = new Array<>();
|
||||
public final Array<Actor> labels = new Array<>();
|
||||
NpcMenu menu;
|
||||
NpcDialogBox dialog;
|
||||
Actor details;
|
||||
@ -430,6 +430,15 @@ public class GameScreen extends ScreenAdapter implements LoadingScreen.Loadable
|
||||
|
||||
//System.out.println("hit " + hit + "; " + collision.point + "; " + collision.normal);
|
||||
}
|
||||
|
||||
clearLabels();
|
||||
Array<Entity> nearby = mapRenderer.getNearbyEntities();
|
||||
for (Entity entity : nearby) {
|
||||
if (entity.isSelectable() && entity.position().dst(player.position()) <= entity.getInteractRange() * 2) {
|
||||
entity.over = true;
|
||||
addLabel(entity.getLabel());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
stage.screenToStageCoordinates(tmpVec2.set(Gdx.input.getX(), Gdx.input.getY()));
|
||||
Actor hit = stage.hit(tmpVec2.x, tmpVec2.y, true);
|
||||
|
Loading…
Reference in New Issue
Block a user