mirror of
https://github.com/PuzzleMC/Puzzle.git
synced 2025-12-16 20:05:09 +01:00
First steps to 1.0.0
- Fix modmenu compat - Better Puzzle settings button based on MidnightLib - Partially fix puzzle-splashscreen
This commit is contained in:
@@ -7,22 +7,23 @@ import net.puzzlemc.gui.screen.PuzzleOptionsScreen;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class ModMenuIntegration implements ModMenuApi {
|
||||
|
||||
//Used to set the config screen for all modules //
|
||||
// @Override
|
||||
// public Map<String, ConfigScreenFactory<?>> getProvidedConfigScreenFactories() {
|
||||
// Map<String, ConfigScreenFactory<?>> map = ImmutableMap.of();
|
||||
// map.put("puzzle",PuzzleOptionsScreen::new);
|
||||
// map.put("puzzle-gui",PuzzleOptionsScreen::new);
|
||||
// map.put("puzzle-blocks",PuzzleOptionsScreen::new);
|
||||
// map.put("puzzle-base",PuzzleOptionsScreen::new);
|
||||
// map.put("puzzle-models",PuzzleOptionsScreen::new);
|
||||
// map.put("puzzle-randomentities",PuzzleOptionsScreen::new);
|
||||
// map.put("puzzle-splashscreen",PuzzleOptionsScreen::new);
|
||||
// return map;
|
||||
// }
|
||||
@Override
|
||||
public Map<String, ConfigScreenFactory<?>> getProvidedConfigScreenFactories() {
|
||||
Map<String, ConfigScreenFactory<?>> map = new HashMap<>();
|
||||
map.put("puzzle",PuzzleOptionsScreen::new);
|
||||
map.put("puzzle-gui",PuzzleOptionsScreen::new);
|
||||
map.put("puzzle-blocks",PuzzleOptionsScreen::new);
|
||||
map.put("puzzle-base",PuzzleOptionsScreen::new);
|
||||
map.put("puzzle-models",PuzzleOptionsScreen::new);
|
||||
map.put("puzzle-randomentities",PuzzleOptionsScreen::new);
|
||||
map.put("puzzle-splashscreen",PuzzleOptionsScreen::new);
|
||||
return map;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
package net.puzzlemc.gui.mixin;
|
||||
|
||||
import eu.midnightdust.lib.util.screen.TexturedOverlayButtonWidget;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.puzzlemc.gui.PuzzleClient;
|
||||
import net.puzzlemc.gui.screen.PuzzleOptionsScreen;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.screen.option.OptionsScreen;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
@@ -15,15 +17,16 @@ import java.util.Objects;
|
||||
|
||||
@Mixin(OptionsScreen.class)
|
||||
public class MixinOptionsScreen extends Screen {
|
||||
private static final Identifier PUZZLE_ICON_TEXTURE = new Identifier(PuzzleClient.id, "textures/gui/puzzle_button.png");
|
||||
|
||||
protected MixinOptionsScreen(Text title) {
|
||||
super(title);
|
||||
}
|
||||
|
||||
@Inject(at = @At("TAIL"),method = "init")
|
||||
public void init(CallbackInfo ci) {
|
||||
PuzzleOptionsScreen puzzleScreen = new PuzzleOptionsScreen(this);
|
||||
this.addDrawableChild(new ButtonWidget(this.width / 2 - 155, this.height / 6 + 144 - 6, 150, 20, new TranslatableText("puzzle.screen.title").append("..."), (button) -> Objects.requireNonNull(this.client).setScreen(puzzleScreen)));
|
||||
@Inject(at = @At("HEAD"), method = "init")
|
||||
private void midnightlib$init(CallbackInfo ci) {
|
||||
this.addDrawableChild(new TexturedOverlayButtonWidget(this.width / 2 - 178, this.height / 6 - 12, 20, 20, 0, 0, 20, PUZZLE_ICON_TEXTURE, 32, 64, (buttonWidget) -> {
|
||||
(Objects.requireNonNull(this.client)).setScreen(new PuzzleOptionsScreen(this));
|
||||
}, new TranslatableText("midnightlib.overview.title")));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
package net.puzzlemc.gui.screen.widget;
|
||||
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
public class DummyButtonWidget extends ButtonWidget {
|
||||
public DummyButtonWidget() {
|
||||
super(-1,-1,0,0,Text.of(""),null);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package net.puzzlemc.gui.screen.widget;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
@@ -10,8 +9,8 @@ import net.minecraft.client.gui.Selectable;
|
||||
import net.minecraft.client.gui.widget.ClickableWidget;
|
||||
import net.minecraft.client.gui.widget.ElementListWidget;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
import java.util.*;
|
||||
@@ -33,7 +32,7 @@ public class PuzzleOptionListWidget extends ElementListWidget<PuzzleOptionListWi
|
||||
public void addAll(List<PuzzleWidget> buttons) {
|
||||
for (PuzzleWidget button : buttons) {
|
||||
if (button.buttonType == ButtonType.TEXT) {
|
||||
this.addButton(new DummyButtonWidget(), button.descriptionText);
|
||||
this.addButton(null, button.descriptionText);
|
||||
} else if (button.buttonType == ButtonType.BUTTON) {
|
||||
this.addButton(new PuzzleButtonWidget(this.width / 2 - 155 + 160, 0, 150, 20, button.buttonTextAction, button.onPress), button.descriptionText);
|
||||
} else if (button.buttonType == ButtonType.SLIDER) {
|
||||
@@ -53,38 +52,30 @@ public class PuzzleOptionListWidget extends ElementListWidget<PuzzleOptionListWi
|
||||
return super.getScrollbarPositionX() + 60;
|
||||
}
|
||||
|
||||
public Optional<ClickableWidget> getHoveredButton(double mouseX, double mouseY) {
|
||||
for (ButtonEntry buttonEntry : this.children()) {
|
||||
for (ClickableWidget widget : buttonEntry.buttons) {
|
||||
if (widget.isMouseOver(mouseX, mouseY)) {
|
||||
return Optional.of(widget);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public static class ButtonEntry extends ElementListWidget.Entry<ButtonEntry> {
|
||||
private static final TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer;
|
||||
private final List<ClickableWidget> buttons;
|
||||
private final Map<ClickableWidget, Text> buttonsWithText;
|
||||
private List<ClickableWidget> buttons = new ArrayList<>();
|
||||
private final ClickableWidget button;
|
||||
private final Text text;
|
||||
|
||||
private ButtonEntry(ImmutableMap<ClickableWidget, Text> buttons) {
|
||||
this.buttons = buttons.keySet().asList();
|
||||
this.buttonsWithText = buttons;
|
||||
private ButtonEntry(ClickableWidget button, Text text) {
|
||||
if (button != null)
|
||||
this.buttons.add(button);
|
||||
this.button = button;
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public static ButtonEntry create(ClickableWidget button, Text text) {
|
||||
return new ButtonEntry(ImmutableMap.of(button, text));
|
||||
return new ButtonEntry(button, text);
|
||||
}
|
||||
|
||||
public void render(MatrixStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) {
|
||||
this.buttonsWithText.forEach((button, text) -> {
|
||||
if (button != null) {
|
||||
button.y = y;
|
||||
button.render(matrices, mouseX, mouseY, tickDelta);
|
||||
if (button instanceof DummyButtonWidget) drawCenteredText(matrices,textRenderer, text,x + 200,y+5,0xFFFFFF);
|
||||
else drawTextWithShadow(matrices,textRenderer, text,x+15,y+5,0xFFFFFF);
|
||||
});
|
||||
}
|
||||
if (button == null) drawCenteredText(matrices,textRenderer, new LiteralText("------ ").append(text).append(" ------"),x + 200,y+5,0xFFFFFF);
|
||||
else drawTextWithShadow(matrices,textRenderer, text,x+15,y+5,0xFFFFFF);
|
||||
}
|
||||
|
||||
public List<? extends Element> children() {
|
||||
|
||||
Reference in New Issue
Block a user