diff --git a/core/assets-raw/sprites/blocks/turrets/bases/block-4.png b/core/assets-raw/sprites/blocks/turrets/bases/block-4.png index e1fcabc496..0cf01f72a9 100644 Binary files a/core/assets-raw/sprites/blocks/turrets/bases/block-4.png and b/core/assets-raw/sprites/blocks/turrets/bases/block-4.png differ diff --git a/core/assets/sprites/logo.png b/core/assets/sprites/logo.png new file mode 100644 index 0000000000..eee1e0e658 Binary files /dev/null and b/core/assets/sprites/logo.png differ diff --git a/core/src/io/anuke/mindustry/core/UI.java b/core/src/io/anuke/mindustry/core/UI.java index 7a234521b3..4f080e6ac8 100644 --- a/core/src/io/anuke/mindustry/core/UI.java +++ b/core/src/io/anuke/mindustry/core/UI.java @@ -75,23 +75,8 @@ public class UI implements ApplicationListener{ Core.scene = new Scene(skin); Core.input.addProcessor(Core.scene); - Dialog.setShowAction(() -> sequence( - alpha(0f), - originCenter(), - moveToAligned(Core.graphics.getWidth() / 2f, Core.graphics.getHeight() / 2f, Align.center), - scaleTo(0.0f, 1f), - parallel( - scaleTo(1f, 1f, 0.1f, Interpolation.fade), - fadeIn(0.1f, Interpolation.fade) - ) - )); - - Dialog.setHideAction(() -> sequence( - parallel( - scaleTo(0.01f, 0.01f, 0.1f, Interpolation.fade), - fadeOut(0.1f, Interpolation.fade) - ) - )); + Dialog.setShowAction(() -> sequence()); + Dialog.setHideAction(() -> sequence()); Tooltips.getInstance().animations = false; diff --git a/core/src/io/anuke/mindustry/graphics/MenuRenderer.java b/core/src/io/anuke/mindustry/graphics/MenuRenderer.java new file mode 100644 index 0000000000..469c586737 --- /dev/null +++ b/core/src/io/anuke/mindustry/graphics/MenuRenderer.java @@ -0,0 +1,119 @@ +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.g2d.*; +import io.anuke.arc.graphics.glutils.FrameBuffer; +import io.anuke.arc.math.Mathf; +import io.anuke.arc.util.Disposable; +import io.anuke.mindustry.content.Blocks; +import io.anuke.mindustry.world.Block; +import io.anuke.mindustry.world.Tile; + +import static io.anuke.mindustry.Vars.tilesize; +import static io.anuke.mindustry.Vars.world; + +public class MenuRenderer implements Disposable{ + private static final int width = 30, height = 30; + + private int cacheFloor, cacheWall; + private Camera camera = new Camera(); + private FrameBuffer shadows; + private CacheBatch batch; + + public MenuRenderer(){ + generate(); + cache(); + } + + private void generate(){ + Tile[][] tiles = world.createTiles(width, height); + shadows = new FrameBuffer(width, height); + + 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; + + tiles[x][y] = new Tile(x, y, floor.id, ore.id, wall.id); + } + } + } + + private void cache(){ + + //draw shadows + Draw.proj().setOrtho(0, 0, shadows.getWidth(), shadows.getHeight()); + shadows.beginDraw(Color.CLEAR); + for(int x = 0; x < width; x++){ + for(int y = 0; y < height; y++){ + if(world.rawTile(x, y).block() != Blocks.air){ + Fill.rect(x + 0.5f, y + 0.5f, 1, 1); + } + } + } + shadows.endDraw(); + + batch = new CacheBatch(new SpriteCache(width * height * 5, true)); + batch.beginCache(); + + SpriteBatch prev = Core.batch; + Core.batch = batch; + + for(int x = 0; x < width; x++){ + for(int y = 0; y < height; y++){ + Tile tile = world.rawTile(x, y); + tile.floor().draw(tile); + } + } + + for(int x = 0; x < width; x++){ + for(int y = 0; y < height; y++){ + Tile tile = world.rawTile(x, y); + if(tile.overlay() != Blocks.air){ + tile.overlay().draw(tile); + } + } + } + + cacheFloor = batch.endCache(); + batch.beginCache(); + + for(int x = 0; x < width; x++){ + for(int y = 0; y < height; y++){ + Tile tile = world.rawTile(x, y); + if(tile.block() != Blocks.air){ + tile.block().draw(tile); + } + } + } + + 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()); + + Draw.flush(); + 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.flush(); + batch.beginDraw(); + batch.drawCache(cacheWall); + batch.endDraw(); + } + + @Override + public void dispose(){ + batch.dispose(); + shadows.dispose(); + } +} diff --git a/core/src/io/anuke/mindustry/ui/dialogs/DeployDialog.java b/core/src/io/anuke/mindustry/ui/dialogs/DeployDialog.java index ab54131619..c6c554633a 100644 --- a/core/src/io/anuke/mindustry/ui/dialogs/DeployDialog.java +++ b/core/src/io/anuke/mindustry/ui/dialogs/DeployDialog.java @@ -88,15 +88,15 @@ public class DeployDialog extends FloatingDialog{ button.row(); button.label(() -> Core.bundle.format("save.playtime", color + slot.getPlayTime())); button.row(); - button.add().grow(); - button.row(); - button.addButton("$abandon", () -> { + row(); + + addButton("$abandon", () -> { ui.showConfirm("$warning", "$abandon.text", () -> { slot.delete(); setup(); }); - }).growX().height(50f).pad(-12).padTop(10); + }).fillX().height(50f).pad(3); }}, new ItemsDisplay()).grow(); diff --git a/core/src/io/anuke/mindustry/ui/fragments/BackgroundFragment.java b/core/src/io/anuke/mindustry/ui/fragments/BackgroundFragment.java index d802a4053f..7450f3128f 100644 --- a/core/src/io/anuke/mindustry/ui/fragments/BackgroundFragment.java +++ b/core/src/io/anuke/mindustry/ui/fragments/BackgroundFragment.java @@ -1,32 +1,12 @@ package io.anuke.mindustry.ui.fragments; -import io.anuke.arc.Core; -import io.anuke.arc.graphics.g2d.*; import io.anuke.arc.scene.Group; -import io.anuke.arc.scene.ui.layout.Unit; -import io.anuke.mindustry.core.GameState.State; - -import static io.anuke.mindustry.Vars.state; public class BackgroundFragment extends Fragment{ + @Override public void build(Group parent){ - Core.scene.table().addRect((a, b, w, h) -> { - Draw.colorl(0.1f); - Fill.crect(0, 0, w, h); - //Draw.shader(Shaders.menu); - // Fill.crect(0, 0, w, h); - //Draw.shader(); - boolean portrait = Core.graphics.getWidth() < Core.graphics.getHeight(); - float logoscl = (int)Unit.dp.scl(1); - TextureRegion logo = Core.atlas.find("logotext"); - float logow = logo.getWidth() * logoscl; - float logoh = logo.getHeight() * logoscl; - - Draw.color(); - //Draw.rect(logo, (int)(w / 2), (int)(h - 10 - logoh - Unit.dp.scl(portrait ? 30f : 0)) + logoh / 2, logow, logoh); - }).visible(() -> state.is(State.menu)).grow(); } } diff --git a/core/src/io/anuke/mindustry/ui/fragments/MenuFragment.java b/core/src/io/anuke/mindustry/ui/fragments/MenuFragment.java index ec66e9e08c..5da907dff3 100644 --- a/core/src/io/anuke/mindustry/ui/fragments/MenuFragment.java +++ b/core/src/io/anuke/mindustry/ui/fragments/MenuFragment.java @@ -1,24 +1,38 @@ package io.anuke.mindustry.ui.fragments; -import io.anuke.arc.*; +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.event.Touchable; import io.anuke.arc.scene.ui.Button; import io.anuke.arc.scene.ui.layout.Table; +import io.anuke.arc.scene.ui.layout.Unit; import io.anuke.arc.util.Align; import io.anuke.mindustry.core.GameState.State; import io.anuke.mindustry.core.Platform; import io.anuke.mindustry.game.EventType.ResizeEvent; -import io.anuke.mindustry.ui.*; +import io.anuke.mindustry.graphics.MenuRenderer; +import io.anuke.mindustry.ui.MenuButton; +import io.anuke.mindustry.ui.MobileButton; import io.anuke.mindustry.ui.dialogs.FloatingDialog; import static io.anuke.mindustry.Vars.*; 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(); @Override public void build(Group parent){ + + Core.scene.table().addRect((a, b, w, h) -> { + renderer.render(); + }); + parent.fill(c -> { container = c; container.visible(() -> state.is(State.menu)); @@ -45,6 +59,20 @@ public class MenuFragment extends Fragment{ //parent.fill(c -> c.bottom().left().add(Strings.format("v{0} {1}-{2} {3}{4}", Version.number, Version.modifier, Version.type, //(Version.build == -1 ? "custom build" : "build " + Version.build), Version.revision == 0 ? "" : "." + Version.revision)).color(Color.DARK_GRAY) //.visible(() -> state.is(State.menu))); + + Core.scene.table().addRect((a, b, w, h) -> { + //Draw.shader(Shaders.menu); + // Fill.crect(0, 0, w, h); + //Draw.shader(); + + boolean portrait = Core.graphics.getWidth() < Core.graphics.getHeight(); + float logoscl = (int)Unit.dp.scl(1); + float logow = Math.min(logo.getWidth() * logoscl, 768); + 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); + }).visible(() -> state.is(State.menu)).grow().get().touchable(Touchable.disabled); } private void buildMobile(){