mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-07-06 12:02:52 +00:00
Add config GUI
This allows you to modify various settings in-game.
This commit is contained in:
parent
1b562ae837
commit
230b578a98
@ -3,9 +3,10 @@
|
|||||||
* Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission.
|
* Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission.
|
||||||
* Send enquiries to dratcliffe@gmail.com
|
* Send enquiries to dratcliffe@gmail.com
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package dan200.computercraft;
|
package dan200.computercraft;
|
||||||
|
|
||||||
|
import com.google.common.base.CaseFormat;
|
||||||
import dan200.computercraft.api.filesystem.IMount;
|
import dan200.computercraft.api.filesystem.IMount;
|
||||||
import dan200.computercraft.api.filesystem.IWritableMount;
|
import dan200.computercraft.api.filesystem.IWritableMount;
|
||||||
import dan200.computercraft.api.media.IMedia;
|
import dan200.computercraft.api.media.IMedia;
|
||||||
@ -82,7 +83,10 @@ import java.util.List;
|
|||||||
// UNIVERSAL //
|
// UNIVERSAL //
|
||||||
///////////////
|
///////////////
|
||||||
|
|
||||||
@Mod( modid = "ComputerCraft", name = "ComputerCraft", version = "${version}" )
|
@Mod(
|
||||||
|
modid = "ComputerCraft", name = "ComputerCraft", version = "${version}",
|
||||||
|
guiFactory = "dan200.computercraft.client.gui.GuiConfigCC$Factory"
|
||||||
|
)
|
||||||
public class ComputerCraft
|
public class ComputerCraft
|
||||||
{
|
{
|
||||||
// GUI IDs
|
// GUI IDs
|
||||||
@ -95,6 +99,8 @@ public class ComputerCraft
|
|||||||
public static final int pocketComputerGUIID = 106;
|
public static final int pocketComputerGUIID = 106;
|
||||||
|
|
||||||
// Configuration options
|
// Configuration options
|
||||||
|
public static Configuration config;
|
||||||
|
|
||||||
public static boolean http_enable = true;
|
public static boolean http_enable = true;
|
||||||
public static String http_whitelist = "*";
|
public static String http_whitelist = "*";
|
||||||
public static boolean disable_lua51_features = false;
|
public static boolean disable_lua51_features = false;
|
||||||
@ -192,11 +198,20 @@ public class ComputerCraft
|
|||||||
public void preInit( FMLPreInitializationEvent event )
|
public void preInit( FMLPreInitializationEvent event )
|
||||||
{
|
{
|
||||||
// Load config
|
// Load config
|
||||||
Configuration config = new Configuration( event.getSuggestedConfigurationFile() );
|
config = new Configuration( event.getSuggestedConfigurationFile() );
|
||||||
config.load();
|
config.load();
|
||||||
|
|
||||||
// Setup general
|
syncConfig();
|
||||||
|
|
||||||
|
// Setup network
|
||||||
|
networkEventChannel = NetworkRegistry.INSTANCE.newEventDrivenChannel( "CC" );
|
||||||
|
networkEventChannel.register( new PacketHandler() );
|
||||||
|
|
||||||
|
proxy.preInit();
|
||||||
|
turtleProxy.preInit();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void syncConfig() {
|
||||||
Property prop = config.get(Configuration.CATEGORY_GENERAL, "http_enable", http_enable);
|
Property prop = config.get(Configuration.CATEGORY_GENERAL, "http_enable", http_enable);
|
||||||
prop.setComment( "Enable the \"http\" API on Computers (see \"http_whitelist\" for more fine grained control than this)" );
|
prop.setComment( "Enable the \"http\" API on Computers (see \"http_whitelist\" for more fine grained control than this)" );
|
||||||
http_enable = prop.getBoolean(http_enable);
|
http_enable = prop.getBoolean(http_enable);
|
||||||
@ -261,14 +276,12 @@ public class ComputerCraft
|
|||||||
prop.setComment( "If set to true, Turtles will push entities out of the way instead of stopping if there is space to do so" );
|
prop.setComment( "If set to true, Turtles will push entities out of the way instead of stopping if there is space to do so" );
|
||||||
turtlesCanPush = prop.getBoolean(turtlesCanPush);
|
turtlesCanPush = prop.getBoolean(turtlesCanPush);
|
||||||
|
|
||||||
|
for (Property property : config.getCategory( Configuration.CATEGORY_GENERAL ).getOrderedValues())
|
||||||
|
{
|
||||||
|
property.setLanguageKey( "gui.computercraft:config." + CaseFormat.LOWER_CAMEL.to( CaseFormat.LOWER_UNDERSCORE, property.getName() ) );
|
||||||
|
}
|
||||||
|
|
||||||
config.save();
|
config.save();
|
||||||
|
|
||||||
// Setup network
|
|
||||||
networkEventChannel = NetworkRegistry.INSTANCE.newEventDrivenChannel( "CC" );
|
|
||||||
networkEventChannel.register( new PacketHandler() );
|
|
||||||
|
|
||||||
proxy.preInit();
|
|
||||||
turtleProxy.preInit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Mod.EventHandler
|
@Mod.EventHandler
|
||||||
|
@ -0,0 +1,61 @@
|
|||||||
|
package dan200.computercraft.client.gui;
|
||||||
|
|
||||||
|
import dan200.computercraft.ComputerCraft;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.gui.GuiScreen;
|
||||||
|
import net.minecraftforge.common.config.ConfigElement;
|
||||||
|
import net.minecraftforge.common.config.Configuration;
|
||||||
|
import net.minecraftforge.common.config.Property;
|
||||||
|
import net.minecraftforge.fml.client.IModGuiFactory;
|
||||||
|
import net.minecraftforge.fml.client.config.GuiConfig;
|
||||||
|
import net.minecraftforge.fml.client.config.IConfigElement;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class GuiConfigCC extends GuiConfig
|
||||||
|
{
|
||||||
|
public GuiConfigCC( GuiScreen parentScreen )
|
||||||
|
{
|
||||||
|
super( parentScreen, getConfigElements(), "ComputerCraft", false, false, "ComputerCraft" );
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<IConfigElement> getConfigElements()
|
||||||
|
{
|
||||||
|
ArrayList<IConfigElement> elements = new ArrayList<IConfigElement>();
|
||||||
|
for (Property property : ComputerCraft.config.getCategory( Configuration.CATEGORY_GENERAL ).getOrderedValues())
|
||||||
|
{
|
||||||
|
elements.add( new ConfigElement( property ) );
|
||||||
|
}
|
||||||
|
return elements;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Factory
|
||||||
|
implements IModGuiFactory
|
||||||
|
{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initialize( Minecraft minecraft )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<? extends GuiScreen> mainConfigGuiClass()
|
||||||
|
{
|
||||||
|
return GuiConfigCC.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<RuntimeOptionCategoryElement> runtimeGuiCategories()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RuntimeOptionGuiHandler getHandlerFor( RuntimeOptionCategoryElement runtimeOptionCategoryElement )
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -71,6 +71,7 @@ import net.minecraft.util.text.translation.I18n;
|
|||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
import net.minecraftforge.event.world.WorldEvent;
|
import net.minecraftforge.event.world.WorldEvent;
|
||||||
|
import net.minecraftforge.fml.client.event.ConfigChangedEvent;
|
||||||
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
|
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
|
||||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||||
import net.minecraftforge.fml.common.gameevent.TickEvent;
|
import net.minecraftforge.fml.common.gameevent.TickEvent;
|
||||||
@ -656,5 +657,13 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
|
|||||||
public void onWorldUnload( WorldEvent.Unload event )
|
public void onWorldUnload( WorldEvent.Unload event )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public void onConfigChanged( ConfigChangedEvent.OnConfigChangedEvent event) {
|
||||||
|
if( event.getModID().equals( "ComputerCraft" ) )
|
||||||
|
{
|
||||||
|
ComputerCraft.syncConfig();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,3 +39,20 @@ upgrade.computercraft:advanced_modem.adjective=Ender
|
|||||||
|
|
||||||
gui.computercraft:wired_modem.peripheral_connected=Peripheral "%s" connected to network
|
gui.computercraft:wired_modem.peripheral_connected=Peripheral "%s" connected to network
|
||||||
gui.computercraft:wired_modem.peripheral_disconnected=Peripheral "%s" disconnected from network
|
gui.computercraft:wired_modem.peripheral_disconnected=Peripheral "%s" disconnected from network
|
||||||
|
|
||||||
|
gui.computercraft:config.http_enable=HTTP enable
|
||||||
|
gui.computercraft:config.http_whitelist=HTTP whitelist
|
||||||
|
gui.computercraft:config.disable_lua51_features=Disable Lua 5.1 features
|
||||||
|
gui.computercraft:config.default_computer_settings=Default computer settings
|
||||||
|
gui.computercraft:config.enable_command_block=Enable command block
|
||||||
|
gui.computercraft:config.modem_range=Modem range
|
||||||
|
gui.computercraft:config.modem_high_altitude_range=Modem range (high-altitude)
|
||||||
|
gui.computercraft:config.modem_range_during_storm=Modem range (storm)
|
||||||
|
gui.computercraft:config.modem_high_altitude_range_during_storm=Modem range (high-altitude, storm)
|
||||||
|
gui.computercraft:config.computer_space_limit=Computer space limit
|
||||||
|
gui.computercraft:config.floppy_space_limit=Floppy space limit
|
||||||
|
gui.computercraft:config.turtles_need_fuel=Turtles need fuel
|
||||||
|
gui.computercraft:config.turtle_fuel_limit=Turtle fuel limit
|
||||||
|
gui.computercraft:config.advanced_turtle_fuel_limit=Advanced turtle fuel limit
|
||||||
|
gui.computercraft:config.turtles_obey_block_protection=Turtles obey block protection
|
||||||
|
gui.computercraft:config.turtles_can_push=Turtles can push
|
||||||
|
Loading…
x
Reference in New Issue
Block a user