Commit 48a4b5c6be4fe5ea4f44646d7425bca68076cb91

Authored by Mumfrey
1 parent 509a79d5

Add an example config panel

src/main/java/com/examplemod/ExampleModConfigPanel.java 0 → 100644
  1 +package com.examplemod;
  2 +
  3 +import com.mumfrey.liteloader.Configurable;
  4 +import com.mumfrey.liteloader.client.gui.GuiCheckbox;
  5 +import com.mumfrey.liteloader.modconfig.AbstractConfigPanel;
  6 +import com.mumfrey.liteloader.modconfig.ConfigPanelHost;
  7 +import net.minecraft.client.resources.I18n;
  8 +
  9 +/**
  10 + * This is a simple example of adding a config panel to a mod. Your LiteMod class should implement
  11 + * {@link Configurable} and return this class in order to support the settings functionality of the
  12 + * mod panel.
  13 + *
  14 + * @author Adam Mummery-Smith
  15 + */
  16 +public class ExampleModConfigPanel extends AbstractConfigPanel
  17 +{
  18 + /* (non-Javadoc)
  19 + * @see com.mumfrey.liteloader.modconfig.ConfigPanel#getPanelTitle()
  20 + */
  21 + @Override
  22 + public String getPanelTitle()
  23 + {
  24 + return I18n.format("examplemod.config.title");
  25 + }
  26 +
  27 + /* (non-Javadoc)
  28 + * @see com.mumfrey.liteloader.modconfig.AbstractConfigPanel#addOptions(com.mumfrey.liteloader.modconfig.ConfigPanelHost)
  29 + */
  30 + @Override
  31 + protected void addOptions(ConfigPanelHost host)
  32 + {
  33 + final LiteModExample mod = host.<LiteModExample>getMod();
  34 +
  35 + this.addLabel(1, 0, 0, 200, 32, 0xFFFF55, I18n.format("examplemod.config.help.1"), I18n.format("examplemod.config.help.2"));
  36 + this.addControl(new GuiCheckbox(0, 0, 32, I18n.format("examplemod.config.option.enabled")), new ConfigOptionListener<GuiCheckbox>()
  37 + {
  38 + @Override
  39 + public void actionPerformed(GuiCheckbox control)
  40 + {
  41 + mod.setClockVisibility(control.checked = !control.checked);
  42 + }
  43 + }).checked = mod.getClockVisibility();
  44 + }
  45 +
  46 + @Override
  47 + public void onPanelHidden()
  48 + {
  49 + // This example applies the changes immediately, however you may wish to only save changes
  50 + // when the user clicks "save and close". In which case you should apply your changes here
  51 + }
  52 +}
... ...
src/main/java/com/examplemod/LiteModExample.java
... ... @@ -2,9 +2,11 @@ package com.examplemod;
2 2  
3 3 import com.google.gson.annotations.Expose;
4 4 import com.google.gson.annotations.SerializedName;
  5 +import com.mumfrey.liteloader.Configurable;
5 6 import com.mumfrey.liteloader.PreRenderListener;
6 7 import com.mumfrey.liteloader.Tickable;
7 8 import com.mumfrey.liteloader.core.LiteLoader;
  9 +import com.mumfrey.liteloader.modconfig.ConfigPanel;
8 10 import com.mumfrey.liteloader.modconfig.ConfigStrategy;
9 11 import com.mumfrey.liteloader.modconfig.ExposableOptions;
10 12 import net.minecraft.client.Minecraft;
... ... @@ -21,7 +23,7 @@ import java.io.File;
21 23 * @author Adam Mummery-Smith
22 24 */
23 25 @ExposableOptions(strategy = ConfigStrategy.Versioned, filename="examplemod.json")
24   -public class LiteModExample implements Tickable, PreRenderListener
  26 +public class LiteModExample implements Tickable, PreRenderListener, Configurable
25 27 {
26 28 /**
27 29 * This is our instance of Clock which we will draw every tick
... ... @@ -75,6 +77,12 @@ public class LiteModExample implements Tickable, PreRenderListener
75 77 return "0.0.0";
76 78 }
77 79  
  80 + @Override
  81 + public Class<? extends ConfigPanel> getConfigPanelClass()
  82 + {
  83 + return ExampleModConfigPanel.class;
  84 + }
  85 +
78 86 /**
79 87 * init() is called very early in the initialisation cycle, before the game is fully initialised, this
80 88 * means that it is important that your mod does not interact with the game in any way at this point.
... ... @@ -132,6 +140,16 @@ public class LiteModExample implements Tickable, PreRenderListener
132 140 this.clock.render(minecraft);
133 141 }
134 142 }
  143 +
  144 + boolean getClockVisibility()
  145 + {
  146 + return this.clock.isVisible();
  147 + }
  148 +
  149 + void setClockVisibility(boolean visible)
  150 + {
  151 + this.clock.setVisible(this.clockVisible = visible);
  152 + }
135 153  
136 154 @Override
137 155 public void onRenderWorld(float partialTicks)
... ...
src/main/resources/assets/example/lang/en_us.lang
1 1  
2   -key.clock.toggle=Toggle Clock
3 2 \ No newline at end of file
  3 +key.clock.toggle=Toggle Clock
  4 +
  5 +examplemod.config.title=Example Mod Configuration
  6 +examplemod.config.help.1=This is a simple option which demonstrates how to
  7 +examplemod.config.help.2=add a checkbox option
  8 +examplemod.config.option.enabled=Enable clock
4 9 \ No newline at end of file
... ...