|
@@ -0,0 +1,144 @@
|
|
|
+package me.km.networking;
|
|
|
+
|
|
|
+import java.util.Collection;
|
|
|
+import java.util.LinkedList;
|
|
|
+import java.util.TreeMap;
|
|
|
+import net.minecraft.client.Minecraft;
|
|
|
+import net.minecraft.client.gui.Gui;
|
|
|
+import net.minecraft.client.gui.ScaledResolution;
|
|
|
+import net.minecraft.potion.PotionEffect;
|
|
|
+import net.minecraft.util.text.TextFormatting;
|
|
|
+import net.minecraft.util.text.translation.I18n;
|
|
|
+import net.minecraftforge.fml.relauncher.Side;
|
|
|
+import net.minecraftforge.fml.relauncher.SideOnly;
|
|
|
+
|
|
|
+@SideOnly(Side.CLIENT)
|
|
|
+public class StatusDisplayGui extends Gui
|
|
|
+{
|
|
|
+ public final static StatusDisplayGui INSTANCE = new StatusDisplayGui(Minecraft.getMinecraft());
|
|
|
+
|
|
|
+ private class LineData implements Comparable<LineData>
|
|
|
+ {
|
|
|
+ private int time;
|
|
|
+ private String text;
|
|
|
+
|
|
|
+ public LineData(int time, String text)
|
|
|
+ {
|
|
|
+ this.time = time;
|
|
|
+ this.text = text;
|
|
|
+ }
|
|
|
+
|
|
|
+ public LineData(String text)
|
|
|
+ {
|
|
|
+ this.time = Integer.MAX_VALUE;
|
|
|
+ this.text = text;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getText()
|
|
|
+ {
|
|
|
+ return text;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getTimeText()
|
|
|
+ {
|
|
|
+ return String.valueOf(time / 20);
|
|
|
+ }
|
|
|
+
|
|
|
+ public int getTimeWidth()
|
|
|
+ {
|
|
|
+ return time == Integer.MAX_VALUE ? 0 : mc.fontRenderer.getStringWidth(getTimeText());
|
|
|
+ }
|
|
|
+
|
|
|
+ public int getTextWidth()
|
|
|
+ {
|
|
|
+ return mc.fontRenderer.getStringWidth(text);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int compareTo(LineData o)
|
|
|
+ {
|
|
|
+ return -Integer.compare(time, o.time);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private TreeMap<Integer, LineData> strings;
|
|
|
+ private Minecraft mc;
|
|
|
+
|
|
|
+ public StatusDisplayGui(Minecraft mc)
|
|
|
+ {
|
|
|
+ this.mc = mc;
|
|
|
+ this.strings = new TreeMap<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void add(int i, String s)
|
|
|
+ {
|
|
|
+ strings.put(i, new LineData(s));
|
|
|
+ }
|
|
|
+
|
|
|
+ public void remove(int i)
|
|
|
+ {
|
|
|
+ strings.remove(i);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void clear()
|
|
|
+ {
|
|
|
+ strings.clear();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void paint()
|
|
|
+ {
|
|
|
+ Collection<PotionEffect> collection = this.mc.player.getActivePotionEffects();
|
|
|
+ if(strings.isEmpty() && collection.isEmpty())
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // getting data
|
|
|
+ LinkedList<LineData> list = new LinkedList<>(strings.values());
|
|
|
+ collection.forEach(effect ->
|
|
|
+ {
|
|
|
+ StringBuilder sb = new StringBuilder("s ");
|
|
|
+ if(effect.getPotion().isBadEffect())
|
|
|
+ {
|
|
|
+ sb.append(TextFormatting.RED);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sb.append(TextFormatting.GREEN);
|
|
|
+ }
|
|
|
+ sb.append(I18n.translateToLocal(effect.getEffectName()));
|
|
|
+ list.add(new LineData(effect.getDuration(), sb.toString()));
|
|
|
+ });
|
|
|
+ // sorting by time
|
|
|
+ list.sort(null);
|
|
|
+
|
|
|
+ int lineHeight = mc.fontRenderer.FONT_HEIGHT;
|
|
|
+ int height = 4 + lineHeight * (strings.size() + collection.size());
|
|
|
+
|
|
|
+ int maxTextWidth = 0;
|
|
|
+ int maxTimeWidth = 0;
|
|
|
+
|
|
|
+ for(LineData data : list)
|
|
|
+ {
|
|
|
+ maxTextWidth = Math.max(data.getTextWidth(), maxTextWidth);
|
|
|
+ maxTimeWidth = Math.max(data.getTimeWidth(), maxTimeWidth);
|
|
|
+ }
|
|
|
+
|
|
|
+ ScaledResolution scaledresolution = new ScaledResolution(mc);
|
|
|
+ int screenWidth = scaledresolution.getScaledWidth();
|
|
|
+
|
|
|
+ int x = screenWidth - maxTextWidth - maxTimeWidth - 4;
|
|
|
+ int y = 2;
|
|
|
+
|
|
|
+ drawRect(x, 0, screenWidth, height, 1342177280);
|
|
|
+
|
|
|
+ x += 2;
|
|
|
+ String time;
|
|
|
+
|
|
|
+ for(LineData data : list)
|
|
|
+ {
|
|
|
+ time = data.getTimeText();
|
|
|
+ mc.fontRenderer.drawString(time + data.getText(), x + maxTimeWidth - mc.fontRenderer.getStringWidth(time), y + 1, 0xFFFFFF);
|
|
|
+ y += lineHeight;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|