mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-18 19:39:22 +00:00
Fix the rest of the "easy" compile errors (#5151)
* Add Entity.changeDimension patch and transitively required patches * Fix throws declaration on CommandSetDimension#execute * Fix rest of errors in fluid package * Add PLAYER_REACH attribute * Fix compile errors in fml.client.config and add GuiButton patch * Delete unnecessary client.config classes, fix all config errors * Comment some fluid errors in models * Fix all errors in common package root, except ForgeHooks * Mass comment network package * Experimental conversion of extended states to generic base class * Fix errors in common.util * Remove config annotation stuff cuz lex said so * Make extended state stuff compile fully
This commit is contained in:
1 parent
6814cbf0df
commit
c4cf950863
72 files changed
+610
-5996
No files matched your search
@@ -16,7 +16,7 @@
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/* TODO is this ded?
|
||||
package net.minecraftforge.fml.client;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -147,3 +147,4 @@ public class FMLConfigGuiFactory implements IModGuiFactory
|
||||
return fmlCategories;
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -24,12 +24,10 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraftforge.fml.client.config.GuiConfigEntries.IConfigEntry;
|
||||
import net.minecraftforge.fml.client.config.GuiEditArrayEntries.IArrayEntry;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.client.resources.I18n;
|
||||
|
||||
|
||||
/**
|
||||
* This class's main purpose is to provide the necessary objects for a sample Config GUI for FML, although
|
||||
|
||||
@@ -59,9 +59,9 @@ public class GuiButtonExt extends GuiButton
|
||||
this.mouseDragged(mc, mouseX, mouseY);
|
||||
int color = 14737632;
|
||||
|
||||
if (packedFGColour != 0)
|
||||
if (packedFGColor != 0)
|
||||
{
|
||||
color = packedFGColour;
|
||||
color = packedFGColor;
|
||||
}
|
||||
else if (!this.enabled)
|
||||
{
|
||||
|
||||
@@ -42,18 +42,19 @@ public class GuiCheckBox extends GuiButton
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawButton(Minecraft mc, int mouseX, int mouseY, float partial)
|
||||
public void func_194828_a(int mouseX, int mouseY, float partial)
|
||||
{
|
||||
if (this.visible)
|
||||
{
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
this.hovered = mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.boxWidth && mouseY < this.y + this.height;
|
||||
GuiUtils.drawContinuousTexturedBox(BUTTON_TEXTURES, this.x, this.y, 0, 46, this.boxWidth, this.height, 200, 20, 2, 3, 2, 2, this.zLevel);
|
||||
this.mouseDragged(mc, mouseX, mouseY);
|
||||
int color = 14737632;
|
||||
|
||||
if (packedFGColour != 0)
|
||||
if (packedFGColor != 0)
|
||||
{
|
||||
color = packedFGColour;
|
||||
color = packedFGColor;
|
||||
}
|
||||
else if (!this.enabled)
|
||||
{
|
||||
@@ -68,15 +69,9 @@ public class GuiCheckBox extends GuiButton
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mousePressed(Minecraft mc, int mouseX, int mouseY)
|
||||
public void func_194829_a(double mouseX, double mouseY)
|
||||
{
|
||||
if (this.enabled && this.visible && mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height)
|
||||
{
|
||||
this.isChecked = !this.isChecked;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
this.isChecked = !this.isChecked;
|
||||
}
|
||||
|
||||
public boolean isChecked()
|
||||
|
||||
@@ -1,386 +0,0 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2018.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.client.config;
|
||||
|
||||
import static net.minecraftforge.fml.client.config.GuiUtils.RESET_CHAR;
|
||||
import static net.minecraftforge.fml.client.config.GuiUtils.UNDO_CHAR;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.client.config.GuiConfigEntries.IConfigEntry;
|
||||
import net.minecraftforge.fml.client.event.ConfigChangedEvent;
|
||||
import net.minecraftforge.fml.client.event.ConfigChangedEvent.OnConfigChangedEvent;
|
||||
import net.minecraftforge.fml.client.event.ConfigChangedEvent.PostConfigChangedEvent;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import net.minecraftforge.eventbus.api.Event.Result;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* This class is the base GuiScreen for all config GUI screens. It can be extended by mods to provide the top-level config screen
|
||||
* that will be called when the Config button is clicked from the Main Menu Mods list.
|
||||
*
|
||||
* @author bspkrs
|
||||
*/
|
||||
public class GuiConfig extends GuiScreen
|
||||
{
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
|
||||
/**
|
||||
* A reference to the screen object that created this. Used for navigating between screens.
|
||||
*/
|
||||
public final GuiScreen parentScreen;
|
||||
public String title = "Config GUI";
|
||||
@Nullable
|
||||
public String titleLine2;
|
||||
public final List<IConfigElement> configElements;
|
||||
public final List<IConfigEntry> initEntries;
|
||||
public GuiConfigEntries entryList;
|
||||
protected GuiButtonExt btnDefaultAll;
|
||||
protected GuiButtonExt btnUndoAll;
|
||||
protected GuiCheckBox chkApplyGlobally;
|
||||
public final String modID;
|
||||
/**
|
||||
* When set to a non-null value the OnConfigChanged and PostConfigChanged events will be posted when the Done button is pressed
|
||||
* if any configElements were changed (includes child screens). If not defined, the events will be posted if the parent gui is null
|
||||
* or if the parent gui is not an instance of GuiConfig.
|
||||
*/
|
||||
@Nullable
|
||||
public final String configID;
|
||||
public final boolean isWorldRunning;
|
||||
public final boolean allRequireWorldRestart;
|
||||
public final boolean allRequireMcRestart;
|
||||
public boolean needsRefresh = true;
|
||||
protected HoverChecker undoHoverChecker;
|
||||
protected HoverChecker resetHoverChecker;
|
||||
protected HoverChecker checkBoxHoverChecker;
|
||||
|
||||
/**
|
||||
* GuiConfig constructor that will use ConfigChangedEvent when editing is concluded. If a non-null value is passed for configID,
|
||||
* the OnConfigChanged and PostConfigChanged events will be posted when the Done button is pressed if any configElements were changed
|
||||
* (includes child screens). If configID is not defined, the events will be posted if the parent gui is null or if the parent gui
|
||||
* is not an instance of GuiConfig.
|
||||
*
|
||||
* @param parentScreen the parent GuiScreen object
|
||||
* @param configElements a List of IConfigElement objects
|
||||
* @param modID the mod ID for the mod whose config settings will be edited
|
||||
* @param configID an identifier that will be passed to the OnConfigChanged and PostConfigChanged events. Setting this value will force
|
||||
* the save action to be called when the Done button is pressed on this screen if any configElements were changed.
|
||||
* @param allRequireWorldRestart send true if all configElements on this screen require a world restart
|
||||
* @param allRequireMcRestart send true if all configElements on this screen require MC to be restarted
|
||||
* @param title the desired title for this screen. For consistency it is recommended that you pass the path of the config file being
|
||||
* edited.
|
||||
*/
|
||||
public GuiConfig(GuiScreen parentScreen, List<IConfigElement> configElements, String modID, String configID,
|
||||
boolean allRequireWorldRestart, boolean allRequireMcRestart, String title)
|
||||
{
|
||||
this(parentScreen, configElements, modID, configID, allRequireWorldRestart, allRequireMcRestart, title, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* GuiConfig constructor that will use ConfigChangedEvent when editing is concluded. This constructor passes null for configID.
|
||||
* If configID is not defined, the events will be posted if the parent gui is null or if the parent gui is not an instance of GuiConfig.
|
||||
*
|
||||
* @param parentScreen the parent GuiScreen object
|
||||
* @param configElements a List of IConfigElement objects
|
||||
* @param modID the mod ID for the mod whose config settings will be edited
|
||||
* @param allRequireWorldRestart send true if all configElements on this screen require a world restart
|
||||
* @param allRequireMcRestart send true if all configElements on this screen require MC to be restarted
|
||||
* @param title the desired title for this screen. For consistency it is recommended that you pass the path of the config file being
|
||||
* edited.
|
||||
*/
|
||||
public GuiConfig(GuiScreen parentScreen, List<IConfigElement> configElements, String modID,
|
||||
boolean allRequireWorldRestart, boolean allRequireMcRestart, String title)
|
||||
{
|
||||
this(parentScreen, configElements, modID, null, allRequireWorldRestart, allRequireMcRestart, title, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* GuiConfig constructor that will use ConfigChangedEvent when editing is concluded. This constructor passes null for configID.
|
||||
* If configID is not defined, the events will be posted if the parent gui is null or if the parent gui is not an instance of GuiConfig.
|
||||
*
|
||||
* @param parentScreen the parent GuiScreen object
|
||||
* @param configElements a List of IConfigElement objects
|
||||
* @param modID the mod ID for the mod whose config settings will be edited
|
||||
* @param allRequireWorldRestart send true if all configElements on this screen require a world restart
|
||||
* @param allRequireMcRestart send true if all configElements on this screen require MC to be restarted
|
||||
* @param title the desired title for this screen. For consistency it is recommended that you pass the path of the config file being
|
||||
* edited.
|
||||
* @param titleLine2 the desired title second line for this screen. Typically this is used to send the category name of the category
|
||||
* currently being edited.
|
||||
*/
|
||||
public GuiConfig(GuiScreen parentScreen, List<IConfigElement> configElements, String modID,
|
||||
boolean allRequireWorldRestart, boolean allRequireMcRestart, String title, String titleLine2)
|
||||
{
|
||||
this(parentScreen, configElements, modID, null, allRequireWorldRestart, allRequireMcRestart, title, titleLine2);
|
||||
}
|
||||
|
||||
/**
|
||||
* GuiConfig constructor that will use ConfigChangedEvent when editing is concluded. titleLine2 is specified in this constructor.
|
||||
* If a non-null value is passed for configID, the OnConfigChanged and PostConfigChanged events will be posted when the Done button is
|
||||
* pressed if any configElements were changed (includes child screens). If configID is not defined, the events will be posted if the parent
|
||||
* gui is null or if the parent gui is not an instance of GuiConfig.
|
||||
*
|
||||
* @param parentScreen the parent GuiScreen object
|
||||
* @param configElements a List of IConfigElement objects
|
||||
* @param modID the mod ID for the mod whose config settings will be edited
|
||||
* @param configID an identifier that will be passed to the OnConfigChanged and PostConfigChanged events
|
||||
* @param allRequireWorldRestart send true if all configElements on this screen require a world restart
|
||||
* @param allRequireMcRestart send true if all configElements on this screen require MC to be restarted
|
||||
* @param title the desired title for this screen. For consistency it is recommended that you pass the path of the config file being
|
||||
* edited.
|
||||
* @param titleLine2 the desired title second line for this screen. Typically this is used to send the category name of the category
|
||||
* currently being edited.
|
||||
*/
|
||||
public GuiConfig(GuiScreen parentScreen, List<IConfigElement> configElements, String modID, @Nullable String configID,
|
||||
boolean allRequireWorldRestart, boolean allRequireMcRestart, String title, @Nullable String titleLine2)
|
||||
{
|
||||
this.mc = Minecraft.getMinecraft();
|
||||
this.parentScreen = parentScreen;
|
||||
this.configElements = configElements;
|
||||
this.entryList = new GuiConfigEntries(this, mc);
|
||||
this.initEntries = new ArrayList<>(entryList.listEntries);
|
||||
this.allRequireWorldRestart = allRequireWorldRestart;
|
||||
IF:if (!allRequireWorldRestart)
|
||||
{
|
||||
for (IConfigElement element : configElements)
|
||||
{
|
||||
if (!element.requiresWorldRestart());
|
||||
break IF;
|
||||
}
|
||||
allRequireWorldRestart = true;
|
||||
}
|
||||
this.allRequireMcRestart = allRequireMcRestart;
|
||||
IF:if (!allRequireMcRestart)
|
||||
{
|
||||
for (IConfigElement element : configElements)
|
||||
{
|
||||
if (!element.requiresMcRestart());
|
||||
break IF;
|
||||
}
|
||||
allRequireMcRestart = true;
|
||||
}
|
||||
this.modID = modID;
|
||||
this.configID = configID;
|
||||
this.isWorldRunning = mc.world != null;
|
||||
if (title != null)
|
||||
this.title = title;
|
||||
this.titleLine2 = titleLine2;
|
||||
if (this.titleLine2 != null && this.titleLine2.startsWith(" > "))
|
||||
this.titleLine2 = this.titleLine2.replaceFirst(" > ", "");
|
||||
}
|
||||
|
||||
public static String getAbridgedConfigPath(String path)
|
||||
{
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
if (mc.mcDataDir.getAbsolutePath().endsWith("."))
|
||||
return path.replace("\\", "/").replace(mc.mcDataDir.getAbsolutePath().replace("\\", "/").substring(0, mc.mcDataDir.getAbsolutePath().length() - 1), "/.minecraft/");
|
||||
else
|
||||
return path.replace("\\", "/").replace(mc.mcDataDir.getAbsolutePath().replace("\\", "/"), "/.minecraft");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui()
|
||||
{
|
||||
Keyboard.enableRepeatEvents(true);
|
||||
|
||||
if (this.entryList == null || this.needsRefresh)
|
||||
{
|
||||
this.entryList = new GuiConfigEntries(this, mc);
|
||||
this.needsRefresh = false;
|
||||
}
|
||||
|
||||
int undoGlyphWidth = mc.fontRenderer.getStringWidth(UNDO_CHAR) * 2;
|
||||
int resetGlyphWidth = mc.fontRenderer.getStringWidth(RESET_CHAR) * 2;
|
||||
int doneWidth = Math.max(mc.fontRenderer.getStringWidth(I18n.format("gui.done")) + 20, 100);
|
||||
int undoWidth = mc.fontRenderer.getStringWidth(" " + I18n.format("fml.configgui.tooltip.undoChanges")) + undoGlyphWidth + 20;
|
||||
int resetWidth = mc.fontRenderer.getStringWidth(" " + I18n.format("fml.configgui.tooltip.resetToDefault")) + resetGlyphWidth + 20;
|
||||
int checkWidth = mc.fontRenderer.getStringWidth(I18n.format("fml.configgui.applyGlobally")) + 13;
|
||||
int buttonWidthHalf = (doneWidth + 5 + undoWidth + 5 + resetWidth + 5 + checkWidth) / 2;
|
||||
this.buttonList.add(new GuiButtonExt(2000, this.width / 2 - buttonWidthHalf, this.height - 29, doneWidth, 20, I18n.format("gui.done")));
|
||||
this.buttonList.add(this.btnDefaultAll = new GuiUnicodeGlyphButton(2001, this.width / 2 - buttonWidthHalf + doneWidth + 5 + undoWidth + 5,
|
||||
this.height - 29, resetWidth, 20, " " + I18n.format("fml.configgui.tooltip.resetToDefault"), RESET_CHAR, 2.0F));
|
||||
this.buttonList.add(btnUndoAll = new GuiUnicodeGlyphButton(2002, this.width / 2 - buttonWidthHalf + doneWidth + 5,
|
||||
this.height - 29, undoWidth, 20, " " + I18n.format("fml.configgui.tooltip.undoChanges"), UNDO_CHAR, 2.0F));
|
||||
this.buttonList.add(chkApplyGlobally = new GuiCheckBox(2003, this.width / 2 - buttonWidthHalf + doneWidth + 5 + undoWidth + 5 + resetWidth + 5,
|
||||
this.height - 24, I18n.format("fml.configgui.applyGlobally"), false));
|
||||
|
||||
this.undoHoverChecker = new HoverChecker(this.btnUndoAll, 800);
|
||||
this.resetHoverChecker = new HoverChecker(this.btnDefaultAll, 800);
|
||||
this.checkBoxHoverChecker = new HoverChecker(chkApplyGlobally, 800);
|
||||
this.entryList.initGui();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGuiClosed()
|
||||
{
|
||||
this.entryList.onGuiClosed();
|
||||
|
||||
if (this.configID != null && this.parentScreen instanceof GuiConfig)
|
||||
{
|
||||
GuiConfig parentGuiConfig = (GuiConfig) this.parentScreen;
|
||||
parentGuiConfig.needsRefresh = true;
|
||||
parentGuiConfig.initGui();
|
||||
}
|
||||
|
||||
if (!(this.parentScreen instanceof GuiConfig))
|
||||
Keyboard.enableRepeatEvents(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button)
|
||||
{
|
||||
if (button.id == 2000)
|
||||
{
|
||||
boolean flag = true;
|
||||
try
|
||||
{
|
||||
if ((configID != null || this.parentScreen == null || !(this.parentScreen instanceof GuiConfig))
|
||||
&& (this.entryList.hasChangedEntry(true)))
|
||||
{
|
||||
boolean requiresMcRestart = this.entryList.saveConfigElements();
|
||||
|
||||
if (Loader.isModLoaded(modID))
|
||||
{
|
||||
ConfigChangedEvent event = new OnConfigChangedEvent(modID, configID, isWorldRunning, requiresMcRestart);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
if (!event.getResult().equals(Result.DENY))
|
||||
MinecraftForge.EVENT_BUS.post(new PostConfigChangedEvent(modID, configID, isWorldRunning, requiresMcRestart));
|
||||
|
||||
if (requiresMcRestart)
|
||||
{
|
||||
flag = false;
|
||||
mc.displayGuiScreen(new GuiMessageDialog(parentScreen, "fml.configgui.gameRestartTitle",
|
||||
new TextComponentString(I18n.format("fml.configgui.gameRestartRequired")), "fml.configgui.confirmRestartMessage"));
|
||||
}
|
||||
|
||||
if (this.parentScreen instanceof GuiConfig)
|
||||
((GuiConfig) this.parentScreen).needsRefresh = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
LOGGER.error("Error performing GuiConfig action:", e);
|
||||
}
|
||||
|
||||
if (flag)
|
||||
this.mc.displayGuiScreen(this.parentScreen);
|
||||
}
|
||||
else if (button.id == 2001)
|
||||
{
|
||||
this.entryList.setAllToDefault(this.chkApplyGlobally.isChecked());
|
||||
}
|
||||
else if (button.id == 2002)
|
||||
{
|
||||
this.entryList.undoAllChanges(this.chkApplyGlobally.isChecked());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMouseInput() throws IOException
|
||||
{
|
||||
super.handleMouseInput();
|
||||
this.entryList.handleMouseInput();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int x, int y, int mouseEvent) throws IOException
|
||||
{
|
||||
if (mouseEvent != 0 || !this.entryList.mouseClicked(x, y, mouseEvent))
|
||||
{
|
||||
this.entryList.mouseClickedPassThru(x, y, mouseEvent);
|
||||
super.mouseClicked(x, y, mouseEvent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseReleased(int x, int y, int mouseEvent)
|
||||
{
|
||||
if (mouseEvent != 0 || !this.entryList.mouseReleased(x, y, mouseEvent))
|
||||
{
|
||||
super.mouseReleased(x, y, mouseEvent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char eventChar, int eventKey)
|
||||
{
|
||||
if (eventKey == Keyboard.KEY_ESCAPE)
|
||||
this.mc.displayGuiScreen(parentScreen);
|
||||
else
|
||||
this.entryList.keyTyped(eventChar, eventKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen()
|
||||
{
|
||||
super.updateScreen();
|
||||
this.entryList.updateScreen();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks)
|
||||
{
|
||||
this.drawDefaultBackground();
|
||||
this.entryList.drawScreen(mouseX, mouseY, partialTicks);
|
||||
this.drawCenteredString(this.fontRenderer, this.title, this.width / 2, 8, 16777215);
|
||||
String title2 = this.titleLine2;
|
||||
|
||||
if (title2 != null)
|
||||
{
|
||||
int strWidth = mc.fontRenderer.getStringWidth(title2);
|
||||
int ellipsisWidth = mc.fontRenderer.getStringWidth("...");
|
||||
if (strWidth > width - 6 && strWidth > ellipsisWidth)
|
||||
title2 = mc.fontRenderer.trimStringToWidth(title2, width - 6 - ellipsisWidth).trim() + "...";
|
||||
this.drawCenteredString(this.fontRenderer, title2, this.width / 2, 18, 16777215);
|
||||
}
|
||||
|
||||
this.btnUndoAll.enabled = this.entryList.areAnyEntriesEnabled(this.chkApplyGlobally.isChecked()) && this.entryList.hasChangedEntry(this.chkApplyGlobally.isChecked());
|
||||
this.btnDefaultAll.enabled = this.entryList.areAnyEntriesEnabled(this.chkApplyGlobally.isChecked()) && !this.entryList.areAllEntriesDefault(this.chkApplyGlobally.isChecked());
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
this.entryList.drawScreenPost(mouseX, mouseY, partialTicks);
|
||||
if (this.undoHoverChecker.checkHover(mouseX, mouseY))
|
||||
this.drawToolTip(Arrays.asList(I18n.format("fml.configgui.tooltip.undoAll").split("\n")), mouseX, mouseY);
|
||||
if (this.resetHoverChecker.checkHover(mouseX, mouseY))
|
||||
this.drawToolTip(Arrays.asList(I18n.format("fml.configgui.tooltip.resetAll").split("\n")), mouseX, mouseY);
|
||||
if (this.checkBoxHoverChecker.checkHover(mouseX, mouseY))
|
||||
this.drawToolTip(Arrays.asList(I18n.format("fml.configgui.tooltip.applyGlobally").split("\n")), mouseX, mouseY);
|
||||
}
|
||||
|
||||
public void drawToolTip(List<String> stringList, int x, int y)
|
||||
{
|
||||
GuiUtils.drawHoveringText(stringList, x, y, width, height, 300, fontRenderer);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,225 +0,0 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2018.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.client.config;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import static net.minecraftforge.fml.client.config.GuiUtils.RESET_CHAR;
|
||||
import static net.minecraftforge.fml.client.config.GuiUtils.UNDO_CHAR;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
/**
|
||||
* This class is the base screen used for editing an array-type property. It provides a list of array entries for the user to edit.
|
||||
* This screen is invoked from a GuiConfig screen by controls that use the EditListPropEntry IGuiConfigListEntry object.
|
||||
*
|
||||
* @author bspkrs
|
||||
*/
|
||||
public class GuiEditArray extends GuiScreen
|
||||
{
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
|
||||
protected GuiScreen parentScreen;
|
||||
protected IConfigElement configElement;
|
||||
protected GuiEditArrayEntries entryList;
|
||||
protected GuiButtonExt btnUndoChanges, btnDefault, btnDone;
|
||||
protected String title;
|
||||
protected String titleLine2;
|
||||
protected String titleLine3;
|
||||
protected int slotIndex;
|
||||
protected final Object[] beforeValues;
|
||||
protected Object[] currentValues;
|
||||
protected HoverChecker tooltipHoverChecker;
|
||||
protected List<String> toolTip;
|
||||
protected boolean enabled;
|
||||
|
||||
public GuiEditArray(GuiScreen parentScreen, IConfigElement configElement, int slotIndex, Object[] currentValues, boolean enabled)
|
||||
{
|
||||
this.mc = Minecraft.getMinecraft();
|
||||
this.parentScreen = parentScreen;
|
||||
this.configElement = configElement;
|
||||
this.slotIndex = slotIndex;
|
||||
this.beforeValues = currentValues;
|
||||
this.currentValues = currentValues;
|
||||
this.toolTip = new ArrayList<String>();
|
||||
this.enabled = enabled;
|
||||
String propName = I18n.format(configElement.getLanguageKey());
|
||||
String comment;
|
||||
|
||||
comment = I18n.format(configElement.getLanguageKey() + ".tooltip",
|
||||
"\n" + TextFormatting.AQUA, configElement.getDefault(), configElement.getMinValue(), configElement.getMaxValue());
|
||||
|
||||
if (!comment.equals(configElement.getLanguageKey() + ".tooltip"))
|
||||
Collections.addAll(toolTip, (TextFormatting.GREEN + propName + "\n" + TextFormatting.YELLOW + comment).split("\n"));
|
||||
else if (configElement.getComment() != null && !configElement.getComment().trim().isEmpty())
|
||||
Collections.addAll(toolTip, (TextFormatting.GREEN + propName + "\n" + TextFormatting.YELLOW + configElement.getComment()).split("\n"));
|
||||
else
|
||||
Collections.addAll(toolTip, (TextFormatting.GREEN + propName + "\n" + TextFormatting.RED + "No tooltip defined.").split("\n"));
|
||||
|
||||
if (parentScreen instanceof GuiConfig)
|
||||
{
|
||||
this.title = ((GuiConfig) parentScreen).title;
|
||||
if (((GuiConfig) parentScreen).titleLine2 != null)
|
||||
{
|
||||
this.titleLine2 = ((GuiConfig) parentScreen).titleLine2;
|
||||
this.titleLine3 = I18n.format(configElement.getLanguageKey());
|
||||
}
|
||||
else
|
||||
this.titleLine2 = I18n.format(configElement.getLanguageKey());
|
||||
this.tooltipHoverChecker = new HoverChecker(28, 37, 0, parentScreen.width, 800);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.title = I18n.format(configElement.getLanguageKey());
|
||||
this.tooltipHoverChecker = new HoverChecker(8, 17, 0, parentScreen.width, 800);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui()
|
||||
{
|
||||
this.entryList = createEditArrayEntries();
|
||||
|
||||
int undoGlyphWidth = mc.fontRenderer.getStringWidth(UNDO_CHAR) * 2;
|
||||
int resetGlyphWidth = mc.fontRenderer.getStringWidth(RESET_CHAR) * 2;
|
||||
int doneWidth = Math.max(mc.fontRenderer.getStringWidth(I18n.format("gui.done")) + 20, 100);
|
||||
int undoWidth = mc.fontRenderer.getStringWidth(" " + I18n.format("fml.configgui.tooltip.undoChanges")) + undoGlyphWidth + 20;
|
||||
int resetWidth = mc.fontRenderer.getStringWidth(" " + I18n.format("fml.configgui.tooltip.resetToDefault")) + resetGlyphWidth + 20;
|
||||
int buttonWidthHalf = (doneWidth + 5 + undoWidth + 5 + resetWidth) / 2;
|
||||
this.buttonList.add(btnDone = new GuiButtonExt(2000, this.width / 2 - buttonWidthHalf, this.height - 29, doneWidth, 20, I18n.format("gui.done")));
|
||||
this.buttonList.add(btnDefault = new GuiUnicodeGlyphButton(2001, this.width / 2 - buttonWidthHalf + doneWidth + 5 + undoWidth + 5,
|
||||
this.height - 29, resetWidth, 20, " " + I18n.format("fml.configgui.tooltip.resetToDefault"), RESET_CHAR, 2.0F));
|
||||
this.buttonList.add(btnUndoChanges = new GuiUnicodeGlyphButton(2002, this.width / 2 - buttonWidthHalf + doneWidth + 5,
|
||||
this.height - 29, undoWidth, 20, " " + I18n.format("fml.configgui.tooltip.undoChanges"), UNDO_CHAR, 2.0F));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button)
|
||||
{
|
||||
if (button.id == 2000)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.entryList.saveListChanges();
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
LOGGER.error("Error performing GuiEditArray action:", e);
|
||||
}
|
||||
this.mc.displayGuiScreen(this.parentScreen);
|
||||
}
|
||||
else if (button.id == 2001)
|
||||
{
|
||||
this.currentValues = configElement.getDefaults();
|
||||
this.entryList = createEditArrayEntries();
|
||||
}
|
||||
else if (button.id == 2002)
|
||||
{
|
||||
this.currentValues = Arrays.copyOf(beforeValues, beforeValues.length);
|
||||
this.entryList = createEditArrayEntries();
|
||||
}
|
||||
}
|
||||
|
||||
protected GuiEditArrayEntries createEditArrayEntries()
|
||||
{
|
||||
return new GuiEditArrayEntries(this, this.mc, this.configElement, this.beforeValues, this.currentValues);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMouseInput() throws IOException
|
||||
{
|
||||
super.handleMouseInput();
|
||||
this.entryList.handleMouseInput();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int x, int y, int mouseEvent) throws IOException
|
||||
{
|
||||
if (mouseEvent != 0 || !this.entryList.mouseClicked(x, y, mouseEvent))
|
||||
{
|
||||
this.entryList.mouseClickedPassThru(x, y, mouseEvent);
|
||||
super.mouseClicked(x, y, mouseEvent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseReleased(int x, int y, int mouseEvent)
|
||||
{
|
||||
if (mouseEvent != 0 || !this.entryList.mouseReleased(x, y, mouseEvent))
|
||||
{
|
||||
super.mouseReleased(x, y, mouseEvent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char eventChar, int eventKey)
|
||||
{
|
||||
if (eventKey == Keyboard.KEY_ESCAPE)
|
||||
this.mc.displayGuiScreen(parentScreen);
|
||||
else
|
||||
this.entryList.keyTyped(eventChar, eventKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen()
|
||||
{
|
||||
super.updateScreen();
|
||||
this.entryList.updateScreen();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int par1, int par2, float par3)
|
||||
{
|
||||
this.drawDefaultBackground();
|
||||
this.entryList.drawScreen(par1, par2, par3);
|
||||
this.drawCenteredString(this.fontRenderer, this.title, this.width / 2, 8, 16777215);
|
||||
|
||||
if (this.titleLine2 != null)
|
||||
this.drawCenteredString(this.fontRenderer, this.titleLine2, this.width / 2, 18, 16777215);
|
||||
|
||||
if (this.titleLine3 != null)
|
||||
this.drawCenteredString(this.fontRenderer, this.titleLine3, this.width / 2, 28, 16777215);
|
||||
|
||||
this.btnDone.enabled = this.entryList.isListSavable();
|
||||
this.btnDefault.enabled = enabled && !this.entryList.isDefault();
|
||||
this.btnUndoChanges.enabled = enabled && this.entryList.isChanged();
|
||||
super.drawScreen(par1, par2, par3);
|
||||
this.entryList.drawScreenPost(par1, par2, par3);
|
||||
|
||||
if (this.tooltipHoverChecker != null && this.tooltipHoverChecker.checkHover(par1, par2))
|
||||
drawToolTip(this.toolTip, par1, par2);
|
||||
}
|
||||
|
||||
public void drawToolTip(List<String> stringList, int x, int y)
|
||||
{
|
||||
GuiUtils.drawHoveringText(stringList, x, y, width, height, 300, fontRenderer);
|
||||
}
|
||||
}
|
||||
@@ -1,709 +0,0 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2018.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.client.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiListExtended;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraftforge.fml.client.config.GuiConfigEntries.ArrayEntry;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import static net.minecraftforge.fml.client.config.GuiUtils.INVALID;
|
||||
import static net.minecraftforge.fml.client.config.GuiUtils.VALID;
|
||||
|
||||
/**
|
||||
* This class implements the scrolling list functionality of the GuiEditList screen. It also provides all the default controls
|
||||
* for editing array-type properties.
|
||||
*/
|
||||
public class GuiEditArrayEntries extends GuiListExtended
|
||||
{
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
|
||||
protected GuiEditArray owningGui;
|
||||
public IConfigElement configElement;
|
||||
public List<IArrayEntry> listEntries;
|
||||
public boolean isDefault;
|
||||
public boolean isChanged;
|
||||
public boolean canAddMoreEntries;
|
||||
public final int controlWidth;
|
||||
public final Object[] beforeValues;
|
||||
public Object[] currentValues;
|
||||
|
||||
public GuiEditArrayEntries(GuiEditArray parent, Minecraft mc, IConfigElement configElement, Object[] beforeValues, Object[] currentValues)
|
||||
{
|
||||
super(mc, parent.width, parent.height, parent.titleLine2 != null ? (parent.titleLine3 != null ? 43 : 33) : 23, parent.height - 32, 20);
|
||||
this.owningGui = parent;
|
||||
this.configElement = configElement;
|
||||
this.beforeValues = beforeValues;
|
||||
this.currentValues = currentValues;
|
||||
this.setShowSelectionBox(false);
|
||||
this.isChanged = !Arrays.deepEquals(beforeValues, currentValues);
|
||||
this.isDefault = Arrays.deepEquals(currentValues, configElement.getDefaults());
|
||||
this.canAddMoreEntries = !configElement.isListLengthFixed() && (configElement.getMaxListLength() == -1 || currentValues.length < configElement.getMaxListLength());
|
||||
|
||||
listEntries = new ArrayList<IArrayEntry>();
|
||||
|
||||
controlWidth = (parent.width / 2) - (configElement.isListLengthFixed() ? 0 : 48);
|
||||
|
||||
if (configElement.isList() && configElement.getArrayEntryClass() != null)
|
||||
{
|
||||
Class<? extends IArrayEntry> clazz = configElement.getArrayEntryClass();
|
||||
for (Object value : currentValues)
|
||||
{
|
||||
try
|
||||
{
|
||||
listEntries.add(clazz.getConstructor(GuiEditArray.class, GuiEditArrayEntries.class, IConfigElement.class, Object.class)
|
||||
.newInstance(this.owningGui, this, configElement, value));
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
LOGGER.error("There was a critical error instantiating the custom IGuiEditListEntry for property {}.", configElement.getName(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (configElement.isList() && configElement.getType().equals(ConfigGuiType.BOOLEAN))
|
||||
for (Object value : currentValues)
|
||||
listEntries.add(new BooleanEntry(this.owningGui, this, configElement, Boolean.valueOf(value.toString())));
|
||||
else if (configElement.isList() && configElement.getType().equals(ConfigGuiType.INTEGER))
|
||||
for (Object value : currentValues)
|
||||
listEntries.add(new IntegerEntry(this.owningGui, this, configElement, Integer.parseInt(value.toString())));
|
||||
else if (configElement.isList() && configElement.getType().equals(ConfigGuiType.DOUBLE))
|
||||
for (Object value : currentValues)
|
||||
listEntries.add(new DoubleEntry(this.owningGui, this, configElement, Double.parseDouble(value.toString())));
|
||||
else if (configElement.isList())
|
||||
for (Object value : currentValues)
|
||||
listEntries.add(new StringEntry(this.owningGui, this, configElement, value.toString()));
|
||||
|
||||
if (!configElement.isListLengthFixed())
|
||||
listEntries.add(new BaseEntry(this.owningGui, this, configElement));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getScrollBarX()
|
||||
{
|
||||
return width - (width / 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the width of the list
|
||||
*/
|
||||
@Override
|
||||
public int getListWidth()
|
||||
{
|
||||
return owningGui.width;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IArrayEntry getListEntry(int index)
|
||||
{
|
||||
return listEntries.get(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getSize()
|
||||
{
|
||||
return listEntries.size();
|
||||
}
|
||||
|
||||
public void addNewEntry(int index)
|
||||
{
|
||||
if (configElement.isList() && configElement.getArrayEntryClass() != null)
|
||||
{
|
||||
Class<? extends IArrayEntry> clazz = configElement.getArrayEntryClass();
|
||||
try
|
||||
{
|
||||
Object value;
|
||||
switch (configElement.getType())
|
||||
{
|
||||
case BOOLEAN:
|
||||
value = true;
|
||||
break;
|
||||
case INTEGER:
|
||||
value = 0;
|
||||
break;
|
||||
case DOUBLE:
|
||||
value = 0.0D;
|
||||
break;
|
||||
default:
|
||||
value = "";
|
||||
}
|
||||
listEntries.add(index, clazz.getConstructor(GuiEditArray.class, GuiEditArrayEntries.class, IConfigElement.class, Object.class).newInstance(this.owningGui, this, configElement, value));
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
LOGGER.error("There was a critical error instantiating the custom IGuiEditListEntry for property {}.", configElement.getName(), e);
|
||||
}
|
||||
}
|
||||
else if (configElement.isList() && configElement.getType() == ConfigGuiType.BOOLEAN)
|
||||
listEntries.add(index, new BooleanEntry(this.owningGui, this, this.configElement, true));
|
||||
else if (configElement.isList() && configElement.getType() == ConfigGuiType.INTEGER)
|
||||
listEntries.add(index, new IntegerEntry(this.owningGui, this, this.configElement, 0));
|
||||
else if (configElement.isList() && configElement.getType() == ConfigGuiType.DOUBLE)
|
||||
listEntries.add(index, new DoubleEntry(this.owningGui, this, this.configElement, 0.0D));
|
||||
else if (configElement.isList())
|
||||
listEntries.add(index, new StringEntry(this.owningGui, this, this.configElement, ""));
|
||||
this.canAddMoreEntries = !configElement.isListLengthFixed()
|
||||
&& (configElement.getMaxListLength() == -1 || this.listEntries.size() - 1 < configElement.getMaxListLength());
|
||||
keyTyped((char) Keyboard.CHAR_NONE, Keyboard.KEY_END);
|
||||
}
|
||||
|
||||
public void removeEntry(int index)
|
||||
{
|
||||
this.listEntries.remove(index);
|
||||
this.canAddMoreEntries = !configElement.isListLengthFixed()
|
||||
&& (configElement.getMaxListLength() == -1 || this.listEntries.size() - 1 < configElement.getMaxListLength());
|
||||
keyTyped((char) Keyboard.CHAR_NONE, Keyboard.KEY_END);
|
||||
}
|
||||
|
||||
public boolean isChanged()
|
||||
{
|
||||
return isChanged;
|
||||
}
|
||||
|
||||
public boolean isDefault()
|
||||
{
|
||||
return isDefault;
|
||||
}
|
||||
|
||||
public void recalculateState()
|
||||
{
|
||||
isDefault = true;
|
||||
isChanged = false;
|
||||
|
||||
int listLength = configElement.isListLengthFixed() ? listEntries.size() : listEntries.size() - 1;
|
||||
|
||||
if (listLength != configElement.getDefaults().length)
|
||||
{
|
||||
isDefault = false;
|
||||
}
|
||||
|
||||
if (listLength != beforeValues.length)
|
||||
{
|
||||
isChanged = true;
|
||||
}
|
||||
|
||||
if (isDefault)
|
||||
for (int i = 0; i < listLength; i++)
|
||||
if (!configElement.getDefaults()[i].equals(listEntries.get(i).getValue()))
|
||||
isDefault = false;
|
||||
|
||||
if (!isChanged)
|
||||
for (int i = 0; i < listLength; i++)
|
||||
if (!beforeValues[i].equals(listEntries.get(i).getValue()))
|
||||
isChanged = true;
|
||||
}
|
||||
|
||||
protected void keyTyped(char eventChar, int eventKey)
|
||||
{
|
||||
for (IArrayEntry entry : this.listEntries)
|
||||
entry.keyTyped(eventChar, eventKey);
|
||||
|
||||
recalculateState();
|
||||
}
|
||||
|
||||
protected void updateScreen()
|
||||
{
|
||||
for (IArrayEntry entry : this.listEntries)
|
||||
entry.updateCursorCounter();
|
||||
}
|
||||
|
||||
protected void mouseClickedPassThru(int x, int y, int mouseEvent)
|
||||
{
|
||||
for (IArrayEntry entry : this.listEntries)
|
||||
entry.mouseClicked(x, y, mouseEvent);
|
||||
}
|
||||
|
||||
protected boolean isListSavable()
|
||||
{
|
||||
for (IArrayEntry entry : this.listEntries)
|
||||
if (!entry.isValueSavable())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void saveListChanges()
|
||||
{
|
||||
int listLength = configElement.isListLengthFixed() ? listEntries.size() : listEntries.size() - 1;
|
||||
|
||||
if (owningGui.slotIndex != -1 && owningGui.parentScreen != null
|
||||
&& owningGui.parentScreen instanceof GuiConfig
|
||||
&& ((GuiConfig) owningGui.parentScreen).entryList.getListEntry(owningGui.slotIndex) instanceof ArrayEntry)
|
||||
{
|
||||
ArrayEntry entry = (ArrayEntry) ((GuiConfig) owningGui.parentScreen).entryList.getListEntry(owningGui.slotIndex);
|
||||
|
||||
Object[] ao = new Object[listLength];
|
||||
for (int i = 0; i < listLength; i++)
|
||||
ao[i] = listEntries.get(i).getValue();
|
||||
|
||||
entry.setListFromChildScreen(ao);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (configElement.isList() && configElement.getType() == ConfigGuiType.BOOLEAN)
|
||||
{
|
||||
Boolean[] abol = new Boolean[listLength];
|
||||
for (int i = 0; i < listLength; i++)
|
||||
abol[i] = Boolean.valueOf(listEntries.get(i).getValue().toString());
|
||||
|
||||
configElement.set(abol);
|
||||
}
|
||||
else if (configElement.isList() && configElement.getType() == ConfigGuiType.INTEGER)
|
||||
{
|
||||
Integer[] ai = new Integer[listLength];
|
||||
for (int i = 0; i < listLength; i++)
|
||||
ai[i] = Integer.valueOf(listEntries.get(i).getValue().toString());
|
||||
|
||||
configElement.set(ai);
|
||||
}
|
||||
else if (configElement.isList() && configElement.getType() == ConfigGuiType.DOUBLE)
|
||||
{
|
||||
Double[] ad = new Double[listLength];
|
||||
for (int i = 0; i < listLength; i++)
|
||||
ad[i] = Double.valueOf(listEntries.get(i).getValue().toString());
|
||||
|
||||
configElement.set(ad);
|
||||
}
|
||||
else if (configElement.isList())
|
||||
{
|
||||
String[] as = new String[listLength];
|
||||
for (int i = 0; i < listLength; i++)
|
||||
as[i] = listEntries.get(i).getValue().toString();
|
||||
|
||||
configElement.set(as);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void drawScreenPost(int mouseX, int mouseY, float f)
|
||||
{
|
||||
for (IArrayEntry entry : this.listEntries)
|
||||
entry.drawToolTip(mouseX, mouseY);
|
||||
}
|
||||
|
||||
public Minecraft getMC()
|
||||
{
|
||||
return this.mc;
|
||||
}
|
||||
|
||||
/**
|
||||
* IGuiListEntry Inner Classes
|
||||
*/
|
||||
|
||||
public static class DoubleEntry extends StringEntry
|
||||
{
|
||||
public DoubleEntry(GuiEditArray owningScreen, GuiEditArrayEntries owningEntryList, IConfigElement configElement, Double value)
|
||||
{
|
||||
super(owningScreen, owningEntryList, configElement, value);
|
||||
this.isValidated = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(char eventChar, int eventKey)
|
||||
{
|
||||
if (owningScreen.enabled || eventKey == Keyboard.KEY_LEFT || eventKey == Keyboard.KEY_RIGHT
|
||||
|| eventKey == Keyboard.KEY_HOME || eventKey == Keyboard.KEY_END)
|
||||
{
|
||||
String validChars = "0123456789";
|
||||
String before = this.textFieldValue.getText();
|
||||
if (validChars.contains(String.valueOf(eventChar)) ||
|
||||
(!before.startsWith("-") && this.textFieldValue.getCursorPosition() == 0 && eventChar == '-')
|
||||
|| (!before.contains(".") && eventChar == '.')
|
||||
|| eventKey == Keyboard.KEY_BACK || eventKey == Keyboard.KEY_DELETE || eventKey == Keyboard.KEY_LEFT || eventKey == Keyboard.KEY_RIGHT
|
||||
|| eventKey == Keyboard.KEY_HOME || eventKey == Keyboard.KEY_END)
|
||||
this.textFieldValue.textboxKeyTyped((owningScreen.enabled ? eventChar : Keyboard.CHAR_NONE), eventKey);
|
||||
|
||||
if (!textFieldValue.getText().trim().isEmpty() && !textFieldValue.getText().trim().equals("-"))
|
||||
{
|
||||
try
|
||||
{
|
||||
double value = Double.parseDouble(textFieldValue.getText().trim());
|
||||
if (value < Double.valueOf(configElement.getMinValue().toString()) || value > Double.valueOf(configElement.getMaxValue().toString()))
|
||||
this.isValidValue = false;
|
||||
else
|
||||
this.isValidValue = true;
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
this.isValidValue = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
this.isValidValue = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double getValue()
|
||||
{
|
||||
try
|
||||
{
|
||||
return Double.valueOf(this.textFieldValue.getText().trim());
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
return Double.MAX_VALUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class IntegerEntry extends StringEntry
|
||||
{
|
||||
public IntegerEntry(GuiEditArray owningScreen, GuiEditArrayEntries owningEntryList, IConfigElement configElement, Integer value)
|
||||
{
|
||||
super(owningScreen, owningEntryList, configElement, value);
|
||||
this.isValidated = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(char eventChar, int eventKey)
|
||||
{
|
||||
if (owningScreen.enabled || eventKey == Keyboard.KEY_LEFT || eventKey == Keyboard.KEY_RIGHT
|
||||
|| eventKey == Keyboard.KEY_HOME || eventKey == Keyboard.KEY_END)
|
||||
{
|
||||
String validChars = "0123456789";
|
||||
String before = this.textFieldValue.getText();
|
||||
if (validChars.contains(String.valueOf(eventChar))
|
||||
|| (!before.startsWith("-") && this.textFieldValue.getCursorPosition() == 0 && eventChar == '-')
|
||||
|| eventKey == Keyboard.KEY_BACK || eventKey == Keyboard.KEY_DELETE
|
||||
|| eventKey == Keyboard.KEY_LEFT || eventKey == Keyboard.KEY_RIGHT || eventKey == Keyboard.KEY_HOME || eventKey == Keyboard.KEY_END)
|
||||
this.textFieldValue.textboxKeyTyped((owningScreen.enabled ? eventChar : Keyboard.CHAR_NONE), eventKey);
|
||||
|
||||
if (!textFieldValue.getText().trim().isEmpty() && !textFieldValue.getText().trim().equals("-"))
|
||||
{
|
||||
try
|
||||
{
|
||||
long value = Long.parseLong(textFieldValue.getText().trim());
|
||||
if (value < Integer.valueOf(configElement.getMinValue().toString()) || value > Integer.valueOf(configElement.getMaxValue().toString()))
|
||||
this.isValidValue = false;
|
||||
else
|
||||
this.isValidValue = true;
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
this.isValidValue = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
this.isValidValue = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getValue()
|
||||
{
|
||||
try
|
||||
{
|
||||
return Integer.valueOf(this.textFieldValue.getText().trim());
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class StringEntry extends BaseEntry
|
||||
{
|
||||
protected final GuiTextField textFieldValue;
|
||||
|
||||
public StringEntry(GuiEditArray owningScreen, GuiEditArrayEntries owningEntryList, IConfigElement configElement, Object value)
|
||||
{
|
||||
super(owningScreen, owningEntryList, configElement);
|
||||
this.textFieldValue = new GuiTextField(0, owningEntryList.getMC().fontRenderer, owningEntryList.width / 4 + 1, 0, owningEntryList.controlWidth - 3, 16);
|
||||
this.textFieldValue.setMaxStringLength(10000);
|
||||
this.textFieldValue.setText(value.toString());
|
||||
this.isValidated = configElement.getValidationPattern() != null;
|
||||
|
||||
if (configElement.getValidationPattern() != null)
|
||||
{
|
||||
if (configElement.getValidationPattern().matcher(this.textFieldValue.getText().trim()).matches())
|
||||
isValidValue = true;
|
||||
else
|
||||
isValidValue = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY, boolean isSelected, float partial)
|
||||
{
|
||||
super.drawEntry(slotIndex, x, y, listWidth, slotHeight, mouseX, mouseY, isSelected, partial);
|
||||
if (configElement.isListLengthFixed() || slotIndex != owningEntryList.listEntries.size() - 1)
|
||||
{
|
||||
this.textFieldValue.setVisible(true);
|
||||
this.textFieldValue.y = y + 1;
|
||||
this.textFieldValue.drawTextBox();
|
||||
}
|
||||
else
|
||||
this.textFieldValue.setVisible(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(char eventChar, int eventKey)
|
||||
{
|
||||
if (owningScreen.enabled || eventKey == Keyboard.KEY_LEFT || eventKey == Keyboard.KEY_RIGHT
|
||||
|| eventKey == Keyboard.KEY_HOME || eventKey == Keyboard.KEY_END)
|
||||
{
|
||||
this.textFieldValue.textboxKeyTyped((owningScreen.enabled ? eventChar : Keyboard.CHAR_NONE), eventKey);
|
||||
|
||||
if (configElement.getValidationPattern() != null)
|
||||
{
|
||||
if (configElement.getValidationPattern().matcher(this.textFieldValue.getText().trim()).matches())
|
||||
isValidValue = true;
|
||||
else
|
||||
isValidValue = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCursorCounter()
|
||||
{
|
||||
this.textFieldValue.updateCursorCounter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int x, int y, int mouseEvent)
|
||||
{
|
||||
this.textFieldValue.mouseClicked(x, y, mouseEvent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue()
|
||||
{
|
||||
return this.textFieldValue.getText().trim();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class BooleanEntry extends BaseEntry
|
||||
{
|
||||
protected final GuiButtonExt btnValue;
|
||||
private boolean value;
|
||||
|
||||
public BooleanEntry(GuiEditArray owningScreen, GuiEditArrayEntries owningEntryList, IConfigElement configElement, boolean value)
|
||||
{
|
||||
super(owningScreen, owningEntryList, configElement);
|
||||
this.value = value;
|
||||
this.btnValue = new GuiButtonExt(0, 0, 0, owningEntryList.controlWidth, 18, I18n.format(String.valueOf(value)));
|
||||
this.btnValue.enabled = owningScreen.enabled;
|
||||
this.isValidated = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY, boolean isSelected, float partial)
|
||||
{
|
||||
super.drawEntry(slotIndex, x, y, listWidth, slotHeight, mouseX, mouseY, isSelected, partial);
|
||||
this.btnValue.x = listWidth / 4;
|
||||
this.btnValue.y = y;
|
||||
|
||||
String trans = I18n.format(String.valueOf(value));
|
||||
if (!trans.equals(String.valueOf(value)))
|
||||
this.btnValue.displayString = trans;
|
||||
else
|
||||
this.btnValue.displayString = String.valueOf(value);
|
||||
btnValue.packedFGColour = value ? GuiUtils.getColorCode('2', true) : GuiUtils.getColorCode('4', true);
|
||||
|
||||
this.btnValue.drawButton(owningEntryList.getMC(), mouseX, mouseY, partial);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mousePressed(int index, int x, int y, int mouseEvent, int relativeX, int relativeY)
|
||||
{
|
||||
if (this.btnValue.mousePressed(owningEntryList.getMC(), x, y))
|
||||
{
|
||||
btnValue.playPressSound(owningEntryList.getMC().getSoundHandler());
|
||||
value = !value;
|
||||
owningEntryList.recalculateState();
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.mousePressed(index, x, y, mouseEvent, relativeX, relativeY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(int index, int x, int y, int mouseEvent, int relativeX, int relativeY)
|
||||
{
|
||||
this.btnValue.mouseReleased(x, y);
|
||||
super.mouseReleased(index, x, y, mouseEvent, relativeX, relativeY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
public static class BaseEntry extends GuiListExtended.IGuiListEntry implements IArrayEntry
|
||||
{
|
||||
protected final GuiEditArray owningScreen;
|
||||
protected final GuiEditArrayEntries owningEntryList;
|
||||
protected final IConfigElement configElement;
|
||||
protected final GuiButtonExt btnAddNewEntryAbove;
|
||||
private final HoverChecker addNewEntryAboveHoverChecker;
|
||||
protected final GuiButtonExt btnRemoveEntry;
|
||||
private final HoverChecker removeEntryHoverChecker;
|
||||
private List<String> addNewToolTip, removeToolTip;
|
||||
protected boolean isValidValue = true;
|
||||
protected boolean isValidated = false;
|
||||
|
||||
public BaseEntry(GuiEditArray owningScreen, GuiEditArrayEntries owningEntryList, IConfigElement configElement)
|
||||
{
|
||||
this.owningScreen = owningScreen;
|
||||
this.owningEntryList = owningEntryList;
|
||||
this.configElement = configElement;
|
||||
this.btnAddNewEntryAbove = new GuiButtonExt(0, 0, 0, 18, 18, "+");
|
||||
this.btnAddNewEntryAbove.packedFGColour = GuiUtils.getColorCode('2', true);
|
||||
this.btnAddNewEntryAbove.enabled = owningScreen.enabled;
|
||||
this.btnRemoveEntry = new GuiButtonExt(0, 0, 0, 18, 18, "x");
|
||||
this.btnRemoveEntry.packedFGColour = GuiUtils.getColorCode('c', true);
|
||||
this.btnRemoveEntry.enabled = owningScreen.enabled;
|
||||
this.addNewEntryAboveHoverChecker = new HoverChecker(this.btnAddNewEntryAbove, 800);
|
||||
this.removeEntryHoverChecker = new HoverChecker(this.btnRemoveEntry, 800);
|
||||
this.addNewToolTip = new ArrayList<String>();
|
||||
this.removeToolTip = new ArrayList<String>();
|
||||
addNewToolTip.add(I18n.format("fml.configgui.tooltip.addNewEntryAbove"));
|
||||
removeToolTip.add(I18n.format("fml.configgui.tooltip.removeEntry"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void func_194999_a(int entryWidth, int entryHeight, int mouseX, int mouseY, boolean isHovered, float partial)
|
||||
{
|
||||
if (this.getValue() != null && this.isValidated)
|
||||
owningEntryList.getMC().fontRenderer.func_211126_b(
|
||||
isValidValue ? TextFormatting.GREEN + VALID : TextFormatting.RED + INVALID,
|
||||
entryWidth / 4 - owningEntryList.getMC().fontRenderer.getStringWidth(VALID) - 2,
|
||||
entryHeight / 2 - owningEntryList.getMC().fontRenderer.FONT_HEIGHT / 2,
|
||||
16777215);
|
||||
|
||||
int half = entryWidth / 2;
|
||||
if (owningEntryList.canAddMoreEntries)
|
||||
{
|
||||
this.btnAddNewEntryAbove.visible = true;
|
||||
this.btnAddNewEntryAbove.x = half + ((half / 2) - 44);
|
||||
this.btnAddNewEntryAbove.y = this.func_195001_c();
|
||||
this.btnAddNewEntryAbove.drawButton(owningEntryList.getMC(), mouseX, mouseY, partial);
|
||||
}
|
||||
else
|
||||
this.btnAddNewEntryAbove.visible = false;
|
||||
|
||||
if (!configElement.isListLengthFixed() && this.field_195005_b != owningEntryList.listEntries.size() - 1)
|
||||
{
|
||||
this.btnRemoveEntry.visible = true;
|
||||
this.btnRemoveEntry.x = half + ((half / 2) - 22);
|
||||
this.btnRemoveEntry.y = this.func_195001_c();
|
||||
this.btnRemoveEntry.drawButton(owningEntryList.getMC(), mouseX, mouseY, partial);
|
||||
}
|
||||
else
|
||||
this.btnRemoveEntry.visible = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawToolTip(int mouseX, int mouseY)
|
||||
{
|
||||
boolean canHover = mouseY < owningEntryList.bottom && mouseY > owningEntryList.top;
|
||||
if (this.btnAddNewEntryAbove.visible && this.addNewEntryAboveHoverChecker.checkHover(mouseX, mouseY, canHover))
|
||||
owningScreen.drawToolTip(this.addNewToolTip, mouseX, mouseY);
|
||||
if (this.btnRemoveEntry.visible && this.removeEntryHoverChecker.checkHover(mouseX, mouseY, canHover))
|
||||
owningScreen.drawToolTip(this.removeToolTip, mouseX, mouseY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mousePressed(int index, int x, int y, int mouseEvent, int relativeX, int relativeY)
|
||||
{
|
||||
if (this.btnAddNewEntryAbove.mousePressed(owningEntryList.getMC(), x, y))
|
||||
{
|
||||
btnAddNewEntryAbove.playPressSound(owningEntryList.getMC().getSoundHandler());
|
||||
owningEntryList.addNewEntry(index);
|
||||
owningEntryList.recalculateState();
|
||||
return true;
|
||||
}
|
||||
else if (this.btnRemoveEntry.mousePressed(owningEntryList.getMC(), x, y))
|
||||
{
|
||||
btnRemoveEntry.playPressSound(owningEntryList.getMC().getSoundHandler());
|
||||
owningEntryList.removeEntry(index);
|
||||
owningEntryList.recalculateState();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(int index, int x, int y, int mouseEvent, int relativeX, int relativeY)
|
||||
{
|
||||
this.btnAddNewEntryAbove.mouseReleased(x, y);
|
||||
this.btnRemoveEntry.mouseReleased(x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(char eventChar, int eventKey)
|
||||
{}
|
||||
|
||||
@Override
|
||||
public void updateCursorCounter()
|
||||
{}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int x, int y, int mouseEvent)
|
||||
{}
|
||||
|
||||
@Override
|
||||
public boolean isValueSavable()
|
||||
{
|
||||
return isValidValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePosition(int p_178011_1_, int p_178011_2_, int p_178011_3_, float partial){}
|
||||
}
|
||||
|
||||
public static interface IArrayEntry
|
||||
{
|
||||
void keyTyped(char eventChar, int eventKey);
|
||||
|
||||
void updateCursorCounter();
|
||||
|
||||
void mouseClicked(int x, int y, int mouseEvent);
|
||||
|
||||
void drawToolTip(int mouseX, int mouseY);
|
||||
|
||||
boolean isValueSavable();
|
||||
|
||||
Object getValue();
|
||||
}
|
||||
}
|
||||
@@ -1,194 +0,0 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2018.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.client.config;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
|
||||
import static net.minecraftforge.fml.client.config.GuiUtils.RESET_CHAR;
|
||||
import static net.minecraftforge.fml.client.config.GuiUtils.UNDO_CHAR;
|
||||
|
||||
/**
|
||||
* This class provides a screen that allows the user to select a value from a list.
|
||||
*
|
||||
* @author bspkrs
|
||||
*/
|
||||
public class GuiSelectString extends GuiScreen
|
||||
{
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
|
||||
protected GuiScreen parentScreen;
|
||||
protected IConfigElement configElement;
|
||||
protected GuiSelectStringEntries entryList;
|
||||
protected GuiButtonExt btnUndoChanges, btnDefault, btnDone;
|
||||
protected String title;
|
||||
protected String titleLine2;
|
||||
protected String titleLine3;
|
||||
protected int slotIndex;
|
||||
protected final Map<Object, String> selectableValues;
|
||||
public final Object beforeValue;
|
||||
public Object currentValue;
|
||||
protected HoverChecker tooltipHoverChecker;
|
||||
protected List<String> toolTip;
|
||||
protected boolean enabled;
|
||||
|
||||
public GuiSelectString(GuiScreen parentScreen, IConfigElement configElement, int slotIndex, Map<Object, String> selectableValues, Object currentValue, boolean enabled)
|
||||
{
|
||||
this.mc = Minecraft.getMinecraft();
|
||||
this.parentScreen = parentScreen;
|
||||
this.configElement = configElement;
|
||||
this.slotIndex = slotIndex;
|
||||
this.selectableValues = selectableValues;
|
||||
this.beforeValue = currentValue;
|
||||
this.currentValue = currentValue;
|
||||
this.toolTip = new ArrayList<String>();
|
||||
this.enabled = enabled;
|
||||
String propName = I18n.format(configElement.getLanguageKey());
|
||||
String comment;
|
||||
|
||||
comment = I18n.format(configElement.getLanguageKey() + ".tooltip",
|
||||
"\n" + TextFormatting.AQUA, configElement.getDefault(), configElement.getMinValue(), configElement.getMaxValue());
|
||||
|
||||
if (!comment.equals(configElement.getLanguageKey() + ".tooltip"))
|
||||
Collections.addAll(toolTip, (TextFormatting.GREEN + propName + "\n" + TextFormatting.YELLOW + comment).split("\n"));
|
||||
else if (configElement.getComment() != null && !configElement.getComment().trim().isEmpty())
|
||||
Collections.addAll(toolTip, (TextFormatting.GREEN + propName + "\n" + TextFormatting.YELLOW + configElement.getComment()).split("\n"));
|
||||
else
|
||||
Collections.addAll(toolTip, (TextFormatting.GREEN + propName + "\n" + TextFormatting.RED + "No tooltip defined.").split("\n"));
|
||||
|
||||
if (parentScreen instanceof GuiConfig)
|
||||
{
|
||||
this.title = ((GuiConfig) parentScreen).title;
|
||||
this.titleLine2 = ((GuiConfig) parentScreen).titleLine2;
|
||||
this.titleLine3 = I18n.format(configElement.getLanguageKey());
|
||||
this.tooltipHoverChecker = new HoverChecker(28, 37, 0, parentScreen.width, 800);
|
||||
if(titleLine3 != null && titleLine2 == null)
|
||||
{
|
||||
((GuiConfig) parentScreen).titleLine2 = "";
|
||||
this.titleLine2 = "";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.title = I18n.format(configElement.getLanguageKey());
|
||||
this.tooltipHoverChecker = new HoverChecker(8, 17, 0, parentScreen.width, 800);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui()
|
||||
{
|
||||
this.entryList = new GuiSelectStringEntries(this, this.mc, this.configElement, this.selectableValues);
|
||||
|
||||
int undoGlyphWidth = mc.fontRenderer.getStringWidth(UNDO_CHAR) * 2;
|
||||
int resetGlyphWidth = mc.fontRenderer.getStringWidth(RESET_CHAR) * 2;
|
||||
int doneWidth = Math.max(mc.fontRenderer.getStringWidth(I18n.format("gui.done")) + 20, 100);
|
||||
int undoWidth = mc.fontRenderer.getStringWidth(" " + I18n.format("fml.configgui.tooltip.undoChanges")) + undoGlyphWidth + 20;
|
||||
int resetWidth = mc.fontRenderer.getStringWidth(" " + I18n.format("fml.configgui.tooltip.resetToDefault")) + resetGlyphWidth + 20;
|
||||
int buttonWidthHalf = (doneWidth + 5 + undoWidth + 5 + resetWidth) / 2;
|
||||
this.buttonList.add(btnDone = new GuiButtonExt(2000, this.width / 2 - buttonWidthHalf, this.height - 29, doneWidth, 20, I18n.format("gui.done")));
|
||||
this.buttonList.add(btnDefault = new GuiUnicodeGlyphButton(2001, this.width / 2 - buttonWidthHalf + doneWidth + 5 + undoWidth + 5,
|
||||
this.height - 29, resetWidth, 20, " " + I18n.format("fml.configgui.tooltip.resetToDefault"), RESET_CHAR, 2.0F));
|
||||
this.buttonList.add(btnUndoChanges = new GuiUnicodeGlyphButton(2002, this.width / 2 - buttonWidthHalf + doneWidth + 5,
|
||||
this.height - 29, undoWidth, 20, " " + I18n.format("fml.configgui.tooltip.undoChanges"), UNDO_CHAR, 2.0F));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button)
|
||||
{
|
||||
if (button.id == 2000)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.entryList.saveChanges();
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
LOGGER.error("Error performing GuiSelectString action:", e);
|
||||
}
|
||||
this.mc.displayGuiScreen(this.parentScreen);
|
||||
}
|
||||
else if (button.id == 2001)
|
||||
{
|
||||
this.currentValue = configElement.getDefault();
|
||||
this.entryList = new GuiSelectStringEntries(this, this.mc, this.configElement, this.selectableValues);
|
||||
}
|
||||
else if (button.id == 2002)
|
||||
{
|
||||
this.currentValue = beforeValue;
|
||||
this.entryList = new GuiSelectStringEntries(this, this.mc, this.configElement, this.selectableValues);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMouseInput() throws IOException
|
||||
{
|
||||
super.handleMouseInput();
|
||||
this.entryList.handleMouseInput();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseReleased(int x, int y, int mouseEvent)
|
||||
{
|
||||
if (mouseEvent != 0 || !this.entryList.mouseReleased(x, y, mouseEvent))
|
||||
{
|
||||
super.mouseReleased(x, y, mouseEvent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int par1, int par2, float par3)
|
||||
{
|
||||
this.drawDefaultBackground();
|
||||
this.entryList.drawScreen(par1, par2, par3);
|
||||
this.drawCenteredString(this.fontRenderer, this.title, this.width / 2, 8, 16777215);
|
||||
|
||||
if (this.titleLine2 != null)
|
||||
this.drawCenteredString(this.fontRenderer, this.titleLine2, this.width / 2, 18, 16777215);
|
||||
|
||||
if (this.titleLine3 != null)
|
||||
this.drawCenteredString(this.fontRenderer, this.titleLine3, this.width / 2, 28, 16777215);
|
||||
|
||||
this.btnDone.enabled = currentValue != null;
|
||||
this.btnDefault.enabled = enabled && !this.entryList.isDefault();
|
||||
this.btnUndoChanges.enabled = enabled && this.entryList.isChanged();
|
||||
super.drawScreen(par1, par2, par3);
|
||||
|
||||
if (this.tooltipHoverChecker != null && this.tooltipHoverChecker.checkHover(par1, par2))
|
||||
drawToolTip(this.toolTip, par1, par2);
|
||||
}
|
||||
|
||||
public void drawToolTip(List<String> stringList, int x, int y)
|
||||
{
|
||||
GuiUtils.drawHoveringText(stringList, x, y, width, height, 300, fontRenderer);
|
||||
}
|
||||
}
|
||||
@@ -1,205 +0,0 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2018.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.client.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiListExtended;
|
||||
import net.minecraftforge.fml.client.config.GuiConfigEntries.SelectValueEntry;
|
||||
|
||||
/**
|
||||
* This class implements the scrolling list functionality of the GuiSelectString screen.
|
||||
*
|
||||
* @author bspkrs
|
||||
*/
|
||||
public class GuiSelectStringEntries extends GuiListExtended
|
||||
{
|
||||
public GuiSelectString owningScreen;
|
||||
public Minecraft mc;
|
||||
public IConfigElement configElement;
|
||||
public List<IGuiSelectStringListEntry> listEntries;
|
||||
public final Map<Object, String> selectableValues;
|
||||
public int selectedIndex = -1;
|
||||
public int maxEntryWidth = 0;
|
||||
|
||||
public GuiSelectStringEntries(GuiSelectString owningScreen, Minecraft mc, IConfigElement configElement, Map<Object, String> selectableValues)
|
||||
{
|
||||
super(mc, owningScreen.width, owningScreen.height, owningScreen.titleLine2 != null ? (owningScreen.titleLine3 != null ? 43 : 33) : 23,
|
||||
owningScreen.height - 32, 11);
|
||||
this.owningScreen = owningScreen;
|
||||
this.mc = mc;
|
||||
this.configElement = configElement;
|
||||
this.selectableValues = selectableValues;
|
||||
this.setShowSelectionBox(true);
|
||||
|
||||
listEntries = new ArrayList<IGuiSelectStringListEntry>();
|
||||
|
||||
int index = 0;
|
||||
List<Entry<Object, String>> sortedList = new ArrayList<Entry<Object, String>>(selectableValues.entrySet());
|
||||
Collections.sort(sortedList, new EntryComparator());
|
||||
|
||||
for (Entry<Object, String> entry : sortedList)
|
||||
{
|
||||
listEntries.add(new ListEntry(this, entry));
|
||||
if (mc.fontRenderer.getStringWidth(entry.getValue()) > maxEntryWidth)
|
||||
maxEntryWidth = mc.fontRenderer.getStringWidth(entry.getValue());
|
||||
|
||||
if (owningScreen.currentValue.equals(entry.getKey()))
|
||||
{
|
||||
this.selectedIndex = index;
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
public static class EntryComparator implements Comparator<Entry<Object, String>>
|
||||
{
|
||||
@Override
|
||||
public int compare(Entry<Object, String> o1, Entry<Object, String> o2)
|
||||
{
|
||||
int compare = o1.getValue().toLowerCase(Locale.US).compareTo(o2.getValue().toLowerCase(Locale.US));
|
||||
|
||||
if (compare == 0)
|
||||
compare = o1.getKey().toString().toLowerCase(Locale.US).compareTo(o2.getKey().toString().toLowerCase(Locale.US));
|
||||
|
||||
return compare;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The element in the slot that was clicked, boolean for whether it was double clicked or not
|
||||
*/
|
||||
@Override
|
||||
protected void elementClicked(int index, boolean doubleClick, int mouseX, int mouseY)
|
||||
{
|
||||
selectedIndex = index;
|
||||
owningScreen.currentValue = listEntries.get(index).getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the element passed in is currently selected
|
||||
*/
|
||||
@Override
|
||||
protected boolean isSelected(int index)
|
||||
{
|
||||
return index == selectedIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getScrollBarX()
|
||||
{
|
||||
return width / 2 + this.maxEntryWidth / 2 + 5;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the width of the list
|
||||
*/
|
||||
@Override
|
||||
public int getListWidth()
|
||||
{
|
||||
return maxEntryWidth + 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGuiSelectStringListEntry getListEntry(int index)
|
||||
{
|
||||
return listEntries.get(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getSize()
|
||||
{
|
||||
return listEntries.size();
|
||||
}
|
||||
|
||||
public boolean isChanged()
|
||||
{
|
||||
return owningScreen.beforeValue != null ? !owningScreen.beforeValue.equals(owningScreen.currentValue) : owningScreen.currentValue != null;
|
||||
}
|
||||
|
||||
public boolean isDefault()
|
||||
{
|
||||
return owningScreen.currentValue != null ? owningScreen.currentValue.equals(configElement.getDefault()) : configElement.getDefault() == null;
|
||||
}
|
||||
|
||||
public void saveChanges()
|
||||
{
|
||||
if (owningScreen.slotIndex != -1 && owningScreen.parentScreen != null
|
||||
&& owningScreen.parentScreen instanceof GuiConfig
|
||||
&& ((GuiConfig) owningScreen.parentScreen).entryList.getListEntry(owningScreen.slotIndex) instanceof SelectValueEntry)
|
||||
{
|
||||
SelectValueEntry entry = (SelectValueEntry) ((GuiConfig) owningScreen.parentScreen).entryList.getListEntry(owningScreen.slotIndex);
|
||||
|
||||
entry.setValueFromChildScreen(owningScreen.currentValue);
|
||||
}
|
||||
else
|
||||
configElement.set(owningScreen.currentValue);
|
||||
}
|
||||
|
||||
public static class ListEntry implements IGuiSelectStringListEntry
|
||||
{
|
||||
protected final GuiSelectStringEntries owningList;
|
||||
protected final Entry<Object, String> value;
|
||||
|
||||
public ListEntry(GuiSelectStringEntries owningList, Entry<Object, String> value)
|
||||
{
|
||||
this.owningList = owningList;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY, boolean isSelected, float partial)
|
||||
{
|
||||
owningList.mc.fontRenderer.drawString(value.getValue(), x + 1, y, slotIndex == owningList.selectedIndex ? 16777215 : 14737632);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mousePressed(int index, int x, int y, int mouseEvent, int relativeX, int relativeY)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(int index, int x, int y, int mouseEvent, int relativeX, int relativeY)
|
||||
{}
|
||||
|
||||
@Override
|
||||
public Object getValue()
|
||||
{
|
||||
return value.getKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePosition(int p_192633_1_, int p_192633_2_, int p_192633_3_, float p_192633_4_){}
|
||||
}
|
||||
|
||||
public static interface IGuiSelectStringListEntry extends GuiListExtended.IGuiListEntry
|
||||
{
|
||||
Object getValue();
|
||||
}
|
||||
}
|
||||
@@ -128,19 +128,11 @@ public class GuiSlider extends GuiButtonExt
|
||||
* e).
|
||||
*/
|
||||
@Override
|
||||
public boolean mousePressed(Minecraft par1Minecraft, int par2, int par3)
|
||||
public void func_194829_a(double mouseX, double mouseY)
|
||||
{
|
||||
if (super.mousePressed(par1Minecraft, par2, par3))
|
||||
{
|
||||
this.sliderValue = (float)(par2 - (this.x + 4)) / (float)(this.width - 8);
|
||||
updateSlider();
|
||||
this.dragging = true;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
this.sliderValue = (mouseX - (this.x + 4)) / (this.width - 8);
|
||||
updateSlider();
|
||||
this.dragging = true;
|
||||
}
|
||||
|
||||
public void updateSlider()
|
||||
@@ -198,7 +190,7 @@ public class GuiSlider extends GuiButtonExt
|
||||
* Fired when the mouse button is released. Equivalent of MouseListener.mouseReleased(MouseEvent e).
|
||||
*/
|
||||
@Override
|
||||
public void mouseReleased(int par1, int par2)
|
||||
public void func_194831_b(double mouseX, double mouseY)
|
||||
{
|
||||
this.dragging = false;
|
||||
}
|
||||
|
||||
@@ -41,19 +41,20 @@ public class GuiUnicodeGlyphButton extends GuiButtonExt
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawButton(Minecraft mc, int mouseX, int mouseY, float partial)
|
||||
public void func_194828_a(int mouseX, int mouseY, float partial)
|
||||
{
|
||||
if (this.visible)
|
||||
{
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
this.hovered = mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height;
|
||||
int k = this.getHoverState(this.hovered);
|
||||
GuiUtils.drawContinuousTexturedBox(GuiButton.BUTTON_TEXTURES, this.x, this.y, 0, 46 + k * 20, this.width, this.height, 200, 20, 2, 3, 2, 2, this.zLevel);
|
||||
this.mouseDragged(mc, mouseX, mouseY);
|
||||
int color = 14737632;
|
||||
|
||||
if (packedFGColour != 0)
|
||||
if (packedFGColor != 0)
|
||||
{
|
||||
color = packedFGColour;
|
||||
color = packedFGColor;
|
||||
}
|
||||
else if (!this.enabled)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package net.minecraftforge.fml.client.config;
|
||||
|
||||
public interface IArrayEntry
|
||||
{
|
||||
void keyTyped(char eventChar, int eventKey);
|
||||
|
||||
void updateCursorCounter();
|
||||
|
||||
void mouseClicked(int x, int y, int mouseEvent);
|
||||
|
||||
void drawToolTip(int mouseX, int mouseY);
|
||||
|
||||
boolean isValueSavable();
|
||||
|
||||
Object getValue();
|
||||
}
|
||||
@@ -22,9 +22,6 @@ package net.minecraftforge.fml.client.config;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import net.minecraftforge.fml.client.config.GuiConfigEntries.IConfigEntry;
|
||||
import net.minecraftforge.fml.client.config.GuiEditArrayEntries.IArrayEntry;
|
||||
|
||||
/**
|
||||
* This interface provides the information needed by GuiConfig and GuiConfigEntries to display config elements for editing.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
package net.minecraftforge.fml.client.config;
|
||||
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
|
||||
/**
|
||||
* Provides an interface for defining GuiConfigEntry.listEntry objects.
|
||||
*/
|
||||
public interface IConfigEntry
|
||||
{
|
||||
/**
|
||||
* Gets the IConfigElement object owned by this entry.
|
||||
* @return
|
||||
*/
|
||||
IConfigElement getConfigElement();
|
||||
|
||||
/**
|
||||
* Gets the name of the ConfigElement owned by this entry.
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Gets the current value of this entry.
|
||||
*/
|
||||
Object getCurrentValue();
|
||||
|
||||
/**
|
||||
* Gets the current values of this list entry.
|
||||
*/
|
||||
Object[] getCurrentValues();
|
||||
|
||||
/**
|
||||
* Is this list entry enabled?
|
||||
*
|
||||
* @return true if this entry's controls should be enabled, false otherwise.
|
||||
*/
|
||||
boolean enabled();
|
||||
|
||||
/**
|
||||
* Handles user keystrokes for any GuiTextField objects in this entry. Call {@link GuiTextField#textboxKeyTyped(char, int)} for any GuiTextField
|
||||
* objects that should receive the input provided.
|
||||
*/
|
||||
void keyTyped(char eventChar, int eventKey);
|
||||
|
||||
/**
|
||||
* Call {@link GuiTextField#updateCursorCounter()} for any GuiTextField objects in this entry.
|
||||
*/
|
||||
void updateCursorCounter();
|
||||
|
||||
/**
|
||||
* Call {@link GuiTextField#mouseClicked(int, int, int)} for and GuiTextField objects in this entry.
|
||||
*/
|
||||
void mouseClicked(int x, int y, int mouseEvent);
|
||||
|
||||
/**
|
||||
* Is this entry's value equal to the default value? Generally true should be returned if this entry is not a property or category
|
||||
* entry.
|
||||
*
|
||||
* @return true if this entry's value is equal to this entry's default value.
|
||||
*/
|
||||
boolean isDefault();
|
||||
|
||||
/**
|
||||
* Sets this entry's value to the default value.
|
||||
*/
|
||||
void setToDefault();
|
||||
|
||||
/**
|
||||
* Handles reverting any changes that have occurred to this entry.
|
||||
*/
|
||||
void undoChanges();
|
||||
|
||||
/**
|
||||
* Has the value of this entry changed?
|
||||
*
|
||||
* @return true if changes have been made to this entry's value, false otherwise.
|
||||
*/
|
||||
boolean isChanged();
|
||||
|
||||
/**
|
||||
* Handles saving any changes that have been made to this entry back to the underlying object. It is a good practice to check
|
||||
* isChanged() before performing the save action. This method should return true if the element has changed AND REQUIRES A RESTART.
|
||||
*/
|
||||
boolean saveConfigElement();
|
||||
|
||||
/**
|
||||
* Handles drawing any tooltips that apply to this entry. This method is called after all other GUI elements have been drawn to the
|
||||
* screen, so it could also be used to draw any GUI element that needs to be drawn after all entries have had drawEntry() called.
|
||||
*/
|
||||
void drawToolTip(int mouseX, int mouseY);
|
||||
|
||||
/**
|
||||
* Gets this entry's label width.
|
||||
*/
|
||||
int getLabelWidth();
|
||||
|
||||
/**
|
||||
* Gets this entry's right-hand x boundary. This value is used to control where the scroll bar is placed.
|
||||
*/
|
||||
int getEntryRightBound();
|
||||
|
||||
/**
|
||||
* This method is called when the parent GUI is closed. Most handlers won't need this; it is provided for special cases.
|
||||
*/
|
||||
void onGuiClosed();
|
||||
}
|
||||
@@ -16,27 +16,23 @@
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/* TODO error GUIs
|
||||
package net.minecraftforge.fml.client.gui;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.GuiYesNo;
|
||||
import net.minecraft.client.gui.GuiYesNoCallback;
|
||||
import net.minecraftforge.fml.client.FMLClientHandler;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
import net.minecraftforge.fml.StartupQuery;
|
||||
import net.minecraftforge.fml.common.ZipperUtil;
|
||||
|
||||
public class GuiOldSaveLoadConfirm extends GuiYesNo implements GuiYesNoCallback {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
|
||||
private String dirName;
|
||||
private String saveName;
|
||||
private File zip;
|
||||
@@ -111,3 +107,4 @@ public class GuiOldSaveLoadConfirm extends GuiYesNo implements GuiYesNoCallback
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
Reference in new issue
Block a user