That's one heck of a commit you've got there...
I may have got a bit behind with version control. A lot behind, in fact. Maybe I'll go back and split this sometime - then again, I probably won't. But hey, at least it's here!
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
package electroblob.wizardry.client.gui.config;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.client.config.*;
|
||||
import net.minecraftforge.fml.client.config.GuiEditArrayEntries.StringEntry;
|
||||
import net.minecraftforge.fml.common.registry.EntityEntry;
|
||||
import net.minecraftforge.fml.common.registry.ForgeRegistries;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* [NYI] Intended as a way of choosing entities by name from all those currently registered, within the config file, so
|
||||
* that users don't have to look up the entity IDs. I can't get this to work correctly at the moment.
|
||||
*/
|
||||
public class EntityNameEntry extends StringEntry {
|
||||
|
||||
protected final GuiButtonExt btnValue;
|
||||
protected Object entityClass;
|
||||
|
||||
public EntityNameEntry(GuiEditArray owningScreen, GuiEditArrayEntries owningEntryList, IConfigElement configElement,
|
||||
Object value){
|
||||
super(owningScreen, owningEntryList, configElement, value);
|
||||
this.btnValue = new GuiButtonExt(0, 0, 0, owningEntryList.controlWidth, 18,
|
||||
I18n.format(this.textFieldValue.getText()));
|
||||
// this.btnValue.enabled = owningScreen.enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY,
|
||||
boolean isSelected, float partialTicks){
|
||||
//super.drawEntry(slotIndex, x, y, listWidth, slotHeight, mouseX, mouseY, isSelected, partial);
|
||||
this.btnValue.x = listWidth / 4;
|
||||
this.btnValue.y = y;
|
||||
|
||||
String trans = I18n.format(this.textFieldValue.getText());
|
||||
if(!trans.equals(this.textFieldValue.getText()))
|
||||
this.btnValue.displayString = trans;
|
||||
else
|
||||
this.btnValue.displayString = this.textFieldValue.getText();
|
||||
// btnValue.packedFGColour = value ? GuiUtils.getColorCode('2', true) : GuiUtils.getColorCode('4', true);
|
||||
|
||||
this.btnValue.drawButton(owningEntryList.getMC(), mouseX, mouseY, partialTicks);
|
||||
}
|
||||
|
||||
@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());
|
||||
// Goodness only knows if this works, but the class is unimplemented right now so it doesn't really matter.
|
||||
Map<Object, String> map = ForgeRegistries.ENTITIES.getEntries().stream().collect(
|
||||
Collectors.<Entry<ResourceLocation, EntityEntry>, Object, String>toMap(e -> e.getValue().getClass(),
|
||||
e -> e.getValue().getName()));
|
||||
Minecraft.getMinecraft().displayGuiScreen(
|
||||
new GuiSelectString(this.owningScreen, configElement, index, map, this.getValue(), true));
|
||||
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 this.textFieldValue.getText();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
package electroblob.wizardry.client.gui.config;
|
||||
|
||||
import electroblob.wizardry.Settings;
|
||||
import electroblob.wizardry.Wizardry;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraftforge.common.config.ConfigElement;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import net.minecraftforge.fml.client.config.DummyConfigElement.DummyCategoryElement;
|
||||
import net.minecraftforge.fml.client.config.GuiConfig;
|
||||
import net.minecraftforge.fml.client.config.GuiConfigEntries;
|
||||
import net.minecraftforge.fml.client.config.GuiConfigEntries.CategoryEntry;
|
||||
import net.minecraftforge.fml.client.config.IConfigElement;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GuiConfigWizardry extends GuiConfig {
|
||||
|
||||
public GuiConfigWizardry(GuiScreen parent){
|
||||
super(parent, getConfigEntries(), Wizardry.MODID, false, false,
|
||||
Wizardry.NAME + " - " + I18n.format("config." + Wizardry.MODID + ".title.general"));
|
||||
// this.titleLine2 = "File location: " + Wizardry.config.getConfigFile().getAbsolutePath();
|
||||
}
|
||||
|
||||
private static List<IConfigElement> getConfigEntries(){
|
||||
|
||||
List<IConfigElement> configList = new ArrayList<IConfigElement>(1);
|
||||
|
||||
configList.add(new DummyCategoryElement("gameplayConfig", "config." + Wizardry.MODID + ".category." + Settings.GAMEPLAY_CATEGORY, GameplayCategory.class));
|
||||
configList.add(new DummyCategoryElement("worldgenConfig", "config." + Wizardry.MODID + ".category." + Settings.WORLDGEN_CATEGORY, WorldgenCategory.class));
|
||||
configList.add(new DummyCategoryElement("commandsConfig", "config." + Wizardry.MODID + ".category." + Settings.COMMANDS_CATEGORY, CommandsCategory.class));
|
||||
configList.add(new DummyCategoryElement("clientConfig", "config." + Wizardry.MODID + ".category." + Settings.CLIENT_CATEGORY, ClientCategory.class));
|
||||
configList.add(new DummyCategoryElement("spellsConfig", "config." + Wizardry.MODID + ".category." + Settings.SPELLS_CATEGORY, SpellsCategory.class));
|
||||
configList.add(new DummyCategoryElement("resistancesConfig", "config." + Wizardry.MODID + ".category." + Settings.RESISTANCES_CATEGORY, ResistancesCategory.class));
|
||||
configList.add(new DummyCategoryElement("compatibilityConfig", "config." + Wizardry.MODID + ".category." + Settings.COMPATIBILITY_CATEGORY, CompatibilityCategory.class));
|
||||
|
||||
configList.addAll(new ConfigElement(Wizardry.settings.getConfigCategory(Configuration.CATEGORY_GENERAL)).getChildElements());
|
||||
|
||||
return configList;
|
||||
}
|
||||
|
||||
// The reason this system is so convoluted is that it's designed for use with the @Config annotation. The problem is,
|
||||
// I'm not sure whether that will play well with the load phases. Hmmm...
|
||||
|
||||
public static abstract class CategoryBase extends CategoryEntry {
|
||||
|
||||
public CategoryBase(GuiConfig owningScreen, GuiConfigEntries owningEntryList, IConfigElement prop){
|
||||
super(owningScreen, owningEntryList, prop);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GuiScreen buildChildScreen(){
|
||||
|
||||
String category = this.getCategory();
|
||||
|
||||
// This GuiConfig object specifies the configID of the object and as such will force-save when it is closed.
|
||||
// The parent GuiConfig object's entryList will also be refreshed to reflect the changes.
|
||||
GuiConfig childScreen = new GuiConfig(this.owningScreen,
|
||||
(new ConfigElement(Wizardry.settings.getConfigCategory(category))).getChildElements(),
|
||||
this.owningScreen.modID, category, false, false,
|
||||
Wizardry.NAME + " - " + I18n.format("config." + Wizardry.MODID + ".title." + category));
|
||||
|
||||
childScreen.titleLine2 = I18n.format("config." + Wizardry.MODID + ".subtitle." + category);
|
||||
|
||||
return childScreen;
|
||||
}
|
||||
|
||||
protected abstract String getCategory();
|
||||
}
|
||||
|
||||
/** Gameplay category of the config gui. */
|
||||
public static class GameplayCategory extends CategoryBase {
|
||||
|
||||
public GameplayCategory(GuiConfig owningScreen, GuiConfigEntries owningEntryList, IConfigElement prop){
|
||||
super(owningScreen, owningEntryList, prop);
|
||||
}
|
||||
|
||||
@Override protected String getCategory() { return Settings.GAMEPLAY_CATEGORY; }
|
||||
}
|
||||
|
||||
/** Worldgen category of the config gui. */
|
||||
public static class WorldgenCategory extends CategoryBase {
|
||||
|
||||
public WorldgenCategory(GuiConfig owningScreen, GuiConfigEntries owningEntryList, IConfigElement prop){
|
||||
super(owningScreen, owningEntryList, prop);
|
||||
}
|
||||
|
||||
@Override protected String getCategory() { return Settings.WORLDGEN_CATEGORY; }
|
||||
}
|
||||
|
||||
/** Commands category of the config gui. */
|
||||
public static class CommandsCategory extends CategoryBase {
|
||||
|
||||
public CommandsCategory(GuiConfig owningScreen, GuiConfigEntries owningEntryList, IConfigElement prop){
|
||||
super(owningScreen, owningEntryList, prop);
|
||||
}
|
||||
|
||||
@Override protected String getCategory() { return Settings.COMMANDS_CATEGORY; }
|
||||
}
|
||||
|
||||
/** Client category of the config gui. */
|
||||
public static class ClientCategory extends CategoryBase {
|
||||
|
||||
public ClientCategory(GuiConfig owningScreen, GuiConfigEntries owningEntryList, IConfigElement prop){
|
||||
super(owningScreen, owningEntryList, prop);
|
||||
}
|
||||
|
||||
@Override protected String getCategory() { return Settings.CLIENT_CATEGORY; }
|
||||
}
|
||||
|
||||
/** Spells category of the config gui. */
|
||||
public static class SpellsCategory extends CategoryBase {
|
||||
|
||||
public SpellsCategory(GuiConfig owningScreen, GuiConfigEntries owningEntryList, IConfigElement prop){
|
||||
super(owningScreen, owningEntryList, prop);
|
||||
}
|
||||
|
||||
@Override protected String getCategory() { return Settings.SPELLS_CATEGORY; }
|
||||
}
|
||||
|
||||
/** Resistances category of the config gui. */
|
||||
public static class ResistancesCategory extends CategoryBase {
|
||||
|
||||
public ResistancesCategory(GuiConfig owningScreen, GuiConfigEntries owningEntryList, IConfigElement prop){
|
||||
super(owningScreen, owningEntryList, prop);
|
||||
}
|
||||
|
||||
@Override protected String getCategory() { return Settings.RESISTANCES_CATEGORY; }
|
||||
}
|
||||
|
||||
/** Commands category of the config gui. */
|
||||
public static class CompatibilityCategory extends CategoryBase {
|
||||
|
||||
public CompatibilityCategory(GuiConfig owningScreen, GuiConfigEntries owningEntryList, IConfigElement prop){
|
||||
super(owningScreen, owningEntryList, prop);
|
||||
}
|
||||
|
||||
@Override protected String getCategory() { return Settings.COMPATIBILITY_CATEGORY; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
package electroblob.wizardry.client.gui.config;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import electroblob.wizardry.Wizardry;
|
||||
import electroblob.wizardry.client.gui.GuiSpellDisplay;
|
||||
import electroblob.wizardry.client.gui.GuiSpellDisplay.Skin;
|
||||
import electroblob.wizardry.registry.Spells;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraftforge.fml.client.config.GuiSelectString;
|
||||
import net.minecraftforge.fml.client.config.IConfigElement;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Map;
|
||||
|
||||
public class GuiSelectHUDSkin extends GuiSelectString {
|
||||
|
||||
public GuiSelectHUDSkin(GuiScreen parentScreen, IConfigElement configElement, int slotIndex, Map<Object, String> selectableValues, Object currentValue, boolean enabled){
|
||||
super(parentScreen, configElement, slotIndex, selectableValues, currentValue, enabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui(){
|
||||
super.initGui();
|
||||
setEntryListDimensions();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button){
|
||||
super.actionPerformed(button);
|
||||
setEntryListDimensions(); // Stops the entry list from resizing when a button is pressed
|
||||
}
|
||||
|
||||
private void setEntryListDimensions(){
|
||||
this.entryList.setDimensions(150, height, 43, height-43);
|
||||
this.entryList.left = 10;
|
||||
this.entryList.maxEntryWidth = 120;
|
||||
this.entryList.headerPadding = 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks){
|
||||
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
|
||||
GlStateManager.disableLighting();
|
||||
|
||||
if(this.currentValue instanceof String){
|
||||
|
||||
this.drawString(this.fontRenderer, I18n.format("config." + Wizardry.MODID + ".spell_hud_skin.preview"), 170, 44, 0xffffff);
|
||||
|
||||
int previewLeft = 170;
|
||||
int previewRight = width-10;
|
||||
int previewTop = 60;
|
||||
int previewBottom = height-43;
|
||||
|
||||
this.drawGradientRect(previewLeft, previewTop, previewRight, previewBottom, 0x88000000, 0x88000000);
|
||||
|
||||
int previewBorder = 10;
|
||||
|
||||
Skin skin = GuiSpellDisplay.getSkin((String)this.currentValue);
|
||||
|
||||
float scale = Math.min((previewRight - previewLeft - 2*previewBorder)/(float)skin.getWidth(),
|
||||
(previewBottom - previewTop - 2*previewBorder)/(float)skin.getHeight());
|
||||
|
||||
float x = (previewLeft + previewRight)/2 - (skin.getWidth()*scale)/2;
|
||||
float y = (previewBottom + previewTop)/2 + (skin.getHeight()*scale)/2;
|
||||
|
||||
GlStateManager.pushMatrix();
|
||||
|
||||
GlStateManager.scale(scale, scale, scale);
|
||||
|
||||
skin.drawBackground((int)(x/scale), (int)(y/scale), false, false,
|
||||
Spells.magic_missile.getIcon(), 0.6f, false);
|
||||
|
||||
skin.drawText((int)(x/scale), (int)(y/scale), false, false,
|
||||
Spells.none.getDisplayNameWithFormatting(),
|
||||
Spells.magic_missile.getDisplayNameWithFormatting(),
|
||||
Spells.none.getDisplayNameWithFormatting(), 0);
|
||||
|
||||
GlStateManager.popMatrix();
|
||||
|
||||
Skin hovered = getHoveredSkin(mouseX, mouseY);
|
||||
|
||||
if(hovered != null){
|
||||
this.drawToolTip(Lists.newArrayList("\u00A7a" + hovered.getName(), "\u00A7e" + hovered.getDescription()),
|
||||
mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
|
||||
GlStateManager.enableLighting();
|
||||
}
|
||||
|
||||
/** Returns the skin corresponding to the list entry being hovered over, or null if there is none. */
|
||||
@Nullable
|
||||
private Skin getHoveredSkin(int mouseX, int mouseY){
|
||||
|
||||
int index = this.entryList.getSlotIndexFromScreenCoords(mouseX, mouseY);
|
||||
|
||||
if(index >= 0 && index <= this.entryList.listEntries.size() && mouseY <= this.entryList.bottom){
|
||||
|
||||
Object object = entryList.getListEntry(index).getValue();
|
||||
|
||||
if(object instanceof String){
|
||||
return GuiSpellDisplay.getSkin((String)object);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override // Stops the world being visible behind the GUI when configuring from within a world
|
||||
public void drawWorldBackground(int tint){
|
||||
this.drawBackground(tint);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package electroblob.wizardry.client.gui.config;
|
||||
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraftforge.fml.client.config.GuiConfig;
|
||||
import net.minecraftforge.fml.client.config.GuiConfigEntries;
|
||||
import net.minecraftforge.fml.client.config.GuiUtils;
|
||||
import net.minecraftforge.fml.client.config.IConfigElement;
|
||||
|
||||
/**
|
||||
* Same as {@link net.minecraftforge.fml.client.config.GuiConfigEntries.BooleanEntry}, but instead of simply
|
||||
* displaying 'true' or 'false', allows the two display strings to be specified in the lang file.
|
||||
*/
|
||||
// BooleanEntry's constructors are private, so I had to copy the whole goddamn class to change one method. Thanks Forge.
|
||||
public class NamedBooleanEntry extends GuiConfigEntries.ButtonEntry {
|
||||
|
||||
protected final boolean beforeValue;
|
||||
protected boolean currentValue;
|
||||
|
||||
private static final String DEFAULT_KEY = "config.ebwizardry.generic";
|
||||
|
||||
public NamedBooleanEntry(GuiConfig owningScreen, GuiConfigEntries owningEntryList, IConfigElement configElement){
|
||||
super(owningScreen, owningEntryList, configElement);
|
||||
this.beforeValue = Boolean.valueOf(configElement.get().toString());
|
||||
this.currentValue = beforeValue;
|
||||
this.btnValue.enabled = enabled();
|
||||
updateValueButtonText();
|
||||
}
|
||||
|
||||
// This is the only method that's any different
|
||||
@Override
|
||||
public void updateValueButtonText(){
|
||||
|
||||
String langKey = configElement.getLanguageKey() + "." + currentValue;
|
||||
this.btnValue.displayString = I18n.format(langKey);
|
||||
// If the key is unspecified, it defaults to the generic 'Enabled'/'Disabled' keys and adds a red/green colour
|
||||
if(this.btnValue.displayString.equals(langKey)){
|
||||
this.btnValue.displayString = I18n.format(DEFAULT_KEY + "." + currentValue);
|
||||
btnValue.packedFGColour = currentValue ? GuiUtils.getColorCode('a', true) : GuiUtils.getColorCode('c', true);
|
||||
}
|
||||
}
|
||||
|
||||
// Everything from here down is the same as BooleanEntry
|
||||
|
||||
@Override
|
||||
public void valueButtonPressed(int slotIndex){
|
||||
if(enabled()) currentValue = !currentValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDefault(){
|
||||
return currentValue == Boolean.valueOf(configElement.getDefault().toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setToDefault(){
|
||||
if(enabled()){
|
||||
currentValue = Boolean.valueOf(configElement.getDefault().toString());
|
||||
updateValueButtonText();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChanged(){
|
||||
return currentValue != beforeValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undoChanges(){
|
||||
if(enabled()){
|
||||
currentValue = beforeValue;
|
||||
updateValueButtonText();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveConfigElement(){
|
||||
if(enabled() && isChanged()){
|
||||
configElement.set(currentValue);
|
||||
return configElement.requiresMcRestart();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean getCurrentValue(){
|
||||
return currentValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean[] getCurrentValues(){
|
||||
return new Boolean[]{getCurrentValue()};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package electroblob.wizardry.client.gui.config;
|
||||
|
||||
import electroblob.wizardry.client.gui.GuiSpellDisplay;
|
||||
import net.minecraftforge.client.gui.ForgeGuiFactory.ForgeConfigGui.ModIDEntry;
|
||||
import net.minecraftforge.fml.client.config.GuiConfig;
|
||||
import net.minecraftforge.fml.client.config.GuiConfigEntries;
|
||||
import net.minecraftforge.fml.client.config.GuiConfigEntries.SelectValueEntry;
|
||||
import net.minecraftforge.fml.client.config.IConfigElement;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Custom config GUI for spell HUD skin selection; displays a list of all the loaded skins and a preview of the currently
|
||||
* selected skin. based off of {@link ModIDEntry} from Forge.
|
||||
*/
|
||||
public class SpellHUDSkinChooserEntry extends SelectValueEntry {
|
||||
|
||||
public SpellHUDSkinChooserEntry(GuiConfig owningScreen, GuiConfigEntries owningEntryList, IConfigElement prop){
|
||||
super(owningScreen, owningEntryList, prop, getSelectableValues());
|
||||
if(this.selectableValues.size() == 0) this.btnValue.enabled = false;
|
||||
}
|
||||
|
||||
private static Map<Object, String> getSelectableValues(){
|
||||
return GuiSpellDisplay.getSkins().entrySet().stream().collect(Collectors.toMap(Entry::getKey,
|
||||
e -> e.getValue().getName()));
|
||||
}
|
||||
|
||||
@Override // Copied from superclass to use custom child screen GUI class
|
||||
public void valueButtonPressed(int slotIndex){
|
||||
mc.displayGuiScreen(new GuiSelectHUDSkin(this.owningScreen, configElement, slotIndex, selectableValues, currentValue, enabled()));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user