Search in sources :

Example 1 with ConfigChangedEvent

use of net.minecraftforge.fml.client.event.ConfigChangedEvent in project DynamicSurroundings by OreCruncher.

the class GuiConfigBase method actionPerformed.

/**
 * Called by the controls from the buttonList when activated. (Mouse pressed for
 * buttons)
 */
@Override
protected void actionPerformed(GuiButton button) {
    if (button.id == 2000) {
        boolean flag = true;
        try {
            if ((this.configID != null || this.parentScreen == null || !(this.parentScreen instanceof GuiConfig)) && (this.entryList.hasChangedEntry(true))) {
                final boolean requiresMcRestart = this.entryList.saveConfigElements();
                // My hook for massaging the results
                doFixups();
                if (Loader.isModLoaded(this.modID)) {
                    final ConfigChangedEvent event = new OnConfigChangedEvent(this.modID, this.configID, this.isWorldRunning, requiresMcRestart);
                    MinecraftForge.EVENT_BUS.post(event);
                    if (!event.getResult().equals(Result.DENY))
                        MinecraftForge.EVENT_BUS.post(new PostConfigChangedEvent(this.modID, this.configID, this.isWorldRunning, requiresMcRestart));
                    if (requiresMcRestart) {
                        flag = false;
                        this.mc.displayGuiScreen(new GuiMessageDialog(this.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 (final Throwable e) {
            FMLLog.log.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());
    }
}
Also used : PostConfigChangedEvent(net.minecraftforge.fml.client.event.ConfigChangedEvent.PostConfigChangedEvent) OnConfigChangedEvent(net.minecraftforge.fml.client.event.ConfigChangedEvent.OnConfigChangedEvent) GuiConfig(net.minecraftforge.fml.client.config.GuiConfig) GuiMessageDialog(net.minecraftforge.fml.client.config.GuiMessageDialog) ConfigChangedEvent(net.minecraftforge.fml.client.event.ConfigChangedEvent) PostConfigChangedEvent(net.minecraftforge.fml.client.event.ConfigChangedEvent.PostConfigChangedEvent) OnConfigChangedEvent(net.minecraftforge.fml.client.event.ConfigChangedEvent.OnConfigChangedEvent) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 2 with ConfigChangedEvent

use of net.minecraftforge.fml.client.event.ConfigChangedEvent in project MinecraftForge by MinecraftForge.

the class GuiConfig method actionPerformed.

@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) {
            e.printStackTrace();
        }
        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());
    }
}
Also used : PostConfigChangedEvent(net.minecraftforge.fml.client.event.ConfigChangedEvent.PostConfigChangedEvent) OnConfigChangedEvent(net.minecraftforge.fml.client.event.ConfigChangedEvent.OnConfigChangedEvent) ConfigChangedEvent(net.minecraftforge.fml.client.event.ConfigChangedEvent) PostConfigChangedEvent(net.minecraftforge.fml.client.event.ConfigChangedEvent.PostConfigChangedEvent) OnConfigChangedEvent(net.minecraftforge.fml.client.event.ConfigChangedEvent.OnConfigChangedEvent) TextComponentString(net.minecraft.util.text.TextComponentString)

Aggregations

TextComponentString (net.minecraft.util.text.TextComponentString)2 ConfigChangedEvent (net.minecraftforge.fml.client.event.ConfigChangedEvent)2 OnConfigChangedEvent (net.minecraftforge.fml.client.event.ConfigChangedEvent.OnConfigChangedEvent)2 PostConfigChangedEvent (net.minecraftforge.fml.client.event.ConfigChangedEvent.PostConfigChangedEvent)2 GuiConfig (net.minecraftforge.fml.client.config.GuiConfig)1 GuiMessageDialog (net.minecraftforge.fml.client.config.GuiMessageDialog)1