-
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.
SubMenuOption, some changes and javadocs
- Loading branch information
1 parent
3ed5a37
commit 9ac1100
Showing
8 changed files
with
111 additions
and
13 deletions.
There are no files selected for viewing
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
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
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
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
77 changes: 77 additions & 0 deletions
77
...ava/com/tanishisherewith/dynamichud/newTrial/utils/contextmenu/options/SubMenuOption.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,77 @@ | ||
package com.tanishisherewith.dynamichud.newTrial.utils.contextmenu.options; | ||
|
||
import com.tanishisherewith.dynamichud.newTrial.utils.contextmenu.ContextMenu; | ||
import com.tanishisherewith.dynamichud.newTrial.utils.contextmenu.Option; | ||
import net.minecraft.client.gui.DrawContext; | ||
import net.minecraft.text.Text; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.awt.*; | ||
import java.util.Objects; | ||
import java.util.function.Consumer; | ||
import java.util.function.Supplier; | ||
|
||
/** | ||
* 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. | ||
* <p> | ||
* 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; | ||
private final ContextMenu parentMenu; | ||
public String name = "Empty"; | ||
|
||
|
||
public SubMenuOption(String name, @NotNull ContextMenu parentMenu, Supplier<Boolean> getter, Consumer<Boolean> setter) { | ||
super(getter, setter); | ||
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.heightOffset = 0; | ||
this.subMenu.shouldDisplay = get(); | ||
} | ||
|
||
@Override | ||
public void render(DrawContext drawContext, int x, int y) { | ||
super.render(drawContext, x, y); | ||
|
||
int color = value ? Color.GREEN.getRGB() : Color.RED.getRGB(); | ||
drawContext.drawText(mc.textRenderer, Text.of(name), x, y, color, false); | ||
|
||
subMenu.render(drawContext, this.x + parentMenu.width, this.y, 0); | ||
} | ||
|
||
@Override | ||
public boolean mouseClicked(double mouseX, double mouseY, int button) { | ||
if (super.mouseClicked(mouseX, mouseY, button)) { | ||
subMenu.toggleDisplay(); | ||
set(subMenu.shouldDisplay); | ||
return true; | ||
} | ||
subMenu.mouseClicked(mouseX, mouseY, button); | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean mouseReleased(double mouseX, double mouseY, int button) { | ||
subMenu.mouseReleased(mouseX, mouseY, button); | ||
return super.mouseReleased(mouseX, mouseY, button); | ||
} | ||
|
||
@Override | ||
public boolean mouseDragged(double mouseX, double mouseY, int button) { | ||
subMenu.mouseDragged(mouseX, mouseY, button); | ||
return super.mouseDragged(mouseX, mouseY, button); | ||
} | ||
|
||
public SubMenuOption getOption(){ | ||
return this; | ||
} | ||
|
||
public ContextMenu getSubMenu() { | ||
return subMenu; | ||
} | ||
} |
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
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
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