Skip to content

Commit dabf70c

Browse files
committed
added hover effect for the buttons
1 parent 121a7b1 commit dabf70c

File tree

3 files changed

+57
-34
lines changed

3 files changed

+57
-34
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents;
2121
import net.fabricmc.loader.api.FabricLoader;
2222
import net.minecraft.client.MinecraftClient;
23+
import net.minecraft.client.WindowEventHandler;
2324
import net.minecraft.client.gui.screen.ingame.GenericContainerScreen;
2425
import net.minecraft.client.option.KeyBinding;
2526
import net.minecraft.client.util.InputUtil;
@@ -28,6 +29,7 @@
2829
import org.greenrobot.eventbus.Subscribe;
2930
import org.lwjgl.glfw.GLFW;
3031

32+
import java.awt.event.WindowEvent;
3133
import java.nio.file.Path;
3234

3335
import static com.coflnet.Utils.ChatComponent;

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

Lines changed: 52 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.coflnet.gui.widget.ItemWidget;
66
import com.coflnet.gui.widget.ScrollableDynamicTextWidget;
77
import net.minecraft.client.MinecraftClient;
8+
import net.minecraft.client.font.MultilineText;
89
import net.minecraft.client.gui.DrawContext;
910
import net.minecraft.client.gui.screen.Screen;
1011
import net.minecraft.client.gui.screen.ingame.GenericContainerScreen;
@@ -21,7 +22,15 @@
2122
import net.minecraft.screen.ScreenHandlerType;
2223
import net.minecraft.screen.slot.SlotActionType;
2324
import net.minecraft.text.HoverEvent;
25+
import net.minecraft.text.MutableText;
2426
import net.minecraft.text.Text;
27+
import org.lwjgl.glfw.GLFWWindowRefreshCallback;
28+
import org.lwjgl.glfw.GLFWWindowSizeCallback;
29+
import oshi.util.tuples.Pair;
30+
31+
import java.awt.event.WindowEvent;
32+
import java.awt.event.WindowStateListener;
33+
import java.util.List;
2534

