Skip to content

Commit

Permalink
Update to malilib changes
Browse files Browse the repository at this point in the history
  • Loading branch information
maruohon committed Feb 19, 2022
1 parent e08d159 commit 8ae65da
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 28 deletions.
1 change: 1 addition & 0 deletions src/main/java/fi/dy/masa/minihud/InitHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class InitHandler implements InitializationHandler
public void registerModHandlers()
{
Registry.CONFIG_MANAGER.registerConfigHandler(BaseModConfig.createDefaultModConfig(Reference.MOD_INFO, Configs.CONFIG_VERSION, Configs.CATEGORIES));
Registry.CONFIG_SCREEN.registerConfigScreenFactory(Reference.MOD_INFO, ConfigScreen::create);
Registry.CONFIG_TAB.registerConfigTabProvider(Reference.MOD_INFO, ConfigScreen::getConfigTabs);

Registry.CONFIG_WIDGET.registerConfigWidgetFactory(InfoLine.class, InfoLineConfigWidget::new);
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/fi/dy/masa/minihud/gui/ConfigScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import javax.annotation.Nullable;
import com.google.common.collect.ImmutableList;
import net.minecraft.client.gui.GuiScreen;
import fi.dy.masa.malilib.config.group.PopupConfigGroup;
import fi.dy.masa.malilib.config.option.ConfigInfo;
import fi.dy.masa.malilib.config.option.GenericButtonConfig;
import fi.dy.masa.malilib.config.util.ConfigUtils;
Expand Down Expand Up @@ -54,7 +55,14 @@ public class ConfigScreen

public static void open()
{
BaseScreen.openScreen(create(null));
BaseScreen.openScreen(create());
}

public static BaseConfigScreen create()
{
// The parent screen should not be set here, to prevent infinite recursion via
// the call to the parent's setWorldAndResolution -> initScreen -> switch tab -> etc.
return new BaseConfigScreen(MOD_INFO, null, ALL_TABS, INFO_LINES, "minihud.gui.title.configs");
}

public static BaseConfigScreen create(@Nullable GuiScreen currentScreen)
Expand All @@ -72,7 +80,7 @@ public static ImmutableList<ConfigTab> getConfigTabs()
private static ImmutableList<ConfigInfo> getGenericOptions()
{
ArrayList<ConfigInfo> genericOptions = new ArrayList<>(Configs.Generic.OPTIONS);
ArrayList<ConfigInfo> colorOptions = new ArrayList<>(Configs.Generic.OPTIONS);
ArrayList<ConfigInfo> colorOptions = new ArrayList<>(Configs.Colors.OPTIONS);
ArrayList<ConfigInfo> lightOptions = new ArrayList<>();

ListUtils.extractEntriesToSecondList(genericOptions, lightOptions, (c) -> c.getName().startsWith("lightLevel"), true);
Expand All @@ -83,6 +91,7 @@ private static ImmutableList<ConfigInfo> getGenericOptions()
ConfigScreen::openHudSettingScreen,
"minihud.config.comment.info_lines_hud_settings"));
genericOptions.add(new ExpandableConfigGroup(MOD_INFO, "light_level", lightOptions));
genericOptions.add(new PopupConfigGroup(MOD_INFO, "light_level", lightOptions));
ConfigUtils.sortConfigsByDisplayName(genericOptions);

return ImmutableList.copyOf(genericOptions);
Expand Down
23 changes: 11 additions & 12 deletions src/main/java/fi/dy/masa/minihud/gui/GuiShapeEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ protected void initScreen()

this.createShapeEditorElements(x, y);

