Skip to content

Commit

Permalink
switch back to 1.19.2
Browse files Browse the repository at this point in the history
  • Loading branch information
uku3lig committed Dec 12, 2022
1 parent 9822c42 commit 825d458
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 26 deletions.
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://modmuss50.me/fabric.html
minecraft_version=1.19.3
yarn_mappings=1.19.3+build.3
minecraft_version=1.19.2
yarn_mappings=1.19.2+build.28
loader_version=0.14.11

# Mod Properties
Expand All @@ -14,4 +14,4 @@ archives_base_name=ukulib

# Dependencies
toml4j_version=0.7.2
fabric_version=0.69.0+1.19.3
fabric_version=0.69.0+1.19.2
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
drawCenteredTextWithShadow(matrices, textRenderer, Text.of("There was an issue with this config screen.").asOrderedText(), width / 2, 100, 0xFFFFFF);
drawCenteredTextWithShadow(matrices, textRenderer, Text.of("Please report this issue to the mod author.").asOrderedText(), width / 2, 100 + textRenderer.fontHeight + 4, 0xFFFFFF);

this.addDrawableChild(ButtonWidget.builder(Text.of("Upload logs to mclo.gs"), button -> uploadLogs())
.dimensions(this.width / 2 - 100, this.height - 51, 200, 20).build());
this.addDrawableChild(new ButtonWidget(this.width / 2 - 100, this.height - 51, 200, 20, Text.of("Upload logs to mclo.gs"), button -> uploadLogs()));
this.addDrawableChild(Ukutils.doneButton(this.width, this.height, this.parent));
super.render(matrices, mouseX, mouseY, delta);
}
Expand Down
41 changes: 34 additions & 7 deletions src/main/java/net/uku3lig/ukulib/config/impl/EntrypointList.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@
import net.minecraft.client.gui.Element;
import net.minecraft.client.gui.Selectable;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.tooltip.Tooltip;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.ClickableWidget;
import net.minecraft.client.gui.widget.ElementListWidget;
import net.minecraft.client.util.OrderableTooltip;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.OrderedText;
import net.minecraft.text.Text;
import net.uku3lig.ukulib.api.UkulibAPI;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

