From 6bd04b8d11ecd43412951d0d7846d0a0c68d9d37 Mon Sep 17 00:00:00 2001 From: sharlotte Date: Wed, 11 Aug 2021 12:13:33 +0900 Subject: [PATCH] clean up --- src/UnitInfo/SUtils.java | 18 ++++++++++++++---- src/UnitInfo/core/HudUi.java | 2 ++ src/UnitInfo/core/PlayerParser.java | 2 ++ src/UnitInfo/ui/SBar.java | 20 +++++++++----------- 4 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/UnitInfo/SUtils.java b/src/UnitInfo/SUtils.java index 393acf5..7b154e2 100644 --- a/src/UnitInfo/SUtils.java +++ b/src/UnitInfo/SUtils.java @@ -1,12 +1,12 @@ package UnitInfo; -import arc.graphics.g2d.NinePatch; -import arc.graphics.g2d.TextureAtlas; -import arc.scene.style.Drawable; -import arc.scene.style.ScaledNinePatchDrawable; +import arc.graphics.g2d.*; +import arc.scene.style.*; import arc.util.Strings; import mindustry.core.UI; +import java.lang.reflect.*; + public class SUtils { public static Drawable getDrawable(TextureAtlas.AtlasRegion region, int left, int right, int top, int bottom){ int[] splits = {left, right, top, bottom}; @@ -22,4 +22,14 @@ public class SUtils { if(String.valueOf(number).split("[.]")[1].matches("0")) return String.valueOf(number).split("[.]")[0]; return Strings.fixed(number, 1); } + + public static Object getFinalStatic(Field field) throws Exception { + field.setAccessible(true); + + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); + modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); + + return field.get(null); + } } diff --git a/src/UnitInfo/core/HudUi.java b/src/UnitInfo/core/HudUi.java index f1b02c2..ef8af57 100644 --- a/src/UnitInfo/core/HudUi.java +++ b/src/UnitInfo/core/HudUi.java @@ -1,7 +1,9 @@ package UnitInfo.core; +import UnitInfo.SUtils; import UnitInfo.ui.*; import arc.*; +import arc.func.Cons; import arc.graphics.*; import arc.graphics.g2d.*; import arc.input.*; diff --git a/src/UnitInfo/core/PlayerParser.java b/src/UnitInfo/core/PlayerParser.java index 6ec6460..681da42 100644 --- a/src/UnitInfo/core/PlayerParser.java +++ b/src/UnitInfo/core/PlayerParser.java @@ -12,6 +12,7 @@ import static UnitInfo.SVars.modRoot; public class PlayerParser{ ObjectMap> chats = new ObjectMap<>(); + public void setEvent() { Events.on(EventType.PlayerChatEvent.class, e -> { if(chats.containsKey(e.player)) chats.get(e.player).add(e.message); @@ -56,6 +57,7 @@ public class PlayerParser{ }); modRoot.child("players.hjson").writeString(data.toString(Stringify.HJSON)); } + public static class PlayerInfo{ Player player; Seq names = new Seq<>(); diff --git a/src/UnitInfo/ui/SBar.java b/src/UnitInfo/ui/SBar.java index 0387a70..cbfef5d 100644 --- a/src/UnitInfo/ui/SBar.java +++ b/src/UnitInfo/ui/SBar.java @@ -11,6 +11,7 @@ import arc.scene.*; import arc.scene.style.*; import arc.scene.ui.layout.*; import arc.util.Align; +import arc.util.Tmp; import mindustry.graphics.*; import mindustry.ui.*; @@ -111,27 +112,24 @@ public class SBar extends Element{ Draw.colorl(0.1f); bar.draw(x, y, width, height); - Draw.color(color.cpy().mul(Pal.lightishGray), blinkColor, blink); + Draw.color(Tmp.c1.set(color).mul(Pal.lightishGray), blinkColor, blink); float topWidth = width * value; if(topWidth > spriteWidth){ top.draw(x, y, topWidth, height); - }else{ - if(ScissorStack.push(scissor.set(x, y, topWidth, height))){ - top.draw(x, y, spriteWidth, height); - ScissorStack.pop(); - } + } else if(ScissorStack.push(scissor.set(x, y, topWidth, height))){ + top.draw(x, y, spriteWidth, height); + ScissorStack.pop(); } Draw.color(color, blinkColor, blink); float topWidthReal = width * (Math.min(value, computed)); if(topWidthReal > spriteWidth){ top.draw(x, y, topWidthReal, height); - }else{ - if(ScissorStack.push(scissor.set(x, y, topWidthReal, height))){ - top.draw(x, y, spriteWidth, height); - ScissorStack.pop(); - } + } else if(ScissorStack.push(scissor.set(x, y, topWidthReal, height))){ + top.draw(x, y, spriteWidth, height); + ScissorStack.pop(); } + Fonts.outline.draw(name, x + width / 2f, y + height * 0.75f, Color.white, Scl.scl(modUiScale < 1 ? modUiScale : 1), false, Align.center); } }