-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ea86f31
commit 6822259
Showing
3 changed files
with
148 additions
and
5 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
...n/java/com/tanishisherewith/dynamichud/newTrial/utils/contextmenu/options/EnumOption.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.tanishisherewith.dynamichud.newTrial.utils.contextmenu.options; | ||
|
||
import com.tanishisherewith.dynamichud.newTrial.utils.contextmenu.Option; | ||
import net.minecraft.client.gui.DrawContext; | ||
import net.minecraft.text.Text; | ||
|
||
import java.awt.Color; | ||
import java.util.function.Consumer; | ||
import java.util.function.Supplier; | ||
|
||
public class EnumOption<E extends Enum<E>> extends Option<E> { | ||
private final E[] values; | ||
private int currentIndex = 0; | ||
public String name = "Empty"; | ||
|
||
public EnumOption(String name, Supplier<E> getter, Consumer<E> setter, E[] values) { | ||
super(getter, setter); | ||
this.name = name; | ||
this.values = values; | ||
this.value = get(); | ||
for (int i = 0; i < values.length; i++) { | ||
if (values[i] == value) { | ||
currentIndex = i; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void render(DrawContext drawContext, int x, int y) { | ||
super.render(drawContext, x, y); | ||
|
||
value = get(); | ||
this.height = mc.textRenderer.fontHeight + 1; | ||
this.width = mc.textRenderer.getWidth(name + ": " + value.name()) + 1; | ||
|
||
int color = Color.WHITE.getRGB(); | ||
drawContext.drawText(mc.textRenderer, Text.of(name + ": " + value.name()), x, y, color, false); | ||
} | ||
|
||
@Override | ||
public boolean mouseClicked(double mouseX, double mouseY, int button) { | ||
super.mouseClicked(mouseX, mouseY, button); | ||
if (isMouseOver(mouseX, mouseY)) { | ||
if(button == 0) { | ||
currentIndex = (currentIndex + 1) % values.length; | ||
if(currentIndex > values.length - 1){ | ||
currentIndex = 0; | ||
} | ||
value = values[currentIndex]; | ||
}else if(button == 1){ | ||
currentIndex = (currentIndex - 1) % values.length; | ||
if(currentIndex < 0){ | ||
currentIndex = values.length - 1; | ||
} | ||
value = values[currentIndex]; | ||
} | ||
set(value); | ||
} | ||
return true; | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
...n/java/com/tanishisherewith/dynamichud/newTrial/utils/contextmenu/options/ListOption.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.tanishisherewith.dynamichud.newTrial.utils.contextmenu.options; | ||
|
||
import com.tanishisherewith.dynamichud.newTrial.utils.contextmenu.Option; | ||
import net.minecraft.client.gui.DrawContext; | ||
import net.minecraft.text.Text; | ||
|
||
import java.awt.*; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.function.Consumer; | ||
import java.util.function.Supplier; | ||
|
||
public class ListOption<T> extends Option<T> { | ||
private final List<T> values; | ||
private int currentIndex = 0; | ||
public String name = "Empty"; | ||
|
||
public ListOption(String name, Supplier<T> getter, Consumer<T> setter, List<T> values) { | ||
super(getter, setter); | ||
this.name = name; | ||
this.values = values; | ||
this.value = getter.get(); | ||
for (int i = 0; i < values.size(); i++) { | ||
if (values.get(i).toString().equals(value)) { | ||
currentIndex = i; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void render(DrawContext drawContext, int x, int y) { | ||
super.render(drawContext, x, y); | ||
|
||
value = get(); | ||
this.height = mc.textRenderer.fontHeight; | ||
this.width = mc.textRenderer.getWidth(name + ": " + value.toString()) + 1; | ||
|
||
int color = Color.WHITE.getRGB(); | ||
drawContext.drawText(mc.textRenderer, Text.of(name + ": " + value.toString()), x, y, color, false); | ||
} | ||
|
||
@Override | ||
public boolean mouseClicked(double mouseX, double mouseY, int button) { | ||
super.mouseClicked(mouseX, mouseY, button); | ||
if (isMouseOver(mouseX, mouseY)) { | ||
if(button == 0) { | ||
currentIndex = (currentIndex + 1) % values.size(); | ||
if(currentIndex > values.size() - 1){ | ||
currentIndex = 0; | ||
} | ||
value = values.get(currentIndex); | ||
}else if(button == 1){ | ||
currentIndex = (currentIndex - 1) % values.size(); | ||
if(currentIndex < 0){ | ||
currentIndex = values.size() - 1; | ||
} | ||
value = values.get(currentIndex); | ||
} | ||
set(value); | ||
} | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters