Skip to content

Commit

Permalink
Updated fabric.mod.json (modmenu.discord, license)
Browse files Browse the repository at this point in the history
Updated build.gradle
Updated the config
Moved RenderableButton.java and Row.java to the components directory
Replaced MouseMixin with MinecraftClientMixin
  • Loading branch information
Spyxar committed Nov 22, 2022
1 parent 83fc895 commit 5cc2af0
Show file tree
Hide file tree
Showing 15 changed files with 325 additions and 272 deletions.
15 changes: 2 additions & 13 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,16 @@ version = project.mod_version
group = project.maven_group

repositories {
//ModMenu & Cloth Config
//ModMenu
maven { url "https://maven.terraformersmc.com/releases/"}
//Cloth Config
maven { url "https://maven.shedaniel.me/" }
}

dependencies {
// To change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

//ModMenu
Expand All @@ -32,10 +30,6 @@ dependencies {
modApi("me.shedaniel.cloth:cloth-config-fabric:8.2.88") {
exclude(group: "net.fabricmc.fabric-api")
}

// Uncomment the following line to enable the deprecated Fabric API modules.
// These are included in the Fabric API production distribution and allow you to update your mod to the latest modules at a later more convenient time.
// modImplementation "net.fabricmc.fabric-api:fabric-api-deprecated:${project.fabric_version}"
}

processResources {
Expand Down Expand Up @@ -67,11 +61,6 @@ publishing {
}
}

// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
repositories {
// Add repositories to publish to here.
// Notice: This block does NOT have the same function as the block in the top level.
// The repositories here will be used for publishing your artifact, not for
// retrieving dependencies.
}
}
40 changes: 40 additions & 0 deletions src/main/java/com/spyxar/tiptapshow/ClickCounter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.spyxar.tiptapshow;

import com.google.common.collect.Lists;

import java.util.Queue;

public class ClickCounter
{
private static final Queue<Long> leftClicks = Lists.newLinkedList();
private static final Queue<Long> rightClicks = Lists.newLinkedList();

public static void registerLeftClick()
{
leftClicks.add(System.currentTimeMillis() + 1000L);
}

public static void registerRightClick()
{
rightClicks.add(System.currentTimeMillis() + 1000L);
}

public static int getLeftCps()
{
return getClicksFromQueue(leftClicks);
}

public static int getRightCps()
{
return getClicksFromQueue(rightClicks);
}

private static int getClicksFromQueue(Queue<Long> clickList)
{
while (!clickList.isEmpty() && clickList.peek() < System.currentTimeMillis())
{
clickList.remove();
}
return clickList.size();
}
}
122 changes: 24 additions & 98 deletions src/main/java/com/spyxar/tiptapshow/KeystrokeOverlay.java
Original file line number Diff line number Diff line change
@@ -1,130 +1,56 @@
package com.spyxar.tiptapshow;

import com.spyxar.tiptapshow.components.Row;
import com.spyxar.tiptapshow.config.TipTapShowConfig;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawableHelper;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.math.MatrixStack;

