1
0
mirror of https://github.com/Anuken/Mindustry.git synced 2024-09-23 06:18:00 +03:00

New menu background, unfinished

This commit is contained in:
Anuken 2019-07-02 14:42:24 -04:00
parent cb7b6eb3f8
commit 217237b57e
6 changed files with 91 additions and 32 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 143 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 154 B

View File

@ -138,6 +138,16 @@
over: flat-over,
disabled: flat,
disabledFontColor: gray
},
clear-toggle-menu: {
font: default-font,
fontColor: white,
checked: flat-down,
down: flat-down,
up: clear,
over: flat-over,
disabled: flat,
disabledFontColor: gray
}
toggle: {
font: default-font,

View File

@ -1,43 +1,74 @@
package io.anuke.mindustry.graphics;
import io.anuke.arc.Core;
import io.anuke.arc.graphics.Camera;
import io.anuke.arc.graphics.Color;
import io.anuke.arc.graphics.*;
import io.anuke.arc.graphics.g2d.*;
import io.anuke.arc.graphics.glutils.FrameBuffer;
import io.anuke.arc.math.Mathf;
import io.anuke.arc.util.Disposable;
import io.anuke.arc.math.Matrix3;
import io.anuke.arc.util.*;
import io.anuke.arc.util.noise.Simplex;
import io.anuke.mindustry.content.Blocks;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.*;
import io.anuke.mindustry.world.blocks.Floor;
import static io.anuke.mindustry.Vars.tilesize;
import static io.anuke.mindustry.Vars.world;
import static io.anuke.mindustry.Vars.*;
public class MenuRenderer implements Disposable{
private static final int width = 30, height = 30;
private static final int width = 100, height = 50;
private static final float darkness = 0.1f;
private int cacheFloor, cacheWall;
private Camera camera = new Camera();
private Matrix3 mat = new Matrix3();
private FrameBuffer shadows;
private CacheBatch batch;
public MenuRenderer(){
Time.mark();
generate();
cache();
Log.info("Time to generate menu: {0}", Time.elapsed());
}
private void generate(){
Tile[][] tiles = world.createTiles(width, height);
shadows = new FrameBuffer(width, height);
Simplex s1 = new Simplex(0);
Simplex s2 = new Simplex(1);
Simplex s3 = new Simplex(2);
for(int x = 0; x < width; x++){
for(int y = 0; y < height; y++){
Block floor = Blocks.metalFloor;
Block ore = Blocks.oreCopper;
Block wall = Mathf.chance(0.5) ? Blocks.air : Blocks.darkMetal;
Block floor = Blocks.shale;
Block ore = Blocks.air;
Block wall = Blocks.air;
tiles[x][y] = new Tile(x, y, floor.id, ore.id, wall.id);
if(s1.octaveNoise2D(3, 0.5, 1/10.0, x, y) > 0.5){
wall = Blocks.shaleRocks;
}
if(s3.octaveNoise2D(3, 0.5, 1/10.0, x, y) > 0.5){
floor = Blocks.stone;
if(wall != Blocks.air){
wall = Blocks.rocks;
}
}
if(s2.octaveNoise2D(3, 0.3, 1/30.0, x, y) > 0.5){
ore = Blocks.oreCopper;
}
if(s2.octaveNoise2D(3, 0.3, 1/15.0, x, y+999999) > 0.7){
ore = Blocks.oreLead;
}
Tile tile;
tiles[x][y] = (tile = new CachedTile());
tile.x = (short)x;
tile.y = (short)y;
tile.setFloor((Floor) floor);
tile.setBlock(wall);
tile.setOverlay(ore);
}
}
}
@ -47,6 +78,7 @@ public class MenuRenderer implements Disposable{
//draw shadows
Draw.proj().setOrtho(0, 0, shadows.getWidth(), shadows.getHeight());
shadows.beginDraw(Color.CLEAR);
Draw.color(Color.BLACK);
for(int x = 0; x < width; x++){
for(int y = 0; y < height; y++){
if(world.rawTile(x, y).block() != Blocks.air){
@ -54,13 +86,13 @@ public class MenuRenderer implements Disposable{
}
}
}
Draw.color();
shadows.endDraw();
batch = new CacheBatch(new SpriteCache(width * height * 5, true));
batch.beginCache();
SpriteBatch prev = Core.batch;
Core.batch = batch;
Core.batch = batch = new CacheBatch(new SpriteCache(width * height * 6, false));
batch.beginCache();
for(int x = 0; x < width; x++){
for(int y = 0; y < height; y++){
@ -90,25 +122,38 @@ public class MenuRenderer implements Disposable{
}
}
//Draw.rect("error", world.width() * tilesize/2f, world.height() * tilesize/2f, 100f, 100f);
cacheWall = batch.endCache();
Core.batch = prev;
}
public void render(){
camera.position.set(Core.graphics.getWidth()/2f, Core.graphics.getHeight()/2f);
camera.resize(Core.graphics.getWidth(), Core.graphics.getHeight());
float scaling = 4f;
camera.position.set(width * tilesize/2f, height * tilesize/2f);
camera.resize(Core.graphics.getWidth() / scaling,
Core.graphics.getHeight() /scaling);
mat.set(Draw.proj());
Draw.flush();
Draw.proj(camera.projection());
batch.setProjection(camera.projection());
batch.beginDraw();
batch.drawCache(cacheFloor);
batch.endDraw();
Draw.rect(Draw.wrap(shadows.getTexture()), width * tilesize/2f, height * tilesize/2f, width * tilesize, height * tilesize);
Draw.rect(Draw.wrap(shadows.getTexture()),
width * tilesize/2f - 4f, height * tilesize/2f - 4f,
width * tilesize, -height * tilesize);
Draw.flush();
batch.beginDraw();
batch.drawCache(cacheWall);
batch.endDraw();
Draw.proj(mat);
Draw.color(0f, 0f, 0f, darkness);
Fill.crect(0, 0, Core.graphics.getWidth(), Core.graphics.getHeight());
Draw.color();
}
@Override

View File

@ -4,7 +4,7 @@ import io.anuke.arc.Core;
import io.anuke.arc.Events;
import io.anuke.arc.graphics.Texture;
import io.anuke.arc.graphics.g2d.Draw;
import io.anuke.arc.scene.Group;
import io.anuke.arc.scene.*;
import io.anuke.arc.scene.event.Touchable;
import io.anuke.arc.scene.ui.Button;
import io.anuke.arc.scene.ui.layout.Table;
@ -24,10 +24,11 @@ public class MenuFragment extends Fragment{
private Texture logo = new Texture("sprites/logo.png");
private Table container, submenu;
private Button currentMenu;
private MenuRenderer renderer = new MenuRenderer();
private MenuRenderer renderer;
@Override
public void build(Group parent){
renderer = new MenuRenderer();
Core.scene.table().addRect((a, b, w, h) -> {
renderer.render();
@ -39,6 +40,7 @@ public class MenuFragment extends Fragment{
if(!mobile){
buildDesktop();
Events.on(ResizeEvent.class, event -> buildDesktop());
}else{
buildMobile();
Events.on(ResizeEvent.class, event -> buildMobile());
@ -67,11 +69,11 @@ public class MenuFragment extends Fragment{
boolean portrait = Core.graphics.getWidth() < Core.graphics.getHeight();
float logoscl = (int)Unit.dp.scl(1);
float logow = Math.min(logo.getWidth() * logoscl, 768);
float logow = Math.min(Math.min(logo.getWidth() * logoscl, 768), Core.graphics.getWidth() - 10);
float logoh = logow * (float)logo.getHeight() / logo.getWidth();
Draw.color();
Draw.rect(Draw.wrap(logo), (int)(w / 2), (int)(h - 10 - logoh - Unit.dp.scl(portrait ? 30f : 0)) + logoh / 2, logow, logoh);
Draw.rect(Draw.wrap(logo), (int)(w / 2), (int)(h - 10 - logoh) + logoh / 2, logow, logoh);
}).visible(() -> state.is(State.menu)).grow().get().touchable(Touchable.disabled);
}
@ -130,10 +132,15 @@ public class MenuFragment extends Fragment{
}
private void buildDesktop(){
container.clear();
container.setSize(Core.graphics.getWidth(), Core.graphics.getHeight());
float width = 230f;
String background = "dialogDim";
String background = "flat";
container.left();
container.add().width(Core.graphics.getWidth()/10f);
container.table(background, t -> {
t.defaults().width(width).height(70f);
@ -208,7 +215,7 @@ public class MenuFragment extends Fragment{
private void buttons(Table t, Buttoni... buttons){
for(Buttoni b : buttons){
Button[] out = {null};
out[0] = t.addImageTextButton(b.text, b.icon + "-small", "clear-toggle",
out[0] = t.addImageTextButton(b.text, b.icon + "-small", "clear-toggle-menu",
iconsizesmall, () -> {
if(currentMenu == out[0]){
currentMenu = null;

View File

@ -1,15 +1,12 @@
package io.anuke.mindustry.world.blocks;
import io.anuke.arc.Core;
import io.anuke.arc.graphics.g2d.Draw;
import io.anuke.arc.graphics.g2d.TextureRegion;
import io.anuke.arc.graphics.g2d.*;
import io.anuke.arc.math.Mathf;
import io.anuke.mindustry.graphics.CacheLayer;
import io.anuke.mindustry.world.Pos;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.*;
import static io.anuke.mindustry.Vars.tilesize;
import static io.anuke.mindustry.Vars.world;
import static io.anuke.mindustry.Vars.*;
public class StaticWall extends Rock{
TextureRegion large;