Skip to content

Commit

Permalink
Merge pull request #247 from KosmX/selection_wheel
Browse files Browse the repository at this point in the history
New selection wheel!
Thank you @DearFox
  • Loading branch information
KosmX authored Jun 3, 2022
2 parents 74fed0f + 1aac843 commit d1690cb
Show file tree
Hide file tree
Showing 12 changed files with 497 additions and 196 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins{
id 'java'
id 'dev.architectury.loom' version '0.11.0-SNAPSHOT' apply false //Forge loom :D
id 'dev.architectury.loom' version '0.12.0-SNAPSHOT' apply false //Forge loom :D
id "architectury-plugin" version "3.4-SNAPSHOT" apply false
id "com.github.johnrengelman.shadow" version "7.1.2" apply false
//id "com.dorongold.task-tree" version "1.5" Current version doesn't support gradle 6.8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
public class ClientConfig extends SerializableConfig {

public final BooleanConfigEntry dark = new BooleanConfigEntry("dark", false, false, basics);

public final BooleanConfigEntry oldChooseWheel = new BooleanConfigEntry("oldChooseWheel", false, false, basics);
public final ConfigEntry<Boolean> enablePerspective = new BooleanConfigEntry("perspective", true, false, basics);
public final BooleanConfigEntry frontAsTPPerspective = new BooleanConfigEntry("default3rdPersonFront", false, false, basics);
public final ConfigEntry<Boolean> showIcons = new BooleanConfigEntry("showicon", "showIcon", true, true, basics);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import io.github.kosmx.emotes.executor.dataTypes.screen.widgets.IButton;
import io.github.kosmx.emotes.executor.dataTypes.screen.IConfirmScreen;
import io.github.kosmx.emotes.main.config.ClientSerializer;
import io.github.kosmx.emotes.main.screen.widget.IChooseWheel;
import io.github.kosmx.emotes.main.screen.widget.IEmoteListWidgetHelper;
import io.github.kosmx.emotes.main.screen.widget.AbstractFastChooseWidget;
import io.github.kosmx.emotes.server.serializer.UniversalEmoteSerializer;
Expand Down Expand Up @@ -367,7 +368,7 @@ protected boolean isValidClickButton(int button){
}

@Override
protected boolean EmotesOnClick(FastChooseElement element, int button){
protected boolean EmotesOnClick(IChooseWheel.IChooseElement element, int button){
if(activeKeyTime != 0) return false;
if(button == 1){
element.clearEmote();
Expand All @@ -383,7 +384,7 @@ protected boolean EmotesOnClick(FastChooseElement element, int button){
}

@Override
protected boolean doHoverPart(FastChooseElement part){
protected boolean doHoverPart(IChooseWheel.IChooseElement part){
return activeKeyTime == 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import io.github.kosmx.emotes.main.screen.AbstractScreenLogic;
import io.github.kosmx.emotes.main.screen.IScreenSlave;
import io.github.kosmx.emotes.main.screen.widget.AbstractFastChooseWidget;
import io.github.kosmx.emotes.main.screen.widget.IChooseWheel;
import io.github.kosmx.emotes.main.screen.widget.ModernChooseWheel;

/**
* Stuff to override
Expand Down Expand Up @@ -63,7 +65,7 @@ public FastMenuWidget(int x, int y, int size){
}

@Override
protected boolean doHoverPart(FastChooseElement part){
protected boolean doHoverPart(IChooseWheel.IChooseElement part){
return part.hasEmote();
}

Expand All @@ -73,7 +75,7 @@ protected boolean isValidClickButton(int button){
}

@Override
protected boolean EmotesOnClick(FastChooseElement element, int button){
protected boolean EmotesOnClick(IChooseWheel.IChooseElement element, int button){
if(element.getEmote() != null){
boolean bl = element.getEmote().playEmote(EmoteInstance.instance.getClientMethods().getMainPlayer());
screen.openScreen(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,222 +2,58 @@

import io.github.kosmx.emotes.common.tools.MathHelper;
import io.github.kosmx.emotes.executor.EmoteInstance;
import io.github.kosmx.emotes.executor.dataTypes.IIdentifier;
import io.github.kosmx.emotes.executor.dataTypes.Text;
import io.github.kosmx.emotes.main.EmoteHolder;
import io.github.kosmx.emotes.main.config.ClientConfig;

import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.UUID;
import java.util.logging.Level;

/**
* Stuff fo override
* void render(MATRIX, int mouseX, int mouseY, float delta)
* boolean onMouseClicked
* void isMouseHover
* @param <MATRIX> Minecraft's MatrixStack
*/
public abstract class AbstractFastChooseWidget<MATRIX, WIDGET> implements IWidgetLogic<MATRIX, WIDGET> {
private IChooseWheel<MATRIX> wheel;


public int x;
public int y;
protected int size;
//protected final FastChooseElement[] elements = new FastChooseElement[8];
protected final ArrayList<FastChooseElement> elements = new ArrayList<>();
private boolean hovered;
private final IIdentifier TEXTURE = ((ClientConfig) EmoteInstance.config).dark.get() ? EmoteInstance.instance.getDefaults().newIdentifier("textures/gui/fastchoose_dark.png") : EmoteInstance.instance.getDefaults().newIdentifier("textures/gui/fastchoose_light.png");

private AbstractFastChooseWidget(){
elements.add( new FastChooseElement(0, 22.5f));
elements.add( new FastChooseElement(1, 67.5f));
elements.add( new FastChooseElement(2, 157.5f));
elements.add( new FastChooseElement(3, 112.5f));
elements.add( new FastChooseElement(4, 337.5f));
elements.add( new FastChooseElement(5, 292.5f));
elements.add( new FastChooseElement(6, 202.5f));
elements.add( new FastChooseElement(7, 247.5f));
}
public final int x;
public final int y;
public final int size;


public AbstractFastChooseWidget(int x, int y, int size){
this();
protected AbstractFastChooseWidget(int x, int y, int size) {
this.x = x;
this.y = y;
this.size = size; //It's a square with same width and height
this.size = size;
this.wheel = IChooseWheel.getWheel(this);
}

public void drawCenteredText(MATRIX matrixStack, Text stringRenderable, float deg){
drawCenteredText(matrixStack, stringRenderable, (float) (((float) (this.x + this.size / 2)) + size * 0.4 * Math.sin(deg * 0.0174533)), (float) (((float) (this.y + this.size / 2)) + size * 0.4 * Math.cos(deg * 0.0174533)));
protected void bind(IChooseWheel<MATRIX> wheel) {
this.wheel = wheel;
}

public void drawCenteredText(MATRIX matrices, Text stringRenderable, float x, float y){
int c = ((ClientConfig)EmoteInstance.config).dark.get() ? 255 : 0; //:D
textDraw(matrices, stringRenderable, x - (float) textRendererGetWidth(stringRenderable) / 2, y - 2, MathHelper.colorHelper(c, c, c, 1));
}

@Nullable
protected FastChooseElement getActivePart(int mouseX, int mouseY){
int x = mouseX - this.x - this.size / 2;
int y = mouseY - this.y - this.size / 2;
int i = 0;
if(x == 0){
return null;
}else if(x < 0){
i += 4;
}

if(y == 0){
return null;
}else if(y < 0){
i += 2;
}

if(Math.abs(x) == Math.abs(y)){
return null;
}else if(Math.abs(x) > Math.abs(y)){
i++;
}
return elements.get(i);
public void render(MATRIX matrices, int mouseX, int mouseY, float delta) {
this.wheel.render(matrices, mouseX, mouseY, delta);
}

public void render(MATRIX matrices, int mouseX, int mouseY, float delta){
checkHovered(mouseX, mouseY);
renderBindTexture(TEXTURE);
renderSystemBlendColor(1, 1, 1, 1);
renderEnableBend();
renderDefaultBendFunction();
renderEnableDepthText();
this.drawTexture(matrices, 0, 0, 0, 0, 2);
if(this.hovered){
FastChooseElement part = getActivePart(mouseX, mouseY);
if(part != null && doHoverPart(part)){
part.renderHover(matrices);
}
}
for(FastChooseElement f : elements){
if(f.hasEmote()) f.render(matrices);
}
}

protected abstract boolean doHoverPart(FastChooseElement part);

/**
* @param matrices MatrixStack ...
* @param x Render x from this pixel
* @param y same
* @param u texture x
* @param v texture y
* @param s used texture part size !NOT THE WHOLE TEXTURE IMAGE SIZE!
*/
private void drawTexture(MATRIX matrices, int x, int y, int u, int v, int s){
drawableDrawTexture(matrices, this.x + x * this.size / 256, this.y + y * this.size / 256, s * this.size / 2, s * this.size / 2, u, v, s * 128, s * 128, 512, 512);
}

private void checkHovered(int mouseX, int mouseY){
this.hovered = mouseX >= this.x && mouseY >= this.y && mouseX <= this.x + this.size && mouseY <= this.y + this.size;
public void drawCenteredText(MATRIX matrixStack, Text stringRenderable, float deg){
drawCenteredText(matrixStack, stringRenderable, (float) (((float) (this.x + this.size / 2)) + size * 0.4 * Math.sin(deg * 0.0174533)), (float) (((float) (this.y + this.size / 2)) + size * 0.4 * Math.cos(deg * 0.0174533)));
}

public boolean emotes_mouseClicked(double mouseX, double mouseY, int button){
checkHovered((int) mouseX, (int) mouseY);
if(this.hovered && this.isValidClickButton(button)){
FastChooseElement element = this.getActivePart((int) mouseX, (int) mouseY);
if(element != null){
return EmotesOnClick(element, button);
}
}
return false;
public void drawCenteredText(MATRIX matrices, Text stringRenderable, float x, float y){
int c = ((ClientConfig) EmoteInstance.config).dark.get() ? 255 : 0; //:D
textDraw(matrices, stringRenderable, x - (float) textRendererGetWidth(stringRenderable) / 2, y - 2, MathHelper.colorHelper(c, c, c, 1));
}


public boolean isMouseOver(double mouseX, double mouseY){
this.checkHovered((int) mouseX, (int) mouseY);
return this.hovered;
}
protected abstract boolean doHoverPart(IChooseWheel.IChooseElement part);

protected abstract boolean isValidClickButton(int button);

protected abstract boolean EmotesOnClick(FastChooseElement element, int button); //What DO I want to do with this element? set or play.
protected abstract boolean EmotesOnClick(IChooseWheel.IChooseElement element, int button); //What DO I want to do with this element? set or play.

protected abstract boolean doesShowInvalid();

protected class FastChooseElement {
private final float angle;
private final int id;

@Nullable

protected FastChooseElement(int num, float angle){
this.angle = angle;
this.id = num;
}

public boolean hasEmote(){
return ((ClientConfig)EmoteInstance.config).fastMenuEmotes[id] != null;
}

public void setEmote(@Nullable EmoteHolder emote){
((ClientConfig)EmoteInstance.config).fastMenuEmotes[id] = emote == null ? null : emote.getUuid();
}

@Nullable
public EmoteHolder getEmote(){
UUID uuid = ((ClientConfig)EmoteInstance.config).fastMenuEmotes[id];
if(uuid != null){
EmoteHolder emote = EmoteHolder.list.get(uuid);
if(emote == null && doesShowInvalid()){
emote = new EmoteHolder.Empty(uuid);
}
return emote;
}
else {
return null;
}
}

public void clearEmote(){
this.setEmote(null);
}

public void render(MATRIX matrices){
UUID emoteID = ((ClientConfig)EmoteInstance.config).fastMenuEmotes[id] != null ? ((ClientConfig)EmoteInstance.config).fastMenuEmotes[id] : null;
IIdentifier identifier = emoteID != null && EmoteHolder.list.get(emoteID) != null ? EmoteHolder.list.get(emoteID).getIconIdentifier() : null;
if(identifier != null && ((ClientConfig)EmoteInstance.config).showIcons.get()){
int s = size / 10;
int iconX = (int) (((float) (x + size / 2)) + size * 0.4 * Math.sin(this.angle * 0.0174533)) - s;
int iconY = (int) (((float) (y + size / 2)) + size * 0.4 * Math.cos(this.angle * 0.0174533)) - s;
renderBindTexture(identifier);
drawableDrawTexture(matrices, iconX, iconY, s * 2, s * 2, 0, 0, 256, 256, 256, 256);
}else{
if(((ClientConfig)EmoteInstance.config).fastMenuEmotes[id] != null){
drawCenteredText(matrices, EmoteHolder.getNonNull(((ClientConfig)EmoteInstance.config).fastMenuEmotes[id]).name, this.angle);
}else{
EmoteInstance.instance.getLogger().log(Level.WARNING, "Tried to render non-existing name", true);
}
}
}

public void renderHover(MATRIX matrices){
int textX = 0;
int textY = 0;
int x = 0;
int y = 0;

if((id & 1) == 0){
textY = 256;
}else{
textX = 256;
}

if((id & 2) == 0){
y = 128;
}

if((id & 4) == 0){
x = 128;
}
drawTexture(matrices, x, y, textX + x, textY + y, 1);
}
public boolean emotes_mouseClicked(double mouseX, double mouseY, int button) {
return this.wheel.mouseClicked(mouseX, mouseY, button);
}

public boolean isMouseOver(double mouseX, double mouseY) {
return this.wheel.isMouseOver(mouseX, mouseY);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package io.github.kosmx.emotes.main.screen.widget;

import io.github.kosmx.emotes.executor.EmoteInstance;
import io.github.kosmx.emotes.main.EmoteHolder;
import io.github.kosmx.emotes.main.config.ClientConfig;

public interface IChooseWheel<MATRIX> {


void render(MATRIX matrices, int mouseX, int mouseY, float delta);

boolean mouseClicked(double mouseX, double mouseY, int button);

boolean isMouseOver(double mouseX, double mouseY);

interface IChooseElement {

boolean hasEmote();

EmoteHolder getEmote();

void clearEmote();

void setEmote(EmoteHolder emote);
}

static <MATRIX, WIDGET> IChooseWheel<MATRIX> getWheel(AbstractFastChooseWidget<MATRIX, WIDGET> widget) {
if (((ClientConfig) EmoteInstance.config).oldChooseWheel.get()) {
return new LegacyChooseWidget<>(widget);
} else {
return new ModernChooseWheel<>(widget);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import io.github.kosmx.emotes.main.screen.IRenderHelper;

public interface IWidgetLogic<MATRIX, WIDGET> extends IRenderHelper<MATRIX>, IWidget<WIDGET> {
default public boolean emotes_mouseClicked(double mouseX, double mouseY, int button){
default boolean emotes_mouseClicked(double mouseX, double mouseY, int button) {
return false;
};
}
}
Loading

0 comments on commit d1690cb

Please sign in to comment.