Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Another mega update. Especially to ContextMenu. #4

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
58a9c6e
So many changes. ContextMenu skins, fixed many bugs, and more compreh…
tanishisherewithhh Sep 30, 2024
a73a79a
Changes and better code structure.
tanishisherewithhh Oct 1, 2024
5ea697b
Bump to 1.21.1
tanishisherewithhh Oct 1, 2024
1cd3569
Scroll-Bar, and a new widget anchoring system for resizing. As well a…
tanishisherewithhh Oct 2, 2024
25c4c4b
Some YACL changes and a few changes.
tanishisherewithhh Oct 3, 2024
8ace820
New Test System
tanishisherewithhh Oct 8, 2024
25af2e0
Error fixing
tanishisherewithhh Oct 9, 2024
70df427
Gradle Changes and stuff.
tanishisherewithhh Oct 9, 2024
3196576
Merge branch 'master' into master
tanishisherewithhh Oct 9, 2024
bbdba6d
Removed ModMenuIntegration.java and added a DH button to option screen
tanishisherewithhh Oct 22, 2024
05da4c7
Merge remote-tracking branch 'origin/master'
tanishisherewithhh Oct 22, 2024
5b7f7fb
Removed unnecessary methods and reverted TextWidget to use the Classi…
tanishisherewithhh Oct 22, 2024
3f93c11
Many refactors, renamed files, smoothened MinecraftSkin panel. Added …
tanishisherewithhh Oct 22, 2024
09cdc78
More changes to ModernSkin, OptionalGroups changes, some refactors an…
tanishisherewithhh Oct 25, 2024
b3da5b5
Completed ModernSkin and fixed a bunch of stuff related to it
tanishisherewithhh Oct 27, 2024
7161b75
Some important changes.
tanishisherewithhh Oct 28, 2024
28d6ec9
MinecraftSkin supports OptionGroups. Added ScrollHandler and group_pa…
tanishisherewithhh Nov 17, 2024
9d9a7a4
Group scroll buttons in MinecraftSkin won't allow user to click when …
tanishisherewithhh Dec 1, 2024
69c84f0
Minimal changes.
tanishisherewithhh Jan 1, 2025
7dbfb30
Some improvements to the code-base
tanishisherewithhh Feb 7, 2025
ab60509
Update upload-artifact
tanishisherewithhh Feb 7, 2025
59d1de4
Easing
tanishisherewithhh Feb 9, 2025
b0dbca6
Option complexity, some changes to animations, MathAnimations, change…
tanishisherewithhh Feb 10, 2025
92073b4
Removed color picker button.
tanishisherewithhh Feb 11, 2025
901a671
Warning Screen for invalid mods.
tanishisherewithhh Feb 13, 2025
78f9b8a
Removed boilerplate, new integration helper classes and DynamicHudCon…
tanishisherewithhh Feb 17, 2025
e840431
Improved code and readability
tanishisherewithhh Feb 19, 2025
58ccff0
Error fix
tanishisherewithhh Feb 19, 2025
04daabe
wrong scope
tanishisherewithhh Feb 23, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:

- name: capture build artifacts
if: ${{ runner.os == 'Linux' && matrix.java == '21' }} # Only upload artifacts built from the latest java on one OS
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: Dynamichud
path: build/libs/
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,5 @@ run/

# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar

*.profileconfig.json
2 changes: 0 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ dependencies {
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

modImplementation "dev.isxander:yet-another-config-lib:${project.yacl_version}"

modApi "com.terraformersmc:modmenu:11.0.1"
}