/**
* A widget to display the list of mods that have integrated with Ukulib. <br>
Expand All @@ -29,6 +32,16 @@ public void addAll(Collection<EntrypointContainer<UkulibAPI>> containers, Screen
containers.stream().map(container -> new ModEntry(container, this.width, parent)).forEach(this::addEntry);
}

public Optional<ClickableWidget> getHoveredButton(double mouseX, double mouseY) {
for (ModEntry entry : this.children()) {
if (entry.button.isMouseOver(mouseX, mouseY)) {
return Optional.of(entry.button);
}
}

return Optional.empty();
}

@Override
public int getRowWidth() {
return 400;
Expand All @@ -43,11 +56,7 @@ public final class ModEntry extends ElementListWidget.Entry<ModEntry> {
private final ButtonWidget button;

public ModEntry(EntrypointContainer<UkulibAPI> container, int width, Screen parent) {
button = ButtonWidget.builder(Text.of(container.getProvider().getMetadata().getName()),
b -> client.setScreen(container.getEntrypoint().supplyConfigScreen().apply(parent)))
.dimensions(width / 2 - 100, 0, 200, 20)
.tooltip(Tooltip.of(Text.of(container.getProvider().getMetadata().getDescription())))
.build();
button = new ModButton(container, width, parent);
}

@Override
Expand All @@ -62,8 +71,26 @@ public List<? extends Element> children() {

@Override
public void render(MatrixStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) {
button.setY(y);
button.y = y;
button.render(matrices, mouseX, mouseY, tickDelta);
}
}

/**
* Simple button that has a cool tooltip :D
*/
private final class ModButton extends ButtonWidget implements OrderableTooltip {
private final String tooltip;

public ModButton(EntrypointContainer<UkulibAPI> container, int width, Screen parent) {
super(width / 2 - 100, 0, 200, 20, Text.of(container.getProvider().getMetadata().getName()),
b -> client.setScreen(container.getEntrypoint().supplyConfigScreen().apply(parent)));
this.tooltip = container.getProvider().getMetadata().getDescription();
}

@Override
public List<OrderedText> getOrderedTooltip() {
return client.textRenderer.wrapLines(Text.of(tooltip), 200);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.entrypoint.EntrypointContainer;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawableHelper;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.option.GameOptionsScreen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.ClickableWidget;
import net.minecraft.client.util.OrderableTooltip;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.screen.ScreenTexts;
import net.minecraft.text.OrderedText;
import net.minecraft.text.Text;
import net.uku3lig.ukulib.api.UkulibAPI;
import net.uku3lig.ukulib.utils.Ukutils;

import java.util.Collections;
import java.util.List;
import java.util.Optional;

/**
* Ukulib's config screen. Shows all the mods that have integrated with Ukulib.
Expand All @@ -27,6 +34,7 @@ public UkulibConfigScreen(Screen parent) {
}

@Override
@SuppressWarnings("ConstantConditions")
protected void init() {
super.init();

Expand All @@ -35,14 +43,22 @@ protected void init() {
entrypointList.addAll(containers, this);
this.addSelectableChild(entrypointList);

this.addDrawableChild(Ukutils.doneButton(this.width, this.height, this.parent));
this.addDrawableChild(new ButtonWidget(this.width / 2 - 100, this.height - 27, 200, 20, ScreenTexts.DONE, button -> this.client.setScreen(this.parent)));
}

@Override
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
this.renderBackground(matrices);
entrypointList.render(matrices, mouseX, mouseY, delta);
drawCenteredText(matrices, textRenderer, title, width / 2, 20, 0xFFFFFF);
this.entrypointList.render(matrices, mouseX, mouseY, delta);
DrawableHelper.drawCenteredText(matrices, textRenderer, title, width / 2, 20, 0xFFFFFF);
super.render(matrices, mouseX, mouseY, delta);

List<OrderedText> list = getHoveredButtonTooltip(mouseX, mouseY);
this.renderOrderedTooltip(matrices, list, mouseX, mouseY);
}

private List<OrderedText> getHoveredButtonTooltip(int mouseX, int mouseY) {
Optional<ClickableWidget> optional = entrypointList.getHoveredButton(mouseX, mouseY);
return optional.isPresent() && optional.get() instanceof OrderableTooltip tooltip ? tooltip.getOrderedTooltip() : Collections.emptyList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@

import lombok.extern.slf4j.Slf4j;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawableHelper;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.option.GameOptionsScreen;
import net.minecraft.client.gui.widget.ButtonListWidget;
import net.minecraft.client.option.SimpleOption;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.OrderedText;
import net.minecraft.text.Text;
import net.uku3lig.ukulib.config.ConfigManager;
import net.uku3lig.ukulib.config.IConfig;
import net.uku3lig.ukulib.config.impl.BrokenConfigScreen;
import net.uku3lig.ukulib.utils.Ukutils;

import java.util.List;

/**
* A screen used to edit a config.
* Instances of this class should NOT be reused.
Expand Down Expand Up @@ -81,7 +85,12 @@ protected void drawFooterButtons() {

@Override
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
render(matrices, buttonList, mouseX, mouseY, delta);
this.renderBackground(matrices);
this.buttonList.render(matrices, mouseX, mouseY, delta);
DrawableHelper.drawCenteredText(matrices, this.textRenderer, this.title, this.width / 2, 20, 0xFFFFFF);
super.render(matrices, mouseX, mouseY, delta);
List<OrderedText> list = GameOptionsScreen.getHoveredButtonTooltip(this.buttonList, mouseX, mouseY);
this.renderOrderedTooltip(matrices, list, mouseX, mouseY);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ protected PositionSelectScreen(Screen parent, int x, int y, ConfigManager<?> man
@Override
protected void init() {
int textWidth = textRenderer.getWidth(ScreenTexts.DONE);
this.addDrawableChild(ButtonWidget.builder(ScreenTexts.DONE, b -> close())
.dimensions(this.width - 20 - textWidth, 10, 10 + textWidth, 20)
.build());
this.addDrawableChild(new ButtonWidget(this.width - 20 - textWidth, 10, 10 + textWidth, 20, ScreenTexts.DONE, b -> close()));
}

@Override
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/uku3lig/ukulib/utils/IconButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ public IconButton(int x, int y, int width, int height, int u, int v, int hovered
@Override
public void renderButton(MatrixStack matrices, int mouseX, int mouseY, float delta) {
// i love stealing minecraft's code
RenderSystem.setShader(GameRenderer::getPositionTexProgram);
RenderSystem.setShader(GameRenderer::getPositionTexShader);
RenderSystem.setShaderTexture(0, WIDGETS_TEXTURE);
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, this.alpha);
int i = this.getYImage(this.isHovered());
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
RenderSystem.enableDepthTest();
this.drawTexture(matrices, this.getX(), this.getY(), 0, 46 + i * 20, this.width / 2, this.height);
this.drawTexture(matrices, this.getX() + this.width / 2, this.getY(), 200 - this.width / 2, 46 + i * 20, this.width / 2, this.height);
this.drawTexture(matrices, this.x, this.y, 0, 46 + i * 20, this.width / 2, this.height);
this.drawTexture(matrices, this.x + this.width / 2, this.y, 200 - this.width / 2, 46 + i * 20, this.width / 2, this.height);

super.renderButton(matrices, mouseX, mouseY, delta);
}
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/net/uku3lig/ukulib/utils/Ukutils.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,8 @@ public static SimpleOption<Boolean> createOpenButton(String key, Text text, Unar
* @return The generated button
*/
public static ButtonWidget doneButton(int width, int height, Screen parent) {
return ButtonWidget.builder(ScreenTexts.DONE, button -> MinecraftClient.getInstance().setScreen(parent))
.dimensions(width / 2 - 100, height - 27, 200, 20)
.build();
return new ButtonWidget(width / 2 - 100, height - 27, 200, 20, ScreenTexts.DONE,
button -> MinecraftClient.getInstance().setScreen(parent));
}

/**
Expand Down

0 comments on commit 825d458

Please sign in to comment.