public class KeystrokeOverlay implements HudRenderCallback
{
//private Row[] rows = config.getrows;
private static final int STANDARD_SIDE_OFFSET = 25;
private static final int STANDARD_TOP_OFFSET = 25;
private static final int BOX_SIZE = 25;
public static final int BOX_SIZE = 25;
public static final int ROW_SEPARATOR_SIZE = 1;
public static final int ROW_WIDTH = 77;
public static final int ROW_HEIGHT_NORMAL = 25;
public static final int ROW_HEIGHT_SMALL = 20;

@SuppressWarnings("RedundantArrayCreation")
@Override
public void onHudRender(MatrixStack matrixStack, float tickDelta)
{
int x = 0;
int y = 0;
MinecraftClient client = MinecraftClient.getInstance();
TipTapShowConfig config = TipTapShowConfig.loadConfig();
if (client == null)
{
TipTapShowMod.LOGGER.error("Client was null, making all renders fail.");
return;
}
if (!config.renderInGui && client.currentScreen != null)
if (client.options.debugEnabled)
{
return;
}
//ToDo: just add basic x and y, then dynamic from config
// also use scaledwidth and height to make the squares the right size
//ToDo: also get vertical exact mid
if (client != null)
if (!config.renderInGui && client.currentScreen != null)
{
int width = client.getWindow().getScaledWidth();
int height = client.getWindow().getScaledHeight();

x = width / 2;
y = height;
return;
}
//a row object would be good, so we dont have to do the +1/2/3 and *1/2/3 but can instead use a foreach
//and have default row offsets from eachother
//ToDo: make use of dynamic display values from the config
// We probably will not have to use client.getWindow().getScaledWidth()/getScaledWidth()
// because people will just be able to change the display to their liking and depending on their GUI scale/fullscreen
// However we may need to do some more math for the text to still be in the middle with a different GUI size, needs testing

//mouse button size: 25 + 25 + 25 + 2 = 77
//so 77 - 1 / 2 is the size per mouse button
RenderableButton forwardButton = new RenderableButton(STANDARD_SIDE_OFFSET + 2 * BOX_SIZE + 2, 25 - 1, BOX_SIZE, BOX_SIZE, client.options.forwardKey);
RenderableButton leftButton = new RenderableButton(STANDARD_SIDE_OFFSET + 1 * BOX_SIZE + 1, 50, BOX_SIZE, BOX_SIZE, client.options.leftKey);
RenderableButton backButton = new RenderableButton(STANDARD_SIDE_OFFSET + 2 * BOX_SIZE + 2, 50, BOX_SIZE, BOX_SIZE, client.options.backKey);
RenderableButton rightButton = new RenderableButton(STANDARD_SIDE_OFFSET + 3 * BOX_SIZE + 3, 50, BOX_SIZE, BOX_SIZE, client.options.rightKey);
//change to mouse button
RenderableButton leftMouseButton = new RenderableButton(STANDARD_SIDE_OFFSET + 1 * BOX_SIZE + 1, 75 + 1, BOX_SIZE, BOX_SIZE, client.options.dropKey);
RenderableButton rightMouseButton = new RenderableButton(STANDARD_SIDE_OFFSET + 3 * BOX_SIZE + 3, 75 + 1, BOX_SIZE, BOX_SIZE, client.options.dropKey);
matrixStack.push();
int offset = 25;
//setup: 0x + rrggbb + alpha
// DrawableHelper.fill(matrixStack, offset, offset, offset + BOX_SIZE, offset + BOX_SIZE, 0x131314b3);
// client.textRenderer.draw(matrixStack, forwardButton.getText(), BOX_SIZE / 2F + offset - letterWidth / 2F, BOX_SIZE / 2F + offset - textHeight / 2F, 16777215);

// Row forwardRow = new Row(forwardButton);
// Row walkRow = new Row(leftButton, backButton, rightButton);
// Row mouseRow = new Row(leftMouseButton, rightMouseButton);
//Todo: render all buttons at the same time, same method because this is laggy when button is pressed
renderButton(forwardButton, matrixStack);
renderButton(leftButton, matrixStack);
renderButton(backButton, matrixStack);
renderButton(rightButton, matrixStack);
renderButton(leftMouseButton, matrixStack);
renderButton(rightMouseButton, matrixStack);

//ToDo: the height stuff is ugly
Row row1 = new Row(STANDARD_SIDE_OFFSET, STANDARD_TOP_OFFSET, ROW_WIDTH, ROW_HEIGHT_NORMAL, new KeyBinding[]{null, client.options.forwardKey, null});
Row row2 = new Row(STANDARD_SIDE_OFFSET, STANDARD_TOP_OFFSET + row1.height + ROW_SEPARATOR_SIZE, ROW_WIDTH, ROW_HEIGHT_NORMAL, new KeyBinding[]{client.options.leftKey, client.options.backKey, client.options.rightKey});
Row row3 = new Row(STANDARD_SIDE_OFFSET, STANDARD_TOP_OFFSET + row1.height + row2.height + ROW_SEPARATOR_SIZE * 2, ROW_WIDTH, ROW_HEIGHT_NORMAL, new KeyBinding[]{client.options.attackKey, client.options.useKey});
Row row4 = new Row(STANDARD_SIDE_OFFSET, STANDARD_TOP_OFFSET + row1.height + row2.height + row3.height + ROW_SEPARATOR_SIZE * 3, ROW_WIDTH, ROW_HEIGHT_SMALL, new KeyBinding[]{client.options.jumpKey});
row1.render(matrixStack);
row2.render(matrixStack);
row3.render(matrixStack);
row4.render(matrixStack);
matrixStack.pop();
}

public void renderButton(RenderableButton button, MatrixStack matrixStack)
{
TipTapShowConfig config = TipTapShowConfig.loadConfig();
//correct way of getting the key: MinecraftClient.getInstance().options.sprintKey.getBoundKeyLocalizedText().getString().toUpperCase()
//text = client.options.forwardKey.getDefaultKey().getLocalizedText().getString().toUpperCase()
MinecraftClient client = MinecraftClient.getInstance();
int fillColor = 0;
int textColor = 0;
//todo mouse button
int letterWidth = client.textRenderer.getWidth(button.getKey().getBoundKeyLocalizedText().getString().toUpperCase());
if (button.getKey().isPressed())
{
// fillColor = 0x131314b3;
// textColor = 16711680;
fillColor = config.pressedBackgroundColor;
textColor = config.pressedKeyColor;
// DrawableHelper.fill(matrixStack, button.getX(), button.getY(), button.getX() + button.getWidth(), button.getY() + button.getHeight(), fillColor);
// client.textRenderer.draw(matrixStack, button.getKey().getBoundKeyLocalizedText().getString().toUpperCase(), BOX_SIZE / 2F + button.getX() - letterWidth / 2F, BOX_SIZE / 2F + button.getY() - client.textRenderer.fontHeight / 2F, textColor);
}
if (!button.getKey().isPressed())
{
// fillColor = 0x131314b3;
// textColor = 16777215;
fillColor = config.backgroundColor;
textColor = config.keyColor;
}
DrawableHelper.fill(matrixStack, button.getX(), button.getY(), button.getX() + button.getWidth(), button.getY() + button.getHeight(), fillColor);
client.textRenderer.draw(matrixStack, button.getKey().getBoundKeyLocalizedText().getString().toUpperCase(), BOX_SIZE / 2F + button.getX() - letterWidth / 2F, BOX_SIZE / 2F + button.getY() - client.textRenderer.fontHeight / 2F, textColor);
}

public void renderRow(Row row, MatrixStack matrixStack)
{
MinecraftClient client = MinecraftClient.getInstance();
int fillColor = 0;
int textColor = 0;
//todo mouse button
for (RenderableButton button : row.getButtons())
{
if (button.getKey().isPressed())
{
fillColor = 0x131314b3;
textColor = 16711680;
// DrawableHelper.fill(matrixStack, button.getX(), button.getY(), button.getX() + button.getWidth(), button.getY() + button.getHeight(), fillColor);
// client.textRenderer.draw(matrixStack, button.getKey().getBoundKeyLocalizedText().getString().toUpperCase(), BOX_SIZE / 2F + button.getX() - letterWidth / 2F, BOX_SIZE / 2F + button.getY() - client.textRenderer.fontHeight / 2F, textColor);
}
if (!button.getKey().isPressed())
{
fillColor = 0x131314b3;
textColor = 16777215;
}
int letterWidth = client.textRenderer.getWidth(button.getKey().getBoundKeyLocalizedText().getString().toUpperCase());
DrawableHelper.fill(matrixStack, button.getX(), button.getY(), button.getX() + button.getWidth(), button.getY() + button.getHeight(), fillColor);
client.textRenderer.draw(matrixStack, button.getKey().getBoundKeyLocalizedText().getString().toUpperCase(), BOX_SIZE / 2F + button.getX() - letterWidth / 2F, BOX_SIZE / 2F + button.getY() - client.textRenderer.fontHeight / 2F, textColor);
}
}
}
87 changes: 0 additions & 87 deletions src/main/java/com/spyxar/tiptapshow/RenderableButton.java

