-
-
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.
Add config screen and custom item use cooldown
- Loading branch information
Showing
10 changed files
with
304 additions
and
27 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
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
163 changes: 163 additions & 0 deletions
163
src/main/java/xyz/ryhon/replanterplus/ConfigScreen.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,163 @@ | ||
package xyz.ryhon.replanterplus; | ||
|
||
import java.util.function.Consumer; | ||
|
||
import net.minecraft.client.gui.DrawContext; | ||
import net.minecraft.client.gui.screen.ButtonTextures; | ||
import net.minecraft.client.gui.screen.Screen; | ||
import net.minecraft.client.gui.widget.ButtonWidget; | ||
import net.minecraft.client.gui.widget.SliderWidget; | ||
import net.minecraft.client.gui.widget.TextWidget; | ||
import net.minecraft.client.gui.widget.ToggleButtonWidget; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.Identifier; | ||
|
||
public class ConfigScreen extends Screen { | ||
Screen parent; | ||
|
||
SwitchButton enabledButton; | ||
SwitchButton sneakToggleButton; | ||
SimpleSlider tickDelaySlider; | ||
ButtonWidget doneButton; | ||
|
||
public ConfigScreen(Screen parent) { | ||
super(Text.empty()); | ||
this.parent = parent; | ||
} | ||
|
||
@Override | ||
protected void init() { | ||
super.init(); | ||
|
||
int buttonWidth = 48; | ||
int buttonHeight = 18; | ||
int panelWidth = 256; | ||
|
||
enabledButton = new SwitchButton( | ||
(width / 2) + (panelWidth / 2) - (buttonWidth), (height / 2) - (buttonHeight * 2), | ||
buttonWidth, buttonHeight, ReplanterPlus.enabled) { | ||
@Override | ||
public void setToggled(boolean toggled) { | ||
super.setToggled(toggled); | ||
ReplanterPlus.enabled = toggled; | ||
} | ||
}; | ||
addDrawableChild(enabledButton); | ||
addSelectableChild(enabledButton); | ||
TextWidget t = new TextWidget(Text.translatable("replanter.configscreen.enabled"), textRenderer); | ||
t.setPosition((width / 2) - (panelWidth / 2), | ||
enabledButton.getY() + (buttonHeight / 2) - (textRenderer.fontHeight / 2)); | ||
addDrawableChild(t); | ||
|
||
sneakToggleButton = new SwitchButton( | ||
enabledButton.getX(), enabledButton.getY() + enabledButton.getHeight(), | ||
enabledButton.getWidth(), enabledButton.getHeight(), | ||
ReplanterPlus.sneakToggle) { | ||
@Override | ||
public void setToggled(boolean toggled) { | ||
super.setToggled(toggled); | ||
ReplanterPlus.sneakToggle = toggled; | ||
} | ||
}; | ||
addDrawableChild(sneakToggleButton); | ||
addSelectableChild(sneakToggleButton); | ||
t = new TextWidget(Text.translatable("replanter.configscreen.sneakToggle"), textRenderer); | ||
t.setPosition((width / 2) - (panelWidth / 2), | ||
sneakToggleButton.getY() + (buttonHeight / 2) - (textRenderer.fontHeight / 2)); | ||
addDrawableChild(t); | ||
|
||
t = new TextWidget(Text.translatable("replanter.configscreen.tickDelay"), textRenderer); | ||
t.setPosition((width / 2) - (panelWidth / 2), | ||
sneakToggleButton.getY() + buttonHeight); | ||
addDrawableChild(t); | ||
|
||
tickDelaySlider = new SimpleSlider(0, 8); | ||
tickDelaySlider.setPosition(t.getX(), t.getY() + t.getHeight()); | ||
tickDelaySlider.setWidth(panelWidth); | ||
tickDelaySlider.setHeight(24); | ||
tickDelaySlider.setIValue(ReplanterPlus.useDelay); | ||
tickDelaySlider.onValue = (Long l) -> | ||
{ | ||
long i = l; | ||
ReplanterPlus.useDelay = (int)i; | ||
}; | ||
addDrawableChild(tickDelaySlider); | ||
addSelectableChild(tickDelaySlider); | ||
|
||
doneButton = ButtonWidget.builder(Text.translatable("replanter.configscreen.done"), (ButtonWidget b) -> { | ||
close(); | ||
}) | ||
.size(96, 24) | ||
.position((width / 2) - (96 / 2), tickDelaySlider.getY() + tickDelaySlider.getHeight() + 8) | ||
.build(); | ||
addDrawableChild(doneButton); | ||
addSelectableChild(doneButton); | ||
} | ||
|
||
public static class SimpleSlider extends SliderWidget { | ||
long min, max; | ||
long iValue; | ||
public Consumer<Long> onValue; | ||
|
||
public SimpleSlider(long min, long max) { | ||
super(0, 0, 0, 0, Text.empty(), 0); | ||
this.min = min; | ||
this.max = max; | ||
updateMessage(); | ||
} | ||
|
||
public void setIValue(long v) { | ||
iValue = v; | ||
setValue((v - min) / (double) (max - min)); | ||
} | ||
|
||
@Override | ||
protected void applyValue() { | ||
iValue = (long) Math.round(value * (max - min)) + min; | ||
setIValue(iValue); | ||
|
||
updateMessage(); | ||
if (onValue != null) | ||
onValue.accept(iValue); | ||
} | ||
|
||
@Override | ||
protected void updateMessage() { | ||
setMessage(Text.literal(iValue + " / " + max)); | ||
} | ||
} | ||
|
||
public class SwitchButton extends ToggleButtonWidget { | ||
private static final ButtonTextures TEXTURES = new ButtonTextures(new Identifier("widget/button"), | ||
new Identifier("widget/button"), new Identifier("widget/button_highlighted")); | ||
|
||
public SwitchButton(int x, int y, int width, int height, boolean toggled) { | ||
super(x, y, width, height, toggled); | ||
setTextures(TEXTURES); | ||
} | ||
|
||
@Override | ||
protected boolean clicked(double mouseX, double mouseY) { | ||
if (super.clicked(mouseX, mouseY)) { | ||
setToggled(!toggled); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public void render(DrawContext context, int mouseX, int mouseY, float delta) { | ||
super.render(context, mouseX, mouseY, delta); | ||
context.drawCenteredTextWithShadow(textRenderer, | ||
Text.translatable("replanter.switchbutton.label." + (toggled ? "on" : "off")), | ||
getX() + (width / 2), getY() + (height / 2) - (textRenderer.fontHeight / 2), | ||
toggled ? 0x00ff00 : 0xff0000); | ||
} | ||
} | ||
|
||
@Override | ||
public void close() { | ||
client.setScreen(parent); | ||
ReplanterPlus.saveConfig(); | ||
} | ||
} |
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,14 @@ | ||
package xyz.ryhon.replanterplus; | ||
|
||
import com.terraformersmc.modmenu.api.ConfigScreenFactory; | ||
import com.terraformersmc.modmenu.api.ModMenuApi; | ||
|
||
public class ModMenuAPIImpl implements ModMenuApi { | ||
@Override | ||
public ConfigScreenFactory<?> getModConfigScreenFactory() { | ||
return (currentScreen) -> | ||
{ | ||
return new ConfigScreen(currentScreen); | ||
}; | ||
} | ||
} |
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
15 changes: 0 additions & 15 deletions
15
src/main/java/xyz/ryhon/replanterplus/mixin/ExampleMixin.java
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,3 +1,12 @@ | ||
{ | ||
"replanter.gui.seed_not_found": ": item not in hotbar" | ||
"category.replanter": "Replanter Plus", | ||
"key.replanter.menu": "Open Config Scren", | ||
"key.replanter.toggle": "Toggle Replanter", | ||
"replanter.gui.seed_not_found": ": item not in hotbar", | ||
"replanter.configscreen.enabled": "Enabled", | ||
"replanter.configscreen.sneakToggle": "Disable When Sneaking", | ||
"replanter.configscreen.tickDelay": "Item Use Delay", | ||
"replanter.configscreen.done": "Done", | ||
"replanter.switchbutton.label.on": "on", | ||
"replanter.switchbutton.label.off": "off" | ||
} |
Oops, something went wrong.