Skip to content

Commit

Permalink
Added Text and cleaned up code/api
Browse files Browse the repository at this point in the history
  • Loading branch information
LordAnaku committed Sep 5, 2022
1 parent 3ce9b05 commit f169c42
Show file tree
Hide file tree
Showing 21 changed files with 954 additions and 563 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G
loader_version=0.14.8

# Mod Properties
mod_version = 1.1.5-1.19.2
mod_version = 1.1.6-1.19.2
maven_group = io.github.lordanaku
archives_base_name = anakus_status_bars

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,14 @@
public class AnakusStatusBarsClient implements ClientModInitializer {
@Override
public void onInitializeClient() {
Settings.registerShouldRenderSettings();
Settings.registerColorSettings();
Settings.registerAlphaSettings();
Settings.registerIconSettings();
Settings.registerPositionSettings();
Settings.registerPositionOffsets();
Settings.registerElementSettings();
RenderHudFunctions.setYModIncrement(TextureRecords.DEFAULT_BAR.height() + 1);



LogHelper.info("Loaded");
ConfigFileHandler.readFromConfig();
ClientSyncHandler.init();

ASBModUtils.registerHudElements(new HealthHudElement(), new HungerHudElement(), new ArmorBarElement(), new MountBarElement(), new BreathBarElement());
ASBModUtils.registerHudElements(new HealthIHudElement(), new HungerIHudElement(), new ArmorBarElement(), new MountBarElement(), new BreathBarElement());

HudRenderCallback.EVENT.register(new RenderHudElements());

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.lordanaku.anakus_status_bars.api;

import io.github.lordanaku.anakus_status_bars.api.hudelements.HudElements;
import io.github.lordanaku.anakus_status_bars.api.hudelements.IHudElement;
import io.github.lordanaku.anakus_status_bars.screen.gui.config.Settings;
import io.github.lordanaku.anakus_status_bars.utils.ASBModUtils;

Expand All @@ -9,7 +9,7 @@ public class ModRegisterFunctions {

/**
* Register Settings for rather or not mod hud elements should render.
* @param key The key for the setting (probably best to stick to ID chosen for HudElements.)
* @param key The key for the setting (probably best to stick to ID chosen for IHudElement.)
* @param value The default value for if hud element should render.
*/
public static void registerShouldRenderModSettings(String key, Boolean value) {
Expand All @@ -18,7 +18,7 @@ public static void registerShouldRenderModSettings(String key, Boolean value) {

/**
* Register Settings for color of hud element.
* @param key The key for the setting (probably best to stick to Color_ID chosen for HudElements.)
* @param key The key for the setting (probably best to stick to Color_ID chosen for IHudElement.)
* @param value The default value for hud element color.
*/
public static void registerColorModSettings(String key, int value) {
Expand All @@ -27,7 +27,7 @@ public static void registerColorModSettings(String key, int value) {

/**
* Register Settings for the alpha of hud element.
* @param key The key for the setting (probably best to stick to Alpha_ID chosen for HudElements.)
* @param key The key for the setting (probably best to stick to Alpha_ID chosen for IHudElement.)
* @param value The default value for hud element alpha.
*/
public static void registerAlphaModSettings(String key, float value) {
Expand All @@ -36,7 +36,7 @@ public static void registerAlphaModSettings(String key, float value) {

/**
* Register Settings for rather or not mod hud elements icon should render.
* @param key The key for the setting (probably best to stick to Icon_ID chosen for HudElements.)
* @param key The key for the setting (probably best to stick to Icon_ID chosen for IHudElement.)
* @param value The default value for if hud element icon should render.
*/
public static void registerIconModSettings(String key, Boolean value) {
Expand All @@ -45,24 +45,24 @@ public static void registerIconModSettings(String key, Boolean value) {

/**
* Register Default side for your hud element to render on to left side. (only call one or the other)
* @param hudElementName The ID of your HudElement. (This must be the same as the ID you gave it in HudElements.)
* @param hudElementName The ID of your HudElement. (This must be the same as the ID you gave it in IHudElement.)
* @param side The default side for your HudElement to render on. (left = true, right = false)
*/
public static void registerHudElementSide(String hudElementName, boolean side) {
if (side) {
if(!ASBModUtils.leftOrderDefault.contains(hudElementName)) ASBModUtils.setOrderDefaults(hudElementName, true);
if(!Settings.leftOrderDefault.contains(hudElementName)) ASBModUtils.setOrderDefaults(hudElementName, true);
if(!Settings.positionOrderSettings.get("left").contains(hudElementName)) Settings.positionOrderSettings.get("left").add(hudElementName);
} else {
if (!ASBModUtils.rightOrderDefault.contains(hudElementName)) ASBModUtils.setOrderDefaults(hudElementName, false);
if (!Settings.rightOrderDefault.contains(hudElementName)) ASBModUtils.setOrderDefaults(hudElementName, false);
if (!Settings.positionOrderSettings.get("right").contains(hudElementName)) Settings.positionOrderSettings.get("right").add(hudElementName);
}
}

/**
* Register Mod Hud Element to array of Hud Elements to be rendered.
* @param hudElements The Hud Element to be registered.
* @param IHudElements The Hud Element to be registered.
*/
public static void registerModHudElements(HudElements hudElements) {
if (!Settings.registry.containsKey(hudElements.name())) Settings.registry.put(hudElements.name(), hudElements);
public static void registerModHudElements(IHudElement IHudElements) {
if (!Settings.registry.containsKey(IHudElements.name())) Settings.registry.put(IHudElements.name(), IHudElements);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.github.lordanaku.anakus_status_bars.api.hudelements;

/**
* Create a Hud Element Type.
* (default values)
* @param name The name of the Hud Element Type.
* @param shouldRender Whether the Hud Element should be rendered.
* @param side What side the Hud Element should be rendered on. (True = Left)
* @param shouldRenderIcon Whether the Hud Element should render an icon.
* @param color The color of the Hud Element.
* @param alpha The alpha of the Hud Element.
*/
public record HudElementType(String name, boolean shouldRender, boolean side, boolean shouldRenderIcon, boolean shouldRenderText, int color, float alpha) {

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.github.lordanaku.anakus_status_bars.api.hudelements;

import me.shedaniel.clothconfig2.api.ConfigCategory;
import me.shedaniel.clothconfig2.api.ConfigEntryBuilder;

public interface IHudElement {
void renderBar();
void renderIcon();
void renderText();
boolean getSide();
IHudElement setSide(boolean side);
boolean shouldRender();
boolean shouldRenderIcon();
boolean shouldRenderText();
void registerSettings(ConfigCategory mainCategory, ConfigCategory iconCategory, ConfigCategory textCategory, ConfigCategory colorCategory, ConfigCategory textColorSettings, ConfigCategory alphaCategory, ConfigEntryBuilder entryBuilder);
String name();
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.github.lordanaku.anakus_status_bars.utils.ASBModUtils;
import io.github.lordanaku.anakus_status_bars.utils.ColorUtils;
import io.github.lordanaku.anakus_status_bars.utils.TextureRecord;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawableHelper;
import net.minecraft.util.Identifier;

Expand Down Expand Up @@ -74,6 +75,25 @@ public static void drawStatusEffectBar(boolean side, int posYMod, TextureRecord
textureRecord.maxWidth(), textureRecord.maxHeight());
}

/**
* Draws the text for the Hud Element.
* @param text - the text to draw.
* @param side - true if the bar is on the left side of the screen, false if on the right side.
* @param icon - rather or not the icon is being drawn.
* @param posYMod - the amount you want to add to the base -40 y position.
* @param color - the color of the text. (Hex Value)
* @param barWidth - the width of the bar so method can determine offset.
*/
public static void drawText(String text, boolean side, boolean icon, int posYMod, int color, int barWidth) {
int finalSide = (side) ? posXLeft - (MinecraftClient.getInstance().textRenderer.getWidth(text) + 1) : posXRight + (barWidth + 1);

if (icon) {
finalSide = (side) ? posXLeft - (MinecraftClient.getInstance().textRenderer.getWidth(text) + 1) - 10 : posXRight + (barWidth + 1) + 10;
}

MinecraftClient.getInstance().textRenderer.drawWithShadow(hudMatrix, text, finalSide, posY + posYMod + 1, color);
}

/**
* Draws the icon for the bar.
* @param side - true if the bar is on the left side of the screen, false if on the right side.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.github.lordanaku.anakus_status_bars.screen.gui.config;

import io.github.lordanaku.anakus_status_bars.api.hudelements.IHudElement;
import io.github.lordanaku.anakus_status_bars.utils.LogHelper;
import me.shedaniel.clothconfig2.api.ConfigBuilder;
import me.shedaniel.clothconfig2.api.ConfigCategory;
import net.minecraft.client.gui.screen.Screen;
Expand All @@ -14,14 +16,19 @@ public static Screen CreateConfigScreen(Screen parent) {
builder.setSavingRunnable(ConfigFileHandler::writeToConfig);

ConfigCategory mainCategory = builder.getOrCreateCategory(Text.translatable("category.anakus_status_bars.general"));
ConfigCategory positionCategory = builder.getOrCreateCategory(Text.translatable("category.anakus_status_bars.position"));
ConfigCategory colorCategory = builder.getOrCreateCategory(Text.translatable("category.anakus_status_bars.color"));
ConfigCategory iconCategory = builder.getOrCreateCategory(Text.translatable("category.anakus_status_bars.icon"));
ConfigCategory textCategory = builder.getOrCreateCategory(Text.translatable("category.anakus_status_bars.text"));
ConfigCategory colorCategory = builder.getOrCreateCategory(Text.translatable("category.anakus_status_bars.color"));
ConfigCategory textColorSettings = builder.getOrCreateCategory(Text.translatable("category.anakus_status_bars.text_color"));
ConfigCategory alphaCategory = builder.getOrCreateCategory(Text.translatable("category.anakus_status_bars.alpha"));
ConfigCategory positionCategory = builder.getOrCreateCategory(Text.translatable("category.anakus_status_bars.position"));

for (IHudElement hudElement : Settings.I_HUD_ELEMENTS_LIST) {
hudElement.registerSettings(mainCategory, iconCategory, textCategory, colorCategory, textColorSettings, alphaCategory, builder.entryBuilder());
LogHelper.info("Registered settings for " + hudElement.name());
}

ConfigValues.buildMain(mainCategory, builder.entryBuilder());
ConfigValues.buildPosition(positionCategory, builder.entryBuilder());
ConfigValues.buildColors(colorCategory, builder.entryBuilder());
ConfigValues.buildIcons(iconCategory, builder.entryBuilder());

return builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,34 @@ public static void readFromConfig() {
Settings.shouldRenderSettings.replace(entry.getKey(), entry.getValue().getAsBoolean());
}
}
if(root.has("icon_settings")) {
JsonObject object = root.get("icon_settings").getAsJsonObject();
for (Map.Entry<String, JsonElement> entry : object.entrySet()) {
Settings.iconSettings.replace(entry.getKey(), entry.getValue().getAsBoolean());
}
}
if(root.has("text_settings")) {
JsonObject object = root.get("text_settings").getAsJsonObject();
for (Map.Entry<String, JsonElement> entry : object.entrySet()) {
Settings.textSettings.replace(entry.getKey(), entry.getValue().getAsBoolean());
}
}
if(root.has("color_settings")) {
JsonObject object = root.get("color_settings").getAsJsonObject();
for (Map.Entry<String, JsonElement> entry : object.entrySet()) {
Settings.colorSettings.replace(entry.getKey(), entry.getValue().getAsInt());
}
}
if(root.has("alpha_settings")) {
JsonObject object = root.get("alpha_settings").getAsJsonObject();
if(root.has("text_color_settings")) {
JsonObject object = root.get("text_color_settings").getAsJsonObject();
for (Map.Entry<String, JsonElement> entry : object.entrySet()) {
Settings.alphaSettings.replace(entry.getKey(), entry.getValue().getAsFloat());
Settings.textColorSettings.replace(entry.getKey(), entry.getValue().getAsInt());
}
}
if(root.has("icon_settings")) {
JsonObject object = root.get("icon_settings").getAsJsonObject();
if(root.has("alpha_settings")) {
JsonObject object = root.get("alpha_settings").getAsJsonObject();
for (Map.Entry<String, JsonElement> entry : object.entrySet()) {
Settings.iconSettings.replace(entry.getKey(), entry.getValue().getAsBoolean());
Settings.alphaSettings.replace(entry.getKey(), entry.getValue().getAsFloat());
}
}
if(root.has("render_side")) {
Expand All @@ -71,9 +83,11 @@ public static void writeToConfig() {

try {
root.add("render_settings", gson.toJsonTree(Settings.shouldRenderSettings));
root.add("icon_settings", gson.toJsonTree(Settings.iconSettings));
root.add("text_settings", gson.toJsonTree(Settings.textSettings));
root.add("color_settings", gson.toJsonTree(Settings.colorSettings));
root.add("text_color_settings", gson.toJsonTree(Settings.textColorSettings));
root.add("alpha_settings", gson.toJsonTree(Settings.alphaSettings));
root.add("icon_settings", gson.toJsonTree(Settings.iconSettings));
root.add("render_side", gson.toJsonTree(Settings.positionOrderSettings));
root.add("offsets", gson.toJsonTree(Settings.positionOffsets));
} catch (Exception e) {
Expand Down

0 comments on commit f169c42

Please sign in to comment.