Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.util.List;

public class ModMenuEventHandler {
public static final Identifier MODS_BUTTON_TEXTURE = Identifier.fromNamespaceAndPath(ModMenu.MOD_ID, "textures/gui/mods_button.png");
private static KeyMapping MENU_KEY_MAPPING;

public static void register() {
Expand Down
73 changes: 46 additions & 27 deletions src/main/java/com/terraformersmc/modmenu/gui/ModsScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.terraformersmc.modmenu.config.ModMenuConfig;
import com.terraformersmc.modmenu.config.ModMenuConfigManager;
import com.terraformersmc.modmenu.gui.widget.DescriptionListWidget;
import com.terraformersmc.modmenu.gui.widget.LegacyTexturedButtonWidget;
import com.terraformersmc.modmenu.gui.widget.ModListWidget;
import com.terraformersmc.modmenu.gui.widget.entries.ModListEntry;
import com.terraformersmc.modmenu.util.DrawingUtil;
Expand All @@ -18,7 +17,12 @@
import net.fabricmc.loader.api.metadata.ModOrigin;
import net.minecraft.SharedConstants;
import net.minecraft.client.gui.GuiGraphicsExtractor;
import net.minecraft.client.gui.components.*;
import net.minecraft.client.gui.components.AbstractWidget;
import net.minecraft.client.gui.components.EditBox;
import net.minecraft.client.gui.components.SpriteIconButton;
import net.minecraft.client.gui.components.WidgetSprites;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.Tooltip;
import net.minecraft.client.gui.components.toasts.SystemToast;
import net.minecraft.client.gui.screens.ConfirmLinkScreen;
import net.minecraft.client.gui.screens.ConfirmScreen;
Expand Down Expand Up @@ -46,8 +50,12 @@
import java.util.stream.Collectors;

public class ModsScreen extends Screen {
private static final Identifier FILTERS_BUTTON_LOCATION = Identifier.fromNamespaceAndPath(ModMenu.MOD_ID, "textures/gui/filters_button.png");
private static final Identifier CONFIGURE_BUTTON_LOCATION = Identifier.fromNamespaceAndPath(ModMenu.MOD_ID, "textures/gui/configure_button.png");
private static final Identifier FILTERS_SPRITE_ENABLED = Identifier.fromNamespaceAndPath(ModMenu.MOD_ID, "filters/enabled");
private static final Identifier FILTERS_SPRITE_DISABLED= Identifier.fromNamespaceAndPath(ModMenu.MOD_ID, "filters/disabled");
private static final Identifier FILTERS_SPRITE_FOCUSED = Identifier.fromNamespaceAndPath(ModMenu.MOD_ID, "filters/focused");
private static final Identifier CONFIGURE_SPRITE_ENABLED = Identifier.fromNamespaceAndPath(ModMenu.MOD_ID, "configure/enabled");
private static final Identifier CONFIGURE_SPRITE_DISABLED = Identifier.fromNamespaceAndPath(ModMenu.MOD_ID, "configure/disabled");
private static final Identifier CONFIGURE_SPRITE_FOCUSED = Identifier.fromNamespaceAndPath(ModMenu.MOD_ID, "configure/focused");

private static final Logger LOGGER = LoggerFactory.getLogger("Mod Menu | ModsScreen");
private final Screen previousScreen;
Expand All @@ -67,11 +75,11 @@ public class ModsScreen extends Screen {
public final Set<String> showModChildren = new HashSet<>();

private EditBox searchBox;
private @Nullable AbstractWidget filtersButton;
private @Nullable SpriteIconButton filtersButton;
private AbstractWidget sortingButton;
private AbstractWidget librariesButton;
private ModListWidget modList;
private @Nullable AbstractWidget configureButton;
private @Nullable SpriteIconButton configureButton;
private AbstractWidget websiteButton;
private AbstractWidget issuesButton;
private DescriptionListWidget descriptionListWidget;
Expand Down Expand Up @@ -135,18 +143,21 @@ protected void init() {
this.updateFiltersX(true);

if (!ModMenuConfig.CONFIG_MODE.getValue()) {
this.filtersButton = LegacyTexturedButtonWidget.legacyTexturedBuilder(ModMenuScreenTexts.TOGGLE_FILTER_OPTIONS,
button -> {
this.setFilterOptionsShown(!this.filterOptionsShown);
}
this.filtersButton =
SpriteIconButton.builder(
ModMenuScreenTexts.TOGGLE_FILTER_OPTIONS,
button -> this.setFilterOptionsShown(!this.filterOptionsShown),
true
)
.position(this.paneWidth / 2 + searchBoxWidth / 2 - 20 / 2 + 2, 22)
.size(20, 20)
.uv(0, 0, 20)
.texture(FILTERS_BUTTON_LOCATION, 32, 64)
.tooltip(ModMenuScreenTexts.TOGGLE_FILTER_OPTIONS)
.sprite(new WidgetSprites(
FILTERS_SPRITE_ENABLED,
FILTERS_SPRITE_DISABLED,
FILTERS_SPRITE_FOCUSED
), 20, 20)
.build();

this.filtersButton.setTooltip(Tooltip.create(ModMenuScreenTexts.TOGGLE_FILTER_OPTIONS));
this.filtersButton.setPosition(this.paneWidth / 2 + searchBoxWidth / 2 - 20 / 2 + 2, 22);
}

// Sorting button
Expand All @@ -170,19 +181,27 @@ protected void init() {

// Configure button
if (!ModMenuConfig.HIDE_CONFIG_BUTTONS.getValue()) {
this.configureButton = LegacyTexturedButtonWidget.legacyTexturedBuilder(CommonComponents.EMPTY, button -> {
final String id = Objects.requireNonNull(selected).getMod().getId();
if (getModHasConfigScreen(id)) {
this.safelyOpenConfigScreen(id);
} else {
button.active = false;
}
})
.position(width - 24, RIGHT_PANE_Y)
.size(20, 20)
.uv(0, 0, 20)
.texture(CONFIGURE_BUTTON_LOCATION, 32, 64)
this.configureButton =
SpriteIconButton.builder(
ModMenuScreenTexts.CONFIGURE,
button -> {
final String id = Objects.requireNonNull(selected).getMod().getId();
if (getModHasConfigScreen(id)) {
this.safelyOpenConfigScreen(id);
} else {
button.active = false;
}
},
true
)
.size(20,20)
.sprite(new WidgetSprites(
CONFIGURE_SPRITE_ENABLED,
CONFIGURE_SPRITE_DISABLED,
CONFIGURE_SPRITE_FOCUSED
), 20, 20)
.build();
this.configureButton.setPosition(width - 24, RIGHT_PANE_Y);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there no way to set the position in the builder?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its not possible to do in the builder.

}

// Website button
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.terraformersmc.modmenu.gui.widget;


import com.terraformersmc.modmenu.ModMenu;
import com.terraformersmc.modmenu.config.ModMenuConfig;
import net.minecraft.client.gui.GuiGraphicsExtractor;
import net.minecraft.client.gui.components.SpriteIconButton;
import net.minecraft.client.gui.components.WidgetSprites;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.Identifier;
import org.jspecify.annotations.Nullable;

public class SmallModMenuButtonWidget extends SpriteIconButton.CenteredIcon {
public static final Identifier MODS_SPRITE_ENABLED = Identifier.fromNamespaceAndPath(ModMenu.MOD_ID, "mods/enabled");
public static final Identifier MODS_SPRITE_DISABLED = Identifier.fromNamespaceAndPath(ModMenu.MOD_ID, "mods/disabled");
public static final Identifier MODS_SPRITE_FOCUSED = Identifier.fromNamespaceAndPath(ModMenu.MOD_ID, "mods/focused");

public SmallModMenuButtonWidget(
int x,
int y,
int width,
int height,
Component message,
int spriteWidth,
int spriteHeight,
int spriteOffsetX,
int spriteOffsetY,
WidgetSprites sprite,
OnPress onPress,
@Nullable Component tooltip,
@Nullable CreateNarration narration,
boolean switchToLoadingAfterPress) {
super(width, height, message, spriteWidth, spriteHeight, spriteOffsetX, spriteOffsetY, sprite, onPress, tooltip, narration, switchToLoadingAfterPress);
this.setPosition(x, y);
}

@Override
public void extractContents(GuiGraphicsExtractor drawContext, int mouseX, int mouseY, float delta) {
super.extractContents(drawContext, mouseX, mouseY, delta);
if (ModMenuConfig.BUTTON_UPDATE_BADGE.getValue() && ModMenu.areModUpdatesAvailable() && getAlpha() >= 1.0f) {
UpdateAvailableBadge.renderBadge(drawContext, this.getX() + this.width - 5, this.getY() - 3);
}
}
}

This file was deleted.

Loading
Loading