GameOverDialog rework (#6783)

* GameOverDialog rework

* cleanup
This commit is contained in:
Goobrr
2022-05-08 09:26:49 -04:00
committed by GitHub
parent e94e31aedf
commit 0f3780dbb2
3 changed files with 123 additions and 51 deletions
+7 -7
View File
@@ -76,13 +76,13 @@ schematic.tagdelconfirm = Delete this tag completely?
schematic.tagexists = That tag already exists. schematic.tagexists = That tag already exists.
stats = Stats stats = Stats
stat.wave = Waves Defeated:[accent] {0} stat.wave = Waves Defeated
stat.unitsCreated = Units Created:[accent] {0} stat.unitsCreated = Units Created
stat.enemiesDestroyed = Enemies Destroyed:[accent] {0} stat.enemiesDestroyed = Enemies Destroyed
stat.built = Buildings Built:[accent] {0} stat.built = Buildings Built
stat.destroyed = Buildings Destroyed:[accent] {0} stat.destroyed = Buildings Destroyed
stat.deconstructed = Buildings Deconstructed:[accent] {0} stat.deconstructed = Buildings Deconstructed
stat.playtime = Time Played:[accent] {0} stat.playtime = Time Played
globalitems = [accent]Total Items globalitems = [accent]Total Items
map.delete = Are you sure you want to delete the map "[accent]{0}[]"? map.delete = Are you sure you want to delete the map "[accent]{0}[]"?
+1
View File
@@ -136,3 +136,4 @@ Evolveye
Jerzy Paciorkiewicz Jerzy Paciorkiewicz
YozoZChomutova YozoZChomutova
Qendolin Qendolin
Goobrr
+115 -44
View File
@@ -1,19 +1,38 @@
package mindustry.ui.dialogs; package mindustry.ui.dialogs;
import arc.*; 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.core.GameState.*;
import mindustry.game.EventType.*; import mindustry.game.EventType.*;
import mindustry.game.*; import mindustry.game.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.ui.*;
import static mindustry.Vars.*; import static mindustry.Vars.*;
public class GameOverDialog extends BaseDialog{ public class GameOverDialog extends BaseDialog{
private Team winner; private Team winner;
private boolean hudShown;
public GameOverDialog(){ public GameOverDialog(){
super("@gameover"); super("@gameover");
setFillParent(true); 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()); Events.on(ResetEvent.class, e -> hide());
} }
@@ -29,7 +48,6 @@ public class GameOverDialog extends BaseDialog{
} }
void rebuild(){ void rebuild(){
title.setText(state.isCampaign() ? Core.bundle.format("sector.lost", state.getSector().name()) : "@gameover");
buttons.clear(); buttons.clear();
cont.clear(); cont.clear();
@@ -37,55 +55,108 @@ public class GameOverDialog extends BaseDialog{
if(state.rules.pvp && winner != null){ if(state.rules.pvp && winner != null){
cont.add(Core.bundle.format("gameover.pvp", winner.localized())).pad(6); 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", () -> { buttons.button("@menu", () -> {
hide(); hide();
logic.reset(); logic.reset();
}).size(130f, 60f); }).size(140f, 60f);
}else{ }
if(control.isHighScore()){ }
cont.add("@highscore").pad(6);
cont.row();
}
cont.pane(t -> { private void addStat(Table parent, String stat, int value, float delay){
t.margin(13f); parent.add(new StatLabel(stat, value, delay)).top().pad(5).growX().height(50).row();
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();
}
if(state.isCampaign() && net.client()){ private static class StatLabel extends Table {
t.add("@gameover.waiting").padTop(20f).row(); 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()){ FLabel statLabel = new FLabel(stat);
if(net.client()){ statLabel.setStyle(Styles.outlineLabel);
buttons.button("@gameover.disconnect", () -> { statLabel.setWrap(true);
logic.reset(); statLabel.pause();
net.reset();
hide(); Label valueLabel = new Label("", Styles.outlineLabel);
state.set(State.menu); valueLabel.setAlignment(Align.right);
}).size(170f, 60f);
}else{ add(statLabel).left().growX().padLeft(5);
buttons.button("@continue", () -> { add(valueLabel).right().growX().padRight(5);
hide();
ui.planet.show(); actions(
}).size(170f, 60f); Actions.scaleTo(0, 1),
} Actions.delay(delay),
}else{ Actions.parallel(
buttons.button("@menu", () -> { Actions.scaleTo(1, 1, 0.3f, Interp.pow3Out),
hide(); Actions.color(Pal.darkestGray, 0.3f, Interp.pow3Out),
logic.reset(); Actions.sequence(
}).size(140f, 60f); 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();
})
)
)
);
} }
} }
} }