processResources {
Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ org.gradle.parallel=true

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.21
yarn_mappings=1.21+build.2
loader_version=0.15.11
minecraft_version=1.21.1
yarn_mappings=1.21.1+build.3
loader_version=0.16.2

# Mod Properties
mod_version = 2.1.0
mod_version = 2.2.0
maven_group = com.tanishisherewith
archives_base_name = dynamichud

# Dependencies
fabric_version=0.100.3+1.21
fabric_version=0.102.1+1.21.1
yacl_version=3.5.0+1.21-fabric
159 changes: 8 additions & 151 deletions src/main/java/com/tanishisherewith/dynamichud/DynamicHUD.java
Original file line number Diff line number Diff line change
@@ -1,51 +1,24 @@
package com.tanishisherewith.dynamichud;

import com.tanishisherewith.dynamichud.config.GlobalConfig;
import com.tanishisherewith.dynamichud.screens.AbstractMoveableScreen;
import com.tanishisherewith.dynamichud.utils.BooleanPool;
import com.tanishisherewith.dynamichud.widget.Widget;
import com.tanishisherewith.dynamichud.integration.IntegrationManager;
import com.tanishisherewith.dynamichud.widget.WidgetManager;
import com.tanishisherewith.dynamichud.widget.WidgetRenderer;
import com.tanishisherewith.dynamichud.widgets.ItemWidget;
import com.tanishisherewith.dynamichud.widgets.TextWidget;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.metadata.ModMetadata;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.option.KeyBinding;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;

@Environment(EnvType.CLIENT)
public class DynamicHUD implements ClientModInitializer {
/**
* This is a map to store the list of widgets for each widget file to be saved.
* <p>
* Allows saving widgets across different mods with same save file name.
*/
public static final HashMap<String, List<Widget>> FILE_MAP = new HashMap<>();
public static final Logger logger = LoggerFactory.getLogger("DynamicHud");
private static final List<WidgetRenderer> widgetRenderers = new ArrayList<>();
public static MinecraftClient MC = MinecraftClient.getInstance();
public static final Logger logger = LoggerFactory.getLogger("DynamicHud");
public static String MOD_ID = "dynamichud";

public static void addWidgetRenderer(WidgetRenderer widgetRenderer) {
widgetRenderers.add(widgetRenderer);
}

public static List<WidgetRenderer> getWidgetRenderers() {
return widgetRenderers;
}

public static void printInfo(String msg) {
logger.info(msg);
Expand All @@ -55,133 +28,17 @@ public static void printWarn(String msg) {
logger.warn(msg);
}

/**
* Opens the MovableScreen when the specified key is pressed.
*
* @param key The key to listen for
* @param screen The AbstractMoveableScreen instance to use to set the screen
*/
public static void openDynamicScreen(KeyBinding key, AbstractMoveableScreen screen) {
if (key.wasPressed()) {
MC.setScreen(screen);
}
}

@Override
public void onInitializeClient() {
printInfo("Initialising DynamicHud");

// Add WidgetData of included widgets
WidgetManager.registerCustomWidgets(
TextWidget.DATA
);
printInfo("Initialising DynamicHUD");

//YACL load
GlobalConfig.HANDLER.load();

printInfo("Integrating mods...");
FabricLoader.getInstance()
.getEntrypointContainers("dynamicHud", DynamicHudIntegration.class)
.forEach(entrypoint -> {
ModMetadata metadata = entrypoint.getProvider().getMetadata();
String modId = metadata.getId();

printInfo(String.format("Supported mod with id %s was found!", modId));

AbstractMoveableScreen screen;
KeyBinding binding;
WidgetRenderer widgetRenderer;
File widgetsFile;
try {
DynamicHudIntegration DHIntegration = entrypoint.getEntrypoint();

//Calls the init method
DHIntegration.init();

//Gets the widget file to save and load the widgets from
widgetsFile = DHIntegration.getWidgetsFile();

// Adds / loads widgets from file
if (widgetsFile.exists()) {
WidgetManager.loadWidgets(widgetsFile);
} else {
DHIntegration.addWidgets();
}

//Calls the second init method
DHIntegration.initAfter();

// Get the instance of AbstractMoveableScreen
screen = Objects.requireNonNull( DHIntegration.getMovableScreen());

// Get the keybind to open the screen instance
binding = DHIntegration.getKeyBind();

//Register custom widget datas by WidgetManager.registerCustomWidgets();
DHIntegration.registerCustomWidgets();

//WidgetRenderer with widgets instance
widgetRenderer = DHIntegration.getWidgetRenderer();
addWidgetRenderer(widgetRenderer);

List<Widget> widgets = FILE_MAP.get(widgetsFile.getName());

if (widgets == null || widgets.isEmpty()) {
FILE_MAP.put(widgetsFile.getName(), widgetRenderer.getWidgets());
} else {
widgets.addAll(widgetRenderer.getWidgets());
FILE_MAP.put(widgetsFile.getName(), widgets);
}

//Register events for rendering, saving, loading, and opening the hudEditor
ClientTickEvents.START_CLIENT_TICK.register((client) -> openDynamicScreen(binding, screen));

/* === Saving === */

//When a player exits a world (SinglePlayer worlds) or a server stops
ServerLifecycleEvents.SERVER_STOPPING.register(server -> saveWidgetsSafely(widgetsFile, FILE_MAP.get(widgetsFile.getName())));

// When a resource pack is reloaded.
ServerLifecycleEvents.END_DATA_PACK_RELOAD.register((server, resourceManager, s) -> saveWidgetsSafely(widgetsFile, FILE_MAP.get(widgetsFile.getName())));

//When player disconnects
ServerPlayConnectionEvents.DISCONNECT.register((handler, packetSender) -> saveWidgetsSafely(widgetsFile, FILE_MAP.get(widgetsFile.getName())));

//When minecraft closes
ClientLifecycleEvents.CLIENT_STOPPING.register((minecraftClient) -> saveWidgetsSafely(widgetsFile, FILE_MAP.get(widgetsFile.getName())));

printInfo(String.format("Integration of mod %s was successful", modId));
} catch (Throwable e) {
if (e instanceof IOException) {
logger.warn("An error has occurred while loading widgets of mod {}", modId, e);
} else {
logger.warn("Mod {} has improper implementation of DynamicHUD", modId, e);
}
}
});
printInfo("(DynamicHUD) Integration of mods found was successful");


//Global config saving (YACL)
ServerLifecycleEvents.SERVER_STOPPING.register(server -> GlobalConfig.HANDLER.save());
ServerLifecycleEvents.END_DATA_PACK_RELOAD.register((server, resourceManager, s) -> GlobalConfig.HANDLER.save());
ServerPlayConnectionEvents.DISCONNECT.register((handler, packetSender) -> GlobalConfig.HANDLER.save());
ClientLifecycleEvents.CLIENT_STOPPING.register((minecraftClient) -> {
GlobalConfig.HANDLER.save();
});

IntegrationManager.integrate();

//In game screen render.
HudRenderCallback.EVENT.register(new HudRender());
}

private void saveWidgetsSafely(File widgetsFile, List<Widget> widgets) {
try {
WidgetManager.saveWidgets(widgetsFile, widgets);
} catch (IOException e) {
logger.error("Failed to save widgets. Widgets passed: {}", widgets);
throw new RuntimeException(e);
}
}

}
5 changes: 3 additions & 2 deletions src/main/java/com/tanishisherewith/dynamichud/HudRender.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.tanishisherewith.dynamichud;

import com.tanishisherewith.dynamichud.integration.IntegrationManager;
import com.tanishisherewith.dynamichud.widget.WidgetRenderer;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.minecraft.client.gui.DrawContext;
Expand All @@ -9,11 +10,11 @@
* Using the fabric event {@link HudRenderCallback} to render widgets in the game HUD.
* Mouse positions are passed in the negatives even though theoretically it's in the centre of the screen.
*/
public class HudRender implements HudRenderCallback{
public class HudRender implements HudRenderCallback {

@Override
public void onHudRender(DrawContext drawContext, RenderTickCounter tickCounter) {
for (WidgetRenderer widgetRenderer : DynamicHUD.getWidgetRenderers()) {
for (WidgetRenderer widgetRenderer : IntegrationManager.getWidgetRenderers()) {
widgetRenderer.renderWidgets(drawContext, -120, -120);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,36 @@
package com.tanishisherewith.dynamichud;

import com.tanishisherewith.dynamichud.integration.DynamicHudConfigurator;
import com.tanishisherewith.dynamichud.integration.DynamicHudIntegration;
import com.tanishisherewith.dynamichud.screens.AbstractMoveableScreen;
import com.tanishisherewith.dynamichud.utils.DynamicValueRegistry;
import com.tanishisherewith.dynamichud.widget.Widget;
import com.tanishisherewith.dynamichud.widget.WidgetManager;
import com.tanishisherewith.dynamichud.widget.WidgetRenderer;
import com.tanishisherewith.dynamichud.widgets.TextWidget;
import net.minecraft.client.gui.screen.TitleScreen;
import net.minecraft.text.Text;

import java.util.List;

public class DynamicHudTest implements DynamicHudIntegration {
public class IntegrationTest implements DynamicHudIntegration {
TextWidget FPSWidget;
TextWidget HelloWidget;
TextWidget DynamicHUDWidget;
DynamicValueRegistry registry;
WidgetRenderer renderer;

@Override
public void init() {
//Global registry
DynamicValueRegistry.registerGlobal("FPS", () -> "FPS: " + DynamicHUD.MC.getCurrentFps());
// We recommend using the syntax "modid:key_name" for easier debugging and to prevent data conflicts in global registries.
DynamicValueRegistry.registerGlobal("dynamichud:FPS", () -> "FPS: " + DynamicHUD.MC.getCurrentFps());

//Local registry
registry = new DynamicValueRegistry(DynamicHUD.MOD_ID);
registry.registerLocal("Hello", () -> "Hello " + DynamicHUD.MC.getSession().getUsername() + "!");
registry.registerLocal("DynamicHUD", () -> "DynamicHUD");


FPSWidget = new TextWidget.Builder()
.setX(250)
.setY(100)
.setY(150)
.setDraggable(true)
.rainbow(false)
.setDRKey("FPS")
.withRegistryKey("dynamichud:FPS")
.setModID(DynamicHUD.MOD_ID)
.shouldScale(false)
.build();
Expand All @@ -44,56 +40,42 @@ public void init() {
.setY(100)
.setDraggable(true)
.rainbow(false)
.setDRKey("Hello")
.setDVR(registry)
.withRegistryKey("Hello")
.withValueRegistry(registry)
.setModID(DynamicHUD.MOD_ID)
.shouldScale(true)
.shadow(true)
.build();

DynamicHUDWidget = new TextWidget.Builder()
.setX(5)
.setY(5)
.setX(0)
.setY(0)
.setDraggable(false)
.rainbow(true)
.setDRKey("DynamicHUD")
.setDVR(registry)
.withRegistryKey("DynamicHUD")
.withValueRegistry(registry)
.setModID(DynamicHUD.MOD_ID)
.shouldScale(true)
.build();

}

@Override
public void addWidgets() {
WidgetManager.addWidget(FPSWidget);
WidgetManager.addWidget(HelloWidget);
WidgetManager.addWidget(DynamicHUDWidget);
public DynamicHudConfigurator configure(DynamicHudConfigurator configurator) {
configurator.addWidget(FPSWidget)
.addWidget(HelloWidget)
.addWidget(DynamicHUDWidget)
.configureRenderer(renderer -> {
renderer.shouldRenderInGameHud(true);
renderer.addScreen(TitleScreen.class);
})
.withMoveableScreen(config -> new AbstractMoveableScreen(Text.literal("Editor Screen"), config.getRenderer()) {});

return configurator;
}

@Override
public void registerCustomWidgets() {
//WidgetManager.addWidgetData(MyWidget.DATA);
}

public void initAfter() {
List<Widget> widgets = WidgetManager.getWidgetsForMod(DynamicHUD.MOD_ID);

renderer = new WidgetRenderer(widgets);
renderer.shouldRenderInGameHud(true);

//This will make widgets render in the titlescreen as well.
renderer.addScreen(TitleScreen.class);
}

@Override
public AbstractMoveableScreen getMovableScreen() {
return new AbstractMoveableScreen(Text.literal("Editor Screen"), renderer) {
};
}

@Override
public WidgetRenderer getWidgetRenderer() {
return renderer;
}

}
Loading