-
Notifications
You must be signed in to change notification settings - Fork 0
/
SimpleScreen.java
170 lines (141 loc) · 5.52 KB
/
SimpleScreen.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
package org.auioc.mcmod.arnicalib.client.gui.screen;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import org.auioc.mcmod.arnicalib.ArnicaLib;
import org.auioc.mcmod.arnicalib.api.game.screen.HScreen;
import org.auioc.mcmod.arnicalib.utils.game.TextUtils;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@OnlyIn(Dist.CLIENT)
public class SimpleScreen extends HScreen {
private static final ResourceLocation TEXTURE = ArnicaLib.id("textures/gui/simple_screen.png");
private static final int TEXTURE_SIZE = 16;
private static final int CORNER_SIZE = 4;
private static final int TOP_LEFT_CORNER_U_OFFSET = 0;
private static final int TOP_LEFT_CORNER_V_OFFSET = 0;
private static final int TOP_RIGHT_CORNER_U_OFFSET = 5;
private static final int TOP_RIGHT_CORNER_V_OFFSET = 0;
private static final int BOTTOM_LEFT_CORNER_U_OFFSET = 0;
private static final int BOTTOM_LEFT_CORNER_V_OFFSET = 5;
private static final int BOTTOM_RIGHT_CORNER_U_OFFSET = 5;
private static final int BOTTOM_RIGHT_CORNER_V_OFFSET = 5;
protected static final int COLOR_BLACK = adjustColor(0x000000);
protected static final int COLOR_WHITE = adjustColor(0xFFFFFF);
protected static final int COLOR_GRAY = adjustColor(0x555555);
protected static final int COLOR_BACKGROUND = adjustColor(0xC6C6C6);
protected final int divWidth;
protected final int divHeight;
protected int divX;
protected int divY;
public SimpleScreen(Component title, int divWidth, int divHeight) {
super(title);
this.divWidth = divWidth;
this.divHeight = divHeight;
}
public SimpleScreen(Component title) {
this(title, 176, 166);
}
public SimpleScreen() {
this(TextUtils.StringText("SimpleScreen"));
}
@Override
public boolean isPauseScreen() {
return false;
}
@Override
public final void render(PoseStack poseStack, int mouseX, int mouseY, float partialTick) {
this.divX = center(this.width, this.divWidth);
this.divY = center(this.height, this.divHeight);
this._renderBackground(poseStack);
this.renderBorderEdge(poseStack);
this.renderBorderCorner(poseStack);
this.subRender(poseStack, mouseX, mouseY, partialTick);
super.render(poseStack, mouseX, mouseY, partialTick);
}
protected void subRender(PoseStack poseStack, int mouseX, int mouseY, float partialTick) {}
private void _renderBackground(PoseStack poseStack) {
super.renderBackground(poseStack);
fill(
poseStack,
this.divX, this.divY,
this.divX + this.divWidth, this.divY + this.divHeight,
COLOR_BACKGROUND
);
}
private void renderBorderEdge(PoseStack poseStack) {
drawBorderEdge(
poseStack,
this.divX, this.divY,
this.divX + this.divWidth, this.divY,
false, false
);
drawBorderEdge(
poseStack,
this.divX, this.divY + this.divHeight,
this.divX + this.divWidth, this.divY + this.divHeight,
false, true
);
drawBorderEdge(
poseStack,
this.divX, this.divY,
this.divX, this.divY + this.divHeight,
true, false
);
drawBorderEdge(
poseStack,
this.divX + this.divWidth, this.divY,
this.divX + this.divWidth, this.divY + this.divHeight,
true, true
);
}
private void renderBorderCorner(PoseStack poseStack) {
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
RenderSystem.setShaderTexture(0, TEXTURE);
blitBorderCorner(
poseStack,
this.divX - CORNER_SIZE, this.divY - CORNER_SIZE,
TOP_LEFT_CORNER_U_OFFSET, TOP_LEFT_CORNER_V_OFFSET
);
blitBorderCorner(
poseStack,
this.divX + this.divWidth, this.divY - CORNER_SIZE,
TOP_RIGHT_CORNER_U_OFFSET, TOP_RIGHT_CORNER_V_OFFSET
);
blitBorderCorner(
poseStack,
this.divX - CORNER_SIZE, this.divY + this.divHeight,
BOTTOM_LEFT_CORNER_U_OFFSET, BOTTOM_LEFT_CORNER_V_OFFSET
);
blitBorderCorner(
poseStack,
this.divX + this.divWidth, this.divY + this.divHeight,
BOTTOM_RIGHT_CORNER_U_OFFSET, BOTTOM_RIGHT_CORNER_V_OFFSET
);
}
private static void drawBorderEdge(PoseStack poseStack, int x1, int y1, int x2, int y2, boolean isVertical, boolean isPositive) {
int p = isPositive ? 1 : -1;
fill(
poseStack,
x1 + (isVertical ? 4 * p : 0), y1 + (isVertical ? 0 : 4 * p),
x2 + (isVertical ? 3 * p : 0), y2 + (isVertical ? 0 : 3 * p),
COLOR_BLACK
);
fill(
poseStack,
x1 + (isVertical ? 3 * p : 0), y1 + (isVertical ? 0 : 3 * p),
x2 + (isVertical ? 1 * p : 0), y2 + (isVertical ? 0 : 1 * p),
isPositive ? COLOR_GRAY : COLOR_WHITE
);
fill(
poseStack,
x1 + (isVertical ? p : 0), y1 + (isVertical ? 0 : p),
x2, y2,
COLOR_BACKGROUND
);
}
private static void blitBorderCorner(PoseStack poseStack, int x, int y, int u, int v) {
blitSquare(poseStack, x, y, u, v, CORNER_SIZE, TEXTURE_SIZE);
}
}