-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
59a2291
commit bb5d01b
Showing
20 changed files
with
403 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/main/java/rubyboat/clothconfigextensions/builders/ButtonBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package rubyboat.clothconfigextensions.builders; | ||
|
||
import net.minecraft.client.gui.widget.ButtonWidget; | ||
import net.minecraft.text.Text; | ||
import rubyboat.clothconfigextensions.entries.ButtonEntry; | ||
|
||
public class ButtonBuilder { | ||
Text value; | ||
Text id; | ||
ButtonWidget.PressAction onPress; | ||
int xbuffer = 0; | ||
|
||
public ButtonBuilder(Text component, Text value) { | ||
this.id = component; | ||
this.value = value; | ||
} | ||
|
||
public ButtonBuilder setOnPress(ButtonWidget.PressAction onPress) { | ||
this.onPress = onPress; | ||
return this; | ||
} | ||
|
||
public ButtonBuilder setWidthBuffer(int xbuffer) { | ||
this.xbuffer = xbuffer; | ||
return this; | ||
} | ||
|
||
public ButtonEntry build() { | ||
return new ButtonEntry(id, value, onPress, xbuffer); | ||
} | ||
} |
140 changes: 140 additions & 0 deletions
140
src/main/java/rubyboat/clothconfigextensions/configEntryBuilderExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
package rubyboat.clothconfigextensions; | ||
|
||
import me.shedaniel.clothconfig2.api.AbstractConfigListEntry; | ||
import me.shedaniel.clothconfig2.api.ConfigEntryBuilder; | ||
import me.shedaniel.clothconfig2.api.ModifierKeyCode; | ||
import me.shedaniel.clothconfig2.gui.entries.DropdownBoxEntry; | ||
import me.shedaniel.clothconfig2.impl.ConfigEntryBuilderImpl; | ||
import me.shedaniel.clothconfig2.impl.builders.*; | ||
import net.minecraft.text.Text; | ||
import rubyboat.clothconfigextensions.builders.ButtonBuilder; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
public class configEntryBuilderExtension implements ConfigEntryBuilder { | ||
|
||
@Override | ||
public Text getResetButtonKey() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public ConfigEntryBuilder setResetButtonKey(Text text) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public IntListBuilder startIntList(Text text, List<Integer> list) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public LongListBuilder startLongList(Text text, List<Long> list) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public FloatListBuilder startFloatList(Text text, List<Float> list) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public DoubleListBuilder startDoubleList(Text text, List<Double> list) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public StringListBuilder startStrList(Text text, List<String> list) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public SubCategoryBuilder startSubCategory(Text text) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public SubCategoryBuilder startSubCategory(Text text, List<AbstractConfigListEntry> list) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public BooleanToggleBuilder startBooleanToggle(Text text, boolean b) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public StringFieldBuilder startStrField(Text text, String s) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public ColorFieldBuilder startColorField(Text text, int i) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public TextFieldBuilder startTextField(Text text, String s) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public TextDescriptionBuilder startTextDescription(Text text) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public <T extends Enum<?>> EnumSelectorBuilder<T> startEnumSelector(Text text, Class<T> aClass, T t) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public <T> SelectorBuilder<T> startSelector(Text text, T[] ts, T t) { | ||
return null; | ||
} | ||
|
||
public ButtonBuilder startButtonBuilder(Text value) { | ||
return new ButtonBuilder(Text.of(UUID.randomUUID().toString()), value); | ||
} | ||
|
||
@Override | ||
public IntFieldBuilder startIntField(Text text, int i) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public LongFieldBuilder startLongField(Text text, long l) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public FloatFieldBuilder startFloatField(Text text, float v) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public DoubleFieldBuilder startDoubleField(Text text, double v) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public IntSliderBuilder startIntSlider(Text text, int i, int i1, int i2) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public LongSliderBuilder startLongSlider(Text text, long l, long l1, long l2) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public KeyCodeBuilder startModifierKeyCodeField(Text text, ModifierKeyCode modifierKeyCode) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public <T> DropdownMenuBuilder<T> startDropdownMenu(Text text, DropdownBoxEntry.SelectionTopCellElement<T> selectionTopCellElement, DropdownBoxEntry.SelectionCellCreator<T> selectionCellCreator) { | ||
return null; | ||
} | ||
} |
126 changes: 126 additions & 0 deletions
126
src/main/java/rubyboat/clothconfigextensions/entries/ButtonEntry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
package rubyboat.clothconfigextensions.entries; | ||
|
||
import com.google.common.collect.Lists; | ||
import me.shedaniel.clothconfig2.gui.AbstractConfigScreen; | ||
import me.shedaniel.clothconfig2.gui.entries.TooltipListEntry; | ||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.font.TextRenderer; | ||
import net.minecraft.client.gui.Element; | ||
import net.minecraft.client.gui.Selectable; | ||
import net.minecraft.client.gui.widget.ButtonWidget; | ||
import net.minecraft.client.util.math.MatrixStack; | ||
import net.minecraft.text.OrderedText; | ||
import net.minecraft.text.Style; | ||
import net.minecraft.text.Text; | ||
import org.jetbrains.annotations.ApiStatus; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.function.Supplier; | ||
|
||
@Environment(EnvType.CLIENT) | ||
public class ButtonEntry extends TooltipListEntry<Object> { | ||
public static final int LINE_HEIGHT = 12; | ||
private final TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer; | ||
Text buttonInnerText; | ||
private int savedWidth = -1; | ||
private int savedX = -1; | ||
private int savedY = -1; | ||
|
||
public int xbuffer; | ||
public int ybuffer; | ||
|
||
private final List<ButtonWidget> widgets; | ||
private ButtonWidget button; | ||
private List<OrderedText> wrappedLines; | ||
@ApiStatus.Internal | ||
@Deprecated | ||
public ButtonEntry(Text fieldName, Text text, ButtonWidget.PressAction onPress, int xbuffer) { | ||
this(fieldName, text, null, onPress, xbuffer); | ||
} | ||
|
||
@ApiStatus.Internal | ||
@Deprecated | ||
public ButtonEntry(Text fieldName, Text text, Supplier<Optional<Text[]>> tooltipSupplier, ButtonWidget.PressAction onPress, int xbuffer) { | ||
super(fieldName, tooltipSupplier); | ||
this.buttonInnerText = text; | ||
this.wrappedLines = Collections.emptyList(); | ||
this.button = new ButtonWidget(0, 0, MinecraftClient.getInstance().textRenderer.getWidth(text) + 6 + xbuffer, 20, text, onPress); | ||
widgets = Lists.newArrayList(button); | ||
} | ||
|
||
@Override | ||
public void render(MatrixStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean isHovered, float delta) { | ||
super.render(matrices, index, y, x, entryWidth, entryHeight, mouseX, mouseY, isHovered, delta); | ||
if (this.savedWidth != entryWidth || this.savedX != x || this.savedY != y) { | ||
this.wrappedLines = this.textRenderer.wrapLines(this.buttonInnerText, entryWidth); | ||
this.savedWidth = entryWidth; | ||
this.savedX = x; | ||
this.savedY = y; | ||
} | ||
button.x = getConfigScreen().width / 2 - button.getWidth() / 2; | ||
button.y = y; | ||
button.render(matrices, mouseX, mouseY, delta); | ||
|
||
|
||
Style style = this.getTextAt(mouseX, mouseY); | ||
AbstractConfigScreen configScreen = this.getConfigScreen(); | ||
if (style != null && configScreen != null) { | ||
configScreen.renderTextHoverEffect(matrices, style, mouseX, mouseY); | ||
} | ||
} | ||
|
||
@Override | ||
public int getItemHeight() { | ||
if (savedWidth == -1) return LINE_HEIGHT; | ||
int lineCount = this.wrappedLines.size(); | ||
return lineCount == 0 ? 0 : 15 + lineCount * LINE_HEIGHT; | ||
} | ||
|
||
@Override | ||
public List<? extends Selectable> narratables() { | ||
return null; | ||
} | ||
|
||
@Nullable | ||
private Style getTextAt(double x, double y) { | ||
int lineCount = this.wrappedLines.size(); | ||
|
||
if (lineCount > 0) { | ||
int textX = (int) Math.floor(x - this.savedX); | ||
int textY = (int) Math.floor(y - 4 - this.savedY); | ||
if (textX >= 0 && textY >= 0 && textX <= this.savedWidth && textY < LINE_HEIGHT * lineCount + lineCount) { | ||
int line = textY / LINE_HEIGHT; | ||
if (line < this.wrappedLines.size()) { | ||
OrderedText orderedText = this.wrappedLines.get(line); | ||
return this.textRenderer.getTextHandler().getStyleAt(orderedText, textX); | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public Object getValue() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Optional<Object> getDefaultValue() { | ||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public void save() { | ||
|
||
} | ||
|
||
@Override | ||
public List<? extends Element> children() { | ||
return widgets; | ||
} | ||
} |
Oops, something went wrong.