11package com .coflnet .gui .cofl ;
22
3+ import CoflCore .CoflSkyCommand ;
34import com .coflnet .gui .AuctionStatus ;
45import com .coflnet .gui .RenderUtils ;
56import com .coflnet .gui .widget .ItemWidget ;
2324import net .minecraft .screen .slot .SlotActionType ;
2425import net .minecraft .text .HoverEvent ;
2526import net .minecraft .text .MutableText ;
27+ import net .minecraft .text .Style ;
2628import net .minecraft .text .Text ;
2729import org .lwjgl .glfw .GLFWWindowRefreshCallback ;
2830import org .lwjgl .glfw .GLFWWindowSizeCallback ;
3234import java .awt .event .WindowStateListener ;
3335import java .util .List ;
3436
37+ import static com .coflnet .Utils .ChatComponent ;
38+
3539public class CoflBinGUI extends Screen {
3640 private TextWidget titleTextWidget ;
3741 private ItemWidget itemWidget ;
@@ -64,10 +68,6 @@ public CoflBinGUI(Item item, GenericContainerScreen gcs){
6468 this .gcs = gcs ;
6569 this .gcsh = gcs .getScreenHandler ();
6670
67- if (gcsh .getType () == ScreenHandlerType .GENERIC_9X3 ){
68- this .auctionStatus = AuctionStatus .CONFIRMING ;
69- } else this .auctionStatus = AuctionStatus .INIT ;
70-
7171 this .width = screenWidth / 2 ;
7272 if (width < 300 ) this .width = 300 ;
7373
@@ -77,6 +77,10 @@ public CoflBinGUI(Item item, GenericContainerScreen gcs){
7777 this .p = 5 ;
7878 this .r = 4 ;
7979
80+ if (gcsh .getType () == ScreenHandlerType .GENERIC_9X3 ){
81+ this .auctionStatus = AuctionStatus .CONFIRMING ;
82+ } else this .auctionStatus = AuctionStatus .INIT ;
83+
8084 leftClickableWidget = new ClickableWidget (
8185 screenWidth / 2 - width / 2 + p ,
8286 screenHeight / 2 + height / 2 - p - (225 - 150 - 12 - p * 5 ) - screenHeight / 15 ,
@@ -87,7 +91,7 @@ public CoflBinGUI(Item item, GenericContainerScreen gcs){
8791 @ Override
8892 protected void renderWidget (DrawContext context , int mouseX , int mouseY , float delta ) {
8993 RenderUtils .drawRoundedRect (context , getX (), getY (), getWidth (), getHeight (), r , this .isMouseOver (mouseX ,mouseY ) ? CoflColConfig .CANCEL_HOVER : CoflColConfig .CANCEL );
90- RenderUtils .drawString (context , this .getMessage ().getLiteralString (), getX () + 6 , getY () + 4 , 0xFFEEEEEE );
94+ RenderUtils .drawString (context , this .getMessage ().getLiteralString (), getX () + 6 , getY () + 4 , CoflColConfig . TEXT_PRIMARY );
9195 }
9296
9397 @ Override
@@ -128,7 +132,7 @@ protected void renderWidget(DrawContext context, int mouseX, int mouseY, float d
128132 this .getMessage ().getString (),
129133 screenWidth / 2 - tempWidth / 2 + p + tempWidth / 5 * 2 + 6 ,
130134 screenHeight / 2 + tempHeight / 2 - p - (225 - 150 - 12 - p *5 ) - screenHeight / 15 + 4 ,
131- 0xFFEEEEEE
135+ CoflColConfig . TEXT_PRIMARY
132136 );
133137 }
134138
@@ -141,6 +145,7 @@ public void onClick(double mouseX, double mouseY) {
141145 leftClickableWidget .onClick (mouseX , mouseY );
142146 } else {
143147 if (auctionStatus != AuctionStatus .CONFIRMING ) clickSlot (BUY_SLOT );
148+ else if (auctionStatus == AuctionStatus .WAITING ) MinecraftClient .getInstance ().inGameHud .getChatHud ().addMessage (Text .literal ("[§1C§6oflnet§f]§7: waiting for auction grace period " ));
144149 else clickSlot (CONFIRM_SLOT );
145150 }
146151 }
@@ -164,41 +169,34 @@ public void onClick(double mouseX, double mouseY) {
164169 protected void drawBox (DrawContext context ) {}
165170
166171 @ Override
167- public boolean mouseReleased (double mouseX , double mouseY , int button ) {
168- if (super .mouseReleased (mouseX , mouseY , button ) && isMouseOver (mouseX ,mouseY ) && button == 0 ){
169- rightClickableWidget .onClick (mouseX ,mouseY );
170- }
171- return super .mouseReleased (mouseX , mouseY , button );
172+ public void onClick (double mouseX , double mouseY ) {
173+ rightClickableWidget .onClick (mouseX ,mouseY );
172174 }
173175 };
174- //loreScrollableTextWidget.updateText(Text.of("AAAAAAAAAAAAAa"));
175-
176176
177177 itemWidget = new ItemWidget (
178178 screenWidth / 2 - width / 2 + p + 2 ,
179179 screenHeight / 2 - height / 2 + p + 12 + p + 2 ,
180180 Items .AIR .getDefaultStack ()
181181 );
182182
183- this .addDrawableChild (titleTextWidget );
184- this .addDrawableChild (loreScrollableTextWidget );
185- this .addDrawableChild (itemWidget );
186- this .addDrawableChild (rightClickableWidget );
187- this .addDrawableChild (leftClickableWidget );
188-
189183 gcsh .addListener (new ScreenHandlerListener () {
190184 @ Override
191185 public void onSlotUpdate (ScreenHandler handler , int slotId , ItemStack stack ) {
192186 //if (stack.getItem() != Items.AIR) System.out.println("slotid: "+slotId);
193- if (slotId == ITEM_SLOT ) setItem (stack );
194- if (auctionStatus != AuctionStatus .CONFIRMING ){
195- if (slotId == BUY_SLOT ) setRightButtonConfig (setAuctionStatus (stack .getItem ()));
196- } else if (auctionStatus == AuctionStatus .CONFIRMING && slotId == CONFIRM_SLOT ) setRightButtonConfig (AuctionStatus .CONFIRMING );
187+ // if (slotId == ITEM_SLOT) setItem(stack);
188+ if (auctionStatus == AuctionStatus .CONFIRMING && slotId == CONFIRM_SLOT ) setRightButtonConfig (AuctionStatus .CONFIRMING );
197189 }
198190
199191 @ Override
200192 public void onPropertyUpdate (ScreenHandler handler , int property , int value ) {}
201193 });
194+
195+ this .addDrawableChild (titleTextWidget );
196+ this .addDrawableChild (loreScrollableTextWidget );
197+ this .addDrawableChild (itemWidget );
198+ this .addDrawableChild (rightClickableWidget );
199+ this .addDrawableChild (leftClickableWidget );
202200 }
203201
204202 private void clickSlot (int slotId ) {
@@ -225,7 +223,6 @@ private void setRightButtonConfig(AuctionStatus auctionStatus){
225223 case INIT :
226224 case BUYING :
227225 case WAITING :
228- System .out .println ("CASE ENTERED" );
229226 rightButtonCol = new Pair <>(CoflColConfig .CONFIRM , CoflColConfig .CONFIRM_HOVER );
230227 rightClickableWidget .setMessage (Text .of ("Buy (You can click anywhere)" ));
231228 break ;
@@ -250,12 +247,12 @@ public MutableText convertTextList(List<Text> collection){
250247 MutableText res = Text .empty ();
251248 if (collection == null || collection .isEmpty ()) return res ;
252249
253- res = Text . literal (collection .getFirst (). getString ()). setStyle ( collection . getFirst (). getStyle ());
250+ res . append (collection .getFirst ());
254251 collection .removeFirst ();
255252
256253 for (Text text : collection ) {
257- MutableText toAppend = Text .literal ("\n " + text . getString ()). setStyle ( text . getStyle ( ));
258- res .append (toAppend );
254+ res . append ( Text .literal ("\n " ));
255+ res .append (text );
259256 }
260257 return res ;
261258 }
@@ -269,6 +266,10 @@ public boolean shouldPause() {
269266 public void renderBackground (DrawContext drawContext , int mouseX , int mouseY , float delta ) {
270267 int screenWidth = MinecraftClient .getInstance ().currentScreen .width ;
271268 int screenHeight = MinecraftClient .getInstance ().currentScreen .height ;
269+ if (!gcsh .getInventory ().isEmpty ()){
270+ if (gcsh .getInventory ().getStack (ITEM_SLOT ).getItem () != Items .AIR ) setItem (gcsh .getInventory ().getStack (ITEM_SLOT ));
271+ if (gcsh .getInventory ().getStack (BUY_SLOT ).getItem () != Items .AIR ) setRightButtonConfig (setAuctionStatus (gcsh .getInventory ().getStack (ITEM_SLOT ).getItem ()));
272+ }
272273
273274 // Background
274275 RenderUtils .drawRoundedRect (drawContext , screenWidth / 2 - width / 2 ,screenHeight / 2 - height / 2 , width , height , r , CoflColConfig .BACKGROUND_PRIMARY );
@@ -282,6 +283,7 @@ public void renderBackground(DrawContext drawContext, int mouseX, int mouseY, fl
282283
283284 @ Override
284285 public void close () {
286+ auctionStatus = AuctionStatus .INIT ;
285287 gcs .close ();
286288 super .close ();
287289 }
0 commit comments