Improved fog of war, added minimap display
This commit is contained in:
@@ -5,6 +5,8 @@ precision mediump int;
|
|||||||
|
|
||||||
uniform sampler2D u_texture;
|
uniform sampler2D u_texture;
|
||||||
|
|
||||||
|
const float round = 0.23;
|
||||||
|
|
||||||
varying vec4 v_color;
|
varying vec4 v_color;
|
||||||
varying vec2 v_texCoord;
|
varying vec2 v_texCoord;
|
||||||
|
|
||||||
@@ -12,5 +14,6 @@ void main() {
|
|||||||
vec4 color = texture2D(u_texture, v_texCoord.xy);
|
vec4 color = texture2D(u_texture, v_texCoord.xy);
|
||||||
color.a = 1.0 - color.r;
|
color.a = 1.0 - color.r;
|
||||||
color.rgb = vec3(0.0);
|
color.rgb = vec3(0.0);
|
||||||
|
color.a = float(int(color.a / round)) * round;
|
||||||
gl_FragColor = color * v_color;
|
gl_FragColor = color * v_color;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -346,6 +346,10 @@ public class Renderer extends RendererModule{
|
|||||||
return avgPosition;
|
return avgPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public FogRenderer fog() {
|
||||||
|
return fog;
|
||||||
|
}
|
||||||
|
|
||||||
public MinimapRenderer minimap() {
|
public MinimapRenderer minimap() {
|
||||||
return minimap;
|
return minimap;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import io.anuke.ucore.entities.impl.DestructibleEntity;
|
|||||||
import io.anuke.ucore.entities.trait.DamageTrait;
|
import io.anuke.ucore.entities.trait.DamageTrait;
|
||||||
import io.anuke.ucore.entities.trait.DrawTrait;
|
import io.anuke.ucore.entities.trait.DrawTrait;
|
||||||
import io.anuke.ucore.entities.trait.SolidTrait;
|
import io.anuke.ucore.entities.trait.SolidTrait;
|
||||||
|
import io.anuke.ucore.graphics.Fill;
|
||||||
import io.anuke.ucore.util.Geometry;
|
import io.anuke.ucore.util.Geometry;
|
||||||
import io.anuke.ucore.util.Mathf;
|
import io.anuke.ucore.util.Mathf;
|
||||||
import io.anuke.ucore.util.Translator;
|
import io.anuke.ucore.util.Translator;
|
||||||
@@ -288,10 +289,18 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
|||||||
public void drawUnder(){}
|
public void drawUnder(){}
|
||||||
public void drawOver(){}
|
public void drawOver(){}
|
||||||
|
|
||||||
|
public void drawView(){
|
||||||
|
Fill.circle(x, y, getViewDistance());
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isInfiniteAmmo(){
|
public boolean isInfiniteAmmo(){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float getViewDistance(){
|
||||||
|
return 60f;
|
||||||
|
}
|
||||||
|
|
||||||
public abstract TextureRegion getIconRegion();
|
public abstract TextureRegion getIconRegion();
|
||||||
public abstract int getItemCapacity();
|
public abstract int getItemCapacity();
|
||||||
public abstract int getAmmoCapacity();
|
public abstract int getAmmoCapacity();
|
||||||
|
|||||||
@@ -2,16 +2,18 @@ package io.anuke.mindustry.graphics;
|
|||||||
|
|
||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
import com.badlogic.gdx.graphics.Pixmap.Format;
|
import com.badlogic.gdx.graphics.Pixmap.Format;
|
||||||
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
import com.badlogic.gdx.graphics.glutils.FrameBuffer;
|
import com.badlogic.gdx.graphics.glutils.FrameBuffer;
|
||||||
import com.badlogic.gdx.utils.Disposable;
|
import com.badlogic.gdx.utils.Disposable;
|
||||||
import io.anuke.mindustry.entities.Player;
|
import io.anuke.mindustry.entities.Unit;
|
||||||
import io.anuke.mindustry.game.EventType.WorldLoadGraphicsEvent;
|
import io.anuke.mindustry.game.EventType.WorldLoadGraphicsEvent;
|
||||||
import io.anuke.ucore.core.Core;
|
import io.anuke.ucore.core.Core;
|
||||||
import io.anuke.ucore.core.Events;
|
import io.anuke.ucore.core.Events;
|
||||||
import io.anuke.ucore.core.Graphics;
|
import io.anuke.ucore.core.Graphics;
|
||||||
|
import io.anuke.ucore.entities.EntityDraw;
|
||||||
|
import io.anuke.ucore.graphics.ClipSpriteBatch;
|
||||||
import io.anuke.ucore.graphics.Draw;
|
import io.anuke.ucore.graphics.Draw;
|
||||||
import io.anuke.ucore.graphics.Fill;
|
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.*;
|
import static io.anuke.mindustry.Vars.*;
|
||||||
|
|
||||||
@@ -47,15 +49,22 @@ public class FogRenderer implements Disposable{
|
|||||||
float u2 = (px + vw)/ tilesize / world.width();
|
float u2 = (px + vw)/ tilesize / world.width();
|
||||||
float v2 = (py + vh)/ tilesize / world.height();
|
float v2 = (py + vh)/ tilesize / world.height();
|
||||||
|
|
||||||
|
if(Core.batch instanceof ClipSpriteBatch){
|
||||||
|
((ClipSpriteBatch) Core.batch).enableClip(false);
|
||||||
|
}
|
||||||
|
|
||||||
Core.batch.getProjectionMatrix().setToOrtho2D(0, 0, world.width() * tilesize, world.height() * tilesize);
|
Core.batch.getProjectionMatrix().setToOrtho2D(0, 0, world.width() * tilesize, world.height() * tilesize);
|
||||||
|
|
||||||
Draw.color(Color.WHITE);
|
Draw.color(Color.WHITE);
|
||||||
|
|
||||||
buffer.begin();
|
buffer.begin();
|
||||||
Graphics.begin();
|
Graphics.begin();
|
||||||
for(Player player : playerGroup.all()){
|
EntityDraw.setClip(false);
|
||||||
Fill.circle(player.x, player.y, 60f);
|
|
||||||
}
|
renderer.drawAndInterpolate(playerGroup, player -> player.getTeam() == players[0].getTeam(), Unit::drawView);
|
||||||
|
renderer.drawAndInterpolate(unitGroups[players[0].getTeam().ordinal()], unit -> true, Unit::drawView);
|
||||||
|
|
||||||
|
EntityDraw.setClip(true);
|
||||||
Graphics.end();
|
Graphics.end();
|
||||||
buffer.end();
|
buffer.end();
|
||||||
|
|
||||||
@@ -65,13 +74,29 @@ public class FogRenderer implements Disposable{
|
|||||||
|
|
||||||
Core.batch.setProjectionMatrix(Core.camera.combined);
|
Core.batch.setProjectionMatrix(Core.camera.combined);
|
||||||
Graphics.shader(Shaders.fog);
|
Graphics.shader(Shaders.fog);
|
||||||
|
renderer.pixelSurface.getBuffer().begin();
|
||||||
Graphics.begin();
|
Graphics.begin();
|
||||||
|
|
||||||
// Core.batch.draw(buffer.getColorBufferTexture(), px + 50, py, 200, 200 * world.height()/(float)world.width());
|
// Core.batch.draw(buffer.getColorBufferTexture(), px + 50, py, 200, 200 * world.height()/(float)world.width());
|
||||||
Core.batch.draw(region, px, py, vw, vh);
|
Core.batch.draw(region, px, py, vw, vh);
|
||||||
|
|
||||||
Graphics.end();
|
Graphics.end();
|
||||||
|
renderer.pixelSurface.getBuffer().end();
|
||||||
Graphics.shader();
|
Graphics.shader();
|
||||||
|
|
||||||
|
Graphics.begin();
|
||||||
|
|
||||||
|
Core.batch.draw(renderer.pixelSurface.texture(), px, py + vh, vw, -vh);
|
||||||
|
Graphics.end();
|
||||||
|
|
||||||
|
if(Core.batch instanceof ClipSpriteBatch){
|
||||||
|
((ClipSpriteBatch) Core.batch).enableClip(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Texture getTexture(){
|
||||||
|
return buffer.getColorBufferTexture();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
73
core/src/io/anuke/mindustry/ui/Minimap.java
Normal file
73
core/src/io/anuke/mindustry/ui/Minimap.java
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
package io.anuke.mindustry.ui;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.graphics.Texture.TextureFilter;
|
||||||
|
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||||
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
|
import io.anuke.mindustry.graphics.Shaders;
|
||||||
|
import io.anuke.ucore.core.Core;
|
||||||
|
import io.anuke.ucore.core.Graphics;
|
||||||
|
import io.anuke.ucore.scene.Element;
|
||||||
|
import io.anuke.ucore.scene.event.InputEvent;
|
||||||
|
import io.anuke.ucore.scene.event.InputListener;
|
||||||
|
import io.anuke.ucore.scene.style.TextureRegionDrawable;
|
||||||
|
import io.anuke.ucore.scene.ui.Image;
|
||||||
|
import io.anuke.ucore.scene.ui.layout.Table;
|
||||||
|
|
||||||
|
import static io.anuke.mindustry.Vars.renderer;
|
||||||
|
|
||||||
|
public class Minimap extends Table {
|
||||||
|
|
||||||
|
public Minimap(){
|
||||||
|
super("button");
|
||||||
|
|
||||||
|
margin(5);
|
||||||
|
marginBottom(10);
|
||||||
|
|
||||||
|
Image image = new Image(new TextureRegionDrawable(new TextureRegion())){
|
||||||
|
@Override
|
||||||
|
public void draw(Batch batch, float parentAlpha) {
|
||||||
|
TextureRegionDrawable draw = (TextureRegionDrawable)getDrawable();
|
||||||
|
draw.getRegion().setRegion(renderer.minimap().getRegion());
|
||||||
|
super.draw(batch, parentAlpha);
|
||||||
|
if(renderer.minimap().getTexture() != null){
|
||||||
|
renderer.minimap().drawEntities(x, y, width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
renderer.fog().getTexture().setFilter(TextureFilter.Nearest, TextureFilter.Nearest);
|
||||||
|
|
||||||
|
//draw.getRegion().setV(draw.getRegion().getV2());
|
||||||
|
//draw.getRegion().setV2(v);
|
||||||
|
draw.getRegion().setTexture(renderer.fog().getTexture());
|
||||||
|
draw.getRegion().setV(1f - draw.getRegion().getV());
|
||||||
|
draw.getRegion().setV2(1f - draw.getRegion().getV2());
|
||||||
|
|
||||||
|
|
||||||
|
Graphics.shader(Shaders.fog);
|
||||||
|
super.draw(batch, parentAlpha);
|
||||||
|
Graphics.shader();
|
||||||
|
|
||||||
|
renderer.fog().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
addListener(new InputListener(){
|
||||||
|
public boolean scrolled (InputEvent event, float x, float y, int amount) {
|
||||||
|
renderer.minimap().zoomBy(amount);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
image.update(() -> {
|
||||||
|
|
||||||
|
Element e = Core.scene.hit(Graphics.mouse().x, Graphics.mouse().y, true);
|
||||||
|
if(e != null && e.isDescendantOf(this)){
|
||||||
|
Core.scene.setScrollFocus(this);
|
||||||
|
}else if(Core.scene.getScrollFocus() == this){
|
||||||
|
Core.scene.setScrollFocus(null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
add(image).size(140f, 140f);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,7 +2,6 @@ package io.anuke.mindustry.ui.fragments;
|
|||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
import com.badlogic.gdx.math.Interpolation;
|
import com.badlogic.gdx.math.Interpolation;
|
||||||
import com.badlogic.gdx.utils.Array;
|
import com.badlogic.gdx.utils.Array;
|
||||||
@@ -10,21 +9,17 @@ import com.badlogic.gdx.utils.Scaling;
|
|||||||
import io.anuke.mindustry.core.GameState.State;
|
import io.anuke.mindustry.core.GameState.State;
|
||||||
import io.anuke.mindustry.net.Net;
|
import io.anuke.mindustry.net.Net;
|
||||||
import io.anuke.mindustry.type.Recipe;
|
import io.anuke.mindustry.type.Recipe;
|
||||||
|
import io.anuke.mindustry.ui.Minimap;
|
||||||
import io.anuke.ucore.core.Core;
|
import io.anuke.ucore.core.Core;
|
||||||
import io.anuke.ucore.core.Graphics;
|
|
||||||
import io.anuke.ucore.core.Inputs;
|
import io.anuke.ucore.core.Inputs;
|
||||||
import io.anuke.ucore.core.Settings;
|
import io.anuke.ucore.core.Settings;
|
||||||
import io.anuke.ucore.graphics.Draw;
|
|
||||||
import io.anuke.ucore.scene.Element;
|
import io.anuke.ucore.scene.Element;
|
||||||
import io.anuke.ucore.scene.Group;
|
import io.anuke.ucore.scene.Group;
|
||||||
import io.anuke.ucore.scene.actions.Actions;
|
import io.anuke.ucore.scene.actions.Actions;
|
||||||
import io.anuke.ucore.scene.builders.imagebutton;
|
import io.anuke.ucore.scene.builders.imagebutton;
|
||||||
import io.anuke.ucore.scene.builders.label;
|
import io.anuke.ucore.scene.builders.label;
|
||||||
import io.anuke.ucore.scene.builders.table;
|
import io.anuke.ucore.scene.builders.table;
|
||||||
import io.anuke.ucore.scene.event.InputEvent;
|
|
||||||
import io.anuke.ucore.scene.event.InputListener;
|
|
||||||
import io.anuke.ucore.scene.event.Touchable;
|
import io.anuke.ucore.scene.event.Touchable;
|
||||||
import io.anuke.ucore.scene.style.TextureRegionDrawable;
|
|
||||||
import io.anuke.ucore.scene.ui.Image;
|
import io.anuke.ucore.scene.ui.Image;
|
||||||
import io.anuke.ucore.scene.ui.ImageButton;
|
import io.anuke.ucore.scene.ui.ImageButton;
|
||||||
import io.anuke.ucore.scene.ui.Label;
|
import io.anuke.ucore.scene.ui.Label;
|
||||||
@@ -132,44 +127,9 @@ public class HudFragment implements Fragment{
|
|||||||
atop();
|
atop();
|
||||||
aright();
|
aright();
|
||||||
|
|
||||||
new table("button"){{
|
Minimap minimap = new Minimap();
|
||||||
Table table = get();
|
|
||||||
margin(5);
|
|
||||||
marginBottom(10);
|
|
||||||
TextureRegionDrawable draw = new TextureRegionDrawable(new TextureRegion());
|
|
||||||
Image image = new Image(){
|
|
||||||
@Override
|
|
||||||
public void draw(Batch batch, float parentAlpha) {
|
|
||||||
super.draw(batch, parentAlpha);
|
|
||||||
if(renderer.minimap().getTexture() != null){
|
|
||||||
renderer.minimap().drawEntities(x, y, width, height);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
image.setDrawable(draw);
|
|
||||||
table.addListener(new InputListener(){
|
|
||||||
public boolean scrolled (InputEvent event, float x, float y, int amount) {
|
|
||||||
renderer.minimap().zoomBy(amount);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
image.update(() -> {
|
|
||||||
|
|
||||||
Element e = Core.scene.hit(Graphics.mouse().x, Graphics.mouse().y, true);
|
add(minimap);
|
||||||
if(e != null && e.isDescendantOf(table)){
|
|
||||||
Core.scene.setScrollFocus(table);
|
|
||||||
}else if(Core.scene.getScrollFocus() == table){
|
|
||||||
Core.scene.setScrollFocus(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (renderer.minimap().getTexture() == null) {
|
|
||||||
draw.getRegion().setRegion(Draw.region("white"));
|
|
||||||
} else {
|
|
||||||
draw.getRegion().setRegion(renderer.minimap().getRegion());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
add(image).size(140f, 140f);
|
|
||||||
}}.end();
|
|
||||||
}}.end();
|
}}.end();
|
||||||
|
|
||||||
//paused table
|
//paused table
|
||||||
|
|||||||
Reference in New Issue
Block a user