Basic minimap
This commit is contained in:
@@ -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(() -> {
|
||||
|
||||
@@ -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