diff --git a/build.gradle b/build.gradle index ffaa10132a..82b5254689 100644 --- a/build.gradle +++ b/build.gradle @@ -21,7 +21,7 @@ allprojects { appName = "Mindustry" gdxVersion = '1.9.8' aiVersion = '1.8.1' - uCoreVersion = 'b882f59'; + uCoreVersion = '5e4e43ed39'; } repositories { diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index 1a0c28ef65..9d8444d0c4 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -14,15 +14,17 @@ text.joingame=Join Game text.quit=Quit text.about.button=About text.name=Name: +text.public=Public text.players={0} players online text.players.single={0} player online text.server.kicked.kick=You have been kicked from the server! text.server.kicked.invalidPassword=Invalid password! -text.server.connected=A player has joined. +text.server.connected={0} has joined. text.server.disconnected={0} has disconnected. text.nohost=Can't host server on a custom map! text.hostserver=Host Server text.host=Host +text.hosting=[accent]Opening server... text.hosts.refresh=Refresh text.hosts.discovering=Discovering LAN games text.hosts.none=[lightgray]No games found! diff --git a/core/src/io/anuke/mindustry/core/Control.java b/core/src/io/anuke/mindustry/core/Control.java index 0929b94daa..5d8449b6ea 100644 --- a/core/src/io/anuke/mindustry/core/Control.java +++ b/core/src/io/anuke/mindustry/core/Control.java @@ -243,9 +243,9 @@ public class Control extends Module{ for(Block block : Block.getAllBlocks()){ block.onReset(); } - - ui.updateItems(); - ui.updateWeapons(); + + ui.hudfrag.updateItems(); + ui.weaponfrag.updateWeapons(); } public void play(){ @@ -264,8 +264,8 @@ public class Control extends Module{ if(mode.infiniteResources){ Arrays.fill(items, 999999999); } - - ui.updateItems(); + + ui.hudfrag.updateItems(); GameState.set(State.playing); } @@ -293,7 +293,7 @@ public class Control extends Module{ } public void playMap(Map map){ - Vars.ui.showLoading(); + ui.loadfrag.show(); saves.resetSave(); Timers.run(16, ()->{ @@ -302,7 +302,7 @@ public class Control extends Module{ play(); }); - Timers.run(18, ()-> ui.hideLoading()); + Timers.run(18, ()-> ui.loadfrag.hide()); } public GameMode getMode(){ @@ -403,7 +403,7 @@ public class Control extends Module{ } Effects.effect(Fx.coreexplosion, core.worldx(), core.worldy()); - Timers.run(60, ()-> ui.showRestart()); + Timers.run(60, ()-> ui.restart.show()); } float waveSpacing(){ @@ -602,23 +602,23 @@ public class Control extends Module{ } if(shouldUpdateItems && (Timers.get("updateItems", 8) || GameState.is(State.paused))){ - ui.updateItems(); + ui.hudfrag.updateItems(); shouldUpdateItems = false; } if(!GameState.is(State.menu)){ input.update(); - if(Inputs.keyTap("pause") && !ui.isGameOver() && !Net.active() && (GameState.is(State.paused) || GameState.is(State.playing))){ + if(Inputs.keyTap("pause") && !ui.restart.isShown() && !Net.active() && (GameState.is(State.paused) || GameState.is(State.playing))){ GameState.set(GameState.is(State.playing) ? State.paused : State.playing); } if(Inputs.keyTap("menu")){ if(GameState.is(State.paused)){ - ui.hideMenu(); + ui.paused.hide(); GameState.set(State.playing); - }else if (!ui.isGameOver()){ - ui.showMenu(); + }else if (!ui.restart.isShown()){ + ui.paused.show(); GameState.set(State.paused); } } @@ -634,7 +634,7 @@ public class Control extends Module{ player.heal(); player.add(); Effects.sound("respawn"); - ui.fadeRespawn(false); + ui.hudfrag.fadeRespawn(false); } } diff --git a/core/src/io/anuke/mindustry/core/NetClient.java b/core/src/io/anuke/mindustry/core/NetClient.java index 12627c5b12..e3212c7452 100644 --- a/core/src/io/anuke/mindustry/core/NetClient.java +++ b/core/src/io/anuke/mindustry/core/NetClient.java @@ -46,9 +46,10 @@ public class NetClient extends Module { connecting = true; gotEntities = false; kicked = false; + Gdx.app.postRunnable(() -> { - Vars.ui.hideLoading(); - Vars.ui.showLoading("$text.connecting.data"); + Vars.ui.loadfrag.hide(); + Vars.ui.loadfrag.show("$text.connecting.data"); }); ConnectPacket c = new ConnectPacket(); @@ -59,7 +60,7 @@ public class NetClient extends Module { Timers.runTask(dataTimeout, () -> { if(!gotEntities){ Gdx.app.error("Mindustry", "Failed to load data!"); - Vars.ui.hideLoading(); + Vars.ui.loadfrag.hide(); Net.disconnect(); } }); @@ -69,9 +70,7 @@ public class NetClient extends Module { if(kicked) return; Gdx.app.postRunnable(() -> { - Timers.runFor(3f, () -> { - Vars.ui.hideLoading(); - }); + Timers.runFor(3f, Vars.ui.loadfrag::hide); GameState.set(State.menu); @@ -96,8 +95,8 @@ public class NetClient extends Module { GameState.set(State.playing); connecting = false; - Vars.ui.hideLoading(); - Vars.ui.hideJoinGame(); + Vars.ui.loadfrag.hide(); + Vars.ui.join.hide(); }); }); @@ -170,9 +169,7 @@ public class NetClient extends Module { Timers.resetTime(packet.time + (float)(TimeUtils.timeSinceMillis(packet.timestamp) / 1000.0 * 60.0)); - Gdx.app.postRunnable(() -> { - Vars.ui.updateItems(); - }); + Gdx.app.postRunnable(Vars.ui.hudfrag::updateItems); }); Net.handle(EnemySpawnPacket.class, spawn -> { @@ -199,7 +196,7 @@ public class NetClient extends Module { //TODO shoot effects for enemies, clientside as well as serverside BulletType type = (BulletType) BaseBulletType.getByID(packet.type); Entity owner = Vars.control.enemyGroup.getByID(packet.owner); - Bullet bullet = new Bullet(type, owner, packet.x, packet.y, packet.angle).add(); + new Bullet(type, owner, packet.x, packet.y, packet.angle).add(); }); Net.handle(BlockDestroyPacket.class, packet -> { @@ -217,7 +214,6 @@ public class NetClient extends Module { }); Net.handle(BlockSyncPacket.class, packet -> { - //TODO implementation, load data... DataInputStream stream = new DataInputStream(packet.stream); try{ @@ -247,13 +243,9 @@ public class NetClient extends Module { } }); - Net.handle(Player.class, player -> { - player.add(); - }); + Net.handle(Player.class, Player::add); - Net.handle(ChatPacket.class, packet -> { - Gdx.app.postRunnable(() -> Vars.ui.addChatMessage(packet.name, packet.text)); - }); + Net.handle(ChatPacket.class, packet -> Gdx.app.postRunnable(() -> Vars.ui.chatfrag.addMessage(packet.name, packet.text))); Net.handle(KickPacket.class, packet -> { kicked = true; @@ -280,7 +272,7 @@ public class NetClient extends Module { Net.send(packet, SendMode.tcp); if(Net.server()){ - Vars.ui.addChatMessage(Vars.player.name, packet.text); + Vars.ui.chatfrag.addMessage(packet.text, Vars.player.name); } } @@ -314,7 +306,7 @@ public class NetClient extends Module { if(Timers.get("syncPlayer", playerSyncTime)){ PositionPacket packet = new PositionPacket(); packet.data = Vars.player.getInterpolator().type.write(Vars.player); - Net.send(packet, SendMode.udp); //TODO udp instead? + Net.send(packet, SendMode.udp); } } } diff --git a/core/src/io/anuke/mindustry/core/NetServer.java b/core/src/io/anuke/mindustry/core/NetServer.java index 262ee2331d..20797b28f8 100644 --- a/core/src/io/anuke/mindustry/core/NetServer.java +++ b/core/src/io/anuke/mindustry/core/NetServer.java @@ -1,7 +1,6 @@ package io.anuke.mindustry.core; import com.badlogic.gdx.Gdx; -import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.utils.IntArray; import com.badlogic.gdx.utils.IntMap; import com.badlogic.gdx.utils.TimeUtils; @@ -22,7 +21,6 @@ import io.anuke.mindustry.resource.Weapon; import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.Tile; import io.anuke.ucore.UCore; -import io.anuke.ucore.core.Effects.Effect; import io.anuke.ucore.core.Timers; import io.anuke.ucore.entities.Entity; import io.anuke.ucore.modules.Module; @@ -42,9 +40,7 @@ public class NetServer extends Module{ public NetServer(){ - Net.handleServer(Connect.class, connect -> { - UCore.log("Connection found: " + connect.addressTCP); - }); + Net.handleServer(Connect.class, connect -> UCore.log("Connection found: " + connect.addressTCP)); Net.handleServer(ConnectPacket.class, packet -> { int id = Net.getLastConnection(); @@ -68,14 +64,11 @@ public class NetServer extends Module{ UCore.log("Packed " + outc.size() + " COMPRESSED bytes of data."); - //TODO compress and uncompress when sending data.stream = new ByteArrayInputStream(outc.toByteArray()); Net.sendStream(id, data); Gdx.app.postRunnable(() -> { - Vars.ui.showInfo("$text.server.connected"); - EntityDataPacket dp = new EntityDataPacket(); Player player = new Player(); @@ -94,6 +87,8 @@ public class NetServer extends Module{ Net.sendExcept(id, player, SendMode.tcp); Net.sendTo(id, dp, SendMode.tcp); + + Vars.ui.showInfo(Bundles.format("text.server.connected", packet.name)); }); }); @@ -162,17 +157,6 @@ public class NetServer extends Module{ }); } - //TODO decide whether to use effects - public void sendEffect(Effect effect, Color color, float x, float y, float rotation){ - EffectPacket packet = new EffectPacket(); - packet.id = effect.id; - packet.color = Color.rgba8888(color); - packet.x = x; - packet.y = y; - packet.rotation = rotation; - Net.send(packet, SendMode.udp); - } - public void handleBullet(BulletType type, Entity owner, float x, float y, float angle, short damage){ BulletPacket packet = new BulletPacket(); packet.x = x; @@ -281,8 +265,6 @@ public class NetServer extends Module{ int h = 12; sendBlockSync(id, x, y, w, h); } - - //TODO sync to each player entity } } @@ -322,8 +304,6 @@ public class NetServer extends Module{ throw new RuntimeException(e); } - //TODO finish - packet.stream = new ByteArrayInputStream(bs.toByteArray()); Net.sendStream(client, packet); diff --git a/core/src/io/anuke/mindustry/core/Renderer.java b/core/src/io/anuke/mindustry/core/Renderer.java index 33f6697804..1f200c4ad3 100644 --- a/core/src/io/anuke/mindustry/core/Renderer.java +++ b/core/src/io/anuke/mindustry/core/Renderer.java @@ -38,7 +38,6 @@ import static io.anuke.ucore.core.Core.batch; import static io.anuke.ucore.core.Core.camera; public class Renderer extends RendererModule{ - private final static int chunksize = 32; private final static float shieldHitDuration = 18f; public Surface shadowSurface, shieldSurface, indicatorSurface; @@ -101,7 +100,7 @@ public class Renderer extends RendererModule{ //TODO identify the source of this bug if(control.core == null){ - ui.showGameError(); + ui.showError("$text.error.crashmessage"); GameState.set(State.menu); return; } @@ -218,7 +217,7 @@ public class Renderer extends RendererModule{ Draw.tscl(0.25f/2); for(Player player : Vars.control.playerGroup.all()){ if(!player.isLocal){ - Draw.text(player.name, player.x, player.y + 6); + Draw.text(player.name, player.x, player.y + 7); } } Draw.tscl(Vars.fontscale); @@ -352,13 +351,13 @@ public class Renderer extends RendererModule{ if(input.breakMode == PlaceMode.holdDelete) input.breakMode.draw(tilex, tiley, 0, 0); - }else if(input.breakMode.delete && control.input.drawPlace() && input.recipe == null){ //TODO test! + }else if(input.breakMode.delete && control.input.drawPlace() && input.recipe == null){ input.breakMode.draw(control.input.getBlockX(), control.input.getBlockY(), control.input.getBlockEndX(), control.input.getBlockEndY()); } - if(Vars.ui.getTools().confirming){ - ToolFragment t = Vars.ui.getTools(); + if(Vars.ui.toolfrag.confirming){ + ToolFragment t = Vars.ui.toolfrag; PlaceMode.areaDelete.draw(t.px, t.py, t.px2, t.py2); } diff --git a/core/src/io/anuke/mindustry/core/Tutorial.java b/core/src/io/anuke/mindustry/core/Tutorial.java index d0fcd9e05d..42d5d63cf4 100644 --- a/core/src/io/anuke/mindustry/core/Tutorial.java +++ b/core/src/io/anuke/mindustry/core/Tutorial.java @@ -36,8 +36,7 @@ public class Tutorial{ } public void buildUI(table table){ - - //TODO maybe align it to the bottom? + table.atop(); new table("pane"){{ @@ -395,7 +394,7 @@ public class Tutorial{ void onSwitch(){ if(!Vars.control.getWeapons().contains(Weapon.multigun, true)){ Vars.control.getWeapons().add(Weapon.multigun); - Vars.ui.updateWeapons(); + Vars.ui.weaponfrag.updateWeapons(); } } }, diff --git a/core/src/io/anuke/mindustry/core/UI.java b/core/src/io/anuke/mindustry/core/UI.java index 615757549c..e6aab81d61 100644 --- a/core/src/io/anuke/mindustry/core/UI.java +++ b/core/src/io/anuke/mindustry/core/UI.java @@ -3,65 +3,53 @@ package io.anuke.mindustry.core; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Colors; -import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.math.Interpolation; -import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.utils.Align; import io.anuke.mindustry.Mindustry; import io.anuke.mindustry.Vars; -import io.anuke.mindustry.core.GameState.State; -import io.anuke.mindustry.mapeditor.MapEditor; import io.anuke.mindustry.mapeditor.MapEditorDialog; -import io.anuke.mindustry.net.Net; -import io.anuke.mindustry.ui.*; +import io.anuke.mindustry.ui.dialogs.*; import io.anuke.mindustry.ui.fragments.*; -import io.anuke.mindustry.world.Tile; -import io.anuke.mindustry.world.blocks.Blocks; -import io.anuke.mindustry.world.blocks.types.Configurable; import io.anuke.ucore.core.*; import io.anuke.ucore.function.Consumer; import io.anuke.ucore.function.Listenable; import io.anuke.ucore.modules.SceneModule; -import io.anuke.ucore.scene.Element; import io.anuke.ucore.scene.Skin; import io.anuke.ucore.scene.actions.Actions; import io.anuke.ucore.scene.builders.build; -import io.anuke.ucore.scene.builders.label; -import io.anuke.ucore.scene.builders.table; -import io.anuke.ucore.scene.event.Touchable; -import io.anuke.ucore.scene.ui.*; +import io.anuke.ucore.scene.ui.Dialog; +import io.anuke.ucore.scene.ui.TextField; import io.anuke.ucore.scene.ui.TextField.TextFieldFilter; -import io.anuke.ucore.scene.ui.TextField.TextFieldFilter.DigitsOnlyFilter; -import io.anuke.ucore.scene.ui.Window.WindowStyle; -import io.anuke.ucore.scene.ui.layout.Table; +import io.anuke.ucore.scene.ui.TooltipManager; import io.anuke.ucore.scene.ui.layout.Unit; -import io.anuke.ucore.util.Bundles; -import io.anuke.ucore.util.Strings; -import java.io.IOException; - -import static io.anuke.mindustry.Vars.*; +import static io.anuke.mindustry.Vars.control; import static io.anuke.ucore.scene.actions.Actions.*; public class UI extends SceneModule{ - Table loadingtable, configtable; - MindustrySettingsDialog prefs; - MindustryKeybindDialog keys; - MapEditorDialog editorDialog; - Dialog about, restart, levels, upgrades, load, settingserror, gameerror, discord, join; - MenuDialog menu; - Tooltip tooltip; - Tile configTile; - MapEditor editor; - boolean wasPaused = false; - - private Fragment menufrag = new MenuFragment(), - toolfrag = new ToolFragment(), - hudfrag = new HudFragment(), - placefrag = new PlacementFragment(), - weaponfrag = new WeaponFragment(), - chatfrag = new ChatFragment(), - listfrag = new PlayerListFragment(); + public AboutDialog about; + public RestartDialog restart; + public LevelDialog levels; + public LoadDialog load; + public DiscordDialog discord; + public JoinDialog join; + public HostDialog host; + public PausedDialog paused; + public SettingsMenuDialog settings; + public ControlsDialog controls; + public MapEditorDialog editor; + public UpgradeDialog upgrades; + + public final MenuFragment menufrag = new MenuFragment(); + public final ToolFragment toolfrag = new ToolFragment(); + public final HudFragment hudfrag = new HudFragment(); + public final PlacementFragment placefrag = new PlacementFragment(); + public final WeaponFragment weaponfrag = new WeaponFragment(); + public final ChatFragment chatfrag = new ChatFragment(); + public final PlayerListFragment listfrag = new PlayerListFragment(); + public final BackgroundFragment backfrag = new BackgroundFragment(); + public final LoadingFragment loadfrag = new LoadingFragment(); + public final BlockConfigFragment configfrag = new BlockConfigFragment(); public UI() { Dialog.setShowAction(()-> sequence( @@ -89,7 +77,7 @@ public class UI extends SceneModule{ TooltipManager.getInstance().animations = false; - Settings.setErrorHandler(()-> Timers.run(1f, ()-> settingserror.show())); + Settings.setErrorHandler(()-> Timers.run(1f, ()-> showError("[crimson]Failed to access local storage.\nSettings will not be saved."))); Settings.defaults("pixelate", true); @@ -114,261 +102,65 @@ public class UI extends SceneModule{ Colors.put("breakStart", Color.YELLOW); Colors.put("breakInvalid", Color.RED); } - + + @Override protected void loadSkin(){ skin = new Skin(Gdx.files.internal("ui/uiskin.json"), Core.atlas); } - - void drawBackground(){ - int w = (int)screen.x; - int h = (int)screen.y; - - Draw.color(); - - TextureRegion back = Draw.region("background"); - float backscl = Unit.dp.scl(5f); - - Draw.alpha(0.7f); - Core.batch.draw(back, w/2 - back.getRegionWidth()*backscl/2 +240f, h/2 - back.getRegionHeight()*backscl/2 + 250f, - back.getRegionWidth()*backscl, back.getRegionHeight()*backscl); - - float logoscl = (int)Unit.dp.scl(7); - TextureRegion logo = skin.getRegion("logotext"); - float logow = logo.getRegionWidth()*logoscl; - float logoh = logo.getRegionHeight()*logoscl; - - - Draw.color(); - Core.batch.draw(logo, w/2 - logow/2, h - logoh + 15, logow, logoh); - - } @Override public void update(){ if(Vars.debug && !Vars.showUI) return; - if(GameState.is(State.menu)){ - scene.getBatch().getProjectionMatrix().setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); - scene.getBatch().begin(); - - drawBackground(); - - scene.getBatch().end(); - } - scene.act(); scene.draw(); if(control.showCursor()) { Draw.color(); + float scl = Unit.dp.scl(3f); - scene.getBatch().begin(); - Draw.rect("controller-cursor", Gdx.input.getX(), Gdx.graphics.getHeight() - Gdx.input.getY(), 16*scl, 16*scl); - scene.getBatch().end(); + + Graphics.begin(); + Draw.rect("controller-cursor", Graphics.mouse().x, Graphics.mouse().y, 16*scl, 16*scl); + Graphics.end(); } } @Override public void init(){ - - configtable = new Table(); - scene.add(configtable); - - if(!Vars.gwt){ - editor = new MapEditor(); - editorDialog = new MapEditorDialog(editor); - } - - settingserror = new Dialog("Warning", "dialog"); - settingserror.content().add("[crimson]Failed to access local storage.\nSettings will not be saved."); - settingserror.content().margin(10f); - settingserror.getButtonTable().addButton("OK", settingserror::hide).size(80f, 55f).pad(4); - - gameerror = new Dialog("$text.error.crashtitle", "dialog"); - gameerror.content().labelWrap("$text.error.crashmessage").width(600f).pad(10f); - gameerror.buttons().addButton("#text.ok", gameerror::hide).size(200f, 50); + editor = new MapEditorDialog(); + controls = new ControlsDialog(); + restart = new RestartDialog(); join = new JoinDialog(); - - discord = new Dialog("Discord", "dialog"); - discord.content().margin(12f); - discord.content().add("$text.discord"); - discord.content().row(); - discord.content().add("[orange]"+Vars.discordURL); - discord.buttons().defaults().size(200f, 50); - discord.buttons().addButton("$text.openlink", () -> Mindustry.platforms.openLink(Vars.discordURL)); - discord.buttons().addButton("$text.back", discord::hide); - + discord = new DiscordDialog(); load = new LoadDialog(); - upgrades = new UpgradeDialog(); - levels = new LevelDialog(); - - prefs = new MindustrySettingsDialog(); - prefs.setStyle(Core.skin.get("dialog", WindowStyle.class)); - - menu = new MenuDialog(); - - prefs.sound.volumePrefs(); - - prefs.game.sliderPref("difficulty", 1, 0, 2, i -> Bundles.get("setting.difficulty." + (i == 0 ? "easy" : i == 1 ? "normal" : "hard"))); - prefs.game.screenshakePref(); - prefs.game.checkPref("smoothcam", true); - prefs.game.checkPref("indicators", true); - prefs.game.checkPref("effects", true); - prefs.game.sliderPref("sensitivity", 100, 10, 300, i -> i + "%"); - prefs.game.sliderPref("saveinterval", 90, 15, 5*120, i -> Bundles.format("setting.seconds", i)); - - prefs.graphics.checkPref("fps", false); - prefs.graphics.checkPref("vsync", true, b -> Gdx.graphics.setVSync(b)); - prefs.graphics.checkPref("lasers", true); - prefs.graphics.checkPref("healthbars", true); - prefs.graphics.checkPref("pixelate", true, b->{ - if(b){ - Vars.renderer.pixelSurface.setScale(Core.cameraScale); - Vars.renderer.shadowSurface.setScale(Core.cameraScale); - Vars.renderer.shieldSurface.setScale(Core.cameraScale); - }else{ - Vars.renderer.shadowSurface.setScale(1); - Vars.renderer.shieldSurface.setScale(1); - } - renderer.setPixelate(b); - }); - - Gdx.graphics.setVSync(Settings.getBool("vsync")); - - prefs.hidden(()->{ - if(!GameState.is(State.menu)){ - if(!wasPaused || Net.active()) - GameState.set(State.playing); - } - }); - - prefs.shown(()->{ - if(!GameState.is(State.menu)){ - wasPaused = GameState.is(State.paused); - if(menu.getScene() != null){ - wasPaused = menu.wasPaused; - } - if(!Net.active()) GameState.set(State.paused); - menu.hide(); - } - }); - - keys = new MindustryKeybindDialog(); - - about = new FloatingDialog("About"); - about.addCloseButton(); - for(String text : aboutText){ - about.content().add(text).left(); - about.content().row(); - } - - restart = new Dialog("$text.gameover", "dialog"); - - restart.shown(()->{ - restart.content().clearChildren(); - if(control.isHighScore()){ - restart.content().add("$text.highscore").pad(6); - restart.content().row(); - } - restart.content().add("$text.lasted").pad(12).get(); - restart.content().add("[GREEN]" + control.getWave()); - restart.pack(); - }); - - restart.getButtonTable().addButton("$text.menu", ()->{ - restart.hide(); - GameState.set(State.menu); - control.reset(); - }).size(200, 50).pad(3); + settings = new SettingsMenuDialog(); + paused = new PausedDialog(); + about = new AboutDialog(); + host = new HostDialog(); build.begin(scene); - + + backfrag.build(); weaponfrag.build(); - hudfrag.build(); - + configfrag.build(); menufrag.build(); - placefrag.build(); - - loadingtable = new table("loadDim"){{ - touchable(Touchable.enabled); - get().addImage("white").growX() - .height(3f).pad(4f).growX().get().setColor(Colors.get("accent")); - row(); - new label("$text.loading"){{ - get().setName("namelabel"); - }}.pad(10); - row(); - get().addImage("white").growX() - .height(3f).pad(4f).growX().get().setColor(Colors.get("accent")); - }}.end().get(); - - loadingtable.setVisible(false); - toolfrag.build(); - chatfrag.build(); - listfrag.build(); - - updateItems(); + loadfrag.build(); build.end(); } - public void addChatMessage(String sender, String message){ - ((ChatFragment)chatfrag).addMessage(message, sender); - } - - public void showGameError(){ - gameerror.show(); - } - - public void updateWeapons(){ - ((WeaponFragment)weaponfrag).updateWeapons(); - } - - public void fadeRespawn(boolean in){ - ((HudFragment)hudfrag).fadeRespawn(in); - } - - public void showConfig(Tile tile){ - configTile = tile; - - configtable.clear(); - ((Configurable)tile.block()).buildTable(tile, configtable); - configtable.pack(); - configtable.setTransform(true); - configtable.actions(Actions.scaleTo(0f, 1f), Actions.visible(true), - Actions.scaleTo(1f, 1f, 0.07f, Interpolation.pow3Out)); - - configtable.update(()->{ - configtable.setOrigin(Align.center); - Vector2 pos = Graphics.screen(tile.worldx(), tile.worldy()); - configtable.setPosition(pos.x, pos.y, Align.center); - if(configTile == null || configTile.block() == Blocks.air){ - hideConfig(); - } - }); - } - - public boolean hasConfigMouse(){ - Element e = scene.hit(Gdx.input.getX(), Gdx.graphics.getHeight() - Gdx.input.getY(), true); - return e != null && (e == configtable || e.isDescendantOf(configtable)); - } - - public void hideConfig(){ - configtable.actions(Actions.scaleTo(0f, 1f, 0.06f, Interpolation.pow3Out), Actions.visible(false)); - } - public void showTextInput(String title, String text, String def, TextFieldFilter filter, Consumer confirmed){ new Dialog(title, "dialog"){{ - content().margin(30); - content().add(text).padRight(6f); + content().margin(30).add(text).padRight(6f); TextField field = content().addField(def, t->{}).size(170f, 50f).get(); field.setTextFieldFilter((f, c) -> field.getText().length() < 12 && filter.acceptChar(f, c)); Mindustry.platforms.addDialog(field); @@ -385,152 +177,17 @@ public class UI extends SceneModule{ showTextInput(title, text, def, (field, c) -> true, confirmed); } + public void showInfo(String info){ + scene.table().add("[accent]" + info).padBottom(Gdx.graphics.getHeight()/2+100f).get().getParent().actions(Actions.fadeOut(4f), Actions.removeActor()); + } + public void showError(String text){ new Dialog("$text.error.title", "dialog"){{ - content().margin(15); - content().add(text); + content().margin(15).add(text); buttons().addButton("$text.ok", this::hide).size(90, 50).pad(4); }}.show(); } - public void showErrorClose(String text){ - new Dialog("$text.error.title", "dialog"){{ - content().margin(15); - content().add(text); - buttons().addButton("$text.quit", Gdx.app::exit).size(90, 50).pad(4); - }}.show(); - } - - public void showLoading(){ - showLoading("$text.loading"); - } - - public void showLoading(String text){ - loadingtable.