package mnm.mods.util.gui.config;

import mnm.mods.util.config.SettingValue;
import mnm.mods.util.gui.GuiComponent;
import mnm.mods.util.gui.IGuiInput;

/**
 * A base setting gui wrapper.
 *
 * @author Matthew
 * @param <T> The setting type
 * @param <Wrapper> The gui this setting will wrap
 */
public abstract class GuiSetting<T> extends GuiComponent implements IGuiInput<T> {

    private final SettingValue<T> setting;

    public GuiSetting(SettingValue<T> setting) {
        this.setting = setting;
    }

    /**
     * Gets the setting object.
     *
     * @return The setting object
     */
    public SettingValue<T> getSetting() {
        return this.setting;
    }

    /**
     * Resets the value to setting value.
     */
    public void reset() {
        this.setValue(this.setting.getValue());
    }

    /**
     * Sets the value to the setting default.
     */
    public void setDefault() {
        this.setValue(this.setting.getDefaultValue());
    }

    /**
     * Sets the setting value to the value.
     */
    public void saveValue() {
        this.setting.setValue(this.getValue());
    }

    public static class GuiSettingWrapped<T, Wrapper extends IGuiInput<T>> extends GuiSetting<T> {

        private final Wrapper input;
        
        public GuiSettingWrapped(SettingValue<T> setting, Wrapper input) {
            super(setting);
            this.input = input;
            if (input instanceof GuiComponent) {
                wrap((GuiComponent) input);
            }
            if (input != null) {
                this.setValue(setting.getValue());
            }
        }

        /**
         * Gets the input object.
         *
         * @return The input object
         */
        public Wrapper getInput() {
            return input;
        }

        @Override
        public T getValue() {
            return getInput().getValue();
        }

        @Override
        public void setValue(T value) {
            getInput().setValue(value);
        }

    }
}

@@ -490,38 +490,81 @@
 ting = setting;%0A
+        this.setValue(setting.getValue());%0A
     %7D%0A
-
 %0A    /**%0A     * 
@@ -1295,17 +1295,9 @@
 ut;%0A
-        
 %0A
+
     
@@ -1419,32 +1419,85 @@
 .input = input;%0A
+            this.input.setValue(setting.getValue());%0A
             if (
@@ -1591,106 +1591,8 @@
   %7D%0A
-            if (input != null) %7B%0A                this.setValue(setting.getValue());%0A            %7D%0A
     
@@ -1816,32 +1816,33 @@
  T getValue() %7B%0A
+%0A
             retu
@@ -1888,32 +1888,32 @@
       @Override%0A
-
         public v
@@ -1932,24 +1932,100 @@
 (T value) %7B%0A
+            if (getInput() == null) %7B%0A                return;%0A            %7D%0A
             

Fix crash caused by non-wrapped setting value not being set