From 6882a9a355b71e4faf8fe640c54b4795d5ee72d3 Mon Sep 17 00:00:00 2001 From: Anuken Date: Mon, 10 Feb 2020 20:22:03 -0500 Subject: [PATCH] Added persistent message server function --- .gitignore | 1 + core/src/mindustry/core/NetClient.java | 40 +++++++++++++++---- .../mindustry/ui/fragments/HudFragment.java | 25 ++++++++++++ gradle.properties | 2 +- 4 files changed, 60 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 17c1aab8e5..f230c07b3c 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,7 @@ logs/ /server/build/ changelog saves/ +/core/assets-raw/fontgen/out/ core/assets/saves/ /core/assets/saves/ steam_appid.txt diff --git a/core/src/mindustry/core/NetClient.java b/core/src/mindustry/core/NetClient.java index 6ecce095e9..270dfa0874 100644 --- a/core/src/mindustry/core/NetClient.java +++ b/core/src/mindustry/core/NetClient.java @@ -13,6 +13,7 @@ import mindustry.annotations.Annotations.*; import mindustry.core.GameState.*; import mindustry.ctype.*; import mindustry.entities.*; +import mindustry.entities.Effects.*; import mindustry.entities.traits.BuilderTrait.*; import mindustry.entities.traits.*; import mindustry.entities.type.*; @@ -261,36 +262,61 @@ public class NetClient implements ApplicationListener{ ui.loadfrag.hide(); } + @Remote(variants = Variant.both, unreliable = true) + public static void setHudText(String message){ + if(message == null) return; + + ui.hudfrag.setHudText(message); + } + + @Remote(variants = Variant.both) + public static void hideHudText(){ + ui.hudfrag.toggleHudText(false); + } + + /** TCP version */ + @Remote(variants = Variant.both) + public static void setHudTextReliable(String message){ + setHudText(message); + } + @Remote(variants = Variant.both) public static void onInfoMessage(String message){ + if(message == null) return; + ui.showText("", message); } - //TODO these are commented out to enforce compatibility with 103! uncomment before 104 release - /* - @Remote(variants = Variant.both) public static void onInfoPopup(String message, float duration, int align, int top, int left, int bottom, int right){ + if(message == null) return; + ui.showInfoPopup(message, duration, align, top, left, bottom, right); } @Remote(variants = Variant.both) - public static void onLabel(String info, float duration, float worldx, float worldy){ - ui.showLabel(info, duration, worldx, worldy); + public static void onLabel(String message, float duration, float worldx, float worldy){ + if(message == null) return; + + ui.showLabel(message, duration, worldx, worldy); } @Remote(variants = Variant.both, unreliable = true) public static void onEffect(Effect effect, float x, float y, float rotation, Color color){ + if(effect == null) return; + Effects.effect(effect, color, x, y, rotation); } @Remote(variants = Variant.both) public static void onEffectReliable(Effect effect, float x, float y, float rotation, Color color){ - Effects.effect(effect, color, x, y, rotation); - }*/ + onEffect(effect, x, y, rotation, color); + } @Remote(variants = Variant.both) public static void onInfoToast(String message, float duration){ + if(message == null) return; + ui.showInfoToast(message, duration); } diff --git a/core/src/mindustry/ui/fragments/HudFragment.java b/core/src/mindustry/ui/fragments/HudFragment.java index 3109179e1b..09f309dd5d 100644 --- a/core/src/mindustry/ui/fragments/HudFragment.java +++ b/core/src/mindustry/ui/fragments/HudFragment.java @@ -43,6 +43,9 @@ public class HudFragment extends Fragment{ private boolean shown = true; private float dsize = 47.2f; + private String hudText = ""; + private boolean showHudText; + private long lastToast; public void build(Group parent){ @@ -341,6 +344,19 @@ public class HudFragment extends Fragment{ t.add("$saveload").style(Styles.outlineLabel); }); + parent.fill(p -> { + p.top().table(Styles.black3, t -> t.margin(4).label(() -> hudText) + .style(Styles.outlineLabel)).padTop(10).visible(p.color.a >= 0.001f); + p.update(() -> { + p.color.a = Mathf.lerpDelta(p.color.a, Mathf.num(showHudText), 0.2f); + if(state.is(State.menu)){ + p.color.a = 0f; + showHudText = false; + } + }); + p.touchable(Touchable.disabled); + }); + blockfrag.build(parent); } @@ -368,6 +384,15 @@ public class HudFragment extends Fragment{ } } + public void setHudText(String text){ + showHudText = true; + hudText = text; + } + + public void toggleHudText(boolean shown){ + showHudText = shown; + } + private void scheduleToast(Runnable run){ long duration = (int)(3.5 * 1000); long since = Time.timeSinceMillis(lastToast); diff --git a/gradle.properties b/gradle.properties index 4aabb4e9b4..c56c42567f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ org.gradle.daemon=true org.gradle.jvmargs=-Xms256m -Xmx1024m -archash=b2996f736d5b6870913f5d8b5496fe6033069ac8 +archash=292d60e7d6c2013334b0f4f30659e1d885f73cfe