From 0f3780dbb2f8dd3918144604661de4df15adcaf0 Mon Sep 17 00:00:00 2001 From: Goobrr <73060700+Goobrr@users.noreply.github.com> Date: Sun, 8 May 2022 20:26:49 +0700 Subject: [PATCH] GameOverDialog rework (#6783) * GameOverDialog rework * cleanup --- core/assets/bundles/bundle.properties | 14 +- core/assets/contributors | 1 + .../mindustry/ui/dialogs/GameOverDialog.java | 159 +++++++++++++----- 3 files changed, 123 insertions(+), 51 deletions(-) diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index d0ac2818fa..03c61f6cc2 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -76,13 +76,13 @@ schematic.tagdelconfirm = Delete this tag completely? schematic.tagexists = That tag already exists. stats = Stats -stat.wave = Waves Defeated:[accent] {0} -stat.unitsCreated = Units Created:[accent] {0} -stat.enemiesDestroyed = Enemies Destroyed:[accent] {0} -stat.built = Buildings Built:[accent] {0} -stat.destroyed = Buildings Destroyed:[accent] {0} -stat.deconstructed = Buildings Deconstructed:[accent] {0} -stat.playtime = Time Played:[accent] {0} +stat.wave = Waves Defeated +stat.unitsCreated = Units Created +stat.enemiesDestroyed = Enemies Destroyed +stat.built = Buildings Built +stat.destroyed = Buildings Destroyed +stat.deconstructed = Buildings Deconstructed +stat.playtime = Time Played globalitems = [accent]Total Items map.delete = Are you sure you want to delete the map "[accent]{0}[]"? diff --git a/core/assets/contributors b/core/assets/contributors index 2c03e1ede0..14b0865cc2 100644 --- a/core/assets/contributors +++ b/core/assets/contributors @@ -136,3 +136,4 @@ Evolveye Jerzy Paciorkiewicz YozoZChomutova Qendolin +Goobrr \ No newline at end of file diff --git a/core/src/mindustry/ui/dialogs/GameOverDialog.java b/core/src/mindustry/ui/dialogs/GameOverDialog.java index 8ab6054b6b..6173752b80 100644 --- a/core/src/mindustry/ui/dialogs/GameOverDialog.java +++ b/core/src/mindustry/ui/dialogs/GameOverDialog.java @@ -1,19 +1,38 @@ package mindustry.ui.dialogs; import arc.*; +import arc.flabel.*; +import arc.math.*; +import arc.scene.actions.*; +import arc.scene.ui.*; +import arc.scene.ui.layout.*; +import arc.util.*; import mindustry.core.GameState.*; import mindustry.game.EventType.*; import mindustry.game.*; +import mindustry.gen.*; +import mindustry.graphics.*; +import mindustry.ui.*; import static mindustry.Vars.*; public class GameOverDialog extends BaseDialog{ private Team winner; + private boolean hudShown; public GameOverDialog(){ super("@gameover"); setFillParent(true); - shown(this::rebuild); + + titleTable.remove(); + + shown(() -> { + hudShown = ui.hudfrag.shown; + ui.hudfrag.shown = false; + rebuild(); + }); + + hidden(() -> ui.hudfrag.shown = hudShown); Events.on(ResetEvent.class, e -> hide()); } @@ -29,7 +48,6 @@ public class GameOverDialog extends BaseDialog{ } void rebuild(){ - title.setText(state.isCampaign() ? Core.bundle.format("sector.lost", state.getSector().name()) : "@gameover"); buttons.clear(); cont.clear(); @@ -37,55 +55,108 @@ public class GameOverDialog extends BaseDialog{ if(state.rules.pvp && winner != null){ cont.add(Core.bundle.format("gameover.pvp", winner.localized())).pad(6); + }else{ + cont.add(state.isCampaign() ? Core.bundle.format("sector.lost", state.getSector().name()) : "@gameover").center().pad(6); + } + cont.row(); + + if(control.isHighScore()){ + cont.add("@highscore").pad(6); + cont.row(); + } + + cont.pane(t -> { + t.margin(13f); + t.left().defaults().left(); + t.setBackground(Styles.black3); + + t.table(stats -> { + if(state.rules.waves) addStat(stats, Core.bundle.get("stat.wave"), state.stats.wavesLasted, 0f); + addStat(stats, Core.bundle.get("stat.unitsCreated"), state.stats.unitsCreated, 0.05f); + addStat(stats, Core.bundle.get("stat.enemiesDestroyed"), state.stats.enemyUnitsDestroyed, 0.1f); + addStat(stats, Core.bundle.get("stat.built"), state.stats.buildingsBuilt, 0.15f); + addStat(stats, Core.bundle.get("stat.destroyed"), state.stats.buildingsDestroyed, 0.2f); + addStat(stats, Core.bundle.get("stat.deconstructed"), state.stats.buildingsDeconstructed, 0.25f); + }).top().grow().row(); + + if(control.saves.getCurrent() != null){ + t.table(tt -> { + tt.add(new FLabel(Core.bundle.get("stat.playtime"))).left().pad(5).growX(); + tt.add(new FLabel("[accent]" + control.saves.getCurrent().getPlayTime())).right().pad(5); + }).growX(); + } + }).minWidth(370).maxSize(580, 500).grow().pad(12).center().get(); + + + if(state.isCampaign() && net.client()){ + cont.add("@gameover.waiting").padTop(20f).row(); + } + + if(state.isCampaign()){ + if(net.client()){ + buttons.button("@gameover.disconnect", () -> { + logic.reset(); + net.reset(); + hide(); + state.set(State.menu); + }).size(170f, 60f); + }else{ + buttons.button("@continue", () -> { + hide(); + ui.planet.show(); + }).size(170f, 60f); + } + }else{ buttons.button("@menu", () -> { hide(); logic.reset(); - }).size(130f, 60f); - }else{ - if(control.isHighScore()){ - cont.add("@highscore").pad(6); - cont.row(); - } + }).size(140f, 60f); + } + } - cont.pane(t -> { - t.margin(13f); - t.left().defaults().left(); - t.add(Core.bundle.format("stat.wave", state.stats.wavesLasted)).row(); - t.add(Core.bundle.format("stat.unitsCreated", state.stats.unitsCreated)).row(); - t.add(Core.bundle.format("stat.enemiesDestroyed", state.stats.enemyUnitsDestroyed)).row(); - t.add(Core.bundle.format("stat.built", state.stats.buildingsBuilt)).row(); - t.add(Core.bundle.format("stat.destroyed", state.stats.buildingsDestroyed)).row(); - t.add(Core.bundle.format("stat.deconstructed", state.stats.buildingsDeconstructed)).row(); - if(control.saves.getCurrent() != null){ - t.add(Core.bundle.format("stat.playtime", control.saves.getCurrent().getPlayTime())).row(); - } + private void addStat(Table parent, String stat, int value, float delay){ + parent.add(new StatLabel(stat, value, delay)).top().pad(5).growX().height(50).row(); + } - if(state.isCampaign() && net.client()){ - t.add("@gameover.waiting").padTop(20f).row(); - } + private static class StatLabel extends Table { + private float progress = 0; - }).pad(12); + public StatLabel(String stat, int value, float delay){ + setTransform(true); + setClip(true); + setBackground(Tex.whiteui); + setColor(Pal.accent); + margin(2f); - if(state.isCampaign()){ - if(net.client()){ - buttons.button("@gameover.disconnect", () -> { - logic.reset(); - net.reset(); - hide(); - state.set(State.menu); - }).size(170f, 60f); - }else{ - buttons.button("@continue", () -> { - hide(); - ui.planet.show(); - }).size(170f, 60f); - } - }else{ - buttons.button("@menu", () -> { - hide(); - logic.reset(); - }).size(140f, 60f); - } + FLabel statLabel = new FLabel(stat); + statLabel.setStyle(Styles.outlineLabel); + statLabel.setWrap(true); + statLabel.pause(); + + Label valueLabel = new Label("", Styles.outlineLabel); + valueLabel.setAlignment(Align.right); + + add(statLabel).left().growX().padLeft(5); + add(valueLabel).right().growX().padRight(5); + + actions( + Actions.scaleTo(0, 1), + Actions.delay(delay), + Actions.parallel( + Actions.scaleTo(1, 1, 0.3f, Interp.pow3Out), + Actions.color(Pal.darkestGray, 0.3f, Interp.pow3Out), + Actions.sequence( + Actions.delay(0.3f), + Actions.run(() -> { + valueLabel.update(() -> { + progress = Math.min(1, progress + (Time.delta / 60)); + valueLabel.setText("" + (int)Mathf.lerp(0, value, value < 10 ? progress : Interp.slowFast.apply(progress))); + }); + statLabel.resume(); + }) + ) + ) + ); } } }