55import com .coflnet .gui .widget .ItemWidget ;
66import com .coflnet .gui .widget .ScrollableDynamicTextWidget ;
77import net .minecraft .client .MinecraftClient ;
8+ import net .minecraft .client .font .MultilineText ;
89import net .minecraft .client .gui .DrawContext ;
910import net .minecraft .client .gui .screen .Screen ;
1011import net .minecraft .client .gui .screen .ingame .GenericContainerScreen ;
2122import net .minecraft .screen .ScreenHandlerType ;
2223import net .minecraft .screen .slot .SlotActionType ;
2324import net .minecraft .text .HoverEvent ;
25+ import net .minecraft .text .MutableText ;
2426import 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
2635public 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 ;
0 commit comments