From 217237b57e8435d24bdc2945483d9b25adcdfec3 Mon Sep 17 00:00:00 2001 From: Anuken Date: Tue, 2 Jul 2019 14:42:24 -0400 Subject: [PATCH] New menu background, unfinished --- core/assets-raw/sprites/ui/empty-sector.png | Bin 143 -> 0 bytes core/assets-raw/sprites/ui/sector-select.png | Bin 154 -> 0 bytes core/assets/sprites/uiskin.json | 10 +++ .../mindustry/graphics/MenuRenderer.java | 85 +++++++++++++----- .../mindustry/ui/fragments/MenuFragment.java | 19 ++-- .../mindustry/world/blocks/StaticWall.java | 9 +- 6 files changed, 91 insertions(+), 32 deletions(-) delete mode 100644 core/assets-raw/sprites/ui/empty-sector.png delete mode 100644 core/assets-raw/sprites/ui/sector-select.png diff --git a/core/assets-raw/sprites/ui/empty-sector.png b/core/assets-raw/sprites/ui/empty-sector.png deleted file mode 100644 index a0bad794cd86732974c40aaea8b6e94b750d2a61..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 143 zcmeAS@N?(olHy`uVBq!ia0y~yU{C;I4mJh`hT^KKFANL}VV*9IAr-fh1%!lt*-x0k z=(MNEop5REYFgC0t=#%qLNLUK=z((obI<W^-q@DC+?gOSpTLKB=70!=d#Wzp$P!XGB&LM diff --git a/core/assets/sprites/uiskin.json b/core/assets/sprites/uiskin.json index 3931878115..69b04bd22b 100644 --- a/core/assets/sprites/uiskin.json +++ b/core/assets/sprites/uiskin.json @@ -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, diff --git a/core/src/io/anuke/mindustry/graphics/MenuRenderer.java b/core/src/io/anuke/mindustry/graphics/MenuRenderer.java index 469c586737..045f34cf5e 100644 --- a/core/src/io/anuke/mindustry/graphics/MenuRenderer.java +++ b/core/src/io/anuke/mindustry/graphics/MenuRenderer.java @@ -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 diff --git a/core/src/io/anuke/mindustry/ui/fragments/MenuFragment.java b/core/src/io/anuke/mindustry/ui/fragments/MenuFragment.java index 5da907dff3..5d754cca52 100644 --- a/core/src/io/anuke/mindustry/ui/fragments/MenuFragment.java +++ b/core/src/io/anuke/mindustry/ui/fragments/MenuFragment.java @@ -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; diff --git a/core/src/io/anuke/mindustry/world/blocks/StaticWall.java b/core/src/io/anuke/mindustry/world/blocks/StaticWall.java index b645abb3b5..79a9b6f1d7 100644 --- a/core/src/io/anuke/mindustry/world/blocks/StaticWall.java +++ b/core/src/io/anuke/mindustry/world/blocks/StaticWall.java @@ -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;