Skip to content

Commit d53e8e1

Browse files
committed
Custom Screens for overriding the auctions UIs
1 parent c748bfa commit d53e8e1

File tree

5 files changed

+448
-0
lines changed

5 files changed

+448
-0
lines changed
Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
package com.coflnet.gui.cofl;
2+
3+
import com.coflnet.gui.RenderUtils;
4+
import com.coflnet.gui.widget.ItemWidget;
5+
import net.minecraft.client.MinecraftClient;
6+
import net.minecraft.client.gui.DrawContext;
7+
import net.minecraft.client.gui.screen.Screen;
8+
import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder;
9+
import net.minecraft.client.gui.widget.ClickableWidget;
10+
import net.minecraft.client.gui.widget.ScrollableTextWidget;
11+
import net.minecraft.client.gui.widget.TextWidget;
12+
import net.minecraft.inventory.Inventory;
13+
import net.minecraft.inventory.InventoryChangedListener;
14+
import net.minecraft.item.Item;
15+
import net.minecraft.item.ItemStack;
16+
import net.minecraft.item.Items;
17+
import net.minecraft.screen.GenericContainerScreenHandler;
18+
import net.minecraft.screen.ScreenHandler;
19+
import net.minecraft.screen.ScreenHandlerListener;
20+
import net.minecraft.text.Text;
21+
22+
public class CoflBinGUI extends Screen implements InventoryChangedListener {
23+
private int width;
24+
private int height;
25+
private int p;
26+
private int r;
27+
public GenericContainerScreenHandler gcsh;
28+
public Item item = Items.AIR;
29+
public String title = "";
30+
public String lore = RenderUtils.lorem();
31+
public String buttonRText = "";
32+
33+
private TextWidget titleTextWidget;
34+
private ItemWidget itemWidget;
35+
private ScrollableTextWidget loreScrollableTextWidget;
36+
private ClickableWidget rightClickableWidget;
37+
private ClickableWidget leftClickableWidget;
38+
39+
public CoflBinGUI(Item item, GenericContainerScreenHandler gcsh){
40+
super(Text.literal("Cofl Bin Gui"));
41+
42+
int screenWidth = MinecraftClient.getInstance().currentScreen.width;
43+
int screenHeight = MinecraftClient.getInstance().currentScreen.height;
44+
45+
this.item = item;
46+
this.gcsh = gcsh;
47+
48+
this.width = screenWidth / 2;
49+
if (width < 300) this.width = 300;
50+
51+
this.height = screenHeight / 3 * 2;
52+
if (height < 225) this.height = 225;
53+
54+
this.p = 5;
55+
this.r = 4;
56+
57+
gcsh.addListener(new ScreenHandlerListener() {
58+
@Override
59+
public void onSlotUpdate(ScreenHandler handler, int slotId, ItemStack stack) {
60+
if (stack.getItem() != Items.AIR) System.out.println("slotid: "+slotId);
61+
switch (slotId){
62+
case 13:
63+
setItem(stack.getItem());
64+
break;
65+
case 31:
66+
break;
67+
case 41:
68+
break;
69+
}
70+
}
71+
72+
@Override
73+
public void onPropertyUpdate(ScreenHandler handler, int property, int value) {}
74+
});
75+
76+
leftClickableWidget = new ClickableWidget(
77+
screenWidth / 2 - width / 2 + p,
78+
screenHeight / 2 + height / 2 - p - (225 - 150 - 12 - p * 5) - screenHeight / 15,
79+
width / 5 * 2 - p,
80+
225 - 150 - 12 - p*5 + screenHeight / 15,
81+
Text.of("Cancel")
82+
){
83+
@Override
84+
protected void renderWidget(DrawContext context, int mouseX, int mouseY, float delta) {
85+
RenderUtils.drawRoundedRect(context, getX(), getY(), getWidth(), getHeight(), r, CoflColConfig.CANCEL);
86+
RenderUtils.drawString(context, this.getMessage().getLiteralString(), getX() + 6, getY() + 4, 0xFFEEEEEE);
87+
}
88+
89+
@Override
90+
protected void appendClickableNarrations(NarrationMessageBuilder builder) {}
91+
92+
@Override
93+
public void onClick(double mouseX, double mouseY) {close();}
94+
};
95+
96+
rightClickableWidget = new ClickableWidget(
97+
screenWidth / 2 - width / 2, //screenWidth / 2 - width / 2 + p + width / 5 * 2,
98+
screenHeight / 2 - height / 2, //screenHeight / 2 + height / 2 - p - (225 - 150 - 12 - p*5) - screenHeight / 15,
99+
width, //width / 5 * 3 - p*2,
100+
height, //225 - 150 - 12 - p*5 + screenHeight / 15,
101+
Text.of(buttonRText)
102+
){
103+
@Override
104+
protected void renderWidget(DrawContext context, int mouseX, int mouseY, float delta) {
105+
RenderUtils.drawRoundedRect(context,
106+
screenWidth / 2 - width / 2 + p + width / 5 * 2,
107+
screenHeight / 2 + height / 2 - p - (225 - 150 - 12 - p*5) - screenHeight / 15,
108+
width / 5 * 3 - p*2,
109+
225 - 150 - 12 - p*5 + screenHeight / 15,
110+
r, CoflColConfig.CONFIRM
111+
);
112+
RenderUtils.drawString(context,
113+
this.getMessage().getString(),
114+
screenWidth / 2 - width / 2 + p + width / 5 * 2 + 6,
115+
screenHeight / 2 + height / 2 - p - (225 - 150 - 12 - p*5) - screenHeight / 15 + 4,
116+
0xFFEEEEEE
117+
);
118+
}
119+
@Override
120+
protected void appendClickableNarrations(NarrationMessageBuilder builder) {}
121+
122+
@Override
123+
public void onClick(double mouseX, double mouseY) {
124+
if (leftClickableWidget.isMouseOver(mouseX, mouseY)) {
125+
leftClickableWidget.onClick(mouseX, mouseY);
126+
} else MinecraftClient.getInstance().player.sendMessage(Text.of("Confim clicked"));
127+
}
128+
};
129+
130+
titleTextWidget = new TextWidget(
131+
screenWidth / 2 - width / 2 + p + 3,
132+
screenHeight / 2 - height / 2 + p + 2,
133+
width - p*2 - 4, 10,
134+
Text.of(title),
135+
MinecraftClient.getInstance().textRenderer
136+
).alignLeft();
137+
138+
loreScrollableTextWidget = new ScrollableTextWidget(
139+
screenWidth / 2 - width / 2 + p + 20 + p + 4,
140+
screenHeight / 2 - height / 2 + p + 12 + p + 2,
141+
width - 20 - p*4 - 4, height - 75 - 2 - screenHeight / 15,
142+
Text.of(lore), MinecraftClient.getInstance().textRenderer
143+
){
144+
@Override
145+
protected void drawBox(DrawContext context) {}
146+
147+
@Override
148+
public void onClick(double mouseX, double mouseY) {
149+
super.onClick(mouseX, mouseY);
150+
}
151+
};
152+
153+
itemWidget = new ItemWidget(
154+
screenWidth / 2 - width / 2 + p + 2,
155+
screenHeight / 2 - height / 2 + p + 12 + p + 2,
156+
this.item.getDefaultStack()
157+
);
158+
159+
this.addDrawableChild(titleTextWidget);
160+
this.addDrawableChild(loreScrollableTextWidget);
161+
this.addDrawableChild(itemWidget);
162+
this.addDrawableChild(rightClickableWidget);
163+
this.addDrawableChild(leftClickableWidget);
164+
}
165+
166+
public void setItem(Item item) {
167+
this.item = item;
168+
}
169+
170+
@Override
171+
public boolean shouldPause() {
172+
return false;
173+
}
174+
175+
@Override
176+
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
177+
super.render(context, mouseX, mouseY, delta);
178+
}
179+
180+
@Override
181+
public void renderBackground(DrawContext drawContext, int mouseX, int mouseY, float delta) {
182+
int screenWidth = MinecraftClient.getInstance().currentScreen.width;
183+
int screenHeight = MinecraftClient.getInstance().currentScreen.height;
184+
185+
// Background
186+
RenderUtils.drawRoundedRect(drawContext, screenWidth / 2 - width / 2,screenHeight / 2 - height / 2, width, height, r, CoflColConfig.BACKGROUND_PRIMARY);
187+
188+
// Title Background
189+
RenderUtils.drawRoundedRect(drawContext, screenWidth / 2 - width / 2 + p,screenHeight / 2 - height / 2 + p, width - p*2, 12, r, CoflColConfig.BACKGROUND_SECONDARY);
190+
191+
// Item Background
192+
RenderUtils.drawRoundedRect(drawContext, screenWidth / 2 - width / 2 + p,screenHeight / 2 - height / 2 + p + 12 + p, 20, 20, r, CoflColConfig.BACKGROUND_SECONDARY);
193+
194+
// Description Background
195+
RenderUtils.drawRoundedRect(drawContext,screenWidth / 2 - width / 2 + p + 20 + p, screenHeight / 2 - height / 2 + p + 12+ p, width - 20 - p*3, height - 75 - screenHeight / 15, r, CoflColConfig.BACKGROUND_SECONDARY);
196+
}
197+
198+
@Override
199+
public void onInventoryChanged(Inventory sender) {
200+
System.out.println("Inv changed");
201+
}
202+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.coflnet.gui.cofl;
2+
3+
public abstract class CoflColConfig {
4+
public static final int BACKGROUND_PRIMARY = 0xFF222831;
5+
public static final int BACKGROUND_SECONDARY = 0xFF393E46;
6+
public static final int CONFIRM = 0xFF00DD00;
7+
public static final int CANCEL = 0xFFB21E1E;
8+
public static final int UNAVAILABLE = 0xFFD07916;
9+
public static final int TEXT_PRIMARY = 0xFFFFFFFF;
10+
public static final int TEXT_SECONDARY = 0xFF606060;
11+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
package com.coflnet.gui.tfm;
2+
3+
import com.coflnet.gui.RenderUtils;
4+
import com.coflnet.gui.widget.ItemWidget;
5+
import net.minecraft.client.MinecraftClient;
6+
import net.minecraft.client.gui.DrawContext;
7+
import net.minecraft.client.gui.screen.Screen;
8+
import net.minecraft.client.gui.widget.MultilineTextWidget;
9+
import net.minecraft.client.gui.widget.TextWidget;
10+
import net.minecraft.item.Item;
11+
import net.minecraft.item.Items;
12+
import net.minecraft.text.Text;
13+
import org.slf4j.Logger;
14+
import org.slf4j.LoggerFactory;
15+
16+
public class TfmBinGUI extends Screen {
17+
private static final Logger log = LoggerFactory.getLogger(TfmBinGUI.class);
18+
private int width;
19+
private int height;
20+
private int p;
21+
private int r;
22+
public Item item = Items.AIR;
23+
public String title = "";
24+
25+
public TfmBinGUI(Item item){
26+
super(
27+
Text.of("Tfm Bin Gui")
28+
);
29+
30+
this.item = item;
31+
32+
this.width = MinecraftClient.getInstance().currentScreen.width / 2;
33+
if (width < 300) this.width = 300;
34+
35+
this.height = MinecraftClient.getInstance().currentScreen.height / 3 * 2;
36+
if (height < 225) this.height = 225;
37+
38+
this.p = 1;
39+
this.r = 4;
40+
41+
int screenWidth = MinecraftClient.getInstance().currentScreen.width;
42+
int screenHeight = MinecraftClient.getInstance().currentScreen.height;
43+
44+
this.addDrawableChild(new TextWidget(
45+
screenWidth / 2 - width / 2 + 12,
46+
screenHeight / 2 - height / 2 + 8,
47+
width - 12, 10,
48+
Text.of("§2C§rofl - Auction View"),
49+
MinecraftClient.getInstance().textRenderer
50+
).alignLeft());
51+
52+
this.addDrawableChild(new MultilineTextWidget(
53+
screenWidth / 2 - width / 2 + 12,
54+
screenHeight / 2 - height / 2 + 8 + 8 + 6,
55+
Text.of(title),
56+
MinecraftClient.getInstance().textRenderer
57+
).setCentered(false));
58+
59+
this.addDrawableChild(new ItemWidget(
60+
screenWidth / 2 - 8,
61+
screenHeight / 2 - 8,
62+
item.getDefaultStack()
63+
));
64+
}
65+
66+
67+
@Override
68+
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
69+
super.render(context, mouseX, mouseY, delta);
70+
}
71+
72+
@Override
73+
public void renderBackground(DrawContext drawContext, int mouseX, int mouseY, float delta){
74+
int screenWidth = MinecraftClient.getInstance().currentScreen.width;
75+
int screenHeight = MinecraftClient.getInstance().currentScreen.height;
76+
77+
RenderUtils.drawRectOutline(
78+
drawContext,
79+
screenWidth / 2 - width / 2,
80+
screenHeight / 2 - height / 2,
81+
width, height,
82+
p, TfmColConfig.BACKGROUND_PRIMARY, TfmColConfig.BORDER
83+
);
84+
85+
RenderUtils.drawRectOutline(
86+
drawContext,
87+
screenWidth / 2 - 80 / 2,
88+
screenHeight / 2 - 40 / 2,
89+
80, 40,
90+
p, TfmColConfig.CONFIRM, TfmColConfig.BORDER
91+
);
92+
93+
RenderUtils.drawRectOutline(
94+
drawContext,
95+
screenWidth / 2 - 36 / 2,
96+
screenHeight / 2 + 40 + p,
97+
36, 30,
98+
p, TfmColConfig.CANCEL, TfmColConfig.BORDER
99+
);
100+
101+
}
102+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.coflnet.gui.tfm;
2+
3+
public abstract class TfmColConfig {
4+
public static final int BACKGROUND_PRIMARY = 0xFF3b3b3b;
5+
public static final int CONFIRM = 0xFF005f00;
6+
public static final int CANCEL = 0xFF5e0000;
7+
public static final int BORDER = 0xFF0b0b0b;
8+
}

0 commit comments

Comments
 (0)