Skip to content

Commit

Permalink
Final refactor and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
tanishisherewithhh committed Apr 13, 2024
1 parent 18d2627 commit 320164f
Show file tree
Hide file tree
Showing 35 changed files with 133 additions and 126 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.tanishisherewith.dynamichud.newTrial;

import com.tanishisherewith.dynamichud.newTrial.config.GlobalConfig;
import com.tanishisherewith.dynamichud.newTrial.screens.AbstractMoveableScreen;
import com.tanishisherewith.dynamichud.newTrial.widget.Widget;
import com.tanishisherewith.dynamichud.newTrial.widget.WidgetManager;
import com.tanishisherewith.dynamichud.newTrial.widget.WidgetRenderer;
import com.tanishisherewith.dynamichud.newTrial.widgets.TextWidget;
package com.tanishisherewith.dynamichud;

import com.tanishisherewith.dynamichud.config.GlobalConfig;
import com.tanishisherewith.dynamichud.screens.AbstractMoveableScreen;
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.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
Expand Down Expand Up @@ -144,7 +144,7 @@ public void onInitializeClient() {
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())));
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) {
Expand All @@ -159,7 +159,7 @@ public void onInitializeClient() {
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());
ClientLifecycleEvents.CLIENT_STOPPING.register((minecraftClient) -> GlobalConfig.HANDLER.save());


HudRenderCallback.EVENT.register(new HudRender());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.tanishisherewith.dynamichud.newTrial;
package com.tanishisherewith.dynamichud;

import com.tanishisherewith.dynamichud.newTrial.screens.AbstractMoveableScreen;
import com.tanishisherewith.dynamichud.newTrial.widget.WidgetData;
import com.tanishisherewith.dynamichud.newTrial.widget.WidgetManager;
import com.tanishisherewith.dynamichud.newTrial.widget.WidgetRenderer;
import com.tanishisherewith.dynamichud.screens.AbstractMoveableScreen;
import com.tanishisherewith.dynamichud.widget.WidgetData;
import com.tanishisherewith.dynamichud.widget.WidgetManager;
import com.tanishisherewith.dynamichud.widget.WidgetRenderer;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.option.KeyBinding;
Expand Down Expand Up @@ -64,7 +64,7 @@ public interface DynamicHudIntegration {
/**
* Initializes the DynamicHud integration.
* <p>
* Suggested to be used to initialize {@link com.tanishisherewith.dynamichud.newTrial.utils.DynamicValueRegistry} and widgets with their respective values
* Suggested to be used to initialize {@link com.tanishisherewith.dynamichud.utils.DynamicValueRegistry} and widgets with their respective values
* </p>
*/
void init();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.tanishisherewith.dynamichud.newTrial;
package com.tanishisherewith.dynamichud;

import com.tanishisherewith.dynamichud.newTrial.screens.AbstractMoveableScreen;
import com.tanishisherewith.dynamichud.newTrial.utils.DynamicValueRegistry;
import com.tanishisherewith.dynamichud.newTrial.widget.Widget;
import com.tanishisherewith.dynamichud.newTrial.widget.WidgetManager;
import com.tanishisherewith.dynamichud.newTrial.widget.WidgetRenderer;
import com.tanishisherewith.dynamichud.newTrial.widgets.TextWidget;
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.client.gui.screen.multiplayer.MultiplayerScreen;
import net.minecraft.text.Text;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.tanishisherewith.dynamichud.newTrial;
package com.tanishisherewith.dynamichud;

import com.tanishisherewith.dynamichud.newTrial.widget.WidgetRenderer;
import com.tanishisherewith.dynamichud.widget.WidgetRenderer;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.minecraft.client.gui.DrawContext;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.tanishisherewith.dynamichud;

import com.tanishisherewith.dynamichud.newTrial.config.GlobalConfig;
import com.tanishisherewith.dynamichud.config.GlobalConfig;
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
import com.terraformersmc.modmenu.api.ModMenuApi;
import net.minecraft.client.gui.screen.Screen;


public class ModMenuIntegration implements ModMenuApi {
public static Screen YACL_CONFIG_SCREEN = GlobalConfig.get().createYACLGUI();

@Override
public ConfigScreenFactory<?> getModConfigScreenFactory() {
return parent -> YACL_CONFIG_SCREEN;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.tanishisherewith.dynamichud.newTrial.config;
package com.tanishisherewith.dynamichud.config;

import dev.isxander.yacl3.api.*;
import dev.isxander.yacl3.api.controller.FloatSliderControllerBuilder;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.tanishisherewith.dynamichud.newTrial.helpers;
package com.tanishisherewith.dynamichud.helpers;

import net.minecraft.util.math.MathHelper;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.tanishisherewith.dynamichud.newTrial.helpers;
package com.tanishisherewith.dynamichud.helpers;

import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import com.tanishisherewith.dynamichud.newTrial.DynamicHUD;
import com.tanishisherewith.dynamichud.DynamicHUD;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.render.*;
import net.minecraft.client.util.math.MatrixStack;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.tanishisherewith.dynamichud.mixins;

import com.tanishisherewith.dynamichud.newTrial.DynamicHUD;
import com.tanishisherewith.dynamichud.newTrial.widget.WidgetManager;
import com.tanishisherewith.dynamichud.newTrial.widget.WidgetRenderer;
import com.tanishisherewith.dynamichud.DynamicHUD;
import com.tanishisherewith.dynamichud.widget.WidgetManager;
import com.tanishisherewith.dynamichud.widget.WidgetRenderer;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
Expand All @@ -14,23 +14,27 @@

@Mixin(Screen.class)
public abstract class ScreenMixin {
@Shadow public int width;
@Shadow
public int width;

@Shadow public int height;
@Shadow
public int height;

@Inject(at = @At("TAIL"), method = "render")
private void render(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) {
for(WidgetRenderer widgetRenderer: DynamicHUD.getWidgetRenderers()){
widgetRenderer.renderWidgets(context,mouseX,mouseY);
for (WidgetRenderer widgetRenderer : DynamicHUD.getWidgetRenderers()) {
widgetRenderer.renderWidgets(context, mouseX, mouseY);
}
}

@Inject(at = @At("HEAD"), method = "resize")
private void onScreenResize(MinecraftClient client,int width, int height, CallbackInfo ci) {
WidgetManager.onScreenResized(width,height,this.width,this.height);
private void onScreenResize(MinecraftClient client, int width, int height, CallbackInfo ci) {
WidgetManager.onScreenResized(width, height, this.width, this.height);
}

@Inject(at = @At("HEAD"), method = "close")
private void onClose(CallbackInfo ci) {
for(WidgetRenderer widgetRenderer: DynamicHUD.getWidgetRenderers()){
for (WidgetRenderer widgetRenderer : DynamicHUD.getWidgetRenderers()) {
widgetRenderer.onCloseScreen();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.tanishisherewith.dynamichud.newTrial.screens;
package com.tanishisherewith.dynamichud.screens;

import com.tanishisherewith.dynamichud.newTrial.widget.WidgetRenderer;
import com.tanishisherewith.dynamichud.widget.WidgetRenderer;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.Text;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.tanishisherewith.dynamichud.newTrial.utils;
package com.tanishisherewith.dynamichud.utils;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.tanishisherewith.dynamichud.newTrial.utils;
package com.tanishisherewith.dynamichud.utils;

import java.util.List;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.tanishisherewith.dynamichud.newTrial.utils;
package com.tanishisherewith.dynamichud.utils;

import java.util.Random;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.tanishisherewith.dynamichud.newTrial.utils;
package com.tanishisherewith.dynamichud.utils;

import com.tanishisherewith.dynamichud.newTrial.DynamicHUD;
import com.tanishisherewith.dynamichud.DynamicHUD;

public class Util {
public static Quadrant getQuadrant(int x, int y) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.tanishisherewith.dynamichud.newTrial.utils.contextmenu;
package com.tanishisherewith.dynamichud.utils.contextmenu;

import com.tanishisherewith.dynamichud.newTrial.helpers.DrawHelper;
import com.tanishisherewith.dynamichud.helpers.DrawHelper;
import net.minecraft.client.gui.DrawContext;

import java.awt.*;
Expand Down Expand Up @@ -46,7 +46,7 @@ public void render(DrawContext drawContext, int x, int y, int height) {
int yOffset = y1 + 3;
this.width = 10;
for (Option<?> option : options) {
if(!option.shouldRender())continue;
if (!option.shouldRender()) continue;
option.render(drawContext, x + 2, yOffset);
this.width = Math.max(this.width, option.width + padding);
yOffset += option.height + 1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.tanishisherewith.dynamichud.newTrial.utils.contextmenu;
package com.tanishisherewith.dynamichud.utils.contextmenu;

import com.tanishisherewith.dynamichud.newTrial.widget.Widget;
import com.tanishisherewith.dynamichud.widget.Widget;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;

Expand All @@ -12,21 +12,22 @@ public abstract class Option<T> {
public int width = 0;
public int height = 0;
public T value = null;
public Supplier<Boolean> shouldRender = () -> true;
protected float scale = 0.0f;
protected Supplier<T> getter;
protected Consumer<T> setter;
protected T defaultValue = null;
protected MinecraftClient mc = MinecraftClient.getInstance();
private Widget selectedWidget; // The widget that this context menu is associated with
public Supplier<Boolean> shouldRender = ()->true;

public Option(Supplier<T> getter, Consumer<T> setter) {
this.getter = getter;
this.setter = setter;
value = get();
defaultValue = get();
}
public Option(Supplier<T> getter, Consumer<T> setter,Supplier<Boolean> shouldRender) {

public Option(Supplier<T> getter, Consumer<T> setter, Supplier<Boolean> shouldRender) {
this.getter = getter;
this.setter = setter;
this.shouldRender = shouldRender;
Expand Down Expand Up @@ -77,7 +78,7 @@ public Option<T> setShouldRender(Supplier<Boolean> shouldRender) {
return this;
}

public boolean shouldRender(){
public boolean shouldRender() {
return shouldRender.get();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.tanishisherewith.dynamichud.newTrial.utils.contextmenu.options;
package com.tanishisherewith.dynamichud.utils.contextmenu.options;

import com.tanishisherewith.dynamichud.newTrial.utils.contextmenu.Option;
import com.tanishisherewith.dynamichud.utils.contextmenu.Option;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.text.Text;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.tanishisherewith.dynamichud.newTrial.utils.contextmenu.options;
package com.tanishisherewith.dynamichud.utils.contextmenu.options;

import com.tanishisherewith.dynamichud.newTrial.helpers.DrawHelper;
import com.tanishisherewith.dynamichud.newTrial.utils.contextmenu.Option;
import com.tanishisherewith.dynamichud.helpers.DrawHelper;
import com.tanishisherewith.dynamichud.utils.contextmenu.Option;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;
import org.apache.commons.lang3.Validate;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.tanishisherewith.dynamichud.newTrial.utils.contextmenu.options;
package com.tanishisherewith.dynamichud.utils.contextmenu.options;

import com.tanishisherewith.dynamichud.newTrial.utils.contextmenu.Option;
import com.tanishisherewith.dynamichud.utils.contextmenu.Option;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.text.Text;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.tanishisherewith.dynamichud.newTrial.utils.contextmenu.options;
package com.tanishisherewith.dynamichud.utils.contextmenu.options;

import com.tanishisherewith.dynamichud.newTrial.utils.contextmenu.Option;
import com.tanishisherewith.dynamichud.utils.contextmenu.Option;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.text.Text;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.tanishisherewith.dynamichud.newTrial.utils.contextmenu.options;
package com.tanishisherewith.dynamichud.utils.contextmenu.options;

import com.tanishisherewith.dynamichud.newTrial.utils.contextmenu.Option;
import com.tanishisherewith.dynamichud.utils.contextmenu.Option;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.text.Text;

Expand All @@ -9,8 +9,8 @@
import java.util.function.Supplier;

public class RunnableOption extends Option<Boolean> {
public String name = "Empty";
private final Runnable task;
public String name = "Empty";

/**
* Runnable option which runs a task when clicked on it.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.tanishisherewith.dynamichud.newTrial.utils.contextmenu.options;
package com.tanishisherewith.dynamichud.utils.contextmenu.options;

import com.tanishisherewith.dynamichud.newTrial.utils.contextmenu.ContextMenu;
import com.tanishisherewith.dynamichud.newTrial.utils.contextmenu.Option;
import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenu;
import com.tanishisherewith.dynamichud.utils.contextmenu.Option;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.text.Text;
import org.jetbrains.annotations.NotNull;
Expand All @@ -14,9 +14,9 @@
/**
* SubMenu option displays a sub menu beside a boolean-like button.
* <p>
* The {@link #getter} gets a boolean value to display/close the subMenu by default.
* The {@link #getter} gets a boolean value to display/close the subMenu by default.
* <p>
* The {@link #setter} returns a boolean value depending on if the subMenu is visible or not
* The {@link #setter} returns a boolean value depending on if the subMenu is visible or not
*/
public class SubMenuOption extends Option<Boolean> {
private final ContextMenu subMenu;
Expand All @@ -26,10 +26,10 @@ public class SubMenuOption extends Option<Boolean> {

public SubMenuOption(String name, @NotNull ContextMenu parentMenu, Supplier<Boolean> getter, Consumer<Boolean> setter) {
super(getter, setter);
Objects.requireNonNull(parentMenu,"Parent Menu cannot be null");
Objects.requireNonNull(parentMenu, "Parent Menu cannot be null");
this.name = name;
this.parentMenu = parentMenu;
this.subMenu = new ContextMenu(parentMenu.x + parentMenu.width,this.y);
this.subMenu = new ContextMenu(parentMenu.x + parentMenu.width, this.y);
this.subMenu.heightOffset = 0;
this.subMenu.shouldDisplay = get();
}
Expand Down Expand Up @@ -67,7 +67,7 @@ public boolean mouseDragged(double mouseX, double mouseY, int button) {
return super.mouseDragged(mouseX, mouseY, button);
}

public SubMenuOption getOption(){
public SubMenuOption getOption() {
return this;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.tanishisherewith.dynamichud.newTrial.utils.contextmenu.options.coloroption;
package com.tanishisherewith.dynamichud.utils.contextmenu.options.coloroption;

import com.tanishisherewith.dynamichud.newTrial.helpers.ColorHelper;
import com.tanishisherewith.dynamichud.newTrial.helpers.DrawHelper;
import com.tanishisherewith.dynamichud.helpers.ColorHelper;
import com.tanishisherewith.dynamichud.helpers.DrawHelper;
import net.minecraft.client.gui.DrawContext;

import java.awt.*;
Expand Down
Loading

0 comments on commit 320164f

Please sign in to comment.