mirror of
https://github.com/Anuken/Mindustry.git
synced 2026-01-27 23:11:12 -08:00
Display camera on map + right-click to pan
This commit is contained in:
parent
e8fbfe536e
commit
4ae8a51676
4 changed files with 55 additions and 12 deletions
|
|
@ -99,15 +99,15 @@ public class MinimapRenderer{
|
|||
region = new TextureRegion(texture);
|
||||
}
|
||||
|
||||
public void drawEntities(float x, float y, float w, float h, float scaling, boolean withLabels){
|
||||
public void drawEntities(float x, float y, float w, float h, float scaling, boolean fullView){
|
||||
lastX = x;
|
||||
lastY = y;
|
||||
lastW = w;
|
||||
lastH = h;
|
||||
lastScl = scaling;
|
||||
worldSpace = withLabels;
|
||||
worldSpace = fullView;
|
||||
|
||||
if(!withLabels){
|
||||
if(!fullView){
|
||||
updateUnitArray();
|
||||
}else{
|
||||
units.clear();
|
||||
|
|
@ -125,8 +125,8 @@ public class MinimapRenderer{
|
|||
for(Unit unit : units){
|
||||
if(unit.inFogTo(player.team()) || !unit.type.drawMinimap) continue;
|
||||
|
||||
float rx = !withLabels ? (unit.x - rect.x) / rect.width * w : unit.x / (world.width() * tilesize) * w;
|
||||
float ry = !withLabels ? (unit.y - rect.y) / rect.width * h : unit.y / (world.height() * tilesize) * h;
|
||||
float rx = !fullView ? (unit.x - rect.x) / rect.width * w : unit.x / (world.width() * tilesize) * w;
|
||||
float ry = !fullView ? (unit.y - rect.y) / rect.width * h : unit.y / (world.height() * tilesize) * h;
|
||||
|
||||
Draw.mixcol(unit.team.color, 1f);
|
||||
float scale = Scl.scl(1f) / 2f * scaling * 32f;
|
||||
|
|
@ -135,7 +135,7 @@ public class MinimapRenderer{
|
|||
Draw.reset();
|
||||
}
|
||||
|
||||
if(withLabels && net.active()){
|
||||
if(fullView && net.active()){
|
||||
for(Player player : Groups.player){
|
||||
if(!player.dead()){
|
||||
float rx = player.x / (world.width() * tilesize) * w;
|
||||
|
|
@ -149,7 +149,7 @@ public class MinimapRenderer{
|
|||
Draw.reset();
|
||||
|
||||
if(state.rules.fog){
|
||||
if(withLabels){
|
||||
if(fullView){
|
||||
float z = zoom;
|
||||
//max zoom out fixes everything, somehow?
|
||||
setZoom(99999f);
|
||||
|
|
@ -186,12 +186,25 @@ public class MinimapRenderer{
|
|||
}
|
||||
|
||||
//TODO might be useful in the standard minimap too
|
||||
if(withLabels){
|
||||
if(fullView){
|
||||
drawSpawns(x, y, w, h, scaling);
|
||||
|
||||
if(!mobile){
|
||||
//draw bounds for camera - not drawn on mobile because you can't shift it by tapping anyway
|
||||
Rect r = Core.camera.bounds(Tmp.r1);
|
||||
Vec2 bot = transform(Tmp.v1.set(r.x, r.y));
|
||||
Vec2 top = transform(Tmp.v2.set(r.x + r.width, r.y + r.height));
|
||||
Lines.stroke(Scl.scl(3f));
|
||||
Draw.color(Pal.accent);
|
||||
Lines.rect(bot.x,bot.y, top.x - bot.x, top.y - bot.y);
|
||||
Draw.reset();
|
||||
}
|
||||
}
|
||||
|
||||
state.rules.objectives.eachRunning(obj -> {
|
||||
for(var marker : obj.markers) marker.drawMinimap(this);
|
||||
for(var marker : obj.markers){
|
||||
marker.drawMinimap(this);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -770,6 +770,12 @@ public class DesktopInput extends InputHandler{
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void panCamera(Vec2 position){
|
||||
panning = true;
|
||||
camera.position.set(position);
|
||||
}
|
||||
|
||||
protected void updateMovement(Unit unit){
|
||||
boolean omni = unit.type.omniMovement;
|
||||
|
||||
|
|
|
|||
|
|
@ -1482,6 +1482,11 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||
return World.toTile(vec.y);
|
||||
}
|
||||
|
||||
/** Forces the camera to a position and enables panning on desktop. */
|
||||
public void panCamera(Vec2 position){
|
||||
camera.position.set(position);
|
||||
}
|
||||
|
||||
public boolean selectedBlock(){
|
||||
return isPlacing();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,9 +5,11 @@ import arc.graphics.*;
|
|||
import arc.graphics.g2d.*;
|
||||
import arc.input.*;
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.scene.*;
|
||||
import arc.scene.event.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.util.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.input.*;
|
||||
import mindustry.ui.*;
|
||||
|
|
@ -20,6 +22,16 @@ public class MinimapFragment{
|
|||
private float baseSize = Scl.scl(5f);
|
||||
public Element elem;
|
||||
|
||||
protected Rect getRectBounds(){
|
||||
float
|
||||
w = Core.graphics.getWidth(),
|
||||
h = Core.graphics.getHeight(),
|
||||
ratio = renderer.minimap.getTexture() == null ? 1f : (float)renderer.minimap.getTexture().height / renderer.minimap.getTexture().width,
|
||||
size = baseSize * zoom * world.width();
|
||||
|
||||
return Tmp.r1.set(w/2f + panx*zoom - size/2f, h/2f + pany*zoom - size/2f * ratio, size, size * ratio);
|
||||
}
|
||||
|
||||
public void build(Group parent){
|
||||
elem = parent.fill((x, y, w, h) -> {
|
||||
w = Core.graphics.getWidth();
|
||||
|
|
@ -35,7 +47,8 @@ public class MinimapFragment{
|
|||
TextureRegion reg = Draw.wrap(renderer.minimap.getTexture());
|
||||
Draw.rect(reg, w/2f + panx*zoom, h/2f + pany*zoom, size, size * ratio);
|
||||
|
||||
renderer.minimap.drawEntities(w/2f + panx*zoom - size/2f, h/2f + pany*zoom - size/2f * ratio, size, size * ratio, zoom, true);
|
||||
Rect bounds = getRectBounds();
|
||||
renderer.minimap.drawEntities(bounds.x, bounds.y, bounds.width, bounds.height, zoom, true);
|
||||
}
|
||||
|
||||
Draw.reset();
|
||||
|
|
@ -69,8 +82,14 @@ public class MinimapFragment{
|
|||
|
||||
@Override
|
||||
public void pan(InputEvent event, float x, float y, float deltaX, float deltaY){
|
||||
panx += deltaX / zoom;
|
||||
pany += deltaY / zoom;
|
||||
if(event.keyCode != KeyCode.mouseRight){
|
||||
panx += deltaX / zoom;
|
||||
pany += deltaY / zoom;
|
||||
}else{
|
||||
Rect r = getRectBounds();
|
||||
Tmp.v1.set(x, y).sub(r.x, r.y).scl(1f / r.width, 1f / r.height).scl(world.unitWidth(), world.unitHeight());
|
||||
control.input.panCamera(Tmp.v1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue