Skip to content

Commit 2a5baf5

Browse files
committed
change button appearance based on the auction status
1 parent 1523c82 commit 2a5baf5

File tree

3 files changed

+70
-27
lines changed

3 files changed

+70
-27
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.coflnet.gui;
2+
3+
public enum AuctionStatus{
4+
SOLD,
5+
WAITING,
6+
BUYING
7+
}

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

Lines changed: 60 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.coflnet.gui.cofl;
22

3+
import com.coflnet.gui.AuctionStatus;
34
import com.coflnet.gui.RenderUtils;
45
import com.coflnet.gui.widget.ItemWidget;
56
import net.minecraft.client.MinecraftClient;
@@ -20,6 +21,12 @@
2021
import net.minecraft.text.Text;
2122

2223
public class CoflBinGUI extends Screen implements InventoryChangedListener {
24+
private TextWidget titleTextWidget;
25+
private ItemWidget itemWidget;
26+
private ScrollableTextWidget loreScrollableTextWidget;
27+
private ClickableWidget rightClickableWidget;
28+
private ClickableWidget leftClickableWidget;
29+
2330
private int width;
2431
private int height;
2532
private int p;
@@ -28,13 +35,8 @@ public class CoflBinGUI extends Screen implements InventoryChangedListener {
2835
public Item item = Items.AIR;
2936
public String title = "";
3037
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+
public String rightButtonText = "";
39+
public int rightButtonCol = 0x00000000;
3840

3941
public CoflBinGUI(Item item, GenericContainerScreenHandler gcsh){
4042
super(Text.literal("Cofl Bin Gui"));
@@ -54,25 +56,6 @@ public CoflBinGUI(Item item, GenericContainerScreenHandler gcsh){
5456
this.p = 5;
5557
this.r = 4;
5658

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-
7659
leftClickableWidget = new ClickableWidget(
7760
screenWidth / 2 - width / 2 + p,
7861
screenHeight / 2 + height / 2 - p - (225 - 150 - 12 - p * 5) - screenHeight / 15,
@@ -98,7 +81,7 @@ protected void appendClickableNarrations(NarrationMessageBuilder builder) {}
9881
screenHeight / 2 - height / 2, //screenHeight / 2 + height / 2 - p - (225 - 150 - 12 - p*5) - screenHeight / 15,
9982
width, //width / 5 * 3 - p*2,
10083
height, //225 - 150 - 12 - p*5 + screenHeight / 15,
101-
Text.of(buttonRText)
84+
Text.of(rightButtonText)
10285
){
10386
@Override
10487
protected void renderWidget(DrawContext context, int mouseX, int mouseY, float delta) {
@@ -161,6 +144,56 @@ public void onClick(double mouseX, double mouseY) {
161144
this.addDrawableChild(itemWidget);
162145
this.addDrawableChild(rightClickableWidget);
163146
this.addDrawableChild(leftClickableWidget);
147+
148+
gcsh.addListener(new ScreenHandlerListener() {
149+
@Override
150+
public void onSlotUpdate(ScreenHandler handler, int slotId, ItemStack stack) {
151+
if (stack.getItem() != Items.AIR) System.out.println("slotid: "+slotId);
152+
switch (slotId){
153+
case 13:
154+
setItem(stack.getItem());
155+
break;
156+
case 31:
157+
switch (getAuctionStatus(stack.getItem())){
158+
case WAITING -> setRightButtonConfig(AuctionStatus.WAITING);
159+
case BUYING -> setRightButtonConfig(AuctionStatus.BUYING);
160+
case SOLD -> setRightButtonConfig(AuctionStatus.SOLD);
161+
case null, default -> System.out.println("Slot 31 empty");
162+
}
163+
break;
164+
case 41:
165+
break;
166+
}
167+
}
168+
169+
@Override
170+
public void onPropertyUpdate(ScreenHandler handler, int property, int value) {}
171+
});
172+
}
173+
174+
private AuctionStatus getAuctionStatus(Item item){
175+
if (item == Items.GOLD_NUGGET) return AuctionStatus.BUYING;
176+
if (item == Items.RED_BED) return AuctionStatus.WAITING;
177+
if (item == Items.POTATO) return AuctionStatus.SOLD;
178+
return null;
179+
}
180+
181+
private void setRightButtonConfig(AuctionStatus auctionStatus){
182+
switch (auctionStatus){
183+
case BUYING:
184+
rightButtonCol = CoflColConfig.CONFIRM;
185+
rightButtonText = "BUY ITEM";
186+
break;
187+
case SOLD:
188+
rightButtonCol = CoflColConfig.UNAVAILABLE;
189+
rightButtonText = "SOLD";
190+
break;
191+
case WAITING:
192+
rightButtonCol = CoflColConfig.UNAVAILABLE;
193+
rightButtonText = "WAITING";
194+
break;
195+
196+
}
164197
}
165198

166199
public void setItem(Item item) {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"keybinding.coflmod.bestflips": "Cofl: Show best flips"
3+
}

0 commit comments

Comments
 (0)