-
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
537 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
src/main/java/de/hysky/skyblocker/config/HudConfigScreen.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package de.hysky.skyblocker.config; | ||
|
||
import de.hysky.skyblocker.skyblock.tabhud.widget.Widget; | ||
import de.hysky.skyblocker.utils.render.RenderHelper; | ||
import it.unimi.dsi.fastutil.ints.IntIntImmutablePair; | ||
import it.unimi.dsi.fastutil.ints.IntIntPair; | ||
import net.minecraft.client.gui.DrawContext; | ||
import net.minecraft.client.gui.screen.Screen; | ||
import net.minecraft.text.Text; | ||
|
||
import java.awt.*; | ||
|
||
public abstract class HudConfigScreen extends Screen { | ||
private final Widget widget; | ||
private final Screen parent; | ||
|
||
private int hudX = 0; | ||
private int hudY = 0; | ||
public HudConfigScreen(Text title, Widget widget, Screen parent) { | ||
super(title); | ||
this.widget = widget; | ||
this.parent = parent; | ||
|
||
int[] posFromConfig = getPosFromConfig(SkyblockerConfigManager.get()); | ||
hudX = posFromConfig[0]; | ||
hudY = posFromConfig[1]; | ||
} | ||
|
||
@Override | ||
public void render(DrawContext context, int mouseX, int mouseY, float delta) { | ||
super.render(context, mouseX, mouseY, delta); | ||
renderBackground(context, mouseX, mouseY, delta); | ||
renderWidget(context, hudX, hudY); | ||
context.drawCenteredTextWithShadow(textRenderer, "Right Click To Reset Position", width / 2, height / 2, Color.GRAY.getRGB()); | ||
} | ||
|
||
@Override | ||
public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) { | ||
IntIntPair dims = getDimensions(); | ||
if (RenderHelper.pointIsInArea(mouseX, mouseY, hudX, hudY, hudX + dims.leftInt(), hudY + dims.rightInt()) && button == 0) { | ||
hudX = (int) Math.max(Math.min(mouseX - (double) dims.leftInt() / 2, this.width - dims.leftInt()), 0); | ||
hudY = (int) Math.max(Math.min(mouseY - (double) dims.rightInt() / 2, this.height - dims.rightInt()), 0); | ||
} | ||
return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY); | ||
} | ||
|
||
@Override | ||
public boolean mouseClicked(double mouseX, double mouseY, int button) { | ||
if (button == 1) { | ||
IntIntPair dims = getDimensions(); | ||
hudX = this.width / 2 - dims.leftInt(); | ||
hudY = this.height / 2 - dims.rightInt(); | ||
} | ||
return super.mouseClicked(mouseX, mouseY, button); | ||
} | ||
|
||
abstract protected int[] getPosFromConfig(SkyblockerConfig config); | ||
|
||
protected IntIntPair getDimensions() { | ||
return new IntIntImmutablePair(widget.getHeight(), widget.getWidth()); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
SkyblockerConfig skyblockerConfig = SkyblockerConfigManager.get(); | ||
savePos(skyblockerConfig, hudX, hudY); | ||
SkyblockerConfigManager.save(); | ||
|
||
client.setScreen(parent); | ||
} | ||
|
||
/** | ||
* This method should save the passed position to the config | ||
* <p> | ||
* NOTE: The parent class will call {@link SkyblockerConfigManager#save()} right after this method | ||
* @param configManager the config so you don't have to get it | ||
* @param x x | ||
* @param y y | ||
*/ | ||
abstract protected void savePos(SkyblockerConfig configManager, int x, int y); | ||
|
||
abstract protected void renderWidget(DrawContext context, int x, int y); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/main/java/de/hysky/skyblocker/skyblock/end/EndHudConfigScreen.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package de.hysky.skyblocker.skyblock.end; | ||
|
||
import de.hysky.skyblocker.config.HudConfigScreen; | ||
import de.hysky.skyblocker.config.SkyblockerConfig; | ||
import de.hysky.skyblocker.config.SkyblockerConfigManager; | ||
import net.minecraft.client.gui.DrawContext; | ||
import net.minecraft.client.gui.screen.Screen; | ||
import net.minecraft.text.Text; | ||
|
||
public class EndHudConfigScreen extends HudConfigScreen { | ||
public EndHudConfigScreen(Screen parent) { | ||
super(Text.literal("End HUD Config"), EndHudWidget.INSTANCE, parent); | ||
} | ||
|
||
@Override | ||
protected int[] getPosFromConfig(SkyblockerConfig config) { | ||
return new int[]{ | ||
config.locations.end.x, | ||
config.locations.end.y, | ||
}; | ||
} | ||
|
||
@Override | ||
protected void savePos(SkyblockerConfig configManager, int x, int y) { | ||
configManager.locations.end.x = x; | ||
configManager.locations.end.y = y; | ||
} | ||
|
||
@Override | ||
protected void renderWidget(DrawContext context, int x, int y) { | ||
EndHudWidget.INSTANCE.setX(x); | ||
EndHudWidget.INSTANCE.setY(y); | ||
EndHudWidget.INSTANCE.render(context, SkyblockerConfigManager.get().locations.end.enableBackground); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
src/main/java/de/hysky/skyblocker/skyblock/end/EndHudWidget.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package de.hysky.skyblocker.skyblock.end; | ||
|
||
import de.hysky.skyblocker.config.SkyblockerConfigManager; | ||
import de.hysky.skyblocker.skyblock.tabhud.widget.Widget; | ||
import de.hysky.skyblocker.skyblock.tabhud.widget.component.IcoTextComponent; | ||
import de.hysky.skyblocker.skyblock.tabhud.widget.component.PlainTextComponent; | ||
import net.minecraft.enchantment.Enchantments; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.item.Items; | ||
import net.minecraft.text.MutableText; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.Formatting; | ||
|
||
import java.text.NumberFormat; | ||
|
||
public class EndHudWidget extends Widget { | ||
private static final MutableText TITLE = Text.literal("The End").formatted(Formatting.LIGHT_PURPLE, Formatting.BOLD); | ||
|
||
public static final EndHudWidget INSTANCE = new EndHudWidget(TITLE, Formatting.DARK_PURPLE.getColorValue()); | ||
|
||
public EndHudWidget(MutableText title, Integer colorValue) { | ||
super(title, colorValue); | ||
this.setX(5); | ||
this.setY(5); | ||
this.update(); | ||
} | ||
|
||
private static final ItemStack ENDERMAN_HEAD = new ItemStack(Items.PLAYER_HEAD); | ||
private static final ItemStack POPPY = new ItemStack(Items.POPPY); | ||
|
||
static { | ||
ENDERMAN_HEAD.getOrCreateNbt().putString("SkullOwner", "MHF_Enderman"); | ||
POPPY.addEnchantment(Enchantments.INFINITY, 1); | ||
|
||
INSTANCE.setX(SkyblockerConfigManager.get().locations.end.x); | ||
INSTANCE.setY(SkyblockerConfigManager.get().locations.end.y); | ||
} | ||
|
||
|
||
@Override | ||
public void updateContent() { | ||
// Zealots | ||
addComponent(new IcoTextComponent(ENDERMAN_HEAD, Text.literal("Zealots").formatted(Formatting.BOLD))); | ||
addComponent(new PlainTextComponent(Text.translatable("skyblocker.end.hud.zealotsSinceLastEye", TheEnd.zealotsSinceLastEye))); | ||
addComponent(new PlainTextComponent(Text.translatable("skyblocker.end.hud.zealotsTotalKills", TheEnd.zealotsKilled))); | ||
NumberFormat instance = NumberFormat.getInstance(); | ||
instance.setMinimumFractionDigits(0); | ||
instance.setMaximumFractionDigits(2); | ||
String avg = TheEnd.eyes == 0 ? "???" : instance.format((float)TheEnd.zealotsKilled / TheEnd.eyes); | ||
addComponent(new PlainTextComponent(Text.translatable("skyblocker.end.hud.avgKillsPerEye", avg))); | ||
|
||
// Endstone protector | ||
addComponent(new IcoTextComponent(POPPY, Text.literal("Endstone Protector").formatted(Formatting.BOLD))); | ||
if (TheEnd.stage == 5) { | ||
addComponent(new PlainTextComponent(Text.translatable("skyblocker.end.hud.stage", "IMMINENT"))); | ||
} else { | ||
addComponent(new PlainTextComponent(Text.translatable("skyblocker.end.hud.stage", String.valueOf(TheEnd.stage)))); | ||
} | ||
if (TheEnd.currentProtectorLocation == null) { | ||
addComponent(new PlainTextComponent(Text.translatable("skyblocker.end.hud.location", "?"))); | ||
} else { | ||
addComponent(new PlainTextComponent(Text.translatable("skyblocker.end.hud.location", TheEnd.currentProtectorLocation.name()))); | ||
} | ||
} | ||
} |
Oops, something went wrong.