Skip to content

Commit 543b52a

Browse files
committed
- skin fixes
- scrollbar fixed
1 parent 9e6e09c commit 543b52a

File tree

6 files changed

+72
-15
lines changed

6 files changed

+72
-15
lines changed

common/src/main/java/smartin/miapi/client/gui/ScrollList.java

Lines changed: 67 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
import net.minecraft.client.gui.DrawContext;
66
import net.minecraft.client.gui.widget.ClickableWidget;
77
import net.minecraft.text.Text;
8-
import net.minecraft.util.math.ColorHelper;
98
import org.joml.Matrix4f;
109
import org.joml.Vector4f;
10+
import smartin.miapi.client.gui.crafting.CraftingScreen;
1111

1212
import java.util.List;
1313

@@ -24,6 +24,10 @@ public class ScrollList extends InteractAbleWidget {
2424
private int maxScrollAmount;
2525
public boolean saveMode = true;
2626
boolean needsScrollbar = false;
27+
public boolean alwaysEnableScrollbar = false;
28+
int barWidth = 8;
29+
boolean scrollbarDragged = false;
30+
public boolean altDesign = false;
2731

2832
/**
2933
* Constructs a new ScrollList with the given x and y coordinates, width, height,
@@ -84,8 +88,8 @@ public void render(DrawContext drawContext, int mouseX, int mouseY, float delta)
8488
if (startY + widget.getHeight() >= this.getY() && startY <= this.getY() + this.height - 1) {
8589
widget.setY(startY);
8690
widget.setX(this.getX());
87-
if (needsScrollbar) {
88-
widget.setWidth(this.width - 5);
91+
if (showScrollbar()) {
92+
widget.setWidth(this.width - barWidth);
8993
} else {
9094
widget.setWidth(this.width);
9195
}
@@ -100,15 +104,39 @@ public void render(DrawContext drawContext, int mouseX, int mouseY, float delta)
100104
startY += widget.getHeight();
101105
}
102106

103-
if (needsScrollbar) {
104-
int barHeight = Math.max(10, this.height * this.height / (this.maxScrollAmount + this.height));
105-
int barY = this.getY() + 1 + (int) ((this.height - barHeight - 2) * (float) this.scrollAmount / this.maxScrollAmount);
106-
int barX = this.getX() + this.width - 5;
107-
drawContext.fill(barX, getY(), barX + 5, this.getY() + this.height, 0xFFCCCCCC);
108-
drawContext.fill(barX, barY, barX + 5, barY + barHeight, ColorHelper.Argb.getArgb(255, 50, 50, 50));
107+
if (showScrollbar()) {
108+
int barX = this.getX() + this.width - barWidth;
109+
float percentage = (float) this.scrollAmount / (float) maxScrollAmount;
110+
renderScrollbarBackground(drawContext, mouseX, mouseY, delta, barX, barWidth);
111+
renderScrollbarClickAble(drawContext, mouseX, mouseY, delta, barX, barWidth, percentage);
109112
}
110113
}
111114

115+
public void renderScrollbarBackground(DrawContext drawContext, int mouseX, int mouseY, float delta, int barX, int barWidth) {
116+
int offsetAlt = 0;
117+
if (altDesign) {
118+
offsetAlt = 28;
119+
}
120+
drawTextureWithEdge(drawContext, CraftingScreen.BACKGROUND_TEXTURE, barX, getY(), 498 - offsetAlt, 96, 14, 15, barWidth, getHeight(), 512, 512, 3);
121+
}
122+
123+
public void renderScrollbarClickAble(DrawContext drawContext, int mouseX, int mouseY, float delta, int barX, int barWidth, float percent) {
124+
int height = (int) ((this.getHeight() - 17) * percent) + 1 + getY();
125+
int offset = 0;
126+
if (!needsScrollbar) {
127+
offset = 16;
128+
}
129+
int offsetAlt = 0;
130+
if (altDesign) {
131+
offsetAlt = 28;
132+
}
133+
drawTextureWithEdge(drawContext, CraftingScreen.BACKGROUND_TEXTURE, barX, height, 498 - 14 - offsetAlt, 96 + offset, 14, 15, barWidth, 15, 512, 512, 3);
134+
}
135+
136+
private boolean showScrollbar() {
137+
return needsScrollbar || alwaysEnableScrollbar;
138+
}
139+
112140
@Override
113141
public void renderHover(DrawContext drawContext, int mouseX, int mouseY, float delta) {
114142
if (isMouseOver(mouseX, mouseY)) {
@@ -166,10 +194,11 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
166194
}
167195

168196
boolean clicked = false;
169-
if (needsScrollbar) {
197+
if (showScrollbar()) {
170198
if (isMouseOver(mouseX, mouseY)) {
171-
if (mouseY > this.getX() + this.width - 5 && mouseY < this.getX() + this.width) {
172-
//TODO:drag motion?
199+
if (mouseX > this.getX() + this.width - barWidth && mouseX < this.getX() + this.width) {
200+
scrollbarDragged = true;
201+
return true;
173202
}
174203
}
175204
}
@@ -186,11 +215,37 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
186215
return false;
187216
}
188217

218+
@Override
219+
public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) {
220+
if (mouseX > this.getX() + this.width - barWidth && mouseX < this.getX() + this.width) {
221+
if (mouseY < (double) this.getY()) {
222+
this.scrollAmount = 0;
223+
return true;
224+
} else if (mouseY > (double) (this.getY() + this.height)) {
225+
this.scrollAmount = maxScrollAmount;
226+
return true;
227+
} else {
228+
double i = Math.min(1, Math.max(0, (mouseY - getY()) / (getHeight() - 10)));
229+
this.scrollAmount = (int) (i * maxScrollAmount);
230+
return true;
231+
}
232+
}
233+
return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY);
234+
}
235+
189236
@Override
190237
public boolean mouseReleased(double mouseX, double mouseY, int button) {
191238
if (this.widgets == null) {
192239
return false;
193240
}
241+
if (showScrollbar()) {
242+
if (isMouseOver(mouseX, mouseY)) {
243+
if (mouseX > this.getX() + this.width - barWidth && mouseX < this.getX() + this.width) {
244+
scrollbarDragged = false;
245+
return true;
246+
}
247+
}
248+
}
194249

195250
boolean released = false;
196251

common/src/main/java/smartin/miapi/client/gui/crafting/statdisplay/StatDisplay.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import smartin.miapi.client.gui.InteractAbleWidget;
1818
import smartin.miapi.client.gui.ScrollList;
1919
import smartin.miapi.client.gui.TransformableWidget;
20-
import smartin.miapi.client.gui.crafting.statdisplay.*;
2120
import smartin.miapi.modules.properties.*;
2221

2322
import java.util.ArrayList;
@@ -160,6 +159,8 @@ public StatDisplay(int x, int y, int width, int height) {
160159
transformableWidget = new TransformableWidget(x, y, width, height, Text.empty());
161160
boxList = new BoxList(x , y, width, height, Text.empty(), new ArrayList<>());
162161
ScrollList list = new ScrollList(x , y , width, height, List.of(boxList));
162+
list.altDesign = true;
163+
list.alwaysEnableScrollbar = true;
163164
transformableWidget.addChild(list);
164165
transformableWidget.rawProjection = new Matrix4f();
165166
//transformableWidget.rawProjection.scale(0.5f, 0.5f, 0.5f);

common/src/main/java/smartin/miapi/modules/MiapiPermissions.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public static List<String> getPerms(PlayerEntity player){
3939
return playerPerms.get(player);
4040
}
4141
List<String> perms = getPerms(player.getUuid());
42+
perms.add("user");
4243
playerPerms.put(player,perms);
4344
return perms;
4445
}
Loading

common/src/main/resources/data/miapi/skins/module/skyrim/goldbrand.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
},
3333
"condition": {
3434
"type": "miapi_perm",
35-
"perms": ["supporter","skyrim","goldbrand"]
35+
"perms": ["user","supporter","skyrim","goldbrand"]
3636
},
3737
"texture": {
3838
"texture": "miapi:textures/skin/skyrim/goldbrand.png",

common/src/main/resources/data/miapi/skins/module/star_wars/light_saber_hilt/anakin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@
2828
},
2929
"condition": {
3030
"type": "miapi_perm",
31-
"perms": ["supporter","star_wars","anakin","lightsaber_hilt"]
31+
"perms": ["user","supporter","star_wars","anakin","lightsaber_hilt"]
3232
}
3333
}

0 commit comments

Comments
 (0)