Skip to content

Commit c08b669

Browse files
committed
Bin GUIs resize with window / tfm gui semi functional
1 parent 1bc0994 commit c08b669

File tree

5 files changed

+210
-160
lines changed

5 files changed

+210
-160
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ dependencies {
3535
// Fabric API. This is technically optional, but you probably want it anyway.
3636
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
3737

38-
implementation 'com.github.Coflnet:CoflSkyCore:main-SNAPSHOT'
38+
implementation 'com.github.Coflnet:CoflSkyCore:main'
3939
implementation "org.greenrobot:eventbus-java:3.3.1"
4040
implementation "org.java-websocket:Java-WebSocket:1.5.2"
4141
}

src/client/java/com/coflnet/CoflModClient.java

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,17 @@
11
package com.coflnet;
22

33
import CoflCore.CoflCore;
4-
import CoflCore.classes.AuctionItem;
54
import CoflCore.classes.ChatMessage;
65
import CoflCore.CoflSkyCommand;
7-
import CoflCore.classes.Flip;
8-
import CoflCore.classes.Sound;
96
import CoflCore.commands.CommandType;
107
import CoflCore.commands.JsonStringCommand;
11-
import CoflCore.commands.models.ChatMessageData;
128
import CoflCore.commands.models.FlipData;
13-
import CoflCore.commands.models.SoundData;
149
import CoflCore.events.*;
15-
import CoflCore.handlers.EventRegistry;
16-
import CoflCore.network.WSClient;
1710
import com.coflnet.gui.RenderUtils;
1811
import com.coflnet.gui.cofl.CoflBinGUI;
1912
import com.coflnet.gui.tfm.TfmBinGUI;
2013
import com.google.gson.Gson;
2114
import com.google.gson.GsonBuilder;
22-
import com.google.gson.JsonObject;
23-
import com.google.gson.JsonParser;
24-
import com.google.gson.reflect.TypeToken;
25-
import com.mojang.authlib.minecraft.client.ObjectMapper;
2615
import com.mojang.brigadier.arguments.StringArgumentType;
2716
import net.fabricmc.api.ClientModInitializer;
2817
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
@@ -32,25 +21,19 @@
3221
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
3322
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
3423
import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents;
35-
import net.fabricmc.fabric.api.message.v1.ServerMessageEvents;
3624
import net.fabricmc.loader.api.FabricLoader;
3725
import net.minecraft.client.MinecraftClient;
3826
import net.minecraft.client.gui.screen.ingame.BookScreen;
3927
import net.minecraft.client.gui.screen.ingame.GenericContainerScreen;
4028
import net.minecraft.client.option.KeyBinding;
4129
import net.minecraft.client.util.InputUtil;
4230
import net.minecraft.item.Items;
43-
import net.minecraft.text.ClickEvent;
4431
import net.minecraft.text.Text;
45-
import org.apache.logging.log4j.core.jackson.Log4jJsonObjectMapper;
46-
import org.greenrobot.eventbus.EventBus;
4732
import org.greenrobot.eventbus.Subscribe;
4833
import org.lwjgl.glfw.GLFW;
4934

