Skip to content

Commit e252787

Browse files
committed
Merge branch 'chordaui' into 1.20
2 parents c1f0b37 + 977b2ef commit e252787

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+4191
-1416
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ mixingradle_version = 0.7-SNAPSHOT
1313
mixin_version = 0.8.5
1414
librarian_version = 1.+
1515
cursegradle_version = 1.4.0
16-
parchment_version = 2023.06.26
16+
parchment_version = 2023.09.03
1717

1818
# curseforge information
1919
projectId = 534612
Lines changed: 72 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,118 @@
11
package com.teammoeg.chorda.client;
22

33
import org.lwjgl.glfw.GLFW;
4+
import org.lwjgl.system.MemoryUtil;
45

5-
import com.mojang.blaze3d.platform.InputConstants;
66

77
import net.minecraft.client.Minecraft;
88
import net.minecraft.client.gui.screens.Screen;
9+
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
10+
import net.minecraft.sounds.SoundEvents;
911

1012
public class CInputHelper {
1113

1214
public CInputHelper() {
1315
}
14-
public boolean shift(int modifiers) {
16+
public static boolean isShift(int modifiers) {
1517
return (modifiers & GLFW.GLFW_MOD_SHIFT) != 0;
1618
}
1719

18-
public boolean control(int modifiers) {
20+
public static boolean isControl(int modifiers) {
1921
return (modifiers & GLFW.GLFW_MOD_CONTROL) != 0;
2022
}
2123

22-
public boolean alt(int modifiers) {
24+
public static boolean isAlt(int modifiers) {
2325
return (modifiers & GLFW.GLFW_MOD_ALT) != 0;
2426
}
25-
26-
public boolean start(int modifiers) {
27-
return (modifiers & GLFW.GLFW_MOD_SUPER) != 0;
28-
}
29-
30-
public boolean numLock(int modifiers) {
31-
return (modifiers & GLFW.GLFW_MOD_NUM_LOCK) != 0;
32-
}
33-
34-
public boolean capsLock(int modifiers) {
35-
return (modifiers & GLFW.GLFW_MOD_CAPS_LOCK) != 0;
36-
}
37-
public boolean onlyControl(int modifiers) {
38-
return control(modifiers) && !shift(modifiers) && !alt(modifiers);
39-
}
40-
public boolean esc(int keyCode) {
27+
public static boolean isEsc(int keyCode) {
4128
return keyCode==GLFW.GLFW_KEY_ESCAPE;
4229
}
4330

44-
public boolean escOrInventory(int keyCode,int scanCode) {
31+
public static boolean shouldCloseMenu(int keyCode,int scanCode) {
4532

46-
return esc(keyCode) || Minecraft.getInstance().options.keyInventory.matches(keyCode, scanCode);
33+
return isEsc(keyCode) || ClientUtils.mc().options.keyInventory.matches(keyCode, scanCode);
4734
}
4835

49-
public boolean enter(int keyCode) {
36+
public static boolean isEnter(int keyCode) {
5037
return keyCode==GLFW.GLFW_KEY_ENTER;
5138
}
5239

53-
public boolean backspace(int keyCode) {
40+
public static boolean isBackspace(int keyCode) {
5441
return keyCode==GLFW.GLFW_KEY_BACKSPACE;
5542
}
5643

57-
public boolean cut(int keyCode) {
44+
public static boolean isCut(int keyCode) {
5845
return Screen.isCut(keyCode);
5946
}
6047

61-
public boolean paste(int keyCode) {
48+
public static boolean isPaste(int keyCode) {
6249
return Screen.isPaste(keyCode);
6350
}
6451

65-
public boolean copy(int keyCode) {
52+
public static boolean isCopy(int keyCode) {
6653
return Screen.isCopy(keyCode);
6754
}
6855

69-
public boolean selectAll(int keyCode) {
56+
public static boolean isSelectAll(int keyCode) {
7057
return Screen.isSelectAll(keyCode);
7158
}
7259

73-
public boolean deselectAll(int keyCode) {
74-
return keyCode == GLFW.GLFW_KEY_D && Screen.hasControlDown() && !Screen.hasShiftDown() && !Screen.hasAltDown();
60+
public static boolean isDeselectAll(int keyCode) {
61+
return keyCode == GLFW.GLFW_KEY_D && Screen.hasControlDown();
62+
}
63+
public static String getClipboardText() {
64+
return ClientUtils.mc().keyboardHandler.getClipboard();
65+
}
66+
67+
public static void setClipboardText(String string) {
68+
ClientUtils.mc().keyboardHandler.setClipboard(string);
69+
}
70+
public static boolean isShiftKeyDown() {
71+
return Screen.hasShiftDown();
72+
}
73+
74+
public static boolean isCtrlKeyDown() {
75+
return Screen.hasControlDown();
76+
}
77+
public static boolean isKeyPressed(int keyCode) {
78+
return GLFW.glfwGetKey(Minecraft.getInstance().getWindow().getWindow(), keyCode) == GLFW.GLFW_PRESS;
79+
}
80+
public static void playClickSound() {
81+
ClientUtils.mc().getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK.value(), 1));
82+
}
83+
public static boolean isMouseLeftDown() {
84+
return GLFW.glfwGetMouseButton(Minecraft.getInstance().getWindow().getWindow(), GLFW.GLFW_MOUSE_BUTTON_LEFT) == GLFW.GLFW_PRESS;
85+
}
86+
public static boolean isMouseRightDown() {
87+
return GLFW.glfwGetMouseButton(Minecraft.getInstance().getWindow().getWindow(), GLFW.GLFW_MOUSE_BUTTON_RIGHT) == GLFW.GLFW_PRESS;
7588
}
89+
public enum Cursor{
90+
NORMAL(GLFW.GLFW_ARROW_CURSOR),
91+
IBEAM(GLFW.GLFW_IBEAM_CURSOR),
92+
CROSSHAIR(GLFW.GLFW_CROSSHAIR_CURSOR),
93+
HAND(GLFW.GLFW_HAND_CURSOR),
94+
HRESIZE(GLFW.GLFW_HRESIZE_CURSOR),
95+
VRESIZE(GLFW.GLFW_VRESIZE_CURSOR);
96+
97+
private final int type;
98+
private long handle = 0L;
99+
100+
Cursor(int type) {
101+
this.type = type;
102+
}
103+
public void use() {
104+
long window = Minecraft.getInstance().getWindow().getWindow();
105+
106+
if (handle == 0) {
107+
handle = GLFW.glfwCreateStandardCursor(type);
108+
}
109+
110+
GLFW.glfwSetCursor(window, handle);
111+
}
112+
public static void reset() {
113+
long window = Minecraft.getInstance().getWindow().getWindow();
114+
GLFW.glfwSetCursor(window, MemoryUtil.NULL);
115+
}
116+
}
117+
76118
}

src/main/java/com/teammoeg/chorda/client/FHIconWrapper.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ public FHIconWrapper(CIcon icon) {
1414

1515
@Override
1616
public void draw(GuiGraphics arg0, int arg1, int arg2, int arg3, int arg4) {
17+
try {
1718
icon.draw(arg0, arg1, arg2, arg3, arg4);
19+
}catch(Throwable t) {
20+
t.printStackTrace();
21+
}
1822
}
1923

2024
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.teammoeg.chorda.client;
2+
3+
import com.teammoeg.chorda.lang.Components;
4+
5+
import net.minecraft.network.chat.Component;
6+
7+
public class StringTextComponentParser {
8+
9+
public StringTextComponentParser() {
10+
}
11+
public static Component parse(String str) {
12+
return Components.str("");
13+
}
14+
15+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package com.teammoeg.chorda.client.cui;
2+
3+
import com.teammoeg.chorda.client.CInputHelper.Cursor;
4+
import com.teammoeg.chorda.client.icon.CIcons;
5+
import com.teammoeg.chorda.client.icon.CIcons.CIcon;
6+
import com.teammoeg.chorda.client.ui.CGuiHelper;
7+
8+
import net.minecraft.client.gui.GuiGraphics;
9+
import net.minecraft.client.gui.components.AbstractWidget;
10+
import net.minecraft.network.chat.Component;
11+
12+
public abstract class Button extends UIWidget {
13+
protected Component title;
14+
protected CIcon icon;
15+
16+
public Button(UIElement panel, Component t, CIcon i) {
17+
super(panel);
18+
setSize(16, 16);
19+
icon = i;
20+
title = t;
21+
}
22+
23+
public Button(UIElement panel) {
24+
this(panel, Component.empty(), CIcons.nop());
25+
}
26+
27+
@Override
28+
public Component getTitle() {
29+
return title;
30+
}
31+
32+
public Button setTitle(Component s) {
33+
title = s;
34+
return this;
35+
}
36+
37+
public Button setIcon(CIcon i) {
38+
icon = i;
39+
return this;
40+
}
41+
42+
private int getTextureY() {
43+
int i = 1;
44+
if (!this.isEnabled()) {
45+
i = 0;
46+
} else if (this.isMouseOver()) {
47+
i = 2;
48+
}
49+
50+
return 46 + i * 20;
51+
}
52+
53+
public void drawBackground(GuiGraphics graphics, int x, int y, int w, int h) {
54+
graphics.blitNineSliced(AbstractWidget.WIDGETS_LOCATION, x, y, w, h, 20, 4, 200, 20, 0, this.getTextureY());
55+
56+
}
57+
58+
public void drawIcon(GuiGraphics graphics, int x, int y, int w, int h) {
59+
icon.draw(graphics, x, y, w, h);
60+
}
61+
62+
@Override
63+
public void render(GuiGraphics graphics, int x, int y, int w, int h) {
64+
CGuiHelper.resetGuiDrawing();
65+
var s = h >= 16 ? 16 : 8;
66+
drawBackground(graphics, x, y, w, h);
67+
drawIcon(graphics, x + (w - s) / 2, y + (h - s) / 2, s, s);
68+
}
69+
70+
@Override
71+
public boolean onMousePressed(MouseButton button) {
72+
if (isMouseOver()) {
73+
if (isEnabled()) {
74+
onClicked(button);
75+
}
76+
77+
return true;
78+
}
79+
80+
return false;
81+
}
82+
83+
public abstract void onClicked(MouseButton button);
84+
85+
@Override
86+
public Cursor getCursor() {
87+
return Cursor.HAND;
88+
}
89+
}

0 commit comments

Comments
 (0)