From def1094357381e9c75dfe4dac8bf7b8e865713bb Mon Sep 17 00:00:00 2001 From: Anuken Date: Thu, 12 Aug 2021 10:07:30 -0400 Subject: [PATCH] Added world data progress bar --- core/src/mindustry/core/NetClient.java | 5 +++++ core/src/mindustry/net/Net.java | 4 ++++ core/src/mindustry/ui/fragments/LoadingFragment.java | 8 ++++++++ 3 files changed, 17 insertions(+) diff --git a/core/src/mindustry/core/NetClient.java b/core/src/mindustry/core/NetClient.java index 6d01275325..a73db1295d 100644 --- a/core/src/mindustry/core/NetClient.java +++ b/core/src/mindustry/core/NetClient.java @@ -507,6 +507,11 @@ public class NetClient implements ApplicationListener{ } } + /** Resets the world data timeout counter. */ + public void resetTimeout(){ + timeoutTime = 0f; + } + public boolean isConnecting(){ return connecting; } diff --git a/core/src/mindustry/net/Net.java b/core/src/mindustry/net/Net.java index 0dc711ea3d..9081b194f4 100644 --- a/core/src/mindustry/net/Net.java +++ b/core/src/mindustry/net/Net.java @@ -272,6 +272,10 @@ public class Net{ throw new RuntimeException("Received stream chunk without a StreamBegin beforehand!"); } builder.add(c.data); + + ui.loadfrag.setProgress(builder.progress()); + netClient.resetTimeout(); + if(builder.isDone()){ streams.remove(builder.id); handleClientReceived(builder.build()); diff --git a/core/src/mindustry/ui/fragments/LoadingFragment.java b/core/src/mindustry/ui/fragments/LoadingFragment.java index a5ab8eeff7..fcd18dfcbe 100644 --- a/core/src/mindustry/ui/fragments/LoadingFragment.java +++ b/core/src/mindustry/ui/fragments/LoadingFragment.java @@ -17,6 +17,7 @@ public class LoadingFragment extends Fragment{ private TextButton button; private Bar bar; private Label nameLabel; + private float progValue; @Override public void build(Group parent){ @@ -55,6 +56,13 @@ public class LoadingFragment extends Fragment{ bar.set(() -> ((int)(progress.get() * 100) + "%"), progress, Pal.accent); } + public void setProgress(float progress){ + progValue = progress; + if(!bar.visible){ + setProgress(() -> progValue); + } + } + public void setButton(Runnable listener){ button.visible = true; button.getListeners().remove(button.getListeners().size - 1);