hud modules now save state to config
This commit is contained in:
parent
b8bb14081e
commit
206d076fbb
7 changed files with 132 additions and 6 deletions
|
@ -14,10 +14,13 @@ import me.kawaiizenbo.moonlight.module.ModuleManager;
|
|||
import me.kawaiizenbo.moonlight.module.Module;
|
||||
import me.kawaiizenbo.moonlight.module.settings.BooleanSetting;
|
||||
import me.kawaiizenbo.moonlight.module.settings.DoubleSetting;
|
||||
import me.kawaiizenbo.moonlight.module.settings.IndexSetting;
|
||||
import me.kawaiizenbo.moonlight.module.settings.KeycodeSetting;
|
||||
import me.kawaiizenbo.moonlight.module.settings.Setting;
|
||||
import me.kawaiizenbo.moonlight.module.settings.StringSetting;
|
||||
import me.kawaiizenbo.moonlight.ui.clickgui.ClickGUIScreen;
|
||||
import me.kawaiizenbo.moonlight.ui.hud.HUDModule;
|
||||
import me.kawaiizenbo.moonlight.ui.hud.HUDModuleManager;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
|
||||
public class Config
|
||||
|
@ -57,19 +60,60 @@ public class Config
|
|||
{
|
||||
ms.put(s.name, ((DoubleSetting)s).value);
|
||||
}
|
||||
if (s instanceof StringSetting)
|
||||
else if (s instanceof StringSetting)
|
||||
{
|
||||
ms.put(s.name, ((StringSetting)s).value);
|
||||
}
|
||||
else if (s instanceof KeycodeSetting)
|
||||
{
|
||||
ms.put(s.name, ((KeycodeSetting)s).value);
|
||||
}
|
||||
else if (s instanceof IndexSetting)
|
||||
{
|
||||
ms.put(s.name, ((IndexSetting)s).index);
|
||||
}
|
||||
}
|
||||
mo.put("settings", ms);
|
||||
mi.put(m.name, mo);
|
||||
}
|
||||
config.put("modules", mi);
|
||||
|
||||
HUDModuleManager.INSTANCE = new HUDModuleManager();
|
||||
Map<String, Object> hi = new HashMap<>();
|
||||
for (HUDModule h : HUDModuleManager.INSTANCE.modules)
|
||||
{
|
||||
Map<String, Object> ho = new HashMap<>();
|
||||
ho.put("enabled", h.enabled);
|
||||
Map<String, Object> hs = new HashMap<>();
|
||||
for (Setting s : h.settings)
|
||||
{
|
||||
if (s instanceof BooleanSetting)
|
||||
{
|
||||
hs.put(s.name, ((BooleanSetting)s).value);
|
||||
}
|
||||
else if (s instanceof DoubleSetting)
|
||||
{
|
||||
hs.put(s.name, ((DoubleSetting)s).value);
|
||||
}
|
||||
else if (s instanceof StringSetting)
|
||||
{
|
||||
hs.put(s.name, ((StringSetting)s).value);
|
||||
}
|
||||
else if (s instanceof KeycodeSetting)
|
||||
{
|
||||
hs.put(s.name, ((KeycodeSetting)s).value);
|
||||
}
|
||||
else if (s instanceof IndexSetting)
|
||||
{
|
||||
hs.put(s.name, ((IndexSetting)s).index);
|
||||
}
|
||||
}
|
||||
ho.put("settings", hs);
|
||||
ho.put("x", h.x);
|
||||
ho.put("y", h.y);
|
||||
hi.put(h.name, ho);
|
||||
}
|
||||
config.put("hud", hi);
|
||||
int xOffset = 4;
|
||||
int yOffset = 4;
|
||||
Map<String, Object> pi = new HashMap<>();
|
||||
|
@ -91,7 +135,8 @@ public class Config
|
|||
ClickGUIScreen.INSTANCE = new ClickGUIScreen();
|
||||
}
|
||||
|
||||
public void load() throws IOException
|
||||
@SuppressWarnings("unchecked")
|
||||
public void load() throws IOException
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
|
@ -12,11 +12,14 @@ import me.kawaiizenbo.moonlight.module.ModuleManager;
|
|||
import me.kawaiizenbo.moonlight.module.Module;
|
||||
import me.kawaiizenbo.moonlight.module.settings.BooleanSetting;
|
||||
import me.kawaiizenbo.moonlight.module.settings.DoubleSetting;
|
||||
import me.kawaiizenbo.moonlight.module.settings.IndexSetting;
|
||||
import me.kawaiizenbo.moonlight.module.settings.KeycodeSetting;
|
||||
import me.kawaiizenbo.moonlight.module.settings.Setting;
|
||||
import me.kawaiizenbo.moonlight.module.settings.StringSetting;
|
||||
import me.kawaiizenbo.moonlight.ui.clickgui.CategoryPane;
|
||||
import me.kawaiizenbo.moonlight.ui.clickgui.ClickGUIScreen;
|
||||
import me.kawaiizenbo.moonlight.ui.hud.HUDModule;
|
||||
import me.kawaiizenbo.moonlight.ui.hud.HUDModuleManager;
|
||||
import me.kawaiizenbo.moonlight.util.ColorUtils;
|
||||
|
||||
public class Moonlight implements ModInitializer
|
||||
|
@ -34,6 +37,7 @@ public class Moonlight implements ModInitializer
|
|||
loadConfig();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void loadConfig()
|
||||
{
|
||||
try
|
||||
|
@ -60,6 +64,39 @@ public class Moonlight implements ModInitializer
|
|||
else if (s instanceof KeycodeSetting)
|
||||
{
|
||||
((KeycodeSetting)s).value = ((Double)((Map<String, Object>)((Map<String, Object>)((Map<String, Object>)CONFIG.config.get("modules")).get(m.name)).get("settings")).get(s.name)).intValue();
|
||||
}
|
||||
else if (s instanceof IndexSetting)
|
||||
{
|
||||
((IndexSetting)s).index = ((Double)((Map<String, Object>)((Map<String, Object>)((Map<String, Object>)CONFIG.config.get("modules")).get(m.name)).get("settings")).get(s.name)).intValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
for (HUDModule m : HUDModuleManager.INSTANCE.modules)
|
||||
{
|
||||
m.enabled = (boolean)((Map<String, Object>)((Map<String, Object>)CONFIG.config.get("hud")).get(m.name)).get("enabled");
|
||||
m.x = ((Double)((Map<String, Object>)((Map<String, Object>)CONFIG.config.get("hud")).get(m.name)).get("x")).intValue();
|
||||
m.y = ((Double)((Map<String, Object>)((Map<String, Object>)CONFIG.config.get("hud")).get(m.name)).get("y")).intValue();
|
||||
for (Setting s : m.settings)
|
||||
{
|
||||
if (s instanceof BooleanSetting)
|
||||
{
|
||||
((BooleanSetting)s).value = (boolean)((Map<String, Object>)((Map<String, Object>)((Map<String, Object>)CONFIG.config.get("hud")).get(m.name)).get("settings")).get(s.name);
|
||||
}
|
||||
else if (s instanceof DoubleSetting)
|
||||
{
|
||||
((DoubleSetting)s).value = (Double)((Map<String, Object>)((Map<String, Object>)((Map<String, Object>)CONFIG.config.get("hud")).get(m.name)).get("settings")).get(s.name);
|
||||
}
|
||||
else if (s instanceof StringSetting)
|
||||
{
|
||||
((StringSetting)s).value = (String)((Map<String, Object>)((Map<String, Object>)((Map<String, Object>)CONFIG.config.get("hud")).get(m.name)).get("settings")).get(s.name);
|
||||
}
|
||||
else if (s instanceof KeycodeSetting)
|
||||
{
|
||||
((KeycodeSetting)s).value = ((Double)((Map<String, Object>)((Map<String, Object>)((Map<String, Object>)CONFIG.config.get("hud")).get(m.name)).get("settings")).get(s.name)).intValue();
|
||||
}
|
||||
else if (s instanceof IndexSetting)
|
||||
{
|
||||
((IndexSetting)s).index = ((Double)((Map<String, Object>)((Map<String, Object>)((Map<String, Object>)CONFIG.config.get("hud")).get(m.name)).get("settings")).get(s.name)).intValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -92,19 +129,60 @@ public class Moonlight implements ModInitializer
|
|||
{
|
||||
ms.put(s.name, ((DoubleSetting)s).value);
|
||||
}
|
||||
if (s instanceof StringSetting)
|
||||
else if (s instanceof StringSetting)
|
||||
{
|
||||
ms.put(s.name, ((StringSetting)s).value);
|
||||
}
|
||||
else if (s instanceof KeycodeSetting)
|
||||
{
|
||||
ms.put(s.name, ((KeycodeSetting)s).value);
|
||||
}
|
||||
else if (s instanceof IndexSetting)
|
||||
{
|
||||
ms.put(s.name, ((IndexSetting)s).index);
|
||||
}
|
||||
}
|
||||
mo.put("settings", ms);
|
||||
mi.put(m.name, mo);
|
||||
}
|
||||
CONFIG.config.put("modules", mi);
|
||||
|
||||
Map<String, Object> hi = new HashMap<>();
|
||||
for (HUDModule h : HUDModuleManager.INSTANCE.modules)
|
||||
{
|
||||
Map<String, Object> ho = new HashMap<>();
|
||||
ho.put("enabled", h.enabled);
|
||||
Map<String, Object> hs = new HashMap<>();
|
||||
for (Setting s : h.settings)
|
||||
{
|
||||
if (s instanceof BooleanSetting)
|
||||
{
|
||||
hs.put(s.name, ((BooleanSetting)s).value);
|
||||
}
|
||||
else if (s instanceof DoubleSetting)
|
||||
{
|
||||
hs.put(s.name, ((DoubleSetting)s).value);
|
||||
}
|
||||
else if (s instanceof StringSetting)
|
||||
{
|
||||
hs.put(s.name, ((StringSetting)s).value);
|
||||
}
|
||||
else if (s instanceof KeycodeSetting)
|
||||
{
|
||||
hs.put(s.name, ((KeycodeSetting)s).value);
|
||||
}
|
||||
else if (s instanceof IndexSetting)
|
||||
{
|
||||
hs.put(s.name, ((IndexSetting)s).index);
|
||||
}
|
||||
}
|
||||
ho.put("settings", hs);
|
||||
ho.put("x", h.x);
|
||||
ho.put("y", h.y);
|
||||
hi.put(h.name, ho);
|
||||
}
|
||||
CONFIG.config.put("hud", hi);
|
||||
|
||||
Map<String, Object> pi = new HashMap<>();
|
||||
for (CategoryPane c : ClickGUIScreen.INSTANCE.categoryPanes)
|
||||
{
|
||||
|
|
|
@ -24,7 +24,8 @@ public class ClientPlayerEntityMixin
|
|||
}
|
||||
}
|
||||
|
||||
@Inject(method = "tick", at = @At(value = "HEAD"), cancellable = true)
|
||||
@SuppressWarnings("resource")
|
||||
@Inject(method = "tick", at = @At(value = "HEAD"), cancellable = true)
|
||||
public void onTick(CallbackInfo ci)
|
||||
{
|
||||
for (Module m : ModuleManager.INSTANCE.getEnabledModules())
|
||||
|
|
|
@ -11,7 +11,8 @@ public class Fullbright extends Module
|
|||
super("Fullbright", "Allows you to see in the dark.", Category.RENDER);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void onEnable()
|
||||
{
|
||||
super.onEnable();
|
||||
|
|
|
@ -15,6 +15,7 @@ public class ClickGUIScreen extends Screen
|
|||
public static ClickGUIScreen INSTANCE = new ClickGUIScreen();
|
||||
public ArrayList<CategoryPane> categoryPanes;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public ClickGUIScreen()
|
||||
{
|
||||
super(Text.literal("ClickGUI"));
|
||||
|
|
|
@ -4,7 +4,6 @@ import me.kawaiizenbo.moonlight.module.Module;
|
|||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public class ModuleButton
|
||||
{
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
"description": "Utility mod with a focus on stability.",
|
||||
"authors": [
|
||||
"KawaiiZenbo",
|
||||
"madeline1805",
|
||||
"BadGamesInc (re-used Hypnotic Code)"
|
||||
],
|
||||
"contact": {
|
||||
|
|
Loading…
Add table
Reference in a new issue