50-
import java.awt.event.KeyEvent;
5135
import java.nio.file.Path;
5236
import java.time.LocalDateTime;
53-
import java.util.ArrayList;
5437
import java.util.concurrent.ExecutorService;
5538
import java.util.concurrent.Executors;
5639
import java.util.concurrent.LinkedBlockingQueue;
@@ -130,7 +113,7 @@ public void onInitializeClient() {
130113
if (!(client.currentScreen instanceof CoflBinGUI || client.currentScreen instanceof TfmBinGUI)) {
131114
switch (CoflCore.config.purchaseOverlay) {
132115
case COFL: client.setScreen(new CoflBinGUI(gcs, flipId));break;
133-
case TFM: client.setScreen(new TfmBinGUI(Items.BREAD));break;
116+
case TFM: client.setScreen(new TfmBinGUI(gcs));break;
134117
case null: default: break;
135118
}
136119
}
@@ -185,14 +168,17 @@ public void onOpenAuctionGUI(OnOpenAuctionGUI event){
185168
}
186169

187170
@Subscribe
188-
public void onFlipReceive(OnFlipReceive event){
171+
public void onFlipMessage(OnFlipReceive event){
189172
System.out.println("FLIP RECEIVED");
190173
}
191174

192175
@Subscribe
193176
public void onReceiveCommand(ReceiveCommand event){
194-
if (event.command.getType() == CommandType.Flip){
177+
if (event.command.getType() == CommandType.ChatMessage){
195178
System.out.println("onReceiveCommand: "+event.command.getData());
179+
180+
// EventBus.getDefault().post(new OnFlipReceive((Flip)event.command.GetAs(new TypeToken<Flip>() {
181+
// }).getData()));
196182
// JsonObject jsonObject = JsonParser.parseString(event.command.getData()).getAsJsonObject();
197183
// EventBus.getDefault().post(new OnFlipReceive(new Flip(
198184
// new ChatMessage[]{},//jsonObject.get("messages"),
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
package com.coflnet.gui;
2+
3+
import com.coflnet.gui.widget.ItemWidget;
4+
import net.minecraft.client.MinecraftClient;
5+
import net.minecraft.client.gui.DrawContext;
6+
import net.minecraft.client.gui.screen.Screen;
7+
import net.minecraft.client.gui.screen.ingame.GenericContainerScreen;
8+
import net.minecraft.entity.player.PlayerEntity;
9+
import net.minecraft.item.ItemStack;
10+
import net.minecraft.screen.GenericContainerScreenHandler;
11+
import net.minecraft.screen.ScreenHandlerType;
12+
import net.minecraft.screen.slot.SlotActionType;
13+
import net.minecraft.text.Text;
14+
15+
public abstract class BinGUI extends Screen {
16+
protected int width;
17+
protected int height;
18+
protected int screenHeight;
19+
protected int screenWidth;
20+
protected int p;
21+
protected int r;
22+
protected final int ITEM_SLOT = 13;
23+
protected final int BUY_SLOT = 31;
24+
protected final int AUCTION_CANCEL_SLOT = 49;
25+
protected final int CONFIRM_SLOT = 11;
26+
protected final int CONFIRMATION_CANCEL_SLOT = 15;
27+
protected ItemWidget itemWidget;
28+
protected ItemStack currentItem;
29+
30+
protected AuctionStatus auctionStatus;
31+
protected GenericContainerScreenHandler gcsh;
32+
protected GenericContainerScreen gcs;
33+
protected BinGUI(Text title, GenericContainerScreen gcs) {
34+
super(title);
35+
screenWidth = MinecraftClient.getInstance().currentScreen.width;
36+
screenHeight = MinecraftClient.getInstance().currentScreen.height;
37+
38+
this.gcs = gcs;
39+
this.gcsh = gcs.getScreenHandler();
40+
41+
if (gcsh.getType() == ScreenHandlerType.GENERIC_9X3){
42+
this.auctionStatus = AuctionStatus.CONFIRMING;
43+
} else this.auctionStatus = AuctionStatus.INIT;
44+
45+
46+
this.width = MinecraftClient.getInstance().currentScreen.width / 2;
47+
if (width < 300) this.width = 300;
48+
49+
this.height = MinecraftClient.getInstance().currentScreen.height / 3 * 2;
50+
if (height < 225) this.height = 225;
51+
}
52+
53+
protected abstract void clearAndInitWidgets(int screenWidth, int screenHeight);
54+
55+
public void setItem(ItemStack item) {
56+
this.currentItem = item;
57+
this.itemWidget.item = item;
58+
}
59+
60+
@Override
61+
public boolean shouldPause() {
62+
return false;
63+
}
64+
65+
@Override
66+
public void close() {
67+
auctionStatus = AuctionStatus.INIT;
68+
gcs.close();
69+
super.close();
70+
}
71+
72+
protected void clickSlot(int slotId) {
73+
PlayerEntity player = client.player;
74+
75+
client.interactionManager.clickSlot(
76+
gcsh.syncId,
77+
slotId,
78+
0,
79+
SlotActionType.PICKUP,
80+
player
81+
);
82+
}
83+
84+
@Override
85+
public void renderBackground(DrawContext context, int mouseX, int mouseY, float delta) {
86+
if (screenWidth != MinecraftClient.getInstance().currentScreen.width
87+
|| screenHeight != MinecraftClient.getInstance().currentScreen.height){
88+
screenWidth = MinecraftClient.getInstance().currentScreen.width;
89+
screenHeight = MinecraftClient.getInstance().currentScreen.height;
90+
clearAndInitWidgets(screenWidth, screenHeight);
91+
}
92+
}
93+
}

src/client/java/com/coflnet/gui/cofl/CoflBinGUI.java

Lines changed: 19 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,57 @@
11
package com.coflnet.gui.cofl;
22

33
import CoflCore.CoflCore;
4-
import CoflCore.CoflSkyCommand;
54
import CoflCore.commands.models.FlipData;
65
import com.coflnet.gui.AuctionStatus;
6+
import com.coflnet.gui.BinGUI;
77
import com.coflnet.gui.RenderUtils;
88
import com.coflnet.gui.widget.ItemWidget;
99
import com.coflnet.gui.widget.ScrollableDynamicTextWidget;
1010
import net.minecraft.client.MinecraftClient;
11-
import net.minecraft.client.font.MultilineText;
1211
import net.minecraft.client.gui.DrawContext;
13-
import net.minecraft.client.gui.screen.Screen;
1412
import net.minecraft.client.gui.screen.ingame.GenericContainerScreen;
1513
import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder;
1614
import net.minecraft.client.gui.widget.*;
17-
import net.minecraft.client.render.item.ItemRenderer;
18-
import net.minecraft.entity.player.PlayerEntity;
1915
import net.minecraft.item.Item;
20-
import net.minecraft.item.ItemStack;
2116
import net.minecraft.item.Items;
22-
import net.minecraft.screen.GenericContainerScreenHandler;
23-
import net.minecraft.screen.ScreenHandler;
24-
import net.minecraft.screen.ScreenHandlerListener;
2517
import net.minecraft.screen.ScreenHandlerType;
26-
import net.minecraft.screen.slot.SlotActionType;
27-
import net.minecraft.text.HoverEvent;
2818
import net.minecraft.text.MutableText;
29-
import net.minecraft.text.Style;
3019
import net.minecraft.text.Text;
31-
import org.lwjgl.glfw.GLFWWindowRefreshCallback;
32-
import org.lwjgl.glfw.GLFWWindowSizeCallback;
3320
import oshi.util.tuples.Pair;
3421

35-
import java.awt.event.WindowEvent;
36-
import java.awt.event.WindowStateListener;
3722
import java.util.List;
3823

39-
import static com.coflnet.Utils.ChatComponent;
40-
41-
public class CoflBinGUI extends Screen {
24+
public class CoflBinGUI extends BinGUI {
4225
private TextWidget titleTextWidget;
43-
private ItemWidget itemWidget;
4426
private ScrollableDynamicTextWidget loreScrollableTextWidget;
4527
private ClickableWidget rightClickableWidget;
4628
private ClickableWidget leftClickableWidget;
4729

48-
private int width;
49-
private int height;
50-
private int p;
51-
private int r;
52-
private final int ITEM_SLOT = 13;
53-
private final int BUY_SLOT = 31;
54-
private final int AUCTION_CANCEL_SLOT = 49;
55-
private final int CONFIRM_SLOT = 11;
56-
private final int CONFIRMATION_CANCEL_SLOT = 15;
57-
private AuctionStatus auctionStatus;
58-
public GenericContainerScreenHandler gcsh;
59-
public GenericContainerScreen gcs;
6030
public String title = "";
6131
public Text lore = Text.of(RenderUtils.lorem());
6232
public Pair<Integer, Integer> rightButtonCol = new Pair<>(CoflColConfig.BACKGROUND_SECONDARY, CoflColConfig.BACKGROUND_SECONDARY);
6333

6434
public CoflBinGUI(GenericContainerScreen gcs, String flipId){
65-
super(Text.literal("Cofl Bin Gui"));
35+
super(Text.literal("Cofl Bin Gui"), gcs);
6636

6737
FlipData f = CoflCore.flipHandler.fds.getFlipById(flipId);
6838
if(f == null){
6939
System.out.println("NO FLIP FOUND");
7040
} else System.out.println("FLIP FOUND WTF");
7141

72-
int screenWidth = MinecraftClient.getInstance().currentScreen.width;
73-
int screenHeight = MinecraftClient.getInstance().currentScreen.height;
74-
75-
this.gcs = gcs;
76-
this.gcsh = gcs.getScreenHandler();
77-
78-
this.width = screenWidth / 2;
79-
if (width < 300) this.width = 300;
80-
81-
this.height = screenHeight / 3 * 2;
82-
if (height < 225) this.height = 225;
83-
8442
this.p = 5;
8543
this.r = 4;
8644

8745
if (gcsh.getType() == ScreenHandlerType.GENERIC_9X3){
8846
this.auctionStatus = AuctionStatus.CONFIRMING;
8947
} else this.auctionStatus = AuctionStatus.INIT;
9048

49+
clearAndInitWidgets(screenWidth, screenHeight);
50+
}
51+
52+
@Override
53+
protected void clearAndInitWidgets(int screenWidth, int screenHeight) {
54+
this.clearChildren();
9155
leftClickableWidget = new ClickableWidget(
9256
screenWidth / 2 - width / 2 + p,
9357
screenHeight / 2 + height / 2 - p - (225 - 150 - 12 - p * 5) - screenHeight / 15,
@@ -123,9 +87,9 @@ public void onClick(double mouseX, double mouseY) {
12387
@Override
12488
protected void renderWidget(DrawContext context, int mouseX, int mouseY, float delta) {
12589
boolean mouseOver = mouseX >= (double)(screenWidth / 2 - tempWidth / 2 + p + tempWidth / 5 * 2)
126-
&& mouseY >= (double)(screenHeight / 2 + tempHeight / 2 - p - (225 - 150 - 12 - p*5) - screenHeight / 15)
127-
&& mouseX < (double)((screenWidth / 2 - tempWidth / 2 + p + tempWidth / 5 * 2) + (tempWidth / 5 * 3 - p*2))
128-
&& mouseY < (double)((screenHeight / 2 + tempHeight / 2 - p - (225 - 150 - 12 - p*5) - screenHeight / 15) + (225 - 150 - 12 - p*5 + screenHeight / 15));
90+
&& mouseY >= (double)(screenHeight / 2 + tempHeight / 2 - p - (225 - 150 - 12 - p*5) - screenHeight / 15)
91+
&& mouseX < (double)((screenWidth / 2 - tempWidth / 2 + p + tempWidth / 5 * 2) + (tempWidth / 5 * 3 - p*2))
92+
&& mouseY < (double)((screenHeight / 2 + tempHeight / 2 - p - (225 - 150 - 12 - p*5) - screenHeight / 15) + (225 - 150 - 12 - p*5 + screenHeight / 15));
12993

13094
RenderUtils.drawRoundedRect(context,
13195
screenWidth / 2 - tempWidth / 2 + p + tempWidth / 5 * 2,
@@ -187,7 +151,6 @@ public void onClick(double mouseX, double mouseY) {
187151
Items.AIR.getDefaultStack()
188152
);
189153

190-
191154
if (auctionStatus == AuctionStatus.CONFIRMING) setRightButtonConfig(AuctionStatus.CONFIRMING);
192155

193156
this.addDrawableChild(titleTextWidget);
@@ -197,18 +160,6 @@ public void onClick(double mouseX, double mouseY) {
197160
this.addDrawableChild(leftClickableWidget);
198161
}
199162

200-
private void clickSlot(int slotId) {
201-
PlayerEntity player = client.player;
202-
203-
client.interactionManager.clickSlot(
204-
gcsh.syncId,
205-
slotId,
206-
0,
207-
SlotActionType.PICKUP,
208-
player
209-
);
210-
}
211-
212163
private AuctionStatus setAuctionStatus(Item item){
213164
if (item == Items.GOLD_NUGGET) auctionStatus = AuctionStatus.BUYING;
214165
if (item == Items.RED_BED) auctionStatus = AuctionStatus.WAITING;
@@ -235,12 +186,6 @@ private void setRightButtonConfig(AuctionStatus auctionStatus){
235186
}
236187
}
237188

238-
public void setItem(ItemStack item) {
239-
lore = convertTextList(getTooltipFromItem(MinecraftClient.getInstance(), item));
240-
loreScrollableTextWidget.updateText(lore);
241-
this.itemWidget.item = item;
242-
}
243-
244189
public MutableText convertTextList(List<Text> collection){
245190
MutableText res = Text.empty();
246191
if (collection == null || collection.isEmpty()) return res;
@@ -255,17 +200,17 @@ public MutableText convertTextList(List<Text> collection){
255200
return res;
256201
}
257202

258-
@Override
259-
public boolean shouldPause() {
260-
return false;
261-
}
262203

263204
@Override
264205
public void renderBackground(DrawContext drawContext, int mouseX, int mouseY, float delta) {
265-
int screenWidth = MinecraftClient.getInstance().currentScreen.width;
266-
int screenHeight = MinecraftClient.getInstance().currentScreen.height;
206+
super.renderBackground(drawContext, mouseX, mouseY, delta);
207+
267208
if(!gcsh.getInventory().isEmpty()){
268-
if (gcsh.getInventory().getStack(ITEM_SLOT).getItem() != Items.AIR) setItem(gcsh.getInventory().getStack(ITEM_SLOT));
209+
if (gcsh.getInventory().getStack(ITEM_SLOT).getItem() != Items.AIR) {
210+
setItem(gcsh.getInventory().getStack(ITEM_SLOT));
211+
lore = convertTextList(getTooltipFromItem(MinecraftClient.getInstance(), currentItem));
212+
loreScrollableTextWidget.updateText(lore);
213+
}
269214
if (gcsh.getInventory().getStack(BUY_SLOT).getItem() != Items.AIR) setRightButtonConfig(setAuctionStatus(gcsh.getInventory().getStack(ITEM_SLOT).getItem()));
270215
}
271216

@@ -279,10 +224,4 @@ public void renderBackground(DrawContext drawContext, int mouseX, int mouseY, fl
279224
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);
280225
}
281226

282-
@Override
283-
public void close() {
284-
auctionStatus = AuctionStatus.INIT;
285-
gcs.close();
286-
super.close();
287-
}
288227
}

0 commit comments

Comments
 (0)