2635
public class CoflBinGUI extends Screen {
2736
private TextWidget titleTextWidget;
@@ -44,8 +53,7 @@ public class CoflBinGUI extends Screen {
4453
public GenericContainerScreen gcs;
4554
public String title = "";
4655
public Text lore = Text.of(RenderUtils.lorem());
47-
public String rightButtonText = "";
48-
public int rightButtonCol = 0x00000000;
56+
public Pair<Integer, Integer> rightButtonCol = new Pair<>(CoflColConfig.BACKGROUND_SECONDARY, CoflColConfig.BACKGROUND_SECONDARY);
4957

5058
public CoflBinGUI(Item item, GenericContainerScreen gcs){
5159
super(Text.literal("Cofl Bin Gui"));
@@ -78,7 +86,7 @@ public CoflBinGUI(Item item, GenericContainerScreen gcs){
7886
){
7987
@Override
8088
protected void renderWidget(DrawContext context, int mouseX, int mouseY, float delta) {
81-
RenderUtils.drawRoundedRect(context, getX(), getY(), getWidth(), getHeight(), r, CoflColConfig.CANCEL);
89+
RenderUtils.drawRoundedRect(context, getX(), getY(), getWidth(), getHeight(), r, this.isMouseOver(mouseX,mouseY) ? CoflColConfig.CANCEL_HOVER : CoflColConfig.CANCEL);
8290
RenderUtils.drawString(context, this.getMessage().getLiteralString(), getX() + 6, getY() + 4, 0xFFEEEEEE);
8391
}
8492

@@ -87,32 +95,39 @@ protected void appendClickableNarrations(NarrationMessageBuilder builder) {}
8795

8896
@Override
8997
public void onClick(double mouseX, double mouseY) {
90-
System.out.println(auctionStatus.name());
9198
if (auctionStatus != AuctionStatus.CONFIRMING) clickSlot(AUCTION_CANCEL_SLOT);
9299
else clickSlot(CONFIRMATION_CANCEL_SLOT);
93100
}
94101
};
95102

103+
int tempWidth = width;
104+
int tempHeight = height;
96105
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,
106+
0, //screenWidth / 2 - width / 2, //screenWidth / 2 - width / 2 + p + width / 5 * 2,
107+
0, //screenHeight / 2 - height / 2, //screenHeight / 2 + height / 2 - p - (225 - 150 - 12 - p*5) - screenHeight / 15,
108+
screenWidth, //width, //width / 5 * 3 - p*2,
109+
screenHeight, //height, //225 - 150 - 12 - p*5 + screenHeight / 15,
101110
Text.of("")
102111
){
103112
@Override
104113
protected void renderWidget(DrawContext context, int mouseX, int mouseY, float delta) {
114+
boolean mouseOver = mouseX >= (double)(screenWidth / 2 - tempWidth / 2 + p + tempWidth / 5 * 2)
115+
&& mouseY >= (double)(screenHeight / 2 + tempHeight / 2 - p - (225 - 150 - 12 - p*5) - screenHeight / 15)
116+
&& mouseX < (double)((screenWidth / 2 - tempWidth / 2 + p + tempWidth / 5 * 2) + (tempWidth / 5 * 3 - p*2))
117+
&& mouseY < (double)((screenHeight / 2 + tempHeight / 2 - p - (225 - 150 - 12 - p*5) - screenHeight / 15) + (225 - 150 - 12 - p*5 + screenHeight / 15));
118+
105119
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,
120+
screenWidth / 2 - tempWidth / 2 + p + tempWidth / 5 * 2,
121+
screenHeight / 2 + tempHeight / 2 - p - (225 - 150 - 12 - p*5) - screenHeight / 15,
122+
tempWidth / 5 * 3 - p*2,
109123
225 - 150 - 12 - p*5 + screenHeight / 15,
110-
r, rightButtonCol
124+
r, mouseOver ? rightButtonCol.getB() : rightButtonCol.getA()
111125
);
126+
112127
RenderUtils.drawString(context,
113128
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,
129+
screenWidth / 2 - tempWidth / 2 + p + tempWidth / 5 * 2 + 6,
130+
screenHeight / 2 + tempHeight / 2 - p - (225 - 150 - 12 - p*5) - screenHeight / 15 + 4,
116131
0xFFEEEEEE
117132
);
118133
}
@@ -208,38 +223,43 @@ private AuctionStatus setAuctionStatus(Item item){
208223
private void setRightButtonConfig(AuctionStatus auctionStatus){
209224
switch (auctionStatus){
210225
case INIT:
211-
rightButtonCol = CoflColConfig.CONFIRM;
212-
rightClickableWidget.setMessage(Text.of("INIT"));
213-
break;
214226
case BUYING:
215-
rightButtonCol = CoflColConfig.CONFIRM;
216-
rightClickableWidget.setMessage(Text.of("BUY ITEM"));
227+
case WAITING:
228+
System.out.println("CASE ENTERED");
229+
rightButtonCol = new Pair<>(CoflColConfig.CONFIRM, CoflColConfig.CONFIRM_HOVER);
230+
rightClickableWidget.setMessage(Text.of("Buy (You can click anywhere)"));
217231
break;
218232
case SOLD:
219-
rightButtonCol = CoflColConfig.UNAVAILABLE;
220-
rightClickableWidget.setMessage(Text.of("SOLD"));
221-
break;
222-
case WAITING:
223-
rightButtonCol = CoflColConfig.UNAVAILABLE;
224-
rightClickableWidget.setMessage(Text.of("WAITING"));
233+
rightButtonCol = new Pair<>(CoflColConfig.UNAVAILABLE, CoflColConfig.UNAVAILABLE);
234+
rightClickableWidget.setMessage(Text.of("Bought by "));
225235
break;
226236
case CONFIRMING:
227-
rightButtonCol = CoflColConfig.CONFIRM;
228-
rightClickableWidget.setMessage(Text.of("CONFIRM"));
237+
rightButtonCol = new Pair<>(CoflColConfig.CONFIRM, CoflColConfig.CONFIRM_HOVER);
238+
rightClickableWidget.setMessage(Text.of("Confirm purchase"));
229239
break;
230240
}
231241
}
232242

233243
public void setItem(ItemStack item) {
234-
lore = Text.empty();
235-
titleTextWidget.setMessage(item.getName());
236-
Text firstEntry = getTooltipFromItem(MinecraftClient.getInstance(), item).getFirst();
237-
lore = firstEntry.getWithStyle(firstEntry.getStyle()).getLast();
238-
244+
lore = convertTextList(getTooltipFromItem(MinecraftClient.getInstance(), item));
239245
loreScrollableTextWidget.updateText(lore);
240246
this.itemWidget.item = item;
241247
}
242248

249+
public MutableText convertTextList(List<Text> collection){
250+
MutableText res = Text.empty();
251+
if (collection == null || collection.isEmpty()) return res;
252+
253+
res = Text.literal(collection.getFirst().getString()).setStyle(collection.getFirst().getStyle());
254+
collection.removeFirst();
255+
256+
for (Text text : collection) {
257+
MutableText toAppend = Text.literal("\n"+text.getString()).setStyle(text.getStyle());
258+
res.append(toAppend);
259+
}
260+
return res;
261+
}
262+
243263
@Override
244264
public boolean shouldPause() {
245265
return false;

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
public abstract class CoflColConfig {
44
public static final int BACKGROUND_PRIMARY = 0xFF222831;
55
public static final int BACKGROUND_SECONDARY = 0xFF393E46;
6-
public static final int CONFIRM = 0xFF00DD00;
6+
public static final int CONFIRM = 0xFF8AD62F;
7+
public static final int CONFIRM_HOVER = 0xFFb1f755;
78
public static final int CANCEL = 0xFFB21E1E;
9+
public static final int CANCEL_HOVER = 0xFFf75555;
810
public static final int UNAVAILABLE = 0xFFD07916;
911
public static final int TEXT_PRIMARY = 0xFFFFFFFF;
10-
public static final int TEXT_SECONDARY = 0xFF606060;
1112
}

0 commit comments

Comments
 (0)