GenericButton button = new GenericButton(ConfigScreen.SHAPES.getDisplayName());
GenericButton button = GenericButton.create(ConfigScreen.SHAPES.getDisplayName());
button.setPosition(x, this.height - 24);
button.setActionListener(() -> {
BaseConfigScreen.setCurrentTab(Reference.MOD_ID, ConfigScreen.SHAPES);
Expand Down Expand Up @@ -157,7 +157,7 @@ private void createShapeEditorElementsSphereBase(int x, int y, boolean addRadius
x += 11;
y += 54;

GenericButton button = new GenericButton("malilib.gui.button.render_layers_gui.set_to_player");
GenericButton button = GenericButton.create("malilib.button.render_layers.set_to_player");
button.setPosition(x, y);
button.setActionListener(() -> {
Entity entity = this.mc.getRenderViewEntity();
Expand Down Expand Up @@ -200,12 +200,11 @@ private void createShapeEditorElementDoubleField(int x, int y, DoubleSupplier su

if (addButton)
{
String hover = StringUtils.translate("malilib.gui.button.hover.plus_minus_tip");
GenericButton button = GenericButton.createIconOnly(() -> DefaultIcons.BTN_PLUSMINUS_16);
GenericButton button = GenericButton.create(DefaultIcons.BTN_PLUSMINUS_16);
button.setPosition(x + 54, y);
button.setActionListener(new DoubleModifierButtonListener(supplier, new DualDoubleConsumer(consumer, (val) -> txtField.setText(String.valueOf(supplier.getAsDouble())) )));
button.setCanScrollToClick(true);
button.addHoverStrings(hover);
button.translateAndAddHoverString("malilib.gui.button.hover.plus_minus_tip");
this.addWidget(button);
}
}
Expand All @@ -224,12 +223,11 @@ private void createShapeEditorElementIntField(int x, int y, IntSupplier supplier

if (addButton)
{
String hover = StringUtils.translate("malilib.gui.button.hover.plus_minus_tip");
GenericButton button = GenericButton.createIconOnly(() -> DefaultIcons.BTN_PLUSMINUS_16);
GenericButton button = GenericButton.create(DefaultIcons.BTN_PLUSMINUS_16);
button.setPosition(x + 54, y);
button.setActionListener(new IntegerModifierButtonListener(supplier, new DualIntConsumer(consumer, (val) -> txtField.setText(String.valueOf(supplier.getAsInt())) )));
button.setCanScrollToClick(true);
button.addHoverStrings(hover);
button.translateAndAddHoverString("malilib.gui.button.hover.plus_minus_tip");
this.addWidget(button);
}
}
Expand All @@ -241,9 +239,10 @@ private void createDirectionButton(int x, int y, Supplier<EnumFacing> supplier,
y += 10;

String name = org.apache.commons.lang3.StringUtils.capitalize(supplier.get().toString().toLowerCase());
GenericButton button = new GenericButton(50, 20, name);
button.setPosition(x, y);
GenericButton button = GenericButton.create(50, 20, name);
button.setActionListener((btn) -> { consumer.accept(PositionUtils.cycleDirection(supplier.get(), btn == 1)); this.initGui(); return true; });
button.setPosition(x, y);

this.addWidget(button);
}

Expand All @@ -253,9 +252,9 @@ private void createRenderTypeButton(int x, int y, Supplier<ShapeRenderType> supp
this.addLabel(x, y, 0xFFFFFFFF, translationKey);
y += 10;

GenericButton button = new GenericButton(supplier.get().getDisplayName());
button.setPosition(x, y);
GenericButton button = GenericButton.create(supplier.get().getDisplayName());
button.setActionListener((btn) -> { consumer.accept(ListUtils.getNextEntry(ShapeRenderType.VALUES, supplier.get(), btn != 0)); this.initGui(); return true; });
button.setPosition(x, y);
this.addWidget(button);
}

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/fi/dy/masa/minihud/gui/GuiShapeManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,9 @@ protected void initScreen()
button.setPosition(x, y + 1);
this.addWidget(button);

button = new GenericButton("minihud.gui.button.add_shape");
button = GenericButton.create("minihud.gui.button.add_shape", this::addShape);
button.setRight(rightX - 10);
button.setY(y);
button.setActionListener(this::addShape);
this.addWidget(button);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ public void reAddSubWidgets()
{
super.reAddSubWidgets();

this.addWidget(this.textField);
this.addWidget(this.booleanButton);
this.addWidget(this.hotkeyButton);
this.addWidget(this.settingsWidget);
this.addWidget(this.resetButton);
}

@Override
public void updateSubWidgetsToGeometryChanges()
{
super.updateSubWidgetsToGeometryChanges();

int x = this.getElementsStartPosition();
int y = this.getY();
int elementWidth = this.getElementWidth();
Expand All @@ -91,12 +103,6 @@ public void reAddSubWidgets()
x += this.settingsWidget.getWidth() + 4;
this.updateResetButton(x, y);
this.updateButtonStates();

this.addWidget(this.textField);
this.addWidget(this.booleanButton);
this.addWidget(this.hotkeyButton);
this.addWidget(this.settingsWidget);
this.addWidget(this.resetButton);
}

@Override
Expand All @@ -121,10 +127,12 @@ public boolean wasModified()
protected void updateButtonStates()
{
this.booleanButton.setEnabled(this.config.getBooleanConfig().isLocked() == false);
this.booleanButton.updateDisplayString();
this.booleanButton.updateButtonState();
this.booleanButton.updateHoverStrings();
this.hotkeyButton.updateDisplayString();

this.hotkeyButton.updateButtonState();
this.hotkeyButton.updateHoverStrings();

this.resetButton.setEnabled(this.config.isModified() && this.config.getBooleanConfig().isLocked() == false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,12 @@ public boolean wasModified()
protected void updateButtonStates()
{
this.booleanButton.setEnabled(this.config.getBooleanConfig().isLocked() == false);
this.booleanButton.updateDisplayString();
this.booleanButton.updateButtonState();
this.booleanButton.updateHoverStrings();
this.hotkeyButton.updateDisplayString();

this.hotkeyButton.updateButtonState();
this.hotkeyButton.updateHoverStrings();

this.resetButton.setEnabled(this.config.isModified() && this.config.getBooleanConfig().isLocked() == false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ public WidgetShapeEntry(int x, int y, int width, int height, int listIndex,

this.setText(StyledTextLine.of(shape.getDisplayName()));

this.configureButton = new GenericButton("minihud.gui.button.configure");
this.toggleButton = OnOffButton.simpleSlider(20, this.shape::isEnabled, this::toggleShapeEnabled);
this.removeButton = new GenericButton("minihud.gui.button.remove");

this.configureButton = GenericButton.create("minihud.gui.button.configure");
this.configureButton.setActionListener(() -> {
GuiShapeEditor gui = new GuiShapeEditor(this.shape);
gui.setParent(GuiUtils.getCurrentScreen());
BaseScreen.openScreen(gui);
});

this.removeButton = GenericButton.create("minihud.gui.button.remove");
this.removeButton.setActionListener(() -> {
ShapeManager.INSTANCE.removeShape(this.shape);
this.listWidget.refreshEntries();
Expand Down

0 comments on commit 8ae65da

Please sign in to comment.