aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/shedaniel/rei/gui/config/ConfigScreen.java
diff options
context:
space:
mode:
authorDaniel She <shekwancheung0528@gmail.com>2019-02-25 21:18:26 +0800
committerGitHub <noreply@github.com>2019-02-25 21:18:26 +0800
commit9e55b44b710f38c63a4bfd17d0b07318d5c68535 (patch)
treea2cc0c519b4327028d7b8f544ba5171fff2d8dc1 /src/main/java/me/shedaniel/rei/gui/config/ConfigScreen.java
parentb7e018527db2e9cae2db4226f6af9fc34054c964 (diff)
downloadRoughlyEnoughItems-9e55b44b710f38c63a4bfd17d0b07318d5c68535.tar.gz
RoughlyEnoughItems-9e55b44b710f38c63a4bfd17d0b07318d5c68535.tar.bz2
RoughlyEnoughItems-9e55b44b710f38c63a4bfd17d0b07318d5c68535.zip
REI v2.3.1 (#40)
- API Changes - Updated Config Screen - Added Tipped Arrows Recipes - Updated Mappings - Added IRecipeHelper - Turning things to Optional - Removed Cheats button, now included with the new config button - Buttons for switching gamemodes / time / weather (default: off) [Maybe not in this update] - Clickable Labels - 3+ recipes at the same time - Fixed RecipeBaseWidget bad rendering when too big - Fixed #42 Patched up item deleting & cheating - Choose Page Dialog
Diffstat (limited to 'src/main/java/me/shedaniel/rei/gui/config/ConfigScreen.java')
-rw-r--r--src/main/java/me/shedaniel/rei/gui/config/ConfigScreen.java211
1 files changed, 179 insertions, 32 deletions
diff --git a/src/main/java/me/shedaniel/rei/gui/config/ConfigScreen.java b/src/main/java/me/shedaniel/rei/gui/config/ConfigScreen.java
index a82375411..6aa884b8e 100644
--- a/src/main/java/me/shedaniel/rei/gui/config/ConfigScreen.java
+++ b/src/main/java/me/shedaniel/rei/gui/config/ConfigScreen.java
@@ -1,10 +1,12 @@
package me.shedaniel.rei.gui.config;
import me.shedaniel.rei.RoughlyEnoughItemsCore;
+import me.shedaniel.rei.client.ClientHelper;
import me.shedaniel.rei.client.GuiHelper;
import me.shedaniel.rei.client.REIItemListOrdering;
+import me.shedaniel.rei.gui.widget.TextFieldWidget;
import net.minecraft.client.MinecraftClient;
-import net.minecraft.client.gui.GuiEventListener;
+import net.minecraft.client.gui.InputListener;
import net.minecraft.client.gui.Screen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.render.GuiLighting;
@@ -39,11 +41,49 @@ public class ConfigScreen extends Screen {
protected void onInitialized() {
listeners.add(entryListWidget = new ConfigEntryListWidget(client, width, height, 32, height - 32, 24));
entryListWidget.configClearEntries();
- entryListWidget.configAddEntry(new ConfigEntry(new TranslatableTextComponent("text.rei.side_searchbox"), new ConfigEntry.ConfigEntryButtonProvider() {
+ entryListWidget.configAddEntry(new ConfigEntry.CategoryTitleConfigEntry(new TranslatableTextComponent("text.rei.config.general")));
+ entryListWidget.configAddEntry(new ConfigEntry.ButtonConfigEntry(new TranslatableTextComponent("text.rei.config.cheating"), new ConfigEntry.ButtonConfigEntry.ConfigEntryButtonProvider() {
@Override
public boolean onPressed(int button, double mouseX, double mouseY) {
if (button == 0)
- RoughlyEnoughItemsCore.getConfigHelper().setSideSearchField(!RoughlyEnoughItemsCore.getConfigHelper().sideSearchField());
+ ClientHelper.setCheating(!ClientHelper.isCheating());
+ return true;
+ }
+
+ @Override
+ public String getText() {
+ return getTrueFalseText(ClientHelper.isCheating());
+ }
+ }));
+ entryListWidget.configAddEntry(new ConfigEntry.CategoryTitleConfigEntry(new TranslatableTextComponent("text.rei.config.appearance")));
+ entryListWidget.configAddEntry(new ConfigEntry.ButtonConfigEntry(new TranslatableTextComponent("text.rei.config.side_search_box"), new ConfigEntry.ButtonConfigEntry.ConfigEntryButtonProvider() {
+ @Override
+ public boolean onPressed(int button, double mouseX, double mouseY) {
+ if (button == 0)
+ RoughlyEnoughItemsCore.getConfigHelper().getConfig().sideSearchField = !RoughlyEnoughItemsCore.getConfigHelper().getConfig().sideSearchField;
+ try {
+ RoughlyEnoughItemsCore.getConfigHelper().saveConfig();
+ } catch (IOException e) {
+ e.printStackTrace();
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String getText() {
+ return getTrueFalseText(RoughlyEnoughItemsCore.getConfigHelper().getConfig().sideSearchField);
+ }
+ }));
+ entryListWidget.configAddEntry(new ConfigEntry.ButtonConfigEntry(new TranslatableTextComponent("text.rei.config.list_ordering"), new ConfigEntry.ButtonConfigEntry.ConfigEntryButtonProvider() {
+ @Override
+ public boolean onPressed(int button, double mouseX, double mouseY) {
+ int index = Arrays.asList(REIItemListOrdering.values()).indexOf(RoughlyEnoughItemsCore.getConfigHelper().getConfig().itemListOrdering) + 1;
+ if (index >= REIItemListOrdering.values().length) {
+ index = 0;
+ RoughlyEnoughItemsCore.getConfigHelper().getConfig().isAscending = !RoughlyEnoughItemsCore.getConfigHelper().getConfig().isAscending;
+ }
+ RoughlyEnoughItemsCore.getConfigHelper().getConfig().itemListOrdering = REIItemListOrdering.values()[index];
try {
RoughlyEnoughItemsCore.getConfigHelper().saveConfig();
} catch (IOException e) {
@@ -55,14 +95,14 @@ public class ConfigScreen extends Screen {
@Override
public String getText() {
- return getTrueFalseText(RoughlyEnoughItemsCore.getConfigHelper().sideSearchField());
+ return I18n.translate("text.rei.config.list_ordering_button", I18n.translate(RoughlyEnoughItemsCore.getConfigHelper().getConfig().itemListOrdering.getNameTranslationKey()), I18n.translate(RoughlyEnoughItemsCore.getConfigHelper().getConfig().isAscending ? "ordering.rei.ascending" : "ordering.rei.descending"));
}
}));
- entryListWidget.configAddEntry(new ConfigEntry(new TranslatableTextComponent("text.rei.enable_craftable_only"), new ConfigEntry.ConfigEntryButtonProvider() {
+ entryListWidget.configAddEntry(new ConfigEntry.ButtonConfigEntry(new TranslatableTextComponent("text.rei.config.mirror_rei"), new ConfigEntry.ButtonConfigEntry.ConfigEntryButtonProvider() {
@Override
public boolean onPressed(int button, double mouseX, double mouseY) {
if (button == 0)
- RoughlyEnoughItemsCore.getConfigHelper().setShowCraftableOnlyButton(!RoughlyEnoughItemsCore.getConfigHelper().showCraftableOnlyButton());
+ RoughlyEnoughItemsCore.getConfigHelper().getConfig().mirrorItemPanel = !RoughlyEnoughItemsCore.getConfigHelper().getConfig().mirrorItemPanel;
try {
RoughlyEnoughItemsCore.getConfigHelper().saveConfig();
} catch (IOException e) {
@@ -74,18 +114,34 @@ public class ConfigScreen extends Screen {
@Override
public String getText() {
- return getTrueFalseText(RoughlyEnoughItemsCore.getConfigHelper().showCraftableOnlyButton());
+ return getTrueFalseText(RoughlyEnoughItemsCore.getConfigHelper().getConfig().mirrorItemPanel);
}
}));
- entryListWidget.configAddEntry(new ConfigEntry(new TranslatableTextComponent("text.rei.list_ordering"), new ConfigEntry.ConfigEntryButtonProvider() {
+ entryListWidget.configAddEntry(new ConfigEntry.CategoryTitleConfigEntry(new TranslatableTextComponent("text.rei.config.modules")));
+ entryListWidget.configAddEntry(new ConfigEntry.ButtonConfigEntry(new TranslatableTextComponent("text.rei.config.enable_craftable_only"), new ConfigEntry.ButtonConfigEntry.ConfigEntryButtonProvider() {
@Override
public boolean onPressed(int button, double mouseX, double mouseY) {
- int index = Arrays.asList(REIItemListOrdering.values()).indexOf(RoughlyEnoughItemsCore.getConfigHelper().getItemListOrdering()) + 1;
- if (index >= REIItemListOrdering.values().length) {
- index = 0;
- RoughlyEnoughItemsCore.getConfigHelper().setAscending(!RoughlyEnoughItemsCore.getConfigHelper().isAscending());
+ if (button == 0)
+ RoughlyEnoughItemsCore.getConfigHelper().getConfig().enableCraftableOnlyButton = !RoughlyEnoughItemsCore.getConfigHelper().getConfig().enableCraftableOnlyButton;
+ try {
+ RoughlyEnoughItemsCore.getConfigHelper().saveConfig();
+ } catch (IOException e) {
+ e.printStackTrace();
+ return false;
}
- RoughlyEnoughItemsCore.getConfigHelper().setItemListOrdering(REIItemListOrdering.values()[index]);
+ return true;
+ }
+
+ @Override
+ public String getText() {
+ return getTrueFalseText(RoughlyEnoughItemsCore.getConfigHelper().getConfig().enableCraftableOnlyButton);
+ }
+ }));
+ entryListWidget.configAddEntry(new ConfigEntry.ButtonConfigEntry(new TranslatableTextComponent("text.rei.config.load_default_plugin"), new ConfigEntry.ButtonConfigEntry.ConfigEntryButtonProvider() {
+ @Override
+ public boolean onPressed(int button, double mouseX, double mouseY) {
+ if (button == 0)
+ RoughlyEnoughItemsCore.getConfigHelper().getConfig().loadDefaultPlugin = !RoughlyEnoughItemsCore.getConfigHelper().getConfig().loadDefaultPlugin;
try {
RoughlyEnoughItemsCore.getConfigHelper().saveConfig();
} catch (IOException e) {
@@ -97,14 +153,24 @@ public class ConfigScreen extends Screen {
@Override
public String getText() {
- return I18n.translate("text.rei.list_ordering_button", I18n.translate(RoughlyEnoughItemsCore.getConfigHelper().getItemListOrdering().getNameTranslationKey()), I18n.translate(RoughlyEnoughItemsCore.getConfigHelper().isAscending() ? "ordering.rei.ascending" : "ordering.rei.descending"));
+ return getTrueFalseText(RoughlyEnoughItemsCore.getConfigHelper().getConfig().loadDefaultPlugin);
+ }
+
+ @Override
+ public void draw(me.shedaniel.rei.gui.widget.ButtonWidget button, Point mouse, float delta) {
+ button.draw(mouse.x, mouse.y, delta);
+ if (button.isHighlighted(mouse)) {
+ GuiLighting.disable();
+ drawTooltip(Arrays.asList(I18n.translate("text.rei.config.load_default_plugin.restart_tooltip").split("\n")), mouse.x, mouse.y);
+ GuiLighting.disable();
+ }
}
}));
- entryListWidget.configAddEntry(new ConfigEntry(new TranslatableTextComponent("text.rei.mirror_rei"), new ConfigEntry.ConfigEntryButtonProvider() {
+ entryListWidget.configAddEntry(new ConfigEntry.ButtonConfigEntry(new TranslatableTextComponent("text.rei.config.disable_credits_button"), new ConfigEntry.ButtonConfigEntry.ConfigEntryButtonProvider() {
@Override
public boolean onPressed(int button, double mouseX, double mouseY) {
if (button == 0)
- RoughlyEnoughItemsCore.getConfigHelper().setMirrorItemPanel(!RoughlyEnoughItemsCore.getConfigHelper().isMirrorItemPanel());
+ RoughlyEnoughItemsCore.getConfigHelper().getConfig().disableCreditsButton = !RoughlyEnoughItemsCore.getConfigHelper().getConfig().disableCreditsButton;
try {
RoughlyEnoughItemsCore.getConfigHelper().saveConfig();
} catch (IOException e) {
@@ -116,14 +182,14 @@ public class ConfigScreen extends Screen {
@Override
public String getText() {
- return getTrueFalseText(RoughlyEnoughItemsCore.getConfigHelper().isMirrorItemPanel());
+ return getTrueFalseText(RoughlyEnoughItemsCore.getConfigHelper().getConfig().disableCreditsButton);
}
}));
- entryListWidget.configAddEntry(new ConfigEntry(new TranslatableTextComponent("text.rei.check_updates"), new ConfigEntry.ConfigEntryButtonProvider() {
+ entryListWidget.configAddEntry(new ConfigEntry.ButtonConfigEntry(new TranslatableTextComponent("text.rei.config.enable_util_buttons"), new ConfigEntry.ButtonConfigEntry.ConfigEntryButtonProvider() {
@Override
public boolean onPressed(int button, double mouseX, double mouseY) {
if (button == 0)
- RoughlyEnoughItemsCore.getConfigHelper().setCheckUpdates(!RoughlyEnoughItemsCore.getConfigHelper().checkUpdates());
+ RoughlyEnoughItemsCore.getConfigHelper().getConfig().showUtilsButtons = !RoughlyEnoughItemsCore.getConfigHelper().getConfig().showUtilsButtons;
try {
RoughlyEnoughItemsCore.getConfigHelper().saveConfig();
} catch (IOException e) {
@@ -135,14 +201,15 @@ public class ConfigScreen extends Screen {
@Override
public String getText() {
- return getTrueFalseText(RoughlyEnoughItemsCore.getConfigHelper().checkUpdates());
+ return getTrueFalseText(RoughlyEnoughItemsCore.getConfigHelper().getConfig().showUtilsButtons);
}
}));
- entryListWidget.configAddEntry(new ConfigEntry(new TranslatableTextComponent("text.rei.load_default_plugin"), new ConfigEntry.ConfigEntryButtonProvider() {
+ entryListWidget.configAddEntry(new ConfigEntry.CategoryTitleConfigEntry(new TranslatableTextComponent("text.rei.config.advanced")));
+ entryListWidget.configAddEntry(new ConfigEntry.ButtonConfigEntry(new TranslatableTextComponent("text.rei.check_updates"), new ConfigEntry.ButtonConfigEntry.ConfigEntryButtonProvider() {
@Override
public boolean onPressed(int button, double mouseX, double mouseY) {
if (button == 0)
- RoughlyEnoughItemsCore.getConfigHelper().setLoadingDefaultPlugin(!RoughlyEnoughItemsCore.getConfigHelper().isLoadingDefaultPlugin());
+ RoughlyEnoughItemsCore.getConfigHelper().getConfig().checkUpdates = !RoughlyEnoughItemsCore.getConfigHelper().getConfig().checkUpdates;
try {
RoughlyEnoughItemsCore.getConfigHelper().saveConfig();
} catch (IOException e) {
@@ -154,19 +221,100 @@ public class ConfigScreen extends Screen {
@Override
public String getText() {
- return getTrueFalseText(RoughlyEnoughItemsCore.getConfigHelper().isLoadingDefaultPlugin());
+ return getTrueFalseText(RoughlyEnoughItemsCore.getConfigHelper().getConfig().checkUpdates);
+ }
+ }));
+ entryListWidget.configAddEntry(new ConfigEntry.TextFieldConfigEntry(new TranslatableTextComponent("text.rei.give_command"), new ConfigEntry.TextFieldConfigEntry.ConfigEntryTextFieldProvider() {
+ @Override
+ public void onInitWidget(TextFieldWidget widget) {
+ widget.setMaxLength(99999);
+ widget.setText(RoughlyEnoughItemsCore.getConfigHelper().getConfig().giveCommand);
+ widget.setSuggestion(I18n.translate("text.rei.give_command.suggestion"));
}
@Override
- public void draw(me.shedaniel.rei.gui.widget.ButtonWidget button, Point mouse, float delta) {
- button.draw(mouse.x, mouse.y, delta);
- if (button.getBounds().contains(mouse)) {
+ public void onUpdateText(TextFieldWidget button, String text) {
+ RoughlyEnoughItemsCore.getConfigHelper().getConfig().giveCommand = text;
+ try {
+ RoughlyEnoughItemsCore.getConfigHelper().saveConfig();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void draw(TextFieldWidget widget, Point mouse, float delta) {
+ widget.draw(mouse.x, mouse.y, delta);
+ if (widget.isHighlighted(mouse)) {
GuiLighting.disable();
- drawTooltip(Arrays.asList(I18n.translate("text.rei.load_default_plugin.restart_tooltip").split("\n")), mouse.x, mouse.y);
+ drawTooltip(Arrays.asList(I18n.translate("text.rei.give_command.tooltip").split("\n")), mouse.x, mouse.y);
GuiLighting.disable();
}
}
}));
+ entryListWidget.configAddEntry(new ConfigEntry.TextFieldConfigEntry(new TranslatableTextComponent("text.rei.gamemode_command"), new ConfigEntry.TextFieldConfigEntry.ConfigEntryTextFieldProvider() {
+ @Override
+ public void onInitWidget(TextFieldWidget widget) {
+ widget.setMaxLength(99999);
+ widget.setText(RoughlyEnoughItemsCore.getConfigHelper().getConfig().gamemodeCommand);
+ widget.setSuggestion(I18n.translate("text.rei.give_command.suggestion"));
+ }
+
+ @Override
+ public void onUpdateText(TextFieldWidget button, String text) {
+ RoughlyEnoughItemsCore.getConfigHelper().getConfig().gamemodeCommand = text;
+ try {
+ RoughlyEnoughItemsCore.getConfigHelper().saveConfig();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }));
+ entryListWidget.configAddEntry(new ConfigEntry.TextFieldConfigEntry(new TranslatableTextComponent("text.rei.config.max_recipes_per_page"), new ConfigEntry.TextFieldConfigEntry.ConfigEntryTextFieldProvider() {
+ @Override
+ public void onInitWidget(TextFieldWidget widget) {
+ widget.setMaxLength(2);
+ widget.setText(RoughlyEnoughItemsCore.getConfigHelper().getConfig().maxRecipePerPage + "");
+ widget.stripInvaild = s -> {
+ StringBuilder stringBuilder_1 = new StringBuilder();
+ char[] var2 = s.toCharArray();
+ int var3 = var2.length;
+
+ for(int var4 = 0; var4 < var3; ++var4) {
+ char char_1 = var2[var4];
+ if (Character.isDigit(char_1))
+ stringBuilder_1.append(char_1);
+ }
+
+ return stringBuilder_1.toString();
+ };
+ }
+
+ @Override
+ public void onUpdateText(TextFieldWidget button, String text) {
+ if (isInvaildNumber(text))
+ try {
+ RoughlyEnoughItemsCore.getConfigHelper().getConfig().maxRecipePerPage = Integer.valueOf(text);
+ RoughlyEnoughItemsCore.getConfigHelper().saveConfig();
+ } catch (Exception e) {
+ }
+ }
+
+ @Override
+ public void draw(TextFieldWidget widget, Point mouse, float delta) {
+ widget.setEditableColor(isInvaildNumber(widget.getText()) ? -1 : Color.RED.getRGB());
+ widget.draw(mouse.x, mouse.y, delta);
+ }
+
+ private boolean isInvaildNumber(String text) {
+ try {
+ int page = Integer.valueOf(text);
+ return page >= 2 && page <= 99;
+ } catch (Exception e) {
+ }
+ return false;
+ }
+ }));
addButton(new ButtonWidget(width / 2 - 100, height - 26, I18n.translate("gui.done")) {
@Override
public void onPressed(double double_1, double double_2) {
@@ -187,12 +335,11 @@ public class ConfigScreen extends Screen {
}
@Override
- public void method_18326(int int_1, int int_2, float float_1) {
- //draw
+ public void draw(int int_1, int int_2, float float_1) {
this.drawTextureBackground(0);
- this.entryListWidget.method_18326(int_1, int_2, float_1);
+ this.entryListWidget.draw(int_1, int_2, float_1);
this.drawStringCentered(this.fontRenderer, I18n.translate("text.rei.config"), this.width / 2, 16, 16777215);
- super.method_18326(int_1, int_2, float_1);
+ super.draw(int_1, int_2, float_1);
}
@Override
@@ -201,7 +348,7 @@ public class ConfigScreen extends Screen {
}
@Override
- public GuiEventListener getFocused() {
+ public InputListener getFocused() {
return entryListWidget;
}