mirror of
https://github.com/xiaozhou233/OrangeX-Client.git
synced 2026-12-05 13:05:52 +08:00
commit
969699edae
6 files changed
+117
-3
No files matched your search
@@ -1,7 +1,9 @@
|
||||
package cn.xiaozhou233.orangex;
|
||||
|
||||
import cn.xiaozhou233.orangex.alts.AltManager;
|
||||
import cn.xiaozhou233.orangex.config.ConfigManager;
|
||||
import cn.xiaozhou233.orangex.font.FontManager;
|
||||
import cn.xiaozhou233.orangex.manager.ResourceManager;
|
||||
import cn.xiaozhou233.orangex.mixin.MixinManager;
|
||||
import cn.xiaozhou233.orangex.module.ModuleManager;
|
||||
import lombok.Getter;
|
||||
@@ -14,13 +16,14 @@ public class OrangeX {
|
||||
@Getter
|
||||
private static OrangeX instance = new OrangeX();
|
||||
|
||||
private final File orangeXDir = new File(System.getProperty("user.home") + "/.orangex");
|
||||
private final EventBus eventBus = EventBus.builder()
|
||||
.logNoSubscriberMessages(false)
|
||||
.logSubscriberExceptions(false)
|
||||
.sendNoSubscriberEvent(false)
|
||||
.sendSubscriberExceptionEvent(false)
|
||||
.build();
|
||||
private final ResourceManager resourceManager = new ResourceManager();
|
||||
private final ConfigManager configManager = new ConfigManager();
|
||||
private final MixinManager mixinManager = new MixinManager();
|
||||
private final ModuleManager moduleManager = new ModuleManager();
|
||||
private final FontManager fontManager = new FontManager();
|
||||
@@ -33,6 +36,7 @@ public class OrangeX {
|
||||
// See Loader -> cn.xiaozhou233.orangex.loader.Loader
|
||||
// See Minecraft -> cn.xiaozhou233.MCPEntry
|
||||
public void start() {
|
||||
configManager.loadConfig();
|
||||
moduleManager.init();
|
||||
altManager.init();
|
||||
mixinManager.start();
|
||||
|
||||
@@ -32,7 +32,7 @@ public class AltManager {
|
||||
public void init() {
|
||||
// register event
|
||||
OrangeX.getInstance().getEventBus().register(this);
|
||||
file = new File(OrangeX.getInstance().getOrangeXDir(), "alts.json");
|
||||
file = OrangeX.getInstance().getResourceManager().getAltConfig();
|
||||
load();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package cn.xiaozhou233.orangex.config;
|
||||
|
||||
import cn.xiaozhou233.orangex.OrangeX;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class ConfigManager {
|
||||
|
||||
private final Gson gson = new Gson();
|
||||
private HashMap<String, PanelPosition> panelConfigMap = new HashMap<>();
|
||||
|
||||
public void loadConfig() {
|
||||
try {
|
||||
// Load Panel Position
|
||||
File panelConfig = OrangeX.getInstance().getResourceManager().getPanelConfig();
|
||||
if (!panelConfig.exists()) {
|
||||
panelConfig.createNewFile();
|
||||
}
|
||||
if (panelConfig.length() != 0) {
|
||||
Type type = new TypeToken<HashMap<String, PanelPosition>>() {}.getType();
|
||||
FileReader reader = new FileReader(panelConfig);
|
||||
HashMap<String, PanelPosition> map = gson.fromJson(reader, type);
|
||||
reader.close();
|
||||
if (map != null) {
|
||||
this.panelConfigMap = map;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public PanelPosition getPanelPosition(String panelName) {
|
||||
return this.panelConfigMap.getOrDefault(panelName, null);
|
||||
}
|
||||
|
||||
public void setPanelPosition(String panelName, PanelPosition position) {
|
||||
this.panelConfigMap.put(panelName, position);
|
||||
}
|
||||
|
||||
public void saveConfig() {
|
||||
try {
|
||||
// Panel Position
|
||||
FileWriter writer = new FileWriter(OrangeX.getInstance().getResourceManager().getPanelConfig());
|
||||
writer.write(gson.toJson(this.panelConfigMap));
|
||||
writer.close();
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package cn.xiaozhou233.orangex.config;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter @Setter
|
||||
public class PanelPosition {
|
||||
public double x;
|
||||
public double y;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package cn.xiaozhou233.orangex.manager;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@Getter
|
||||
public class ResourceManager {
|
||||
private final File orangeXDir = new File(System.getProperty("user.home") + "/.orangex");
|
||||
|
||||
// Alt
|
||||
private File altConfig = new File(orangeXDir, "alts.json");
|
||||
|
||||
// Panel Config
|
||||
private File panelConfig = new File(orangeXDir, "panel.json");
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package cn.xiaozhou233.orangex.ui.clickgui;
|
||||
|
||||
import cn.xiaozhou233.orangex.OrangeX;
|
||||
import cn.xiaozhou233.orangex.config.ConfigManager;
|
||||
import cn.xiaozhou233.orangex.config.PanelPosition;
|
||||
import cn.xiaozhou233.orangex.module.Module;
|
||||
import cn.xiaozhou233.orangex.module.ModuleCategory;
|
||||
import cn.xiaozhou233.orangex.module.value.*;
|
||||
@@ -36,7 +38,15 @@ public class ClickGuiScreen extends GuiScreen {
|
||||
double gap = 10;
|
||||
|
||||
for (ModuleCategory category : ModuleCategory.values()) {
|
||||
Panel panel = new Panel(category.name(), startX, startY, panelWidth);
|
||||
|
||||
// Load Position from panel.json
|
||||
PanelPosition position = OrangeX.getInstance().getConfigManager().getPanelPosition(category.name());
|
||||
Panel panel;
|
||||
if (position == null) {
|
||||
panel = new Panel(category.name(), startX, startY, panelWidth);
|
||||
} else {
|
||||
panel = new Panel(category.name(), position.getX(), position.getY(), panelWidth);
|
||||
}
|
||||
|
||||
for (Module module : OrangeX.getInstance().getModuleManager().getModulesByCategory(category)) {
|
||||
ModuleButton button = new ModuleButton(0, 0, panelWidth, module, panel);
|
||||
@@ -107,6 +117,12 @@ public class ClickGuiScreen extends GuiScreen {
|
||||
protected void mouseReleased(int mouseX, int mouseY, int state) {
|
||||
if (draggingPanel != null) {
|
||||
draggingPanel.mouseReleased(mouseX, mouseY, state);
|
||||
|
||||
// Save Position to HashMap
|
||||
ConfigManager configManager = OrangeX.getInstance().getConfigManager();
|
||||
configManager.setPanelPosition(draggingPanel.getTitle(),
|
||||
new PanelPosition(draggingPanel.getAbsoluteX(), draggingPanel.getAbsoluteY()));
|
||||
|
||||
draggingPanel = null;
|
||||
}
|
||||
|
||||
@@ -130,4 +146,11 @@ public class ClickGuiScreen extends GuiScreen {
|
||||
public boolean doesGuiPauseGame() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGuiClosed() {
|
||||
super.onGuiClosed();
|
||||
// Save position to panel.json
|
||||
OrangeX.getInstance().getConfigManager().saveConfig();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user