Skip to content

Commit

Permalink
anchor and align
Browse files Browse the repository at this point in the history
  • Loading branch information
deirn committed Feb 3, 2021
1 parent a172c2f commit 3e11a22
Show file tree
Hide file tree
Showing 5 changed files with 207 additions and 93 deletions.
105 changes: 74 additions & 31 deletions src/main/java/mcp/mobius/waila/api/impl/config/WailaConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,52 +130,95 @@ public boolean shouldDisplayFluids() {

public static class ConfigOverlay {

private float overlayPosX = 0.5F;
private float overlayPosY = 0.99F;
private SizeChoice overlaySize = SizeChoice.NORMAL;
private ConfigOverlayColor color = new ConfigOverlayColor();
private final Position position = new Position();
private float scale = 1.0F;
private final ConfigOverlayColor color = new ConfigOverlayColor();

public void setOverlayPosX(float overlayPosX) {
this.overlayPosX = overlayPosX;
public void setScale(float scale) {
this.scale = scale;
}

public void setOverlayPosY(float overlayPosY) {
this.overlayPosY = overlayPosY;
public Position getPosition() {
return position;
}

public void setOverlaySize(SizeChoice overlaySize) {
this.overlaySize = overlaySize;
public float getScale() {
return scale;
}

public float getOverlayPosX() {
return Math.min(Math.max(overlayPosX, 0.0F), 1.0F);
public ConfigOverlayColor getColor() {
return color;
}

public float getOverlayPosY() {
return Math.min(Math.max(overlayPosY, 0.0F), 1.0F);
}
public static class Position {

public SizeChoice getOverlaySize() {
return overlaySize;
}
private int x = 0;
private int y = 0;
private HorizontalAlignment alignX = HorizontalAlignment.CENTER;
private VerticalAlignment alignY = VerticalAlignment.TOP;
private HorizontalAlignment anchorX = HorizontalAlignment.CENTER;
private VerticalAlignment anchorY = VerticalAlignment.TOP;

public ConfigOverlayColor getColor() {
return color;
}
public void setX(int x) {
this.x = x;
}

public enum SizeChoice {
HALF(0.5F, 2.0F),
NORMAL(1.0F, 1.0F),
// DOUBLE(2.0F, 0.5F),
;
public void setY(int y) {
this.y = y;
}

public void setAlignX(HorizontalAlignment alignX) {
this.alignX = alignX;
}

public void setAlignY(VerticalAlignment alignY) {
this.alignY = alignY;
}

public void setAnchorX(HorizontalAlignment anchorX) {
this.anchorX = anchorX;
}

public float scale;
public float multiplier;
public void setAnchorY(VerticalAlignment anchorY) {
this.anchorY = anchorY;
}

SizeChoice(float scale, float multiplier) {
this.scale = scale;
this.multiplier = multiplier;
public int getX() {
return x;
}

public int getY() {
return y;
}

public HorizontalAlignment getAlignX() {
return alignX;
}

public VerticalAlignment getAlignY() {
return alignY;
}

public HorizontalAlignment getAnchorX() {
return anchorX;
}

public VerticalAlignment getAnchorY() {
return anchorY;
}

public enum VerticalAlignment {
TOP,
MIDDLE,
BOTTOM
}

public enum HorizontalAlignment {
LEFT,
CENTER,
RIGHT
}

}

public static class ConfigOverlayColor {
Expand Down
91 changes: 50 additions & 41 deletions src/main/java/mcp/mobius/waila/gui/GuiConfigWaila.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import net.minecraft.text.LiteralText;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Identifier;
import net.minecraft.util.Util;
import net.minecraft.util.math.MathHelper;
import org.apache.commons.lang3.StringEscapeUtils;

public class GuiConfigWaila extends GuiOptions {
Expand All @@ -25,99 +25,108 @@ public GuiConfigWaila(Screen parent) {
@Override
public OptionsListWidget getOptions() {
OptionsListWidget options = new OptionsListWidget(this, client, width + 45, height, 32, height - 32, 30, Waila.CONFIG::save);
options.add(new OptionsEntryButton(Util.createTranslationKey("config", new Identifier(Waila.MODID, "general")), new ButtonWidget(0, 0, 100, 20, LiteralText.EMPTY, w -> {
client.openScreen(new GuiOptions(GuiConfigWaila.this, new TranslatableText(Util.createTranslationKey("config", new Identifier(Waila.MODID, "general")))) {
options.add(new OptionsEntryButton("config.waila.general", new ButtonWidget(0, 0, 100, 20, LiteralText.EMPTY, w ->
client.openScreen(new GuiOptions(this, new TranslatableText("config.waila.general")) {
@Override
public OptionsListWidget getOptions() {
OptionsListWidget options = new OptionsListWidget(this, client, width + 45, height, 32, height - 32, 30);
options.add(new OptionsEntryValueBoolean(Util.createTranslationKey("config", new Identifier(Waila.MODID, "display_tooltip")), Waila.CONFIG.get().getGeneral().shouldDisplayTooltip(), val ->
options.add(new OptionsEntryValueBoolean("config.waila.display_tooltip", Waila.CONFIG.get().getGeneral().shouldDisplayTooltip(), val ->
Waila.CONFIG.get().getGeneral().setDisplayTooltip(val)
));
options.add(new OptionsEntryValueBoolean(Util.createTranslationKey("config", new Identifier(Waila.MODID, "display_fluids")), Waila.CONFIG.get().getGeneral().shouldDisplayFluids(), val ->
options.add(new OptionsEntryValueBoolean("config.waila.display_fluids", Waila.CONFIG.get().getGeneral().shouldDisplayFluids(), val ->
Waila.CONFIG.get().getGeneral().setDisplayFluids(val)
));
options.add(new OptionsEntryValueBoolean(Util.createTranslationKey("config", new Identifier(Waila.MODID, "sneaky_details")), Waila.CONFIG.get().getGeneral().shouldShiftForDetails(), val ->
options.add(new OptionsEntryValueBoolean("config.waila.sneaky_details", Waila.CONFIG.get().getGeneral().shouldShiftForDetails(), val ->
Waila.CONFIG.get().getGeneral().setShiftForDetails(val)
));
options.add(new OptionsEntryValueEnum<>(Util.createTranslationKey("config", new Identifier(Waila.MODID, "display_mode")), WailaConfig.DisplayMode.values(), Waila.CONFIG.get().getGeneral().getDisplayMode(), val ->
options.add(new OptionsEntryValueEnum<>("config.waila.display_mode", WailaConfig.DisplayMode.values(), Waila.CONFIG.get().getGeneral().getDisplayMode(), val ->
Waila.CONFIG.get().getGeneral().setDisplayMode(val)
));
options.add(new OptionsEntryValueBoolean(Util.createTranslationKey("config", new Identifier(Waila.MODID, "hide_from_players")), Waila.CONFIG.get().getGeneral().shouldHideFromPlayerList(), val ->
options.add(new OptionsEntryValueBoolean("config.waila.hide_from_players", Waila.CONFIG.get().getGeneral().shouldHideFromPlayerList(), val ->
Waila.CONFIG.get().getGeneral().setHideFromPlayerList(val)
));
options.add(new OptionsEntryValueBoolean(Util.createTranslationKey("config", new Identifier(Waila.MODID, "hide_from_debug")), Waila.CONFIG.get().getGeneral().shouldHideFromDebug(), val ->
options.add(new OptionsEntryValueBoolean("config.waila.hide_from_debug", Waila.CONFIG.get().getGeneral().shouldHideFromDebug(), val ->
Waila.CONFIG.get().getGeneral().setHideFromDebug(val)
));
options.add(new OptionsEntryValueBoolean(Util.createTranslationKey("config", new Identifier(Waila.MODID, "display_item")), Waila.CONFIG.get().getGeneral().shouldShowItem(), val ->
options.add(new OptionsEntryValueBoolean("config.waila.display_item", Waila.CONFIG.get().getGeneral().shouldShowItem(), val ->
Waila.CONFIG.get().getGeneral().setShowItem(val)
));
options.add(new OptionsEntryValueBoolean(Util.createTranslationKey("config", new Identifier(Waila.MODID, "tts")), Waila.CONFIG.get().getGeneral().shouldEnableTextToSpeech(), val ->
options.add(new OptionsEntryValueBoolean("config.waila.tts", Waila.CONFIG.get().getGeneral().shouldEnableTextToSpeech(), val ->
Waila.CONFIG.get().getGeneral().setEnableTextToSpeech(val)
));
return options;
}
});
})));
options.add(new OptionsEntryButton(Util.createTranslationKey("config", new Identifier(Waila.MODID, "overlay")), new ButtonWidget(0, 0, 100, 20, LiteralText.EMPTY, w -> {
client.openScreen(new GuiOptions(GuiConfigWaila.this, new TranslatableText(Util.createTranslationKey("config", new Identifier(Waila.MODID, "overlay")))) {
}))));
options.add(new OptionsEntryButton("config.waila.overlay", new ButtonWidget(0, 0, 100, 20, LiteralText.EMPTY, w ->
client.openScreen(new GuiOptions(this, new TranslatableText("config.waila.overlay")) {
@Override
public OptionsListWidget getOptions() {
OptionsListWidget options = new OptionsListWidget(this, client, width + 45, height, 32, height - 32, 30);
options.add(new OptionsEntryValueInput<>(Util.createTranslationKey("config", new Identifier(Waila.MODID, "overlay_pos_x")), Waila.CONFIG.get().getOverlay().getOverlayPosX(), val ->
Waila.CONFIG.get().getOverlay().setOverlayPosX(Math.min(1.0F, Math.max(0.0F, val)))
, OptionsEntryValueInput.FLOAT));
options.add(new OptionsEntryValueInput<>(Util.createTranslationKey("config", new Identifier(Waila.MODID, "overlay_pos_y")), Waila.CONFIG.get().getOverlay().getOverlayPosY(), val ->
Waila.CONFIG.get().getOverlay().setOverlayPosY(Math.min(1.0F, Math.max(0.0F, val)))
, OptionsEntryValueInput.FLOAT));
options.add(new OptionsEntryValueEnum<>(Util.createTranslationKey("config", new Identifier(Waila.MODID, "overlay_size")), WailaConfig.ConfigOverlay.SizeChoice.values(), Waila.CONFIG.get().getOverlay().getOverlaySize(), val ->
Waila.CONFIG.get().getOverlay().setOverlaySize(val)
));
options.add(new OptionsEntryButton(Util.createTranslationKey("config", new Identifier(Waila.MODID, "overlay_color")), new ButtonWidget(0, 0, 100, 20, LiteralText.EMPTY, w -> {
client.openScreen(new GuiOptions(GuiConfigWaila.this, new TranslatableText(Util.createTranslationKey("config", new Identifier(Waila.MODID, "overlay_color")))) {
options.add(new OptionsEntryButton("config.waila.overlay_pos", new ButtonWidget(0, 0, 100, 20, LiteralText.EMPTY, w ->
client.openScreen(new GuiOptions(this, new TranslatableText("config.waila.overlay_pos")) {
@Override
public OptionsListWidget getOptions() {
OptionsListWidget options = new OptionsListWidget(this, client, width + 45, height, 32, height - 32, 30);
options.add(new OptionsEntryValueInput<>("config.waila.overlay_pos_x", Waila.CONFIG.get().getOverlay().getPosition().getX(), val ->
Waila.CONFIG.get().getOverlay().getPosition().setX(val), OptionsEntryValueInput.INTEGER));
options.add(new OptionsEntryValueInput<>("config.waila.overlay_pos_y", Waila.CONFIG.get().getOverlay().getPosition().getY(), val ->
Waila.CONFIG.get().getOverlay().getPosition().setY(val), OptionsEntryValueInput.INTEGER));
options.add(new OptionsEntryValueEnum<>("config.waila.overlay_anchor_x", WailaConfig.ConfigOverlay.Position.HorizontalAlignment.values(), Waila.CONFIG.get().getOverlay().getPosition().getAnchorX(), val ->
Waila.CONFIG.get().getOverlay().getPosition().setAnchorX(val)));
options.add(new OptionsEntryValueEnum<>("config.waila.overlay_anchor_y", WailaConfig.ConfigOverlay.Position.VerticalAlignment.values(), Waila.CONFIG.get().getOverlay().getPosition().getAnchorY(), val ->
Waila.CONFIG.get().getOverlay().getPosition().setAnchorY(val)));
options.add(new OptionsEntryValueEnum<>("config.waila.overlay_align_x", WailaConfig.ConfigOverlay.Position.HorizontalAlignment.values(), Waila.CONFIG.get().getOverlay().getPosition().getAlignX(), val ->
Waila.CONFIG.get().getOverlay().getPosition().setAlignX(val)));
options.add(new OptionsEntryValueEnum<>("config.waila.overlay_align_y", WailaConfig.ConfigOverlay.Position.VerticalAlignment.values(), Waila.CONFIG.get().getOverlay().getPosition().getAlignY(), val ->
Waila.CONFIG.get().getOverlay().getPosition().setAlignY(val)));
return options;
}
}))));
options.add(new OptionsEntryValueInput<>("config.waila.overlay_scale", Waila.CONFIG.get().getOverlay().getScale(), val ->
Waila.CONFIG.get().getOverlay().setScale(MathHelper.clamp(val, 0.0F, 1.0F)), OptionsEntryValueInput.FLOAT));
options.add(new OptionsEntryButton("config.waila.overlay_color", new ButtonWidget(0, 0, 100, 20, LiteralText.EMPTY, w ->
client.openScreen(new GuiOptions(this, new TranslatableText("config.waila.overlay_color")) {
@Override
public OptionsListWidget getOptions() {
OptionsListWidget options = new OptionsListWidget(this, client, width + 45, height, 32, height - 32, 30);
options.add(new OptionsEntryValueInput<>(Util.createTranslationKey("config", new Identifier(Waila.MODID, "overlay_alpha")), Waila.CONFIG.get().getOverlay().getColor().getRawAlpha(), val ->
options.add(new OptionsEntryValueInput<>("config.waila.overlay_alpha", Waila.CONFIG.get().getOverlay().getColor().getRawAlpha(), val ->
Waila.CONFIG.get().getOverlay().getColor().setAlpha(Math.min(100, Math.max(0, val)))
, OptionsEntryValueInput.INTEGER));
options.add(new OptionsEntryValueCycle(Util.createTranslationKey("config", new Identifier(Waila.MODID, "overlay_theme")),
options.add(new OptionsEntryValueCycle("config.waila.overlay_theme",
Waila.CONFIG.get().getOverlay().getColor().getThemes().stream().map(t -> t.getId().toString()).sorted(String::compareToIgnoreCase).toArray(String[]::new),
Waila.CONFIG.get().getOverlay().getColor().getTheme().getId().toString(),
val ->
Waila.CONFIG.get().getOverlay().getColor().applyTheme(new Identifier(val))
));
return options;
}
});
})));
}))));
return options;
}
});
})));
options.add(new OptionsEntryButton(Util.createTranslationKey("config", new Identifier(Waila.MODID, "formatting")), new ButtonWidget(0, 0, 100, 20, LiteralText.EMPTY, w -> {
client.openScreen(new GuiOptions(GuiConfigWaila.this, new TranslatableText(Util.createTranslationKey("config", new Identifier(Waila.MODID, "overlay")))) {
}))));
options.add(new OptionsEntryButton("config.waila.formatting", new ButtonWidget(0, 0, 100, 20, LiteralText.EMPTY, w ->
client.openScreen(new GuiOptions(this, new TranslatableText("config.waila.overlay")) {
@Override
public OptionsListWidget getOptions() {
OptionsListWidget options = new OptionsListWidget(this, client, width + 45, height, 32, height - 32, 30);
options.add(new OptionsEntryValueInput<>(Util.createTranslationKey("config", new Identifier(Waila.MODID, "format_mod_name")), StringEscapeUtils.escapeJava(Waila.CONFIG.get().getFormatting().getModName()), val ->
options.add(new OptionsEntryValueInput<>("config.waila.format_mod_name", StringEscapeUtils.escapeJava(Waila.CONFIG.get().getFormatting().getModName()), val ->
Waila.CONFIG.get().getFormatting().setModName(val.isEmpty() || !val.contains("%s") ? Waila.CONFIG.get().getFormatting().getModName() : val)
));
options.add(new OptionsEntryValueInput<>(Util.createTranslationKey("config", new Identifier(Waila.MODID, "format_block_name")), StringEscapeUtils.escapeJava(Waila.CONFIG.get().getFormatting().getBlockName()), val ->
options.add(new OptionsEntryValueInput<>("config.waila.format_block_name", StringEscapeUtils.escapeJava(Waila.CONFIG.get().getFormatting().getBlockName()), val ->
Waila.CONFIG.get().getFormatting().setBlockName(val.isEmpty() || !val.contains("%s") ? Waila.CONFIG.get().getFormatting().getBlockName() : val)
));
options.add(new OptionsEntryValueInput<>(Util.createTranslationKey("config", new Identifier(Waila.MODID, "format_fluid_name")), StringEscapeUtils.escapeJava(Waila.CONFIG.get().getFormatting().getFluidName()), val ->
options.add(new OptionsEntryValueInput<>("config.waila.format_fluid_name", StringEscapeUtils.escapeJava(Waila.CONFIG.get().getFormatting().getFluidName()), val ->
Waila.CONFIG.get().getFormatting().setFluidName(val.isEmpty() || !val.contains("%s") ? Waila.CONFIG.get().getFormatting().getFluidName() : val)
));
options.add(new OptionsEntryValueInput<>(Util.createTranslationKey("config", new Identifier(Waila.MODID, "format_entity_name")), StringEscapeUtils.escapeJava(Waila.CONFIG.get().getFormatting().getEntityName()), val ->
options.add(new OptionsEntryValueInput<>("config.waila.format_entity_name", StringEscapeUtils.escapeJava(Waila.CONFIG.get().getFormatting().getEntityName()), val ->
Waila.CONFIG.get().getFormatting().setEntityName(val.isEmpty() || !val.contains("%s") ? Waila.CONFIG.get().getFormatting().getEntityName() : val)
));
options.add(new OptionsEntryValueInput<>(Util.createTranslationKey("config", new Identifier(Waila.MODID, "format_registry_name")), StringEscapeUtils.escapeJava(Waila.CONFIG.get().getFormatting().getRegistryName()), val ->
options.add(new OptionsEntryValueInput<>("config.waila.format_registry_name", StringEscapeUtils.escapeJava(Waila.CONFIG.get().getFormatting().getRegistryName()), val ->
Waila.CONFIG.get().getFormatting().setRegistryName(val.isEmpty() || !val.contains("%s") ? Waila.CONFIG.get().getFormatting().getRegistryName() : val)
));
return options;
}
});
})));
}))));
return options;
}

Expand Down
Loading

0 comments on commit 3e11a22

Please sign in to comment.