Basic minimap
This commit is contained in:
@@ -9,10 +9,7 @@ import io.anuke.arc.graphics.g2d.Draw;
|
||||
import io.anuke.arc.graphics.g2d.TextureAtlas;
|
||||
import io.anuke.arc.input.KeyCode;
|
||||
import io.anuke.arc.scene.ui.TextField;
|
||||
import io.anuke.arc.util.BufferUtils;
|
||||
import io.anuke.arc.util.Interval;
|
||||
import io.anuke.arc.util.Strings;
|
||||
import io.anuke.arc.util.Time;
|
||||
import io.anuke.arc.util.*;
|
||||
import io.anuke.mindustry.content.Mechs;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.entities.Effects;
|
||||
@@ -101,7 +98,7 @@ public class Control implements ApplicationListener{
|
||||
});
|
||||
|
||||
Events.on(WorldLoadEvent.class, event -> {
|
||||
Core.app.post(() -> Core.camera.position.set(player));
|
||||
Core.app.post(() -> Core.app.post(() -> Core.camera.position.set(player)));
|
||||
});
|
||||
|
||||
Events.on(ResetEvent.class, event -> {
|
||||
|
||||
@@ -67,6 +67,7 @@ public class UI implements ApplicationListener{
|
||||
public ContentInfoDialog content;
|
||||
public DeployDialog deploy;
|
||||
public TechTreeDialog tech;
|
||||
public MinimapDialog minimap;
|
||||
|
||||
public Cursor drillCursor, unloadCursor;
|
||||
|
||||
@@ -178,6 +179,7 @@ public class UI implements ApplicationListener{
|
||||
content = new ContentInfoDialog();
|
||||
deploy = new DeployDialog();
|
||||
tech = new TechTreeDialog();
|
||||
minimap = new MinimapDialog();
|
||||
|
||||
Group group = Core.scene.root;
|
||||
|
||||
|
||||
@@ -25,13 +25,13 @@ import static io.anuke.mindustry.Vars.tilesize;
|
||||
import static io.anuke.mindustry.Vars.world;
|
||||
|
||||
public class MinimapRenderer implements Disposable{
|
||||
private static final int baseSize = 16;
|
||||
private static final float baseSize = 16f;
|
||||
private final Array<Unit> units = new Array<>();
|
||||
private Pixmap pixmap;
|
||||
private Texture texture;
|
||||
private TextureRegion region;
|
||||
private Rectangle rect = new Rectangle(), scissor = new Rectangle();
|
||||
private int zoom = 4;
|
||||
private float zoom = 4;
|
||||
|
||||
public MinimapRenderer(){
|
||||
Events.on(WorldLoadEvent.class, event -> {
|
||||
@@ -49,7 +49,7 @@ public class MinimapRenderer implements Disposable{
|
||||
|
||||
public void zoomBy(float amount){
|
||||
zoom += amount;
|
||||
zoom = Mathf.clamp(zoom, 1, Math.min(world.width(), world.height()) / baseSize / 2);
|
||||
zoom = Mathf.clamp(zoom, 1f, Math.min(world.width(), world.height()) / baseSize / 2f);
|
||||
}
|
||||
|
||||
public float getZoom(){
|
||||
@@ -69,7 +69,7 @@ public class MinimapRenderer implements Disposable{
|
||||
public void drawEntities(float x, float y, float w, float h){
|
||||
updateUnitArray();
|
||||
|
||||
int sz = baseSize * zoom;
|
||||
float sz = baseSize * zoom;
|
||||
float dx = (Core.camera.position.x / tilesize);
|
||||
float dy = (Core.camera.position.y / tilesize);
|
||||
dx = Mathf.clamp(dx, sz, world.width() - sz);
|
||||
@@ -95,7 +95,7 @@ public class MinimapRenderer implements Disposable{
|
||||
public TextureRegion getRegion(){
|
||||
if(texture == null) return null;
|
||||
|
||||
int sz = Mathf.clamp(baseSize * zoom, baseSize, Math.min(world.width(), world.height()));
|
||||
float sz = Mathf.clamp(baseSize * zoom, baseSize, Math.min(world.width(), world.height()));
|
||||
float dx = (Core.camera.position.x / tilesize);
|
||||
float dy = (Core.camera.position.y / tilesize);
|
||||
dx = Mathf.clamp(dx, sz, world.width() - sz);
|
||||
@@ -124,7 +124,7 @@ public class MinimapRenderer implements Disposable{
|
||||
}
|
||||
|
||||
public void updateUnitArray(){
|
||||
int sz = baseSize * zoom;
|
||||
float sz = baseSize * zoom;
|
||||
float dx = (Core.camera.position.x / tilesize);
|
||||
float dy = (Core.camera.position.y / tilesize);
|
||||
dx = Mathf.clamp(dx, sz, world.width() - sz);
|
||||
|
||||
@@ -2,17 +2,35 @@ package io.anuke.mindustry.ui;
|
||||
|
||||
import io.anuke.arc.Core;
|
||||
import io.anuke.arc.graphics.g2d.Draw;
|
||||
import io.anuke.arc.input.KeyCode;
|
||||
import io.anuke.arc.scene.Element;
|
||||
import io.anuke.arc.scene.event.ClickListener;
|
||||
import io.anuke.arc.scene.event.InputEvent;
|
||||
import io.anuke.arc.scene.event.InputListener;
|
||||
import io.anuke.arc.scene.event.Touchable;
|
||||
import io.anuke.arc.scene.ui.layout.Container;
|
||||
import io.anuke.arc.scene.ui.layout.Unit;
|
||||
|
||||
import static io.anuke.mindustry.Vars.renderer;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class Minimap extends Container<Element>{
|
||||
|
||||
public Minimap(){
|
||||
super(new Element(){
|
||||
background("pane");
|
||||
float margin = 5f;
|
||||
touchable(Touchable.enabled);
|
||||
|
||||
addChild(new Element(){
|
||||
{
|
||||
setSize(Unit.dp.scl(140f));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void act(float delta){
|
||||
setPosition(margin, margin);
|
||||
|
||||
super.act(delta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(){
|
||||
@@ -26,10 +44,8 @@ public class Minimap extends Container<Element>{
|
||||
}
|
||||
});
|
||||
|
||||
background("pane");
|
||||
|
||||
size(140f);
|
||||
margin(5f);
|
||||
margin(margin);
|
||||
|
||||
addListener(new InputListener(){
|
||||
@Override
|
||||
@@ -37,6 +53,34 @@ public class Minimap extends Container<Element>{
|
||||
renderer.minimap.zoomBy(amounty);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean touchDown(InputEvent event, float x, float y, int pointer, KeyCode button){
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void touchDragged(InputEvent event, float x, float y, int pointer){
|
||||
if(mobile){
|
||||
renderer.minimap.zoomBy(Core.input.deltaY(pointer) / 12f / Unit.dp.scl(1f));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
addListener(new ClickListener(){
|
||||
|
||||
@Override
|
||||
public void touchUp(InputEvent event, float x, float y, int pointer, KeyCode button){
|
||||
float tapSquareSize = Unit.dp.scl(14f);
|
||||
if(Math.abs(x - touchDownX) < tapSquareSize && Math.abs(y - touchDownY) < tapSquareSize){
|
||||
super.touchUp(event, x, y, pointer, button);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clicked(InputEvent event, float x, float y){
|
||||
ui.minimap.show();
|
||||
}
|
||||
});
|
||||
|
||||
update(() -> {
|
||||
|
||||
64
core/src/io/anuke/mindustry/ui/dialogs/MinimapDialog.java
Normal file
64
core/src/io/anuke/mindustry/ui/dialogs/MinimapDialog.java
Normal file
@@ -0,0 +1,64 @@
|
||||
package io.anuke.mindustry.ui.dialogs;
|
||||
|
||||
import io.anuke.arc.Core;
|
||||
import io.anuke.arc.graphics.Color;
|
||||
import io.anuke.arc.graphics.g2d.Draw;
|
||||
import io.anuke.arc.input.KeyCode;
|
||||
import io.anuke.arc.scene.event.InputEvent;
|
||||
import io.anuke.arc.scene.event.InputListener;
|
||||
import io.anuke.arc.scene.ui.layout.Unit;
|
||||
|
||||
import static io.anuke.mindustry.Vars.mobile;
|
||||
import static io.anuke.mindustry.Vars.renderer;
|
||||
|
||||
public class MinimapDialog extends FloatingDialog{
|
||||
|
||||
public MinimapDialog(){
|
||||
super("$minimap");
|
||||
setFillParent(false);
|
||||
|
||||
shown(this::setup);
|
||||
|
||||
addCloseButton();
|
||||
shouldPause = true;
|
||||
}
|
||||
|
||||
void setup(){
|
||||
cont.clear();
|
||||
float size = Math.min(Core.graphics.getWidth(), Core.graphics.getHeight()) / Unit.dp.scl(1f) / 1.3f;
|
||||
|
||||
cont.table("pane", t -> {
|
||||
t.addRect((x, y, width, height) -> {
|
||||
if(renderer.minimap.getRegion() == null) return;
|
||||
Draw.color(Color.WHITE);
|
||||
Draw.rect(renderer.minimap.getRegion(), x + width/2f, y + height/2f, width, height);
|
||||
|
||||
if(renderer.minimap.getTexture() != null){
|
||||
renderer.minimap.drawEntities(x, y, width, height);
|
||||
}
|
||||
}).grow();
|
||||
}).size(size);
|
||||
|
||||
cont.addListener(new InputListener(){
|
||||
@Override
|
||||
public boolean scrolled(InputEvent event, float x, float y, float amountx, float amounty){
|
||||
renderer.minimap.zoomBy(amounty);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean touchDown(InputEvent event, float x, float y, int pointer, KeyCode button){
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void touchDragged(InputEvent event, float x, float y, int pointer){
|
||||
if(mobile){
|
||||
renderer.minimap.zoomBy(Core.input.deltaY(pointer) / 30f / Unit.dp.scl(1f));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Core.app.post(() -> Core.scene.setScrollFocus(cont));
|
||||
}
|
||||
}
|
||||
@@ -209,6 +209,7 @@ public class SettingsMenuDialog extends SettingsDialog{
|
||||
}
|
||||
}
|
||||
|
||||
graphics.checkPref("minimap", !mobile);
|
||||
graphics.checkPref("fps", false);
|
||||
graphics.checkPref("indicators", true);
|
||||
graphics.checkPref("animatedwater", !mobile);
|
||||
|
||||
@@ -32,6 +32,7 @@ import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.net.Packets.AdminAction;
|
||||
import io.anuke.mindustry.ui.Bar;
|
||||
import io.anuke.mindustry.ui.IntFormat;
|
||||
import io.anuke.mindustry.ui.Minimap;
|
||||
import io.anuke.mindustry.ui.dialogs.FloatingDialog;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
@@ -156,15 +157,18 @@ public class HudFragment extends Fragment{
|
||||
}).visible(() -> shown);
|
||||
});
|
||||
|
||||
//minimap
|
||||
parent.fill(t -> t.top().right().add(new Minimap()).visible(() -> !state.is(State.menu) && Core.settings.getBool("minimap")));
|
||||
|
||||
//fps display
|
||||
parent.fill(info -> {
|
||||
info.top().right().margin(4).visible(() -> Core.settings.getBool("fps") && !state.is(State.menu));
|
||||
info.bottom().left().margin(4).visible(() -> Core.settings.getBool("fps") && !state.is(State.menu));
|
||||
IntFormat fps = new IntFormat("fps");
|
||||
IntFormat ping = new IntFormat("ping");
|
||||
info.label(() -> fps.get(Core.graphics.getFramesPerSecond())).right();
|
||||
info.row();
|
||||
|
||||
info.label(() -> ping.get(Net.getPing())).visible(Net::client).right();
|
||||
info.row();
|
||||
info.label(() -> fps.get(Core.graphics.getFramesPerSecond())).right();
|
||||
});
|
||||
|
||||
//spawner warning
|
||||
|
||||
Reference in New Issue
Block a user