mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-02-21 20:33:10 +01:00
Add option to change the hud position
This commit is contained in:
parent
ed15923f28
commit
449862ca7e
5 changed files with 138 additions and 11 deletions
|
@ -7,6 +7,7 @@ import com.google.gson.GsonBuilder;
|
|||
import com.minelittlepony.common.util.GamePaths;
|
||||
import com.minelittlepony.common.util.registry.RegistryTypeAdapter;
|
||||
import com.minelittlepony.common.util.settings.*;
|
||||
import com.minelittlepony.unicopia.client.gui.HudPosition;
|
||||
|
||||
public class Config extends com.minelittlepony.common.util.settings.Config {
|
||||
public final Setting<Set<String>> speciesWhiteList = value("server", "speciesWhiteList", (Set<String>)new HashSet<String>())
|
||||
|
@ -42,6 +43,9 @@ public class Config extends com.minelittlepony.common.util.settings.Config {
|
|||
public final Setting<Integer> hudPage = value("client", "hudActivePage", 0)
|
||||
.addComment("The page of abilities currently visible in the HUD. You can change this in-game using the PG_UP and PG_DWN keys (configurable)");
|
||||
|
||||
public final Setting<HudPosition> hudPosition = value("client", "hudPosition", HudPosition.MAIN_HAND)
|
||||
.addComment("Location of the HUD on-screen");
|
||||
|
||||
public final Setting<Boolean> disableWaterPlantsFix = value("compatibility", "disableWaterPlantsFix", false)
|
||||
.addComment("Disables this mod's built in fix for making sea plants waterlogged")
|
||||
.addComment("Turn this ON if you're using another mod that does something similar of if you encounter copatibility issues with other mods.");
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
package com.minelittlepony.unicopia.client.gui;
|
||||
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
|
||||
public enum HudPosition {
|
||||
MAIN_HAND(Alignment.UNSET, Alignment.UNSET),
|
||||
OFF_HAND(Alignment.UNSET, Alignment.UNSET),
|
||||
|
||||
TOP_LEFT(Alignment.START, Alignment.START),
|
||||
TOP_CENTER(Alignment.MIDDLE, Alignment.START),
|
||||
TOP_RIGHT(Alignment.END, Alignment.START),
|
||||
|
||||
CENTER_LEFT(Alignment.START, Alignment.MIDDLE),
|
||||
CENTER_CENTER(Alignment.MIDDLE, Alignment.MIDDLE),
|
||||
CENTER_RIGHT(Alignment.END, Alignment.MIDDLE),
|
||||
|
||||
BOTTOM_LEFT(Alignment.START, Alignment.END),
|
||||
BOTTOM_CENTER(Alignment.MIDDLE, Alignment.END),
|
||||
BOTTOM_RIGHT(Alignment.END, Alignment.END);
|
||||
|
||||
private final Alignment horizontal;
|
||||
private final Alignment vertical;
|
||||
|
||||
HudPosition(Alignment horizontal, Alignment vertical) {
|
||||
this.horizontal = horizontal;
|
||||
this.vertical = vertical;
|
||||
}
|
||||
|
||||
public Alignment getHorizontal() {
|
||||
return horizontal;
|
||||
}
|
||||
|
||||
public Alignment getVertical() {
|
||||
return vertical;
|
||||
}
|
||||
|
||||
public enum Alignment {
|
||||
UNSET,
|
||||
START,
|
||||
MIDDLE,
|
||||
END;
|
||||
|
||||
public int getSignum() {
|
||||
return this == UNSET ? 0 : this == START ? -1 : 1;
|
||||
}
|
||||
|
||||
public Alignment opposite() {
|
||||
return (this == UNSET || this == MIDDLE) ? this : this == START ? END : START;
|
||||
}
|
||||
|
||||
public Alignment or(Alignment fallback) {
|
||||
return this == UNSET ? fallback : this;
|
||||
}
|
||||
|
||||
public int pick(int start, int middle, int end, int unset) {
|
||||
return switch(this) {
|
||||
case UNSET -> unset;
|
||||
case START -> start;
|
||||
case MIDDLE -> middle;
|
||||
case END -> end;
|
||||
};
|
||||
}
|
||||
|
||||
public int pick(int start, int end, int unset) {
|
||||
return switch(this) {
|
||||
case UNSET -> unset;
|
||||
case START -> start;
|
||||
case MIDDLE -> MathHelper.lerp(0.5F, start, end);
|
||||
case END -> end;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
|
@ -18,7 +18,9 @@ import net.minecraft.client.gui.screen.Screen;
|
|||
import net.minecraft.server.integrated.IntegratedServer;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Arm;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
|
||||
public class SettingsScreen extends GameGui {
|
||||
private final Config config = Unicopia.getConfig();
|
||||
|
@ -28,6 +30,8 @@ public class SettingsScreen extends GameGui {
|
|||
@Nullable
|
||||
private Style mineLpStatus;
|
||||
|
||||
private long drawingHudOutline;
|
||||
|
||||
public SettingsScreen(Screen parent) {
|
||||
super(Text.translatable("unicopia.options.title"), parent);
|
||||
|
||||
|
@ -68,16 +72,25 @@ public class SettingsScreen extends GameGui {
|
|||
})
|
||||
.getStyle().setText("unicopia.options.ignore_mine_lp");
|
||||
|
||||
row += 10;
|
||||
|
||||
mineLpStatus = content.addButton(new Label(LEFT, row += 10)).getStyle().setText(getMineLPStatus());
|
||||
|
||||
content.addButton(new Toggle(LEFT, row += 20, config.toggleAbilityKeys.get()))
|
||||
.onChange(config.toggleAbilityKeys)
|
||||
.getStyle().setText("unicopia.options.toggle_ability_keys");
|
||||
|
||||
mineLpStatus = content.addButton(new Label(LEFT, row += 10)).getStyle().setText(getMineLPStatus());
|
||||
content.addButton(new EnumSlider<>(LEFT, row += 20, config.hudPosition))
|
||||
.onChange(v -> {
|
||||
drawingHudOutline = System.currentTimeMillis() + 1000L;
|
||||
return config.hudPosition.set(v);
|
||||
})
|
||||
.setTextFormat(v -> Text.translatable("unicopia.options.hud_position", v.getValue().name()));
|
||||
|
||||
RegistryIndexer<Race> races = RegistryIndexer.of(Race.REGISTRY);
|
||||
|
||||
content.addButton(new Slider(LEFT, row += 25, 0, races.size(), races.indexOf(config.preferredRace.get())))
|
||||
.onChange(races.createSetter(config.preferredRace::set))
|
||||
.onChange(races.createSetter(config.preferredRace))
|
||||
.setTextFormat(v -> Text.translatable("unicopia.options.preferred_race", races.valueOf(v.getValue()).getDisplayName()));
|
||||
|
||||
IntegratedServer server = client.getServer();
|
||||
|
@ -112,6 +125,31 @@ public class SettingsScreen extends GameGui {
|
|||
public void render(DrawContext context, int mouseX, int mouseY, float tickDelta) {
|
||||
super.render(context, mouseX, mouseY, tickDelta);
|
||||
content.render(context, mouseX, mouseY, tickDelta);
|
||||
if (drawingHudOutline > System.currentTimeMillis()) {
|
||||
|
||||
int scaledWidth = client.getWindow().getScaledWidth();
|
||||
int scaledHeight = client.getWindow().getScaledHeight();
|
||||
|
||||
HudPosition selectedPos = config.hudPosition.get();
|
||||
|
||||
for (var hudPos : HudPosition.values()) {
|
||||
HudPosition.Alignment armAlignment = client.options.getMainArm().getValue() == Arm.LEFT ? HudPosition.Alignment.START : HudPosition.Alignment.END;
|
||||
if (hudPos == HudPosition.OFF_HAND) {
|
||||
armAlignment = armAlignment.opposite();
|
||||
}
|
||||
|
||||
int left = hudPos.getHorizontal().pick(2, scaledWidth - 50, ((scaledWidth - 50) / 2) + (109 * armAlignment.getSignum()));
|
||||
int top = hudPos.getVertical().pick(12, scaledHeight - 50, scaledHeight - 50);
|
||||
if (hudPos == HudPosition.BOTTOM_CENTER) {
|
||||
top -= 22;
|
||||
}
|
||||
|
||||
context.getMatrices().push();
|
||||
context.getMatrices().translate(left + UHud.PRIMARY_SLOT_SIZE / 2, top + UHud.PRIMARY_SLOT_SIZE / 2, 0);
|
||||
DrawableUtil.drawArc(context.getMatrices(), 0, UHud.PRIMARY_SLOT_SIZE / 2, 0, MathHelper.TAU, hudPos == selectedPos ? 0xEEFF00A5 : 0xEEFFFF25);
|
||||
context.getMatrices().pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -97,7 +97,14 @@ public class UHud {
|
|||
}
|
||||
|
||||
font = client.textRenderer;
|
||||
xDirection = client.player.getMainArm() == Arm.LEFT ? -1 : 1;
|
||||
|
||||
HudPosition hudPos = Unicopia.getConfig().hudPosition.get();
|
||||
HudPosition.Alignment armAlignment = client.player.getMainArm() == Arm.LEFT ? HudPosition.Alignment.START : HudPosition.Alignment.END;
|
||||
if (hudPos == HudPosition.OFF_HAND) {
|
||||
armAlignment = armAlignment.opposite();
|
||||
}
|
||||
|
||||
xDirection = hudPos.getHorizontal().or(armAlignment.opposite()).opposite().getSignum();
|
||||
|
||||
matrices.push();
|
||||
matrices.translate(scaledWidth / 2, scaledHeight / 2, 0);
|
||||
|
@ -111,11 +118,13 @@ public class UHud {
|
|||
matrices.pop();
|
||||
matrices.push();
|
||||
|
||||
int hudX = ((scaledWidth - 50) / 2) + (109 * xDirection);
|
||||
int hudY = scaledHeight - 50;
|
||||
int hudX = hudPos.getHorizontal().pick(2, scaledWidth - 50, ((scaledWidth - 50) / 2) + (109 * armAlignment.getSignum()));
|
||||
int hudY = hudPos.getVertical().pick(12, scaledHeight - 50, scaledHeight - 50);
|
||||
if (hudPos == HudPosition.BOTTOM_CENTER) {
|
||||
hudY -= 22;
|
||||
}
|
||||
int hudZ = hotbarZ;
|
||||
|
||||
|
||||
float exhaustion = pony.getMagicalReserves().getExhaustion().getPercentFill();
|
||||
|
||||
if (exhaustion > 0.5F || EquinePredicates.RAGING.test(client.player)) {
|
||||
|
@ -205,12 +214,14 @@ public class UHud {
|
|||
int progress = Math.min(255, (int)(time * 255F / 20F));
|
||||
|
||||
if (progress > 8) {
|
||||
int color = Colors.WHITE;
|
||||
int alpha = progress << 24 & -16777216;
|
||||
int color = ColorHelper.Argb.withAlpha(progress, Colors.WHITE);
|
||||
|
||||
color |= alpha;
|
||||
HudPosition hudPos = Unicopia.getConfig().hudPosition.get();
|
||||
|
||||
context.drawCenteredTextWithShadow(font, message, 25, -15, color);
|
||||
int messageWidth = font.getWidth(message);
|
||||
int messageX = hudPos.getHorizontal().pick(0, 25 - messageWidth/2, -messageWidth + 45, 25 - messageWidth/2);
|
||||
int messageY = hudPos.getVertical().pick(55, -17, -17, -17);
|
||||
context.drawText(font, message, messageX, messageY, color, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -374,7 +385,7 @@ public class UHud {
|
|||
}
|
||||
|
||||
public void tick() {
|
||||
if (messageTime > 0) {
|
||||
if (!client.isPaused() && messageTime > 0) {
|
||||
messageTime--;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1568,6 +1568,7 @@
|
|||
"unicopia.options.ignore_mine_lp.detected": "* Your detected race is %s",
|
||||
"unicopia.options.ignore_mine_lp.undetected": "* We will not use your detected race",
|
||||
"unicopia.options.preferred_race": "Preferred Race: %s",
|
||||
"unicopia.options.hud_position": "HUD Position: %s",
|
||||
"unicopia.options.whitelist": "Enable Whitelist",
|
||||
"unicopia.options.whitelist.race": "Allow %ss",
|
||||
"unicopia.options.whitelist.details": "* Select the races you wish to allow",
|
||||
|
|
Loading…
Reference in a new issue