mirror of
https://github.com/xiaozhou233/OrangeX-Client.git
synced 2026-12-05 13:05:52 +08:00
WIP: ClickGUI
This commit is contained in:
1 parent
30760373e7
commit
5bf074444e
13 files changed
+1205
-5
No files matched your search
@@ -3,12 +3,14 @@ package cn.xiaozhou233.orangex.module.option;
|
||||
import cn.xiaozhou233.orangex.module.Module;
|
||||
import com.google.gson.JsonElement;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
public abstract class Option<T> {
|
||||
protected final String name;
|
||||
protected final String description;
|
||||
protected final Module parent;
|
||||
@Setter
|
||||
protected T value;
|
||||
protected final T defaultValue;
|
||||
|
||||
@@ -20,10 +22,6 @@ public abstract class Option<T> {
|
||||
this.value = defaultValue;
|
||||
}
|
||||
|
||||
public void setValue(T value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
this.value = defaultValue;
|
||||
}
|
||||
|
||||
@@ -55,4 +55,29 @@ public class ModeOption extends Option<String> {
|
||||
public void deserialize(JsonElement element) {
|
||||
setValue(element.getAsString());
|
||||
}
|
||||
|
||||
public void next() {
|
||||
|
||||
int index = getIndex();
|
||||
|
||||
index++;
|
||||
|
||||
if(index >= modes.length)
|
||||
index = 0;
|
||||
|
||||
setValue(modes[index]);
|
||||
}
|
||||
|
||||
|
||||
public void previous() {
|
||||
|
||||
int index = getIndex();
|
||||
|
||||
index--;
|
||||
|
||||
if(index < 0)
|
||||
index = modes.length - 1;
|
||||
|
||||
setValue(modes[index]);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,181 @@
|
||||
package cn.xiaozhou233.orangex.ui.clickgui;
|
||||
|
||||
import cn.xiaozhou233.orangex.module.Module;
|
||||
import cn.xiaozhou233.orangex.module.ModuleCategory;
|
||||
import cn.xiaozhou233.orangex.OrangeX;
|
||||
import cn.xiaozhou233.orangex.ui.clickgui.component.impl.ModuleButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ClickGUIScreen extends GuiScreen {
|
||||
}
|
||||
|
||||
private final List<Panel> panels = new ArrayList<>();
|
||||
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
|
||||
panels.clear();
|
||||
|
||||
|
||||
int x = 20;
|
||||
|
||||
|
||||
for(ModuleCategory category : ModuleCategory.values()) {
|
||||
|
||||
Panel panel = new Panel(
|
||||
category,
|
||||
x,
|
||||
30,
|
||||
120,
|
||||
20
|
||||
);
|
||||
|
||||
|
||||
int y = 20;
|
||||
|
||||
|
||||
for(Module module :
|
||||
OrangeX.getInstance()
|
||||
.getModuleManager()
|
||||
.getModules()) {
|
||||
|
||||
|
||||
if(module.getCategory() != category)
|
||||
continue;
|
||||
|
||||
|
||||
panel.addComponent(
|
||||
new ModuleButton(
|
||||
panel,
|
||||
module,
|
||||
0,
|
||||
y
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
y += 20;
|
||||
}
|
||||
|
||||
|
||||
panels.add(panel);
|
||||
|
||||
x += 140;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void drawScreen(
|
||||
int mouseX,
|
||||
int mouseY,
|
||||
float partialTicks
|
||||
) {
|
||||
|
||||
|
||||
for(Panel panel : panels) {
|
||||
|
||||
panel.drawScreen(
|
||||
mouseX,
|
||||
mouseY,
|
||||
partialTicks
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
super.drawScreen(
|
||||
mouseX,
|
||||
mouseY,
|
||||
partialTicks
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(
|
||||
int mouseX,
|
||||
int mouseY,
|
||||
int mouseButton
|
||||
) throws java.io.IOException {
|
||||
|
||||
|
||||
for(Panel panel : panels) {
|
||||
|
||||
panel.mouseClicked(
|
||||
mouseX,
|
||||
mouseY,
|
||||
mouseButton
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
super.mouseClicked(
|
||||
mouseX,
|
||||
mouseY,
|
||||
mouseButton
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void mouseReleased(
|
||||
int mouseX,
|
||||
int mouseY,
|
||||
int mouseButton
|
||||
) {
|
||||
|
||||
|
||||
for(Panel panel : panels) {
|
||||
|
||||
panel.mouseReleased(
|
||||
mouseX,
|
||||
mouseY,
|
||||
mouseButton
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
super.mouseReleased(
|
||||
mouseX,
|
||||
mouseY,
|
||||
mouseButton
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void keyTyped(
|
||||
char typedChar,
|
||||
int keyCode
|
||||
) throws java.io.IOException {
|
||||
|
||||
|
||||
for(Panel panel : panels) {
|
||||
|
||||
panel.keyTyped(
|
||||
typedChar,
|
||||
keyCode
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
if(keyCode == 1) {
|
||||
mc.displayGuiScreen(null);
|
||||
}
|
||||
|
||||
|
||||
super.keyTyped(
|
||||
typedChar,
|
||||
keyCode
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean doesGuiPauseGame() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
package cn.xiaozhou233.orangex.ui.clickgui;
|
||||
|
||||
import cn.xiaozhou233.orangex.module.ModuleCategory;
|
||||
import cn.xiaozhou233.orangex.ui.clickgui.component.Component;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
public class Panel {
|
||||
|
||||
private final ModuleCategory category;
|
||||
|
||||
private int x;
|
||||
private int y;
|
||||
|
||||
private final int width;
|
||||
private final int height;
|
||||
|
||||
private final int headerHeight = 20;
|
||||
|
||||
private boolean open = true;
|
||||
|
||||
private boolean dragging;
|
||||
|
||||
private int dragX;
|
||||
private int dragY;
|
||||
|
||||
private final List<Component> components = new ArrayList<>();
|
||||
|
||||
|
||||
public Panel(ModuleCategory category,int x,int y,int width,int height) {
|
||||
this.category = category;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
|
||||
public void drawScreen(int mouseX,int mouseY,float partialTicks) {
|
||||
|
||||
if (dragging) {
|
||||
x = mouseX - dragX;
|
||||
y = mouseY - dragY;
|
||||
}
|
||||
|
||||
|
||||
drawBackground();
|
||||
|
||||
|
||||
if (!open)
|
||||
return;
|
||||
|
||||
|
||||
for (Component component : components) {
|
||||
component.drawScreen(mouseX,mouseY,partialTicks);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void drawBackground() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void mouseClicked(int mouseX,int mouseY,int mouseButton) {
|
||||
|
||||
if (isHovered(mouseX,mouseY)) {
|
||||
|
||||
if (mouseButton == 0) {
|
||||
|
||||
dragging = true;
|
||||
|
||||
dragX = mouseX - x;
|
||||
dragY = mouseY - y;
|
||||
}
|
||||
|
||||
if (mouseButton == 1) {
|
||||
open = !open;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!open)
|
||||
return;
|
||||
|
||||
|
||||
for (Component component : components) {
|
||||
component.mouseClicked(mouseX,mouseY,mouseButton);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void mouseReleased(int mouseX,int mouseY,int mouseButton) {
|
||||
|
||||
if (mouseButton == 0)
|
||||
dragging = false;
|
||||
|
||||
|
||||
for (Component component : components) {
|
||||
component.mouseReleased(mouseX,mouseY,mouseButton);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void keyTyped(char typedChar,int keyCode) {
|
||||
|
||||
for (Component component : components) {
|
||||
component.keyTyped(typedChar,keyCode);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private boolean isHovered(int mouseX,int mouseY) {
|
||||
|
||||
return mouseX >= x &&
|
||||
mouseX <= x + width &&
|
||||
mouseY >= y &&
|
||||
mouseY <= y + headerHeight;
|
||||
}
|
||||
|
||||
|
||||
public void addComponent(Component component) {
|
||||
components.add(component);
|
||||
|
||||
updateLayout();
|
||||
}
|
||||
|
||||
public void updateLayout() {
|
||||
|
||||
int offset = headerHeight;
|
||||
|
||||
|
||||
for(Component component : components) {
|
||||
|
||||
component.setOffsetY(offset);
|
||||
|
||||
offset += component.getHeight();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
package cn.xiaozhou233.orangex.ui.clickgui.component;
|
||||
|
||||
import cn.xiaozhou233.orangex.OrangeX;
|
||||
import cn.xiaozhou233.orangex.ui.clickgui.Panel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
public abstract class Component {
|
||||
|
||||
protected final Panel parent;
|
||||
|
||||
protected final int offsetX;
|
||||
@Setter
|
||||
protected int offsetY;
|
||||
|
||||
protected final int width;
|
||||
protected int height;
|
||||
|
||||
|
||||
public Component(
|
||||
Panel parent,
|
||||
int offsetX,
|
||||
int offsetY,
|
||||
int width,
|
||||
int height
|
||||
) {
|
||||
this.parent = parent;
|
||||
this.offsetX = offsetX;
|
||||
this.offsetY = offsetY;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
|
||||
public abstract void drawScreen(
|
||||
int mouseX,
|
||||
int mouseY,
|
||||
float partialTicks
|
||||
);
|
||||
|
||||
|
||||
public void mouseClicked(
|
||||
int mouseX,
|
||||
int mouseY,
|
||||
int mouseButton
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void mouseReleased(
|
||||
int mouseX,
|
||||
int mouseY,
|
||||
int mouseButton
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void keyTyped(
|
||||
char typedChar,
|
||||
int keyCode
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public int getX() {
|
||||
return parent.getX() + offsetX;
|
||||
}
|
||||
|
||||
|
||||
public int getY() {
|
||||
return parent.getY() + offsetY;
|
||||
}
|
||||
|
||||
|
||||
protected boolean isHovered(
|
||||
int mouseX,
|
||||
int mouseY
|
||||
) {
|
||||
|
||||
return mouseX >= getX()
|
||||
&& mouseX <= getX() + width
|
||||
&& mouseY >= getY()
|
||||
&& mouseY <= getY() + height;
|
||||
}
|
||||
|
||||
|
||||
protected void drawString(
|
||||
String text,
|
||||
int x,
|
||||
int y,
|
||||
int color
|
||||
) {
|
||||
|
||||
OrangeX.getInstance()
|
||||
.getStbFontManager()
|
||||
.getProxima(18)
|
||||
.drawString(
|
||||
text,
|
||||
x,
|
||||
y,
|
||||
color
|
||||
);
|
||||
}
|
||||
}
|
||||
+154
@@ -0,0 +1,154 @@
|
||||
package cn.xiaozhou233.orangex.ui.clickgui.component.impl;
|
||||
|
||||
import cn.xiaozhou233.orangex.module.Module;
|
||||
import cn.xiaozhou233.orangex.module.option.Option;
|
||||
import cn.xiaozhou233.orangex.ui.clickgui.Panel;
|
||||
import cn.xiaozhou233.orangex.ui.clickgui.component.Component;
|
||||
import cn.xiaozhou233.orangex.ui.clickgui.component.option.OptionComponent;
|
||||
import cn.xiaozhou233.orangex.ui.clickgui.component.option.OptionComponentFactory;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ModuleButton extends Component {
|
||||
|
||||
private final Module module;
|
||||
|
||||
@Getter
|
||||
private boolean expanded;
|
||||
@Getter
|
||||
private final List<OptionComponent> options = new ArrayList<>();
|
||||
|
||||
public ModuleButton(Panel parent,Module module,int offsetX,int offsetY) {
|
||||
super(parent,offsetX,offsetY,120,20);
|
||||
|
||||
this.module = module;
|
||||
|
||||
int optionY = 20;
|
||||
|
||||
for (Option<?> option : module.getOptions()) {
|
||||
|
||||
OptionComponent component =
|
||||
OptionComponentFactory.create(
|
||||
parent,
|
||||
option,
|
||||
offsetX,
|
||||
offsetY + optionY
|
||||
);
|
||||
|
||||
if(component != null)
|
||||
options.add(component);
|
||||
|
||||
optionY += 18;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX,int mouseY,float partialTicks) {
|
||||
|
||||
int color = module.isEnabled()
|
||||
? 0xff55ffff
|
||||
: 0xffffffff;
|
||||
|
||||
drawString(
|
||||
module.getName(),
|
||||
getX() + 5,
|
||||
getY() + 5,
|
||||
color
|
||||
);
|
||||
|
||||
|
||||
if(expanded) {
|
||||
for(OptionComponent option : options) {
|
||||
option.drawScreen(mouseX,mouseY,partialTicks);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void drawOptions(int mouseX,int mouseY,float partialTicks) {
|
||||
|
||||
for(OptionComponent option : options) {
|
||||
option.drawScreen(mouseX,mouseY,partialTicks);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int mouseX,int mouseY,int mouseButton) {
|
||||
|
||||
if(isHovered(mouseX,mouseY)) {
|
||||
|
||||
if(mouseButton == 0)
|
||||
module.toggle();
|
||||
|
||||
if(mouseButton == 1) {
|
||||
|
||||
expanded = !expanded;
|
||||
|
||||
parent.updateLayout();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(expanded) {
|
||||
for(OptionComponent option : options) {
|
||||
option.mouseClicked(mouseX,mouseY,mouseButton);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void mouseClickedOptions(int mouseX,int mouseY,int mouseButton) {
|
||||
|
||||
for(OptionComponent option : options) {
|
||||
option.mouseClicked(mouseX,mouseY,mouseButton);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void mouseReleased(int mouseX, int mouseY, int mouseButton) {
|
||||
|
||||
if (expanded) {
|
||||
mouseReleasedOptions(mouseX,mouseY,mouseButton);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void mouseReleasedOptions(int mouseX,int mouseY,int mouseButton) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void keyTyped(char typedChar, int keyCode) {
|
||||
|
||||
if (expanded) {
|
||||
keyTypedOptions(typedChar,keyCode);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void keyTypedOptions(char typedChar,int keyCode) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected void drawString(String text,int x,int y,int color) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
|
||||
if(!expanded)
|
||||
return 20;
|
||||
|
||||
|
||||
return 20 + options.size() * 18;
|
||||
}
|
||||
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
package cn.xiaozhou233.orangex.ui.clickgui.component.option;
|
||||
|
||||
import cn.xiaozhou233.orangex.module.option.impl.BooleanOption;
|
||||
import cn.xiaozhou233.orangex.ui.clickgui.Panel;
|
||||
|
||||
public class BooleanComponent extends OptionComponent{
|
||||
|
||||
private final BooleanOption option;
|
||||
|
||||
|
||||
public BooleanComponent(
|
||||
Panel parent,
|
||||
BooleanOption option,
|
||||
int offsetX,
|
||||
int offsetY
|
||||
) {
|
||||
super(parent,option,offsetX,offsetY,120,18);
|
||||
this.option = option;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX,int mouseY,float partialTicks) {
|
||||
|
||||
drawString(
|
||||
option.getName(),
|
||||
getX() + 5,
|
||||
getY() + 5,
|
||||
0xffffffff
|
||||
);
|
||||
|
||||
|
||||
drawString(
|
||||
option.getValue() ? "ON" : "OFF",
|
||||
getX() + width - 25,
|
||||
getY() + 5,
|
||||
option.getValue()
|
||||
? 0xff55ffff
|
||||
: 0xffffffff
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int mouseX,int mouseY,int mouseButton) {
|
||||
|
||||
if (!isHovered(mouseX,mouseY))
|
||||
return;
|
||||
|
||||
|
||||
if (mouseButton == 0) {
|
||||
option.setValue(!option.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
package cn.xiaozhou233.orangex.ui.clickgui.component.option;
|
||||
|
||||
import cn.xiaozhou233.orangex.module.option.impl.ColorOption;
|
||||
import cn.xiaozhou233.orangex.ui.clickgui.Panel;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class ColorComponent extends OptionComponent {
|
||||
|
||||
private final ColorOption option;
|
||||
|
||||
|
||||
public ColorComponent(
|
||||
Panel parent,
|
||||
ColorOption option,
|
||||
int offsetX,
|
||||
int offsetY
|
||||
) {
|
||||
super(parent,option,offsetX,offsetY,120,18);
|
||||
this.option = option;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX,int mouseY,float partialTicks) {
|
||||
|
||||
drawString(
|
||||
option.getName(),
|
||||
getX() + 5,
|
||||
getY() + 5,
|
||||
0xffffffff
|
||||
);
|
||||
|
||||
|
||||
drawRect(
|
||||
getX() + width - 25,
|
||||
getY() + 3,
|
||||
getX() + width - 5,
|
||||
getY() + 15,
|
||||
option.getValue()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int mouseX,int mouseY,int mouseButton) {
|
||||
|
||||
if(!isHovered(mouseX,mouseY))
|
||||
return;
|
||||
|
||||
|
||||
if(mouseButton == 0) {
|
||||
|
||||
option.setValue(
|
||||
getNextColor()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private int getNextColor() {
|
||||
|
||||
int color = option.getValue();
|
||||
|
||||
float[] hsb =
|
||||
Color.RGBtoHSB(
|
||||
(color >> 16) & 255,
|
||||
(color >> 8) & 255,
|
||||
color & 255,
|
||||
null
|
||||
);
|
||||
|
||||
|
||||
hsb[0] += 0.1f;
|
||||
|
||||
|
||||
if(hsb[0] > 1)
|
||||
hsb[0] = 0;
|
||||
|
||||
|
||||
return Color.HSBtoRGB(
|
||||
hsb[0],
|
||||
hsb[1],
|
||||
hsb[2]
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
package cn.xiaozhou233.orangex.ui.clickgui.component.option;
|
||||
|
||||
import cn.xiaozhou233.orangex.module.option.impl.ModeOption;
|
||||
import cn.xiaozhou233.orangex.ui.clickgui.Panel;
|
||||
|
||||
public class ModeComponent extends OptionComponent {
|
||||
|
||||
private final ModeOption option;
|
||||
|
||||
|
||||
public ModeComponent(
|
||||
Panel parent,
|
||||
ModeOption option,
|
||||
int offsetX,
|
||||
int offsetY
|
||||
) {
|
||||
super(parent,option,offsetX,offsetY,120,18);
|
||||
this.option = option;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX,int mouseY,float partialTicks) {
|
||||
|
||||
drawString(
|
||||
option.getName(),
|
||||
getX() + 5,
|
||||
getY() + 5,
|
||||
0xffffffff
|
||||
);
|
||||
|
||||
|
||||
drawString(
|
||||
option.getValue(),
|
||||
getX() + width - 45,
|
||||
getY() + 5,
|
||||
0xff55ffff
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int mouseX,int mouseY,int mouseButton) {
|
||||
|
||||
if (!isHovered(mouseX,mouseY))
|
||||
return;
|
||||
|
||||
|
||||
if(mouseButton == 0) {
|
||||
|
||||
option.next();
|
||||
}
|
||||
|
||||
|
||||
if(mouseButton == 1) {
|
||||
|
||||
option.previous();
|
||||
}
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package cn.xiaozhou233.orangex.ui.clickgui.component.option;
|
||||
|
||||
import cn.xiaozhou233.orangex.module.option.Option;
|
||||
import cn.xiaozhou233.orangex.ui.clickgui.Panel;
|
||||
import cn.xiaozhou233.orangex.ui.clickgui.component.Component;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public abstract class OptionComponent extends Component {
|
||||
|
||||
protected final Option<?> option;
|
||||
|
||||
|
||||
public OptionComponent(
|
||||
Panel parent,
|
||||
Option<?> option,
|
||||
int offsetX,
|
||||
int offsetY,
|
||||
int width,
|
||||
int height
|
||||
) {
|
||||
super(parent,offsetX,offsetY,width,height);
|
||||
this.option = option;
|
||||
}
|
||||
|
||||
protected void drawRect(
|
||||
int left,
|
||||
int top,
|
||||
int right,
|
||||
int bottom,
|
||||
int color
|
||||
) {
|
||||
|
||||
net.minecraft.client.gui.Gui.drawRect(
|
||||
left,
|
||||
top,
|
||||
right,
|
||||
bottom,
|
||||
color
|
||||
);
|
||||
}
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
package cn.xiaozhou233.orangex.ui.clickgui.component.option;
|
||||
|
||||
import cn.xiaozhou233.orangex.module.option.Option;
|
||||
import cn.xiaozhou233.orangex.module.option.impl.*;
|
||||
import cn.xiaozhou233.orangex.ui.clickgui.Panel;
|
||||
|
||||
public class OptionComponentFactory {
|
||||
|
||||
public static OptionComponent create(
|
||||
Panel panel,
|
||||
Option<?> option,
|
||||
int x,
|
||||
int y
|
||||
) {
|
||||
|
||||
if (option instanceof BooleanOption) {
|
||||
return new BooleanComponent(
|
||||
panel,
|
||||
(BooleanOption) option,
|
||||
x,
|
||||
y
|
||||
);
|
||||
}
|
||||
|
||||
if (option instanceof IntOption) {
|
||||
return new SliderComponent(
|
||||
panel,
|
||||
(IntOption) option,
|
||||
x,
|
||||
y
|
||||
);
|
||||
}
|
||||
|
||||
if (option instanceof DoubleOption) {
|
||||
return new SliderComponent(
|
||||
panel,
|
||||
(DoubleOption) option,
|
||||
x,
|
||||
y
|
||||
);
|
||||
}
|
||||
|
||||
if (option instanceof ModeOption) {
|
||||
return new ModeComponent(
|
||||
panel,
|
||||
(ModeOption) option,
|
||||
x,
|
||||
y
|
||||
);
|
||||
}
|
||||
|
||||
if (option instanceof ColorOption) {
|
||||
return new ColorComponent(
|
||||
panel,
|
||||
(ColorOption) option,
|
||||
x,
|
||||
y
|
||||
);
|
||||
}
|
||||
|
||||
if (option instanceof StringOption) {
|
||||
return new StringComponent(
|
||||
panel,
|
||||
(StringOption) option,
|
||||
x,
|
||||
y
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+158
@@ -0,0 +1,158 @@
|
||||
package cn.xiaozhou233.orangex.ui.clickgui.component.option;
|
||||
|
||||
import cn.xiaozhou233.orangex.module.option.impl.DoubleOption;
|
||||
import cn.xiaozhou233.orangex.module.option.impl.IntOption;
|
||||
import cn.xiaozhou233.orangex.ui.clickgui.Panel;
|
||||
|
||||
public class SliderComponent extends OptionComponent {
|
||||
|
||||
private final double min;
|
||||
private final double max;
|
||||
|
||||
private boolean dragging;
|
||||
|
||||
|
||||
public SliderComponent(
|
||||
Panel parent,
|
||||
IntOption option,
|
||||
int offsetX,
|
||||
int offsetY
|
||||
) {
|
||||
super(parent,option,offsetX,offsetY,120,18);
|
||||
|
||||
this.min = option.getMin();
|
||||
this.max = option.getMax();
|
||||
}
|
||||
|
||||
public SliderComponent(
|
||||
Panel parent,
|
||||
DoubleOption option,
|
||||
int offsetX,
|
||||
int offsetY
|
||||
) {
|
||||
super(parent,option,offsetX,offsetY,120,18);
|
||||
|
||||
this.min = option.getMin();
|
||||
this.max = option.getMax();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX,int mouseY,float partialTicks) {
|
||||
|
||||
double value = getValue();
|
||||
|
||||
double percent =
|
||||
(value - min) / (max - min);
|
||||
|
||||
|
||||
int barWidth = width - 10;
|
||||
|
||||
|
||||
drawString(
|
||||
option.getName(),
|
||||
getX() + 5,
|
||||
getY() + 3,
|
||||
0xffffffff
|
||||
);
|
||||
|
||||
|
||||
// Background bar
|
||||
drawRect(
|
||||
getX() + 5,
|
||||
getY() + 15,
|
||||
getX() + 5 + barWidth,
|
||||
getY() + 18,
|
||||
0xff555555
|
||||
);
|
||||
|
||||
|
||||
// Value bar
|
||||
drawRect(
|
||||
getX() + 5,
|
||||
getY() + 15,
|
||||
getX() + 5 + (int)(barWidth * percent),
|
||||
getY() + 18,
|
||||
0xff55ffff
|
||||
);
|
||||
|
||||
|
||||
drawString(
|
||||
String.valueOf(value),
|
||||
getX() + width - 25,
|
||||
getY() + 3,
|
||||
0xffaaaaaa
|
||||
);
|
||||
|
||||
|
||||
if(dragging)
|
||||
updateValue(mouseX);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int mouseX,int mouseY,int mouseButton) {
|
||||
|
||||
if(mouseButton == 0 && isHovered(mouseX,mouseY)) {
|
||||
dragging = true;
|
||||
updateValue(mouseX);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void mouseReleased(int mouseX,int mouseY,int mouseButton) {
|
||||
|
||||
if(mouseButton == 0)
|
||||
dragging = false;
|
||||
}
|
||||
|
||||
|
||||
private void updateValue(int mouseX) {
|
||||
|
||||
double percent =
|
||||
(mouseX - (getX() + 5))
|
||||
/ (double)(width - 10);
|
||||
|
||||
|
||||
percent = Math.max(0,Math.min(1,percent));
|
||||
|
||||
|
||||
double value =
|
||||
min + (max - min) * percent;
|
||||
|
||||
|
||||
if(option instanceof IntOption) {
|
||||
|
||||
((IntOption) option)
|
||||
.setValue((int)value);
|
||||
|
||||
} else if(option instanceof DoubleOption) {
|
||||
|
||||
((DoubleOption) option)
|
||||
.setValue(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private double getValue() {
|
||||
|
||||
if(option instanceof IntOption) {
|
||||
|
||||
return ((IntOption) option)
|
||||
.getValue();
|
||||
|
||||
}
|
||||
|
||||
|
||||
if(option instanceof DoubleOption) {
|
||||
|
||||
return ((DoubleOption) option)
|
||||
.getValue();
|
||||
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
+122
@@ -0,0 +1,122 @@
|
||||
package cn.xiaozhou233.orangex.ui.clickgui.component.option;
|
||||
|
||||
import cn.xiaozhou233.orangex.module.option.impl.StringOption;
|
||||
import cn.xiaozhou233.orangex.ui.clickgui.Panel;
|
||||
|
||||
public class StringComponent extends OptionComponent {
|
||||
|
||||
private final StringOption option;
|
||||
|
||||
private boolean typing;
|
||||
|
||||
|
||||
public StringComponent(
|
||||
Panel parent,
|
||||
StringOption option,
|
||||
int offsetX,
|
||||
int offsetY
|
||||
) {
|
||||
super(parent,option,offsetX,offsetY,120,18);
|
||||
this.option = option;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX,int mouseY,float partialTicks) {
|
||||
|
||||
drawString(
|
||||
option.getName(),
|
||||
getX() + 5,
|
||||
getY() + 5,
|
||||
0xffffffff
|
||||
);
|
||||
|
||||
|
||||
String value = option.getValue();
|
||||
|
||||
if(typing)
|
||||
value += "_";
|
||||
|
||||
|
||||
drawString(
|
||||
value,
|
||||
getX() + width - 50,
|
||||
getY() + 5,
|
||||
typing
|
||||
? 0xff55ffff
|
||||
: 0xffaaaaaa
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void mouseClicked(
|
||||
int mouseX,
|
||||
int mouseY,
|
||||
int mouseButton
|
||||
) {
|
||||
|
||||
if(!isHovered(mouseX,mouseY))
|
||||
return;
|
||||
|
||||
|
||||
if(mouseButton == 0) {
|
||||
typing = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void keyTyped(
|
||||
char typedChar,
|
||||
int keyCode
|
||||
) {
|
||||
|
||||
if(!typing)
|
||||
return;
|
||||
|
||||
|
||||
// Backspace
|
||||
if(keyCode == 14) {
|
||||
|
||||
String value = option.getValue();
|
||||
|
||||
if(value.length() > 0) {
|
||||
option.setValue(
|
||||
value.substring(
|
||||
0,
|
||||
value.length() - 1
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Enter
|
||||
if(keyCode == 28) {
|
||||
typing = false;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if(Character.isISOControl(typedChar))
|
||||
return;
|
||||
|
||||
|
||||
option.setValue(
|
||||
option.getValue() + typedChar
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void mouseReleased(
|
||||
int mouseX,
|
||||
int mouseY,
|
||||
int mouseButton
|
||||
) {
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user