This file was deleted.

21 changes: 0 additions & 21 deletions src/main/java/com/spyxar/tiptapshow/Row.java

This file was deleted.

21 changes: 6 additions & 15 deletions src/main/java/com/spyxar/tiptapshow/TipTapShowMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

//ToDo: not ready for publish yet, change build.gradle, and fabric.mod and mixins.json and modid
public class TipTapShowMod implements ModInitializer
{
//features:
//a command to open the config(clothconfig)
// options: hud type, WASD or arrow pictures
// rainbow mode, when enabled it will wave over all colors
// text shadow (drawwithshadow)
// allow adding a custom key to be displayed as stroke aswell
// a setting that will sync the custom keys with the default color of the keys (wasd, space lmb, rmb)
// allow for moving of the display place
// set of settings to display certain things: movement keys, mouse keys, space, and cps(always, never, on click)
//ToDo features:
// A setting to render arrows instead of WASD (or the keybind walking is set to)
// Rainbow color mode for keys
// Allow for adding custom keys
// Moving the display place
// Settings to not display certain parts
public static final String MOD_ID = "tiptapshow";

public static TipTapShowMod instance = null;
Expand All @@ -28,13 +24,8 @@ public class TipTapShowMod implements ModInitializer
@Override
public void onInitialize()
{
// This code runs as soon as Minecraft is in a mod-load-ready state.
// However, some things (like resources) may still be uninitialized.
// Proceed with mild caution.

instance = this;
config = TipTapShowConfig.loadConfig();
System.out.println("Hello Fabric world!");
HudRenderCallback.EVENT.register(new KeystrokeOverlay());
}
}
Loading

0 comments on commit 5cc2af0

Please sign in to comment.